From owner-freebsd-arch@FreeBSD.ORG Thu Jan 31 00:52:03 2008 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2D88816A46D; Thu, 31 Jan 2008 00:52:03 +0000 (UTC) (envelope-from jroberson@chesapeake.net) Received: from webaccess-cl.virtdom.com (webaccess-cl.virtdom.com [216.240.101.25]) by mx1.freebsd.org (Postfix) with ESMTP id CDCAB13C4D9; Thu, 31 Jan 2008 00:52:02 +0000 (UTC) (envelope-from jroberson@chesapeake.net) Received: from [192.168.1.107] (cpe-24-94-75-93.hawaii.res.rr.com [24.94.75.93]) (authenticated bits=0) by webaccess-cl.virtdom.com (8.13.6/8.13.6) with ESMTP id m0V0q0Ms087960; Wed, 30 Jan 2008 19:52:01 -0500 (EST) (envelope-from jroberson@chesapeake.net) Date: Wed, 30 Jan 2008 14:56:05 -1000 (HST) From: Jeff Roberson X-X-Sender: jroberson@desktop To: Attilio Rao In-Reply-To: <3bbf2fe10801291659r650ec27eu5c346b1b85118713@mail.gmail.com> Message-ID: <20080130145548.P957@desktop> References: <20080128190244.R957@desktop> <3bbf2fe10801291201n7b355205o43b648791f5ca387@mail.gmail.com> <20080129143512.M957@desktop> <3bbf2fe10801291659r650ec27eu5c346b1b85118713@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: ups@freebsd.org, arch@freebsd.org, rwatson@freebsd.org Subject: Re: rwlock patch to prefer writers and improve spinning. X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2008 00:52:03 -0000 On Wed, 30 Jan 2008, Attilio Rao wrote: > 2008/1/30, Jeff Roberson : >> On Tue, 29 Jan 2008, Attilio Rao wrote: >> >>> 2008/1/29, Jeff Roberson : >>>> http://people.freebsd.org/~jeff/rwlock.diff >>>> >>>> Attilio and I have come up with a rwlock patch that prevents writer >>>> starvation by blocking readers whenever there are writers waiting on the >>>> turnstile. >>>> >>>> To avoid deadlocks caused by recursive readers a new per-thread count of >>>> outstanding rw read locks is maintained. When a thread is known to own >>>> read locks it will bypass the pending writers checks. This could lead to >>>> writer starvation in pathological cases but will not deadlock. >>>> >>>> In addition, I have added code to optimistically spin in the write lock >>>> path when there are readers. The spin is limited by two counters. One >>>> controls the number of spins while waiting for the lock state to change >>>> and another controls the number of lock state changes we'll observe before >>>> we give up. >>>> >>>> To add these two features new flags were required. I removed the >>>> recursion flag and instead there is an extra branch in the inlined code to >>>> check the recursion count before the atomic. Another option would be to >>>> further increase the alignment of struct thread, however, I don't really >>>> think that is necessary. >>>> >>>> This has been thoroughly tested with nokia's stack but it had to be >>>> forward ported to current. Any rwlock users are encouraged to test before >>>> I commit. >>>> >>>> Feedback is welcome. >>> >>> Jeff, >>> it is not missing a kern/subr_witness.c part where some checks are axed out? >> >> Oh you are right I forgot to include some turnstile pieces as well. I >> will provide them soon. > > Gah, I meant kern/subr_turnstile.c really :) The patch is updated in place at: http://people.freebsd.org/~jeff/rwlock.diff > > Attilio > > > -- > Peace can only be achieved by understanding - A. Einstein >