From owner-freebsd-arch Thu Jan 3 15:20:21 2002 Delivered-To: freebsd-arch@freebsd.org Received: from apollo.backplane.com (apollo.backplane.com [216.240.41.2]) by hub.freebsd.org (Postfix) with ESMTP id 51D4437B419; Thu, 3 Jan 2002 15:20:14 -0800 (PST) Received: (from dillon@localhost) by apollo.backplane.com (8.11.6/8.9.1) id g03NKEE73347; Thu, 3 Jan 2002 15:20:14 -0800 (PST) (envelope-from dillon) Date: Thu, 3 Jan 2002 15:20:14 -0800 (PST) From: Matthew Dillon Message-Id: <200201032320.g03NKEE73347@apollo.backplane.com> To: John Baldwin Cc: Terry Lambert , Peter Jeremy , Michal Mertl , Bruce Evans , Mike Smith , Bernd Walter , arch@FreeBSD.ORG, Alfred Perlstein , Bernd Walter Subject: Re: When to use atomic_ functions? (was: 64 bit counters) References: 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 There are a number of ways to do queue management without the use of mutexes or locks or critical sections. The easiest is to use a fixed length FIFO with a separate read and write index. struct { struct foo *fifo[64]; int read_index; int filler[(cacheline calculation)]; int write_index; int filler[(cacheline calculation)]; } Foo; If there is only one reader and one writer, only lazy synchronization is necessary and no locks or mutexes are necessary at all. If there are multiple readers or multiple writers then it is possible to use cmpexg type instructions and still avoid any locks or mutexes, though in this case it is easier to simply use a mutex. For example, if we have a per-cpu queue of pending interrupts our interrupt handler can 'write' to the queue without any sort of synchronization, mutexes, or locks, and other (idle or in-scheduler) cpu's may compete to read from the queue by obtaining a mutex. -Matt To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message