[PATCH] Document non-semantics of atomic_read() and atomic_set()

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Linus Torvalds <torvalds@...>
Cc: Denys Vlasenko <vda.linux@...>, Kyle Moffett <mrmacman_g4@...>, Arjan van de Ven <arjan@...>, Nick Piggin <piggin@...>, Satyam Sharma <satyam@...>, Herbert Xu <herbert@...>, Paul Mackerras <paulus@...>, Christoph Lameter <clameter@...>, Ilpo Jarvinen <ilpo.jarvinen@...>, Paul E. McKenney <paulmck@...>, Stefan Richter <stefanr@...>, Linux Kernel Mailing List <linux-kernel@...>, <linux-arch@...>, Netdev <netdev@...>, Andrew Morton <akpm@...>, <ak@...>, <heiko.carstens@...>, David Miller <davem@...>, <schwidefsky@...>, <wensong@...>, <horms@...>, <wjiang@...>, <cfriesen@...>, <zlynx@...>, <rpjday@...>, <jesper.juhl@...>, <segher@...>
Date: Monday, September 10, 2007 - 7:19 pm

From: Chris Snook <csnook@redhat.com>

Unambiguously document the fact that atomic_read() and atomic_set()
do not imply any ordering or memory access, and that callers are
obligated to explicitly invoke barriers as needed to ensure that
changes to atomic variables are visible in all contexts that need
to see them.

Signed-off-by: Chris Snook <csnook@redhat.com>

--- a/Documentation/atomic_ops.txt	2007-07-08 19:32:17.000000000 -0400
+++ b/Documentation/atomic_ops.txt	2007-09-10 19:02:50.000000000 -0400
@@ -12,7 +12,11 @@
 C integer type will fail.  Something like the following should
 suffice:
 
-	typedef struct { volatile int counter; } atomic_t;
+	typedef struct { int counter; } atomic_t;
+
+	Historically, counter has been declared volatile.  This is now
+discouraged.  See Documentation/volatile-considered-harmful.txt for the
+complete rationale.
 
 	The first operations to implement for atomic_t's are the
 initializers and plain reads.
@@ -42,6 +46,22 @@
 
 which simply reads the current value of the counter.
 
+*** WARNING: atomic_read() and atomic_set() DO NOT IMPLY BARRIERS! ***
+
+Some architectures may choose to use the volatile keyword, barriers, or
+inline assembly to guarantee some degree of immediacy for atomic_read()
+and atomic_set().  This is not uniformly guaranteed, and may change in
+the future, so all users of atomic_t should treat atomic_read() and
+atomic_set() as simple C assignment statements that may be reordered or
+optimized away entirely by the compiler or processor, and explicitly
+invoke the appropriate compiler and/or memory barrier for each use case.
+Failure to do so will result in code that may suddenly break when used with
+different architectures or compiler optimizations, or even changes in
+unrelated code which changes how the compiler optimizes the section
+accessing atomic_t variables.
+
+*** YOU HAVE BEEN WARNED! ***
+
 Now, we move onto the actual atomic operation interfaces.
 
 	void atomic_add(int i, atomic_t *v);
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Tue Aug 14, 6:31 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Wed Aug 15, 3:59 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Thu Aug 16, 4:50 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Fri Aug 17, 6:34 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Thu Aug 16, 5:00 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Fri Aug 17, 6:38 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Fri Aug 24, 1:15 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Wed Aug 15, 8:26 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Wed Aug 15, 8:42 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Wed Aug 15, 10:07 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Thu Aug 16, 3:39 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Thu Aug 16, 2:54 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Thu Aug 16, 4:20 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Fri Aug 17, 1:41 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Mon Sep 10, 2:59 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Mon Sep 10, 10:27 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Mon Sep 10, 5:36 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Fri Aug 17, 7:17 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Fri Aug 17, 8:04 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Fri Aug 17, 10:15 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Sat Aug 18, 1:18 am)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Fri Aug 17, 6:09 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Arjan van de Ven, (Mon Sep 10, 10:51 am)
[PATCH] Document non-semantics of atomic_read() and atomic_s..., Chris Snook, (Mon Sep 10, 7:19 pm)
Re: [PATCH] Document non-semantics of atomic_read() and atom..., Christoph Lameter, (Tue Sep 11, 3:35 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Mon Sep 10, 2:59 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Tue Aug 21, 10:59 am)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Mon Aug 20, 6:07 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Paul E. McKenney, (Thu Aug 16, 12:34 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Fri Aug 17, 6:14 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Paul E. McKenney, (Fri Aug 17, 10:31 am)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Wed Aug 15, 10:15 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Wed Aug 15, 10:17 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Paul E. McKenney, (Wed Aug 15, 10:35 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Wed Aug 15, 8:59 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Wed Aug 15, 9:41 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Paul E. McKenney, (Wed Aug 15, 10:32 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Wed Aug 15, 8:40 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Wed Aug 15, 2:31 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Wed Aug 15, 4:42 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Paul E. McKenney, (Wed Aug 15, 10:25 am)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Wed Aug 15, 4:58 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Segher Boessenkool, (Wed Aug 15, 5:07 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Paul E. McKenney, (Wed Aug 15, 12:08 pm)
Re: [PATCH 0/24] make atomic_read() behave consistently acro..., Christoph Lameter, (Tue Aug 14, 6:51 pm)