Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=d99c4f6b13b3149bc83703ab1493beaeaaaf8a2d
Commit:     d99c4f6b13b3149bc83703ab1493beaeaaaf8a2d
Parent:     ba6f867f114760d4e43f0f93abe280ee0a0d696e
Author:     Paul E. McKenney <[EMAIL PROTECTED]>
AuthorDate: Wed Feb 6 01:37:25 2008 -0800
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Wed Feb 6 10:41:06 2008 -0800

    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/[EMAIL PROTECTED]/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 <[EMAIL PROTECTED]>
    Acked-by: Herbert Xu <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
---
 include/linux/rcupdate.h |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index d32c14d..37a642c 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -174,10 +174,13 @@ struct rcu_head {
  * code.
  */
 
-#define rcu_assign_pointer(p, v)       ({ \
-                                               smp_wmb(); \
-                                               (p) = (v); \
-                                       })
+#define rcu_assign_pointer(p, v) \
+       ({ \
+               if (!__builtin_constant_p(v) || \
+                   ((v) != NULL)) \
+                       smp_wmb(); \
+               (p) = (v); \
+       })
 
 /**
  * synchronize_sched - block until all CPUs have exited any non-preemptive
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to