Skip to content

Commit e62d8ae

Browse files
paulmckrcuFrederic Weisbecker
authored andcommitted
rcu-tasks: Pull sampling of ->percpu_dequeue_lim out of loop
The rcu_tasks_need_gpcb() samples ->percpu_dequeue_lim as part of the condition clause of a "for" loop, which is a bit confusing. This commit therefore hoists this sampling out of the loop, using the result loaded in the condition clause. So why does this work in the face of a concurrent switch from single-CPU queueing to per-CPU queueing? o The call_rcu_tasks_generic() that makes the change has already enqueued its callback, which means that all of the other CPU's callback queues are empty. o For the call_rcu_tasks_generic() that first notices the switch to per-CPU queues, the smp_store_release() used to update ->percpu_enqueue_lim pairs with the raw_spin_trylock_rcu_node()'s full barrier that is between the READ_ONCE(rtp->percpu_enqueue_shift) and the rcu_segcblist_enqueue() that enqueues the callback. o Because this CPU's queue is empty (unless it happens to be the original single queue, in which case there is no need for synchronization), this call_rcu_tasks_generic() will do an irq_work_queue() to schedule a handler for the needed rcuwait_wake_up() call. This call will be ordered after the first call_rcu_tasks_generic() function's change to ->percpu_dequeue_lim. o This rcuwait_wake_up() will either happen before or after the set_current_state() in rcuwait_wait_event(). If it happens before, the "condition" argument's call to rcu_tasks_need_gpcb() will be ordered after the original change, and all callbacks on all CPUs will be visible. Otherwise, if it happens after, then the grace-period kthread's state will be set back to running, which will result in a later call to rcuwait_wait_event() and thus to rcu_tasks_need_gpcb(), which will again see the change. So it all works out. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
1 parent 92a708d commit e62d8ae

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/rcu/tasks.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,16 @@ static void rcu_barrier_tasks_generic(struct rcu_tasks *rtp)
432432
static int rcu_tasks_need_gpcb(struct rcu_tasks *rtp)
433433
{
434434
int cpu;
435+
int dequeue_limit;
435436
unsigned long flags;
436437
bool gpdone = poll_state_synchronize_rcu(rtp->percpu_dequeue_gpseq);
437438
long n;
438439
long ncbs = 0;
439440
long ncbsnz = 0;
440441
int needgpcb = 0;
441442

442-
for (cpu = 0; cpu < smp_load_acquire(&rtp->percpu_dequeue_lim); cpu++) {
443+
dequeue_limit = smp_load_acquire(&rtp->percpu_dequeue_lim);
444+
for (cpu = 0; cpu < dequeue_limit; cpu++) {
443445
struct rcu_tasks_percpu *rtpcp = per_cpu_ptr(rtp->rtpcpu, cpu);
444446

445447
/* Advance and accelerate any new callbacks. */

0 commit comments

Comments
 (0)