google-benchmark: Add NetBSD bits

Sponsored by <The NetBSD Foundation>
This commit is contained in:
Kamil Rytarowski 2017-11-17 02:13:30 +01:00
parent 23ac180642
commit e986307924
4 changed files with 80 additions and 0 deletions

View File

@ -4,3 +4,6 @@ SHA1 (benchmark-1.3.0.tar.gz) = ea74b9d99327f7ef8150dc7c683e6155fa29ef3c
RMD160 (benchmark-1.3.0.tar.gz) = 456d2d6125d77cbf847764a45eedca53c315aea6
SHA512 (benchmark-1.3.0.tar.gz) = 272775e4dbd0ecc65a2a3a64f24e79682b630929dea3af47349329ac8b796341f1197458a67c9aac0e514857ebe7cbc191d18f6fd2c0aea3242562e69d8a6849
Size (benchmark-1.3.0.tar.gz) = 105485 bytes
SHA1 (patch-src_internal__macros.h) = 3076cd5dab9399a536e76ba53c9cc247150b8300
SHA1 (patch-src_sysinfo.cc) = 289548f2aceb1afdc7dcba7fc6aed5e75c3ce330
SHA1 (patch-src_timers.cc) = a709bba78c097132c6331c436f02a4d059e747eb

View File

@ -0,0 +1,13 @@
$NetBSD$
--- src/internal_macros.h.orig 2017-11-03 17:00:29.000000000 +0000
+++ 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__)

View File

@ -0,0 +1,51 @@
$NetBSD$
--- src/sysinfo.cc.orig 2017-11-03 17:00:29.000000000 +0000
+++ 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.

View File

@ -0,0 +1,13 @@
$NetBSD$
--- src/timers.cc.orig 2017-11-03 17:00:29.000000000 +0000
+++ src/timers.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
#if defined(BENCHMARK_OS_MACOSX)