Skip to content

Commit 2cb1f6e

Browse files
author
Frederic Weisbecker
committed
rcu: Conditionally build CPU-hotplug teardown callbacks
Among the three CPU-hotplug teardown RCU callbacks, two of them early exit if CONFIG_HOTPLUG_CPU=n, and one is left unchanged. In any case all of them have an implementation when CONFIG_HOTPLUG_CPU=n. Align instead with the common way to deal with CPU-hotplug teardown callbacks and provide a proper stub when they are not supported. Reviewed-by: Paul E. McKenney <paulmck@kernel.org> Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
1 parent c964c1f commit 2cb1f6e

File tree

2 files changed

+63
-62
lines changed

2 files changed

+63
-62
lines changed

include/linux/rcutree.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,16 @@ void rcu_all_qs(void);
110110
/* RCUtree hotplug events */
111111
int rcutree_prepare_cpu(unsigned int cpu);
112112
int rcutree_online_cpu(unsigned int cpu);
113-
int rcutree_offline_cpu(unsigned int cpu);
113+
void rcu_cpu_starting(unsigned int cpu);
114+
115+
#ifdef CONFIG_HOTPLUG_CPU
114116
int rcutree_dead_cpu(unsigned int cpu);
115117
int rcutree_dying_cpu(unsigned int cpu);
116-
void rcu_cpu_starting(unsigned int cpu);
118+
int rcutree_offline_cpu(unsigned int cpu);
119+
#else
120+
#define rcutree_dead_cpu NULL
121+
#define rcutree_dying_cpu NULL
122+
#define rcutree_offline_cpu NULL
123+
#endif
117124

118125
#endif /* __LINUX_RCUTREE_H */

kernel/rcu/tree.c

Lines changed: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4237,25 +4237,6 @@ static bool rcu_init_invoked(void)
42374237
return !!rcu_state.n_online_cpus;
42384238
}
42394239

4240-
/*
4241-
* Near the end of the offline process. Trace the fact that this CPU
4242-
* is going offline.
4243-
*/
4244-
int rcutree_dying_cpu(unsigned int cpu)
4245-
{
4246-
bool blkd;
4247-
struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
4248-
struct rcu_node *rnp = rdp->mynode;
4249-
4250-
if (!IS_ENABLED(CONFIG_HOTPLUG_CPU))
4251-
return 0;
4252-
4253-
blkd = !!(READ_ONCE(rnp->qsmask) & rdp->grpmask);
4254-
trace_rcu_grace_period(rcu_state.name, READ_ONCE(rnp->gp_seq),
4255-
blkd ? TPS("cpuofl-bgp") : TPS("cpuofl"));
4256-
return 0;
4257-
}
4258-
42594240
/*
42604241
* All CPUs for the specified rcu_node structure have gone offline,
42614242
* and all tasks that were preempted within an RCU read-side critical
@@ -4301,23 +4282,6 @@ static void rcu_cleanup_dead_rnp(struct rcu_node *rnp_leaf)
43014282
}
43024283
}
43034284

4304-
/*
4305-
* The CPU has been completely removed, and some other CPU is reporting
4306-
* this fact from process context. Do the remainder of the cleanup.
4307-
* There can only be one CPU hotplug operation at a time, so no need for
4308-
* explicit locking.
4309-
*/
4310-
int rcutree_dead_cpu(unsigned int cpu)
4311-
{
4312-
if (!IS_ENABLED(CONFIG_HOTPLUG_CPU))
4313-
return 0;
4314-
4315-
WRITE_ONCE(rcu_state.n_online_cpus, rcu_state.n_online_cpus - 1);
4316-
// Stop-machine done, so allow nohz_full to disable tick.
4317-
tick_dep_clear(TICK_DEP_BIT_RCU);
4318-
return 0;
4319-
}
4320-
43214285
/*
43224286
* Propagate ->qsinitmask bits up the rcu_node tree to account for the
43234287
* first CPU in a given leaf rcu_node structure coming online. The caller
@@ -4470,29 +4434,6 @@ int rcutree_online_cpu(unsigned int cpu)
44704434
return 0;
44714435
}
44724436

4473-
/*
4474-
* Near the beginning of the process. The CPU is still very much alive
4475-
* with pretty much all services enabled.
4476-
*/
4477-
int rcutree_offline_cpu(unsigned int cpu)
4478-
{
4479-
unsigned long flags;
4480-
struct rcu_data *rdp;
4481-
struct rcu_node *rnp;
4482-
4483-
rdp = per_cpu_ptr(&rcu_data, cpu);
4484-
rnp = rdp->mynode;
4485-
raw_spin_lock_irqsave_rcu_node(rnp, flags);
4486-
rnp->ffmask &= ~rdp->grpmask;
4487-
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
4488-
4489-
rcutree_affinity_setting(cpu, cpu);
4490-
4491-
// nohz_full CPUs need the tick for stop-machine to work quickly
4492-
tick_dep_set(TICK_DEP_BIT_RCU);
4493-
return 0;
4494-
}
4495-
44964437
/*
44974438
* Mark the specified CPU as being online so that subsequent grace periods
44984439
* (both expedited and normal) will wait on it. Note that this means that
@@ -4646,7 +4587,60 @@ void rcutree_migrate_callbacks(int cpu)
46464587
cpu, rcu_segcblist_n_cbs(&rdp->cblist),
46474588
rcu_segcblist_first_cb(&rdp->cblist));
46484589
}
4649-
#endif
4590+
4591+
/*
4592+
* The CPU has been completely removed, and some other CPU is reporting
4593+
* this fact from process context. Do the remainder of the cleanup.
4594+
* There can only be one CPU hotplug operation at a time, so no need for
4595+
* explicit locking.
4596+
*/
4597+
int rcutree_dead_cpu(unsigned int cpu)
4598+
{
4599+
WRITE_ONCE(rcu_state.n_online_cpus, rcu_state.n_online_cpus - 1);
4600+
// Stop-machine done, so allow nohz_full to disable tick.
4601+
tick_dep_clear(TICK_DEP_BIT_RCU);
4602+
return 0;
4603+
}
4604+
4605+
/*
4606+
* Near the end of the offline process. Trace the fact that this CPU
4607+
* is going offline.
4608+
*/
4609+
int rcutree_dying_cpu(unsigned int cpu)
4610+
{
4611+
bool blkd;
4612+
struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
4613+
struct rcu_node *rnp = rdp->mynode;
4614+
4615+
blkd = !!(READ_ONCE(rnp->qsmask) & rdp->grpmask);
4616+
trace_rcu_grace_period(rcu_state.name, READ_ONCE(rnp->gp_seq),
4617+
blkd ? TPS("cpuofl-bgp") : TPS("cpuofl"));
4618+
return 0;
4619+
}
4620+
4621+
/*
4622+
* Near the beginning of the process. The CPU is still very much alive
4623+
* with pretty much all services enabled.
4624+
*/
4625+
int rcutree_offline_cpu(unsigned int cpu)
4626+
{
4627+
unsigned long flags;
4628+
struct rcu_data *rdp;
4629+
struct rcu_node *rnp;
4630+
4631+
rdp = per_cpu_ptr(&rcu_data, cpu);
4632+
rnp = rdp->mynode;
4633+
raw_spin_lock_irqsave_rcu_node(rnp, flags);
4634+
rnp->ffmask &= ~rdp->grpmask;
4635+
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
4636+
4637+
rcutree_affinity_setting(cpu, cpu);
4638+
4639+
// nohz_full CPUs need the tick for stop-machine to work quickly
4640+
tick_dep_set(TICK_DEP_BIT_RCU);
4641+
return 0;
4642+
}
4643+
#endif /* #ifdef CONFIG_HOTPLUG_CPU */
46504644

46514645
/*
46524646
* On non-huge systems, use expedited RCU grace periods to make suspend

0 commit comments

Comments
 (0)