Handling Receive packets via NAPI

NAPI stands for New API though currently it is not so new 🙂 . The network driver receives a large number of packets and at a fast pace. For each packet, if a Hardware IRQ is raised, the software driver would need to wake up for each interrupt and handle the packets. Interrupt service processing and handling packets might overwhelm the system. In order to reduce the number of receive interrupts, New API (NAPI) was developed.

It allowed to poll the irq line at fixed intervals and pull all the queued data packets in the DMA ring at single shot. Care should be taken that the poll time is not too long and it impacts sytem throughput.

NAPI performs the below two operations:

  1. Interrupt Mitigation – prevent frequent TX complete/RX interrupts from occurring. poll at frequent intervals
  2. packet throttling (in a way) – If thousands of packets are coming into the system and the processor is unable to handle the packets, since the packets are dequeued to the host only at poll time, the packets can be dropped at the network adapter itself and not be copied into the kernel for processing

For a driver to support NAPI –

  1. It should register the napi poll method to the kernel. This is done via netif_napi_add API.
  2. Once the poll method is added, napi_schedule API can be invoked in IRQ handling to schedule the NAPI poll and the kernel will invoke the NAPI callback registered during netif_napi_add
  3. napi_complete will need to be invoked once the napi work is completed to remove the work from poll
  4. napi_enable and napi_disable can be called to disable a POLL temporarily and to re-enable NAPI poll
  5. netif_napi_del unregisters the poll method

The below links provides detail on NAPI operation

  1. https://wiki.linuxfoundation.org/networking/napi
  2. https://www.kernel.org/doc/html/next/networking/napi.html

Comments

  1. Pingback: How is Data packet TX/RX handled? | Hitch Hiker's Guide to Learning

Leave a Reply

Your email address will not be published. Required fields are marked *