From owner-cvs-src@FreeBSD.ORG Sun Jul 3 01:16:52 2005 Return-Path: X-Original-To: cvs-src@FreeBSD.org Delivered-To: cvs-src@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7186F16AB0F; Sun, 3 Jul 2005 00:59:36 +0000 (GMT) (envelope-from ps@mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id D03EB442A5; Sun, 3 Jul 2005 00:45:49 +0000 (GMT) (envelope-from ps@mu.org) Received: by elvis.mu.org (Postfix, from userid 1000) id 5E8D86E1AB; Sat, 2 Jul 2005 17:39:06 -0700 (PDT) X-Original-To: ps@mu.org Delivered-To: ps@mu.org Received: from mx2.freebsd.org (mx2.freebsd.org [216.136.204.119]) by elvis.mu.org (Postfix) with ESMTP id C4F055CA79 for ; Thu, 11 Nov 2004 08:15:07 -0800 (PST) Received: from hub.freebsd.org (hub.freebsd.org [216.136.204.18]) by mx2.freebsd.org (Postfix) with ESMTP id 540D458A63 for ; Thu, 11 Nov 2004 16:14:24 +0000 (GMT) (envelope-from owner-src-committers@FreeBSD.org) Received: by hub.freebsd.org (Postfix) id 6B86116A532; Thu, 11 Nov 2004 16:13:52 +0000 (GMT) Delivered-To: ps@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 538) id 9046416A4FB; Thu, 11 Nov 2004 16:13:46 +0000 (GMT) Delivered-To: src-committers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1444E16A4D7 for ; Thu, 11 Nov 2004 16:13:39 +0000 (GMT) Received: from mail5.speakeasy.net (mail5.speakeasy.net [216.254.0.205]) by mx1.FreeBSD.org (Postfix) with ESMTP id 482AB43D4C for ; Thu, 11 Nov 2004 16:13:38 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: (qmail 14127 invoked from network); 11 Nov 2004 16:13:38 -0000 Received: from dsl027-160-063.atl1.dsl.speakeasy.net (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) by mail5.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 11 Nov 2004 16:13:37 -0000 Received: from [10.50.41.235] (gw1.twc.weather.com [216.133.140.1]) (authenticated bits=0) by server.baldwin.cx (8.12.11/8.12.11) with ESMTP id iABGDLDd044012; Thu, 11 Nov 2004 11:13:33 -0500 (EST) (envelope-from jhb@FreeBSD.org) From: John Baldwin To: Don Lewis User-Agent: KMail/1.6.2 References: <200411090049.iA90nOmC055719@gw.catspoiler.org> In-Reply-To: <200411090049.iA90nOmC055719@gw.catspoiler.org> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200411100924.12039.jhb@FreeBSD.org> Sender: owner-src-committers@FreeBSD.org Precedence: bulk X-Loop: FreeBSD.ORG X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on elvis.mu.org X-Spam-Status: No, score=-7.2 required=5.0 tests=AWL,BAYES_00, DATE_IN_PAST_24_48 autolearn=no version=3.0.0 X-Spam-Level: Cc: src-committers@FreeBSD.org, alc@FreeBSD.org, cvs-src@FreeBSD.org, alfred@FreeBSD.org, cvs-all@FreeBSD.org, das@FreeBSD.org Subject: Re: cvs commit: src/sys/vm vm_zeroidle.c X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.5 List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Sun, 03 Jul 2005 01:16:52 -0000 X-Original-Date: Wed, 10 Nov 2004 09:24:12 -0500 X-List-Received-Date: Sun, 03 Jul 2005 01:16:52 -0000 On Monday 08 November 2004 07:49 pm, Don Lewis wrote: > On 8 Nov, John Baldwin wrote: > > It is no longer required to hold the mutex over cv_wait() and > > cv_signal(). I intentionally changed that so that you can do: > > > > lock() > > blah() > > unlock() > > cv_signal() > > > > and reduce the number of context switches if you preempt in cv_signal(). > > cv_wait() unlocks and relocks the mutex, so it is necessary to hold the > mutex before calling cv_wait(). It is also likely that the mutex would > have to be held to avoid having the condition being waited on going away > after the mutex was dropped and before the cv_wait() call, which could > cause the thread to miss a wakeup and sleep forever. Ok, this is fairly standard practice and nothing new here. Even spl() on 4.x required you to keep the spl raised when you called tsleep() which is similar. (That is when sleeping you should generally do: mtx_lock() while (still_need_to_sleep()) cv_wait() do_stuff mtx_unlock() > If the caller holds the mutex across the call to cv_signal(), the caller > may be able to avoid calls to cv_signal() if it knows that there are no > waiters. In most cases, the caller will want to release the mutex when > it calls cv_signal(). A version of cv_signal() that releases the mutex > after calling sleepq_lock() and before calling sleepq_signal() or > sleepq_release() would allow unnecessary calls to sleepq_signal() to be > optimized out, while avoiding the extra context switches that could be > caused by holding the mutex until after cv_signal(). You can already do this by just dropping the lock before cv_signal() now, i.e.: mtx_lock(); update_some_stuff; if (wakeup_needed) need_wakeup = 1; else need_wakeup = 0; mtx_unlock(); if (need_wakeup) cv_signal() cv_signal() itself has some optimizations so that for most cases when there are no waiters it won't bother do a sleepq_signal() but instead will just lock the spin mutex, check the waiters count, and then bail. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org