From: Wouter Wijngaards Date: Thu, 22 Mar 2007 12:35:40 +0000 (+0000) Subject: Counts number of locks to make contention check fractional check of trouble. X-Git-Tag: release-0.2~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22791a44ca0e15d571952a044679255e8f12ad31;p=thirdparty%2Funbound.git Counts number of locks to make contention check fractional check of trouble. git-svn-id: file:///svn/unbound/trunk@189 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/testcode/checklocks.c b/testcode/checklocks.c index 7db62e1e3..dda3be2fa 100644 --- a/testcode/checklocks.c +++ b/testcode/checklocks.c @@ -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) diff --git a/testcode/checklocks.h b/testcode/checklocks.h index 05ec7ca1d..72ad9ef04 100644 --- a/testcode/checklocks.h +++ b/testcode/checklocks.h @@ -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 */