Reference this article: http://blog.csdn.net/zhangskd/article/details/21992933
Essentially, an interruption is an electrical signal that, when something happens to the device, it interrupts and sends the electrical signal to the interrupt controller via the bus.
If the interrupted line is active, the interrupt controller sends the electrical signal to a specific pin on the processor. The processor then immediately stopped what he was doing,
Jumps to the entry point of the interrupt handler for interrupt processing.
(1) Hard interrupt
Generated automatically by peripherals connected to the system, such as network cards and hard drives. It is mainly used to inform the operating system peripheral state changes. For example, when a NIC receives a packet
, an interrupt is issued. The interrupt we usually refer to is a hard interrupt (HARDIRQ).
(2) Soft interrupt
In order to meet the requirements of real-time systems, interrupt processing should be as fast as possible. Linux in order to achieve this feature, when interrupts occur, hard interrupt processing those short time
The work that can be done, and the work that handles the event longer, is done after the interrupt, that is, the soft interrupt (SOFTIRQ).
(Note: bottom-half)
Soft interrupt Instruction
int is a soft interrupt instruction.
The Interrupt vector table is the corresponding table of the interrupt number and the address of the interrupt handler function.
int N-Trigger soft interrupt N. The address of the corresponding interrupt handler function is: interrupt vector table address + 4 * N.
The difference between hard interrupts and soft interrupts
A soft interrupt is generated by an execution interrupt instruction, and a hard interrupt is caused by a peripheral.
The interrupt number of the hard interrupt is provided by the interrupt controller, and the interrupt number of the soft interrupt is indicated directly by the instruction without the use of an interrupt controller.
Hard interrupts are masked and soft interrupts are not shielded. (as mentioned below, when dealing with a hard interrupt, all the same type interrupts are shielded)
The hard interrupt handler ensures that it can complete the task quickly, so that the program executes without waiting longer, called the top half.
Soft interrupt processing the unfinished work of a hard interrupt is a mechanism that is deferred and belongs to the lower part.
Switch
(1a hard interrupt switch simply disables and activates the local interrupt on the current processor: local_irq_disable (); local_irq_enable (); Save local interrupt System state suppression and activation: unsignedLongFlags;local_irq_save (flags); Local_irq_restore (flags); (2The soft interrupt switch prohibits the lower half, such as SOFTIRQ, Tasklet, and Workqueue, etc.: local_bh_disable (); local_bh_enable (); It is important to note that the lower half of the block can still be preempted by a hard interrupt. (3) to determine the interrupt status#defineIn_interrupt () (Irq_count ())//Is in a broken state (hard or soft interrupt)#defineIN_IRQ () (Hardirq_count ())//are you in a hard interrupt#defineIN_SOFTIRQ () (Softirq_count ())//are you in a soft interrupt
View Code
Soft interrupt
(1) Definition
A soft interrupt is a set of statically defined lower-half interfaces that can be executed concurrently on all processors, even if the two types are the same.
But a soft interrupt does not preempt another soft interrupt, and the only thing that can preempt a soft interrupt is a hard interrupt .
Soft interrupts are represented by the softirq_action structure:
struct softirq_action { void (*action) (struct/**/} ;
There are currently 10 registered soft interrupts, defined as a global array:
Static structsoftirq_action Softirq_vec[nr_softirqs];enum{HI_SOFTIRQ=0,/*High-priority tasklets*/Timer_softirq,/*the lower half of the timer*/Net_tx_softirq,/*Sending network packets*/Net_rx_softirq,/*Receiving Network packets*/Block_softirq,/*Block Device*/Block_iopoll_softirq, TASKLET_SOFTIRQ,/*tasklets of normal priority*/Sched_softirq,/*Dispatch Program*/Hrtimer_softirq,/*High-resolution timers*/Rcu_softirq,/*RCU Lock*/Nr_softirqs/*Ten*/};
(3) trigger soft interrupt
Call RAISE_SOFTIRQ () to trigger a soft interrupt.
The pending soft interrupts are checked and executed in the following places:
1. When returning from a hardware interrupt code
2. In the KSOFTIRQD kernel thread
3. In the code that shows the check and execution of the soft interrupt to be processed, such as in the network subsystem
Soft interrupts are performed in DO_SOFTIRQ (), regardless of the method used to evoke them. If a soft interrupt is pending,
DO_SOFTIRQ () loops through each of the corresponding handlers that call them.
Triggering soft interrupts in an interrupt handler is the most common form. The interrupt handler performs related operations on the hardware device,
The corresponding soft interrupt is then triggered, and finally exits. When the kernel finishes executing the interrupt handler, it will immediately call
Do_softirq (), the soft interrupt begins execution of the interrupt handler to complete the remaining tasks.
(4) KSOFTIRQD kernel thread
The kernel does not immediately handle a re-triggered soft interrupt.
When a large number of soft interrupts occur, the kernel wakes up a set of kernel threads to process.
These threads have the lowest priority (nice value), which prevents them from seizing resources with other important tasks.
But they will eventually be executed, so this compromise will ensure that the user program does not
Being starved of processing time and ensuring that excessive soft interrupts are eventually processed.
Each processor has one such thread, with the name Ksoftirqd/n,n as the processor number.
Interrupt nesting
Http://blog.chinaunix.net/uid-28111044-id-3398997.html
Interrupt handlers in Linux are not required to be re-entered. When a given interrupt handler is executing, the corresponding in-line disconnection is masked on all processors to prevent another new interrupt from being received on the same interrupt. Normally, all other interrupts are open, so the other interrupts on the different interrupt lines can be processed, but the current break is always forbidden. It can be seen that the same interrupt handler is never called at the same time to handle nested interrupts, which greatly simplifies the writing of interrupt handlers.
Description:Linux divides the process of processing hardware interrupts into two parts called top halves and Bottom halves the upper part of the work is a time-demanding, operating hardware, or can not be interrupted by other interrupts of the important work, this will be blocked on all processors in the current break , if this interrupt processing is sa_interrupt marked, then all local interrupts will be masked globally. The lower half will resume responding to all interrupts, which makes the system in the interrupt screen state as short as possible, and the interrupt response capability is naturally higher. The work done in the lower part is less sensitive to time, and is not hardware-independent, and can be executed later. For example, there is an example of this: said is the network card receive interrupt processing, the upper part: Interrupt Start, receive, enter interrupt handler, answer network card, copy network packet to memory Sk_buff, then the next half.
Seize
http://blog.csdn.net/vividonly/article/details/6609053
A hard interrupt can be "interrupted" by another hard interrupt with a higher priority than its own, not "interrupted" by a sibling (same hard interrupt) or a low-level hard interrupt, or "interrupted" by a soft interrupt.
Soft interrupts can be "interrupted" by a hard interrupt, but not interrupted by another soft interrupt. On one CPU, soft interrupts are always executed serially. So on a single processor, access to the soft-interrupted data structure does not require any synchronization primitives.
In accordance with Intel's microprocessor manual, synchronous interrupts and asynchronous interrupts are also known as exceptions (or software interrupts) and interrupts, respectively .
Both hard and soft interrupts can preempt (or be called interrupts) exceptions (most typically system calls), but exceptions cannot preempt hard interrupts and soft interrupts .
the kernel preemption is not allowed for hard interrupts and soft interrupts (as long as the interrupt context) is executed, in other words, process switching is never allowed in the interrupt context. (It is understood that because interrupt handlers need to be completed more quickly and interrupt handlers can be nested, the interrupt handler must not be blocked, otherwise performance is not guaranteed.)
Soft interrupts with hard interrupt & interrupt preemption nesting