[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160501195313.GL3686@linux.vnet.ibm.com>
Date: Sun, 1 May 2016 12:53:13 -0700
From: "Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>
To: Christoph Hellwig <hch@...radead.org>
Cc: Muhammad Falak R Wani <falakreyaz@...il.com>,
"Nicholas A. Bellinger" <nab@...ux-iscsi.org>,
target-devel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] target: use RCU_INIT_POINTER() when NULLing.
On Sun, May 01, 2016 at 10:01:20AM -0700, Christoph Hellwig wrote:
> On Sun, May 01, 2016 at 06:22:01PM +0530, Muhammad Falak R Wani wrote:
> > It is safe to use RCU_INIT_POINTER() to NULL, instead of
> > rcu_assign_pointer().
> > This results in slightly smaller/faster code.
>
> If this is indeed the case, rcu_assign_pointer should simply check
> for NULL using __builtin_constant_p and do the right thing transparently
> instead of burdening it on every user.
Last time around, there was a compiler bug that prevented this from
working correctly. But it could well be time to look at it again.
How does the following (untested) patch look?
Thanx, Paul
------------------------------------------------------------------------
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index c61b6b9506e7..3a4dbfe63c1a 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -650,7 +650,16 @@ static inline void rcu_preempt_sleep_check(void)
* please be careful when making changes to rcu_assign_pointer() and the
* other macros that it invokes.
*/
-#define rcu_assign_pointer(p, v) smp_store_release(&p, RCU_INITIALIZER(v))
+#define rcu_assign_pointer(p, v) \
+({ \
+ typeof(v) _r_a_p__v = (v); \
+ \
+ if (__builtin_constant_p(v) && (_r_a_p__v) == NULL) \
+ WRITE_ONCE((p), (_r_a_p__v)); \
+ else \
+ smp_store_release(&p, RCU_INITIALIZER(_r_a_p__v)); \
+ _r_a_p__v; \
+})
/**
* rcu_access_pointer() - fetch RCU pointer with no dereferencing
Powered by blists - more mailing lists