Commit c4fadc88 authored by Tatuya JINMEI 神明達哉's avatar Tatuya JINMEI 神明達哉
Browse files

2356. [bug] Builtin mutex profiler was not scalable enough.

			[RT #17436]

(I plan to merge this to 9.[345])
parent e062b72f
2356. [bug] Builtin mutex profiler was not scalable enough.
[RT #17436]
2355. [func] Extend the number statistics counters available.
[RT #17590]
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: mutex.c,v 1.14 2007/06/19 23:47:18 tbox Exp $ */
/* $Id: mutex.c,v 1.15 2008/04/04 01:49:09 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment