Mutex in interrupt context in Linux

Source: Internet
Author: User
In Linux, there are two different contexts: Process context and interrupt context. There is no process context in the interrupt, but there is an interrupt context.

In Linux, there are two different contexts: Process context and interrupt context.
There is no process context in the interrupt, but there is an interrupt context. therefore, no sleep occurs in the interrupt context, that is, process switching is not allowed.
This makes it impossible to use synchronization primitives (semaphores, processes, synchronization variables, etc.) and long-term mutex primitives (this will lead to process sleep) in the interrupt context ), instead, we can only use short-term mutex primitives (such as spin locks ).

Interrupt handling on UP (single CPU system)
Mutual exclusion
If the code of an interrupt handler accesses or updates the same data structure used by the non-interrupted code (usually referred to as the benchmark code), there will be competition conditions.
Fortunately, the process that is allowed to run in the INCORE state will temporarily prohibit interruption. Therefore, as long as the benchmark code updates a data structure shared with the interrupt handler
First, stop interruption, execute the critical segment, and then re-allow interruption. The actions that prohibit and allow interruption are mutually exclusive.
When intercept mutex is adopted, the encoding must be explicitly written into the algorithm using the function.

MP (multi-CPU system)
In the MP system, interruptions can occur on any processor. At a minimum, each process receives clock interruptions, but may also receive I/O interruptions. In the MP system, the routine
SPL does not provide adequate protection because their execution affects the interrupt priority on the processor that executes them. Interruption may occur on another processor if the device driver
Increasing the number of jobs running elsewhere will create a competitive condition. Because the interrupt handler represents another entry point into the kernel.

When the data structure is shared between the baseline driver code and the interrupt handler, UP can block the interrupt to prevent competing technologies, which are insufficient in the multi-thread MP kernel.
The critical segment must be executed on a processor, and the execution of the blocking interrupt routine will only block the interruption on that processor. If an interrupt occurs on another processor, there will be
The two processors simultaneously access and may update critical resources. Since these critical segments require short-term mutual exclusion, spin locks can be used to protect data.
Related Article

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.