* [RFC PATCH] x86: Use volatile semantics for atomic_set()
@ 2014-09-22 19:39 Pranith Kumar
2014-09-22 20:08 ` Peter Zijlstra
0 siblings, 1 reply; 4+ messages in thread
From: Pranith Kumar @ 2014-09-22 19:39 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
maintainer:X86 ARCHITECTURE..., Peter Zijlstra, Paul E. McKenney,
open list:X86 ARCHITECTURE...
All the atomic operations have volatile semantics to prevent compiler
reordering. Enforce the same semantics for atomic_set() too.
Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
---
arch/x86/include/asm/atomic.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
index bf20c81..fa92e93 100644
--- a/arch/x86/include/asm/atomic.h
+++ b/arch/x86/include/asm/atomic.h
@@ -36,7 +36,7 @@ static inline int atomic_read(const atomic_t *v)
*/
static inline void atomic_set(atomic_t *v, int i)
{
- v->counter = i;
+ ACCESS_ONCE(v->counter) = i;
}
/**
--
2.1.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [RFC PATCH] x86: Use volatile semantics for atomic_set()
2014-09-22 19:39 [RFC PATCH] x86: Use volatile semantics for atomic_set() Pranith Kumar
@ 2014-09-22 20:08 ` Peter Zijlstra
2014-09-22 21:42 ` Pranith Kumar
0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2014-09-22 20:08 UTC (permalink / raw)
To: Pranith Kumar
Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
maintainer:X86 ARCHITECTURE..., Paul E. McKenney,
open list:X86 ARCHITECTURE...
On Mon, Sep 22, 2014 at 03:39:21PM -0400, Pranith Kumar wrote:
> All the atomic operations have volatile semantics to prevent compiler
> reordering. Enforce the same semantics for atomic_set() too.
To what point? atomic_set() is typically not what you expect it to
anyhow.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC PATCH] x86: Use volatile semantics for atomic_set()
2014-09-22 20:08 ` Peter Zijlstra
@ 2014-09-22 21:42 ` Pranith Kumar
2014-09-23 8:12 ` Peter Zijlstra
0 siblings, 1 reply; 4+ messages in thread
From: Pranith Kumar @ 2014-09-22 21:42 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
maintainer:X86 ARCHITECTURE..., Paul E. McKenney,
open list:X86 ARCHITECTURE...
On Mon, Sep 22, 2014 at 4:08 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Mon, Sep 22, 2014 at 03:39:21PM -0400, Pranith Kumar wrote:
>> All the atomic operations have volatile semantics to prevent compiler
>> reordering. Enforce the same semantics for atomic_set() too.
>
> To what point? atomic_set() is typically not what you expect it to
> anyhow.
This is the only atomic operation which allows compiler reordering. I
am not sure why this exception was made. Any ideas as to why we do
this?
As I mentioned, this patch removes this inconsistency by disallowing
compiler reordering.
--
Pranith
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC PATCH] x86: Use volatile semantics for atomic_set()
2014-09-22 21:42 ` Pranith Kumar
@ 2014-09-23 8:12 ` Peter Zijlstra
0 siblings, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2014-09-23 8:12 UTC (permalink / raw)
To: Pranith Kumar
Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
maintainer:X86 ARCHITECTURE..., Paul E. McKenney,
open list:X86 ARCHITECTURE...
On Mon, Sep 22, 2014 at 05:42:16PM -0400, Pranith Kumar wrote:
> On Mon, Sep 22, 2014 at 4:08 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> > On Mon, Sep 22, 2014 at 03:39:21PM -0400, Pranith Kumar wrote:
> >> All the atomic operations have volatile semantics to prevent compiler
> >> reordering. Enforce the same semantics for atomic_set() too.
> >
> > To what point? atomic_set() is typically not what you expect it to
> > anyhow.
>
> This is the only atomic operation which allows compiler reordering. I
> am not sure why this exception was made. Any ideas as to why we do
> this?
Because it typically doesn't matter. And you should never use
atomic_set() where it does matter.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-09-23 8:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-22 19:39 [RFC PATCH] x86: Use volatile semantics for atomic_set() Pranith Kumar
2014-09-22 20:08 ` Peter Zijlstra
2014-09-22 21:42 ` Pranith Kumar
2014-09-23 8:12 ` Peter Zijlstra
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.