Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 3 Jan 2002 15:20:14 -0800 (PST)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        John Baldwin <jhb@FreeBSD.ORG>
Cc:        Terry Lambert <tlambert2@mindspring.com>, Peter Jeremy <peter.jeremy@alcatel.com.au>, Michal Mertl <mime@traveller.cz>, Bruce Evans <bde@zeta.org.au>, Mike Smith <msmith@FreeBSD.ORG>, Bernd Walter <ticso@cicely8.cicely.de>, arch@FreeBSD.ORG, Alfred Perlstein <bright@mu.org>, Bernd Walter <ticso@cicely9.cicely.de>
Subject:   Re: When to use atomic_ functions? (was: 64 bit counters)
Message-ID:  <200201032320.g03NKEE73347@apollo.backplane.com>
References:   <XFMail.020103145704.jhb@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
    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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200201032320.g03NKEE73347>