I’ve been reading this for quite some time but doesn’t make sense to me.. Probably because I’m new to all this and still don’t understand few kernel concepts.
This was what i came up with (no error or NULL handing, it’s just for the sake of the question):
Kernel spinlocks are executed inside kernel threads, which is preemtive.
void spinlock_acquire(spinlock_t *spinlock)
{
tryagain:
while(spinlock->plock != UNLOCKED) ;
context_switch_block;
if(spinlock->plock != UNLOCKED) {
context_switch_unblock;
goto tryagain;
}
spinlock_lock(spinlock, current_thread);
context_switch_unblock;
}
Before Linux was a preemptive kernel, spinlocks on UP were basically no-ops. Once the kernel was made preemptive, a call to
preempt_disable()was added to spinlocks.So it goes more or less like this:
spin_lock_bh, which disables softirqs, tasklets, etc… (bhis for historical name, it comes from “bottom half”).spin_lock_irq*, which disables hardware interrupts.