From 1fe1729a1fb334480b120f686700cb79a370563d Mon Sep 17 00:00:00 2001 From: Veselin Georgiev Date: Thu, 8 Jan 2009 16:38:39 +0000 Subject: [PATCH] Added CPU clock OS detection routine for Mac OS X git-svn-id: https://svn.code.sf.net/p/libcpuid/code/HEAD/libcpuid@48 3b4be424-7ac5-41d7-8526-f4ddcb85d872 --- libcpuid/rdtsc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libcpuid/rdtsc.c b/libcpuid/rdtsc.c index 6f0bd0e..2819a8e 100644 --- a/libcpuid/rdtsc.c +++ b/libcpuid/rdtsc.c @@ -107,6 +107,19 @@ int cpu_clock_by_os(void) return (int)result; } #else +#ifdef __APPLE__ +#include +#include +/* Assuming Mac OS X with hw.cpufrequency sysctl */ +int cpu_clock_by_os(void) +{ + long long result = -1; + size_t size = sizeof(result); + if (sysctlbyname("hw.cpufrequency", &result, &size, NULL, 0)) + return -1; + return (int) (result / (long long) 1000000); +} +#else /* Assuming Linux with /proc/cpuinfo */ int cpu_clock_by_os(void) { @@ -129,6 +142,7 @@ int cpu_clock_by_os(void) fclose(f); return -1; } +#endif /* __APPLE__ */ #endif /* _WIN32 */ /* Emulate doing useful CPU intensive work */