22 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
23 TEXT(
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"),
24 0, KEY_READ, &key) != ERROR_SUCCESS)
27 if (RegQueryValueEx(key, TEXT(
"~MHz"),
NULL,
NULL, (LPBYTE)&
result,
28 (LPDWORD)&
size) != ERROR_SUCCESS) {
40 #include <sys/sysctl.h>
41 #include <sys/types.h>
49 if (sysctlbyname(
"hw.cpufrequency", &
result, &
size,
NULL, 0))
return -1;
50 return (
int)(
result / (
long long)1000000);
67 f = fopen(
"/proc/cpuinfo",
"rt");
70 while (fgets(line,
sizeof(line), f)) {
71 if (!strncmp(line,
"cpu MHz", 7)) {
72 s = strchr(line,
':');
73 if (s && 1 == sscanf(s,
":%d.", &
result)) {
90 #include <mach/clock.h>
91 #include <mach/clock_types.h>
92 #include <mach/mach.h>
99 host_basic_info_data_t basic_info;
100 host_info_t info = (host_info_t)&basic_info;
101 host_flavor_t flavor = HOST_BASIC_INFO;
102 mach_msg_type_number_t
count = HOST_BASIC_INFO_COUNT;
103 kr = host_info(mach_host_self(), flavor, info, &
count);
104 if (kr != KERN_SUCCESS)
return 1;
105 return basic_info.avail_cpus;
109 #define GET_TOTAL_CPUS_DEFINED
118 SYSTEM_INFO system_info;
119 GetSystemInfo(&system_info);
120 return system_info.dwNumberOfProcessors;
124 #define GET_TOTAL_CPUS_DEFINED
128 #include <sys/sysinfo.h>
136 #define GET_TOTAL_CPUS_DEFINED
139 #if defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || \
140 defined __bsdi__ || defined __QNX__
141 #include <sys/sysctl.h>
142 #include <sys/types.h>
147 int mib[2] = {CTL_HW, HW_NCPU};
149 size_t len =
sizeof(ncpus);
150 if (sysctl(mib, 2, &ncpus, &len, (
void *)0, 0) != 0)
return 1;
155 #define GET_TOTAL_CPUS_DEFINED
158 #ifndef GET_TOTAL_CPUS_DEFINED
int get_total_cpus()
Returns the total number of CPUs.
int cpu_clock_by_os()
Returns the CPU clock, as reported by the OS.
Generic file read and write utility for python interface.