]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
test for pthread_setaffinity_np
authorMatthew Barr <matthew.barr@intel.com>
Fri, 12 May 2017 01:29:58 +0000 (11:29 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 30 May 2017 04:00:30 +0000 (14:00 +1000)
Only enable setting threads per core when available

cmake/config.h.in
tools/hsbench/CMakeLists.txt
tools/hsbench/main.cpp

index 5434668e52bec90c921c88dce1d72e4a122315bc..62029cb9764566389c7501b8ab190f10ec96b265 100644 (file)
@@ -46,6 +46,8 @@
    0 if you don't. */
 #cmakedefine HAVE_DECL_PTHREAD_SETAFFINITY_NP
 
+#cmakedefine HAVE_PTHREAD_NP_H
+
 /* Define to 1 if you have the `malloc_info' function. */
 #cmakedefine HAVE_MALLOC_INFO
 
index 3b9a73f735d8d84cebf6949651e1a249c8d93c37..8f718ee3dd976fba2643d7023df4437834d0340a 100644 (file)
@@ -11,6 +11,18 @@ else()
     set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -isystem ${SQLITE3_INCLUDE_DIRS}")
 endif()
 
+# BSD has the _np funcs in a _np header
+CHECK_INCLUDE_FILE(pthread_np.h HAVE_PTHREAD_NP_H)
+if (HAVE_PTHREAD_NP_H)
+    set (PTHREAD_NP_INC pthread_np.h)
+else ()
+    set (PTHREAD_NP_INC pthread.h)
+endif ()
+
+set (CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_GNU_SOURCE")
+set (CMAKE_REQUIRED_LIBRARIES pthread)
+CHECK_CXX_SYMBOL_EXISTS(pthread_setaffinity_np ${PTHREAD_NP_INC} HAVE_DECL_PTHREAD_SETAFFINITY_NP)
+
 CHECK_FUNCTION_EXISTS(malloc_info HAVE_MALLOC_INFO)
 CHECK_FUNCTION_EXISTS(shmget HAVE_SHMGET)
 set(HAVE_SHMGET ${HAVE_SHMGET} CACHE BOOL "shmget()")
index b5506af3d9585ad0d9c976c63cb4ab5a5d16c5f1..3153737eec15fd1d566dc24527b4269b71225279 100644 (file)
@@ -56,6 +56,9 @@
 #include <getopt.h>
 #ifndef _WIN32
 #include <pthread.h>
+#if defined(HAVE_PTHREAD_NP_H)
+#include <pthread_np.h>
+#endif
 #include <unistd.h>
 #endif
 
@@ -122,7 +125,11 @@ public:
     // Apply processor affinity (if available) to this thread.
     bool affine(UNUSED int cpu) {
 #ifdef HAVE_DECL_PTHREAD_SETAFFINITY_NP
+#if defined(__linux__)
         cpu_set_t cpuset;
+#else // BSD
+        cpuset_t cpuset;
+#endif
         CPU_ZERO(&cpuset);
         assert(cpu >= 0 && cpu < CPU_SETSIZE);
 
@@ -166,7 +173,9 @@ void usage(const char *error) {
            " (default: streaming).\n");
     printf("  -V              Benchmark in vectored mode"
            " (default: streaming).\n");
+#ifdef HAVE_DECL_PTHREAD_SETAFFINITY_NP
     printf("  -T CPU,CPU,...  Benchmark with threads on these CPUs.\n");
+#endif
     printf("  -i DIR          Don't compile, load from files in DIR"
            " instead.\n");
     printf("  -w DIR          After compiling, save to files in DIR.\n");
@@ -195,7 +204,11 @@ struct BenchmarkSigs {
 static
 void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets,
                  UNUSED unique_ptr<Grey> &grey) {
-    const char options[] = "-b:c:Cd:e:E:G:hi:n:No:p:sT:Vw:z:";
+    const char options[] = "-b:c:Cd:e:E:G:hi:n:No:p:sVw:z:"
+#if HAVE_DECL_PTHREAD_SETAFFINITY_N
+        "T:" // add the thread flag
+#endif
+        ;
     int in_sigfile = 0;
     int do_per_scan = 0;
     int do_echo_matches = 0;