aboutsummaryrefslogtreecommitdiff
path: root/MicroBenchmarks
diff options
context:
space:
mode:
authorKamil Rytarowski <n54@gmx.com>2018-12-15 14:39:07 +0000
committerKamil Rytarowski <n54@gmx.com>2018-12-15 14:39:07 +0000
commit8a788e323b39d2768b9f107b081eb57293863524 (patch)
treea15e67ed11570348c068558fbb0ebf1c10d536cc /MicroBenchmarks
parent5ff3a8503dfbcf386947cace46645963fb9989ef (diff)
[test-suite] Fix NetBSD support in benchmark 1.3.0
Fixed by backporting the upstream fix from here: https://github.com/google/benchmark/pull/482 git-svn-id: https://llvm.org/svn/llvm-project/test-suite/trunk@349272 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'MicroBenchmarks')
-rw-r--r--MicroBenchmarks/libs/benchmark-1.3.0/src/internal_macros.h2
-rw-r--r--MicroBenchmarks/libs/benchmark-1.3.0/src/sysinfo.cc18
2 files changed, 16 insertions, 4 deletions
diff --git a/MicroBenchmarks/libs/benchmark-1.3.0/src/internal_macros.h b/MicroBenchmarks/libs/benchmark-1.3.0/src/internal_macros.h
index 94288745..b59261ca 100644
--- a/MicroBenchmarks/libs/benchmark-1.3.0/src/internal_macros.h
+++ b/MicroBenchmarks/libs/benchmark-1.3.0/src/internal_macros.h
@@ -39,6 +39,8 @@
#endif
#elif defined(__FreeBSD__)
#define BENCHMARK_OS_FREEBSD 1
+#elif defined(__NetBSD__)
+#define BENCHMARK_OS_NETBSD 1
#elif defined(__linux__)
#define BENCHMARK_OS_LINUX 1
#elif defined(__native_client__)
diff --git a/MicroBenchmarks/libs/benchmark-1.3.0/src/sysinfo.cc b/MicroBenchmarks/libs/benchmark-1.3.0/src/sysinfo.cc
index 7feb79e6..7997605f 100644
--- a/MicroBenchmarks/libs/benchmark-1.3.0/src/sysinfo.cc
+++ b/MicroBenchmarks/libs/benchmark-1.3.0/src/sysinfo.cc
@@ -25,7 +25,7 @@
#include <sys/time.h>
#include <sys/types.h> // this header must be included before 'sys/sysctl.h' to avoid compilation error on FreeBSD
#include <unistd.h>
-#if defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_MACOSX
+#if defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_MACOSX || defined BENCHMARK_OS_NETBSD
#include <sys/sysctl.h>
#endif
#endif
@@ -230,7 +230,9 @@ void InitializeSystemInfo() {
cpuinfo_num_cpus = num_cpus;
}
-#elif defined BENCHMARK_OS_FREEBSD
+#elif defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_NETBSD
+// FreeBSD notes
+// =============
// For this sysctl to work, the machine must be configured without
// SMP, APIC, or APM support. hz should be 64-bit in freebsd 7.0
// and later. Before that, it's a 32-bit quantity (and gives the
@@ -242,7 +244,7 @@ void InitializeSystemInfo() {
// To FreeBSD 6.3 (it's the same in 6-STABLE):
// http://fxr.watson.org/fxr/source/i386/i386/tsc.c?v=RELENG6#L131
// 139 error = sysctl_handle_int(oidp, &freq, sizeof(freq), req);
-#if __FreeBSD__ >= 7
+#if (__FreeBSD__ >= 7) || defined(__NetBSD__)
uint64_t hz = 0;
#else
unsigned int hz = 0;
@@ -256,8 +258,16 @@ void InitializeSystemInfo() {
} else {
cpuinfo_cycles_per_second = hz;
}
-// TODO: also figure out cpuinfo_num_cpus
+ int32_t num_cpus = 0;
+ size_t size = sizeof(num_cpus);
+ if (::sysctlbyname("hw.ncpu", &num_cpus, &size, nullptr, 0) == 0 &&
+ (size == sizeof(num_cpus))) {
+ cpuinfo_num_cpus = num_cpus;
+ } else {
+ fprintf(stderr, "%s\n", strerror(errno));
+ std::exit(EXIT_FAILURE);
+ }
#elif defined BENCHMARK_OS_WINDOWS
// In NT, read MHz from the registry. If we fail to do so or we're in win9x
// then make a crude estimate.