Tuesday, 3 July 2012

Linux Network Driver Interrupt Mitigation


Introduction:
NAPI ("New API") is a modification to the Linux driver packet processing framework, which is designed to improve the performance of high-speed networking. NAPI works through:
Interrupt mitigation

High-speed networking can create thousands of interrupts per second, all of which tell the system something it already knew: it has lots of packets to process. NAPI allows drivers to run with (some) interrupts disabled during times of high traffic, with a corresponding decrease in system load.

Packet throttling
When the system is overwhelmed and must drop packets, it's better if those packets are disposed of before much effort goes into processing them. NAPI-compliant drivers can often cause packets to be dropped in the network adaptor itself, before the kernel sees them at all.
NAPI was first incorporated in the 2.5/2.6 kernel. The use of NAPI is entirely optional.
Real World Example of NAPI network driver:
In driver init function:
  netif_napi_add(xxx, napi, napi_poll_func, weight)
In driver open function:
  setup the irq routine
  napi_enable(napi)
In irq routine:
  napi_schedule(napi)
In napi_poll_func:
  do the actual packet reception
  call netif_receive_skb(skb) to send packets to linux kernel for further processing. If the packet received is IP packet, it will be forwarded to linux's packet filtering framework.
  if (all packets are received)
    napi_complete(napi)

napi polling function will be called when there is sufficient packets being received on the network card. The network card must have enough RAM or DMA ring to store the packets.
  

No comments:

Post a Comment