From owner-freebsd-arch@FreeBSD.ORG Wed Jan 30 00:59:57 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 8214416A418 for ; Wed, 30 Jan 2008 00:59:57 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.152]) by mx1.freebsd.org (Postfix) with ESMTP id 9379813C45A for ; Wed, 30 Jan 2008 00:59:54 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: by fg-out-1718.google.com with SMTP id 16so32307fgg.35 for ; Tue, 29 Jan 2008 16:59:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received: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; bh=xwRvjptm4qEEl3iElVUshWz8xOUfNYGxpMICAJ6u9wk=; b=uP59L7FXcNIO1EScCIaYCNITq8rxbSEevy164Vin1KMk3ajjSihnw45xDav8zGKrIWnbomIDapWdrVC9IvNHwCOm/BQv0EhJ4uKbHyVHmS7DKRUZLqG/vFwItGAp4cBAULyGtvuTwBf9Jyy3j7Jtei2adv5Wcj2DgWT0GM96hWM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=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=ZXsxup6QkPR7w+YISCjoP/+Vb5dSThFJwj+YcIoBOe3Kkb9O8QvSwYmGeIxOTPRCOdhKGWhgbxi+e31i5ThsTlV/0E8aVe9xoYrU640tY+Do0TiuMWnhNCxLqEVPlbloAnjSJg1vY2zBzGqxG9YlTiemsOsHn9nfdf7Q/HXcLyM= Received: by 10.86.28.5 with SMTP id b5mr67581fgb.79.1201654793125; Tue, 29 Jan 2008 16:59:53 -0800 (PST) Received: by 10.86.28.19 with HTTP; Tue, 29 Jan 2008 16:59:53 -0800 (PST) Message-ID: <3bbf2fe10801291659r650ec27eu5c346b1b85118713@mail.gmail.com> Date: Wed, 30 Jan 2008 01:59:53 +0100 From: "Attilio Rao" Sender: asmrookie@gmail.com To: "Jeff Roberson" In-Reply-To: <20080129143512.M957@desktop> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20080128190244.R957@desktop> <3bbf2fe10801291201n7b355205o43b648791f5ca387@mail.gmail.com> <20080129143512.M957@desktop> X-Google-Sender-Auth: 5c75ad6b3912479c 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: Wed, 30 Jan 2008 00:59:57 -0000 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 :) Attilio -- Peace can only be achieved by understanding - A. Einstein