In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, Xiaobian will bring you an example analysis of Linux network packages from interruption to reception. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
linux
Since we're going to talk about it, then we'll decide the entire life of a package.
trigger an interrupt
In a non-virtualized environment, the NIC writes packets to the kernel's rx_ring queue buffer via DMA and triggers interrupts.
If VMM configures GIC ITS (Interrupt Translation Service) under virtualization environment, it establishes mapping between physical interrupt and virtual interrupt to complete interrupt virtualization, so that NIC can directly send interrupt to VM, and at the same time, NIC writes packet directly to rx_ring of VM kernel through IOMMU through IO virtualization.
Top Half
After receiving the interrupt, the CPU calls the ISR of the network card, which is the so-called interrupt handler.
allocate sk_buf into input_pkt_queue(discard if queue is full)
issue a soft interrupt NET_RX_SOFTIRQ, which can be scheduled, for example, by tasklet
Bottom Half
sk_buf is passed from input_pkt_queue to process_queue, and the handler of the network layer protocol is invoked according to the protocol type
ip_rcv performs packet checking, ip_router_input() performs routing, and determines local/forwarding/dropping
tcp_v4_rcv performs packet header check, tcp_v4_lookup queries corresponding socket and connection, if normal, tcp_prequeue puts skb into socket receiving queue
socket wakes up the process in which it is located
kqueue
Since epoll has no papers, let's talk about how kqueue does it. kqueue will get kqueue by reverse pointer according to the knote list bound by socket (each listening kqueue may create a knote), and add knote to the end of kqueue's ready queue. If a process happens to be listening at this time, it wakes up, kqueue is scanned, and all events are obtained from the ready queue to know all sockets that are ready.
The wake-up process calls the socket recv system call, or tcp_recvmsg if TCP copies data from sk_buffer
Batch
netif_receive_skb_list()
Linux's NAPI also continues to delay soft interrupt processing, waiting for it to accumulate enough skbs to poll and process all skbs at once.
SKB
Skb does not store messages directly, but stores pointers. The pointers only need to be moved to complete unpacking, while the messages themselves do not need to be modified. The upper layer stack sets the header pointer for the next layer while processing the current layer and moves the data pointer. Skb itself, meanwhile, is a queue implemented in a doubly linked list. qlen is the element length of the list, lock is the lock when adding the element.
Skb structure
When it comes to the usage of pointers, here is an impressive trick when doing OS lab, which is also the abnormal place of C pointers.
#define list_entry(ptr, type, field) \ container_of(ptr, type, field) #define container_of(ptr, type, field) \ ((type *)((void *)(ptr) - (u64)(&(((type *)(0))->field))))
(u64)(&(((type *)(0))->field))) refers to the offset of field in the structure type. By subtracting this offset, we can find the address of the parent type object where an object is located, that is, container.
In general, we will use the following method to let the list nodes wrap the data.
struct page_list_node { struct page p; struct list_node *prev; struct list_node *next; };
However, through pointer operations, you can let data wrap linked list nodes.
struct list_head { struct list_head *prev; struct list_head *next; }; struct page{ struct list_head list_node; }
In the case of only knowing the nodes of the linked list, the position of the container object can be known and extracted by means of the member offset.
list_entry(somenode,struct page,list_node);
The list_head itself can exist on any object, but their entry can point to different types depending on the parameters, which feels a bit generic.
Content from SJTU,iPads OS-16-Network
The above is a small series for everyone to share the Linux network package from interrupt to receive the example analysis, if there is just a similar doubt, may wish to refer to the above analysis to understand. If you want to know more about it, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Open the bookmark in a new tab: browser.tabs.loadBookmarksInTabs;true
© 2024 shulou.com SLNews company. All rights reserved.