[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210604142548.GD1676809@rowland.harvard.edu>
Date: Fri, 4 Jun 2021 10:25:48 -0400
From: Alan Stern <stern@...land.harvard.edu>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>, will@...nel.org,
paulmck@...nel.org, parri.andrea@...il.com, boqun.feng@...il.com,
npiggin@...il.com, dhowells@...hat.com, j.alglave@....ac.uk,
luc.maranget@...ia.fr, akiyks@...il.com,
linux-kernel@...r.kernel.org, linux-toolchains@...r.kernel.org,
linux-arch@...r.kernel.org
Subject: Re: [RFC] LKMM: Add volatile_if()
On Fri, Jun 04, 2021 at 12:12:07PM +0200, Peter Zijlstra wrote:
> Hi!
>
> With optimizing compilers becoming more and more agressive and C so far
> refusing to acknowledge the concept of control-dependencies even while
> we keep growing the amount of reliance on them, things will eventually
> come apart.
>
> There have been talks with toolchain people on how to resolve this; one
> suggestion was allowing the volatile qualifier on branch statements like
> 'if', but so far no actual compiler has made any progress on this.
>
> Rather than waiting any longer, provide our own construct based on that
> suggestion. The idea is by Alan Stern and refined by Paul and myself.
>
> Code generation is sub-optimal (for the weak architectures) since we're
> forced to convert the condition into another and use a fixed conditional
> branch instruction, but shouldn't be too bad.
>
> Usage of volatile_if requires the @cond to be headed by a volatile load
> (READ_ONCE() / atomic_read() etc..) such that the compiler is forced to
> emit the load and the branch emitted will have the required
> data-dependency. Furthermore, volatile_if() is a compiler barrier, which
> should prohibit the compiler from lifting anything out of the selection
> statement.
>
> This construct should place control dependencies on a stronger footing
> until such time that the compiler folks get around to accepting them :-)
>
> I've converted most architectures we care about, and the rest will get
> an extra smp_mb() by means of the 'generic' fallback implementation (for
> now).
>
> I've converted the control dependencies I remembered and those found
> with a search for smp_acquire__after_ctrl_dep(), there might be more.
>
> Compile tested only (alpha, arm, arm64, x86_64, powerpc, powerpc64, s390
> and sparc64).
>
> Suggested-by: Alan Stern <stern@...land.harvard.edu>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
Is there any interest in doing the same sort of thing for switch
statements? A similar approach would probably work, but maybe people
don't care about it.
Alan
Powered by blists - more mailing lists