Commit 165702af authored by Leif Walsh's avatar Leif Walsh Committed by Yoni Fogel

refs #5368 add portability wrapper for sched_setaffinity/sched_getaffinity

git-svn-id: file:///svn/toku/tokudb@48692 c7de825b-a66e-492c-adef-691d508d4ae1
parent e9225704
...@@ -58,6 +58,7 @@ check_function_exists(malloc_usable_size HAVE_MALLOC_USABLE_SIZE) ...@@ -58,6 +58,7 @@ check_function_exists(malloc_usable_size HAVE_MALLOC_USABLE_SIZE)
check_function_exists(memalign HAVE_MEMALIGN) check_function_exists(memalign HAVE_MEMALIGN)
check_function_exists(valloc HAVE_VALLOC) check_function_exists(valloc HAVE_VALLOC)
## check whether we can pin processes to cpus ## check whether we can pin processes to cpus
check_function_exists(cpuset_getaffinity HAVE_CPUSET_GETAFFINITY)
check_function_exists(sched_getaffinity HAVE_SCHED_GETAFFINITY) check_function_exists(sched_getaffinity HAVE_SCHED_GETAFFINITY)
## check whether we have random_r or nrand48 to use as a reentrant random function ## check whether we have random_r or nrand48 to use as a reentrant random function
check_function_exists(nrand48 HAVE_NRAND48) check_function_exists(nrand48 HAVE_NRAND48)
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <unistd.h> #include <unistd.h>
#include <pthread.h> #include <pthread.h>
#include "threadpool.h" #include "threadpool.h"
#include "toku_affinity.h"
int verbose = 0; int verbose = 0;
...@@ -74,27 +75,21 @@ int main(int argc, char *argv[]) { ...@@ -74,27 +75,21 @@ int main(int argc, char *argv[]) {
} }
int starti = i; int starti = i;
#if defined(HAVE_SCHED_GETAFFINITY)
if (ncpus > 0) { if (ncpus > 0) {
cpu_set_t cpuset; toku_cpuset_t cpuset;
CPU_ZERO(&cpuset); TOKU_CPU_ZERO(&cpuset);
for (i = 0; i < ncpus; i++) for (i = 0; i < ncpus; i++)
CPU_SET(i, &cpuset); TOKU_CPU_SET(i, &cpuset);
int r; int r;
r = sched_setaffinity(getpid(), sizeof cpuset, &cpuset); r = toku_setaffinity(getpid(), sizeof cpuset, &cpuset);
assert(r == 0); assert(r == 0);
cpu_set_t use_cpuset; toku_cpuset_t use_cpuset;
CPU_ZERO(&use_cpuset); TOKU_CPU_ZERO(&use_cpuset);
r = sched_getaffinity(getpid(), sizeof use_cpuset, &use_cpuset); r = toku_getaffinity(getpid(), sizeof use_cpuset, &use_cpuset);
assert(r == 0); assert(r == 0);
assert(memcmp(&cpuset, &use_cpuset, sizeof cpuset) == 0); assert(memcmp(&cpuset, &use_cpuset, sizeof cpuset) == 0);
} }
#else
/* currently disabled for systems that don't have
* sched_setaffinity/sched_getaffinity (darwin)
*/
#endif
if (starti == argc) { if (starti == argc) {
dotest(poolsize, nloops); dotest(poolsize, nloops);
......
...@@ -6,6 +6,7 @@ set(tokuportability_srcs ...@@ -6,6 +6,7 @@ set(tokuportability_srcs
os_malloc os_malloc
partitioned_counter partitioned_counter
portability portability
toku_affinity
toku_assert toku_assert
toku_pthread toku_pthread
toku_fair_rwlock toku_fair_rwlock
...@@ -18,11 +19,6 @@ set_property(TARGET ${LIBTOKUPORTABILITY} ${LIBTOKUPORTABILITY}_static APPEND PR ...@@ -18,11 +19,6 @@ set_property(TARGET ${LIBTOKUPORTABILITY} ${LIBTOKUPORTABILITY}_static APPEND PR
set_target_properties(${LIBTOKUPORTABILITY}_static PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(${LIBTOKUPORTABILITY}_static PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(${LIBTOKUPORTABILITY} LINK_PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${EXTRA_SYSTEM_LIBS}) target_link_libraries(${LIBTOKUPORTABILITY} LINK_PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${EXTRA_SYSTEM_LIBS})
if (CMAKE_CXX_COMPILER_ID STREQUAL Intel)
## ignore warning about cilkrts linking dynamically
add_space_separated_property(TARGET ${LIBTOKUPORTABILITY} LINK_FLAGS "-diag-disable 10237")
endif ()
set_property(SOURCE file memory os_malloc portability toku_assert toku_rwlock APPEND PROPERTY set_property(SOURCE file memory os_malloc portability toku_assert toku_rwlock APPEND PROPERTY
COMPILE_DEFINITIONS TOKU_ALLOW_DEPRECATED=1) COMPILE_DEFINITIONS TOKU_ALLOW_DEPRECATED=1)
......
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "Copyright (c) 2012 Tokutek Inc. All rights reserved."
#ident "$Id$"
#include <config.h>
#include "toku_affinity.h"
#if defined(HAVE_SCHED_GETAFFINITY)
int toku_getaffinity(pid_t pid, size_t cpusetsize, toku_cpuset_t *cpusetp) {
return sched_getaffinity(pid, cpusetsize, cpusetp);
}
int toku_setaffinity(pid_t pid, size_t cpusetsize, const toku_cpuset_t *cpusetp) {
return sched_setaffinity(pid, cpusetsize, cpusetp);
}
#elif defined(HAVE_CPUSET_GETAFFINITY)
int toku_getaffinity(pid_t pid, size_t cpusetsize, toku_cpuset_t *cpusetp) {
return cpuset_getaffinity(CPU_LEVEL_CPUSET, CPU_WHICH_PID, pid, cpusetsize, cpusetp);
}
int toku_setaffinity(pid_t pid, size_t cpusetsize, const toku_cpuset_t *cpusetp) {
return cpuset_setaffinity(CPU_LEVEL_CPUSET, CPU_WHICH_PID, pid, cpusetsize, cpusetp);
}
#else
// dummy implementation to get rid of unused warnings etc
int toku_getaffinity(pid_t pid __attribute__((unused)),
size_t cpusetsize __attribute__((unused)),
toku_cpuset_t *cpusetp) {
TOKU_CPU_ZERO(cpusetp);
return 0;
}
int toku_setaffinity(pid_t pid __attribute__((unused)),
size_t cpusetsize __attribute__((unused)),
const toku_cpuset_t *cpusetp __attribute__((unused))) {
return 0;
}
#endif
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "Copyright (c) 2012 Tokutek Inc. All rights reserved."
#ident "$Id$"
#ifndef TOKU_AFFINITY_H
#define TOKU_AFFINITY_H
#include <config.h>
#include <stddef.h>
#include <sys/types.h>
#if defined(HAVE_SCHED_GETAFFINITY)
# include <sched.h>
typedef cpu_set_t toku_cpuset_t;
# define TOKU_CPU_ZERO(p) CPU_ZERO(p)
# define TOKU_CPU_SET(n, p) CPU_SET(n, p)
#elif defined(HAVE_CPUSET_GETAFFINITY)
# include <sys/param.h>
# include <sys/cpuset.h>
typedef cpuset_t toku_cpuset_t;
# define TOKU_CPU_ZERO(p) CPU_ZERO(p)
# define TOKU_CPU_SET(n, p) CPU_SET(n, p)
#else
// dummy implementation to get rid of unused warnings etc
typedef int toku_cpuset_t;
# define TOKU_CPU_ZERO(p) (*p = 0)
# define TOKU_CPU_SET(n, p) ((void) (n, p))
#endif
// see sched_getaffinity(2)
int toku_getaffinity(pid_t pid, size_t cpusetsize, toku_cpuset_t *cpusetp);
// see sched_setaffinity(2)
int toku_setaffinity(pid_t pid, size_t cpusetsize, const toku_cpuset_t *cpusetp);
#endif // TOKU_AFFINITY_H
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "toku_pthread.h" #include "toku_pthread.h"
#include <db.h> #include <db.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "toku_affinity.h"
#include "key-val.h" #include "key-val.h"
enum {NUM_INDEXER_INDEXES=1}; enum {NUM_INDEXER_INDEXES=1};
...@@ -238,27 +239,22 @@ do_args (int argc, char * const argv[]) { ...@@ -238,27 +239,22 @@ do_args (int argc, char * const argv[]) {
argc--; argv++; argc--; argv++;
} }
#if defined(HAVE_SCHED_GETAFFINITY)
if (num_cpus > 0) { if (num_cpus > 0) {
cpu_set_t cpuset; toku_cpuset_t cpuset;
CPU_ZERO(&cpuset); TOKU_CPU_ZERO(&cpuset);
for (int i = 0; i < num_cpus; i++) for (int i = 0; i < num_cpus; i++) {
CPU_SET(i, &cpuset); TOKU_CPU_SET(i, &cpuset);
}
int r; int r;
r = sched_setaffinity(toku_os_getpid(), sizeof cpuset, &cpuset); r = toku_setaffinity(toku_os_getpid(), sizeof cpuset, &cpuset);
assert(r == 0); assert(r == 0);
cpu_set_t use_cpuset; toku_cpuset_t use_cpuset;
CPU_ZERO(&use_cpuset); TOKU_CPU_ZERO(&use_cpuset);
r = sched_getaffinity(toku_os_getpid(), sizeof use_cpuset, &use_cpuset); r = toku_getaffinity(toku_os_getpid(), sizeof use_cpuset, &use_cpuset);
assert(r == 0); assert(r == 0);
assert(memcmp(&cpuset, &use_cpuset, sizeof cpuset) == 0); assert(memcmp(&cpuset, &use_cpuset, sizeof cpuset) == 0);
} }
#else
/* not implemented unless we have sched_getaffinity/sched_setaffinity, for
* example, on darwin. sort of a todo.
*/
#endif
} }
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#cmakedefine HAVE_MALLOC_USABLE_SIZE 1 #cmakedefine HAVE_MALLOC_USABLE_SIZE 1
#cmakedefine HAVE_MEMALIGN 1 #cmakedefine HAVE_MEMALIGN 1
#cmakedefine HAVE_VALLOC 1 #cmakedefine HAVE_VALLOC 1
#cmakedefine HAVE_CPUSET_GETAFFINITY 1
#cmakedefine HAVE_SCHED_GETAFFINITY 1 #cmakedefine HAVE_SCHED_GETAFFINITY 1
#cmakedefine HAVE_NRAND48 1 #cmakedefine HAVE_NRAND48 1
#cmakedefine HAVE_RANDOM_R 1 #cmakedefine HAVE_RANDOM_R 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment