urcu,defer_rcu: Make defer_rcu encoding more compact for marker
authorLai Jiangshan <laijs@cn.fujitsu.com>
Thu, 29 Sep 2011 17:47:13 +0000 (13:47 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 29 Sep 2011 17:47:13 +0000 (13:47 -0400)
When the function changes (and the function is aligned), and only the
data is the marker, we can get away with using only 2 pointers rather
than 3.

[ Edit by Mathieu Desnoyers: patch cleanup, changelog updates ]

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
urcu-defer-impl.h

index 4211f7c76954c2fc1bfd088ac0497cb2a34516a9..34d99c92997641323175c909f13f793fa27df33d 100644 (file)
@@ -61,7 +61,9 @@
  * 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 either:
+ *   fct | DQ_FCT_BIT, data (if fct is aligned), or
+ *   -2L, fct, data (if fct is not aligned).
  * Here, DQ_FCT_MARK == ~DQ_FCT_BIT. Required for the test order.
  */
 #define DQ_FCT_BIT             (1 << 0)
@@ -322,14 +324,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 function with DQ_FCT_BIT
+        *      store the data
+        * otherwise:
+        *      store the marker (DQ_FCT_MARK)
+        *      store the function
+        *      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],
@@ -339,17 +354,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 */
This page took 0.02587 seconds and 4 git commands to generate.