Re: [PATCH 53/75] patch: Adapt struct pcpu_sw_netstats change to u64_stats_t

Johannes Berg <[email protected]> Fri, 28 Jun 2024 12:47:58 +0200
Newsgroups org.kernel.vger.backports
Message-ID <[email protected]>
On Fri, 2024-06-28 at 01:47 +0200, Hauke Mehrtens wrote:
> ++#if LINUX_VERSION_IS_GEQ(6,0,0)
> +=C2=A0	u64_stats_inc(&stats64->rx_packets);
> +=C2=A0	u64_stats_add(&stats64->rx_bytes, skb->len);
> ++#else
> ++	stats64->rx_packets++;
> ++	stats64->rx_bytes +=3D 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)+=3D(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