diff --git a/bin/named/main.c b/bin/named/main.c index 2296a0b876..e683d9c07b 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: main.c,v 1.97 2000/12/12 23:05:54 bwelling Exp $ */ +/* $Id: main.c,v 1.98 2000/12/29 01:29:51 bwelling Exp $ */ #include @@ -572,8 +572,10 @@ main(int argc, char *argv[]) { cleanup(); - if (want_stats) + if (want_stats) { isc_mem_stats(ns_g_mctx, stdout); + isc_mutex_stats(stdout); + } isc_mem_destroy(&ns_g_mctx); isc_app_finish(); diff --git a/lib/isc/Makefile.in b/lib/isc/Makefile.in index 20a8ca5086..91c7843710 100644 --- a/lib/isc/Makefile.in +++ b/lib/isc/Makefile.in @@ -13,7 +13,7 @@ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# $Id: Makefile.in,v 1.68 2000/11/14 23:43:36 tale Exp $ +# $Id: Makefile.in,v 1.69 2000/12/29 01:29:52 bwelling Exp $ srcdir = @srcdir@ VPATH = @srcdir@ @@ -41,7 +41,8 @@ UNIXOBJS = @ISC_ISCIPV6_O@ \ NLSOBJS = nls/msgcat.@O@ -THREADOBJS = @ISC_THREAD_DIR@/condition.@O@ @ISC_THREAD_DIR@/thread.@O@ +THREADOBJS = @ISC_THREAD_DIR@/condition.@O@ @ISC_THREAD_DIR@/mutex.@O@ \ + @ISC_THREAD_DIR@/thread.@O@ WIN32OBJS = win32/condition.@O@ win32/dir.@O@ win32/file.@O@ \ win32/fsaccess.@O@ win32/once.@O@ win32/stdtime.@O@ \ diff --git a/lib/isc/nothreads/Makefile.in b/lib/isc/nothreads/Makefile.in index de9f805478..9c06a21659 100644 --- a/lib/isc/nothreads/Makefile.in +++ b/lib/isc/nothreads/Makefile.in @@ -13,7 +13,7 @@ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# $Id: Makefile.in,v 1.2 2000/08/29 19:22:34 bwelling Exp $ +# $Id: Makefile.in,v 1.3 2000/12/29 01:29:53 bwelling Exp $ srcdir = @srcdir@ VPATH = @srcdir@ @@ -28,9 +28,9 @@ CINCLUDES = -I${srcdir}/include \ CDEFINES = CWARNINGS = -OBJS = condition.@O@ thread.@O@ +OBJS = condition.@O@ mutex.@O@ thread.@O@ -SRCS = condition.c thread.c +SRCS = condition.c mutex.c thread.c SUBDIRS = include TARGETS = ${OBJS} diff --git a/lib/isc/nothreads/mutex.c b/lib/isc/nothreads/mutex.c new file mode 100644 index 0000000000..fcfaa9d8a0 --- /dev/null +++ b/lib/isc/nothreads/mutex.c @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2000 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: mutex.c,v 1.1 2000/12/29 01:29:54 bwelling Exp $ */ + +/* This file intentionally left blank. */ diff --git a/lib/isc/pthreads/Makefile.in b/lib/isc/pthreads/Makefile.in index 800998808b..459ae9c811 100644 --- a/lib/isc/pthreads/Makefile.in +++ b/lib/isc/pthreads/Makefile.in @@ -13,7 +13,7 @@ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# $Id: Makefile.in,v 1.14 2000/08/01 01:30:59 tale Exp $ +# $Id: Makefile.in,v 1.15 2000/12/29 01:29:55 bwelling Exp $ srcdir = @srcdir@ VPATH = @srcdir@ @@ -28,9 +28,9 @@ CINCLUDES = -I${srcdir}/include \ CDEFINES = CWARNINGS = -OBJS = condition.@O@ thread.@O@ +OBJS = condition.@O@ mutex.@O@ thread.@O@ -SRCS = condition.c thread.c +SRCS = condition.c mutex.c thread.c SUBDIRS = include TARGETS = ${OBJS} diff --git a/lib/isc/pthreads/mutex.c b/lib/isc/pthreads/mutex.c new file mode 100644 index 0000000000..08d1e466bb --- /dev/null +++ b/lib/isc/pthreads/mutex.c @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2000 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM + * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL + * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: mutex.c,v 1.1 2000/12/29 01:29:56 bwelling Exp $ */ + +#include + +#include +#include +#include + +#include +#include + +#if ISC_MUTEX_PROFILE + +struct mutexstats { + const char *file; + int line; + isc_uint64_t us; + isc_uint32_t count; +}; + +#define TABLESIZE (8 * 1024) +static struct mutexstats stats[TABLESIZE]; +static pthread_mutex_t statslock = PTHREAD_MUTEX_INITIALIZER; + +#define tvdiff(tv2, tv1) \ + ((((tv2).tv_sec - (tv1).tv_sec) * 1000000) + \ + (tv2).tv_usec - (tv1).tv_usec) + + +isc_result_t +isc_mutex_lockprofile(isc_mutex_t *mp, const char * file, int line) { + struct timeval tv1, tv2; + int ret; + int realline; + unsigned int diff; + + UNUSED(file); + + gettimeofday(&tv1, NULL); + ret = pthread_mutex_lock(mp); + gettimeofday(&tv2, NULL); + if (ret != 0) + return (ISC_R_UNEXPECTED); + diff = tvdiff(tv2, tv1); + if (diff == 0) + return (ISC_R_SUCCESS); + RUNTIME_CHECK(pthread_mutex_lock(&statslock) == 0); + INSIST(line >= 0 && line < TABLESIZE); + realline = line; + while (stats[line].file != NULL && stats[line].file != file) { + line++; + INSIST(line < TABLESIZE); + } + if (stats[line].file == NULL) { + stats[line].file = file; + stats[line].line = realline; + stats[line].us = 0; + stats[line].count = 0; + } + stats[line].us += diff; + stats[line].count++; + RUNTIME_CHECK(pthread_mutex_unlock(&statslock) == 0); + + return (ISC_R_SUCCESS); +} + +void +isc_mutex_statsprofile(FILE *fp) { + int i; + fprintf(fp, "Mutex stats (in us)\n"); + for (i = 0; i < TABLESIZE; i++) { + if (stats[i].file == NULL) + continue; + fprintf(fp, "%14s %6d: %10lluus %10u %10llu\n", + stats[i].file, stats[i].line, stats[i].us, + stats[i].count, stats[i].us / stats[i].count); + } +} + +#endif /* ISC_MUTEX_PROFILE */ diff --git a/util/copyrights b/util/copyrights index b2d2cf9093..9f07f0bc71 100644 --- a/util/copyrights +++ b/util/copyrights @@ -1259,6 +1259,7 @@ ./lib/isc/nothreads/include/isc/mutex.h C 2000 ./lib/isc/nothreads/include/isc/once.h C 2000 ./lib/isc/nothreads/include/isc/thread.h C 2000 +./lib/isc/nothreads/mutex.c C 2000 ./lib/isc/nothreads/thread.c C 2000 ./lib/isc/ondestroy.c C 2000 ./lib/isc/print.c C 1999,2000 @@ -1273,6 +1274,7 @@ ./lib/isc/pthreads/include/isc/mutex.h C 1998,1999,2000 ./lib/isc/pthreads/include/isc/once.h C 1999,2000 ./lib/isc/pthreads/include/isc/thread.h C 1998,1999,2000 +./lib/isc/pthreads/mutex.c C 2000 ./lib/isc/pthreads/thread.c C 2000 ./lib/isc/quota.c C 2000 ./lib/isc/random.c C 1999,2000