I am reading Linux Kernel Development recently, and I have a few questions related to disabling preemption.
In the \"Interrupt Control\" section of
preempt_disable()
doesn't disable the interrupts. It however increments the count of preempt counter. Let's say you call preempt_disable()
n times in your code path, preemption will only enable at the nth preempt_enable()
.scheduler_tick()
won't be called on system tick (no interrupt handler invoked). However, if the program triggers the schedule function, preemption will occur if preempt_disable()
was not invoked.raw_spin_lock()
doesn't disable local interrupts which may lead to deadlock. For instance, if an interrupt handler is invoked which tries to lock already held spin lock, it won't be able to unless the process itself releases it which is not possible as interrupt return wouldn't occur.
So, it's better to use raw_spin_lock_irq()
, which disables interrupts.