From owner-freebsd-arch@FreeBSD.ORG Wed May 20 19:36:50 2009 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 75FBA106566B for ; Wed, 20 May 2009 19:36:50 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 46B628FC14 for ; Wed, 20 May 2009 19:36:50 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id EEE1F46B86; Wed, 20 May 2009 15:36:49 -0400 (EDT) Received: from jhbbsd.hudson-trading.com (unknown [209.249.190.8]) by bigwig.baldwin.cx (Postfix) with ESMTPA id DC7878A028; Wed, 20 May 2009 15:36:48 -0400 (EDT) From: John Baldwin To: Jeff Roberson Date: Wed, 20 May 2009 15:24:48 -0400 User-Agent: KMail/1.9.7 References: <20090514131613.T1224@besplex.bde.org> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200905201524.49090.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Wed, 20 May 2009 15:36:48 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=4.2 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?= , arch@freebsd.org Subject: Re: lockless file descriptor lookup 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, 20 May 2009 19:36:50 -0000 On Wednesday 20 May 2009 2:59:52 pm Jeff Roberson wrote: > On Thu, 14 May 2009, Bruce Evans wrote: > > Anyway, you probably need atomics that have suitable memory barriers. > > Memory barriers must affect the compiler and make it perform refreshes > > for them to work, so you shouldn't need any volatile casts. E.g., all > > atomic store operations (including cmpset) have release semantics even > > if they aren't spelled with "_rel" or implemented using inline asm. > > On amd64 and i386, they happen to be implemented using inline asm with > > "memory" clobbers. The "memory" clobbers force refreshes of all > > non-local variables. > > So I think I need an _acq memory barrier on the atomic cmpset of the > refcount to prevent speculative loading of the fd_ofiles array pointer by > the processor and the volatile in the second dereference as I have it > now to prevent caching of the pointer by the compiler. What do you think? > > The references prior to the atomic increment have no real ordering > requirements. Only the ones afterwards need to be strict so that we can > verify the results. I think having the _acq is correct and that the "memory" clobber it contains will force the compiler to reload fd_ofiles without needing the volatile cast (and thus that you can remove the volatile cast altogether and just add the _acq barrier). -- John Baldwin