Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1416148

Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep

From "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Newsgroups linux.kernel
Subject Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep
Date 2016-06-07 15:10 +0200
Message-ID <rHoVA-37S-39@gated-at.bofh.it> (permalink)
References (5 earlier) <rFXE6-3Ng-41@gated-at.bofh.it> <rGy0W-2a4-1@gated-at.bofh.it> <rH6vE-7U4-43@gated-at.bofh.it> <rHjsR-82q-7@gated-at.bofh.it> <rHoCe-2KD-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, Jun 07, 2016 at 02:41:44PM +0200, Hannes Frederic Sowa wrote:
> On 07.06.2016 09:15, Peter Zijlstra wrote:
> >>
> >> diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
> >> index 147ae8ec836f..a4d0a99de04d 100644
> >> --- a/Documentation/memory-barriers.txt
> >> +++ b/Documentation/memory-barriers.txt
> >> @@ -806,6 +806,41 @@ out-guess your code.  More generally, although READ_ONCE() does force
> >>  the compiler to actually emit code for a given load, it does not force
> >>  the compiler to use the results.
> >>  
> >> +In addition, control dependencies apply only to the then-clause and
> >> +else-clause of the if-statement in question.  In particular, it does
> >> +not necessarily apply to code following the if-statement:
> >> +
> >> +	q = READ_ONCE(a);
> >> +	if (q) {
> >> +		WRITE_ONCE(b, p);
> >> +	} else {
> >> +		WRITE_ONCE(b, r);
> >> +	}
> >> +	WRITE_ONCE(c, 1);  /* BUG: No ordering against the read from "a". */
> >> +
> >> +It is tempting to argue that there in fact is ordering because the
> >> +compiler cannot reorder volatile accesses and also cannot reorder
> >> +the writes to "b" with the condition.  Unfortunately for this line
> >> +of reasoning, the compiler might compile the two writes to "b" as
> >> +conditional-move instructions, as in this fanciful pseudo-assembly
> >> +language:
> 
> I wonder if we already guarantee by kernel compiler settings that this
> behavior is not allowed by at least gcc.
> 
> We unconditionally set --param allow-store-data-races=0 which should
> actually prevent gcc from generating such conditional stores.
> 
> Am I seeing this correct here?

In this case, the store to "c" is unconditional, so pulling it forward
would not generate a data race.  However, the compiler is still prohibited
from pulling it forward because it is not allowed to reorder volatile
references.  So, yes, the compiler cannot reorder, but for a different
reason.

Some CPUs, on the other hand, can do this reordering, as Will Deacon
pointed out earlier in this thread.

							Thanx, Paul

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep Vineet Gupta <Vineet.Gupta1@synopsys.com> - 2016-06-03 11:20 +0200
  Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep Peter Zijlstra <peterz@infradead.org> - 2016-06-03 11:40 +0200
    Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-06-03 14:10 +0200
      Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep Peter Zijlstra <peterz@infradead.org> - 2016-06-03 14:30 +0200
        Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep Peter Zijlstra <peterz@infradead.org> - 2016-06-03 14:30 +0200
          Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-06-03 15:40 +0200
        Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-06-03 15:40 +0200
          Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep Will Deacon <will.deacon@arm.com> - 2016-06-03 15:50 +0200
            Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-06-05 06:40 +0200
              Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-06-06 19:30 +0200
                Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep Peter Zijlstra <peterz@infradead.org> - 2016-06-07 09:20 +0200
                Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep Hannes Frederic Sowa <hannes@stressinduktion.org> - 2016-06-07 14:50 +0200
                Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-06-07 15:10 +0200
                Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep Hannes Frederic Sowa <hannes@stressinduktion.org> - 2016-06-07 17:00 +0200
                Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-06-07 17:30 +0200
                Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep Peter Zijlstra <peterz@infradead.org> - 2016-06-07 19:50 +0200
                Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-06-07 20:50 +0200
                Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep Will Deacon <will.deacon@arm.com> - 2016-06-07 20:10 +0200
                Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-06-07 20:50 +0200
                Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-06-07 21:00 +0200
                Re: [RFC][PATCH 1/3] locking: Introduce smp_acquire__after_ctrl_dep Hannes Frederic Sowa <hannes@stressinduktion.org> - 2016-06-07 20:40 +0200

csiph-web