From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 9 02:40:53 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 AEF3616A4B3; Thu, 9 Oct 2003 02:40:53 -0700 (PDT) Received: from c211-28-27-130.belrs2.nsw.optusnet.com.au (c211-28-27-130.belrs2.nsw.optusnet.com.au [211.28.27.130]) by mx1.FreeBSD.org (Postfix) with ESMTP id 325B143FF2; Thu, 9 Oct 2003 02:40:52 -0700 (PDT) (envelope-from peterjeremy@optushome.com.au) Received: from server.c211-28-27-130.belrs2.nsw.optusnet.com.au (localhost.c211-28-27-130.belrs2.nsw.optusnet.com.au [127.0.0.1]) ESMTP id h999cIdb069100; Thu, 9 Oct 2003 19:38:18 +1000 (EST) peter@server.c211-28-27-130.belrs2.nsw.optusnet.com.au) Received: (from peter@localhost) (8.12.9p1/8.12.9/Submit) id h999bgnL069097; Thu, 9 Oct 2003 19:37:42 +1000 (EST) (envelope-from peter) Date: Thu, 9 Oct 2003 19:37:42 +1000 From: Peter Jeremy To: Harti Brandt Message-ID: <20031009093741.GA69062@server.c211-28-27-130.belrs2.nsw.optusnet.com.au> References: <20031008083059.GA520@garage.freebsd.pl> <20031008114506.I63940@beagle.fokus.fraunhofer.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20031008114506.I63940@beagle.fokus.fraunhofer.de> User-Agent: Mutt/1.4.1i cc: hsu@freebsd.org cc: rwatson@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 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 09:40:53 -0000 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. Peter