From: Jakub Kicinski <kuba@kernel.org>
To: Samiullah Khawaja <skhawaja@google.com>
Cc: Wei Wang <weiwan@google.com>,
"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, netdev@vger.kernel.org
Subject: Re: [PATCH net-next v2] net: stop napi kthreads when THREADED napi is disabled
Date: Wed, 21 May 2025 15:21:47 -0700 [thread overview]
Message-ID: <20250521152147.077f1cb0@kernel.org> (raw)
In-Reply-To: <CAAywjhTjdgjz=oD0NUtp-k7Lccek-4e9wCJfMG-p0AGpDHwJiQ@mail.gmail.com>
On Wed, 21 May 2025 12:51:33 -0700 Samiullah Khawaja wrote:
> > This might suffer from the problem you highlighted earlier,
> > CPU 0 (IRQ) CPU 1 (NAPI thr) CPU 2 (config)
> >
> > ____napi_schedule()
> > if (test_bit(NAPI_STATE_THREADED))
> > if (thread) {
> >
> > kthread_stop()
> > if (state & SCHED_THREADED || !(state & SCHED)) {
> > state &= ~THREADED;
> > if (try_cmp_xchg())
> > break
> >
> > set_bit(NAPI_STATE_SCHED_THREADED)
> > wake_up_process(thread);
This got a bit line wrapped for me so can't judge :(
> > This would happen without the try_cmp_xchg logic that I added in my
> > patch in the __napi_schedule (in the fast path). __napi_schedule would
> > have to make sure that the kthread is not stopping while it is trying
> > to do SCHED. This is similar to the logic we have in
> > napi_schedule_prep that handles the STATE_DISABLE, STATE_SCHED and
> > STATE_MISSED scenarios. Also if it falls back to normal softirq, it
> > needs to make sure that the kthread is not polling at the same time.
> Discard this as the SCHED would be set in napi_schedule_prepare before
> __napi_schedule is called in IRQ, so try_cmp_xchg would return false.
> I think if the thread stops if the napi is idle(SCHED is not) set then
> it should do. This should make sure any pending SCHED_THREADED are
> also done. The existing logic in napi_schedulle_prep should handle all
> the cases.
I think we're on the same page. We're clearing the THREADED bit
(not SCHED_THREADED). Only napi_schedule() path looks at that bit,
after setting SCHED. So if we cmpxchg on a state where SCHED was
clear - we can't race with anything that cares about THREADED bit.
Just to be clear - the stopping of the thread has to be after the
proposed loop, so kthread_should_stop() does not come into play.
And FWIW my understanding is that we don't need any barriers on the
fast path (SCHED vs checking THREADED) because memory ordering is
a thing which exists only between distinct memory words.
next prev parent reply other threads:[~2025-05-21 22:21 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
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 [this message]
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=20250521152147.077f1cb0@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).