From: Evan Hunt Date: Mon, 10 Mar 2014 19:14:35 +0000 (-0700) Subject: [master] use adaptive locks when available X-Git-Tag: v9.10.0b2~35 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=8cbf3b6fc35091abde426930f2eadb8f53476c98;p=thirdparty%2Fbind9.git [master] use adaptive locks when available 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] --- diff --git a/CHANGES b/CHANGES index 71cf63ef449..f7564038c8b 100644 --- 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] diff --git a/config.h.in b/config.h.in index dd0f71b1076..0f6658fdf32 100644 --- a/config.h.in +++ b/config.h.in @@ -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 diff --git a/configure b/configure index 926e7c36587..0211dcf501f 100755 --- 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 + +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)" diff --git a/configure.in b/configure.in index 8b5c7f060c7..623ab17dcf4 100644 --- a/configure.in +++ b/configure.in @@ -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 + ]], [[ + 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)" diff --git a/lib/isc/pthreads/mutex.c b/lib/isc/pthreads/mutex.c index c7e5795b680..ef8896d9dbf 100644 --- a/lib/isc/pthreads/mutex.c +++ b/lib/isc/pthreads/mutex.c @@ -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) {