On Sun, 18 Oct 2020 19:36:49 +0200 Andrew Lunn wrote:
> On Sun, Oct 18, 2020 at 09:49:51AM -0700, Jakub Kicinski wrote:
> > > + struct u64_stats_sync syncp;
> > > +} __aligned(1 * sizeof(u64));
> >
> > Why aligned to u64? Compiler should pick a reasonable alignment here
> > by itself.
>
> Hi Jakub
>
> I wondered that as well. But:
>
> struct gnet_stats_basic_cpu {
> struct gnet_stats_basic_packed bstats;
> struct u64_stats_sync syncp;
> } __aligned(2 * sizeof(u64));
>
> /* often modified stats are per-CPU, other are shared (netdev->stats) */
> struct pcpu_sw_netstats {
> u64 rx_packets;
> u64 rx_bytes;
> u64 tx_packets;
> u64 tx_bytes;
> struct u64_stats_sync syncp;
> } __aligned(4 * sizeof(u64));
>
> struct pcpu_lstats {
> u64_stats_t packets;
> u64_stats_t bytes;
> struct u64_stats_sync syncp;
> } __aligned(2 * sizeof(u64));
>
> Cargo cult or is there a real need?
Hm, looks like the intent is to enforce power of two alignment
to prevent the structure from spanning cache lines. Doesn't make
any difference for 1 counter, but I guess we can keep the style
for consistency.