[test-suite] r349272 - [test-suite] Fix NetBSD support in benchmark 1.3.0

Kamil Rytarowski via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 15 06:39:07 PST 2018


Author: kamil
Date: Sat Dec 15 06:39:07 2018
New Revision: 349272

URL: http://llvm.org/viewvc/llvm-project?rev=349272&view=rev
Log:
[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

Modified:
    test-suite/trunk/MicroBenchmarks/libs/benchmark-1.3.0/src/internal_macros.h
    test-suite/trunk/MicroBenchmarks/libs/benchmark-1.3.0/src/sysinfo.cc

Modified: test-suite/trunk/MicroBenchmarks/libs/benchmark-1.3.0/src/internal_macros.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MicroBenchmarks/libs/benchmark-1.3.0/src/internal_macros.h?rev=349272&r1=349271&r2=349272&view=diff
==============================================================================
--- test-suite/trunk/MicroBenchmarks/libs/benchmark-1.3.0/src/internal_macros.h (original)
+++ test-suite/trunk/MicroBenchmarks/libs/benchmark-1.3.0/src/internal_macros.h Sat Dec 15 06:39:07 2018
@@ -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__)

Modified: test-suite/trunk/MicroBenchmarks/libs/benchmark-1.3.0/src/sysinfo.cc
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MicroBenchmarks/libs/benchmark-1.3.0/src/sysinfo.cc?rev=349272&r1=349271&r2=349272&view=diff
==============================================================================
--- test-suite/trunk/MicroBenchmarks/libs/benchmark-1.3.0/src/sysinfo.cc (original)
+++ test-suite/trunk/MicroBenchmarks/libs/benchmark-1.3.0/src/sysinfo.cc Sat Dec 15 06:39:07 2018
@@ -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.




More information about the llvm-commits mailing list