23 #include "precompiled.h"
29 #include <sys/sysctl.h>
33 static size_t numProcessors;
35 if(numProcessors == 0)
38 int mib[]={CTL_HW, HW_NCPU};
40 size_t len =
sizeof(ncpus);
41 int ret = sysctl(mib, 2, &ncpus, &len, NULL, 0);
43 numProcessors = (size_t)ncpus;
52 static uintptr_t processorMask;
66 pageSize = (size_t)sysconf(_SC_PAGESIZE);
81 size_t memorySize = 0;
82 size_t len =
sizeof(memorySize);
84 int mib[2] = { CTL_HW, HW_PHYSMEM };
85 sysctl(mib, 2, &memorySize, &len, 0, 0);
93 size_t memoryAvailable = 0;
94 size_t len =
sizeof(memoryAvailable);
96 int mib[2] = { CTL_HW, HW_USERMEM };
97 sysctl(mib, 2, &memoryAvailable, &len, 0, 0);
98 memoryAvailable /=
MiB;
99 return memoryAvailable;
115 const uintptr_t processorMask = uintptr_t(1) << processor;
117 cb(processor, cbData);
size_t os_cpu_QueryMemorySize()
static const size_t pageSize
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Status os_cpu_CallByEachCPU(OsCpuCallback cb, uintptr_t cbData)
execute the specified function once on each processor.
size_t os_cpu_NumProcessors()
size_t os_cpu_LargePageSize()
uintptr_t os_cpu_SetThreadAffinityMask(uintptr_t processorMask)
restrict the current thread to a set of processors.
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
size_t os_cpu_MemoryAvailable()
i64 Status
Error handling system.
uintptr_t os_cpu_ProcessorMask()
void(* OsCpuCallback)(size_t processor, uintptr_t cbData)
called by os_cpu_CallByEachCPU.