Fix: move wait loop increment before first conditional block
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 1 Mar 2014 21:22:52 +0000 (16:22 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 1 Mar 2014 21:22:52 +0000 (16:22 -0500)
The fix "Fix: high cpu usage in synchronize_rcu with long RCU read-side
C.S." has an imperfection in urcu.c and urcu-qsbr.c: when incrementing
the wait loop counter for the last time, the first conditional branch is
not taken, but the following conditionals are, and they assume the first
conditional has been taken.

Within urcu.c (urcu-mb, urcu-membarrier and urcu-signal), and
urcu-qsbr.c, this will simply skip the first wait_gp() call, without any
noticeable ill side-effect.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
urcu-qsbr.c
urcu.c

index d02572513139eb5986529328c0066deb319cafc9..d8ae1c1257517645e22ef143b8b23950ff330d1b 100644 (file)
@@ -130,6 +130,8 @@ static void wait_for_readers(struct cds_list_head *input_readers,
         * current rcu_gp.ctr value.
         */
        for (;;) {
+               if (wait_loops < RCU_QS_ACTIVE_ATTEMPTS)
+                       wait_loops++;
                if (wait_loops >= RCU_QS_ACTIVE_ATTEMPTS) {
                        uatomic_set(&rcu_gp.futex, -1);
                        /*
@@ -142,8 +144,6 @@ static void wait_for_readers(struct cds_list_head *input_readers,
                        }
                        /* Write futex before read reader_gp */
                        cmm_smp_mb();
-               } else {
-                       wait_loops++;
                }
                cds_list_for_each_entry_safe(index, tmp, input_readers, node) {
                        switch (rcu_reader_state(&index->ctr)) {
diff --git a/urcu.c b/urcu.c
index 087a0c67ad73fddf212fec3bd4ff63854ab8b8d4..8cccbbce0868b518f9020f2d94eaedd41e22d2dc 100644 (file)
--- a/urcu.c
+++ b/urcu.c
@@ -242,12 +242,12 @@ static void wait_for_readers(struct cds_list_head *input_readers,
         * rcu_gp.ctr value.
         */
        for (;;) {
+               if (wait_loops < RCU_QS_ACTIVE_ATTEMPTS)
+                       wait_loops++;
                if (wait_loops >= RCU_QS_ACTIVE_ATTEMPTS) {
                        uatomic_dec(&rcu_gp.futex);
                        /* Write futex before read reader_gp */
                        smp_mb_master(RCU_MB_GROUP);
-               } else {
-                       wait_loops++;
                }
 
                cds_list_for_each_entry_safe(index, tmp, input_readers, node) {
This page took 0.027789 seconds and 4 git commands to generate.