Determine CPU speed on FreeBSD

This commit is contained in:
Yamagi Burmeister 2016-04-13 19:24:51 +02:00
parent b299789db5
commit 0e672b866e

View File

@ -37,6 +37,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#if PLATFORM_FREEBSD
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
// Read the Pentium TimeStampCounter (or something like that). // Read the Pentium TimeStampCounter (or something like that).
static inline __int64 ReadTSC(void) static inline __int64 ReadTSC(void)
{ {
@ -340,6 +345,13 @@ CTimer::CTimer(BOOL bInterrupt /*=TRUE*/)
#elif PLATFORM_MACOSX #elif PLATFORM_MACOSX
tm_llPerformanceCounterFrequency = tm_llCPUSpeedHZ = ((__int64) GetCPUSpeed()) * 1000000; tm_llPerformanceCounterFrequency = tm_llCPUSpeedHZ = ((__int64) GetCPUSpeed()) * 1000000;
#elif PLATFORM_FREEBSD
__int64 mhz = 0;
size_t len = sizeof(mhz);
sysctlbyname("hw.clockrate", &mhz, &len, NULL, 0);
tm_llPerformanceCounterFrequency = tm_llCPUSpeedHZ = (__int64) (mhz * 1000000);
#else #else
// !!! FIXME : This is an ugly hack. // !!! FIXME : This is an ugly hack.
double mhz = 0.0; double mhz = 0.0;