Skip to content

Commit e0775ce

Browse files
committed
rcu: Avoid IPIing idle CPUs from synchronize_sched_expedited()
Currently, synchronize_sched_expedited() sends IPIs to all online CPUs, even those that are idle or executing in nohz_full= userspace. Because idle CPUs and nohz_full= userspace CPUs are in extended quiescent states, there is no need to IPI them in the first place. This commit therefore avoids IPIing CPUs that are already in extended quiescent states. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent 61cfd09 commit e0775ce

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

‎kernel/rcu/tree.c‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2950,6 +2950,9 @@ static int synchronize_sched_expedited_cpu_stop(void *data)
29502950
*/
29512951
void synchronize_sched_expedited(void)
29522952
{
2953+
cpumask_var_t cm;
2954+
bool cma = false;
2955+
int cpu;
29532956
long firstsnap, s, snap;
29542957
int trycount = 0;
29552958
struct rcu_state *rsp = &rcu_sched_state;
@@ -2984,11 +2987,26 @@ void synchronize_sched_expedited(void)
29842987
}
29852988
WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
29862989

2990+
/* Offline CPUs, idle CPUs, and any CPU we run on are quiescent. */
2991+
cma = zalloc_cpumask_var(&cm, GFP_KERNEL);
2992+
if (cma) {
2993+
cpumask_copy(cm, cpu_online_mask);
2994+
cpumask_clear_cpu(raw_smp_processor_id(), cm);
2995+
for_each_cpu(cpu, cm) {
2996+
struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
2997+
2998+
if (!(atomic_add_return(0, &rdtp->dynticks) & 0x1))
2999+
cpumask_clear_cpu(cpu, cm);
3000+
}
3001+
if (cpumask_weight(cm) == 0)
3002+
goto all_cpus_idle;
3003+
}
3004+
29873005
/*
29883006
* Each pass through the following loop attempts to force a
29893007
* context switch on each CPU.
29903008
*/
2991-
while (try_stop_cpus(cpu_online_mask,
3009+
while (try_stop_cpus(cma ? cm : cpu_online_mask,
29923010
synchronize_sched_expedited_cpu_stop,
29933011
NULL) == -EAGAIN) {
29943012
put_online_cpus();
@@ -3000,6 +3018,7 @@ void synchronize_sched_expedited(void)
30003018
/* ensure test happens before caller kfree */
30013019
smp_mb__before_atomic(); /* ^^^ */
30023020
atomic_long_inc(&rsp->expedited_workdone1);
3021+
free_cpumask_var(cm);
30033022
return;
30043023
}
30053024

@@ -3009,6 +3028,7 @@ void synchronize_sched_expedited(void)
30093028
} else {
30103029
wait_rcu_gp(call_rcu_sched);
30113030
atomic_long_inc(&rsp->expedited_normal);
3031+
free_cpumask_var(cm);
30123032
return;
30133033
}
30143034

@@ -3018,6 +3038,7 @@ void synchronize_sched_expedited(void)
30183038
/* ensure test happens before caller kfree */
30193039
smp_mb__before_atomic(); /* ^^^ */
30203040
atomic_long_inc(&rsp->expedited_workdone2);
3041+
free_cpumask_var(cm);
30213042
return;
30223043
}
30233044

@@ -3032,13 +3053,17 @@ void synchronize_sched_expedited(void)
30323053
/* CPU hotplug operation in flight, use normal GP. */
30333054
wait_rcu_gp(call_rcu_sched);
30343055
atomic_long_inc(&rsp->expedited_normal);
3056+
free_cpumask_var(cm);
30353057
return;
30363058
}
30373059
snap = atomic_long_read(&rsp->expedited_start);
30383060
smp_mb(); /* ensure read is before try_stop_cpus(). */
30393061
}
30403062
atomic_long_inc(&rsp->expedited_stoppedcpus);
30413063

3064+
all_cpus_idle:
3065+
free_cpumask_var(cm);
3066+
30423067
/*
30433068
* Everyone up to our most recent fetch is covered by our grace
30443069
* period. Update the counter, but only if our work is still

0 commit comments

Comments
 (0)