Skip to content

Commit bf9d2f1

Browse files
committed
[test-suite] Fix NetBSD support in benchmark 1.3.0
Fixed by backporting the upstream fix from here: google/benchmark#482 llvm-svn: 349272
1 parent 7027018 commit bf9d2f1

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

MicroBenchmarks/libs/benchmark-1.3.0/src/internal_macros.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#endif
4040
#elif defined(__FreeBSD__)
4141
#define BENCHMARK_OS_FREEBSD 1
42+
#elif defined(__NetBSD__)
43+
#define BENCHMARK_OS_NETBSD 1
4244
#elif defined(__linux__)
4345
#define BENCHMARK_OS_LINUX 1
4446
#elif defined(__native_client__)

MicroBenchmarks/libs/benchmark-1.3.0/src/sysinfo.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <sys/time.h>
2626
#include <sys/types.h> // this header must be included before 'sys/sysctl.h' to avoid compilation error on FreeBSD
2727
#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
2929
#include <sys/sysctl.h>
3030
#endif
3131
#endif
@@ -230,7 +230,9 @@ void InitializeSystemInfo() {
230230
cpuinfo_num_cpus = num_cpus;
231231
}
232232

233-
#elif defined BENCHMARK_OS_FREEBSD
233+
#elif defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_NETBSD
234+
// FreeBSD notes
235+
// =============
234236
// For this sysctl to work, the machine must be configured without
235237
// SMP, APIC, or APM support. hz should be 64-bit in freebsd 7.0
236238
// and later. Before that, it's a 32-bit quantity (and gives the
@@ -242,7 +244,7 @@ void InitializeSystemInfo() {
242244
// To FreeBSD 6.3 (it's the same in 6-STABLE):
243245
// http://fxr.watson.org/fxr/source/i386/i386/tsc.c?v=RELENG6#L131
244246
// 139 error = sysctl_handle_int(oidp, &freq, sizeof(freq), req);
245-
#if __FreeBSD__ >= 7
247+
#if (__FreeBSD__ >= 7) || defined(__NetBSD__)
246248
uint64_t hz = 0;
247249
#else
248250
unsigned int hz = 0;
@@ -256,8 +258,16 @@ void InitializeSystemInfo() {
256258
} else {
257259
cpuinfo_cycles_per_second = hz;
258260
}
259-
// TODO: also figure out cpuinfo_num_cpus
260261

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+
}
261271
#elif defined BENCHMARK_OS_WINDOWS
262272
// In NT, read MHz from the registry. If we fail to do so or we're in win9x
263273
// then make a crude estimate.

0 commit comments

Comments
 (0)