Skip to content

Commit a81aeaf

Browse files
Frederic Weisbeckerpaulmckrcu
authored andcommitted
rcu/nocb: Optimize kthreads and rdp initialization
Currently cpumask_available() is used to prevent from unwanted NOCB initialization. However if neither "rcu_nocbs=" nor "nohz_full=" parameters are passed to a kernel built with CONFIG_CPUMASK_OFFSTACK=n, the initialization path is still taken, running through all sorts of needless operations and iterations on an empty cpumask. Fix this by relying on a real initialization state instead. This also optimizes kthread creation, preventing needless iteration over all online CPUs when the kernel is booted without any offloaded CPUs. Reviewed-by: Neeraj Upadhyay <quic_neeraju@quicinc.com> Signed-off-by: Frederic Weisbecker <frederic@kernel.org> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Uladzislau Rezki <urezki@gmail.com> Cc: Josh Triplett <josh@joshtriplett.org> Cc: Joel Fernandes <joel@joelfernandes.org> Tested-by: Juri Lelli <juri.lelli@redhat.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent 8d97039 commit a81aeaf

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

kernel/rcu/tree_nocb.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@ static inline bool rcu_current_is_nocb_kthread(struct rcu_data *rdp)
6060
* Parse the boot-time rcu_nocb_mask CPU list from the kernel parameters.
6161
* If the list is invalid, a warning is emitted and all CPUs are offloaded.
6262
*/
63+
64+
static bool rcu_nocb_is_setup;
65+
6366
static int __init rcu_nocb_setup(char *str)
6467
{
6568
alloc_bootmem_cpumask_var(&rcu_nocb_mask);
6669
if (cpulist_parse(str, rcu_nocb_mask)) {
6770
pr_warn("rcu_nocbs= bad CPU range, all CPUs set\n");
6871
cpumask_setall(rcu_nocb_mask);
6972
}
73+
rcu_nocb_is_setup = true;
7074
return 1;
7175
}
7276
__setup("rcu_nocbs=", rcu_nocb_setup);
@@ -1167,13 +1171,17 @@ void __init rcu_init_nohz(void)
11671171
need_rcu_nocb_mask = true;
11681172
#endif /* #if defined(CONFIG_NO_HZ_FULL) */
11691173

1170-
if (!cpumask_available(rcu_nocb_mask) && need_rcu_nocb_mask) {
1171-
if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
1172-
pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n");
1173-
return;
1174+
if (need_rcu_nocb_mask) {
1175+
if (!cpumask_available(rcu_nocb_mask)) {
1176+
if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
1177+
pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n");
1178+
return;
1179+
}
11741180
}
1181+
rcu_nocb_is_setup = true;
11751182
}
1176-
if (!cpumask_available(rcu_nocb_mask))
1183+
1184+
if (!rcu_nocb_is_setup)
11771185
return;
11781186

11791187
#if defined(CONFIG_NO_HZ_FULL)
@@ -1275,8 +1283,10 @@ static void __init rcu_spawn_nocb_kthreads(void)
12751283
{
12761284
int cpu;
12771285

1278-
for_each_online_cpu(cpu)
1279-
rcu_spawn_cpu_nocb_kthread(cpu);
1286+
if (rcu_nocb_is_setup) {
1287+
for_each_online_cpu(cpu)
1288+
rcu_spawn_cpu_nocb_kthread(cpu);
1289+
}
12801290
}
12811291

12821292
/* How many CB CPU IDs per GP kthread? Default of -1 for sqrt(nr_cpu_ids). */

0 commit comments

Comments
 (0)