Deep understanding of Linux Network Technology insider--frame reception and transmission

Source: Internet
Author: User

Frame receiving NAPI and NETIF_RX (non-NAPI)The Linux kernel obtains network frame arrival notifications in two ways: interrupts and polling. (Interrupt value device interrupts to the kernel, polling refers to the Linux kernel active polling device)In the early Linux kernel, network frames are primarily interrupted to inform the arrival of the Linux kernel frame. This is a non-napi way.In today's operating system, the Linux kernel uses the Napi method to get the message that the frame arrives. The Napi mix uses interrupts and polling. Netif_rx (non-NAPI):When each frame is received, the device sends an interrupt to the kernel. (In the case of low-traffic loads, this approach contrasts with the polling advantage.) However, due to the additional overhead required for interrupt processing, there is a lot of network overhead due to frequent processing of interrupts under high traffic loads. ) NAPI:Under low traffic load, use polling to notify the kernel network that the frame received is complete. Polling is used under high-traffic loads. Under the NAPI mechanism:For a device, when a frame is received and entered into the device input queue, the driver does not immediately send an interrupt to the kernel, but rather first determines whether the kernel is still processing the frames in the device input queue, and if so, does not send interrupts, the kernel naturally processes the frames in the device input queue.For the kernel, when a network frame is processed from a device input queue from an interrupt to a network frame, the kernel does not do other things first, but instead polls the device input queue to see if there are any other frames to process. If so, loop processing; If the frame in the device input queue has been processed, you can do something else and wait for the device driver to interrupt the next time it is sent.
NAIP Mechanism ImplementationWe know that each CPU has such a queue, which is primarily used to store incoming frame. Since he has a queue for each CPU, we do not have any locks between different CPUs to control the concurrent processing of this frame queue. We have to get the frame data at the operating system level, which is read by this data.
struct softnet_data{    struct qdisc        *output_queue;      Qdisc is the shorthand for queueing discipline, which is the queuing rule, the QoS. Here is the control of the output frame.    struct Sk_buff_head input_pkt_queue;    The input frame is saved in this queue before it is driven, (not applicable to Napi driver, Napi has its own private queue)    struct list_head    poll_list;          Represents the list of devices to be processed by the input frame.     struct Sk_buff      *completion_queue;  Represents a linked list of frames that have been successfully passed out.    struct napi_struct  backlog;            To be compatible with non-NAPI drivers.                                                                    };
Napi used the struct list_head poll_list in the structure softnet_data;            and struct napi_struct backlog; To be compatible with non-NAPI drivers.
struct Napi_struct {/* The poll_list must only is managed by the entity which * changes the state of the Napi_stat  E_sched bit. This means * Whoever atomically sets so bit can add this napi_struct * to the PER-CPU poll_list, and whoever CLE     Ars that bit * can remove from the list right before clearing the bit. */struct List_head poll_list;    Device list (devices that have new frames waiting to be processed in the ingress queue) unsigned long state;    int weight; Int (*poll) (struct napi_struct *, int);    Exit the buffer from the ingress queue of the device (Napi private queue, Softnet_data->input_pkt_queue different) #ifdef config_netpoll spinlock_t Poll_lock;    int poll_owner; #endif unsigned int gro_count;    struct Net_device *dev;    struct List_head dev_list;    struct Sk_buff *gro_list;                                                                                                           struct Sk_buff *skb; };
We need to pay attention to the Poll_list member, which indicates that there is a list of devices in the input queue that needs to be processed, which is used to support polling. The devices in this list are in the off-interrupt state. The kernel is polled at the appropriate time to process the frames received by these devices.





















Deep understanding of Linux Network Technology insider--frame reception and transmission

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.