Skip to content

Commit faa059c

Browse files
committed
rcu: Optimize and protect atomic_cmpxchg() loop
This commit reworks the atomic_cmpxchg() loop in rcu_eqs_special_set() to do only the initial read from the current CPU's rcu_data structure's ->dynticks field explicitly. On subsequent passes, this value is instead retained from the failing atomic_cmpxchg() operation. Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 92c0b88 commit faa059c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

kernel/rcu/tree.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,17 @@ bool rcu_eqs_special_set(int cpu)
342342
{
343343
int old;
344344
int new;
345+
int new_old;
345346
struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
346347

348+
new_old = atomic_read(&rdp->dynticks);
347349
do {
348-
old = atomic_read(&rdp->dynticks);
350+
old = new_old;
349351
if (old & RCU_DYNTICK_CTRL_CTR)
350352
return false;
351353
new = old | RCU_DYNTICK_CTRL_MASK;
352-
} while (atomic_cmpxchg(&rdp->dynticks, old, new) != old);
354+
new_old = atomic_cmpxchg(&rdp->dynticks, old, new);
355+
} while (new_old != old);
353356
return true;
354357
}
355358

0 commit comments

Comments
 (0)