Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


Assume that interface-specific data are contained innet_device->private; this is the method used by
most network card drivers. The auxiliary functionnetdev_privis provided to access it.

Now the kernel needs to be informed that a new packet is available. A two-stage approach is required:


  1. netif_rx_schedule_prepprepares the device to be put on the poll list. Essentially, this sets
    theNAPI_STATE_SCHEDflag innapi_struct->flags.

  2. If setting this flag succeeds (it just fails if NAPI is already active), the driver must disable
    IRQs with a suitable device-specific method. Invoking__netif_rx_scheduleadds the
    device’snapi_structto the poll list and raises the softIRQNET_RX_SOFTIRQ.Thisnotifies
    the kernel to start polling innet_rx_action.


Handling the Rx SoftIRQ


After having discussed what individual device drivers are required to do for NAPI, the kernel’s
responsibilities remain to be investigated.net_rx_actionis as before the handler for the softIRQ
NET_RX_SOFTIRQ. Recall that a simplified version was shown in the preceding section. With more details
about NAPI in place, we are now prepared to discuss all the details. Figure 12-13 shows the code flow
diagram.

net_rx_action

Budget used up or
processing takes too long?

Call poll method

Decrease budget

Yes

No

Loop over all deviceson poll list work == weight Move device to end of poll list

Raise NET_RX_SOFTIRQ

Figure 12-13: Code flow diagram fornet_rx_action.

Essentially, the kernel processes all devices that are currently on the poll list by calling the device-specific
pollmethods for one after another. The device’s weight is used as the local budget, that is, the number
of packets that may be processed in a single poll step.

It must be made sure that not too much time is spent in the softIRQ handler. Processing is aborted on
two conditions:


  1. More than one jiffie has been spent in the handler.

  2. The total number of processed packetsis larger than a total budget specified
    bynetdev_budget. Usually, this is set to 300, but the value can be changed via
    /proc/sys/net/core/netdev_budget.
    This budget must not be confused with the local budget for each network device! After each
    poll step, the number of processed packets is subtracted from the global budget, and if the
    value drops below zero, the softIRQ handler is aborted.

Free download pdf