25
25
#include < sys/time.h>
26
26
#include < sys/types.h> // this header must be included before 'sys/sysctl.h' to avoid compilation error on FreeBSD
27
27
#include < unistd.h>
28
- #if defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_MACOSX
28
+ #if defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_MACOSX || defined BENCHMARK_OS_NETBSD
29
29
#include < sys/sysctl.h>
30
30
#endif
31
31
#endif
@@ -230,7 +230,9 @@ void InitializeSystemInfo() {
230
230
cpuinfo_num_cpus = num_cpus;
231
231
}
232
232
233
- #elif defined BENCHMARK_OS_FREEBSD
233
+ #elif defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_NETBSD
234
+ // FreeBSD notes
235
+ // =============
234
236
// For this sysctl to work, the machine must be configured without
235
237
// SMP, APIC, or APM support. hz should be 64-bit in freebsd 7.0
236
238
// and later. Before that, it's a 32-bit quantity (and gives the
@@ -242,7 +244,7 @@ void InitializeSystemInfo() {
242
244
// To FreeBSD 6.3 (it's the same in 6-STABLE):
243
245
// http://fxr.watson.org/fxr/source/i386/i386/tsc.c?v=RELENG6#L131
244
246
// 139 error = sysctl_handle_int(oidp, &freq, sizeof(freq), req);
245
- #if __FreeBSD__ >= 7
247
+ #if ( __FreeBSD__ >= 7) || defined(__NetBSD__)
246
248
uint64_t hz = 0 ;
247
249
#else
248
250
unsigned int hz = 0 ;
@@ -256,8 +258,16 @@ void InitializeSystemInfo() {
256
258
} else {
257
259
cpuinfo_cycles_per_second = hz;
258
260
}
259
- // TODO: also figure out cpuinfo_num_cpus
260
261
262
+ int32_t num_cpus = 0 ;
263
+ size_t size = sizeof (num_cpus);
264
+ if (::sysctlbyname (" hw.ncpu" , &num_cpus, &size, nullptr , 0 ) == 0 &&
265
+ (size == sizeof (num_cpus))) {
266
+ cpuinfo_num_cpus = num_cpus;
267
+ } else {
268
+ fprintf (stderr, " %s\n " , strerror (errno));
269
+ std::exit (EXIT_FAILURE);
270
+ }
261
271
#elif defined BENCHMARK_OS_WINDOWS
262
272
// In NT, read MHz from the registry. If we fail to do so or we're in win9x
263
273
// then make a crude estimate.
0 commit comments