From mboxrd@z Thu Jan 1 00:00:00 1970 From: michi1@michaelblizek.twilightparadox.com (michi1 at michaelblizek.twilightparadox.com) Date: Sun, 9 Oct 2011 15:44:54 +0200 Subject: When is to preempt safe? In-Reply-To: References: <20111007193909.GA2281@michaelblizek.twilightparadox.com> <20111009062936.GA2325@michaelblizek.twilightparadox.com> Message-ID: <20111009134454.GB10358@grml> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org Hi! On 23:53 Sat 08 Oct , Dave Hylands wrote: > Hi Michi, > > On Sat, Oct 8, 2011 at 11:29 PM, Michael Blizek > 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