All of lore.kernel.org
 help / color / mirror / Atom feed
* Is WRITE_ONCE() enough to prevent invention of stores?
@ 2017-09-16 11:01 Akira Yokosawa
  2017-09-17  1:07 ` Paul E. McKenney
  0 siblings, 1 reply; 15+ messages in thread
From: Akira Yokosawa @ 2017-09-16 11:01 UTC (permalink / raw)
  To: Paul E. McKenney; +Cc: perfbook, Akira Yokosawa

Hi Paul,

I'm a bit disturbed by the description in Section 14.3.1 "Memory-Reference
Restrictions" quoted below:

> Oddly enough, the compiler is within its rights to use a variable
> as temporary storage just before a store to that variable, thus
> inventing stores to that variable.
> Fortunately, most compilers avoid this sort of thing, at least outside
> of stack variables.
> Nevertheless, using WRITE_ONCE() (or declaring the variable
> volatile) should prevent this sort of thing.
> But take care: If you have a translation unit that uses that variable,
> and never makes a volatile access to it, the compiler has no way of
> knowing that it needs to be careful.

I'm wondering if using WRITE_ONCE() in a translation unit is really
enough to prevent invention of stores.

Accessing via a volatile-cast pointer guarantees the access is not
optimized out (and hopefully the referenced value is respected).

But I suspect that it has any effect in preventing invention of extra
loads/stores.

Isn't declaring the variable volatile necessary for the guarantee?

In practice, as is described in the above quote: "Fortunately, most
compilers avoid this sort of thing, at least outside of stack variables",
we can assume non-volatile shared variables are not spilled out to
the variables themselves as far as GCC/LLVM is concerned.
But this is compiler dependent, I suppose.

      Thanks, Akira


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-11-01 20:15 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-16 11:01 Is WRITE_ONCE() enough to prevent invention of stores? Akira Yokosawa
2017-09-17  1:07 ` Paul E. McKenney
2017-09-17 11:04   ` Akira Yokosawa
2017-09-17 21:55     ` Paul E. McKenney
2017-09-17 22:51       ` Akira Yokosawa
2017-10-30 18:14         ` Paul E. McKenney
2017-10-31  3:03           ` Yubin Ruan
2017-10-31  3:14             ` [PATCH] memorder: Add one solution for one snippet Yubin Ruan
2017-10-31  3:50               ` Paul E. McKenney
2017-10-31  5:04                 ` Yubin Ruan
2017-10-31  3:45             ` Is WRITE_ONCE() enough to prevent invention of stores? Paul E. McKenney
2017-10-31 15:36           ` Akira Yokosawa
2017-10-31 16:27             ` Paul E. McKenney
2017-10-31 22:25               ` Akira Yokosawa
2017-11-01 20:15                 ` Paul E. McKenney

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.