netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Jason Xing <kerneljasonxing@gmail.com>,
	Eric Dumazet <edumazet@google.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Jason Xing <kernelxing@tencent.com>,
	netdev@vger.kernel.org, eric.dumazet@gmail.com
Subject: Re: [PATCH net-next 4/4] net: optimize ____napi_schedule() to avoid extra NET_RX_SOFTIRQ
Date: Thu, 30 Mar 2023 13:39:27 +0200	[thread overview]
Message-ID: <bbda81c4ca4d9d3ee458f4f2e1d58b2c3326732f.camel@redhat.com> (raw)
In-Reply-To: <CAL+tcoAEZ3nGfk6OVMY3O0W_c37cUMw94ugUNJsRaFuQz8_TbA@mail.gmail.com>

On Thu, 2023-03-30 at 17:50 +0800, Jason Xing wrote:
> On Wed, Mar 29, 2023 at 7:53 AM Eric Dumazet <edumazet@google.com> wrote:
> > 
> > ____napi_schedule() adds a napi into current cpu softnet_data poll_list,
> > then raises NET_RX_SOFTIRQ to make sure net_rx_action() will process it.
> > 
> > Idea of this patch is to not raise NET_RX_SOFTIRQ when being called indirectly
> > from net_rx_action(), because we can process poll_list from this point,
> > without going to full softirq loop.
> > 
> > This needs a change in net_rx_action() to make sure we restart
> > its main loop if sd->poll_list was updated without NET_RX_SOFTIRQ
> > being raised.
> > 
> > Signed-off-by: Eric Dumazet <edumazet@google.com>
> > Cc: Jason Xing <kernelxing@tencent.com>
> > ---
> >  net/core/dev.c | 22 ++++++++++++++++++----
> >  1 file changed, 18 insertions(+), 4 deletions(-)
> > 
> > diff --git a/net/core/dev.c b/net/core/dev.c
> > index f34ce93f2f02e7ec71f5e84d449fa99b7a882f0c..0c4b21291348d4558f036fb05842dab023f65dc3 100644
> > --- a/net/core/dev.c
> > +++ b/net/core/dev.c
> > @@ -4360,7 +4360,11 @@ static inline void ____napi_schedule(struct softnet_data *sd,
> >         }
> > 
> >         list_add_tail(&napi->poll_list, &sd->poll_list);
> > -       __raise_softirq_irqoff(NET_RX_SOFTIRQ);
> > +       /* If not called from net_rx_action()
> > +        * we have to raise NET_RX_SOFTIRQ.
> > +        */
> > +       if (!sd->in_net_rx_action)
> > +               __raise_softirq_irqoff(NET_RX_SOFTIRQ);
> >  }
> > 
> >  #ifdef CONFIG_RPS
> > @@ -6648,6 +6652,7 @@ static __latent_entropy void net_rx_action(struct softirq_action *h)
> >         LIST_HEAD(list);
> >         LIST_HEAD(repoll);
> > 
> > +start:
> >         sd->in_net_rx_action = true;
> >         local_irq_disable();
> >         list_splice_init(&sd->poll_list, &list);
> > @@ -6659,9 +6664,18 @@ static __latent_entropy void net_rx_action(struct softirq_action *h)
> >                 skb_defer_free_flush(sd);
> > 
> >                 if (list_empty(&list)) {
> > -                       sd->in_net_rx_action = false;
> > -                       if (!sd_has_rps_ipi_waiting(sd) && list_empty(&repoll))
> > -                               goto end;
> > +                       if (list_empty(&repoll)) {
> > +                               sd->in_net_rx_action = false;
> > +                               barrier();
> > +                               /* We need to check if ____napi_schedule()
> > +                                * had refilled poll_list while
> > +                                * sd->in_net_rx_action was true.
> > +                                */
> > +                               if (!list_empty(&sd->poll_list))
> > +                                       goto start;
> 
> I noticed that since we decide to go back and restart this loop, it
> would be better to check the time_limit. More than that,
> skb_defer_free_flush() can consume some time which is supposed to take
> into account.

Note that we can have a __napi_schedule() invocation with sd-
>in_net_rx_action only after executing the napi_poll() call below and
thus after the related time check (that is - after performing at least
one full iteration of the main for(;;) loop).

I don't think another check right here is needed.

Thanks,

Paolo


  reply	other threads:[~2023-03-30 11:41 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28 23:50 [PATCH net-next 0/4] net: rps/rfs improvements Eric Dumazet
2023-03-28 23:50 ` [PATCH net-next 1/4] net: napi_schedule_rps() cleanup Eric Dumazet
2023-03-28 23:50 ` [PATCH net-next 2/4] net: add softnet_data.in_net_rx_action Eric Dumazet
2023-03-28 23:50 ` [PATCH net-next 3/4] net: optimize napi_schedule_rps() Eric Dumazet
2023-03-28 23:50 ` [PATCH net-next 4/4] net: optimize ____napi_schedule() to avoid extra NET_RX_SOFTIRQ Eric Dumazet
2023-03-29 12:47   ` Yunsheng Lin
2023-03-29 15:47     ` Eric Dumazet
2023-03-30  2:33       ` Yunsheng Lin
2023-03-30  2:57         ` Eric Dumazet
2023-03-30  6:47           ` Yunsheng Lin
2023-03-30  7:36             ` Yunsheng Lin
2023-03-30  9:50   ` Jason Xing
2023-03-30 11:39     ` Paolo Abeni [this message]
2023-03-30 11:44       ` Eric Dumazet
2023-03-30 12:03       ` Jason Xing
2023-03-29  2:40 ` [PATCH net-next 0/4] net: rps/rfs improvements Jason Xing
2023-03-30  3:04 ` Jakub Kicinski
2023-03-30  3:15   ` Eric Dumazet
2023-03-30  3:39     ` Eric Dumazet
2023-03-30  3:57       ` Jakub Kicinski
2023-03-30 12:00 ` patchwork-bot+netdevbpf

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=bbda81c4ca4d9d3ee458f4f2e1d58b2c3326732f.camel@redhat.com \
    --to=pabeni@redhat.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=kerneljasonxing@gmail.com \
    --cc=kernelxing@tencent.com \
    --cc=kuba@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).