RE: [PATCH v2] hv_netvsc: Add per-cpu ethtool stats for netvsc

From: Yidong Ren
Date: Wed Jun 13 2018 - 18:03:49 EST


> From: devel <driverdev-devel-bounces@xxxxxxxxxxxxxxxxxxxxxx> On Behalf
> Of Stephen Hemminger
> > +/* statistics per queue (rx/tx packets/bytes) */ #define
> > +NETVSC_PCPU_STATS_LEN (num_present_cpus() *
> ARRAY_SIZE(pcpu_stats))
>
> Even though Hyper-V/Azure does not support hot plug cpu's it might be
> better to num_cpu_possible to avoid any possible future surprises.

That will create a very long output (num_cpu_possible = 128 on my machine) for ethtool,
While doesn't provide additional info.
num_present_cpus() would cause problem only if someone removed cpu
between netvsc_get_sset_count() and netvsc_get_strings() and netvsc_get_ethtool_stats().

An alternative way could be: Check all stats, and only output if not zero.
This need to be done in two pass. First pass to get the correct count, second pass to print the number.
Is there an elegant way to do this?