From owner-svn-src-stable@FreeBSD.ORG Fri Apr 20 22:01:13 2012 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 381AF106564A; Fri, 20 Apr 2012 22:01:13 +0000 (UTC) (envelope-from davide@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 18AA28FC17; Fri, 20 Apr 2012 22:01:13 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q3KM1Cq1057553; Fri, 20 Apr 2012 22:01:12 GMT (envelope-from davide@svn.freebsd.org) Received: (from davide@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q3KM1Cxn057549; Fri, 20 Apr 2012 22:01:12 GMT (envelope-from davide@svn.freebsd.org) Message-Id: <201204202201.q3KM1Cxn057549@svn.freebsd.org> From: Davide Italiano Date: Fri, 20 Apr 2012 22:01:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r234509 - in stable/8/sys: conf kern X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Apr 2012 22:01:13 -0000 Author: davide Date: Fri Apr 20 22:01:12 2012 New Revision: 234509 URL: http://svn.freebsd.org/changeset/base/234509 Log: MFC: r233045, r234302 r233045: Add rudimentary profiling of the hash table used in the umtx code to hold active lock queues. r234302: Fix some style bugs introduced in a previous commit (r233045) Approved by: gnn (mentor) Modified: stable/8/sys/conf/NOTES stable/8/sys/conf/options stable/8/sys/kern/kern_umtx.c Directory Properties: stable/8/sys/ (props changed) Modified: stable/8/sys/conf/NOTES ============================================================================== --- stable/8/sys/conf/NOTES Fri Apr 20 21:56:13 2012 (r234508) +++ stable/8/sys/conf/NOTES Fri Apr 20 22:01:12 2012 (r234509) @@ -262,6 +262,8 @@ options SX_NOINLINE # frequency. # TURNSTILE_PROFILING enables rudimentary profiling of the hash table # used to hold active lock queues. +# UMTX_PROFILING enables rudimentary profiling of the hash table used + to hold active lock queues. # WITNESS enables the witness code which detects deadlocks and cycles # during locking operations. # WITNESS_KDB causes the witness code to drop into the kernel debugger if @@ -285,8 +287,9 @@ options MPROF_HASH_SIZE="1543" # Profiling for internal hash tables. options SLEEPQUEUE_PROFILING options TURNSTILE_PROFILING +options UMTX_PROFILING + - ##################################################################### # COMPATIBILITY OPTIONS Modified: stable/8/sys/conf/options ============================================================================== --- stable/8/sys/conf/options Fri Apr 20 21:56:13 2012 (r234508) +++ stable/8/sys/conf/options Fri Apr 20 22:01:12 2012 (r234509) @@ -179,6 +179,7 @@ SYSVSEM opt_sysvipc.h SYSVSHM opt_sysvipc.h SW_WATCHDOG opt_watchdog.h TURNSTILE_PROFILING +UMTX_PROFILING VFS_AIO VERBOSE_SYSINIT opt_global.h WLCACHE opt_wavelan.h Modified: stable/8/sys/kern/kern_umtx.c ============================================================================== --- stable/8/sys/kern/kern_umtx.c Fri Apr 20 21:56:13 2012 (r234508) +++ stable/8/sys/kern/kern_umtx.c Fri Apr 20 22:01:12 2012 (r234509) @@ -29,6 +29,8 @@ __FBSDID("$FreeBSD$"); #include "opt_compat.h" +#include "opt_umtx_profiling.h" + #include #include #include @@ -134,6 +136,10 @@ struct umtxq_chain { /* All PI in the list */ TAILQ_HEAD(,umtx_pi) uc_pi_list; +#ifdef UMTX_PROFILING + int length; + int max_length; +#endif }; #define UMTXQ_LOCKED_ASSERT(uc) mtx_assert(&(uc)->uc_lock, MA_OWNED) @@ -170,6 +176,12 @@ SYSCTL_NODE(_debug, OID_AUTO, umtx, CTLF SYSCTL_INT(_debug_umtx, OID_AUTO, umtx_pi_allocated, CTLFLAG_RD, &umtx_pi_allocated, 0, "Allocated umtx_pi"); +#ifdef UMTX_PROFILING +static long max_length; +SYSCTL_LONG(_debug_umtx, OID_AUTO, max_length, CTLFLAG_RD, &max_length, 0, "max_length"); +static SYSCTL_NODE(_debug_umtx, OID_AUTO, chains, CTLFLAG_RD, 0, "umtx chain stats"); +#endif + static void umtxq_sysinit(void *); static void umtxq_hash(struct umtx_key *key); static struct umtxq_chain *umtxq_getchain(struct umtx_key *key); @@ -196,6 +208,27 @@ SYSINIT(umtx, SI_SUB_EVENTHANDLER+1, SI_ static struct mtx umtx_lock; +#ifdef UMTX_PROFILING +static void +umtx_init_profiling(void) +{ + struct sysctl_oid *chain_oid; + char chain_name[10]; + int i; + + for (i = 0; i < UMTX_CHAINS; ++i) { + snprintf(chain_name, sizeof(chain_name), "%d", i); + chain_oid = SYSCTL_ADD_NODE(NULL, + SYSCTL_STATIC_CHILDREN(_debug_umtx_chains), OID_AUTO, + chain_name, CTLFLAG_RD, NULL, "umtx hash stats"); + SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(chain_oid), OID_AUTO, + "max_length0", CTLFLAG_RD, &umtxq_chains[0][i].max_length, 0, NULL); + SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(chain_oid), OID_AUTO, + "max_length1", CTLFLAG_RD, &umtxq_chains[1][i].max_length, 0, NULL); + } +} +#endif + static void umtxq_sysinit(void *arg __unused) { @@ -212,8 +245,15 @@ umtxq_sysinit(void *arg __unused) TAILQ_INIT(&umtxq_chains[i][j].uc_pi_list); umtxq_chains[i][j].uc_busy = 0; umtxq_chains[i][j].uc_waiters = 0; +#ifdef UMTX_PROFILING + umtxq_chains[i][j].length = 0; + umtxq_chains[i][j].max_length = 0; +#endif } } +#ifdef UMTX_PROFILING + umtx_init_profiling(); +#endif mtx_init(&umtx_lock, "umtx lock", NULL, MTX_SPIN); EVENTHANDLER_REGISTER(process_exec, umtx_exec_hook, NULL, EVENTHANDLER_PRI_ANY); @@ -331,6 +371,14 @@ umtxq_insert_queue(struct umtx_q *uq, in uc = umtxq_getchain(&uq->uq_key); UMTXQ_LOCKED_ASSERT(uc); TAILQ_INSERT_TAIL(&uc->uc_queue[q], uq, uq_link); +#ifdef UMTX_PROFILING + uc->length++; + if (uc->length > uc->max_length) { + uc->max_length = uc->length; + if (uc->max_length > max_length) + max_length = uc->max_length; + } +#endif uq->uq_flags |= UQF_UMTXQ; } @@ -343,6 +391,9 @@ umtxq_remove_queue(struct umtx_q *uq, in UMTXQ_LOCKED_ASSERT(uc); if (uq->uq_flags & UQF_UMTXQ) { TAILQ_REMOVE(&uc->uc_queue[q], uq, uq_link); +#ifdef UMTX_PROFILING + uc->length--; +#endif uq->uq_flags &= ~UQF_UMTXQ; } }