Date: Thu, 9 Oct 2003 19:24:15 +0200 From: Bernd Walter <ticso@cicely12.cicely.de> To: Peter Jeremy <peterjeremy@optushome.com.au> Cc: freebsd-hackers@freebsd.org Subject: Re: Dynamic reads without locking. Message-ID: <20031009172414.GY13791@cicely12.cicely.de> In-Reply-To: <20031009093741.GA69062@server.c211-28-27-130.belrs2.nsw.optusnet.com.au> References: <20031008083059.GA520@garage.freebsd.pl> <20031008114506.I63940@beagle.fokus.fraunhofer.de> <20031009093741.GA69062@server.c211-28-27-130.belrs2.nsw.optusnet.com.au>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031009172414.GY13791>