diff --git a/source/lib/sysdep/linux/lcpu.cpp b/source/lib/sysdep/linux/lcpu.cpp index c832aa1fad..0e293a3f1e 100644 --- a/source/lib/sysdep/linux/lcpu.cpp +++ b/source/lib/sysdep/linux/lcpu.cpp @@ -1,12 +1,34 @@ #include "precompiled.h" -#include "lcpu.h" +#include "../cpu.h" #if OS_LINUX #include "valgrind.h" #endif +double cpu_ClockFrequency() +{ + return -1; // don't know +} + + +uint cpu_NumProcessors() +{ + long res = sysconf(_SC_NPROCESSORS_CONF); + if (res == -1) + return 0; + else + return (uint)res; +} + + +size_t cpu_PageSize() +{ + return (size_t)sysconf(_SC_PAGESIZE); +} + + static int SysconfFromMemType(CpuMemoryIndicators mem_type) { switch(mem_type) @@ -19,7 +41,7 @@ static int SysconfFromMemType(CpuMemoryIndicators mem_type) UNREACHABLE; } -size_t lcpu_MemorySize(CpuMemoryIndicators mem_type) +size_t cpu_MemorySize(CpuMemoryIndicators mem_type) { const int sc_name = SysconfFromMemType(mem_type); const size_t pageSize = sysconf(_SC_PAGESIZE); @@ -28,7 +50,7 @@ size_t lcpu_MemorySize(CpuMemoryIndicators mem_type) } -LibError lcpu_CallByEachCPU(CpuCallback cb, void* param) +LibError cpu_CallByEachCPU(CpuCallback cb, void* param) { long ncpus = sysconf(_SC_NPROCESSORS_CONF); diff --git a/source/lib/sysdep/linux/lcpu.h b/source/lib/sysdep/linux/lcpu.h deleted file mode 100644 index 9203060775..0000000000 --- a/source/lib/sysdep/linux/lcpu.h +++ /dev/null @@ -1,4 +0,0 @@ -#include "lib/sysdep/cpu.h" - -extern size_t lcpu_MemorySize(CpuMemoryIndicators mem_type); -extern LibError lcpu_CallByEachCPU(CpuCallback cb, void* param); diff --git a/source/lib/sysdep/osx/ocpu.cpp b/source/lib/sysdep/osx/ocpu.cpp index 3771c106d6..989049ec01 100644 --- a/source/lib/sysdep/osx/ocpu.cpp +++ b/source/lib/sysdep/osx/ocpu.cpp @@ -1,16 +1,19 @@ #include "precompiled.h" -#include "ocpu.h" +#include "../cpu.h" #include -int ocpu_IsThrottlingPossible() + +double cpu_ClockFrequency() { - return -1; // don't know + return -1.0; // don't know } -int ocpu_NumPackages() + +uint cpu_NumProcessors() { + // Mac OS X doesn't have sysconf(_SC_NPROCESSORS_CONF) int mib[]={CTL_HW, HW_NCPU}; int ncpus; size_t len = sizeof(ncpus); @@ -20,15 +23,10 @@ int ocpu_NumPackages() return ncpus; } -double ocpu_ClockFrequency() -{ - return -1; // don't know -} -LibError ocpu_CallByEachCPU(CpuCallback cb, void* param) +size_t cpu_PageSize() { - // TODO: implement - return ERR::NOT_IMPLEMENTED; + return (size_t)sysconf(_SC_PAGESIZE); } @@ -44,7 +42,7 @@ static int SysctlFromMemType(CpuMemoryIndicators mem_type) UNREACHABLE; } -size_t ocpu_MemorySize(CpuMemoryIndicators mem_type) +size_t cpu_MemorySize(CpuMemoryIndicators mem_type) { size_t memory_size = 0; size_t len = sizeof(memory_size); @@ -53,3 +51,9 @@ size_t ocpu_MemorySize(CpuMemoryIndicators mem_type) sysctl(mib, 2, &memory_size, &len, 0, 0); return memory_size; } + +LibError cpu_CallByEachCPU(CpuCallback cb, void* param) +{ + // TODO: implement + return ERR::NOT_IMPLEMENTED; +} diff --git a/source/lib/sysdep/osx/ocpu.h b/source/lib/sysdep/osx/ocpu.h deleted file mode 100644 index db5bbd25af..0000000000 --- a/source/lib/sysdep/osx/ocpu.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef INCLUDED_OCPU -#define INCLUDED_OCPU - -#include "lib/sysdep/cpu.h" - -extern size_t ocpu_MemorySize(CpuMemoryIndicators mem_type); - -extern int ocpu_IsThrottlingPossible(); -extern int ocpu_NumPackages(); -extern double ocpu_ClockFrequency(); -extern LibError ocpu_CallByEachCPU(CpuCallback cb, void* param); - -#endif // #ifndef INCLUDED_OCPU diff --git a/source/lib/sysdep/unix/ucpu.cpp b/source/lib/sysdep/unix/ucpu.cpp deleted file mode 100644 index 50dbbf83db..0000000000 --- a/source/lib/sysdep/unix/ucpu.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "precompiled.h" - -#include "ucpu.h" - -int ucpu_IsThrottlingPossible() -{ - return -1; // don't know -} - - -uint cpu_NumProcessors() -{ - long res = sysconf(_SC_NPROCESSORS_CONF); - if (res == -1) - return 0; - else - return (uint)res; -} - -int ucpu_NumPackages() -{ - long res = sysconf(_SC_NPROCESSORS_CONF); - if (res == -1) - return 1; - else - return (int)res; -} - -double ucpu_ClockFrequency() -{ - return -1; // don't know -} - - -size_t ucpu_PageSize() -{ - return (size_t)sysconf(_SC_PAGE_SIZE); -} - -LibError ucpu_CallByEachCPU(CpuCallback cb, void* param) -{ - // TODO: implement - return ERR::NOT_IMPLEMENTED; -} diff --git a/source/lib/sysdep/unix/ucpu.h b/source/lib/sysdep/unix/ucpu.h deleted file mode 100644 index b8ddd1f22b..0000000000 --- a/source/lib/sysdep/unix/ucpu.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef INCLUDED_UCPU -#define INCLUDED_UCPU - -#include "lib/sysdep/cpu.h" - -extern int ucpu_IsThrottlingPossible(); -extern int ucpu_NumPackages(); -extern double ucpu_ClockFrequency(); -extern size_t ucpu_PageSize(); -extern LibError ucpu_CallByEachCPU(CpuCallback cb, void* param); - -#endif // #ifndef INCLUDED_UCPU diff --git a/source/lib/sysdep/unix/udbg.cpp b/source/lib/sysdep/unix/udbg.cpp index 44b7b99000..5a79fcd4e2 100644 --- a/source/lib/sysdep/unix/udbg.cpp +++ b/source/lib/sysdep/unix/udbg.cpp @@ -1,8 +1,8 @@ /* udbg.cpp This file contains debug helpers that are common for all unix systems. See -udbg_bfd.cpp for the linux-specific stuff (Using BFD and backtrace() for symbol -lookups and backtraces) +linux/ldbg.cpp for the linux-specific stuff (Using BFD and backtrace() for +symbol lookups and backtraces) */ #include "precompiled.h" diff --git a/source/lib/sysdep/win/wcpu.cpp b/source/lib/sysdep/win/wcpu.cpp index 5547e0c722..408d9ce340 100644 --- a/source/lib/sysdep/win/wcpu.cpp +++ b/source/lib/sysdep/win/wcpu.cpp @@ -15,15 +15,6 @@ #include "lib/bits.h" -uint cpu_NumProcessors() -{ - SYSTEM_INFO si; - GetSystemInfo(&si); // can't fail - const uint numProcessors = (uint)si.dwNumberOfProcessors; - return numProcessors; -} - - static LibError ReadFrequencyFromRegistry(DWORD* freqMhz) { HKEY hKey; @@ -32,7 +23,7 @@ static LibError ReadFrequencyFromRegistry(DWORD* freqMhz) DWORD size = sizeof(*freqMhz); LONG ret = RegQueryValueEx(hKey, "~MHz", 0, 0, (LPBYTE)freqMhz, &size); - + RegCloseKey(hKey); if(ret != ERROR_SUCCESS) @@ -52,6 +43,15 @@ double cpu_ClockFrequency() } +uint cpu_NumProcessors() +{ + SYSTEM_INFO si; + GetSystemInfo(&si); // can't fail + const uint numProcessors = (uint)si.dwNumberOfProcessors; + return numProcessors; +} + + size_t cpu_PageSize() { SYSTEM_INFO si; @@ -90,16 +90,6 @@ size_t cpu_MemorySize(CpuMemoryIndicators mem_type) } -//----------------------------------------------------------------------------- - -// 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. -// note: implemented by switching thread affinity masks and forcing -// a reschedule, which is apparently not possible with POSIX. -// -// may fail if e.g. OS is preventing us from running on some CPUs. -// called from ia32.cpp get_cpu_count. LibError cpu_CallByEachCPU(CpuCallback cb, void* param) { const HANDLE hProcess = GetCurrentProcess();