From owner-freebsd-arch Wed Jan 2 20:13:32 2002 Delivered-To: freebsd-arch@freebsd.org Received: from avocet.prod.itd.earthlink.net (avocet.mail.pas.earthlink.net [207.217.120.50]) by hub.freebsd.org (Postfix) with ESMTP id B45DF37B419; Wed, 2 Jan 2002 20:13:28 -0800 (PST) Received: from pool0067.cvx22-bradley.dialup.earthlink.net ([209.179.198.67] helo=mindspring.com) by avocet.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16LzFv-0004rA-00; Wed, 02 Jan 2002 20:13:27 -0800 Message-ID: <3C33DA68.8E9700D4@mindspring.com> Date: Wed, 02 Jan 2002 20:13:28 -0800 From: Terry Lambert X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Matthew Dillon Cc: John Baldwin , Peter Jeremy , Michal Mertl , Bruce Evans , Mike Smith , Bernd Walter , arch@FreeBSD.ORG Subject: Re: When to use atomic_ functions? (was: 64 bit counters) References: <200201030158.g031wWD61364@apollo.backplane.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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: > Let me put this in perspective, to show you how twisted the code > has become. > > * Because preemption can cause a thread to resume on a different cpu, > the per-cpu area pointer is not consistent and per-cpu variables > must be accessed atomically with the pointer. This is sorta bogus in general. CPU migration needs to be treated as an extraordinary event. This is why I suggested per CPU queues for scheduling, oh so long ago: it deals with the issue without causing all the complex cruft that Linux goes trough to try to get thread group affinity in the scheduler, and it makes it real easy to do negaffinity to maximize concurrency for a multithreaded program on a multi-CPU box. > * This means that obtaining 'curthread', for example, becomes relatively > non-cacheable in terms of code generation. Every time you get it you > have to re-obtain it. So a great deal of our code does this in order > to work around the lack of optimization: This has to be done anyway, or rather it's implicit anyway. I think this problem will be solving itself, eventually, and that eating the overhead is OK, for now, in the rare cases, it's really necessary. > :No. People need to write algorithms and not assume that implementation > :specifics about certain functions. There is a manpage (though it needs a bit > :of updating) for the critcal section stuff and it still accurately documents > :what the API is guaranteed to provide: protection from preemption. > > I don't understand what you are saying here. The algorithm I described > is platform independant (just as our spl mechanism was). What more can > one ask? It's great.. an API that everyone can depend on performing > well, exactly as advertised, across a multitude of platforms. I also think it's dangerous to do this. The contention domains are something I would rather be micromanaged, with a *lot* of assumptions about implementation: as many are necessary to get rid of the contention in all the common code cases -- or mitigate them as much as possible, anyway. PS: As to the "half the core locked up" comment: just implement, and whatever is best is what gets used, even if that means backing stuff out. FreeBSD has a long and glorious history of using this approach. 8-). -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message