From owner-cvs-all@FreeBSD.ORG Thu Nov 11 16:13:38 2004 Return-Path: Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AC7D216A4DD for ; Thu, 11 Nov 2004 16:13:38 +0000 (GMT) Received: from mail5.speakeasy.net (mail5.speakeasy.net [216.254.0.205]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4714E43D46 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 ) 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 Date: Wed, 10 Nov 2004 09:24:12 -0500 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> X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on server.baldwin.cx cc: src-committers@FreeBSD.org cc: alc@FreeBSD.org cc: cvs-src@FreeBSD.org cc: alfred@FreeBSD.org cc: cvs-all@FreeBSD.org cc: das@FreeBSD.org Subject: Re: cvs commit: src/sys/vm vm_zeroidle.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Nov 2004 16:13:38 -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