Skip to content

Commit 98ec984

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 b8991a1 commit 98ec984

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

kernel/rcu/tree_nocb.h

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,45 +1210,34 @@ 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 defined(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL)
1222+
if (!rcu_state.nocb_is_setup && !cpumask)
1223+
cpumask = cpu_possible_mask;
1224+
#endif
12301225

1231-
if (need_rcu_nocb_mask) {
1226+
if (cpumask) {
12321227
if (!cpumask_available(rcu_nocb_mask)) {
12331228
if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
12341229
pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n");
12351230
return;
12361231
}
12371232
}
1233+
1234+
cpumask_or(rcu_nocb_mask, rcu_nocb_mask, cpumask);
12381235
rcu_state.nocb_is_setup = true;
12391236
}
12401237

12411238
if (!rcu_state.nocb_is_setup)
12421239
return;
12431240

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-
12521241
if (!cpumask_subset(rcu_nocb_mask, cpu_possible_mask)) {
12531242
pr_info("\tNote: kernel parameter 'rcu_nocbs=', 'nohz_full', or 'isolcpus=' contains nonexistent CPUs.\n");
12541243
cpumask_and(rcu_nocb_mask, cpu_possible_mask,

0 commit comments

Comments
 (0)