From: Colin Foster <colin.foster@in-advantage.com>
To: Vladimir Oltean <vladimir.oltean@nxp.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
aolo Abeni <pabeni@redhat.com>, Jakub Kicinski <kuba@kernel.org>,
Eric Dumazet <edumazet@google.com>,
"David S. Miller" <davem@davemloft.net>,
Florian Fainelli <f.fainelli@gmail.com>,
Vivien Didelot <vivien.didelot@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
"UNGLinuxDriver@microchip.com" <UNGLinuxDriver@microchip.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Claudiu Manoil <claudiu.manoil@nxp.com>
Subject: Re: [PATCH v1 net-next 1/1] net: ethernet: ocelot: remove the need for num_stats initializer
Date: Sat, 30 Apr 2022 15:31:28 -0700 [thread overview]
Message-ID: <20220430223128.GB3871052@euler> (raw)
In-Reply-To: <20220430213344.ifiw2wjtxqd2dqbj@skbuf>
On Sat, Apr 30, 2022 at 09:33:45PM +0000, Vladimir Oltean wrote:
> On Sat, Apr 30, 2022 at 10:47:35AM -0700, Colin Foster wrote:
> > > > struct ocelot_stat_layout {
> > > > u32 offset;
> > > > + u32 flags;
> > >
> > > Was it really necessary to add an extra u32 to struct ocelot_stat_layout?
> > > Couldn't you check for the end of stats by looking at stat->name[0] and
> > > comparing against the null terminator, for an empty string?
> >
> > I considered this as well. I could either have explicitly added the
> > flags field, as I did, or implicitly looked for .name == NULL (or
> > name[0] == '\0' as you suggest).
>
> No, you cannot check for .name == NULL. The "name" member of struct
> ocelot_stat_layout is most definitely not NULL, but has the value of the
> memory address of the first char from that array. Contrast this with
> "char *name", where a NULL comparison can indeed be made.
My apologies - I had the structure wrong in my head and thought it was a
const char *. Checking for NULL is clearly not an option.
>
> > I figured it might be better to make this an explicit relationship by
> > way of flags - but I'm happy to change OCELOT_STAT_END and for_each_stat
> > to rely on .name if you prefer.
>
> I would have understood introducing a flag to mark the last element of
> an array as special (as opposed to introducing a dummy extra element).
> But even that calculation would have been wrong.
>
> Before:
>
> pahole -C ocelot_stat_layout drivers/net/ethernet/mscc/ocelot.o
> struct ocelot_stat_layout {
> u32 offset; /* 0 4 */
> char name[32]; /* 4 32 */
>
> /* size: 36, cachelines: 1, members: 2 */
> /* last cacheline: 36 bytes */
> };
>
> After:
>
> pahole -C ocelot_stat_layout drivers/net/ethernet/mscc/ocelot.o
> struct ocelot_stat_layout {
> u32 offset; /* 0 4 */
> u32 flags; /* 4 4 */
> char name[32]; /* 8 32 */
>
> /* size: 40, cachelines: 1, members: 3 */
> /* last cacheline: 40 bytes */
> };
>
> For example, vsc9959_stats_layout has 92 elements (93 with the dummy one
> you've added now). The overhead of 4 bytes per element amounts to 368
> extra bytes. Whereas a single dummy element at the end would have
> amounted to just 36 extra bytes.
>
> With your approach, what we get is 372 extra bytes, so worst of both worlds.
Understood. I'll send an update momentarily. I also didn't know about
'pahole' which looks to be a useful tool! Thanks again for the
feedback.
>
> > > > char name[ETH_GSTRING_LEN];
> > > > };
> > > >
> > > > +#define OCELOT_STAT_END { .flags = OCELOT_STAT_FLAG_END }
next prev parent reply other threads:[~2022-04-30 22:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-29 21:30 [PATCH v1 net-next 0/1] net: ethernet: ocelot: remove num_stats initializer requirement Colin Foster
2022-04-29 21:30 ` [PATCH v1 net-next 1/1] net: ethernet: ocelot: remove the need for num_stats initializer Colin Foster
2022-04-30 15:15 ` Vladimir Oltean
2022-04-30 17:47 ` Colin Foster
2022-04-30 21:33 ` Vladimir Oltean
2022-04-30 22:31 ` Colin Foster [this message]
2022-04-30 12:40 ` [PATCH v1 net-next 0/1] net: ethernet: ocelot: remove num_stats initializer requirement 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=20220430223128.GB3871052@euler \
--to=colin.foster@in-advantage.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=alexandre.belloni@bootlin.com \
--cc=andrew@lunn.ch \
--cc=claudiu.manoil@nxp.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=vivien.didelot@gmail.com \
--cc=vladimir.oltean@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 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).