From owner-freebsd-arch@FreeBSD.ORG Mon Mar 6 13:45:46 2006 Return-Path: X-Original-To: arch@freebsd.org Delivered-To: freebsd-arch@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1BE5D16A420; Mon, 6 Mar 2006 13:45:46 +0000 (GMT) (envelope-from _pppp@mail.ru) Received: from f36.mail.ru (f36.mail.ru [194.67.57.74]) by mx1.FreeBSD.org (Postfix) with ESMTP id AB23743D49; Mon, 6 Mar 2006 13:45:45 +0000 (GMT) (envelope-from _pppp@mail.ru) Received: from mail by f36.mail.ru with local id 1FGG1v-000BKH-00; Mon, 06 Mar 2006 16:45:43 +0300 Received: from [81.200.14.42] by koi.mail.ru with HTTP; Mon, 06 Mar 2006 16:45:43 +0300 From: dima <_pppp@mail.ru> To: Robert Watson Mime-Version: 1.0 X-Mailer: mPOP Web-Mail 2.19 X-Originating-IP: [81.200.14.42] Date: Mon, 06 Mar 2006 16:45:43 +0300 In-Reply-To: <20060305133516.P51568@fledge.watson.org> Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 8bit Message-Id: Cc: arch@freebsd.org, Poul-Henning Kamp Subject: Re[2]: wakeup idea... X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: dima <_pppp@mail.ru> List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Mar 2006 13:45:46 -0000 >> Here is a possibly stupid idea. >> >> Historically sleep/wakeup have happened on a pointer which was just a magic >> number. >> >> In many cases, this pointer is actually a relevant datastructure. >> >> Would it possibly be an optimization to make a variant of the sleep/wakeup >> calls where the pointer points to an integer type which contains non-zero if >> anybody is actually sleeping on that address ? >> >> Anybody up for a quick prototype ? > > In principle this is part of the point of a condition variable, which > associates a struct with waitable conditions, and includes an int that > contains the number of waiters: > > struct cv { > const char *cv_description; > int cv_waiters; > }; > > Presumably the tricky bit is optimizing this such that you avoid undesirable > races. (But maybe if you call cv_signal without the condition mutex held, you > accept that race by definition?) I'm working on a new implementation of SX locks: http://wikitest.freebsd.org/moin.cgi/Usable_20lock_20implementation_20with_20SX_2dsemantics Direct handoff (as described in "Solaris Internals") seems to do the trick. You just don't need any additional mutex for wakeup process since the current owner chooses who and when to wakeup. Since CV-s and SX-es have very similar semantics I describe my ideas here. We would need 2 list-like datastructures: 1. Current holders (for proper priority propagation) 2. Current waiters (for direct handoff) The first one can be implemented as an array; the reason of such a design decision is to avoid locking at SX acquire. The second list needs to be implemented as a (sorted by priority) queue (TAILQ for now) which needs a mutex for consistency.