From owner-freebsd-arch Wed Jan 2 6:54:11 2002 Delivered-To: freebsd-arch@freebsd.org Received: from prg.traveller.cz (prg.traveller.cz [193.85.2.77]) by hub.freebsd.org (Postfix) with ESMTP id 7176F37B421; Wed, 2 Jan 2002 06:54:07 -0800 (PST) Received: from prg.traveller.cz (localhost [127.0.0.1]) by prg.traveller.cz (8.12.1[KQ-CZ](1)/8.12.1/pukvis) with ESMTP id g02Erxlk053667; Wed, 2 Jan 2002 15:53:59 +0100 (CET) Received: from localhost (mime@localhost) by prg.traveller.cz (8.12.1[KQ-CZ](1)/pukvis) with ESMTP id g02ErwxE053664; Wed, 2 Jan 2002 15:53:58 +0100 (CET) Date: Wed, 2 Jan 2002 15:53:55 +0100 (CET) From: Michal Mertl To: Matthew Dillon Cc: Bruce Evans , Mike Smith , Bernd Walter , Subject: Re: When to use atomic_ functions? (was: 64 bit counters) In-Reply-To: <200201012349.g01NnKA40071@apollo.backplane.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 On Tue, 1 Jan 2002, Matthew Dillon wrote: > > :On Tue, 1 Jan 2002, Mike Smith wrote: > : > :> > MBs are not needed for the variable itself, but they are making this > :> > family of functions very expensive. > :> > It's not very wise to handle counters with atomic_ functions unless > :> > the need to have MBs in them is not removed. > :> > :> It's imperative to use atomic operations for counters on SMP systems. > : > :Not true. Atomic operations for counters are not needed on SMP systems > :in at least the following cases: > :- if there is a lock that prevents other processes from accessing the > : counter > :- if the counters are per-CPU. See previous mail by someone named msmith. > : > :Bruce > > Well, I'm not sure how I got on the Cc list but I agree with Bruce > on this one. An SMP-synchronized counter increment is a ridiculous > waste of time. They should be per-cpu and then we don't care *how* > wide the counters are. Having programs like netstat, or our sysctl > mechanism, aggregate the count values is easy. > I don't know how much time will be wasted - my measurements on pII show the atomic_ operations aren't that expensive. There is a lot of counters and to have all of them for each processor would waste a bit of memory but more importantly it would require some structural changes - which may end up causing counters update being even more expensive that atomic_. Using atomic ops is easy. Even if you somewhere forget to use atomic_, if would still work - only with slight chance the value become wrong. Anyway I'm just building world with my changes (only kernel and netstat modified). I'm sure I missed several places to do some changes but at least it runs and counts (I hope I'm wrong - I used egrep a lot). Do I understand correctly that on i386 I don't need anything special for atomic_XXX_{rel|acq}? I implemented only one version (with cmpxchg8b - on SMP with lock prepended) and others are just #defines to use the same function. My patch will break other archs but I'll look at their atomic.h and see if I can make appropriate changes. -- Michal Mertl mime@traveller.cz To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message