From 1ee7755a588c6499047c958406e9bbc83dce95a2 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Mon, 24 May 2010 05:51:00 -0400 Subject: [PATCH] RX and NAPI. --- 15net/net | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/15net/net b/15net/net index 4e0b7e7..d64afd7 100644 --- a/15net/net +++ b/15net/net @@ -91,8 +91,53 @@ * Current code already updates last time packet was transmitted * Driver should set watchdog\\_timeo and ndo\\_tx\\_timeout +# Reception + +* Usually happens in an interrupt handler +* Driver allocates skb: some drivers allocate it when setting up and arrange the + device to write into the buffers directly +* Must set skb field protocol: easily done for ethernet drivers with + eth\\_type\\_trans +* Finally, call netif\\_rx + +# NAPI + +* To allow more performance, NAPI introduces polling, avoiding too much + interrupts when load is high +* Driver disables interrupts and enables polling in its interrupt handler + when RX happens +* Network subsystem uses a softirq to do the polling +* The driver poll function disables polling and reenabled interrupts when it's + done with its hardware queue + # NAPI +* struct napi\\_struct +* netif\\_napi\\_add(dev, napi, poll\\_func, weight) +* napi\\_enable: called in open +* napi\\_disable: called in stop - awaits completion +* napi\\_schedule + - napi\\_schedule\\_prep + - \\_\\_napi\\_schedule +* napi\\_complete: called in poll when all is done +* Use netif\\_receive\\_skb instead of netif\\_rx + +# NAPI step by step + +* In the interrupt handler: + - Checks that the interrupt received is RX + - Call napi\\_schedule\\_prep to check that napi isn't already scheduled + - Disable RX + - Call \\_\\_napi\\_schedule + +# Weight and Budget + +* The weight is the start budget for the interface, usually 16 +* The poll function must not dequeue more frames than the budget +* It must call napi\\_complete if and only if it has exhausted the hardware + queues with less than the budget +* It must return the number of entries in the queue processed + # Changes in net device * Use netdev\\_priv, no priv anymore -- 2.20.1