From owner-freebsd-current@FreeBSD.ORG Tue Aug 8 16:09:02 2006 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 53E5816A4E2 for ; Tue, 8 Aug 2006 16:09:02 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.236]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6070243D53 for ; Tue, 8 Aug 2006 16:09:00 +0000 (GMT) (envelope-from asmrookie@gmail.com) Received: by wx-out-0506.google.com with SMTP id i27so791017wxd for ; Tue, 08 Aug 2006 09:08:59 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=iUZZ8fulYqBGpXLvUhI0hOuHL0HWvz7y1zMXEOFwwrWZvOMEraJNXPrVgc0lIY3moc4YNpr22aoo+NJRnMJPn2BeCHD6zz4Us18YQ44V1EbsflG04P8xtCRHGNJovVtQvdslpdtgqoswahhqYVCeyVEtJuh4WHbsLKYAzg26TKI= Received: by 10.70.74.6 with SMTP id w6mr921776wxa; Tue, 08 Aug 2006 09:08:59 -0700 (PDT) Received: by 10.70.11.18 with HTTP; Tue, 8 Aug 2006 09:08:59 -0700 (PDT) Message-ID: <3bbf2fe10608080908l3c8e7c3aq1e65a610d76d189b@mail.gmail.com> Date: Tue, 8 Aug 2006 18:08:59 +0200 From: "Attilio Rao" Sender: asmrookie@gmail.com To: "Suleiman Souhlal" In-Reply-To: <44D7B7ED.5070302@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <3bbf2fe10608071227j17c4cfa6qd84e1d8e53668fda@mail.gmail.com> <44D7B7ED.5070302@FreeBSD.org> X-Google-Sender-Auth: 2680590499697724 Cc: freebsd-current@freebsd.org, freebsd-arch@freebsd.org Subject: Re: [PATCH] Adding Solaris-style "owner of records" to rwlocks X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Aug 2006 16:09:02 -0000 2006/8/8, Suleiman Souhlal : > Attilio Rao wrote: > > This is a first implementation of the owner of records concept in rwlocks. > > It allows to avoid the priority inversion problem in the current > > rwlocks implementation (for readers). > > > > The main idea (that John and I discussed) is to have as owner of > > records the first rlock'er for a "class contention". > > The implementation consists in adding two flags (RW_LOCK_OWNED and > > RW_LOCK_EXEMPTED) which are used in order to not penalyze the easy > > case, and syncronizing the operation of acquiring and dropping the > > owner of records with the turnstile spin-lock. > > The main scheme might work in this way: > > > > thread1::rlock() -> sets the owner of records > > thread2::rlock() -> checks for RW_LOCK_OWNED bit and, if it is set, go > > in the easy case > > thread3::rlock() -> checks for RW_LOCK_OWNED... > > thread4::wlock() -> blocks and land its priority to thread1 > > thread1::runlock() -> disable the owner of records (disowning the > > associated turnstile) and sets the RW_LOCK_EXEMPTED flag. In this way > > other threads will treact as an easy case. > > ... > > Aren't you missing the hard part: transferring ownership from one reader > to another? If you don't, you'll still have priority inversions as soon > as the initial reader unlocks.. Exactly, but having a complete owner switching would be: 1) too hard to achieve in terms of resource taken 2) will imply too many races and we might get a too hard function With this implementation, only the first rlock (for every class contention) will be penalyzed while the other are treacted as the easy/hard case. It doesn't completely solve the priority inversion problem, but it's the better compromise between performances/correctnes. Attilio -- Peace can only be achieved by understanding - A. Einstein