Re: splx()

Theodore Ts'o (tytso@mit.edu)
Wed, 19 Jul 1995 16:22:33 +0200


Date: Tue, 18 Jul 1995 08:54:05 +0300
From: Linus Torvalds <Linus.Torvalds@cs.Helsinki.FI>

[ Preacher mode on: this isn't specifically to Greg, but is just
something I feel very strongly about: ]

I say this every once in a while: spl-levels are BAD. There is _no_
good reason to use prioritized interrupts. Only broken hardware uses
them, and the right way to handle interrupts is with a bit-mask, not
with a priority. Look at the linux low-level interrupt handling
routines to see how this is done (<asm-i386/irq.h>).

It should be noted (out of fairness) that modern BSD implementations do
implement splx() has a bit-mask, not as prioritized interrupts. One
advantage of the BSD implementation, by the way, is that the way
masked interrupts are happened is in *software*, not in hardware.
Basically, how this works is that instead reprogramming the PIC, when an
masked interrupt comes in, a flag in a bitfield is set. Then when that
particular interrupt is unmasked, the interrupt handler is called out of
splx() so that the interrupt can be handled.

So while the BSD interface still uses the name splx(), in reality it
isn't a prioritized system at all. They just kept the old names to
avoid needing to make global source changes.

The advantage of such a system, by the way, is that it's much cheaper to
mask just one particular interrupt, since all you need to do is set a
bit in the interrupt mask variable in memory. In contrast, under Linux,
in order to mask an interrupt, you have to directly reprogram the
interrupt controller, which is expensive. (Even just cli()/sti() is
expensive.) A further advantage of handling interrupt masking in
software is that it may make things much easier in multiprocessor
systems.

Hence, don't write off the BSD interrupt scheme out of hand. It
actually doesn't suffer from the problems that many people think it
does; and in fact, it has a number of advantages over the current system
used by Linux.

- Ted