Message ID | 20240627234808.1253337-54-hauke@hauke-m.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | backports: Update to kernel 6.1.95 | expand |
On Fri, 2024-06-28 at 01:47 +0200, Hauke Mehrtens wrote: > ++#if LINUX_VERSION_IS_GEQ(6,0,0) > + u64_stats_inc(&stats64->rx_packets); > + u64_stats_add(&stats64->rx_bytes, skb->len); > ++#else > ++ stats64->rx_packets++; > ++ stats64->rx_bytes += skb->len; > ++#endif I suspect we _could_ do this with an auto-detect macro? #if ... /* < 5.5 */ #define u64_stats_inc(v) (*v)++ #define u64_stats_add(v, a) (*v)+=(a) #else #define u64_stats_inc(v) \ do { if (__builtin_types_compatible(typeof(v), *u64_stats_t) u64_stats_inc(v); else (*v)++; } while(0) or so? But then it's only one driver here ... johannes
On 6/28/24 12:47, Johannes Berg wrote: > On Fri, 2024-06-28 at 01:47 +0200, Hauke Mehrtens wrote: >> ++#if LINUX_VERSION_IS_GEQ(6,0,0) >> + u64_stats_inc(&stats64->rx_packets); >> + u64_stats_add(&stats64->rx_bytes, skb->len); >> ++#else >> ++ stats64->rx_packets++; >> ++ stats64->rx_bytes += skb->len; >> ++#endif > > I suspect we _could_ do this with an auto-detect macro? > > #if ... /* < 5.5 */ > #define u64_stats_inc(v) (*v)++ > #define u64_stats_add(v, a) (*v)+=(a) > #else > #define u64_stats_inc(v) \ > do { > if (__builtin_types_compatible(typeof(v), *u64_stats_t) > u64_stats_inc(v); > else > (*v)++; > } while(0) > > > or so? > > But then it's only one driver here ... > > johannes I think that should work because u64_stats_inc() and u64_stats_add() are not used in other places for now. This patch is needed because of this upstream change: https://git.kernel.org/linus/9962acefbcb92736c268aafe5f52200948f60f3e It changes the type from u64 to u64_stats_t. The functions are already in the kernel for much longer. Even kernel 5.10 uses them on some net counters. If we replace all u64_stats_inc() and u64_stats_add() usage with the ++ and similar operations this could also affect other places where we do not want to do this. I would prefer to stay with this patch. The code in this area is also not changing often. Hauke
diff --git a/patches/0111-pcpu_sw_netstats.patch b/patches/0111-pcpu_sw_netstats.patch new file mode 100644 index 00000000..70f3fad6 --- /dev/null +++ b/patches/0111-pcpu_sw_netstats.patch @@ -0,0 +1,30 @@ +--- a/drivers/net/usb/usbnet.c ++++ b/drivers/net/usb/usbnet.c +@@ -334,8 +334,13 @@ void usbnet_skb_return (struct usbnet *d + skb->protocol = eth_type_trans (skb, dev->net); + + flags = u64_stats_update_begin_irqsave(&stats64->syncp); ++#if LINUX_VERSION_IS_GEQ(6,0,0) + u64_stats_inc(&stats64->rx_packets); + u64_stats_add(&stats64->rx_bytes, skb->len); ++#else ++ stats64->rx_packets++; ++ stats64->rx_bytes += skb->len; ++#endif + u64_stats_update_end_irqrestore(&stats64->syncp, flags); + + netif_dbg(dev, rx_status, dev->net, "< rx, len %zu, type 0x%x\n", +@@ -1253,8 +1258,13 @@ static void tx_complete (struct urb *urb + unsigned long flags; + + flags = u64_stats_update_begin_irqsave(&stats64->syncp); ++#if LINUX_VERSION_IS_GEQ(6,0,0) + u64_stats_add(&stats64->tx_packets, entry->packets); + u64_stats_add(&stats64->tx_bytes, entry->length); ++#else ++ stats64->tx_packets += entry->packets; ++ stats64->tx_bytes += entry->length; ++#endif + u64_stats_update_end_irqrestore(&stats64->syncp, flags); + } else { + dev->net->stats.tx_errors++;
In kernel 6.0 the struct pcpu_sw_netstats which contains the counters for network devices changes from attributes of type u64 to u64_stats_t. The new types need special functions, use the old arithmetic operations on older kernel versions. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> --- patches/0111-pcpu_sw_netstats.patch | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 patches/0111-pcpu_sw_netstats.patch