lkml.org 
[lkml]   [2016]   [Feb]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: Documentation/memory-barriers.txt: How can READ_ONCE() and WRITE_ONCE() provide cache coherence?
From
Date
On 27.02.2016 00:31, Paul E. McKenney wrote:
> Without READ_ONCE(), common sub-expression elimination optimizations
> can cause later reads of a given variable to see older value than
> previous reads did. For a (silly) example:
>
> a = complicated_pure_function(x);
> b = x;
> c = complicated_pure_function(x);
>
> The compiler is within its rights to transform this into the following:
>
> a = complicated_pure_function(x);
> b = x;
> c = a(x);
>
> In this case, the assignment to b might see a newer value of x than did
> the later assignment to c. This violates cache coherence, which states
> that all reads from a given variable must agree on the order of values
> taken on by that variable.

I see how READ_ONCE() and WRITE_ONCE() can prevent compiler from
speculating on variable values and optimizing memory accesses. But
concerning cache coherency itself, my understanding is that software can
really ensure hardware cache coherency by using one of the following
methods:
- by not using the caches
- by using some sort of cache maintenance instructions
- by using hardware cache coherency mechanisms (which is what normally
used)

What kind of "cache coherency" do you mean?

Thanks,
Sergey

\
 
 \ /
  Last update: 2016-02-27 22:01    [W:0.049 / U:0.500 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site