From owner-p4-projects@FreeBSD.ORG Wed Jun 28 04:45:45 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 75B5316A408; Wed, 28 Jun 2006 04:45:45 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9C11A16A400 for ; Wed, 28 Jun 2006 04:45:44 +0000 (UTC) (envelope-from kmacy@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 44C3544624 for ; Wed, 28 Jun 2006 04:45:44 +0000 (GMT) (envelope-from kmacy@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k5S4jiS0042732 for ; Wed, 28 Jun 2006 04:45:44 GMT (envelope-from kmacy@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k5S4jhjT042729 for perforce@freebsd.org; Wed, 28 Jun 2006 04:45:43 GMT (envelope-from kmacy@freebsd.org) Date: Wed, 28 Jun 2006 04:45:43 GMT Message-Id: <200606280445.k5S4jhjT042729@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to kmacy@freebsd.org using -f From: Kip Macy To: Perforce Change Reviews Cc: Subject: PERFORCE change 100185 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jun 2006 04:45:45 -0000 http://perforce.freebsd.org/chv.cgi?CH=100185 Change 100185 by kmacy@kmacy_storage:sun4v_work_sleepq on 2006/06/28 04:44:46 add support for LK_DRAIN semantics Affected files ... .. //depot/projects/kmacy_sun4v/src/sys/kern/kern_sxu.c#4 edit .. //depot/projects/kmacy_sun4v/src/sys/sys/sxu.h#3 edit Differences ... ==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_sxu.c#4 (text+ko) ==== @@ -110,6 +110,30 @@ lock_destroy(&sx->sxu_object); } + +void +_sxu_drain(struct sxu *sx, struct cv *cv_drain, const char *file, int line) +{ + mtx_lock(sx->sxu_lock); + KASSERT(sx->sxu_drain_cvp == NULL, ("sxu lock already being drained")); + KASSERT(sx->sx->sxu_xholder != curthread ("sxu draining against myself")); + WITNESS_CHECKORDER(&sx->sxu_object, LOP_NEWORDER, file, line); + + sx->sxu_drain_cvp = cv_drain; + cv_wait(cv_drain, sx->sxu_lock); + + + /* Acquire an exclusive lock. */ + sx->sxu_cnt--; + sx->sxu_xholder = curthread; + sx->sxu_drain_cvp = NULL; + + LOCK_LOG_LOCK("SLOCK", &sx->sxu_object, 0, 0, file, line); + WITNESS_LOCK(&sx->sxu_object, 0, file, line); + mtx_unlock(sx->sxu_lock); +} + + int _sxu_slock(struct sxu *sx, int timo, const char *file, int line) { @@ -132,8 +156,8 @@ if (sx->sxu_cnt < 0) lock_profile_waitstart(&waittime); while (sx->sxu_cnt < 0) { + lock_profile_obtain_lock_failed(&sx->sxu_object, &contested); sx->sxu_shrd_wcnt++; - lock_profile_obtain_lock_failed(&sx->sxu_object, &contested); if (timo) error = cv_timedwait(&sx->sxu_shrd_cv, sx->sxu_lock, timo); else @@ -273,11 +297,13 @@ if (sx->sxu_cnt == 0) lock_profile_release_lock(&sx->sxu_object); - if (sx->sxu_excl_wcnt > 0) { - if (sx->sxu_cnt == 0) - cv_signal(&sx->sxu_excl_cv); - } else if (sx->sxu_shrd_wcnt > 0) /* XXX why would shrd_wcnt be > 0 if the holder is shared? */ + + if (sx->sxu_excl_wcnt > 0 && sx->sxu_cnt == 0) + cv_signal(&sx->sxu_excl_cv); + else if (sx->sxu_shrd_wcnt > 0) /* XXX why would shrd_wcnt be > 0 if the holder is shared? */ cv_broadcast(&sx->sxu_shrd_cv); + else if (sx->sxu_drain_cvp && (sx->sx_cnt == 0)) + cv_signal(sx->sxu_drain_cvp); LOCK_LOG_LOCK("SUNLOCK", &sx->sxu_object, 0, 0, file, line); @@ -306,9 +332,10 @@ cv_broadcast(&sx->sxu_shrd_cv); else if (sx->sxu_excl_wcnt > 0) cv_signal(&sx->sxu_excl_cv); + else if (sx->sxu_drain_cvp) + cv_signal(sx->sxu_drain_cvp); LOCK_LOG_LOCK("XUNLOCK", &sx->sxu_object, 0, 0, file, line); - mtx_unlock(sx->sxu_lock); } ==== //depot/projects/kmacy_sun4v/src/sys/sys/sxu.h#3 (text+ko) ==== @@ -43,7 +43,7 @@ struct cv sxu_excl_cv; /* xlock waiters. */ int sxu_excl_wcnt; /* Number of xlock waiters. */ struct thread *sxu_xholder; /* Thread presently holding xlock. */ - struct cv sxu_drain_cv; /* drain waiter. */ + struct cv *sxu_drain_cvp; /* pointer to drain waiter (if any). */ }; #ifdef _KERNEL @@ -58,6 +58,8 @@ void _sxu_xunlock(struct sxu *sx, const char *file, int line); int _sxu_try_upgrade(struct sxu *sx, const char *file, int line); void _sxu_downgrade(struct sxu *sx, const char *file, int line); +void _sxu_drain(struct sxu *sx, struct cv *cv_drain, const char *file, int line); + #ifdef INVARIANT_SUPPORT void _sxu_assert(struct sxu *sxu, int what, const char *file, int line); #endif @@ -87,6 +89,8 @@ #define sxu_xunlock(sx) _sxu_xunlock((sx), LOCK_FILE, LOCK_LINE) #define sxu_try_upgrade(sx) _sxu_try_upgrade((sx), LOCK_FILE, LOCK_LINE) #define sxu_downgrade(sx) _sxu_downgrade((sx), LOCK_FILE, LOCK_LINE) +#define sxu_drain(sx, cv) _sxu_drain((sx), (cv), LOCK_FILE, LOCK_LINE) + #define sxu_unlock(sx) do { \ if ((sx)->sx_cnt < 0) \ sxu_xunlock(sx); \