Re: [PATCH -tip v3 09/11] data_race: Avoid nested statement expression

From: Arnd Bergmann
Date: Wed May 27 2020 - 05:27:14 EST


On Wed, May 27, 2020 at 9:44 AM 'Marco Elver' via Clang Built Linux
<clang-built-linux@xxxxxxxxxxxxxxxx> wrote:
> On Wed, 27 May 2020 at 09:22, Will Deacon <will@xxxxxxxxxx> wrote:
> >
> > Nice! FWIW, I'm planning to have Alpha override __READ_ONCE_SCALAR()
> > eventually, so that smp_read_barrier_depends() can disappear forever. I
> > just bit off more than I can chew for 5.8 :(
> >
> > However, '__unqual_scalar_typeof()' is still useful for
> > load-acquire/store-release on arm64, so we still need a better solution to
> > the build-time regression imo. I'm not fond of picking random C11 features
> > to accomplish that, but I also don't have any better ideas...
>
> We already use _Static_assert in the kernel, so it's not the first use
> of a C11 feature.
>
> > Is there any mileage in the clever trick from Rasmus?
> >
> > https://lore.kernel.org/r/6cbc8ae1-8eb1-a5a0-a584-2081fca1c4aa@xxxxxxxxxxxxxxxxxx
>
> Apparently that one only works with GCC 7 or newer, and is only
> properly defined behaviour since C11. It also relies on multiple
> _Pragma. I'd probably take the arguably much cleaner _Generic solution
> over that. ;-)

I'd have to try, but I suspect we could force gcc-4.9 or higher to
accept it by always passing --std=gnu11 instead of --std=gnu89,
but that still wouldn't help us with gcc-4.8, and it's definitely not
something we could consider changing for v5.8.

However, if we find a solution that is nicer and faster but does
requires C11 or some other features from a newer compiler,
I think making it version dependent is a good idea and lets us
drop the worse code eventually.

> I think given that Peter and Arnd already did some testing, and it
> works as intended, if you don't mind, I'll send a patch for the
> _Generic version. At least that'll give us a more optimized
> __unqual_scalar_typeof(). Any further optimizations to READ_ONCE()
> like you mentioned then become a little less urgent.

Right. I think there is still room for optimization around here, but
for v5.8 I'm happy enough with Marco's__unqual_scalar_typeof()
change. Stephen Rothwell is probably the one who's most affected
by compile speed, so it would be good to get an Ack/Nak from him
on whether this brings speed and memory usage back to normal
for him as well.

Arnd