hopefully bring linux and MacOS X into line with the newly refactored sysdep interface.

This was SVN commit r5367.
This commit is contained in:
janwas 2007-09-23 16:15:46 +00:00
parent ea791fc6ef
commit 3f9b020169
8 changed files with 53 additions and 110 deletions

View File

@ -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);

View File

@ -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);

View File

@ -1,16 +1,19 @@
#include "precompiled.h"
#include "ocpu.h"
#include "../cpu.h"
#include <sys/sysctl.h>
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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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"

View File

@ -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();