Forced noun bottom-half, soft interrupt, preemptive option

Source: Internet
Author: User

Bottom-half

http://bbs.csdn.net/topics/60226240

See in interrupts, exceptions, and system calls

Linux interrupt services are generally performed in the case of a shutdown interrupt, to avoid nesting but to control complications
Linux divides some interrupt processing into two parts, the first part is executed under the condition of shut off, has "atom" sex, and it is usually to be executed immediately after the interruption occurs, the second part is bottom half, is executing under the condition of interrupting, this part can be deferred for a period of time again, It is also possible to combine multiple interrupts bottom half together.
The bottom half makes the entire system more flexible, because some outages are lost due to the long duration of the outage and the inability of the CPU to respond to other interrupts.

Soft interrupt

http://blog.csdn.net/sxf_824/article/details/6560363

Soft interrupt is the concept of hardware interruption, which is simulated by software to realize the effect of asynchronous execution on macro. In many cases, soft interrupts and "signals" are somewhat similar, while soft interrupts are also corresponding to hard interrupts, "hard interrupts are external device-to-CPU interrupts", "soft interrupts are usually hard interrupt service program to the core of the interrupt", "signal is the kernel (or other processes) to a process interrupt" (" Linux Kernel source code scenario Analysis Chapter III).

A typical application of soft interrupts is the so-called "bottom half" (bottom half), which derives its name from the mechanism of separating the hardware interrupt processing into the "top half" and "lower half" phases: the top half runs in the context of the shielding interrupt, and is used to complete critical processing actions , while the lower half is relatively not very urgent, it is often time-consuming, so the system runs its own schedule and is not executed in the context of the interrupt service. The application of bottom half is also the reason that the excitation kernel develops the current soft interrupt mechanism, so we start with the implementation of the bottom half first.

The earliest bottom half implementation is the way to borrow the interrupt vector table, which can still be seen in the current 2.4.x kernel: ...

Before introducing Tasklet, it is necessary to first look at the earlier task queue mechanism. Obviously, the original bottom half mechanism has a few great limitations, the most important one is that the number is limited to 32, as the system hardware more and more, the application of soft interrupts more and more large, this number is obviously not enough, and, each bottom half can only hook up a function, is not enough to use. Therefore, in the 2.0.x kernel, it has been expanded with Task queue (Task queues) , which is used in 2.4.2 implementations.

As seen from the above, task queue is based on bottom half, while bottom half in v2.4.x is based on the newly introduced tasklet.
  
The main consideration in introducing Tasklet is to better support SMP and improve the utilization of SMP CPUs : Different Tasklet can run on different CPUs at the same time . In its source code comments also explained a few features, boils down to a point, that is: the same tasklet will only run on one CPU.

As you can see from the previous discussion, the task queue is based on the bottom Half,bottom half based on Tasklet, and Tasklet is based on SOFTIRQ.
  
As you can say, SOFTIRQ is the oldest bottom half thought, but on top of this "bottom half" mechanism, a larger and more complex soft interrupt subsystem has been implemented.

static inline void __cpu_raise_softirq (int cpu, int nr)

This function is used to activate the soft interrupt, which is actually the CPU number CPU of NR number of soft interrupt active position 1. This active bit will be judged in DO_SOFTIRQ (). Tasklet_schedule () and Tasklet_hi_schedule () will call this function.

Wikipedia content: Soft interrupt is the original "bottom half processing" of Linux system upgrade, on the basis of the original development of new processing methods to adapt to multi-CPU, multi-threaded soft interrupt processing.

A soft interrupt is a means of implementing a system API function call: The return address and the CPU State register contents are stacked when the function is called, and the execution of the stack returns a breakpoint after the function has finished executing. The soft interrupt call will return the address and CPU status register content stack, modify the privilege level, find the interrupt vector table according to the interrupt number, find the ISR (Interrupt service Routine) Interrupt Service routine address, jump execution.

In summary, the difference between a function call and a soft interrupt call is that the soft interrupt is much more capable of modifying the privilege level and finding the interrupt vector table, and the rest is exactly the same.

In general, soft interrupts are caused by a trigger event of the kernel mechanism (such as a process run time-out), but it is not negligible that a large number of soft interrupts are caused by hardware-related interrupts, such as when a hardware interrupt is generated by the printer port, and hardware-related hard interrupts are notified. A hard interrupt generates a soft interrupt and is sent to the operating system kernel so that the kernel wakes up the process of sleep in the printer task queue based on this soft interrupt.

Core elements constituting the soft interrupt mechanism include: 1, soft interrupt status Register soft interrupt state (Irq_stat) 2, soft interrupt vector table (SOFTIRQ_VEC) 3, Soft Interrupt Daemon Daemon Soft interrupt work engineering simulates the actual interrupt processing process, when a soft interrupt event occurs, the first need to set the corresponding interrupt tag bit, trigger the interrupt transaction, and then wake the daemon to detect the interrupt status register, if through the query found a soft interrupt transaction occurs, Then the corresponding soft interrupt Service program action () is invoked by querying the soft interrupt vector table. This is the process of soft interrupts, and the only difference from a hardware interrupt is the mapping process from the interrupt token to the Interrupt service program. After the CPU hardware interrupt occurs, the CPU needs to map the hardware interrupt request through the vector table to a specific service program, the process is hardware automatic, but the soft interrupt is not, it needs to guard the thread to implement this process, this is the software simulation interrupt, so called soft interrupt.  A soft interrupt does not preempt another soft interrupt, only a hardware interrupt can preempt the soft interrupt, so a hard interrupt can guarantee a strict time requirement. The origin of soft interrupts http://blog.chinaunix.net/uid-27717694-id-3807979.html
    1. The Linux bottom half (hereinafter referred to as BH) mechanism has two drawbacks, namely:
    2. (1) At any one time, the system can only have one CPU to execute bottom half code, to prevent two or more CPUs simultaneously to perform bottom half function and interfere with each other. The implementation of BH code is therefore strictly "serialized".
    3. (2) The BH function does not allow nesting.

These two shortcomings are insignificant in a single CPU system, but they are very deadly in SMP systems. Because the strict serialization of the BH mechanism obviously does not take full advantage of the multi-CPU characteristics of the SMP system. To this end, the Linux2.4 kernel is extended on the basis of the BH mechanism, the so-called "soft Interrupt Request" (SOFTIRQ) (Irq:interrupt requests interrupt request) mechanism.

The SOFTIRQ mechanism of 2.Linux is closely related to SMP. Therefore, the design and implementation of the whole SOFTIRQ mechanism has been implemented from the beginning to a thought: "Who triggers, who executes" (who marks,who runs), that is, the CPU that triggered the soft interrupt is responsible for performing the soft interrupt it triggered, And each CPU is triggered by its own soft interrupt and control mechanism. This design idea also makes the SOFTIRQ mechanism take full advantage of the performance and characteristics of the SMP system.

Here the system defines a total of 32 soft interrupt request descriptors. Soft interrupt vector I (0≤i≤31) corresponding to the soft interrupt request descriptor is softirq_vec[i] (above said, the quantity is not enough, now with Taskqueue). This array is a global array of systems, that is, it is shared by all CPUs. One thing to note here is that each CPU has its own trigger and control mechanism, and only performs the soft interrupt request that he triggers, but the soft interrupt service routines performed by each CPU are the same, that is, the soft interrupt service functions defined in the Execute softirq_vec[] array.

3. To implement the "who triggers, who executes" idea, it is necessary to define its own trigger and control variables for each CPU. To do this, Linux defines the data structure irq_cpustat_t in the Include/asm-i386/hardirq.h header file to describe the interrupt statistics for a CPU, which has member variables for triggering and controlling soft interrupts. The data structure irq_cpustat_t is defined as follows ...

Forced noun bottom-half, soft interrupt, preemptive option

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.