Re: [PATCH net-next v2 5/7] netdevsim: report stats by default, like a real device

Petr Machata
2024-04-04T11:22:41Z

Jakub Kicinski <kuba@kernel.org> writes:

> Real devices should implement qstats. Devices which support
> pause or FEC configuration should also report the relevant stats.
>
> nsim was missing FEC stats completely, some of the qstats
> and pause stats required toggling a debugfs knob.
>
> Note that the tests which used pause always initialize the setting
> so they shouldn't be affected by the different starting value.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Petr Machata <petrm@nvidia.com>

Just:

> @@ -330,6 +331,49 @@ static const struct net_device_ops nsim_vf_netdev_ops = {
> .ndo_set_features = nsim_set_features,
> };
>
> +/* We don't have true par-queue stats, yet, so do some random fakery here. */

per

> +static void nsim_get_queue_stats_rx(struct net_device *dev, int idx,
> + struct netdev_queue_stats_rx *stats)
> +{
> + struct rtnl_link_stats64 rtstats = {};
> +
> + nsim_get_stats64(dev, &rtstats);
> +
> + stats->packets = rtstats.rx_packets - !!rtstats.rx_packets;

This is just to make sure that per-queue stats are lower than the
overall rtstats I presume?

> + stats->bytes = rtstats.rx_bytes;
> +}
> +
> +static void nsim_get_queue_stats_tx(struct net_device *dev, int idx,
> + struct netdev_queue_stats_tx *stats)
> +{
> + struct rtnl_link_stats64 rtstats = {};
> +
> + nsim_get_stats64(dev, &rtstats);
> +
> + stats->packets = rtstats.tx_packets - !!rtstats.tx_packets;
> + stats->bytes = rtstats.tx_bytes;
> +}