ArticleslgStudy

science

New API

New API is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand New API rather than just read about it. In short: New API (also referred to as NAPI) is an interface to use interrupt mitigation techniques for networking devices in the Linux kernel. Such an approach is intended to reduce the overhead of packet receiving.

Key takeaways

  • New API belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect New API to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of New API from memory before moving on to harder problems.

Reference excerpt

New API (also referred to as NAPI) is an interface to use interrupt mitigation techniques for networking devices in the Linux kernel. 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 (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 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 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 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'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 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. The pktgen traffic generator was also born around this time. Pktgen was extensively used to test NAPI scenarios not induced by real world traffic.

References

Further reading Jamal Hadi Salim; Robert Olsson; Alexey Kuznetsov (2001-11-10). Beyond softnet (PDF). 5th Annual Linux Showcase & Conference (ALS '01). pp. 165–172. Retrieved 2011-03-06. The classical NAPI paper. Jonathan Corbet (2003-04-28). "Driver porting: Network drivers". LWN.net. Retrieved 2011-03-06. Jonathan Corbet (2006-12-18). "Reworking NAPI". LWN.net. Retrieved 2011-03-06. Jonathan Corbet; Alessandro Rubini; Greg Kroah-Hartman (February 2005). "Chapter 17: Networking drivers" (PDF). Linux Device Drivers (3rd ed.). O'Reilly Media. ISBN 978-0-596-00590-0. Retrieved 2011-03-06.

External links Early NAPI work NAPI description on Linux Foundation Archived 2016-06-11 at the Wayback Machine Network overview, November 19, 2009, The Linux Foundation, by Rami Rosen (archived from the original on October 30, 2011)

Worked examples

Example 1 — a first encounter with New API

Start with the simplest possible case. Write down what New API claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to New API before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about New API ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of New API

In research
New API appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses New API in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
New API is common in secondary-school and first-year university syllabi. It links to neighbouring topics Ethernet, Interfaces of the Linux kernel, Linux drivers, so understanding it makes those chapters shorter.
In everyday life
Look for New API outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “New API” →

How to study New API in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what New API means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain New API out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is New API in simple terms?

New API (also referred to as NAPI) is an interface to use interrupt mitigation techniques for networking devices in the Linux kernel. Such an approach is intended to reduce the overhead of packet receiving.

Why does New API matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study New API?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on New API.

Tags

  • Ethernet
  • Interfaces of the Linux kernel
  • Linux drivers
  • Linux kernel features

Keep exploring