From owner-freebsd-arch@FreeBSD.ORG Mon Aug 27 13:54:30 2007 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9F89416A418; Mon, 27 Aug 2007 13:54:30 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from speedfactory.net (mail6.speedfactory.net [66.23.216.219]) by mx1.freebsd.org (Postfix) with ESMTP id E8BF213C461; Mon, 27 Aug 2007 13:54:29 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (unverified [66.23.211.162]) by speedfactory.net (SurgeMail 3.8k2) with ESMTP id 205598043-1834499 for multiple; Mon, 27 Aug 2007 09:54:42 -0400 Received: from zion.baldwin.cx (zion.baldwin.cx [192.168.0.7]) (authenticated bits=0) by server.baldwin.cx (8.13.8/8.13.8) with ESMTP id l7RDsH9R027472; Mon, 27 Aug 2007 09:54:18 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-arch@freebsd.org Date: Mon, 27 Aug 2007 09:14:59 -0400 User-Agent: KMail/1.9.7 References: <20070818120056.GA6498@garage.freebsd.pl> <20070824142952.GA24469@hub.freebsd.org> <20070825151913.S568@10.0.0.1> In-Reply-To: <20070825151913.S568@10.0.0.1> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200708270915.00516.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [192.168.0.1]); Mon, 27 Aug 2007 09:54:19 -0400 (EDT) X-Virus-Scanned: ClamAV 0.88.3/4075/Mon Aug 27 08:49:55 2007 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx Cc: Attilio Rao , Alfred Perlstein , Pawel Jakub Dawidek Subject: Re: Lockless uidinfo. 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: Mon, 27 Aug 2007 13:54:30 -0000 On Saturday 25 August 2007 06:23:10 pm Jeff Roberson wrote: > > On Fri, 24 Aug 2007, Kris Kennaway wrote: > > > On Fri, Aug 24, 2007 at 04:09:27PM +0200, Pawel Jakub Dawidek wrote: > >> On Wed, Aug 22, 2007 at 09:02:53PM +0200, Attilio Rao wrote: > >>> 2007/8/21, Pawel Jakub Dawidek : > >>>> > >>>> New patch is here: > >>>> > >>>> http://people.freebsd.org/~pjd/patches/uidinfo_waitfree.patch > >>> > >>> --- sys/ia64/include/atomic.h.orig > >>> +++ sys/ia64/include/atomic.h > >>> @@ -370,4 +370,15 @@ > >>> > >>> #define atomic_fetchadd_int atomic_fetchadd_32 > >>> > >>> +static __inline u_long > >>> +atomic_fetchadd_long(volatile u_long *p, u_long v) > >>> +{ > >>> + u_long value; > >>> + > >>> + do { > >>> + value = *p; > >>> + } while (!atomic_cmpset_64(p, value, value + v)); > >>> + return (value); > >>> +} > >>> + > >>> > >>> In cycles like those, as you get spinning, I would arrange things in > >>> order to do a cpu_spinwait(). Like this: > >>> > >>> for (;;) { > >>> value = *p; > >>> if (atomic_cmpset_64(p, value, value + v)) > >>> break; > >>> cpu_spinwait(); > >>> } > >> > >> In this case there is no difference as this is MI ia64 code and > >> cpu_spinwait() is defined as /* nothing */ there. As a general rule, > >> this might be a good idea. > > > I don't know that these kinds of loops really need cpu_spinwait(). If you > consider that the loop condition is only triggered if a single instruction > overlaps with another thread and one thread always wins, the number of > cases where we restart more than once is negligible. I believe pjd's test > that was artificially constructed to cause as much contention as possible > still only saw 30% loop once. > > This is contrasted with spin-wait code where no-one is making any progress > while a lock is held. I think this just adds complexity to the code > without any advantage. > > The cpu_spinwait() function is meant to stop one HTT core from starving > another that is holding a lock. In this case there is no lock and so > there is no starvation possible. Actually by spinwaiting you may increase > the chance for a second loop. Agreed. cpu_spinwait() is for when we know we will have to wait at least for a little while. -- John Baldwin