Linux kernel packet forwarding process (ii): Interrupt

Source: Internet
Author: User

"Copyright notice: Reprint please keep Source: Blog.csdn.net/gentleliu. E-mail: shallnew*163.com "

The kernel must process the interrupt system before processing the 2-tier packet. Setting up an interrupt system makes it possible to process thousands of frames per second.

When a frame is received, the driver indicates that the device generates a hardware interrupt on behalf of the kernel, the kernel interrupts other activities, and then invokes a handler for the driver's registration to meet the needs of the device. When a frame is received by the event, the handler queues the frame somewhere, and then notifies the kernel.
The use of polling technology can easily waste a lot of system resources, because the kernel will continue to read check if there is a frame coming.

However, using interrupts forces an interrupt to occur every time a frame is received. Will waste a lot of time on CPU processing outages. Under high flow loads. The interrupt code continues to preempt the code being processed. At some point, the input queue is full, causing the old frame to not be processed, and the new frame cannot be queued. Appears receive-livelock.
The breaking advantage is that the delay between frame acceptance and processing is very short. The disadvantage is that it does not perform well under high loads.

When the CPU receives an interrupt notification message, the handler associated with the interrupt event is called, which has a numbered representation. During the operation of the handler, the kernel is in the interrupt context (interrupt context), and the CPU serving the interrupt event is shut down and the interrupt function cannot be serviced at this time. You cannot run other processes, and the CPU is completely part of the interrupt handler and cannot be preempted. In short, the interrupt handler function is non-preemptive and is not re-entered (reentrant). This can reduce the likelihood of a competitive situation, but this has a potentially serious impact on performance.
Therefore, the interrupt handler function should be completed as soon as possible. Interrupt events can preempt the CPU first. This is due to the assumption that the operating system keeps the hardware waiting too long. Data may be lost, and there is one aspect. Assume that the kernel or user-space process must be delayed or preempted. Then no data will be lost. Therefore, the interrupt handling function is now divided into the upper and lower halves. General (1) Tasks are time-sensitive or (2) and task-related or (3) need to be guaranteed not to be interrupted by other interruptions in the upper part of the operation. The ability to postpone less urgent tasks in the lower half of the operation.

The lower part is mainly divided into soft interrupts, tasklet. Task Force column.

The bottom half of the infrastructure is: 1, the lower part of the class into the appropriate type. 2. The relationship between the type of the lower half of the register and its processing function. 3, for the lower half of the function scheduling. Ready to run. 4, notify the kernel has a scheduled BH exists.

The lower half of the kernel (linux-2.6.32) type has: (defined in include/linux/interrupt.h)

enum{    hi_softirq=0,    Timer_softirq,    Net_tx_softirq,    Net_rx_softirq,    Block_softirq,    BLOCK_IOPOLL_SOFTIRQ,    Tasklet_softirq,    Sched_softirq,    Hrtimer_softirq,    RCU_SOFTIRQ,/    * Preferable RCU should always being the last SOFTIRQ */    Nr_softirqs};

A soft IRQ is usually registered within the associated subsystem.
During kernel initialization, Softirq_init will register TASKLET_SOFTIRQ and HI_SOFTIRQ related processing functions.
void __init softirq_init (void) {    ...    OPEN_SOFTIRQ (TASKLET_SOFTIRQ, tasklet_action);    OPEN_SOFTIRQ (HI_SOFTIRQ, tasklet_hi_action);}
The network subsystem is divided into two kinds of soft IRQ. Net_tx_softirq and NET_RX_SOFTIRQ. Processing of sending packets and receiving packets, respectively. These two soft IRQ are registered in the Net_dev_init function (NET/CORE/DEV.C):
    OPEN_SOFTIRQ (NET_TX_SOFTIRQ, net_tx_action);    OPEN_SOFTIRQ (NET_RX_SOFTIRQ, net_rx_action);
The soft interrupt processing functions for sending and receiving packets are registered as Net_rx_action and net_tx_action.


Among the OPEN_SOFTIRQ implementations are:

void Open_softirq (int nr, void (*action) (struct softirq_action *)) {    softirq_vec[nr].action = action;}


Linux kernel packet forwarding process (ii): Interrupt

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.