What are the advantages of NAPI over IRQ Coalesce?

As you know, there are two approaches to avoid some overhead of hardware interrupts in high-load networks, when there are too many hardware interrupts, and switching to them takes too much time. This is very important for performance and the choice of approach to the program style.

  • NAPI (new API) - Does not use hardware interrupts and polls of an Ethernet device after a certain period of time. The Linux kernel uses the default interrupt control mode and switches only to polling mode when the incoming packet stream exceeds a certain threshold.

http://en.wikipedia.org/wiki/New_API The kernel can periodically check for incoming network packets without interruption , which eliminates the overhead of handling interrupts.

  1. Combining interrupts - Uses hardware interrupts , but if an interrupt occurs, it turns off the interrupt and starts poll for a certain period of time, after which the poll ends and the interrupt is activated.

The https://en.wikipedia.org/wiki/Interrupt_coalescing method is held on which events that usually trigger a hardware interrupt are held , either until a certain amount of work is reached , or timeout timers are reached .

Both approaches do not have significant interrupt costs - this is an advantage over interrupt-driven mode.

But the second approach - Merging interrupts is more rational, because it:

  • Less latency . After the packet has appeared, it immediately tries to process it, immediately interrupts or polls if the interrupt occurred recently. The opposing NAPI will not process the frame immediately, but will wait a certain period of time for the next poll.

  • Less CPU usage . Runs a poll only if at least one packet has already appeared. But he doesn’t do the poll in vain, even if the frames were not received, as if he did NAPI.

What are the advantages of NAPI over IRQ Coalesce?

+8
performance linux interrupt linux-kernel network-programming
source share
2 answers

I see NAPI as a form of interrupt merging. I think your question may arise due to a misunderstanding of NAPI. First of all, interrupts are associated with NAPI. In addition, NAPI polling is not really “in vain”. Remember that for NAPI, the idea is that high bandwidth traffic is explosive. NAPI only "starts" after a "packet interrupt" occurs.

Here's a quick overview of how you intend to use NAPI:

The kernel starts a “packet receive interrupt” that detects a network device driver using NAPI. Then, the network device driver disables interrupts associated with receiving packets and, using NAPI, tells the Linux network subsystem to poll the device driver. The polling function is implemented by the device driver and transferred to the network subsystem and contains the device driver package handler. After a sufficient number of packets has been received or a timeout has been reached, packet interruptions are turned on again and everything starts again.

Thus, NAPI is just a centralized API on the Linux network subsystem to support interrupt collapse in order to reduce obesity. NAPI provides device driver developers with a clean infrastructure for merging with interrupts. NAPI does not work all the time, but only happens when the traffic is actually received, which makes it essentially a scheme for combining interrupts ... At least in my book.

Note All this was in the context of a network device driver using NAPI, but in fact NAPI can be used for any interrupt. This is one of the benefits of NAPI.

If in my understanding there are any errors, do not hesitate to indicate them!

+6
source share

Let them begin without napi and merging with interruptions.

First case: livelock. This means that when many interrupts are continuously dispatched from the servel process, the CPU only processes interrupts and never allows the user-level process to start and actually serve requests. To do this, we create napi that process it in hybrid mode (interupt + polling). When an interruption occurs, process it and poll for a while to resolve subsequence requests.

Second case: optimization. Before initiating an interrupt, the device will first wait a bit before delivering the interrupt to the CPU. While waiting, other requests may complete soon, and thus multiple interrupts can be combined into a single interrupt delivery, which reduces the cost of handling interrupts.

In conclusion, there is no conflict between them. And they are for different occasions, although Napi can also optimize the processor load.

Link: Principles of designing computer systems.

0
source share

All Articles