From owner-p4-projects@FreeBSD.ORG Wed Jun 28 03:37:18 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 1CFE216A4A7; Wed, 28 Jun 2006 03:37:18 +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 D73B016A414 for ; Wed, 28 Jun 2006 03:37:17 +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 8A50543D48 for ; Wed, 28 Jun 2006 03:37:17 +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 k5S3bH2X038510 for ; Wed, 28 Jun 2006 03:37:17 GMT (envelope-from kmacy@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k5S3bHh3038507 for perforce@freebsd.org; Wed, 28 Jun 2006 03:37:17 GMT (envelope-from kmacy@freebsd.org) Date: Wed, 28 Jun 2006 03:37:17 GMT Message-Id: <200606280337.k5S3bHh3038507@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 100182 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 03:37:18 -0000 http://perforce.freebsd.org/chv.cgi?CH=100182 Change 100182 by kmacy@kmacy_storage:sun4v_work_sleepq on 2006/06/28 03:36:26 add timeout functionality to sxu locks and sxu.h header as a base Affected files ... .. //depot/projects/kmacy_sun4v/src/sys/kern/kern_sxu.c#2 edit .. //depot/projects/kmacy_sun4v/src/sys/sys/sxu.h#1 add Differences ... ==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_sxu.c#2 (text+ko) ==== @@ -110,13 +110,16 @@ lock_destroy(&sx->sx_object); } -void -_sx_slock(struct sx *sx, const char *file, int line) +int +_sx_slock(struct sx *sx, int timo, const char *file, int line) { - int contested; - uint64_t waittime = 0; - + int contested, error; + uint64_t waittime; + + waittime = 0; + error = 0; + mtx_lock(sx->sx_lock); KASSERT(sx->sx_xholder != curthread, ("%s (%s): slock while xlock is held @ %s:%d\n", __func__, @@ -131,8 +134,13 @@ while (sx->sx_cnt < 0) { sx->sx_shrd_wcnt++; lock_profile_obtain_lock_failed(&sx->sx_object, &contested); - cv_wait(&sx->sx_shrd_cv, sx->sx_lock); + if (timo) + error = cv_timedwait(&sx->sx_shrd_cv, sx->sx_lock, timo); + else + cv_wait(&sx->sx_shrd_cv, sx->sx_lock); sx->sx_shrd_wcnt--; + if (error) + goto fail; } @@ -145,7 +153,9 @@ LOCK_LOG_LOCK("SLOCK", &sx->sx_object, 0, 0, file, line); WITNESS_LOCK(&sx->sx_object, 0, file, line); + fail: mtx_unlock(sx->sx_lock); + return (error); } int @@ -166,12 +176,15 @@ } } -void -_sx_xlock(struct sx *sx, const char *file, int line) +int +_sx_xlock(struct sx *sx, int timo, const char *file, int line) { - int contested; - uint64_t waittime = 0; + int contested, error; + uint64_t waittime; + + error = 0; + waittime= 0; mtx_lock(sx->sx_lock); @@ -194,8 +207,14 @@ while (sx->sx_cnt != 0) { sx->sx_excl_wcnt++; lock_profile_obtain_lock_failed(&sx->sx_object, &contested); - cv_wait(&sx->sx_excl_cv, sx->sx_lock); + if (timo) + error = cv_timedwait(&sx->sx_excl_cv, sx->sx_lock, timo); + else + cv_wait(&sx->sx_excl_cv, sx->sx_lock); sx->sx_excl_wcnt--; + + if (error) + goto fail; } MPASS(sx->sx_cnt == 0); @@ -208,7 +227,9 @@ LOCK_LOG_LOCK("XLOCK", &sx->sx_object, 0, 0, file, line); WITNESS_LOCK(&sx->sx_object, LOP_EXCLUSIVE, file, line); + fail: mtx_unlock(sx->sx_lock); + return (error); } int @@ -255,7 +276,7 @@ if (sx->sx_excl_wcnt > 0) { if (sx->sx_cnt == 0) cv_signal(&sx->sx_excl_cv); - } else if (sx->sx_shrd_wcnt > 0) + } else if (sx->sx_shrd_wcnt > 0) /* XXX why would shrd_wcnt be > 0 if the holder is shared? */ cv_broadcast(&sx->sx_shrd_cv); LOCK_LOG_LOCK("SUNLOCK", &sx->sx_object, 0, 0, file, line);