aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/rcupdate.h
diff options
context:
space:
mode:
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>2008-02-06 04:37:25 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-06 13:41:06 -0500
commitd99c4f6b13b3149bc83703ab1493beaeaaaf8a2d (patch)
tree32e09d76cb46755d7420e6ad9a6e0802dab47963 /include/linux/rcupdate.h
parentba6f867f114760d4e43f0f93abe280ee0a0d696e (diff)
Remove rcu_assign_pointer() penalty for NULL pointers
The rcu_assign_pointer() primitive currently unconditionally executes a memory barrier, even when a NULL pointer is being assigned. This has lead some to avoid using rcu_assign_pointer() for NULL pointers, which loses the self-documenting advantages of rcu_assign_pointer() This patch uses __builtin_const_p() to omit needless memory barriers for NULL-pointer assignments at compile time with no runtime penalty, as discussed in the following thread: http://www.mail-archive.com/netdev@vger.kernel.org/msg54852.html Tested on x86_64 and ppc64, also compiled the four cases (NULL/non-NULL and const/non-const) with gcc version 4.1.2, and hand-checked the assembly output. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Acked-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/rcupdate.h')
-rw-r--r--include/linux/rcupdate.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index d32c14de270e..37a642c54871 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -174,10 +174,13 @@ struct rcu_head {
174 * code. 174 * code.
175 */ 175 */
176 176
177#define rcu_assign_pointer(p, v) ({ \ 177#define rcu_assign_pointer(p, v) \
178 smp_wmb(); \ 178 ({ \
179 (p) = (v); \ 179 if (!__builtin_constant_p(v) || \
180 }) 180 ((v) != NULL)) \
181 smp_wmb(); \
182 (p) = (v); \
183 })
181 184
182/** 185/**
183 * synchronize_sched - block until all CPUs have exited any non-preemptive 186 * synchronize_sched - block until all CPUs have exited any non-preemptive