Linux Soft Interrupt Principle Analysis

Source: Internet
Author: User


Linux Soft Interrupt Principle Analysis in Linux the Soft Interrupt mechanism is used in the system for use with the strictest time requirements and the most important lower half of the interrupt. In the system design process, we all know that the interrupt context cannot handle too many things and needs to be returned quickly. Otherwise, it is easy to cause the loss of the interrupt event, which leads to a problem: who will complete the reason for the service interruption? In the frontend and backend programs, as there is only one interrupt context and one task context, the interrupt context trigger event sets the tag bit, and the task context cyclically scans the tag bit to execute the corresponding action, that is to say, after a disconnection occurs, the task is completed by the task. However, the task context is scanned and the real-time performance cannot be guaranteed. In Linux and Windows, this continuous loop task is the Soft Interrupt daemon described in this article. In Windows, processing time-consuming interrupted transactions is called the process of interruption delay, and in Linux it is called the lower half of the interrupt. Obviously, the upper half of the interrupt is used to process idle operations such as cleaning interruption, then, the lower half of the interrupt is triggered when the service program is exited to complete the specific functions.
In Linux, the lower half of the interrupt is implemented based on the Soft Interrupt mechanism. Therefore, the implementation of the lower half of the Soft Interrupt mechanism is very simple. Based on the above description, we should also be clear about why we should define a soft interrupt mechanism. One sentence is to deal with time-demanding tasks, and such a requirement occurs in the lower half of the interruptions, therefore, the implementation adopts the Soft Interrupt mechanism. Core elements of the soft interrupt mechanism composed of www.2cto.com include: 1. soft interrupt Status Register soft interrupt state (irq_stat) 2. soft interrupt vector table (softirq_vec) 3. The work project of the Soft Interrupt daemon www.2cto.com simulates the actual interrupt processing process. When a soft interrupt occurs, you must first set the corresponding interrupt tag to trigger the interrupt transaction, then wake up the daemon thread to check the interrupt State Register. If a Soft Interrupt transaction is found through the query, the soft interrupt service program action () is called through the soft interrupt vector table (). This is the Soft Interrupt process. The only difference from the hardware interrupt is the ing process from the interrupt mark to the interrupt service program. After a hardware interruption occurs, the CPU needs to map the hardware interruption request to a specific service program through the ing table. This process is completed by hardware self-motion, but the soft interruption is not, it requires a daemon thread to implement this process, which is the interrupt of software simulation, so it is called Soft Interrupt. A Soft Interrupt won't be used to seize another Soft Interrupt. Only a hardware interrupt can be used to seize the Soft Interrupt. Therefore, the soft interrupt can ensure strict time requirements. In Linux, Soft Interrupt implementation analysis can register up to 32 soft interrupts in Linux. Currently, the system uses six soft interrupts: timer processing, SCSI processing, network sending and receiving processing, and Tasklet mechanism, the tasklet mechanism is used to implement the lower half. The core data structure of Soft Interrupt is the interrupt vector table, which is defined as follows: struct softirq_action {void (* action) (struct softirq_action *); /* Soft Interrupt Service Program */void * data;/* service program input parameter */www.2cto.com}; Soft Interrupt daemon is the core of the Soft Interrupt mechanism, and its implementation process is relatively simple, you can query the Soft Interrupt status irq_stat to determine whether an event has occurred. If so, the soft interrupt vector table is reflected and the registered action function can be called. From this analysis, we can see that the execution context of the Soft Interrupt service program is Soft Interrupt daemon. In Linux, the daemon thread function of Soft Interrupt is do_softirq (). Triggering a Soft Interrupt transaction is implemented through raise_softirq (). This function sets the Soft Interrupt status bit when the interrupt is closed, and determines whether the daemon is directly awakened if it is not in the interrupt context. The list of commonly used soft interrupt functions is as follows: 1. Open_softirq registers a soft interrupt and registers the Soft Interrupt service program to the soft interrupt vector table. 2. Raise_softirq: sets the Soft Interrupt state bitmap to trigger Soft Interrupt transactions. Tasklet mechanism is used to analyze Tasklet as a soft interrupt. Considering the priority issue, it occupies the 0 and 5 soft interruptions in the vector table respectively. Www.2cto.com when the Soft Interrupt event of tasklet occurs, execute the Soft Interrupt Service Program of tasklet-action. The service program scans a tasklet task list and executes the specific service programs in the task. Here is an example to illustrate: when a user reads and writes a USB device, a hardware interruption occurs, and the hardware interruption service program constructs a tasklet_struct, in this structure, specify the method function used to complete the interrupt task (the lower half executes the function), and then attach tasklet_struct to the tasklet_struct linked list of the tasklet. This step can be completed using the tasklet_schedule function. Finally, the hardware interrupt service program exits and the CPU starts to schedule the Soft Interrupt daemon. The Soft Interrupt daemon will find that the tasklet has an event, it will execute tasklet-action, and then tasklet-action will scan the tasklet_struct linked list, execute the lower half of the specific USB interrupt service program. This is the entire process of applying tasklet to complete the implementation of the lower half of the interrupt. The tasklet implementation in www.2cto.com Linux is relatively simple, and it encapsulates an important data structure tasklet_struct. The main functions of using tasklet are listed as follows: 1. tasklet_init, initialize a tasklet_struct, of course, you can use the static initialization method. The macro is DECLARE_TASKLET. 2. tasklet_schedule: Schedule A tasklet and add the input tasklet_struct to the tasklet linked list. The Soft Interrupt mechanism in Linux simulates the hardware interrupt process, and its design idea can be fully applied in other embedded OS. Author llg521208

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.