Here is a scenario. Let’s say that a kernel task is running on a uniprocessor system with preemption disabled. The task acquires a spin lock. Now it is executing it’s critical section. At this time, what if the time slice available for this task expires and it has to schedule out?
- Does the
spin_lock
have a mechanism to prevent this? - Can it be scheduled out? If yes, then what happens to the critical section?
- Can it be interrupted by an IRQ? (Assuming that preemption is disabled)
- Is this scenario feasible? In other words, could this scenario happen?
From the kernel code, I understand that the spin_lock is basically a nop
on a uniprocessor with preemption disabled. To be accurate, all it does is barrier()
I understand why it is a nop
(as it is a uniprocessor and no other task could be manipulating the data at that instant) but I still don’t understand how it could be uninterrupted(due to IRQs or scheduling).What am I missing here? Pointers to the Linux kernel code which indicates about this could be really helpful.
My basic assumptions:
32 bit Linux kernel