POSIX doesn't really specify _SC_NPROCESSORS_CONF, so add a sysdep routine for that. ia32 now uses it, which is one more step towards unbreaking macosx. thanks to ali for the report :)
This was SVN commit r5300.
This commit is contained in:
parent
efe104ee5d
commit
84e4e5aa12
@ -224,6 +224,19 @@ void* cpu_memcpy(void* RESTRICT dst, const void* RESTRICT src, size_t nbytes)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int cpu_OsNumProcessors()
|
||||
{
|
||||
#if OS_WIN
|
||||
return wcpu_NumProcessors();
|
||||
#elif OS_UNIX
|
||||
return ucpu_NumPackages();
|
||||
#else
|
||||
#error "port"
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
LibError cpu_CallByEachCPU(CpuCallback cb, void* param)
|
||||
{
|
||||
#if OS_WIN
|
||||
|
@ -77,6 +77,18 @@ extern size_t cpu_MemorySize(CpuMemoryIndicators mem_type);
|
||||
extern void* cpu_memcpy(void* RESTRICT dst, const void* RESTRICT src, size_t size);
|
||||
|
||||
|
||||
/**
|
||||
* @return the number of what the OS deems "processors" or -1 on failure.
|
||||
*
|
||||
* this is used by ia32 when it cannot determine the number via APIC IDs.
|
||||
* in other situations, the cpu_NumPackages et al. functions are preferable
|
||||
* since they are more specific.
|
||||
*
|
||||
* note: this function is necessary because POSIX sysconf _SC_NPROCESSORS_CONF
|
||||
* is not suppored on MacOSX, else we would use that.
|
||||
**/
|
||||
extern int cpu_OsNumProcessors();
|
||||
|
||||
// execute the specified function once on each CPU.
|
||||
// this includes logical HT units and proceeds serially (function
|
||||
// is never re-entered) in order of increasing OS CPU ID.
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "lib/posix/posix.h" // pthread, sysconf
|
||||
#include "lib/posix/posix.h" // pthread
|
||||
#include "lib/bits.h"
|
||||
#include "lib/timer.h"
|
||||
#include "lib/module_init.h"
|
||||
@ -470,6 +470,7 @@ static void ExtractFieldsIntoSet(const Ids& apicIds, uint& bit_pos, uint num_val
|
||||
}
|
||||
|
||||
|
||||
// @return false if unavailable / no information can be returned.
|
||||
static bool DetectProcessorTopologyViaApicIds()
|
||||
{
|
||||
// old APIC (see ia32_ApicId for details)
|
||||
@ -510,8 +511,7 @@ static bool DetectProcessorTopologyViaApicIds()
|
||||
|
||||
static void GuessProcessorTopologyViaOsCount()
|
||||
{
|
||||
// get the number of what the OS deems "processors"
|
||||
const long numProcessors = sysconf(_SC_NPROCESSORS_CONF);
|
||||
const int numProcessors = cpu_OsNumProcessors();
|
||||
|
||||
// note: we cannot hope to always return correct results since disabled
|
||||
// cores/logical units cannot be distinguished from the situation of the
|
||||
|
Loading…
Reference in New Issue
Block a user