From: David Miller <davem@davemloft.net>
To: khc@pm.waw.pl
Cc: netdev@vger.kernel.org
Subject: Re: NAPI and ->poll()
Date: Tue, 08 Jul 2008 14:24:50 -0700 (PDT) [thread overview]
Message-ID: <20080708.142450.171642381.davem@davemloft.net> (raw)
In-Reply-To: <m3vdzgfqv8.fsf@maximus.localdomain>
From: Krzysztof Halasa <khc@pm.waw.pl>
Date: Tue, 08 Jul 2008 15:27:23 +0200
> Just noticed a weird fragment in my code and want to be sure:
> The NAPI poll() method should _always_ return a number of sk_buffs
> processed, even if it calls netif_rx_complete() and then maybe
> netif_rx_reschedule()?
Yes, and the value you return lets the core layer know whether
you called netif_rx_complete() or not.
You may only do a netif_rx_complete() if you return a value
less than the given budget. This is a pretty strict requirement,
and it's described in the following comment from net/core/dev.c:
/* Drivers must not modify the NAPI state if they
* consume the entire weight. In such cases this code
* still "owns" the NAPI instance and therefore can
* move the instance around on the list at-will.
*/
if (unlikely(work == weight)) {
if (unlikely(napi_disable_pending(n)))
__napi_complete(n);
else
list_move_tail(&n->poll_list, list);
}
So, as you can see, if you consume the entire budget, your
caller assumes that it still owns the NAPI context and it is
still scheduled. Otherwise, if less than the budget is consumed,
you must netif_rx_complete().
You must make these decisions regardless of whether your hardware
says there is more work left. It must be strictly performed
based upon the work quota consumed.
One common mistake is to consume exactly the quota, and do
a netif_rx_complete() because no more RX packets are
present in the hardware. This is wrong, you must simply
return the work consumed, and let the mid-layer call you
one more time.
next prev parent reply other threads:[~2008-07-08 21:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-08 13:27 NAPI and ->poll() Krzysztof Halasa
2008-07-08 21:24 ` David Miller [this message]
2008-07-08 23:00 ` Krzysztof Halasa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080708.142450.171642381.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=khc@pm.waw.pl \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox