From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 9 10:24:34 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4395416A4B3; Thu, 9 Oct 2003 10:24:34 -0700 (PDT) Received: from srv1.cosmo-project.de (srv1.cosmo-project.de [213.83.6.106]) by mx1.FreeBSD.org (Postfix) with ESMTP id 09A2A43FEC; Thu, 9 Oct 2003 10:24:31 -0700 (PDT) (envelope-from ticso@cicely12.cicely.de) Received: from cicely5.cicely.de (cicely5.cicely.de [IPv6:3ffe:400:8d0:301:200:92ff:fe9b:20e7]) (authenticated bits=0) h99HOJt2099486 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Thu, 9 Oct 2003 19:24:22 +0200 (CEST) (envelope-from ticso@cicely12.cicely.de) Received: from cicely12.cicely.de (cicely12.cicely.de [IPv6:3ffe:400:8d0:301::12]) by cicely5.cicely.de (8.12.10/8.12.10) with ESMTP id h99HOHS8036540 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 9 Oct 2003 19:24:18 +0200 (CEST) (envelope-from ticso@cicely12.cicely.de) Received: from cicely12.cicely.de (localhost [127.0.0.1]) by cicely12.cicely.de (8.12.10/8.12.10) with ESMTP id h99HOH2u039406; Thu, 9 Oct 2003 19:24:17 +0200 (CEST) (envelope-from ticso@cicely12.cicely.de) Received: (from ticso@localhost) by cicely12.cicely.de (8.12.10/8.12.10/Submit) id h99HOFAJ039394; Thu, 9 Oct 2003 19:24:15 +0200 (CEST) (envelope-from ticso) Date: Thu, 9 Oct 2003 19:24:15 +0200 From: Bernd Walter To: Peter Jeremy Message-ID: <20031009172414.GY13791@cicely12.cicely.de> References: <20031008083059.GA520@garage.freebsd.pl> <20031008114506.I63940@beagle.fokus.fraunhofer.de> <20031009093741.GA69062@server.c211-28-27-130.belrs2.nsw.optusnet.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20031009093741.GA69062@server.c211-28-27-130.belrs2.nsw.optusnet.com.au> X-Operating-System: FreeBSD cicely12.cicely.de 5.1-CURRENT alpha User-Agent: Mutt/1.5.4i cc: rwatson@freebsd.org cc: hsu@freebsd.org cc: freebsd-hackers@freebsd.org Subject: Re: Dynamic reads without locking. X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: ticso@cicely.de List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Oct 2003 17:24:34 -0000 On Thu, Oct 09, 2003 at 07:37:42PM +1000, Peter Jeremy wrote: > On Wed, Oct 08, 2003 at 11:51:06AM +0200, Harti Brandt wrote: > >You need to lock when reading if you insist on consistent data. Even a > >simple read may be non-atomic (this should be the case for 64bit > >operations on all our platforms). So you need to do > > > >mtx_lock(&foo_mtx); > >bar = foo; > >mtx_unlock(&foo_mtx); > > > >if foo is a datatype that is not guaranteed to be red atomically. For > >8-bit data you should be safe without the lock on any architecture. I'm > >not sure for 16 and 32 bit, but for 64-bit you need the look for all > >our architectures, I think. > > AFAIK, aligned 64-bit reads should be atomic on all 64-bit > architectures, ie everything except i386. Smaller aligned reads > should be atomic on all supported architectures. Unaligned reads > are not atomic anywhere. > > Note that, possibly contrary to expectations, 8-bit and 16-bit > _writes_ are not atomic on many (all?) the 64-bit architectures. > Small writes are generally done by doing a 64-bit read, insert > under mask and 64-bit write. The mask case is true - e.g. on alpha <=ev5, but it's still atomic. You write the 8 or 16 bit in a single step, but the other bits of the same 32bit memory location are loaded into a register as well and masked. Note that this is semanticaly in no way different from a CPU loading a whole cacheline to change a single byte which is what every modern system does. -- B.Walter BWCT http://www.bwct.de ticso@bwct.de info@bwct.de