From: Jakub Kicinski <kuba@kernel.org>
To: Samiullah Khawaja <skhawaja@google.com>
Cc: "David S . Miller " <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
almasrymina@google.com, willemb@google.com, jdamato@fastly.com,
mkarsten@uwaterloo.ca, weiwan@google.com, netdev@vger.kernel.org
Subject: Re: [PATCH net-next v2] net: stop napi kthreads when THREADED napi is disabled
Date: Tue, 20 May 2025 19:09:41 -0700 [thread overview]
Message-ID: <20250520190941.56523ded@kernel.org> (raw)
In-Reply-To: <20250519224325.3117279-1-skhawaja@google.com>
On Mon, 19 May 2025 22:43:25 +0000 Samiullah Khawaja wrote:
> -/* Called with irq disabled */
> -static inline void ____napi_schedule(struct softnet_data *sd,
> - struct napi_struct *napi)
> +static inline bool ____try_napi_schedule_threaded(struct softnet_data *sd,
> + struct napi_struct *napi)
> {
> struct task_struct *thread;
> + unsigned long new, val;
>
> - lockdep_assert_irqs_disabled();
> + do {
> + val = READ_ONCE(napi->state);
> +
> + if (!(val & NAPIF_STATE_THREADED))
> + return false;
Do we really need to complicate the fastpath to make the slowpath easy?
Plus I'm not sure it works.
CPU 0 (IRQ) CPU 1 (NAPI thr) CPU 2 (config)
if (test_bit(NAPI_STATE_SCHED_THREADED))
...
____napi_schedule()
cmpxchg(...)
wake_up_process(thread);
clear_bit(NAPI_STATE_THREADED)
kthread_stop(thread)
if (kthread_should_stop())
exit
Right?
I think the shutting down thread should do this:
while (true) {
state = READ_ONCE()
// safe to clear if thread owns the NAPI,
// or NAPI is completely idle
if (state & SCHED_THREADED || !(state & SCHED)) {
state &= ~THREADED;
} else {
msleep(1);
continue;
}
if (try_cmpxchg())
break;
}
But that's just an idea, it could also be wrong... :S
next prev parent reply other threads:[~2025-05-21 2:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-19 22:43 [PATCH net-next v2] net: stop napi kthreads when THREADED napi is disabled Samiullah Khawaja
2025-05-20 0:34 ` Wei Wang
2025-05-21 2:09 ` Jakub Kicinski [this message]
2025-05-21 16:41 ` Wei Wang
2025-05-21 17:28 ` Samiullah Khawaja
2025-05-21 19:51 ` Samiullah Khawaja
2025-05-21 22:21 ` Jakub Kicinski
2025-05-21 22:50 ` Samiullah Khawaja
2025-05-29 0:04 ` Jakub Kicinski
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=20250520190941.56523ded@kernel.org \
--to=kuba@kernel.org \
--cc=almasrymina@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jdamato@fastly.com \
--cc=mkarsten@uwaterloo.ca \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=skhawaja@google.com \
--cc=weiwan@google.com \
--cc=willemb@google.com \
/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;
as well as URLs for NNTP newsgroup(s).