Transferred from: http://blog.csdn.net/kasalyn/article/details/11473885
static inline void Raw_spin_lock (raw_spinlock_t *lock)
{
Preempt_disable ();
Do_raw_spin_lock (lock);
}
Why call Preempt_disable () to close preemption before a real lock is locked?
= = "
1. If the kernel can be preempted, a single CPU
Process1 enters the kernel state through the system call, if it needs access to the critical section, it gets locked, locked, v=1 before entering the critical section, then enters the critical section
If an external interrupt occurs while the PROCESS1 is executing a critical section code in the kernel state, when the interrupt handler returns, because the kernel is preemptive, a dispatch point will appear, If there is a process process2 in the CPU's running queue that is higher than the currently interrupted process Process1, then the interrupted process will be swapped out of the processor, even if it is running in the kernel state at this time.
If the PROCESS2 also enters the kernel state through system calls and accesses the same critical section, a deadlock is formed (because the PROCESS1 with the lock will never be able to run again to release the lock)
2. If the kernel can be preempted, multi-CPU
CPU1 on the PROCESS1 through the system call into the kernel state, if it needs to access the critical section, before entering the critical section to obtain a lock, locked, v=1, and then enter the critical section
If an external interrupt occurs while the PROCESS1 is executing a critical section code in the kernel state, when the interrupt handler returns, because the kernel is preemptive, a dispatch point will appear, If a process process2 with a higher priority than the currently interrupted process Process1 in the CPU1 's running queue, the interrupted process Process1 will be swapped out of the processor, even if it is running in the kernel state at this time.
If the PROCESS3 on the CPU2 also enters the kernel state through the system call and accesses the same critical section, the deadlock is also formed
To prevent the system from entering a deadlock state, call Preempt_disable () to close the preemption before it is actually locked
Why call Preempt_disable () to close the preemption case "go" before the real lock