View the Linux NIC driver code, softnet_data []

Source: Internet
Author: User

When I saw the NIC Driver, I didn't know it. I checked the structure and shared it below.

2. Queue Layer
What is the queue layer? Generally, when the network adapter sends and receives data, it needs to maintain a Buffer Queue to cache possible burst data, similar to the previous DMA ring buffer.
The queue layer contains a file called struct softnet_data:
Struct softnet_data
{
/* Throttle is used for congestion control. When congestion occurs, throttle is set and subsequent incoming packets are discarded */
Int throttle;
/* The congestion level returned by the netif_rx function */
Int cng_level;
Int avg_blog;
/* The softnet_data structure contains a pointer to the receiving and transmission queues. The input_pkt_queue Member points to the prepared transmission queue.
The first pointer to the sk_buffs package linked list at the network layer. The package in this queue is submitted by the netif_rx function */
Struct sk_buff_head input_pkt_queue;

Struct list_head poll_list;
Struct net_device * output_queue;
Struct sk_buff * completion_queue;

Struct net_device backlog_dev;/* sorry. 8 )*/
};
The kernel uses a variable softnet_data with the same name. It is a per-CPU variable and each CPU has one.

[I] net/CORE/dev. C [/I]

Declare_per_cpu (struct softnet_data, softnet_data); [/Code]
I found the problem here. What is the CPU? The driver is a newbie. Make sure you understand it.

Return softnet_data [this_cpu]. cng_level;

How to explain the this_cpu parameter?

A new problem occurs here, queue = & softnet_data [this_cpu]

Queue-> input_pkt_queue.qlen

Queue-> throttle is used for congestion control.CodeWhich function is used to change it?

Start from here:

If (queue-> throttle)

Goto drop;

Enqueue:

Dev_hold (SKB-> Dev );

_ Skb_queue_tail (& queue-> input_pkt_queue, SKB );

/* Runs from irqs or BH's, no need to Waka BH */

Cpu_raise_softirq (this_cpu, net_rx_softirq );

Local_irq_restore (flags );

....

Return softnet_data [this_cpu]. cng_level;

}

If (queue-> throttle ){

Queue-> throttle = 0 ;}

If the following functions have nothing to change this value, then it cannot execute this If statement;

Dev_hold (SKB-> Dev );

_ Skb_queue_tail (& queue-> input_pkt_queue, SKB );

/* Runs from irqs or BH's, no need to Waka BH */

Cpu_raise_softirq (this_cpu, net_rx_softirq );

Local_irq_restore (flags );

Let's take a look at the above functions (for future analysis)

 

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.