[PATCH] netdev: support netdev_budget for napi thread poll

tao posted 1 patch 2 months, 1 week ago
net/core/dev.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH] netdev: support netdev_budget for napi thread poll
Posted by tao 2 months, 1 week ago
For napi thread poll, we expect the net.core.netdev_budget to be available.

In the loop, poll as many packets as possible to netdev_budget

Signed-off-by: tao <wangtaowt166@163.com>
---
 net/core/dev.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 1e740faf9e78..104a17642842 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -6876,6 +6876,7 @@ static void napi_threaded_poll_loop(struct napi_struct *napi)
 	struct bpf_net_context __bpf_net_ctx, *bpf_net_ctx;
 	struct softnet_data *sd;
 	unsigned long last_qs = jiffies;
+	int budget = READ_ONCE(net_hotdata.netdev_budget);
 
 	for (;;) {
 		bool repoll = false;
@@ -6888,7 +6889,7 @@ static void napi_threaded_poll_loop(struct napi_struct *napi)
 		sd->in_napi_threaded_poll = true;
 
 		have = netpoll_poll_lock(napi);
-		__napi_poll(napi, &repoll);
+		budget -= __napi_poll(napi, &repoll);
 		netpoll_poll_unlock(have);
 
 		sd->in_napi_threaded_poll = false;
@@ -6905,6 +6906,9 @@ static void napi_threaded_poll_loop(struct napi_struct *napi)
 		if (!repoll)
 			break;
 
+		if (budget > 0)
+			continue;
+
 		rcu_softirq_qs_periodic(last_qs);
 		cond_resched();
 	}
-- 
2.25.1
Re: [PATCH] netdev: support netdev_budget for napi thread poll
Posted by Eric Dumazet 2 months, 1 week ago
On Sun, Sep 22, 2024 at 5:08 PM tao <wangtaowt166@163.com> wrote:
>
> For napi thread poll, we expect the net.core.netdev_budget to be available.
>
> In the loop, poll as many packets as possible to netdev_budget
>

We do not 'expect' net.core.netdev_budget to be available, we have
better cond_resched() calls.

Please provide reasoning, and keep in mind net-next is currently closed.