Reputation: 1272
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;
}
Upvotes: 1
Views: 3318
Reputation: 43688
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... (bh
is for historical name, it comes from "bottom half").spin_lock_irq*
, which disables hardware interrupts.Upvotes: 9
Reputation: 8563
Spin lock is unnecessary on non-SMP. Since a spin lock disabled interrupts, it is not possible to anyone else to have the lock at that point. Once thread A disabled interrupts, is is not possible for thread B to try and acquire the same lock, as there is nothing that can cause A to lose the CPU in favor of B. As such, all spin lock does on non-SMP is, well, nothing (except if you ask it to disable interrupts).
Shachar
Upvotes: 2