All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: Yannick Vignon <yannick.vignon@oss.nxp.com>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Jose Abreu <joabreu@synopsys.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Antoine Tenart <atenart@kernel.org>,
	Alexander Lobakin <alexandr.lobakin@intel.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Paolo Abeni <pabeni@redhat.com>, Wei Wang <weiwan@google.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Yunsheng Lin <linyunsheng@huawei.com>,
	Arnd Bergmann <arnd@arndb.de>, netdev <netdev@vger.kernel.org>,
	Vladimir Oltean <olteanv@gmail.com>,
	Xiaoliang Yang <xiaoliang.yang_1@nxp.com>,
	mingkai.hu@nxp.com, Joakim Zhang <qiangqing.zhang@nxp.com>,
	sebastien.laveze@nxp.com, Yannick Vignon <yannick.vignon@nxp.com>
Subject: Re: [PATCH net-next 1/2] net: napi: wake up ksoftirqd if needed after scheduling NAPI
Date: Thu, 3 Feb 2022 15:57:17 -0800	[thread overview]
Message-ID: <CANn89i+4afh3A-5ynOQ4aQf5-G1qJFkbkPPFJnh2BdS3qZ+nyQ@mail.gmail.com> (raw)
In-Reply-To: <0ad1a438-8e29-4613-df46-f913e76a1770@oss.nxp.com>

On Thu, Feb 3, 2022 at 3:40 PM Yannick Vignon
<yannick.vignon@oss.nxp.com> wrote:
>
> On 2/3/2022 8:08 PM, Eric Dumazet wrote:
> > On Thu, Feb 3, 2022 at 11:06 AM Yannick Vignon
> > <yannick.vignon@oss.nxp.com> wrote:
> >>
> >> From: Yannick Vignon <yannick.vignon@nxp.com>
> >>
> >> If NAPI was not scheduled from interrupt or softirq,
> >> __raise_softirq_irqoff would mark the softirq pending, but not
> >> wake up ksoftirqd. With force threaded IRQs, this is
> >> compensated by the fact that the interrupt handlers are
> >> protected inside a local_bh_disable()/local_bh_enable()
> >> section, and bh_enable will call do_softirq if needed. With
> >> normal threaded IRQs however, this is no longer the case
> >> (unless the interrupt handler itself calls local_bh_enable()),
> >> whic results in a pending softirq not being handled, and the
> >> following message being printed out from tick-sched.c:
> >> "NOHZ tick-stop error: Non-RCU local softirq work is pending, handler #%02x!!!\n"
> >>
> >> Call raise_softirq_irqoff instead to make sure ksoftirqd is
> >> woken up in such a case, ensuring __napi_schedule, etc behave
> >> normally in more situations than just from an interrupt,
> >> softirq or from within a bh_disable/bh_enable section.
> >>
> >
> > This is buggy. NAPI is called from the right context.
> >
> > Can you provide a stack trace or something, so that the buggy driver
> > can be fixed ?
> >
>
> Maybe some background on how I came to this would be helpful. I have
> been chasing down sources of latencies in processing rx packets on a
> PREEMPT_RT kernel and the stmmac driver. I observed that the main ones
> were bh_dis/en sections, preventing even my high-prio, (force-)threaded
> rx irq from being handled in a timely manner. Given that explicitly
> threaded irq handlers were not enclosed in a bh_dis/en section, and that
> from what I saw the stmmac interrupt handler didn't need such a
> protection anyway, I modified the stmmac driver to request threaded
> interrupts. This worked, safe for that "NOHZ" message: because
> __napi_schedule was now called from a kernel thread context, the softirq
> was no longer triggered.
> (note that the problem solves itself when enabling threaded NAPI)
>
> Is there a rule saying we shouldn't call __napi_schedule from a regular
> kernel thread, and in particular a threaded interrupt handler?

The rule is that you need to be in a safe context before calling
__napi_schedule()

This has been the case for more than a decade.

We are not going to slow down the stack just in case a process context
does not care about BH.

Please check:

commit ec13ee80145ccb95b00e6e610044bbd94a170051
Author: Michael S. Tsirkin <mst@redhat.com>
Date:   Wed May 16 10:57:12 2012 +0300

    virtio_net: invoke softirqs after __napi_schedule


>
> >> Signed-off-by: Yannick Vignon <yannick.vignon@nxp.com>
> >> ---
> >>   net/core/dev.c | 2 +-
> >>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/net/core/dev.c b/net/core/dev.c
> >> index 1baab07820f6..f93b3173454c 100644
> >> --- a/net/core/dev.c
> >> +++ b/net/core/dev.c
> >> @@ -4239,7 +4239,7 @@ static inline void ____napi_schedule(struct softnet_data *sd,
> >>          }
> >>
> >>          list_add_tail(&napi->poll_list, &sd->poll_list);
> >> -       __raise_softirq_irqoff(NET_RX_SOFTIRQ);
> >> +       raise_softirq_irqoff(NET_RX_SOFTIRQ);
> >>   }
> >>
> >>   #ifdef CONFIG_RPS
> >> --
> >> 2.25.1
> >>
>

  reply	other threads:[~2022-02-03 23:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 18:40 [PATCH net-next 1/2] net: napi: wake up ksoftirqd if needed after scheduling NAPI Yannick Vignon
2022-02-03 18:40 ` [PATCH net-next 2/2] net: stmmac: move to threaded IRQ Yannick Vignon
2022-02-03 19:08 ` [PATCH net-next 1/2] net: napi: wake up ksoftirqd if needed after scheduling NAPI Eric Dumazet
2022-02-03 23:40   ` Yannick Vignon
2022-02-03 23:57     ` Eric Dumazet [this message]
2022-02-04  1:09     ` Jakub Kicinski
2022-02-04  8:19       ` Sebastian Andrzej Siewior
2022-02-04 15:43         ` Jakub Kicinski
2022-02-04 17:15           ` Yannick Vignon
2022-02-04 17:36             ` Jakub Kicinski
2022-02-04 17:45             ` Jakub Kicinski
2022-02-04 18:03               ` Sebastian Andrzej Siewior
2022-02-04 18:50                 ` Jakub Kicinski
2022-02-04 18:52                   ` Jakub Kicinski
2022-02-08 11:51                   ` Sebastian Andrzej Siewior
2022-02-08 15:35                     ` Jakub Kicinski
2022-02-08 17:45                       ` Sebastian Andrzej Siewior
2022-02-09  0:16                         ` Jakub Kicinski
2022-02-08 15:57                     ` Paolo Abeni
2022-02-08 18:21                       ` Sebastian Andrzej Siewior
2022-02-09 11:26                   ` Marc Kleine-Budde
2022-02-03 19:41 ` Sebastian Andrzej Siewior

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=CANn89i+4afh3A-5ynOQ4aQf5-G1qJFkbkPPFJnh2BdS3qZ+nyQ@mail.gmail.com \
    --to=edumazet@google.com \
    --cc=alexandr.lobakin@intel.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=arnd@arndb.de \
    --cc=atenart@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=davem@davemloft.net \
    --cc=joabreu@synopsys.com \
    --cc=kuba@kernel.org \
    --cc=linyunsheng@huawei.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=memxor@gmail.com \
    --cc=mingkai.hu@nxp.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=peppe.cavallaro@st.com \
    --cc=qiangqing.zhang@nxp.com \
    --cc=sebastien.laveze@nxp.com \
    --cc=weiwan@google.com \
    --cc=xiaoliang.yang_1@nxp.com \
    --cc=yannick.vignon@nxp.com \
    --cc=yannick.vignon@oss.nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.