From owner-freebsd-arch Fri Dec 28 23:41:41 2001 Delivered-To: freebsd-arch@freebsd.org Received: from mass.dis.org (mass.dis.org [216.240.45.41]) by hub.freebsd.org (Postfix) with ESMTP id 0C3E637B421; Fri, 28 Dec 2001 23:41:39 -0800 (PST) Received: from mass.dis.org (localhost [127.0.0.1]) by mass.dis.org (8.11.6/8.11.3) with ESMTP id fBT7nZF20289; Fri, 28 Dec 2001 23:49:37 -0800 (PST) (envelope-from msmith@mass.dis.org) Message-Id: <200112290749.fBT7nZF20289@mass.dis.org> X-Mailer: exmh version 2.1.1 10/15/1999 To: John Baldwin Cc: arch@FreeBSD.org Subject: Re: 64 bit counters In-reply-to: Your message of "Fri, 28 Dec 2001 23:28:18 PST." Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 28 Dec 2001 23:49:35 -0800 From: Mike Smith Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > >> > lock; addl %eax,(u_int64_t) > >> > lock; adcl $0,4(u_int64_t) > >> > >> This is all well and good, but not portable. > > > > Aren't all other architectures we support 64 bit? Not PowerPC, for example. > > On i386 even present > > form (32 bit addition) isn't atomic (no lock involved). That's not correct; these counters currently hide behind Giant. > > Anyway the code probably should be rewritten to use mutexes or atomic > > operations or whatever. I'll look at some current sources and maybe I'll > > be able to understand what are all these locks, mutexes, msleep and so on. Mutexes and atomic ops are both *expensive*. The sampled approach I described is relatively cheap (and has a known, fixed cost). > You can use cmpxchg8b on SMP systems (it's available on all machines that > support SMP I think) and use non-SMP versions otherwise where needed. You > would just implement the atomic_foo_64 versions this way. You would need to > use cmpxchg8b instead of addl/adcl for the acq and rel variants for SMP. This is probably the best way to go, though the cost of the atomic operations makes me twitchy. -- ... every activity meets with opposition, everyone who acts has his rivals and unfortunately opponents also. But not because people want to be opponents, rather because the tasks and relationships force people to take different points of view. [Dr. Fritz Todt] V I C T O R Y N O T V E N G E A N C E To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message