Subject: Re: lock-free data structures
To: matthew green <mrg@eterna.com.au>
From: Garrett D'Amore <garrett_damore@tadpole.com>
List: tech-kern
Date: 01/03/2006 12:34:16
matthew green wrote:

>lock-free data structures aren't useful for all data structures.
>sometimes you need to fiddle with a LOT of stuff inside the lock,
>not just add one to a counter.
>
>as you say, this is a very machine-specific operation and while
>some code in netbsd could benefit from such a scheme i'm sure,
>making that code portable in an MI place could be difficult and
>require a lot of MD support code to be written.  in other words,
>we haven't rejected this approach but no one has made a good
>case for it or produced the code, yet
>  
>
Seems to me that some basic atomic math operations (increment,
decrement, and test versions of those) would go a long way.

In my opinion, one of the most scalable kernels around is Solaris
(proven on 100+ CPU SMP systems), and if getting locking "right" is key,
it would definitely benefit NetBSD if some developers examined the
Solaris design.

Of course, Solaris uses a hardware test-and-set operation, but they also
use something called a barrier which basically ensures a consistent view
of memory between processors when a boundary is crossed.   There is also
some use of atomic math operations, but less so.

The main thing I think that Solaris gets right is lots and lots of
little locks, coupled with software designed so that very rarely do you
ever fail to get a lock (unless as a reader for a reader/writer
lock).    The locks themselves are optimized so that the common case of
uncontended locks is very fast.

One other thing I like about Solaris is that the interrupt masking
behavior of certain kinds of locks is hidden behind the interface -- so
callers needn't normally worry about setting the processor mask
explicitly.  (The exception is for "high level" locks, which block out
the timer interrupt.  Typically hi level locks are only used for certain
hotplug devices (PCMCIA) and for serial ports.)

    -- Garrett

>
>.mrg.
>  
>


-- 
Garrett D'Amore                          http://www.tadpolecomputer.com/
Sr. Staff Engineer          Extending the Power of 64-bit UNIX Computing
Tadpole Computer, Inc.                             Phone: (951) 325-2134