From owner-cvs-src@FreeBSD.ORG Tue Nov 9 00:49:37 2004 Return-Path: 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 00C2316A4CE; Tue, 9 Nov 2004 00:49:37 +0000 (GMT) Received: from gw.catspoiler.org (217-ip-163.nccn.net [209.79.217.163]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9E75643D1D; Tue, 9 Nov 2004 00:49:36 +0000 (GMT) (envelope-from truckman@FreeBSD.org) Received: from FreeBSD.org (mousie.catspoiler.org [192.168.101.2]) by gw.catspoiler.org (8.13.1/8.13.1) with ESMTP id iA90nOmC055719; Mon, 8 Nov 2004 16:49:28 -0800 (PST) (envelope-from truckman@FreeBSD.org) Message-Id: <200411090049.iA90nOmC055719@gw.catspoiler.org> Date: Mon, 8 Nov 2004 16:49:24 -0800 (PST) From: Don Lewis To: jhb@FreeBSD.org In-Reply-To: <200411081311.42201.jhb@FreeBSD.org> MIME-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii 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-src@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2004 00:49:37 -0000 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. 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().