mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
test for pthread_setaffinity_np
Only enable setting threads per core when available
This commit is contained in:
parent
4976f019f4
commit
b0a5bd8940
@ -46,6 +46,8 @@
|
|||||||
0 if you don't. */
|
0 if you don't. */
|
||||||
#cmakedefine HAVE_DECL_PTHREAD_SETAFFINITY_NP
|
#cmakedefine HAVE_DECL_PTHREAD_SETAFFINITY_NP
|
||||||
|
|
||||||
|
#cmakedefine HAVE_PTHREAD_NP_H
|
||||||
|
|
||||||
/* Define to 1 if you have the `malloc_info' function. */
|
/* Define to 1 if you have the `malloc_info' function. */
|
||||||
#cmakedefine HAVE_MALLOC_INFO
|
#cmakedefine HAVE_MALLOC_INFO
|
||||||
|
|
||||||
|
@ -11,6 +11,18 @@ else()
|
|||||||
set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -isystem ${SQLITE3_INCLUDE_DIRS}")
|
set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -isystem ${SQLITE3_INCLUDE_DIRS}")
|
||||||
endif()
|
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(malloc_info HAVE_MALLOC_INFO)
|
||||||
CHECK_FUNCTION_EXISTS(shmget HAVE_SHMGET)
|
CHECK_FUNCTION_EXISTS(shmget HAVE_SHMGET)
|
||||||
set(HAVE_SHMGET ${HAVE_SHMGET} CACHE BOOL "shmget()")
|
set(HAVE_SHMGET ${HAVE_SHMGET} CACHE BOOL "shmget()")
|
||||||
|
@ -56,6 +56,9 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#if defined(HAVE_PTHREAD_NP_H)
|
||||||
|
#include <pthread_np.h>
|
||||||
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -122,7 +125,11 @@ public:
|
|||||||
// Apply processor affinity (if available) to this thread.
|
// Apply processor affinity (if available) to this thread.
|
||||||
bool affine(UNUSED int cpu) {
|
bool affine(UNUSED int cpu) {
|
||||||
#ifdef HAVE_DECL_PTHREAD_SETAFFINITY_NP
|
#ifdef HAVE_DECL_PTHREAD_SETAFFINITY_NP
|
||||||
|
#if defined(__linux__)
|
||||||
cpu_set_t cpuset;
|
cpu_set_t cpuset;
|
||||||
|
#else // BSD
|
||||||
|
cpuset_t cpuset;
|
||||||
|
#endif
|
||||||
CPU_ZERO(&cpuset);
|
CPU_ZERO(&cpuset);
|
||||||
assert(cpu >= 0 && cpu < CPU_SETSIZE);
|
assert(cpu >= 0 && cpu < CPU_SETSIZE);
|
||||||
|
|
||||||
@ -166,7 +173,9 @@ void usage(const char *error) {
|
|||||||
" (default: streaming).\n");
|
" (default: streaming).\n");
|
||||||
printf(" -V Benchmark in vectored mode"
|
printf(" -V Benchmark in vectored mode"
|
||||||
" (default: streaming).\n");
|
" (default: streaming).\n");
|
||||||
|
#ifdef HAVE_DECL_PTHREAD_SETAFFINITY_NP
|
||||||
printf(" -T CPU,CPU,... Benchmark with threads on these CPUs.\n");
|
printf(" -T CPU,CPU,... Benchmark with threads on these CPUs.\n");
|
||||||
|
#endif
|
||||||
printf(" -i DIR Don't compile, load from files in DIR"
|
printf(" -i DIR Don't compile, load from files in DIR"
|
||||||
" instead.\n");
|
" instead.\n");
|
||||||
printf(" -w DIR After compiling, save to files in DIR.\n");
|
printf(" -w DIR After compiling, save to files in DIR.\n");
|
||||||
@ -195,7 +204,11 @@ struct BenchmarkSigs {
|
|||||||
static
|
static
|
||||||
void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets,
|
void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets,
|
||||||
UNUSED unique_ptr<Grey> &grey) {
|
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 in_sigfile = 0;
|
||||||
int do_per_scan = 0;
|
int do_per_scan = 0;
|
||||||
int do_echo_matches = 0;
|
int do_echo_matches = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user