HOME

TheInfoList



OR:

New API (also referred to as NAPI) is an interface to use interrupt mitigation techniques for networking devices in the
Linux kernel The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ...
. Such an approach is intended to reduce the overhead of packet receiving. The idea is to defer incoming message handling until there is a sufficient amount of them so that it is worth handling them all at once.


Motivation

A straightforward method of implementing a network driver is to interrupt the kernel by issuing an
interrupt request In a computer, an interrupt request (or IRQ) is a hardware signal sent to the processor that temporarily stops a running program and allows a special program, an interrupt handler, to run instead. Hardware interrupts are used to handle events s ...
(IRQ) for each and every incoming packet. However, servicing IRQs is costly in terms of processor resources and time. Therefore, the straightforward implementation can be very inefficient in high-speed networks, constantly interrupting the kernel with the thousands of packets per second. Overall performance of the system as well as network throughput can suffer as a result.
Polling Poll, polled, or polling may refer to: Figurative head counts * Poll, a formal election ** Election verification exit poll, a survey taken to verify election counts ** Polling, voting to make decisions or determine opinions ** Polling places o ...
is an alternative to interrupt-based processing. The kernel can periodically check for the arrival of incoming network packets without being interrupted, which eliminates the overhead of interrupt processing. Establishing an optimal polling frequency is important, however. Too frequent polling wastes CPU resources by repeatedly checking for incoming packets that have not yet arrived. On the other hand, polling too infrequently introduces latency by reducing system reactivity to incoming packets, and it may result in the loss of packets if the incoming packet buffer fills up before being processed. As a compromise, the Linux kernel uses the interrupt-driven mode by default and only switches to polling mode when the flow of incoming packets exceeds a certain threshold, known as the "weight" of the network interface.


Compliant drivers

A driver using the NAPI interface will work as follow: * Packet receive interrupts are disabled. * The driver provides a poll method to the kernel. That method will fetch all incoming packets available, on the network card or a
DMA DMA may refer to: Arts * DMA (magazine), ''DMA'' (magazine), a defunct dance music magazine * Dallas Museum of Art, an art museum in Texas, US * Danish Music Awards, an award show held in Denmark * BT Digital Music Awards, an annual event in the U ...
ring, so that they will then be handled by the kernel. * When allowed to, the kernel calls the device poll method to possibly handle many packets at once.


Advantages

* The load induced by
interrupts In digital computers, an interrupt (sometimes referred to as a trap) is a request for the processor to ''interrupt'' currently executing code (when permitted), so that the event can be processed in a timely manner. If the request is accepted, ...
is reduced even though the kernel has to poll. * Packets are less likely to be re-ordered, while out of order packet handling might be a bottleneck otherwise. * In case the kernel is unable to handle all incoming packets, the kernel does not have to do any work in order to drop them: they are simply overwritten in the
network card A network interface controller (NIC, also known as a network interface card, network adapter, LAN adapter or physical network interface, and by similar terms) is a computer hardware component that connects a computer to a computer network. Ear ...
's incoming ring buffer. Without NAPI, the kernel has to handle every incoming packet regardless of whether there is time to service it, which leads to thrashing.


History

NAPI was an over-three-year effort by Alexey Kuznetsov, Jamal Hadi Salim and Robert Olsson. Initial effort to include NAPI was met with resistance by some members of the community, however David Miller worked hard to ensure NAPI's inclusion. A lot of real world testing was done in the
Uppsala university Uppsala University ( sv, Uppsala universitet) is a public research university in Uppsala, Sweden. Founded in 1477, it is the oldest university in Sweden and the Nordic countries still in operation. The university rose to significance during ...
network before inclusion. In fact
www.slu.se
was the first production NAPI-based OS and is still powered to this day by NAPI-based Bifrost/Linux routers. Th
pktgen
traffic generator A traffic generation model is a stochastic model of the traffic flows or data sources in a communication network, for example a cellular network or a computer network. A packet generation model is a traffic generation model of the packet flows o ...
was also born around this time. Pktgen was extensively used to test NAPI scenarios not induced by real world traffic.


References


Further reading

* The classical NAPI paper. * * *


External links

* tp://robur.slu.se/pub/Linux/net-development/NAPI/ Early NAPI work
NAPI description on Linux Foundation

Network overview
November 19, 2009, The Linux Foundation, by Rami Rosen (archived from the original on October 30, 2011) {{Linux Interfaces of the Linux kernel Linux kernel features Linux drivers Ethernet