Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1344684
| From | Sergey Fedorov <serge.fdrv@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Documentation/memory-barriers.txt: How can READ_ONCE() and WRITE_ONCE() provide cache coherence? |
| Date | 2016-02-26 22:20 +0100 |
| Message-ID | <r6xXP-JF-7@gated-at.bofh.it> (permalink) |
| Organization | linux.* mail to news gateway |
Hi, I just can't understand how this kind of compiler barrier macros may provide any form of cache coherence. Sure, such kind of compiler barrier is necessary to "reliably" access a variable from multiple CPUs. But why it is stated that these macros *provide* cache coherence? From Documentation/memory-barriers.txt: > The READ_ONCE() and WRITE_ONCE() functions can prevent any number of > optimizations that, while perfectly safe in single-threaded code, can > be fatal in concurrent code. Here are some examples of these sorts > of optimizations: > > (*) The compiler is within its rights to reorder loads and stores > to the same variable, and in some cases, the CPU is within its > rights to reorder loads to the same variable. This means that > the following code: > > a[0] = x; > a[1] = x; > > Might result in an older value of x stored in a[1] than in a[0]. > Prevent both the compiler and the CPU from doing this as follows: > > a[0] = READ_ONCE(x); > a[1] = READ_ONCE(x); > > In short, READ_ONCE() and WRITE_ONCE() provide cache coherence for > accesses from multiple CPUs to a single variable. Thanks, Sergey
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
Documentation/memory-barriers.txt: How can READ_ONCE() and WRITE_ONCE() provide cache coherence? Sergey Fedorov <serge.fdrv@gmail.com> - 2016-02-26 22:20 +0100
Re: Documentation/memory-barriers.txt: How can READ_ONCE() and WRITE_ONCE() provide cache coherence? "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-26 22:40 +0100
Re: Documentation/memory-barriers.txt: How can READ_ONCE() and WRITE_ONCE() provide cache coherence? Sergey Fedorov <serge.fdrv@gmail.com> - 2016-02-27 21:20 +0100
Re: Documentation/memory-barriers.txt: How can READ_ONCE() and WRITE_ONCE() provide cache coherence? "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-02-28 00:00 +0100
Re: Documentation/memory-barriers.txt: How can READ_ONCE() and WRITE_ONCE() provide cache coherence? Sergey Fedorov <serge.fdrv@gmail.com> - 2016-02-29 20:10 +0100
csiph-web