netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Alexander Lobakin <aleksander.lobakin@intel.com>,
	Eric Dumazet <edumazet@google.com>, Kees Cook <kees@kernel.org>
Cc: "Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>,
	"Daniel Xu" <dxu@dxuuu.xyz>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Toke Høiland-Jørgensen" <toke@kernel.org>,
	"Jesper Dangaard Brouer" <hawk@kernel.org>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	netdev@vger.kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Toke Høiland-Jørgensen" <toke@redhat.com>
Subject: Re: [PATCH net-next v4 1/8] net: gro: decouple GRO from the NAPI layer
Date: Fri, 7 Feb 2025 15:21:47 +0100	[thread overview]
Message-ID: <eba70511-b6eb-4ff2-ae1a-183fa626d60a@intel.com> (raw)
In-Reply-To: <3decafb9-34fe-4fb7-9203-259b813f810c@intel.com>

On 2/7/25 12:56, Alexander Lobakin wrote:
> From: Eric Dumazet <edumazet@google.com>
> Date: Thu, 6 Feb 2025 19:35:50 +0100
> 
>> On Thu, Feb 6, 2025 at 1:15 PM Alexander Lobakin
>> <aleksander.lobakin@intel.com> wrote:
>>>
>>> From: Eric Dumazet <edumazet@google.com>
>>> Date: Wed, 5 Feb 2025 18:48:50 +0100
>>>
>>>> On Wed, Feb 5, 2025 at 5:46 PM Alexander Lobakin
>>>> <aleksander.lobakin@intel.com> wrote:
>>>>>
>>>>> In fact, these two are not tied closely to each other. The only
>>>>> requirements to GRO are to use it in the BH context and have some
>>>>> sane limits on the packet batches, e.g. NAPI has a limit of its
>>>>> budget (64/8/etc.).
>>>>> Move purely GRO fields into a new tagged group, &gro_node. Embed it
>>>>> into &napi_struct and adjust all the references. napi_id doesn't
>>>>> really belong to GRO, but:
>>>>>
>>>>> 1. struct gro_node has a 4-byte padding at the end anyway. If you
>>>>>     leave napi_id outside, struct napi_struct takes additional 8 bytes
>>>>>     (u32 napi_id + another 4-byte padding).
>>>>> 2. gro_receive_skb() uses it to mark skbs. We don't want to split it
>>>>>     into two functions or add an `if`, as this would be less efficient,
>>>>>     but we need it to be NAPI-independent. The current approach doesn't
>>>>>     change anything for NAPI-backed GROs; for standalone ones (which
>>>>>     are less important currently), the embedded napi_id will be just
>>>>>     zero => no-op.
>>>>>
>>>>> Three Ethernet drivers use napi_gro_flush() not really meant to be
>>>>> exported, so move it to <net/gro.h> and add that include there.
>>>>> napi_gro_receive() is used in more than 100 drivers, keep it
>>>>> in <linux/netdevice.h>.
>>>>> This does not make GRO ready to use outside of the NAPI context
>>>>> yet.
>>>>>
>>>>> Tested-by: Daniel Xu <dxu@dxuuu.xyz>
>>>>> Acked-by: Jakub Kicinski <kuba@kernel.org>
>>>>> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
>>>>> Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
>>>>> ---
>>>>>   include/linux/netdevice.h                  | 26 +++++---
>>>>>   include/net/busy_poll.h                    | 11 +++-
>>>>>   include/net/gro.h                          | 35 +++++++----
>>>>>   drivers/net/ethernet/brocade/bna/bnad.c    |  1 +
>>>>>   drivers/net/ethernet/cortina/gemini.c      |  1 +
>>>>>   drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c |  1 +
>>>>>   net/core/dev.c                             | 60 ++++++++-----------
>>>>>   net/core/gro.c                             | 69 +++++++++++-----------
>>>>>   8 files changed, 112 insertions(+), 92 deletions(-)
>>>>>
>>>>> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>>>>> index 2a59034a5fa2..d29b6ebde73f 100644
>>>>> --- a/include/linux/netdevice.h
>>>>> +++ b/include/linux/netdevice.h
>>>>> @@ -340,8 +340,8 @@ struct gro_list {
>>>>>   };
>>>>>
>>>>>   /*
>>>>> - * size of gro hash buckets, must less than bit number of
>>>>> - * napi_struct::gro_bitmask
>>>>> + * size of gro hash buckets, must be <= the number of bits in
>>>>> + * gro_node::bitmask
>>>>>    */
>>>>>   #define GRO_HASH_BUCKETS       8
>>>>>
>>>>> @@ -370,7 +370,6 @@ struct napi_struct {
>>>>>          unsigned long           state;
>>>>>          int                     weight;
>>>>>          u32                     defer_hard_irqs_count;
>>>>> -       unsigned long           gro_bitmask;
>>>>>          int                     (*poll)(struct napi_struct *, int);
>>>>>   #ifdef CONFIG_NETPOLL
>>>>>          /* CPU actively polling if netpoll is configured */
>>>>> @@ -379,11 +378,14 @@ struct napi_struct {
>>>>>          /* CPU on which NAPI has been scheduled for processing */
>>>>>          int                     list_owner;
>>>>>          struct net_device       *dev;
>>>>> -       struct gro_list         gro_hash[GRO_HASH_BUCKETS];
>>>>>          struct sk_buff          *skb;
>>>>> -       struct list_head        rx_list; /* Pending GRO_NORMAL skbs */
>>>>> -       int                     rx_count; /* length of rx_list */
>>>>> -       unsigned int            napi_id; /* protected by netdev_lock */
>>>>> +       struct_group_tagged(gro_node, gro,
>>>>> +               unsigned long           bitmask;
>>>>> +               struct gro_list         hash[GRO_HASH_BUCKETS];
>>>>> +               struct list_head        rx_list; /* Pending GRO_NORMAL skbs */
>>>>> +               int                     rx_count; /* length of rx_list */
>>>>> +               u32                     napi_id; /* protected by netdev_lock */
>>>>> +
>>>>
>>>> I am old school, I would prefer a proper/standalone old C construct.
>>>>
>>>> struct gro_node  {
>>>>                  unsigned long           bitmask;
>>>>                 struct gro_list         hash[GRO_HASH_BUCKETS];
>>>>                 struct list_head        rx_list; /* Pending GRO_NORMAL skbs */
>>>>                 int                     rx_count; /* length of rx_list */
>>>>                 u32                     napi_id; /* protected by netdev_lock */
>>>> };
>>>>
>>>> Really, what struct_group_tagged() can possibly bring here, other than
>>>> obfuscation ?
>>>
>>> You'd need to adjust every ->napi_id access, which is a lot.
>>> Plus, as I wrote previously, napi_id doesn't really belong here, but
>>> embedding it here eases life.
>>>
>>> I'm often an old school, too, but sometimes this helps a lot.
>>> Unless you have very strong preference on this.
>>>
>>
>> Is struct_group_tagged even supported by ctags ?
>>
>> In terms of maintenance, I am sorry to say this looks bad to me.

I get that it's not in good style to impose "new style" on the old folks
(esp. Founders, Maintainers). I agree that our drivers are just a random
sample in the pool of drivers, and it is not clearly a win-win to have 
us experiment there with "modern practices". But this particular
contribution from Olek is for benefit of all. It will be also a great
example how to use struct_group :)
I hope that we will get more struct_group usage, it's really great
mechanism to keep/pass only a part of the bigger struct (and zero/don't
care about the rest).

>>
>> Even without ctags, I find git grep -n "struct xxxx {" quite good.

I also use mostly grep to find stuff, including the ` {` "trick".
And I do add wrappers when it gets tedious, here is a one for tagged
structs:
function sgrep() {     # here is the pattern: vv
	grep -EInr "struct(_group_tagged[(]| )$*( [{]|,)" |
	awk '
		/{$/ { print; normal = 1; next }
		{ tagged[tag++] = $0 }
		END {
			if (!normal)
				for (t = 0; t < tag; t++)
					print tagged[t]
		}'; }

awk resolves the complexity of "struct something," being sometimes
a parameter of a macro

> 
> compile_commands.json (already supported natively by Kbuild) + clangd is
> not enough?
> 
> Elixir correctly tags struct_group()s.
> 
> napi->napi_id is used in a lot of core files and drivers, adjusting all
> the references is not what I wanted to do in the series which does
> completely different things.
> 
> Page Pool uses tagged struct groups, as well a ton of other different
> files. Do you want to revert all this and adjust a couple thousand
> references only due to ctags and grep?
> 
> (instead of just clicking on the references generated by clangd)
> 
> Thanks,
> Olek
> 


  reply	other threads:[~2025-02-07 14:22 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-05 16:36 [PATCH net-next v4 0/8] bpf: cpumap: enable GRO for XDP_PASS frames Alexander Lobakin
2025-02-05 16:36 ` [PATCH net-next v4 1/8] net: gro: decouple GRO from the NAPI layer Alexander Lobakin
2025-02-05 17:48   ` Eric Dumazet
2025-02-06  2:56     ` Jakub Kicinski
2025-02-06 12:12     ` Alexander Lobakin
2025-02-06 18:35       ` Eric Dumazet
2025-02-07 11:56         ` Alexander Lobakin
2025-02-07 14:21           ` Przemek Kitszel [this message]
2025-02-07 14:55           ` Eric Dumazet
2025-02-07 15:18             ` Alexander Lobakin
2025-02-07 15:28               ` Eric Dumazet
2025-02-07 15:43                 ` Alexander Lobakin
2025-02-05 16:36 ` [PATCH net-next v4 2/8] net: gro: expose GRO init/cleanup to use outside of NAPI Alexander Lobakin
2025-02-05 16:36 ` [PATCH net-next v4 3/8] bpf: cpumap: switch to GRO from netif_receive_skb_list() Alexander Lobakin
2025-02-05 16:36 ` [PATCH net-next v4 4/8] bpf: cpumap: reuse skb array instead of a linked list to chain skbs Alexander Lobakin
2025-02-05 16:36 ` [PATCH net-next v4 5/8] net: skbuff: introduce napi_skb_cache_get_bulk() Alexander Lobakin
2025-02-05 16:36 ` [PATCH net-next v4 6/8] bpf: cpumap: switch to napi_skb_cache_get_bulk() Alexander Lobakin
2025-02-05 16:36 ` [PATCH net-next v4 7/8] veth: use napi_skb_cache_get_bulk() instead of xdp_alloc_skb_bulk() Alexander Lobakin
2025-02-05 16:36 ` [PATCH net-next v4 8/8] xdp: remove xdp_alloc_skb_bulk() Alexander Lobakin
2025-02-10 14:05 ` [PATCH net-next v4 0/8] bpf: cpumap: enable GRO for XDP_PASS frames Alexander Lobakin
2025-02-10 15:31   ` Eric Dumazet
2025-02-10 15:31     ` Alexander Lobakin
2025-02-11  0:35       ` Jakub Kicinski
2025-02-12 14:22         ` Alexander Lobakin
2025-02-12 15:55           ` Alexander Lobakin
2025-02-12 18:29             ` Jakub Kicinski
2025-02-14 15:43               ` Alexander Lobakin

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=eba70511-b6eb-4ff2-ae1a-183fa626d60a@intel.com \
    --to=przemyslaw.kitszel@intel.com \
    --cc=aleksander.lobakin@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dxu@dxuuu.xyz \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kees@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=toke@kernel.org \
    --cc=toke@redhat.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).