From: Peter Zijlstra <peterz@infradead.org>
To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
mingo@kernel.org, will.deacon@arm.com,
paulmck@linux.vnet.ibm.com, Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH 30/31] arch,doc: Convert smp_mb__*
Date: Wed, 19 Mar 2014 07:47:59 +0100 [thread overview]
Message-ID: <20140319065205.370836264@infradead.org> (raw)
In-Reply-To: 20140319064729.660482086@infradead.org
[-- Attachment #1: peterz-doc-smp_mb__atomic.patch --]
[-- Type: text/plain, Size: 6061 bytes --]
Update the documentation to reflect the change of barrier primitives.
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
---
Documentation/atomic_ops.txt | 31 ++++++++++----------------
Documentation/memory-barriers.txt | 44 ++++++++++----------------------------
2 files changed, 24 insertions(+), 51 deletions(-)
--- a/Documentation/atomic_ops.txt
+++ b/Documentation/atomic_ops.txt
@@ -285,15 +285,13 @@ If a caller requires memory barrier sema
operation which does not return a value, a set of interfaces are
defined which accomplish this:
- void smp_mb__before_atomic_dec(void);
- void smp_mb__after_atomic_dec(void);
- void smp_mb__before_atomic_inc(void);
- void smp_mb__after_atomic_inc(void);
+ void smp_mb__before_atomic(void);
+ void smp_mb__after_atomic(void);
-For example, smp_mb__before_atomic_dec() can be used like so:
+For example, smp_mb__before_atomic() can be used like so:
obj->dead = 1;
- smp_mb__before_atomic_dec();
+ smp_mb__before_atomic();
atomic_dec(&obj->ref_count);
It makes sure that all memory operations preceding the atomic_dec()
@@ -302,15 +300,10 @@ operation. In the above example, it gua
"1" to obj->dead will be globally visible to other cpus before the
atomic counter decrement.
-Without the explicit smp_mb__before_atomic_dec() call, the
+Without the explicit smp_mb__before_atomic() call, the
implementation could legally allow the atomic counter update visible
to other cpus before the "obj->dead = 1;" assignment.
-The other three interfaces listed are used to provide explicit
-ordering with respect to memory operations after an atomic_dec() call
-(smp_mb__after_atomic_dec()) and around atomic_inc() calls
-(smp_mb__{before,after}_atomic_inc()).
-
A missing memory barrier in the cases where they are required by the
atomic_t implementation above can have disastrous results. Here is
an example, which follows a pattern occurring frequently in the Linux
@@ -487,12 +480,12 @@ memory operation done by test_and_set_bi
Which returns a boolean indicating if bit "nr" is set in the bitmask
pointed to by "addr".
-If explicit memory barriers are required around clear_bit() (which
-does not return a value, and thus does not need to provide memory
-barrier semantics), two interfaces are provided:
+If explicit memory barriers are required around {set,clear}_bit() (which do
+not return a value, and thus does not need to provide memory barrier
+semantics), two interfaces are provided:
- void smp_mb__before_clear_bit(void);
- void smp_mb__after_clear_bit(void);
+ void smp_mb__before_atomic(void);
+ void smp_mb__after_atomic(void);
They are used as follows, and are akin to their atomic_t operation
brothers:
@@ -500,13 +493,13 @@ They are used as follows, and are akin t
/* All memory operations before this call will
* be globally visible before the clear_bit().
*/
- smp_mb__before_clear_bit();
+ smp_mb__before_atomic();
clear_bit( ... );
/* The clear_bit() will be visible before all
* subsequent memory operations.
*/
- smp_mb__after_clear_bit();
+ smp_mb__after_atomic();
There are two special bitops with lock barrier semantics (acquire/release,
same as spinlocks). These operate in the same way as their non-_lock/unlock
--- a/Documentation/memory-barriers.txt
+++ b/Documentation/memory-barriers.txt
@@ -1583,20 +1583,21 @@ CPU from reordering them.
insert anything more than a compiler barrier in a UP compilation.
- (*) smp_mb__before_atomic_dec();
- (*) smp_mb__after_atomic_dec();
- (*) smp_mb__before_atomic_inc();
- (*) smp_mb__after_atomic_inc();
-
- These are for use with atomic add, subtract, increment and decrement
- functions that don't return a value, especially when used for reference
- counting. These functions do not imply memory barriers.
+ (*) smp_mb__before_atomic();
+ (*) smp_mb__after_atomic();
+
+ These are for use with atomic (such as add, subtract, increment and
+ decrement) functions that don't return a value, especially when used for
+ reference counting. These functions do not imply memory barriers.
+
+ These are also used for atomic bitop functions that do not return a
+ value (such as set_bit and clear_bit).
As an example, consider a piece of code that marks an object as being dead
and then decrements the object's reference count:
obj->dead = 1;
- smp_mb__before_atomic_dec();
+ smp_mb__before_atomic();
atomic_dec(&obj->ref_count);
This makes sure that the death mark on the object is perceived to be set
@@ -1606,27 +1607,6 @@ CPU from reordering them.
operations" subsection for information on where to use these.
- (*) smp_mb__before_clear_bit(void);
- (*) smp_mb__after_clear_bit(void);
-
- These are for use similar to the atomic inc/dec barriers. These are
- typically used for bitwise unlocking operations, so care must be taken as
- there are no implicit memory barriers here either.
-
- Consider implementing an unlock operation of some nature by clearing a
- locking bit. The clear_bit() would then need to be barriered like this:
-
- smp_mb__before_clear_bit();
- clear_bit( ... );
-
- This prevents memory operations before the clear leaking to after it. See
- the subsection on "Locking Functions" with reference to RELEASE operation
- implications.
-
- See Documentation/atomic_ops.txt for more information. See the "Atomic
- operations" subsection for information on where to use these.
-
-
MMIO WRITE BARRIER
------------------
@@ -2283,11 +2263,11 @@ barriers, but might be used for implemen
change_bit();
With these the appropriate explicit memory barrier should be used if necessary
-(smp_mb__before_clear_bit() for instance).
+(smp_mb__before_atomic() for instance).
The following also do _not_ imply memory barriers, and so may require explicit
-memory barriers under some circumstances (smp_mb__before_atomic_dec() for
+memory barriers under some circumstances (smp_mb__before_atomic() for
instance):
atomic_add();
next prev parent reply other threads:[~2014-03-19 6:47 UTC|newest]
Thread overview: 79+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-19 6:47 [PATCH 00/31] Clean up smp_mb__ barriers Peter Zijlstra
2014-03-19 6:47 ` [PATCH 01/31] ia64: Fix up smp_mb__{before,after}_clear_bit Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 02/31] arc,hexagon: Delete asm/barrier.h Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 03/31] arch: Prepare for smp_mb__{before,after}_atomic() Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 04/31] arch,alpha: Convert smp_mb__* Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 05/31] arch,arc: " Peter Zijlstra
2014-03-19 6:47 ` [PATCH 06/31] arch,arm: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-04-14 16:19 ` Will Deacon
2014-04-14 16:19 ` Will Deacon
2014-03-19 6:47 ` [PATCH 07/31] arch,arm64: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-21 11:54 ` Catalin Marinas
2014-03-19 6:47 ` [PATCH 08/31] arch,avr32: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 09/31] arch,blackfin: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 10/31] arch,c6x: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-04-09 15:35 ` Mark Salter
2014-04-09 15:35 ` Mark Salter
2014-03-19 6:47 ` [PATCH 11/31] arch,cris: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-20 11:11 ` Jesper Nilsson
2014-03-20 11:11 ` Jesper Nilsson
2014-03-19 6:47 ` [PATCH 12/31] arch,frv: " Peter Zijlstra
2014-03-19 6:47 ` [PATCH 13/31] arch,hexagon: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 14/31] arch,ia64: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 15/31] arch,m32r: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 16/31] arch,m68k: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 17/31] arch,metag: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 18/31] arch,mips: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 19/31] arch,mn10300: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 20/31] arch,openrisc: " Peter Zijlstra
2014-03-19 6:47 ` [PATCH 21/31] arch,parisc: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 22/31] arch,powerpc: " Peter Zijlstra
2014-03-19 6:47 ` [PATCH 23/31] arch,s390: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 13:50 ` Heiko Carstens
2014-03-19 6:47 ` [PATCH 24/31] arch,score: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 18:53 ` Lennox Wu
2014-03-19 6:47 ` [PATCH 25/31] arch,sh: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 26/31] arch,sparc: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 17:54 ` David Miller
2014-03-19 6:47 ` [PATCH 27/31] arch,tile: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 17:49 ` Chris Metcalf
2014-03-19 17:49 ` Chris Metcalf
2014-03-19 6:47 ` [PATCH 28/31] arch, x86: " Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra
2014-03-19 6:47 ` [PATCH 29/31] arch,xtensa: " Peter Zijlstra
2014-03-19 13:11 ` Max Filippov
2014-03-19 13:11 ` Max Filippov
2014-03-19 13:30 ` Peter Zijlstra
2014-03-19 13:30 ` Peter Zijlstra
2014-03-19 6:47 ` Peter Zijlstra [this message]
2014-03-19 6:47 ` [PATCH 30/31] arch,doc: " Peter Zijlstra
2014-03-19 17:15 ` Paul E. McKenney
2014-03-19 6:48 ` [PATCH 31/31] arch: Mass conversion of smp_mb__* Peter Zijlstra
2014-03-19 6:48 ` Peter Zijlstra
2014-03-19 9:55 ` [PATCH 00/31] Clean up smp_mb__ barriers David Howells
2014-03-19 9:58 ` Peter Zijlstra
2014-03-19 10:07 ` David Howells
2014-03-19 17:36 ` [PATCH 30/31] arch,doc: Convert smp_mb__* David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140319065205.370836264@infradead.org \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=torvalds@linux-foundation.org \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).