Re: tutorial question: where mb() is needed?

Linus Torvalds (torvalds@transmeta.com)
9 Jan 1999 06:25:32 GMT


In article <Pine.LNX.3.96.990107212450.1261B-100000@laser.bogus>,
Andrea Arcangeli <andrea@e-mind.com> wrote:
>On Wed, 6 Jan 1999, Ryan Moore wrote:
>
>> Presumably all of this code isn't in a locked section for performance
>> reasons. Instead, the scheduler is relying on the fact that the scheduler
>> on another processor won't mess with this current process unless the
>> has_cpu is zero.
>
>Understood. But so what about spinlocks? Should we run a mb() a bit before
>releasing every spinlock?

No. The spinlocks themselves contain the required SMP memory
synchronization points internally: otherwise they wouldn't be very
useful as locking primitives. For example, on intel any locked memory
reference (and the spinlocks do them) will act as a memory barrier, and
that's why you don't see any extra code in asm-i386/spinlocks.h - on
other architectures the spinlocks do other things to get the same goal.

See for example the asm-alpha/spinlocks.h file, which has the proper
explicit mb() calls (on the alpha, and any other sane SMP architecture,
the memory barrier issue is separate from any issue of atomicity).

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/