mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-12 08:36:04 +00:00
5d80d2ee5d
- add AlignedAllocator - an STL allocator that returns cache-line-aligned objects (required to avoid RFOs when threads write to various independent items in a container) - bits: bit_mask can now be used for N=0..numBits (works around full-word-shifts-are-undefined issue) - precompiled.h: remove scoped_ptr, add function-related stuff from TR1 - numa: . add numa_IsMemoryInterleaved . numa_Allocate is now able to allocate large pages as well (reduces TLB misses) - os_cpu: interface change to support 32-bit apps running on WoW64 systems with > 4 GB of memory - topology: use new x86_x64_EnumerateCaches API; fix detection of cache ID - x86_x64: provide the means of enumerating all caches returned by CPUID and detect L1 cache size This was SVN commit r6004.
109 lines
2.0 KiB
C++
109 lines
2.0 KiB
C++
#include "precompiled.h"
|
|
|
|
#include "../cpu.h"
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
double os_cpu_ClockFrequency()
|
|
{
|
|
return -1; // don't know
|
|
}
|
|
|
|
|
|
size_t os_cpu_NumProcessors()
|
|
{
|
|
static size_t numProcessors;
|
|
|
|
if(numProcessors == 0)
|
|
{
|
|
// Mac OS X doesn't have sysconf(_SC_NPROCESSORS_CONF)
|
|
int mib[]={CTL_HW, HW_NCPU};
|
|
int ncpus;
|
|
size_t len = sizeof(ncpus);
|
|
int ret = sysctl(mib, 2, &ncpus, &len, NULL, 0);
|
|
debug_assert(ret != -1);
|
|
numProcessors = (size_t)ncpus;
|
|
}
|
|
|
|
return numProcessors;
|
|
}
|
|
|
|
|
|
uintptr_t os_cpu_ProcessorMask()
|
|
{
|
|
static uintptr_t processorMask;
|
|
|
|
if(!processorMask)
|
|
processorMask = bit_mask<uintptr_t>(os_cpu_NumProcessors());
|
|
|
|
return processorMask;
|
|
}
|
|
|
|
|
|
size_t os_cpu_PageSize()
|
|
{
|
|
static size_t pageSize;
|
|
|
|
if(!pageSize)
|
|
pageSize = (size_t)sysconf(_SC_PAGESIZE);
|
|
|
|
return pageSize;
|
|
}
|
|
|
|
|
|
size_t os_cpu_LargePageSize()
|
|
{
|
|
// assume they're unsupported.
|
|
return 0;
|
|
}
|
|
|
|
|
|
size_t os_cpu_MemorySize()
|
|
{
|
|
static size_t memorySize;
|
|
|
|
if(!memorySize)
|
|
{
|
|
size_t len = sizeof(memorySize);
|
|
// Argh, the API doesn't seem to be const-correct
|
|
/*const*/ int mib[2] = { CTL_HW, HW_PHYSMEM };
|
|
sysctl(mib, 2, &memorySize, &len, 0, 0);
|
|
memorySize /= MiB;
|
|
}
|
|
|
|
return memorySize;
|
|
}
|
|
|
|
|
|
size_t os_cpu_MemoryAvailable()
|
|
{
|
|
size_t memoryAvailable = 0;
|
|
size_t len = sizeof(memoryAvailable);
|
|
// Argh, the API doesn't seem to be const-correct
|
|
/*const*/ int mib[2] = { CTL_HW, HW_USERMEM };
|
|
sysctl(mib, 2, &memoryAvailable, &len, 0, 0);
|
|
memoryAvailable /= MiB;
|
|
return memoryAvailable;
|
|
}
|
|
|
|
|
|
uintptr_t os_cpu_SetThreadAffinityMask(uintptr_t processorMask)
|
|
{
|
|
// not yet implemented. when doing so, see http://developer.apple.com/releasenotes/Performance/RN-AffinityAPI/
|
|
|
|
return os_cpu_ProcessorMask();
|
|
}
|
|
|
|
|
|
LibError cpu_CallByEachCPU(OsCpuCallback cb, uintptr_t cbData)
|
|
{
|
|
for(size_t processor = 0; processor < os_cpu_NumProcessors(); processor++)
|
|
{
|
|
os_cpu_SetThreadAffinity(processor);
|
|
cb(processor, cbData);
|
|
}
|
|
|
|
return INFO::OK;
|
|
}
|