This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC][PATCH 0/5] arch: atomic rework
- From: Peter Zijlstra <peterz at infradead dot org>
- To: Peter Sewell <Peter dot Sewell at cl dot cam dot ac dot uk>
- Cc: "mark dot batty at cl dot cam dot ac dot uk" <Mark dot Batty at cl dot cam dot ac dot uk>, Paul McKenney <paulmck at linux dot vnet dot ibm dot com>, Torvald Riegel <triegel at redhat dot com>, torvalds at linux-foundation dot org, Will Deacon <will dot deacon at arm dot com>, Ramana dot Radhakrishnan at arm dot com, dhowells at redhat dot com, linux-arch at vger dot kernel dot org, linux-kernel at vger dot kernel dot org, akpm at linux-foundation dot org, mingo at kernel dot org, gcc at gcc dot gnu dot org
- Date: Tue, 18 Feb 2014 13:53:57 +0100
- Subject: Re: [RFC][PATCH 0/5] arch: atomic rework
- Authentication-results: sourceware.org; auth=none
- References: <CAHWkzRQSaKOM23yg1LbCO=uWremNzwnXUCUJF2H-+z_Xhmp79g at mail dot gmail dot com>
On Tue, Feb 18, 2014 at 12:12:06PM +0000, Peter Sewell wrote:
> Several of you have said that the standard and compiler should not
> permit speculative writes of atomics, or (effectively) that the
> compiler should preserve dependencies.
The example below only deals with control dependencies; so I'll limit
myself to that.
> In simple examples it's easy
> to see what that means, but in general it's not so clear what the
> language should guarantee, because dependencies may go via non-atomic
> code in other compilation units, and we have to consider the extent to
> which it's desirable to limit optimisation there.
>
> For example, suppose we have, in one compilation unit:
>
> void f(int ra, int*rb) {
> if (ra==42)
> *rb=42;
> else
> *rb=42;
> }
>
> and in another compilation unit the bodies of two threads:
>
> // Thread 0
> r1 = x;
> f(r1,&r2);
> y = r2;
>
> // Thread 1
> r3 = y;
> f(r3,&r4);
> x = r4;
>
> where accesses to x and y are annotated C11 atomic
> memory_order_relaxed or Linux ACCESS_ONCE(), accesses to
> r1,r2,r3,r4,ra,rb are not annotated, and x and y initially hold 0.
So I'm intuitively ok with this, however I would expect something like:
void f(_Atomic int ra, _Atomic int *rb);
To preserve dependencies and not make the conditional go away, simply
because in that case the:
if (ra == 42)
the 'ra' usage can be seen as an atomic load.
> So as far as we can see, either:
>
> 1) if you can accept the latter behaviour (if the Linux codebase does
> not rely on its absence), the language definition should permit it,
> and current compiler optimisations can be used,
Currently there's exactly 1 site in the Linux kernel that relies on
control dependencies as far as I know -- the one I put in. And its
limited to a single function, so no cross translation unit funnies
there.
Of course, nobody is going to tell me when or where they'll put in the
next one; since its now documented as accepted practise.
However, PaulMck and our RCU usage very much do cross all sorts of TU
boundaries; but those are data dependencies.
~ Peter