]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[master] use adaptive locks when available
authorEvan Hunt <each@isc.org>
Mon, 10 Mar 2014 19:14:35 +0000 (12:14 -0700)
committerEvan Hunt <each@isc.org>
Mon, 10 Mar 2014 19:14:35 +0000 (12:14 -0700)
3781. [tuning] Use adaptive mutex locks when available; this
has been found to improve performance under load
on many systems. "configure --with-locktype=standard"
restores conventional mutex locks. [RT #32576]

CHANGES
config.h.in
configure
configure.in
lib/isc/pthreads/mutex.c

diff --git a/CHANGES b/CHANGES
index 71cf63ef449dbff0565431572fe915211307e3a6..f7564038c8bba17afee5811aba3a6c0533a9a16e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
+3781.  [tuning]        Use adaptive mutex locks when available; this
+                       has been found to improve performance under load
+                       on many systems. "configure --with-locktype=standard"
+                       restores conventional mutex locks. [RT #32576]
+
 3780.  [bug]           $GENERATE handled negative numbers incorrectly. 
                        [RT #25528]
 
index dd0f71b1076120a55dc67142bfeeef7b2331859b..0f6658fdf3226aeee48a34a00ef53b409e905364 100644 (file)
@@ -335,6 +335,9 @@ int sigwait(const unsigned int *set, int *sig);
 /* Define if your PKCS11 provider supports GOST. */
 #undef HAVE_PKCS11_GOST
 
+/* Support for PTHREAD_MUTEX_ADAPTIVE_NP */
+#undef HAVE_PTHREAD_MUTEX_ADAPTIVE_NP
+
 /* Define to 1 if you have the `pthread_yield' function. */
 #undef HAVE_PTHREAD_YIELD
 
index 926e7c3658762d8c446fd978e79d6382c75d1c97..0211dcf501fa97a87a756b96b9ac046ac383265a 100755 (executable)
--- a/configure
+++ b/configure
@@ -978,6 +978,7 @@ with_geoip
 with_gssapi
 with_randomdev
 enable_threads
+with_locktype
 with_libtool
 enable_native_pkcs11
 with_openssl
@@ -1691,6 +1692,7 @@ Optional Packages:
   --with-geoip=PATH       Build with GeoIP support (yes|no|path)
   --with-gssapi=PATH      Specify path for system-supplied GSSAPI [default=yes]
   --with-randomdev=PATH   Specify path for random device
+  --with-locktype=ARG       Specify mutex lock type (adaptive or standard)
   --with-libtool          use GNU libtool
   --with-openssl=PATH     Build with OpenSSL yes|no|path.
                          (Crypto is required for DNSSEC)
@@ -14855,6 +14857,57 @@ if test "x$ac_cv_func_pthread_attr_setstacksize" = xyes; then :
 fi
 
 
+
+# Check whether --with-locktype was given.
+if test "${with_locktype+set}" = set; then :
+  withval=$with_locktype; locktype="$withval"
+else
+  locktype="adaptive"
+fi
+
+
+        case "$locktype" in
+                adaptive)
+                        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for PTHREAD_MUTEX_ADAPTIVE_NP" >&5
+$as_echo_n "checking for PTHREAD_MUTEX_ADAPTIVE_NP... " >&6; }
+
+                        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+                          #define _GNU_SOURCE
+                          #include <pthread.h>
+
+int
+main ()
+{
+
+                          return (PTHREAD_MUTEX_ADAPTIVE_NP);
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+   { $as_echo "$as_me:${as_lineno-$LINENO}: result: using adaptive lock type" >&5
+$as_echo "using adaptive lock type" >&6; }
+
+$as_echo "#define HAVE_PTHREAD_MUTEX_ADAPTIVE_NP 1" >>confdefs.h
+
+else
+   { $as_echo "$as_me:${as_lineno-$LINENO}: result: using standard lock type" >&5
+$as_echo "using standard lock type" >&6; }
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+                        ;;
+                standard)
+                        { $as_echo "$as_me:${as_lineno-$LINENO}: result: using standard lock type" >&5
+$as_echo "using standard lock type" >&6; }
+                        ;;
+                *)
+                        as_fn_error $? "You must specify \"adaptive\" or \"standard\" for --with-locktype." "$LINENO" 5
+                        ;;
+        esac
+
        for ac_header in sched.h
 do :
   ac_fn_c_check_header_mongrel "$LINENO" "sched.h" "ac_cv_header_sched_h" "$ac_includes_default"
@@ -23715,7 +23768,12 @@ echo "========================================================================"
 echo "Configuration summary:"
 echo "------------------------------------------------------------------------"
 echo "Optional features enabled:"
-$use_threads && echo "    Multiprocessing support (--enable-threads)"
+if $use_threads; then
+    echo "    Multiprocessing support (--enable-threads)"
+    if test "$enable_full_report" = "yes" -o "$locktype" = "standard"; then
+        echo "        Mutex lock type: $locktype"
+    fi
+fi
 test "$use_tuning" = "large" && echo "    Large-system tuning (--with-tuning)"
 test "$use_geoip" = "no" || echo "    GeoIP access control (--with-geoip)"
 test "$use_gssapi" = "no" || echo "    GSS-API (--with-gssapi)"
index 8b5c7f060c797fd2229f225fd7e008a38314834c..623ab17dcf4873b5bb147450acd374dcabcbcdef 100644 (file)
@@ -1,4 +1,5 @@
 # Copyright (C) 2004-2014  Internet Systems Consortium, Inc. ("ISC")
+
 # Copyright (C) 1998-2003  Internet Software Consortium.
 #
 # Permission to use, copy, modify, and/or distribute this software for any
@@ -1022,6 +1023,33 @@ then
        AC_CHECK_FUNC(pthread_attr_setstacksize,
                      AC_DEFINE(HAVE_PTHREAD_ATTR_SETSTACKSIZE),)
 
+        AC_ARG_WITH(locktype,
+                [  --with-locktype=ARG       Specify mutex lock type (adaptive or standard)],
+                locktype="$withval", locktype="adaptive")
+
+        case "$locktype" in
+                adaptive)
+                        AC_MSG_CHECKING([for PTHREAD_MUTEX_ADAPTIVE_NP])
+
+                        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+                          #define _GNU_SOURCE
+                          #include <pthread.h>
+                        ]], [[
+                          return (PTHREAD_MUTEX_ADAPTIVE_NP);
+                        ]])],
+                        [ AC_MSG_RESULT(using adaptive lock type)
+                          AC_DEFINE([HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], 1,
+                                    [Support for PTHREAD_MUTEX_ADAPTIVE_NP]) ],
+                        [ AC_MSG_RESULT(using standard lock type) ])
+                        ;;
+                standard)
+                        AC_MSG_RESULT(using standard lock type)
+                        ;;
+                *)
+                        AC_MSG_ERROR([You must specify "adaptive" or "standard" for --with-locktype.])
+                        ;;
+        esac
+
        AC_CHECK_HEADERS(sched.h)
 
        case "$host" in
@@ -4419,7 +4447,12 @@ echo "========================================================================"
 echo "Configuration summary:"
 echo "------------------------------------------------------------------------"
 echo "Optional features enabled:"
-$use_threads && echo "    Multiprocessing support (--enable-threads)"
+if $use_threads; then
+    echo "    Multiprocessing support (--enable-threads)"
+    if test "$enable_full_report" = "yes" -o "$locktype" = "standard"; then
+        echo "        Mutex lock type: $locktype"
+    fi
+fi
 test "$use_tuning" = "large" && echo "    Large-system tuning (--with-tuning)"
 test "$use_geoip" = "no" || echo "    GeoIP access control (--with-geoip)"
 test "$use_gssapi" = "no" || echo "    GSS-API (--with-gssapi)"
index c7e5795b6807a95228b204833d855324fa1d98d1..ef8896d9dbf135fd24cb6b3b5ba3180c39c6d506 100644 (file)
@@ -260,8 +260,20 @@ isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line) {
        char strbuf[ISC_STRERRORSIZE];
        isc_result_t result = ISC_R_SUCCESS;
        int err;
+#ifdef HAVE_PTHREAD_MUTEX_ADAPTIVE_NP
+       pthread_mutexattr_t attr;
 
+       if (pthread_mutexattr_init(&attr) != 0)
+               return (ISC_R_UNEXPECTED);
+       if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP) != 0) {
+               pthread_mutexattr_destroy(&attr);
+               return (ISC_R_UNEXPECTED);
+       }
+       err = pthread_mutex_init(mp, &attr);
+#else /* HAVE_PTHREAD_MUTEX_ADAPTIVE_NP */
        err = pthread_mutex_init(mp, ISC__MUTEX_ATTRS);
+#endif /* HAVE_PTHREAD_MUTEX_ADAPTIVE_NP */
+
        if (err == ENOMEM)
                return (ISC_R_NOMEMORY);
        if (err != 0) {