Re: [PATCH net-next 07/12] net: dsa: rzn1-a5psw: add statistics support
From: Clément Léger
Date: Fri Apr 15 2022 - 09:45:59 EST
Le Fri, 15 Apr 2022 15:37:38 +0200,
Andrew Lunn <andrew@xxxxxxx> a écrit :
> > > > +static void a5psw_get_ethtool_stats(struct dsa_switch *ds, int port,
> > > > + uint64_t *data)
> > > > +{
> > > > + struct a5psw *a5psw = ds->priv;
> > > > + u32 reg_lo, reg_hi;
> > > > + unsigned int u;
> > > > +
> > > > + for (u = 0; u < ARRAY_SIZE(a5psw_stats); u++) {
> > > > + /* A5PSW_STATS_HIWORD is global and thus, access must be
> > > > + * exclusive
> > > > + */
> > >
> > > Could you explain that a bit more. The RTNL lock will prevent two
> > > parallel calls to this function.
> >
> > Ok, I wasn't sure of the locking applicable here.
>
> In general, RTNL protects you for any user space management like
> operation on the driver. In this case, if you look in net/ethtool, you
> will find the IOCTL handler code takes RTNL before calling into the
> main IOCTL dispatcher. If you want to be paranoid/document the
> assumption, you can add an ASSERT_RTNL().
Ok, I'll look at the call stack in details to see what locking is
applied.
>
> The semantics for some of the other statistics Vladimir requested can
> be slightly different. One of them is in atomic context, because a
> spinlock is held. But i don't remember if RTNL is also held. This is
> less of an issue for your switch, since it uses MMIO, however many
> switches need to perform blocking IO over MDIO, SPI, IC2 etc to get
> stats, which you cannot do in atomic context. So they end up returning
> cached values.
>
> Look in the mailing list for past discussion for details.
Ok, thanks,
>
> Andrew
--
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com