From owner-svn-src-head@FreeBSD.ORG Fri Aug 9 11:24:30 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 1E3252DA; Fri, 9 Aug 2013 11:24:30 +0000 (UTC) (envelope-from attilio@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0B45A21AF; Fri, 9 Aug 2013 11:24:30 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r79BOTcO099816; Fri, 9 Aug 2013 11:24:29 GMT (envelope-from attilio@svn.freebsd.org) Received: (from attilio@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r79BOT7w099814; Fri, 9 Aug 2013 11:24:29 GMT (envelope-from attilio@svn.freebsd.org) Message-Id: <201308091124.r79BOT7w099814@svn.freebsd.org> From: Attilio Rao Date: Fri, 9 Aug 2013 11:24:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r254139 - in head: share/man/man9 sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Aug 2013 11:24:30 -0000 Author: attilio Date: Fri Aug 9 11:24:29 2013 New Revision: 254139 URL: http://svnweb.freebsd.org/changeset/base/254139 Log: Give mutex(9) the ability to recurse on a per-instance basis. Now the MTX_RECURSE flag can be passed to the mtx_*_flag() calls. This helps in cases we want to narrow down to specific calls the possibility to recurse for some locks. Sponsored by: EMC / Isilon storage division Reviewed by: jeff, alc Tested by: pho Modified: head/share/man/man9/mutex.9 head/sys/kern/kern_mutex.c Modified: head/share/man/man9/mutex.9 ============================================================================== --- head/share/man/man9/mutex.9 Fri Aug 9 11:11:11 2013 (r254138) +++ head/share/man/man9/mutex.9 Fri Aug 9 11:24:29 2013 (r254139) @@ -225,8 +225,10 @@ or lock, respectively, and also accept a .Fa flags argument. -In both cases, the only flag presently available for lock acquires is -.Dv MTX_QUIET . +In both cases, the only flags presently available for lock acquires are +.Dv MTX_QUIET +and +.Dv MTX_RECURSE . If the .Dv MTX_QUIET bit is turned on in the @@ -235,6 +237,12 @@ argument, then if .Dv KTR_LOCK tracing is being done, it will be silenced during the lock acquire. +If the +.Dv MTX_RECURSE +bit is turned on in the +.Fa flags +argument, then the mutex can be acquired recursively. +.Pp .Pp The .Fn mtx_trylock Modified: head/sys/kern/kern_mutex.c ============================================================================== --- head/sys/kern/kern_mutex.c Fri Aug 9 11:11:11 2013 (r254138) +++ head/sys/kern/kern_mutex.c Fri Aug 9 11:24:29 2013 (r254139) @@ -218,13 +218,14 @@ __mtx_lock_flags(volatile uintptr_t *c, KASSERT(LOCK_CLASS(&m->lock_object) == &lock_class_mtx_sleep, ("mtx_lock() of spin mutex %s @ %s:%d", m->lock_object.lo_name, file, line)); - WITNESS_CHECKORDER(&m->lock_object, opts | LOP_NEWORDER | LOP_EXCLUSIVE, - file, line, NULL); + WITNESS_CHECKORDER(&m->lock_object, (opts & ~MTX_RECURSE) | + LOP_NEWORDER | LOP_EXCLUSIVE, file, line, NULL); __mtx_lock(m, curthread, opts, file, line); LOCK_LOG_LOCK("LOCK", &m->lock_object, opts, m->mtx_recurse, file, line); - WITNESS_LOCK(&m->lock_object, opts | LOP_EXCLUSIVE, file, line); + WITNESS_LOCK(&m->lock_object, (opts & ~MTX_RECURSE) | LOP_EXCLUSIVE, + file, line); curthread->td_locks++; } @@ -271,9 +272,11 @@ __mtx_lock_spin_flags(volatile uintptr_t ("mtx_lock_spin() of sleep mutex %s @ %s:%d", m->lock_object.lo_name, file, line)); if (mtx_owned(m)) - KASSERT((m->lock_object.lo_flags & LO_RECURSABLE) != 0, + KASSERT((m->lock_object.lo_flags & LO_RECURSABLE) != 0 || + (opts & MTX_RECURSE) != 0, ("mtx_lock_spin: recursed on non-recursive mutex %s @ %s:%d\n", m->lock_object.lo_name, file, line)); + opts &= ~MTX_RECURSE; WITNESS_CHECKORDER(&m->lock_object, opts | LOP_NEWORDER | LOP_EXCLUSIVE, file, line, NULL); __mtx_lock_spin(m, curthread, opts, file, line); @@ -335,12 +338,14 @@ _mtx_trylock_flags_(volatile uintptr_t * ("mtx_trylock() of spin mutex %s @ %s:%d", m->lock_object.lo_name, file, line)); - if (mtx_owned(m) && (m->lock_object.lo_flags & LO_RECURSABLE) != 0) { + if (mtx_owned(m) && ((m->lock_object.lo_flags & LO_RECURSABLE) != 0 || + (opts & MTX_RECURSE) != 0)) { m->mtx_recurse++; atomic_set_ptr(&m->mtx_lock, MTX_RECURSED); rval = 1; } else rval = _mtx_obtain_lock(m, (uintptr_t)curthread); + opts &= ~MTX_RECURSE; LOCK_LOG_TRY("LOCK", &m->lock_object, opts, rval, file, line); if (rval) { @@ -391,15 +396,18 @@ __mtx_lock_sleep(volatile uintptr_t *c, m = mtxlock2mtx(c); if (mtx_owned(m)) { - KASSERT((m->lock_object.lo_flags & LO_RECURSABLE) != 0, + KASSERT((m->lock_object.lo_flags & LO_RECURSABLE) != 0 || + (opts & MTX_RECURSE) != 0, ("_mtx_lock_sleep: recursed on non-recursive mutex %s @ %s:%d\n", m->lock_object.lo_name, file, line)); + opts &= ~MTX_RECURSE; m->mtx_recurse++; atomic_set_ptr(&m->mtx_lock, MTX_RECURSED); if (LOCK_LOG_TEST(&m->lock_object, opts)) CTR1(KTR_LOCK, "_mtx_lock_sleep: %p recursing", m); return; } + opts &= ~MTX_RECURSE; #ifdef HWPMC_HOOKS PMC_SOFT_CALL( , , lock, failed);