2222 * AP_ACTIVE AP_ACTIVE
2323 */
2424
25+ /*
26+ * CPU hotplug states. The state machine invokes the installed state
27+ * startup callbacks sequentially from CPUHP_OFFLINE + 1 to CPUHP_ONLINE
28+ * during a CPU online operation. During a CPU offline operation the
29+ * installed teardown callbacks are invoked in the reverse order from
30+ * CPU_ONLINE - 1 down to CPUHP_OFFLINE.
31+ *
32+ * The state space has three sections: PREPARE, STARTING and ONLINE.
33+ *
34+ * PREPARE: The callbacks are invoked on a control CPU before the
35+ * hotplugged CPU is started up or after the hotplugged CPU has died.
36+ *
37+ * STARTING: The callbacks are invoked on the hotplugged CPU from the low level
38+ * hotplug startup/teardown code with interrupts disabled.
39+ *
40+ * ONLINE: The callbacks are invoked on the hotplugged CPU from the per CPU
41+ * hotplug thread with interrupts and preemption enabled.
42+ *
43+ * Adding explicit states to this enum is only necessary when:
44+ *
45+ * 1) The state is within the STARTING section
46+ *
47+ * 2) The state has ordering constraints vs. other states in the
48+ * same section.
49+ *
50+ * If neither #1 nor #2 apply, please use the dynamic state space when
51+ * setting up a state by using CPUHP_PREPARE_DYN or CPUHP_PREPARE_ONLINE
52+ * for the @state argument of the setup function.
53+ *
54+ * See Documentation/core-api/cpu_hotplug.rst for further information and
55+ * examples.
56+ */
2557enum cpuhp_state {
2658 CPUHP_INVALID = -1 ,
59+
60+ /* PREPARE section invoked on a control CPU */
2761 CPUHP_OFFLINE = 0 ,
2862 CPUHP_CREATE_THREADS ,
2963 CPUHP_PERF_PREPARE ,
@@ -95,6 +129,11 @@ enum cpuhp_state {
95129 CPUHP_BP_PREPARE_DYN ,
96130 CPUHP_BP_PREPARE_DYN_END = CPUHP_BP_PREPARE_DYN + 20 ,
97131 CPUHP_BRINGUP_CPU ,
132+
133+ /*
134+ * STARTING section invoked on the hotplugged CPU in low level
135+ * bringup and teardown code.
136+ */
98137 CPUHP_AP_IDLE_DEAD ,
99138 CPUHP_AP_OFFLINE ,
100139 CPUHP_AP_SCHED_STARTING ,
@@ -155,6 +194,8 @@ enum cpuhp_state {
155194 CPUHP_AP_ARM_CACHE_B15_RAC_DYING ,
156195 CPUHP_AP_ONLINE ,
157196 CPUHP_TEARDOWN_CPU ,
197+
198+ /* Online section invoked on the hotplugged CPU from the hotplug thread */
158199 CPUHP_AP_ONLINE_IDLE ,
159200 CPUHP_AP_SCHED_WAIT_EMPTY ,
160201 CPUHP_AP_SMPBOOT_THREADS ,
@@ -216,14 +257,15 @@ int __cpuhp_setup_state_cpuslocked(enum cpuhp_state state, const char *name,
216257 int (* teardown )(unsigned int cpu ),
217258 bool multi_instance );
218259/**
219- * cpuhp_setup_state - Setup hotplug state callbacks with calling the callbacks
260+ * cpuhp_setup_state - Setup hotplug state callbacks with calling the @startup
261+ * callback
220262 * @state: The state for which the calls are installed
221263 * @name: Name of the callback (will be used in debug output)
222- * @startup: startup callback function
223- * @teardown: teardown callback function
264+ * @startup: startup callback function or NULL if not required
265+ * @teardown: teardown callback function or NULL if not required
224266 *
225- * Installs the callback functions and invokes the startup callback on
226- * the present cpus which have already reached the @state.
267+ * Installs the callback functions and invokes the @ startup callback on
268+ * the online cpus which have already reached the @state.
227269 */
228270static inline int cpuhp_setup_state (enum cpuhp_state state ,
229271 const char * name ,
@@ -233,6 +275,18 @@ static inline int cpuhp_setup_state(enum cpuhp_state state,
233275 return __cpuhp_setup_state (state , name , true, startup , teardown , false);
234276}
235277
278+ /**
279+ * cpuhp_setup_state_cpuslocked - Setup hotplug state callbacks with calling
280+ * @startup callback from a cpus_read_lock()
281+ * held region
282+ * @state: The state for which the calls are installed
283+ * @name: Name of the callback (will be used in debug output)
284+ * @startup: startup callback function or NULL if not required
285+ * @teardown: teardown callback function or NULL if not required
286+ *
287+ * Same as cpuhp_setup_state() except that it must be invoked from within a
288+ * cpus_read_lock() held region.
289+ */
236290static inline int cpuhp_setup_state_cpuslocked (enum cpuhp_state state ,
237291 const char * name ,
238292 int (* startup )(unsigned int cpu ),
@@ -244,14 +298,14 @@ static inline int cpuhp_setup_state_cpuslocked(enum cpuhp_state state,
244298
245299/**
246300 * cpuhp_setup_state_nocalls - Setup hotplug state callbacks without calling the
247- * callbacks
301+ * @startup callback
248302 * @state: The state for which the calls are installed
249303 * @name: Name of the callback.
250- * @startup: startup callback function
251- * @teardown: teardown callback function
304+ * @startup: startup callback function or NULL if not required
305+ * @teardown: teardown callback function or NULL if not required
252306 *
253- * Same as @ cpuhp_setup_state except that no calls are executed are invoked
254- * during installation of this callback . NOP if SMP=n or HOTPLUG_CPU=n.
307+ * Same as cpuhp_setup_state() except that the @startup callback is not
308+ * invoked during installation. NOP if SMP=n or HOTPLUG_CPU=n.
255309 */
256310static inline int cpuhp_setup_state_nocalls (enum cpuhp_state state ,
257311 const char * name ,
@@ -262,6 +316,19 @@ static inline int cpuhp_setup_state_nocalls(enum cpuhp_state state,
262316 false);
263317}
264318
319+ /**
320+ * cpuhp_setup_state_nocalls_cpuslocked - Setup hotplug state callbacks without
321+ * invoking the @startup callback from
322+ * a cpus_read_lock() held region
323+ * callbacks
324+ * @state: The state for which the calls are installed
325+ * @name: Name of the callback.
326+ * @startup: startup callback function or NULL if not required
327+ * @teardown: teardown callback function or NULL if not required
328+ *
329+ * Same as cpuhp_setup_state_nocalls() except that it must be invoked from
330+ * within a cpus_read_lock() held region.
331+ */
265332static inline int cpuhp_setup_state_nocalls_cpuslocked (enum cpuhp_state state ,
266333 const char * name ,
267334 int (* startup )(unsigned int cpu ),
@@ -275,13 +342,13 @@ static inline int cpuhp_setup_state_nocalls_cpuslocked(enum cpuhp_state state,
275342 * cpuhp_setup_state_multi - Add callbacks for multi state
276343 * @state: The state for which the calls are installed
277344 * @name: Name of the callback.
278- * @startup: startup callback function
279- * @teardown: teardown callback function
345+ * @startup: startup callback function or NULL if not required
346+ * @teardown: teardown callback function or NULL if not required
280347 *
281348 * Sets the internal multi_instance flag and prepares a state to work as a multi
282349 * instance callback. No callbacks are invoked at this point. The callbacks are
283350 * invoked once an instance for this state are registered via
284- * @ cpuhp_state_add_instance or @ cpuhp_state_add_instance_nocalls.
351+ * cpuhp_state_add_instance() or cpuhp_state_add_instance_nocalls()
285352 */
286353static inline int cpuhp_setup_state_multi (enum cpuhp_state state ,
287354 const char * name ,
@@ -306,9 +373,10 @@ int __cpuhp_state_add_instance_cpuslocked(enum cpuhp_state state,
306373 * @state: The state for which the instance is installed
307374 * @node: The node for this individual state.
308375 *
309- * Installs the instance for the @state and invokes the startup callback on
310- * the present cpus which have already reached the @state. The @state must have
311- * been earlier marked as multi-instance by @cpuhp_setup_state_multi.
376+ * Installs the instance for the @state and invokes the registered startup
377+ * callback on the online cpus which have already reached the @state. The
378+ * @state must have been earlier marked as multi-instance by
379+ * cpuhp_setup_state_multi().
312380 */
313381static inline int cpuhp_state_add_instance (enum cpuhp_state state ,
314382 struct hlist_node * node )
@@ -322,15 +390,27 @@ static inline int cpuhp_state_add_instance(enum cpuhp_state state,
322390 * @state: The state for which the instance is installed
323391 * @node: The node for this individual state.
324392 *
325- * Installs the instance for the @state The @state must have been earlier
326- * marked as multi-instance by @cpuhp_setup_state_multi.
393+ * Installs the instance for the @state. The @state must have been earlier
394+ * marked as multi-instance by cpuhp_setup_state_multi. NOP if SMP=n or
395+ * HOTPLUG_CPU=n.
327396 */
328397static inline int cpuhp_state_add_instance_nocalls (enum cpuhp_state state ,
329398 struct hlist_node * node )
330399{
331400 return __cpuhp_state_add_instance (state , node , false);
332401}
333402
403+ /**
404+ * cpuhp_state_add_instance_nocalls_cpuslocked - Add an instance for a state
405+ * without invoking the startup
406+ * callback from a cpus_read_lock()
407+ * held region.
408+ * @state: The state for which the instance is installed
409+ * @node: The node for this individual state.
410+ *
411+ * Same as cpuhp_state_add_instance_nocalls() except that it must be
412+ * invoked from within a cpus_read_lock() held region.
413+ */
334414static inline int
335415cpuhp_state_add_instance_nocalls_cpuslocked (enum cpuhp_state state ,
336416 struct hlist_node * node )
@@ -346,7 +426,7 @@ void __cpuhp_remove_state_cpuslocked(enum cpuhp_state state, bool invoke);
346426 * @state: The state for which the calls are removed
347427 *
348428 * Removes the callback functions and invokes the teardown callback on
349- * the present cpus which have already reached the @state.
429+ * the online cpus which have already reached the @state.
350430 */
351431static inline void cpuhp_remove_state (enum cpuhp_state state )
352432{
@@ -355,14 +435,22 @@ static inline void cpuhp_remove_state(enum cpuhp_state state)
355435
356436/**
357437 * cpuhp_remove_state_nocalls - Remove hotplug state callbacks without invoking
358- * teardown
438+ * the teardown callback
359439 * @state: The state for which the calls are removed
360440 */
361441static inline void cpuhp_remove_state_nocalls (enum cpuhp_state state )
362442{
363443 __cpuhp_remove_state (state , false);
364444}
365445
446+ /**
447+ * cpuhp_remove_state_nocalls_cpuslocked - Remove hotplug state callbacks without invoking
448+ * teardown from a cpus_read_lock() held region.
449+ * @state: The state for which the calls are removed
450+ *
451+ * Same as cpuhp_remove_state nocalls() except that it must be invoked
452+ * from within a cpus_read_lock() held region.
453+ */
366454static inline void cpuhp_remove_state_nocalls_cpuslocked (enum cpuhp_state state )
367455{
368456 __cpuhp_remove_state_cpuslocked (state , false);
@@ -390,8 +478,8 @@ int __cpuhp_state_remove_instance(enum cpuhp_state state,
390478 * @state: The state from which the instance is removed
391479 * @node: The node for this individual state.
392480 *
393- * Removes the instance and invokes the teardown callback on the present cpus
394- * which have already reached the @state.
481+ * Removes the instance and invokes the teardown callback on the online cpus
482+ * which have already reached @state.
395483 */
396484static inline int cpuhp_state_remove_instance (enum cpuhp_state state ,
397485 struct hlist_node * node )
0 commit comments