Skip to content

Commit 2f91146

Browse files
Zhen Leipaulmckrcu
authored andcommitted
rcu: Simplify rcu_init_nohz() cpumask handling
In kernels built with either CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y or CONFIG_NO_HZ_FULL=y, additional CPUs must be added to rcu_nocb_mask. Except that kernels booted without the rcu_nocbs= will not have allocated rcu_nocb_mask. And the current rcu_init_nohz() function uses its need_rcu_nocb_mask and offload_all local variables to track the rcu_nocb and nohz_full state. But there is a much simpler approach, namely creating a cpumask pointer to track the default and then using cpumask_available() to check the rcu_nocb_mask state. This commit takes this approach, thereby simplifying and shortening the rcu_init_nohz() function. Signed-off-by: Zhen Lei <[email protected]> Reviewed-by: Joel Fernandes (Google) <[email protected]> Acked-by: Frederic Weisbecker <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent a3450c5 commit 2f91146

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

kernel/rcu/tree_nocb.h

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,45 +1210,33 @@ EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
12101210
void __init rcu_init_nohz(void)
12111211
{
12121212
int cpu;
1213-
bool need_rcu_nocb_mask = false;
1214-
bool offload_all = false;
12151213
struct rcu_data *rdp;
1216-
1217-
#if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
1218-
if (!rcu_state.nocb_is_setup) {
1219-
need_rcu_nocb_mask = true;
1220-
offload_all = true;
1221-
}
1222-
#endif /* #if defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) */
1214+
const struct cpumask *cpumask = NULL;
12231215

12241216
#if defined(CONFIG_NO_HZ_FULL)
1225-
if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) {
1226-
need_rcu_nocb_mask = true;
1227-
offload_all = false; /* NO_HZ_FULL has its own mask. */
1228-
}
1229-
#endif /* #if defined(CONFIG_NO_HZ_FULL) */
1217+
if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask))
1218+
cpumask = tick_nohz_full_mask;
1219+
#endif
1220+
1221+
if (IS_ENABLED(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) &&
1222+
!rcu_state.nocb_is_setup && !cpumask)
1223+
cpumask = cpu_possible_mask;
12301224

1231-
if (need_rcu_nocb_mask) {
1225+
if (cpumask) {
12321226
if (!cpumask_available(rcu_nocb_mask)) {
12331227
if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
12341228
pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n");
12351229
return;
12361230
}
12371231
}
1232+
1233+
cpumask_or(rcu_nocb_mask, rcu_nocb_mask, cpumask);
12381234
rcu_state.nocb_is_setup = true;
12391235
}
12401236

12411237
if (!rcu_state.nocb_is_setup)
12421238
return;
12431239

1244-
#if defined(CONFIG_NO_HZ_FULL)
1245-
if (tick_nohz_full_running)
1246-
cpumask_or(rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask);
1247-
#endif /* #if defined(CONFIG_NO_HZ_FULL) */
1248-
1249-
if (offload_all)
1250-
cpumask_setall(rcu_nocb_mask);
1251-
12521240
if (!cpumask_subset(rcu_nocb_mask, cpu_possible_mask)) {
12531241
pr_info("\tNote: kernel parameter 'rcu_nocbs=', 'nohz_full', or 'isolcpus=' contains nonexistent CPUs.\n");
12541242
cpumask_and(rcu_nocb_mask, cpu_possible_mask,

0 commit comments

Comments
 (0)