]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2356. [bug] Builtin mutex profiler was not scalable enough.
authorTatuya JINMEI 神明達哉 <jinmei@isc.org>
Fri, 4 Apr 2008 02:58:42 +0000 (02:58 +0000)
committerTatuya JINMEI 神明達哉 <jinmei@isc.org>
Fri, 4 Apr 2008 02:58:42 +0000 (02:58 +0000)
[RT #17436]

CHANGES
lib/isc/pthreads/mutex.c

diff --git a/CHANGES b/CHANGES
index 19126e4ea92853fc7a5b581a7eeb538c774272cd..79f331e11502876241006567e2d4c27098e71f91 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+2356.  [bug]           Builtin mutex profiler was not scalable enough.
+                       [RT #17436]
+
 2353.  [func]          libbind: nsid support. [RT #17091]
 
 2350.  [port]          win32: IPv6 support. [RT #17797]
index 7716980e10a2765cec016677e2bdcf0590971d90..5970acd16bbcfac7ca47ac76d70ab6ac45a13126 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: mutex.c,v 1.8.18.4 2005/07/12 01:22:32 marka Exp $ */
+/* $Id: mutex.c,v 1.8.18.5 2008/04/04 02:58:42 jinmei Exp $ */
 
 /*! \file */
 
@@ -77,8 +77,11 @@ struct isc_mutexstats {
        isc_mutexlocker_t       lockers[ISC_MUTEX_MAX_LOCKERS];
 };
 
-#define TABLESIZE (8 * 1024)
-static isc_mutexstats_t stats[TABLESIZE];
+#ifndef ISC_MUTEX_PROFTABLESIZE
+#define ISC_MUTEX_PROFTABLESIZE (16 * 1024)
+#endif
+static isc_mutexstats_t stats[ISC_MUTEX_PROFTABLESIZE];
+static int stats_next = 0;
 static isc_boolean_t stats_init = ISC_FALSE;
 static pthread_mutex_t statslock = PTHREAD_MUTEX_INITIALIZER;
 
@@ -95,21 +98,19 @@ isc_mutex_init_profile(isc_mutex_t *mp, const char *file, int line) {
 
        RUNTIME_CHECK(pthread_mutex_lock(&statslock) == 0);
 
-       if (stats_init == ISC_FALSE) {
-               for (i = 0; i < TABLESIZE; i++) {
-                       stats[i].file = NULL;
-               }
+       if (stats_init == ISC_FALSE)
                stats_init = ISC_TRUE;
-       }
 
-       mp->stats = NULL;
-       for (i = 0; i < TABLESIZE; i++) {
-               if (stats[i].file == NULL) {
-                       mp->stats = &stats[i];
-                       break;
-               }
-       }
-       RUNTIME_CHECK(mp->stats != NULL);
+       /*
+        * If all statistics entries have been used, give up and trigger an
+        * assertion failure.  There would be no other way to deal with this
+        * because we'd like to keep record of all locks for the purpose of
+        * debugging and the number of necessary locks is unpredictable.
+        * If this failure is triggered while debugging, named should be
+        * rebuilt with an increased ISC_MUTEX_PROFTABLESIZE.
+        */
+       RUNTIME_CHECK(stats_next < ISC_MUTEX_PROFTABLESIZE);
+       mp->stats = &stats[stats_next++];
 
        RUNTIME_CHECK(pthread_mutex_unlock(&statslock) == 0);
 
@@ -196,10 +197,9 @@ void
 isc_mutex_statsprofile(FILE *fp) {
        isc_mutexlocker_t *locker;
        int i, j;
+
        fprintf(fp, "Mutex stats (in us)\n");
-       for (i = 0; i < TABLESIZE; i++) {
-               if (stats[i].file == NULL)
-                       continue;
+       for (i = 0; i < stats_next; i++) {
                fprintf(fp, "%-12s %4d: %10u  %lu.%06lu %lu.%06lu\n",
                        stats[i].file, stats[i].line, stats[i].count,
                        stats[i].locked_total.tv_sec,
@@ -251,6 +251,7 @@ pthread_mutexattr_t isc__mutex_attrs = {
 };
 #endif
 
+#if !(ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK)) && !ISC_MUTEX_PROFILE
 isc_result_t
 isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line) {
        char strbuf[ISC_STRERRORSIZE];
@@ -268,3 +269,4 @@ isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line) {
        }
        return (result);
 }
+#endif