[ltt-dev] [PATCH 4/7] urcu, defer_rcu: Simplify defer_rcu() encoding

Lai Jiangshan laijs at cn.fujitsu.com
Wed Sep 28 04:34:30 EDT 2011


use the same code as function changed even only
just the data is not aligned.

Signed-off-by: Lai Jiangshan <laijs at cn.fujitsu.com>
---
 urcu-defer-impl.h |   38 ++++++++++++++++++++------------------
 1 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/urcu-defer-impl.h b/urcu-defer-impl.h
index 49570ff..b1478ab 100644
--- a/urcu-defer-impl.h
+++ b/urcu-defer-impl.h
@@ -61,7 +61,7 @@
  * Assumes that (void *)-2L is not used often. Used to encode non-aligned
  * functions and non-aligned data using extra space.
  * We encode the (void *)-2L fct as: -2L, fct, data.
- * We encode the (void *)-2L data as: -2L, fct, data.
+ * We encode the (void *)-2L data as: fct | DQ_FCT_BIT, data or -2L, fct, data.
  * Here, DQ_FCT_MARK == ~DQ_FCT_BIT. Required for the test order.
  */
 #define DQ_FCT_BIT		(1 << 0)
@@ -318,14 +318,27 @@ void _defer_rcu(void (*fct)(void *p), void *p)
 		assert(head - CMM_LOAD_SHARED(defer_queue.tail) == 0);
 	}
 
-	if (unlikely(defer_queue.last_fct_in != fct)) {
+	/*
+	 * Encode:
+	 * if the function is not changed and the data is aligned and it is
+	 * not the marker:
+	 *	store the data
+	 * otherwise if the function is aligned and its not the marker:
+	 *	store the funciotn with DQ_FCT_BIT
+	 *	store the data
+	 * otherwise:
+	 *	store the marker (DQ_FCT_MARK)
+	 *	store the funciotn
+	 *	store the data
+	 *
+	 * Decode: see the comments before 'struct defer_queue'
+	 *         or the code in rcu_defer_barrier_queue().
+	 */
+	if (unlikely(defer_queue.last_fct_in != fct
+			|| DQ_IS_FCT_BIT(p)
+			|| p == DQ_FCT_MARK)) {
 		defer_queue.last_fct_in = fct;
 		if (unlikely(DQ_IS_FCT_BIT(fct) || fct == DQ_FCT_MARK)) {
-			/*
-			 * If the function to encode is not aligned or the
-			 * marker, write DQ_FCT_MARK followed by the function
-			 * pointer.
-			 */
 			_CMM_STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK],
 				      DQ_FCT_MARK);
 			_CMM_STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK],
@@ -335,17 +348,6 @@ void _defer_rcu(void (*fct)(void *p), void *p)
 			_CMM_STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK],
 				      fct);
 		}
-	} else {
-		if (unlikely(DQ_IS_FCT_BIT(p) || p == DQ_FCT_MARK)) {
-			/*
-			 * If the data to encode is not aligned or the marker,
-			 * write DQ_FCT_MARK followed by the function pointer.
-			 */
-			_CMM_STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK],
-				      DQ_FCT_MARK);
-			_CMM_STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK],
-				      fct);
-		}
 	}
 	_CMM_STORE_SHARED(defer_queue.q[head++ & DEFER_QUEUE_MASK], p);
 	cmm_smp_wmb();	/* Publish new pointer before head */
-- 
1.7.4.4





More information about the lttng-dev mailing list