When is to preempt safe?

michi1 at michaelblizek.twilightparadox.com michi1 at michaelblizek.twilightparadox.com
Sun Oct 9 09:44:54 EDT 2011


Hi!

On 23:53 Sat 08 Oct     , Dave Hylands wrote:
> Hi Michi,
> 
> On Sat, Oct 8, 2011 at 11:29 PM, Michael Blizek
> <michi1 at michaelblizek.twilightparadox.com> wrote:
...
> > Disabling interrupts actually disables preemption as well. Preemption is
> > triggered by a timer interrupt, which cannot arrive in this case. Spinlocks
> > can be aquired both by disabling interrupts (spin_lock_irqsave) or by
> > disabling preemption (spin_lock_bh). However, you cannot use spin_lock_bh if
> > the same spin_lock is aquired in an interrupt handler. spin_lock_bh allows
> > interrupt handlers to be invoked while you are still in the critical section.
> > If the interrupt handler is processed on the same CPU as the critical section,
> > you are stuck in a deadlock.
> 
> Disabling interrupts DOES NOT disable preemption on an SMP machine. It
> only disables preemption on the core that interrupts are disabled on.

AFAIK there is no "global" preemption disable in linux. This operation would
be very slow. There is stop_machine for stuff like module loading, but I guess
this is not what you mean.

spin_lock_bh also disables preemption only on the local cpu.

	-Michi
-- 
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com



More information about the Kernelnewbies mailing list