On Tue, Sep 12, 2023 at 8:03 PM Eric Dumazet <edumazet@xxxxxxxxxx> wrote:
Sure, this was what was suggested (perhaps not _very_ precisely, butOh well, I just read the patch, and it seems wrong indeed.
the general idea was pretty clear).
v2 seems ok, right ?
It seems we are all on the same page.
+static __cold struct net_device_core_stats __percpu
*dev_core_stats(struct net_device *dev)
+{
+ /* This READ_ONCE() pairs with the write in netdev_core_stats_alloc() */
+ struct net_device_core_stats __percpu *p = READ_ONCE(dev->core_stats);
+
+ if (likely(p))
+ return p;
+
+ return netdev_core_stats_alloc(dev);
+}
+
+#define DEV_CORE_STATS_INC(FIELD) \
+void dev_core_stats_##FIELD##_inc(struct net_device *dev) \
+{ \
+ struct net_device_core_stats __percpu *p; \
+ \
+ p = dev_core_stats(dev); \
+ if (p) \
+ this_cpu_inc(p->FIELD); \
+} \
+EXPORT_SYMBOL(dev_core_stats_##FIELD##_inc)
netdev_core_stats_alloc() is the one that can be cold.