From owner-svn-src-head@FreeBSD.ORG Tue Jun 25 20:23:09 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 832CDCFD; Tue, 25 Jun 2013 20:23:09 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 747C21334; Tue, 25 Jun 2013 20:23:09 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5PKN9oM041941; Tue, 25 Jun 2013 20:23:09 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r5PKN8du041933; Tue, 25 Jun 2013 20:23:08 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201306252023.r5PKN8du041933@svn.freebsd.org> From: John Baldwin Date: Tue, 25 Jun 2013 20:23:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r252212 - head/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: Tue, 25 Jun 2013 20:23:09 -0000 Author: jhb Date: Tue Jun 25 20:23:08 2013 New Revision: 252212 URL: http://svnweb.freebsd.org/changeset/base/252212 Log: A few mostly cosmetic nits to aid in debugging: - Call lock_init() first before setting any lock_object fields in lock init routines. This way if the machine panics due to a duplicate init the lock's original state is preserved. - Somewhat similarly, don't decrement td_locks and td_slocks until after an unlock operation has completed successfully. Modified: head/sys/kern/kern_lock.c head/sys/kern/kern_mutex.c head/sys/kern/kern_rwlock.c head/sys/kern/kern_sx.c Modified: head/sys/kern/kern_lock.c ============================================================================== --- head/sys/kern/kern_lock.c Tue Jun 25 20:03:06 2013 (r252211) +++ head/sys/kern/kern_lock.c Tue Jun 25 20:23:08 2013 (r252212) @@ -238,8 +238,6 @@ wakeupshlk(struct lock *lk, const char * u_int realexslp; int queue, wakeup_swapper; - TD_LOCKS_DEC(curthread); - TD_SLOCKS_DEC(curthread); WITNESS_UNLOCK(&lk->lock_object, 0, file, line); LOCK_LOG_LOCK("SUNLOCK", &lk->lock_object, 0, 0, file, line); @@ -339,6 +337,8 @@ wakeupshlk(struct lock *lk, const char * } lock_profile_release_lock(&lk->lock_object); + TD_LOCKS_DEC(curthread); + TD_SLOCKS_DEC(curthread); return (wakeup_swapper); } @@ -397,12 +397,12 @@ lockinit(struct lock *lk, int pri, const iflags |= LO_IS_VNODE; iflags |= flags & (LK_ADAPTIVE | LK_NOSHARE); + lock_init(&lk->lock_object, &lock_class_lockmgr, wmesg, NULL, iflags); lk->lk_lock = LK_UNLOCKED; lk->lk_recurse = 0; lk->lk_exslpfail = 0; lk->lk_timo = timo; lk->lk_pri = pri; - lock_init(&lk->lock_object, &lock_class_lockmgr, wmesg, NULL, iflags); STACK_ZERO(lk); } Modified: head/sys/kern/kern_mutex.c ============================================================================== --- head/sys/kern/kern_mutex.c Tue Jun 25 20:03:06 2013 (r252211) +++ head/sys/kern/kern_mutex.c Tue Jun 25 20:23:08 2013 (r252212) @@ -243,7 +243,6 @@ __mtx_unlock_flags(volatile uintptr_t *c KASSERT(LOCK_CLASS(&m->lock_object) == &lock_class_mtx_sleep, ("mtx_unlock() of spin mutex %s @ %s:%d", m->lock_object.lo_name, file, line)); - curthread->td_locks--; WITNESS_UNLOCK(&m->lock_object, opts | LOP_EXCLUSIVE, file, line); LOCK_LOG_LOCK("UNLOCK", &m->lock_object, opts, m->mtx_recurse, file, line); @@ -252,6 +251,7 @@ __mtx_unlock_flags(volatile uintptr_t *c if (m->mtx_recurse == 0) LOCKSTAT_PROFILE_RELEASE_LOCK(LS_MTX_UNLOCK_RELEASE, m); __mtx_unlock(m, curthread, opts, file, line); + curthread->td_locks--; } void @@ -894,10 +894,10 @@ _mtx_init(volatile uintptr_t *c, const c flags |= LO_NOPROFILE; /* Initialize mutex. */ + lock_init(&m->lock_object, class, name, type, flags); + m->mtx_lock = MTX_UNOWNED; m->mtx_recurse = 0; - - lock_init(&m->lock_object, class, name, type, flags); } /* Modified: head/sys/kern/kern_rwlock.c ============================================================================== --- head/sys/kern/kern_rwlock.c Tue Jun 25 20:03:06 2013 (r252211) +++ head/sys/kern/kern_rwlock.c Tue Jun 25 20:23:08 2013 (r252212) @@ -207,9 +207,9 @@ _rw_init_flags(volatile uintptr_t *c, co if (opts & RW_QUIET) flags |= LO_QUIET; + lock_init(&rw->lock_object, &lock_class_rw, name, NULL, flags); rw->rw_lock = RW_UNLOCKED; rw->rw_recurse = 0; - lock_init(&rw->lock_object, &lock_class_rw, name, NULL, flags); } void @@ -319,13 +319,13 @@ _rw_wunlock_cookie(volatile uintptr_t *c KASSERT(rw->rw_lock != RW_DESTROYED, ("rw_wunlock() of destroyed rwlock @ %s:%d", file, line)); __rw_assert(c, RA_WLOCKED, file, line); - curthread->td_locks--; WITNESS_UNLOCK(&rw->lock_object, LOP_EXCLUSIVE, file, line); LOCK_LOG_LOCK("WUNLOCK", &rw->lock_object, 0, rw->rw_recurse, file, line); if (!rw_recursed(rw)) LOCKSTAT_PROFILE_RELEASE_LOCK(LS_RW_WUNLOCK_RELEASE, rw); __rw_wunlock(rw, curthread, file, line); + curthread->td_locks--; } /* * Determines whether a new reader can acquire a lock. Succeeds if the @@ -598,8 +598,6 @@ _rw_runlock_cookie(volatile uintptr_t *c KASSERT(rw->rw_lock != RW_DESTROYED, ("rw_runlock() of destroyed rwlock @ %s:%d", file, line)); __rw_assert(c, RA_RLOCKED, file, line); - curthread->td_locks--; - curthread->td_rw_rlocks--; WITNESS_UNLOCK(&rw->lock_object, 0, file, line); LOCK_LOG_LOCK("RUNLOCK", &rw->lock_object, 0, 0, file, line); @@ -693,6 +691,8 @@ _rw_runlock_cookie(volatile uintptr_t *c break; } LOCKSTAT_PROFILE_RELEASE_LOCK(LS_RW_RUNLOCK_RELEASE, rw); + curthread->td_locks--; + curthread->td_rw_rlocks--; } /* Modified: head/sys/kern/kern_sx.c ============================================================================== --- head/sys/kern/kern_sx.c Tue Jun 25 20:03:06 2013 (r252211) +++ head/sys/kern/kern_sx.c Tue Jun 25 20:23:08 2013 (r252212) @@ -228,9 +228,9 @@ sx_init_flags(struct sx *sx, const char flags |= LO_QUIET; flags |= opts & SX_NOADAPTIVE; + lock_init(&sx->lock_object, &lock_class_sx, description, NULL, flags); sx->sx_lock = SX_LOCK_UNLOCKED; sx->sx_recurse = 0; - lock_init(&sx->lock_object, &lock_class_sx, description, NULL, flags); } void @@ -362,11 +362,11 @@ _sx_sunlock(struct sx *sx, const char *f KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, ("sx_sunlock() of destroyed sx @ %s:%d", file, line)); _sx_assert(sx, SA_SLOCKED, file, line); - curthread->td_locks--; WITNESS_UNLOCK(&sx->lock_object, 0, file, line); LOCK_LOG_LOCK("SUNLOCK", &sx->lock_object, 0, 0, file, line); __sx_sunlock(sx, file, line); LOCKSTAT_PROFILE_RELEASE_LOCK(LS_SX_SUNLOCK_RELEASE, sx); + curthread->td_locks--; } void @@ -378,13 +378,13 @@ _sx_xunlock(struct sx *sx, const char *f KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, ("sx_xunlock() of destroyed sx @ %s:%d", file, line)); _sx_assert(sx, SA_XLOCKED, file, line); - curthread->td_locks--; WITNESS_UNLOCK(&sx->lock_object, LOP_EXCLUSIVE, file, line); LOCK_LOG_LOCK("XUNLOCK", &sx->lock_object, 0, sx->sx_recurse, file, line); if (!sx_recursed(sx)) LOCKSTAT_PROFILE_RELEASE_LOCK(LS_SX_XUNLOCK_RELEASE, sx); __sx_xunlock(sx, curthread, file, line); + curthread->td_locks--; } /*