Re: [PATCH 1/2] net: Enable 64-bit net device statistics on 32-bit architectures

Stephen Hemminger
2010-06-03T18:47:41Z

On Thu, 03 Jun 2010 18:39:04 +0100
Ben Hutchings <bhutchings@solarflare.com> wrote:

> #if BITS_PER_LONG == 64
> +#define NET_DEVICE_STATS_DEFINE(name) u64 name
> +#define RTNL_LINK_STATS64_READ(stats, name) \
> + ACCESS_ONCE((stats)->name)
> +#define RTNL_LINK_STATS64_READ_OFFSET(stats, offset) \
> + ACCESS_ONCE((const u64 *)((const u8 *)(stats) + (offset)))
> +#define RTNL_LINK_STATS64_READ32(stats, name) \
> + ((u32)ACCESS_ONCE((stats)->name))
> +#else
> +#if defined(__LITTLE_ENDIAN)
> +#define NET_DEVICE_STATS_DEFINE(name) u32 name, pad_ ## name
> +#define RTNL_LINK_STATS64_READ_OFFSET(stats, offset) \
> + (ACCESS_ONCE(*(const u32 *)((const u8 *)(stats) + (offset))) | \
> + (u64)(*(const u32 *)((const u8 *)(stats) + (offset) + 4)) << 32)
> +#define RTNL_LINK_STATS64_READ32(stats, name) \
> + (((const volatile u32 *)&(stats)->name)[0])
> +#else
> +#define NET_DEVICE_STATS_DEFINE(name) u32 pad_ ## name, name
> +#define RTNL_LINK_STATS64_READ_OFFSET(stats, offset) \
> + ((u64)(*(const u32 *)((const u8 *)(stats) + (offset))) << 32 | \
> + ACCESS_ONCE(*(const u32 *)((const u8 *)(stats) + (offset) + 4)))
> +#define RTNL_LINK_STATS64_READ32(stats, name) \
> + (((const volatile u32 *)&(stats)->name)[1])
> +#endif
> +#define RTNL_LINK_STATS64_READ(stats, name) \
> + RTNL_LINK_STATS64_READ_OFFSET( \
> + stats, offsetof(struct rtnl_link_stats64, name))
> +#endif

Macros... with multiple casts. Gack

--