From owner-freebsd-arch Thu Jan 3 2:25:48 2002 Delivered-To: freebsd-arch@freebsd.org Received: from rwcrmhc52.attbi.com (rwcrmhc52.attbi.com [216.148.227.88]) by hub.freebsd.org (Postfix) with ESMTP id 4F5CB37B419; Thu, 3 Jan 2002 02:25:44 -0800 (PST) Received: from peter3.wemm.org ([12.232.27.13]) by rwcrmhc52.attbi.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20020103102543.LJHP6450.rwcrmhc52.attbi.com@peter3.wemm.org>; Thu, 3 Jan 2002 10:25:43 +0000 Received: from overcee.netplex.com.au (overcee.wemm.org [10.0.0.3]) by peter3.wemm.org (8.11.0/8.11.0) with ESMTP id g03APhs32262; Thu, 3 Jan 2002 02:25:43 -0800 (PST) (envelope-from peter@wemm.org) Received: from wemm.org (localhost [127.0.0.1]) by overcee.netplex.com.au (Postfix) with ESMTP id 7737039EC; Thu, 3 Jan 2002 02:25:43 -0800 (PST) (envelope-from peter@wemm.org) X-Mailer: exmh version 2.5 07/13/2001 with nmh-1.0.4 To: Matthew Dillon Cc: John Baldwin , arch@FreeBSD.ORG, Bernd Walter , Mike Smith , Bruce Evans , Michal Mertl , Peter Jeremy Subject: Re: When to use atomic_ functions? (was: 64 bit counters) In-Reply-To: <200201030535.g035Zq062246@apollo.backplane.com> Date: Thu, 03 Jan 2002 02:25:43 -0800 From: Peter Wemm Message-Id: <20020103102543.7737039EC@overcee.netplex.com.au> 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 Matthew Dillon wrote: > :> Most of the critical section code in the system is going to be at > :> the top level. sti and cli *ARE* expensive, that's why the original > :> spl code went to such great lengths to avoid calling them. I > :> believe one or both instructions synchronizes the cpu pipeline, > :> interrupting instruction flow. It is nasty stuff. > : > :Not quite.. We went to extremes to avoid touching the ISA PIC, since that > :meant going over the 4.77Mhz (or 8Mhz) isa bus.. potentially taking many > :hundreds of cpu clock ticks per inb/outb. cli/sti is nothing compared to > :that. The spl code optimized the mask updates on the PIC, not cli/sti > :as such. The APIC is worse since it could take 40+ IO operations to set > :the complete mask, although thankfully at FSB speeds (not > :cpu core speed), not ISA speed. > : > :Cheers, > :-Peter > :-- > :Peter Wemm - peter@FreeBSD.org; peter@yahoo-inc.com; peter@netplex.com.au > > An ISA or PCI bus access is certainly expensive, but I don't see how > it applies to spl*() calls. The original spl*() implementation that we inherited caused every spl call to change the pic masks. BSDI only implemented lazy masking around BSD/OS 3.0 or so. I'm not sure exactly when bde's implementation went in (it may have got into 386bsd before the fork, or it may have been via the patchkit). We get away with simple assignment in RELENG_4 because we absolutely lock all reentrancy that can touch cpl etc with the giant mp_lock. All spl* calls are inside the giant kernel lock. Anyway, this is heading off on a tangent, but my point was the the objective of the original implementation (that we have a descendant of in RELENG_4) was to stop the spl* functions from hitting hardware, much more so than to minimize cli/sti usage. It just so happens that the implementation didn't need cli/sti very much. Places where those are used hasn't changed very much over time (ignoring the *horrible* things that were done when the APIC support was added). > The interrupt handler assembly has to > manipulate the controller no matter how spl*()'s are implemented > and that is where most of the optimizations were made (things like > AUTO_EOI and such). Since spl*() calls manipulate multiple interrupt > sources I don't think anyone would ever consider actually trying to > screw around with the PIC in spl*(), even if the PIC had been fast. It certainly used to. Many SYSV/386 commercial OS's used to up until (relatively) recently as well. This is going well off topic though. Incidently, probably 90%+ of freebsd boxes (all those that run GENERIC or similar) are essentially wire-oring the interrupt masks together due to the slip/ppp drivers in the kernel. On most of them, splanything() pretty much masks all interrupts. Check tty_imask, net_imask, and bio_imask and see for yourself (and check cambio/camnet as well). We *almost* have a boolean "interrupts on or off" state on most of these systems (not quite but almost). Cheers, -Peter -- Peter Wemm - peter@FreeBSD.org; peter@yahoo-inc.com; peter@netplex.com.au "All of this is for nothing if we don't go to the stars" - JMS/B5 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message