]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Counts number of locks to make contention check fractional check of trouble.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 22 Mar 2007 12:35:40 +0000 (12:35 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 22 Mar 2007 12:35:40 +0000 (12:35 +0000)
git-svn-id: file:///svn/unbound/trunk@189 be551aaa-1e26-0410-a405-d3ace91eadb9

testcode/checklocks.c
testcode/checklocks.h

index 7db62e1e3de0446993052a347aabc221b74d2dd2..dda3be2fa893d0e4ec4aec1e0a73768f14afa194 100644 (file)
@@ -47,7 +47,6 @@
  * those used for logging which is nice.
  *
  * Todo: 
- *      - refcount statistics.
  *      - debug status print, of thread lock stacks, and current waiting.
  */
 #ifdef USE_THREAD_DEBUG
@@ -305,7 +304,7 @@ void
 checklock_destroy(enum check_lock_type type, struct checked_lock** lock,
         const char* func, const char* file, int line)
 {
-       const size_t contention_interest = 10;
+       const size_t contention_interest = 1; /* promille contented locks */
        struct checked_lock* e;
        if(!lock) 
                return;
@@ -324,11 +323,13 @@ checklock_destroy(enum check_lock_type type, struct checked_lock** lock,
        *lock = NULL; /* use after free will fail */
        LOCKRET(pthread_mutex_unlock(&e->lock));
 
-       /* contention */
-       if(e->contention_count > contention_interest) {
-               log_info("lock created %s %s %d has contention %u",
+       /* contention, look at fraction in trouble. */
+       if(e->history_count > 1 &&
+          1000*e->contention_count/e->history_count > contention_interest) {
+               log_info("lock created %s %s %d has contention %u of %u",
                        e->create_func, e->create_file, e->create_line,
-                       (unsigned int)e->contention_count);
+                       (unsigned int)e->contention_count, 
+                       (unsigned int)e->history_count);
        }
 
        /* delete it */
@@ -433,6 +434,7 @@ checklock_lockit(enum check_lock_type type, struct checked_lock* lock,
 
        acquire_locklock(lock, func, file, line);
        lock->contention_count += contend;
+       lock->history_count++;
        if(exclusive && lock->hold_count > 0)
                lock_error(lock, func, file, line, "got nonexclusive lock");
        if(type==check_lock_rwlock && getwr && lock->writeholder)
index 05ec7ca1d4bb82bb7592a13601d3fddb50626f9a..72ad9ef04f2a6c9b79a3ef64976ffae057f0911f 100644 (file)
@@ -138,6 +138,8 @@ struct checked_lock {
        int create_thread, create_instance;
        /** contention count */
        size_t contention_count;
+       /** number of times locked, ever */
+       size_t history_count;
        /** hold count (how many threads are holding this lock) */
        int hold_count;
        /** how many threads are waiting for this lock */