]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
isc_thread_setaffinity()
authorWitold Krecicki <wpk@isc.org>
Wed, 3 Oct 2018 21:20:22 +0000 (23:20 +0200)
committerWitold Kręcicki <wpk@isc.org>
Wed, 24 Oct 2018 07:06:57 +0000 (07:06 +0000)
config.h.in
configure
configure.ac
lib/isc/pthreads/include/isc/thread.h
lib/isc/pthreads/thread.c
lib/isc/win32/include/isc/thread.h
lib/isc/win32/libisc.def.in
lib/isc/win32/thread.c

index 75fbd002e795b9e3655e350623b995baf7399194..f377a42cedcb1988197151a55cdc282f30114c0e 100644 (file)
@@ -72,6 +72,9 @@
 /* Define to 1 if you have the <cmocka.h> header file. */
 #undef HAVE_CMOCKA_H
 
+/* Define to 1 if you have the `cpuset_setaffinty' function. */
+#undef HAVE_CPUSET_SETAFFINITY
+
 /* Define to 1 if you have the <devpoll.h> header file. */
 #undef HAVE_DEVPOLL_H
 
 /* define if OpenSSL supports Ed25519 */
 #undef HAVE_OPENSSL_ED25519
 
+/* Define to 1 if you have the `processor_bind' function. */
+#undef HAVE_PROCESSOR_BIND
+
 /* Define if you have POSIX threads libraries and header files. */
 #undef HAVE_PTHREAD
 
 /* Have PTHREAD_PRIO_INHERIT. */
 #undef HAVE_PTHREAD_PRIO_INHERIT
 
+/* Define to 1 if you have the `pthread_setaffinity_np' function. */
+#undef HAVE_PTHREAD_SETAFFINITY_NP
+
 /* Define to 1 if you have the `pthread_setname_np' function. */
 #undef HAVE_PTHREAD_SETNAME_NP
 
 /* Define to 1 if you have the <sched.h> header file. */
 #undef HAVE_SCHED_H
 
+/* Define to 1 if you have the `sched_setaffinity' function. */
+#undef HAVE_SCHED_SETAFFINITY
+
 /* Define to 1 if you have the `sched_yield' function. */
 #undef HAVE_SCHED_YIELD
 
 /* Define to 1 if you have the <sys/capability.h> header file. */
 #undef HAVE_SYS_CAPABILITY_H
 
+/* Define to 1 if you have the <sys/cpuset.h> header file. */
+#undef HAVE_SYS_CPUSET_H
+
 /* Define to 1 if you have the <sys/devpoll.h> header file. */
 #undef HAVE_SYS_DEVPOLL_H
 
 /* Define to 1 if you have the <sys/param.h> header file. */
 #undef HAVE_SYS_PARAM_H
 
+/* Define to 1 if you have the <sys/prctl.h> header file. */
+#undef HAVE_SYS_PRCTL_H
+
+/* Define to 1 if you have the <sys/procset.h> header file. */
+#undef HAVE_SYS_PROCSET_H
+
 /* Define to 1 if you have the <sys/select.h> header file. */
 #undef HAVE_SYS_SELECT_H
 
index efbe6855fc55b141be428e2eb424731cd4666232..c6356bdc03deb06c637daf2724869c8be3ca86a5 100755 (executable)
--- a/configure
+++ b/configure
 done
 
 
+for ac_header in sys/cpuset.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "sys/cpuset.h" "ac_cv_header_sys_cpuset_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_cpuset_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_SYS_CPUSET_H 1
+_ACEOF
+
+fi
+
+done
+
+for ac_header in sys/procset.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "sys/procset.h" "ac_cv_header_sys_procset_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_procset_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_SYS_PROCSET_H 1
+_ACEOF
+
+fi
+
+done
+
+for ac_func in pthread_setaffinity_np cpuset_setaffinity processor_bind sched_setaffinity
+do :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+#
+# Additional OS-specific issues related to pthreads and sigwait.
+#
+case "$host" in
+       #
+       # One more place to look for sigwait.
+       #
+       *-freebsd*)
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sigwait in -lc_r" >&5
+$as_echo_n "checking for sigwait in -lc_r... " >&6; }
+if ${ac_cv_lib_c_r_sigwait+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lc_r  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char sigwait ();
+int
+main ()
+{
+return sigwait ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_c_r_sigwait=yes
+else
+  ac_cv_lib_c_r_sigwait=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_r_sigwait" >&5
+$as_echo "$ac_cv_lib_c_r_sigwait" >&6; }
+if test "x$ac_cv_lib_c_r_sigwait" = xyes; then :
+  $as_echo "#define HAVE_SIGWAIT 1" >>confdefs.h
+
+fi
+
+               case $host in
+               *-freebsd5.[012]|*-freebsd5.[012].*);;
+               *-freebsd5.[3456789]|*-freebsd5.[3456789].*)
+                       $as_echo "#define NEED_PTHREAD_SCOPE_SYSTEM 1" >>confdefs.h
+
+                       ;;
+               *-freebsd6.*)
+                       $as_echo "#define NEED_PTHREAD_SCOPE_SYSTEM 1" >>confdefs.h
+
+                       ;;
+               esac
+               ;;
+       #
+       # LinuxThreads requires some changes to the way we
+       # deal with signals.
+       #
+       *-linux*)
+               $as_echo "#define HAVE_LINUXTHREADS 1" >>confdefs.h
+
+               ;;
+esac
+
 # Look for functions relating to thread naming
 for ac_func in pthread_setname_np pthread_set_name_np
 do :
index 914e5ae2c141164766df855e3d07d33bb2aa861e..d6567d56cc843524981610daa12a92bf57efd638 100644 (file)
@@ -715,6 +715,38 @@ AC_CHECK_HEADERS([sched.h])
 AC_SEARCH_LIBS([sched_yield],[rt])
 AC_CHECK_FUNCS([sched_yield pthread_yield pthread_yield_np])
 
+AC_CHECK_HEADERS([sys/cpuset.h])
+AC_CHECK_HEADERS([sys/procset.h])
+AC_CHECK_FUNCS([pthread_setaffinity_np cpuset_setaffinity processor_bind sched_setaffinity])
+
+#
+# Additional OS-specific issues related to pthreads and sigwait.
+#
+case "$host" in
+       #
+       # One more place to look for sigwait.
+       #
+       *-freebsd*)
+               AC_CHECK_LIB(c_r, sigwait, AC_DEFINE(HAVE_SIGWAIT),)
+               case $host in
+               *-freebsd5.[[012]]|*-freebsd5.[[012]].*);;
+               *-freebsd5.[[3456789]]|*-freebsd5.[[3456789]].*)
+                       AC_DEFINE(NEED_PTHREAD_SCOPE_SYSTEM)
+                       ;;
+               *-freebsd6.*)
+                       AC_DEFINE(NEED_PTHREAD_SCOPE_SYSTEM)
+                       ;;
+               esac
+               ;;
+       #
+       # LinuxThreads requires some changes to the way we
+       # deal with signals.
+       #
+       *-linux*)
+               AC_DEFINE(HAVE_LINUXTHREADS)
+               ;;
+esac
+
 # Look for functions relating to thread naming
 AC_CHECK_FUNCS([pthread_setname_np pthread_set_name_np])
 AC_CHECK_HEADERS([pthread_np.h], [], [], [#include <pthread.h>])
index 798af338ac02ca376cb69c4c017bba0e98cdac18..6d969500285685190c67627d7a50bc96de983126 100644 (file)
@@ -44,6 +44,9 @@ isc_thread_yield(void);
 void
 isc_thread_setname(isc_thread_t thread, const char *name);
 
+isc_result_t
+isc_thread_setaffinity(int cpu);
+
 /* XXX We could do fancier error handling... */
 
 #define isc_thread_join(t, rp) \
index ba7ae52daae42a3f65d927cd7a3cbc4dd3fe0008..f8029e26ed9cadcd1e7a5d558e0597402dc57e7d 100644 (file)
 #include <sched.h>
 #endif
 
+#if defined(HAVE_CPUSET_H)
+#include <sys/param.h>
+#include <sys/cpuset.h>
+#endif
+
+#if defined(HAVE_SYS_PROCESET_H)
+#include <sys/types.h>
+#include <sys/processor.h>
+#include <sys/procset.h>
+#endif
+
 #include <isc/thread.h>
 #include <isc/util.h>
 
@@ -91,3 +102,31 @@ isc_thread_yield(void) {
        pthread_yield_np();
 #endif
 }
+
+isc_result_t
+isc_thread_setaffinity(int cpu) {
+#if defined(HAVE_CPUSET_SETAFFINITY)
+       cpuset_t cpuset;
+       CPU_ZERO(&cpuset);
+       CPU_SET(cpu, &cpuset);
+       if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1,
+           &cpuset, sizeof(cpuset)) != 0) {
+               return (ISC_R_FAILURE);
+       }
+#elif defined(HAVE_PTHREAD_SETAFFINITY_NP)
+       cpu_set_t set;
+       CPU_ZERO(&set);
+       CPU_SET(cpu, &set);
+       if (pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t),
+           &set) != 0) {
+               return (ISC_R_FAILURE);
+       }
+#elif defined(HAVE_PROCESSOR_BIND)
+       if (processor_bind(P_LWPID, P_MYID, cpu, NULL) != 0) {
+               return (ISC_R_FAILURE);
+       }
+#else
+       UNUSED(cpu);
+#endif
+       return (ISC_R_SUCCESS);
+}
index be1343afcb7f243e5e1910e9db21a415597cbe0d..25b83af07382b065b9ec3725c05e7597c462b4ca 100644 (file)
@@ -79,6 +79,9 @@ isc_thread_setconcurrency(unsigned int level);
 void
 isc_thread_setname(isc_thread_t, const char *);
 
+isc_result_t
+isc_thread_setaffinity(int cpu);
+
 int
 isc_thread_key_create(isc_thread_key_t *key, void (*func)(void *));
 
index a42ce21807576bdb83473e0863f5cb8c75e012cf..ea25fc3f2d356d7d505b18a9770a6df052318866 100644 (file)
@@ -658,6 +658,7 @@ isc_thread_key_create
 isc_thread_key_delete
 isc_thread_key_getspecific
 isc_thread_key_setspecific
+isc_thread_setaffinity
 isc_thread_setconcurrency
 isc_thread_setname
 isc_time_add
index ebc2f2936f0f0e29932b42b3df8835b56c63e1fd..7c147164d249de10f33862e6398bb0bcfe8ad5e4 100644 (file)
@@ -66,6 +66,12 @@ isc_thread_setname(isc_thread_t thread, const char *name) {
        UNUSED(name);
 }
 
+isc_result_t
+isc_thread_setaffinity(int cpu) {
+       /* no-op on Windows for now */
+       return (ISC_R_SUCCESS);
+}
+
 void *
 isc_thread_key_getspecific(isc_thread_key_t key) {
        return(TlsGetValue(key));