Why call Preempt_disable () to close the preemption case "go" before the real lock

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.