Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1342441
| From | Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH tip/core/rcu 02/14] documentation: Fix control dependency and identical stores |
| Date | 2016-02-24 22:20 +0100 |
| Message-ID | <r5P0K-1T4-9@gated-at.bofh.it> (permalink) |
| References | <r5zS2-84d-11@gated-at.bofh.it> <r5A1J-87D-37@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
----- On Feb 24, 2016, at 12:00 AM, Paul E. McKenney paulmck@linux.vnet.ibm.com wrote:
> The summary of the "CONTROL DEPENDENCIES" section incorrectly states that
> barrier() may be used to prevent compiler reordering when more than one
> leg of the control-dependent "if" statement start with identical stores.
> This is incorrect at high optimization levels. This commit therefore
> updates the summary to match the detailed description.
>
> Reported by: Jianyu Zhan <nasa4836@gmail.com>
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> ---
> Documentation/memory-barriers.txt | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/memory-barriers.txt
> b/Documentation/memory-barriers.txt
> index 904ee42d078e..e26058d3e253 100644
> --- a/Documentation/memory-barriers.txt
> +++ b/Documentation/memory-barriers.txt
> @@ -800,9 +800,13 @@ In summary:
> use smp_rmb(), smp_wmb(), or, in the case of prior stores and
> later loads, smp_mb().
>
> - (*) If both legs of the "if" statement begin with identical stores
> - to the same variable, a barrier() statement is required at the
> - beginning of each leg of the "if" statement.
> + (*) If both legs of the "if" statement begin with identical stores to
> + the same variable, then those stores must be ordered, either by
> + preceding both of them with smp_mb() or by using smp_store_release()
> + to carry out the stores. Please note that it is -not- sufficient
> + to use barrier() at beginning of each leg of the "if" statement,
> + as optimizing compilers do not necessarily respect barrier()
> + in this case.
Hrm, I really don't understand this one.
One caveat, as stated here, would be that optimizing compilers
can reorder instruction with respect to barrier() placed at the
beginning of if/else legs that start with identical stores.
It goes on stating that "smp_mb() or smp_store_release()" should
be used rather than barrier() in those cases.
I don't get how, from a compiler optimization perspective,
barrier() is any different from smp_mb().
#define barrier() __asm__ __volatile__("": : :"memory")
vs
#define mb() asm volatile("mfence":::"memory")
What the compiler would observe is a "memory" clobber in both
cases.
Now if the stated cause of this issue would have been
internal reordering of those identical stores within the
processor, I would understand that smp_mb() has an
effect which differs from the compiler barrier, but since
the paragraph begins by stating that this is purely for
compiler optimizations, I'm confused.
What am I missing there ?
Thanks,
Mathieu
>
> (*) Control dependencies require at least one run-time conditional
> between the prior load and the subsequent store, and this
> --
> 2.5.2
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH tip/core/rcu 0/14] Documentation updates for 4.6 "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:10 +0100
[PATCH tip/core/rcu 01/14] documentation: Add real-time requirements from CPU-bound workloads "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:10 +0100
[PATCH tip/core/rcu 14/14] documentation: Clarify compiler store-fusion example "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:10 +0100
[PATCH tip/core/rcu 12/14] documentation: Document illegality of call_rcu() from offline CPUs "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:10 +0100
[PATCH tip/core/rcu 07/14] documentation: Distinguish between local and global transitivity "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:10 +0100
[PATCH tip/core/rcu 05/14] documentation: Remove obsolete reference to RCU-protected indexes "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:10 +0100
[PATCH tip/core/rcu 08/14] documentation: Add alternative release-acquire outcome "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:10 +0100
[PATCH tip/core/rcu 11/14] documentation: Transitivity is not cumulativity "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:10 +0100
[PATCH tip/core/rcu 04/14] documentation: Add synchronize_rcu_mult() to the requirements "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:10 +0100
[PATCH tip/core/rcu 13/14] documentation: Explain how RCU's combining tree fights contention "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:20 +0100
[PATCH tip/core/rcu 10/14] documentation: Explain why rcu_read_lock() needs no barrier() "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:20 +0100
[PATCH tip/core/rcu 03/14] documentation: Fix memory-barriers.txt section references "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:20 +0100
[PATCH tip/core/rcu 02/14] documentation: Fix control dependency and identical stores "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:20 +0100
Re: [PATCH tip/core/rcu 02/14] documentation: Fix control dependency and identical stores Mathieu Desnoyers <mathieu.desnoyers@efficios.com> - 2016-02-24 22:20 +0100
Re: [PATCH tip/core/rcu 02/14] documentation: Fix control dependency and identical stores "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 22:50 +0100
Re: [PATCH tip/core/rcu 02/14] documentation: Fix control dependency and identical stores Jianyu Zhan <nasa4836@gmail.com> - 2016-02-25 07:50 +0100
Re: [PATCH tip/core/rcu 02/14] documentation: Fix control dependency and identical stores "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-25 15:10 +0100
Re: [PATCH tip/core/rcu 02/14] documentation: Fix control dependency and identical stores Peter Zijlstra <peterz@infradead.org> - 2016-02-25 09:30 +0100
Re: [PATCH tip/core/rcu 02/14] documentation: Fix control dependency and identical stores "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-25 15:10 +0100
Re: [PATCH tip/core/rcu 02/14] documentation: Fix control dependency and identical stores Peter Zijlstra <peterz@infradead.org> - 2016-02-25 15:50 +0100
Re: [PATCH tip/core/rcu 02/14] documentation: Fix control dependency and identical stores "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-25 16:50 +0100
[PATCH tip/core/rcu 06/14] documentation: Subsequent writes ordered by rcu_dereference() "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-24 06:20 +0100
csiph-web