mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] cpu/hotplug: Update documentation and naming convention for hotplug callbacks
@ 2026-11-27  7:26 Srivatsa S. Bhat (Microsoft)
  2026-11-27  7:26 ` [PATCH 1/4] Documentation: core-api/cpuhotplug: Fix a few minor inconsistencies Srivatsa S. Bhat (Microsoft)
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Srivatsa S. Bhat (Microsoft) @ 2026-11-27  7:26 UTC (permalink / raw)
  To: Jonathan Corbet, Shuah Khan, Randy Dunlap, Thomas Gleixner,
	Peter Zijlstra
  Cc: linux-doc, linux-kernel, Srivatsa S. Bhat, Prasanna Kumar T S M,
	Saurabh Sengar

Hi,

This series makes the CPU hotplug documentation more consistent with the code
and a bit easier to follow. It fixes minor documentation issues and explains the
BP/AP terminology in terms of the control and target CPUs.

Patches 1 and 2 clean up the documentation and header comments, patch 3 explains
BP/AP, and patch 4 adds callback naming guidance.

Thank you very much!

---
Srivatsa S. Bhat (Microsoft) (4):
      Documentation: core-api/cpuhotplug: Fix a few minor inconsistencies
      cpu/hotplug: Trivial doc updates in cpuhotplug.h
      cpu/hotplug: Demystify the terms 'BP' and 'AP' in the code
      Documentation: core-api/cpuhotplug: Add naming convention for callbacks

 Documentation/core-api/cpu_hotplug.rst | 173 ++++++++++++++++++++-------------
 include/linux/cpuhotplug.h             |  74 +++++++-------
 2 files changed, 142 insertions(+), 105 deletions(-)
---
base-commit: 9437ee8b6cf607e883b36e44bd755968daaebd48
change-id: 20261127-docs-cpuhp-ae2d101b7f75

Regards,
Srivatsa


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] Documentation: core-api/cpuhotplug: Fix a few minor inconsistencies
  2026-11-27  7:26 [PATCH 0/4] cpu/hotplug: Update documentation and naming convention for hotplug callbacks Srivatsa S. Bhat (Microsoft)
@ 2026-11-27  7:26 ` Srivatsa S. Bhat (Microsoft)
  2026-11-27  7:26 ` [PATCH 2/4] cpu/hotplug: Trivial doc updates in cpuhotplug.h Srivatsa S. Bhat (Microsoft)
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Srivatsa S. Bhat (Microsoft) @ 2026-11-27  7:26 UTC (permalink / raw)
  To: Jonathan Corbet, Shuah Khan, Randy Dunlap, Thomas Gleixner,
	Peter Zijlstra
  Cc: linux-doc, linux-kernel, Srivatsa S. Bhat, Prasanna Kumar T S M,
	Saurabh Sengar

Update the documentation to fix inconsistencies with the code and to
also improve readability.

Highlights:

- STARTUP section -> STARTING section
- "perf/online" -> "perf:online" (in examples)
- Fix missing mention of cpuhp_state_add_instance_nocalls_cpuslocked()
- Minor readability improvements and grammatical fixes throughout.

Signed-off-by: Srivatsa S. Bhat (Microsoft) <srivatsa@csail.mit.edu>
---
 Documentation/core-api/cpu_hotplug.rst | 143 +++++++++++++++++----------------
 1 file changed, 73 insertions(+), 70 deletions(-)

diff --git a/Documentation/core-api/cpu_hotplug.rst b/Documentation/core-api/cpu_hotplug.rst
index f8b3f59a3d5f..4e228fc00624 100644
--- a/Documentation/core-api/cpu_hotplug.rst
+++ b/Documentation/core-api/cpu_hotplug.rst
@@ -13,9 +13,9 @@ CPU hotplug in the Kernel
 Introduction
 ============
 
-Modern advances in system architectures have introduced advanced error
-reporting and correction capabilities in processors. There are couple OEMS that
-support NUMA hardware which are hot pluggable as well, where physical node
+Modern advances in system architectures have introduced advanced error reporting
+and correction capabilities in processors. There are a couple of OEMS that
+support NUMA hardware which are hot-pluggable as well, where physical node
 insertion and removal require support for CPU hotplug.
 
 Such advances require CPUs available to a kernel to be removed either for
@@ -33,7 +33,7 @@ Command Line Switches
 ``maxcpus=n``
   Restrict boot time CPUs to *n*. Say if you have four CPUs, using
   ``maxcpus=2`` will only boot two. You can choose to bring the
-  other CPUs later online.
+  other CPUs online later.
 
 ``nr_cpus=n``
   Restrict the total amount of CPUs the kernel will support. If the number
@@ -57,23 +57,23 @@ CPU maps
   upfront can save some boot time memory.
 
 ``cpu_online_mask``
-  Bitmap of all CPUs currently online. Its set in ``__cpu_up()``
+  Bitmap of all CPUs currently online. It is set in ``__cpu_up()``
   after a CPU is available for kernel scheduling and ready to receive
-  interrupts from devices. Its cleared when a CPU is brought down using
+  interrupts from devices. It is cleared when a CPU is brought down using
   ``__cpu_disable()``, before which all OS services including interrupts are
   migrated to another target CPU.
 
 ``cpu_present_mask``
-  Bitmap of CPUs currently present in the system. Not all
-  of them may be online. When physical hotplug is processed by the relevant
-  subsystem (e.g ACPI) can change and new bit either be added or removed
-  from the map depending on the event is hot-add/hot-remove. There are currently
-  no locking rules as of now. Typical usage is to init topology during boot,
-  at which time hotplug is disabled.
-
-You really don't need to manipulate any of the system CPU maps. They should
-be read-only for most use. When setting up per-cpu resources almost always use
-``cpu_possible_mask`` or ``for_each_possible_cpu()`` to iterate. To macro
+  Bitmap of CPUs currently present in the system. Not all of them may be online.
+  The time at which the physical hotplug is processed by the relevant subsystem
+  (e.g ACPI) can change and the new bit can either be added or removed from the
+  map depending on whether the event is a hot-add or a hot-remove, respectively.
+  There are currently no locking rules as of now. Typical usage is to init
+  topology during boot, at which time hotplug is disabled.
+
+You really don't need to manipulate any of the system CPU maps. They should be
+read-only for most purposes. When setting up per-cpu resources, almost always
+use ``cpu_possible_mask`` or ``for_each_possible_cpu()`` to iterate. The macro
 ``for_each_cpu()`` can be used to iterate over a custom CPU mask.
 
 Never use anything other than ``cpumask_t`` to represent bitmap of CPUs.
@@ -134,9 +134,9 @@ at state ``CPUHP_OFFLINE``. This includes:
 * All processes are migrated away from this outgoing CPU to new CPUs.
   The new CPU is chosen from each process' current cpuset, which may be
   a subset of all online CPUs.
-* All interrupts targeted to this CPU are migrated to a new CPU
-* timers are also migrated to a new CPU
-* Once all services are migrated, kernel calls an arch specific routine
+* All interrupts targeted to this CPU are migrated to a new CPU.
+* Timers are also migrated to a new CPU.
+* Once all services are migrated, the kernel calls an arch specific routine
   ``__cpu_disable()`` to perform arch specific cleanup.
 
 
@@ -155,14 +155,14 @@ the state CPUHP_ONLINE is reached. They can also be invoked when the
 callbacks of a state are set up or an instance is added to a multi-instance
 state.
 
-When a CPU is offlined the teardown callbacks are invoked in the reverse
+When a CPU is offlined, the teardown callbacks are invoked in the reverse
 order sequentially until the state CPUHP_OFFLINE is reached. They can also
 be invoked when the callbacks of a state are removed or an instance is
 removed from a multi-instance state.
 
 If a usage site requires only a callback in one direction of the hotplug
-operations (CPU online or CPU offline) then the other not-required callback
-can be set to NULL when the state is set up.
+operation (CPU online or CPU offline), then the other unnecessary callback
+pointer can be set to NULL when the state is set up.
 
 The state space is divided into three sections:
 
@@ -237,7 +237,7 @@ A successful online operation looks like this::
   [CPUHP_BRINGUP_CPU + 1]->startup()   -> success
   ...
   [CPUHP_AP_ONLINE]->startup()         -> success
-  === End of STARTUP section
+  === End of STARTING section
   [CPUHP_AP_ONLINE + 1]->startup()     -> success
   ...
   [CPUHP_ONLINE - 1]->startup()        -> success
@@ -249,7 +249,7 @@ A successful offline operation looks like this::
   [CPUHP_ONLINE - 1]->teardown()       -> success
   ...
   [CPUHP_AP_ONLINE + 1]->teardown()    -> success
-  === Start of STARTUP section
+  === Start of STARTING section
   [CPUHP_AP_ONLINE]->teardown()        -> success
   ...
   [CPUHP_BRINGUP_ONLINE - 1]->teardown()
@@ -273,14 +273,14 @@ A failed online operation looks like this::
   [CPUHP_BRINGUP_CPU + 1]->startup()   -> success
   ...
   [CPUHP_AP_ONLINE]->startup()         -> success
-  === End of STARTUP section
+  === End of STARTING section
   [CPUHP_AP_ONLINE + 1]->startup()     -> success
   ---
   [CPUHP_AP_ONLINE + N]->startup()     -> fail
   [CPUHP_AP_ONLINE + (N - 1)]->teardown()
   ...
   [CPUHP_AP_ONLINE + 1]->teardown()
-  === Start of STARTUP section
+  === Start of STARTING section
   [CPUHP_AP_ONLINE]->teardown()
   ...
   [CPUHP_BRINGUP_ONLINE - 1]->teardown()
@@ -323,7 +323,7 @@ down again because that would likely result in an endless loop::
   [CPUHP_ONLINE - (N - 1)]->teardown() -> success
   [CPUHP_ONLINE - N]->teardown()       -> fail
 
-Lather, rinse and repeat. In this case the CPU left in state::
+Lather, rinse and repeat. In this case the CPU was left in state::
 
   [CPUHP_ONLINE - (N - 1)]
 
@@ -345,7 +345,7 @@ There are two ways to allocate a CPU hotplug state:
   callback. The statically allocated states are described by constants in
   the cpuhp_state enum which can be found in include/linux/cpuhotplug.h.
 
-  Insert the state into the enum at the proper place so the ordering
+  Insert the state into the enum at the proper place so that the ordering
   requirements are fulfilled. The state constant has to be used for state
   setup and removal.
 
@@ -355,7 +355,7 @@ There are two ways to allocate a CPU hotplug state:
 
 * Dynamic allocation
 
-  When there are no ordering requirements for the state callbacks then
+  When there are no ordering requirements for the state callbacks, then
   dynamic allocation is the preferred method. The state number is allocated
   by the setup function and returned to the caller on success.
 
@@ -409,37 +409,37 @@ offline  For states in the ONLINE section which do not provide
          a startup callback
 ======== =======================================================
 
-As the @name argument is only used for sysfs and instrumentation other mode
-descriptors can be used as well if they describe the nature of the state
-better than the common ones.
+As the @name argument is only used for sysfs and instrumentation,
+other mode descriptors can be used as well if they describe the nature
+of the state better than the common ones.
 
-Examples for @name arguments: "perf/online", "perf/x86:prepare",
-"RCU/tree:dying", "sched/waitempty"
+Examples for @name arguments: "perf:online", "perf/x86:prepare",
+"RCU/tree:dying", "sched:waitempty"
 
 The @startup argument is a function pointer to the callback which should be
 invoked during a CPU online operation. If the usage site does not require a
-startup callback set the pointer to NULL.
+startup callback, set the pointer to NULL.
 
 The @teardown argument is a function pointer to the callback which should
 be invoked during a CPU offline operation. If the usage site does not
-require a teardown callback set the pointer to NULL.
+require a teardown callback, set the pointer to NULL.
 
 The functions differ in the way how the installed callbacks are treated:
 
   * cpuhp_setup_state_nocalls(), cpuhp_setup_state_nocalls_cpuslocked()
-    and cpuhp_setup_state_multi() only install the callbacks
+    and cpuhp_setup_state_multi() only install the callbacks.
 
   * cpuhp_setup_state() and cpuhp_setup_state_cpuslocked() install the
     callbacks and invoke the @startup callback (if not NULL) for all online
-    CPUs which have currently a state greater than the newly installed
-    state. Depending on the state section the callback is either invoked on
-    the current CPU (PREPARE section) or on each online CPU (ONLINE
-    section) in the context of the CPU's hotplug thread.
+    CPUs which currently have a state greater than the newly installed
+    state. Depending on the state section, the callback is either
+    invoked on the current CPU (PREPARE section) or on each online CPU
+    (ONLINE section) in the context of the CPU's hotplug thread.
 
-    If a callback fails for CPU N then the teardown callback for CPU
+    If a callback fails for CPU N, then the teardown callback for CPU
     0 .. N-1 is invoked to rollback the operation. The state setup fails,
     the callbacks for the state are not installed and in case of dynamic
-    allocation the allocated state is freed.
+    allocation, the allocated state is freed.
 
 The state setup and the callback invocations are serialized against CPU
 hotplug operations. If the setup function has to be called from a CPU
@@ -484,8 +484,8 @@ The functions differ in the way how the installed callbacks are treated:
     and cpuhp_remove_multi_state() only remove the callbacks.
 
   * cpuhp_remove_state() removes the callbacks and invokes the teardown
-    callback (if not NULL) for all online CPUs which have currently a state
-    greater than the removed state. Depending on the state section the
+    callback (if not NULL) for all online CPUs which currently have a state
+    greater than the removed state. Depending on the state section, the
     callback is either invoked on the current CPU (PREPARE section) or on
     each online CPU (ONLINE section) in the context of the CPU's hotplug
     thread.
@@ -497,7 +497,7 @@ hotplug operations. If the remove function has to be called from a CPU
 hotplug read locked region, then the _cpuslocked() variants have to be
 used. These functions cannot be used from within CPU hotplug callbacks.
 
-If a multi-instance state is removed then the caller has to remove all
+If a multi-instance state is removed, then the caller has to remove all
 instances first.
 
 Multi-Instance state instance management
@@ -508,6 +508,7 @@ state:
 
   * cpuhp_state_add_instance(state, node)
   * cpuhp_state_add_instance_nocalls(state, node)
+  * cpuhp_state_add_instance_nocalls_cpuslocked(state, node)
 
 The @state argument is either a statically allocated state or the state
 number which was allocated in the dynamic range by cpuhp_setup_state_multi().
@@ -519,22 +520,23 @@ via container_of().
 
 The functions differ in the way how the installed callbacks are treated:
 
-  * cpuhp_state_add_instance_nocalls() and only adds the instance to the
-    multi-instance state's node list.
+  * cpuhp_state_add_instance_nocalls() and
+    cpuhp_state_add_instance_nocalls_cpuslocked() only adds the
+    instance to the multi-instance state's node list.
 
   * cpuhp_state_add_instance() adds the instance and invokes the startup
     callback (if not NULL) associated with @state for all online CPUs which
-    have currently a state greater than @state. The callback is only
-    invoked for the to be added instance. Depending on the state section
+    currently have a state greater than @state. The callback is only
+    invoked for the instance to be added. Depending on the state section,
     the callback is either invoked on the current CPU (PREPARE section) or
     on each online CPU (ONLINE section) in the context of the CPU's hotplug
     thread.
 
-    If a callback fails for CPU N then the teardown callback for CPU
+    If a callback fails for CPU N, then the teardown callback for CPU
     0 .. N-1 is invoked to rollback the operation, the function fails and
     the instance is not added to the node list of the multi-instance state.
 
-To remove an instance from the state's node list these functions are
+To remove an instance from the state's node list, these functions are
 available:
 
   * cpuhp_state_remove_instance(state, node)
@@ -550,9 +552,9 @@ The functions differ in the way how the installed callbacks are treated:
 
   * cpuhp_state_remove_instance() removes the instance and invokes the
     teardown callback (if not NULL) associated with @state for all online
-    CPUs which have currently a state greater than @state.  The callback is
-    only invoked for the to be removed instance.  Depending on the state
-    section the callback is either invoked on the current CPU (PREPARE
+    CPUs which currently have a state greater than @state. The callback is
+    only invoked for the instance to be removed. Depending on the state
+    section, the callback is either invoked on the current CPU (PREPARE
     section) or on each online CPU (ONLINE section) in the context of the
     CPU's hotplug thread.
 
@@ -618,8 +620,8 @@ Testing of hotplug states
 =========================
 
 One way to verify whether a custom state is working as expected or not is to
-shutdown a CPU and then put it online again. It is also possible to put the CPU
-to certain state (for instance *CPUHP_AP_ONLINE*) and then go back to
+offline a CPU and then get it online again. It is also possible to put the CPU
+to a certain state (for instance *CPUHP_AP_ONLINE*) and then go back to
 *CPUHP_ONLINE*. This would simulate an error one state after *CPUHP_AP_ONLINE*
 which would lead to rollback to the online state.
 
@@ -645,14 +647,14 @@ To rollback CPU4 to ``lib/percpu_cnt:online`` and back online just issue::
   $ cat /sys/devices/system/cpu/cpu4/hotplug/state
   140
 
-It is important to note that the teardown callback of state 140 have been
+It is important to note that the teardown callback of state 140 has been
 invoked. And now get back online::
 
   $ echo 169 > /sys/devices/system/cpu/cpu4/hotplug/target
   $ cat /sys/devices/system/cpu/cpu4/hotplug/state
   169
 
-With trace events enabled, the individual steps are visible, too::
+With trace events enabled, the individual steps are visible too::
 
   #  TASK-PID   CPU#    TIMESTAMP  FUNCTION
   #     | |       |        |         |
@@ -681,7 +683,7 @@ With trace events enabled, the individual steps are visible, too::
    cpuhp/4-31   [004]  95.552: cpuhp_exit:  cpu: 0004  state: 168 step: 168 ret: 0
       bash-394  [005]  95.553: cpuhp_exit:  cpu: 0004  state: 169 step: 140 ret: 0
 
-As it an be seen, CPU4 went down until timestamp 22.996 and then back up until
+As it can be seen, CPU4 went down until timestamp 22.996 and then back up until
 95.552. All invoked callbacks including their return codes are visible in the
 trace.
 
@@ -701,16 +703,17 @@ The following functions and configurations are required:
   kernel after the routine returns. This includes the shutdown of the timer.
 
 ``__cpu_die()``
-  This actually supposed to ensure death of the CPU. Actually look at some
-  example code in other arch that implement CPU hotplug. The processor is taken
-  down from the ``idle()`` loop for that specific architecture. ``__cpu_die()``
-  typically waits for some per_cpu state to be set, to ensure the processor dead
-  routine is called to be sure positively.
+  This is actually supposed to ensure the death of the CPU. Look at some example
+  code in other archs that implement CPU hotplug. The processor is taken down
+  from the ``idle()`` loop for that specific architecture. ``__cpu_die()``
+  typically waits for some per_cpu state to be set, to be absolutely sure that
+  the processor's dead routine has been called.
 
 User Space Notification
 =======================
 
-After CPU successfully onlined or offline udev events are sent. A udev rule like::
+After a CPU is successfully onlined or offlined, udev events are sent.
+A udev rule like::
 
   SUBSYSTEM=="cpu", DRIVERS=="processor", DEVPATH=="/devices/system/cpu/*", RUN+="the_hotplug_receiver.sh"
 
@@ -730,11 +733,11 @@ will receive all events. A script like::
 
 can process the event further.
 
-When changes to the CPUs in the system occur, the sysfs file
+When changes occur to the CPUs in the system, the sysfs file
 /sys/devices/system/cpu/crash_hotplug contains '1' if the kernel
-updates the kdump capture kernel list of CPUs itself (via elfcorehdr and
+updates the kdump capture kernel's list of CPUs itself (via elfcorehdr and
 other relevant kexec segment), or '0' if userspace must update the kdump
-capture kernel list of CPUs.
+capture kernel's list of CPUs.
 
 The availability depends on the CONFIG_HOTPLUG_CPU kernel configuration
 option.
@@ -750,7 +753,7 @@ of the elfcorehdr (which contains the list of CPUs) and other relevant
 kexec segments, then the rule skips the unload-then-reload of the kdump
 capture kernel.
 
-Kernel Inline Documentations Reference
+Kernel Inline Documentation References
 ======================================
 
 .. kernel-doc:: include/linux/cpuhotplug.h

-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] cpu/hotplug: Trivial doc updates in cpuhotplug.h
  2026-11-27  7:26 [PATCH 0/4] cpu/hotplug: Update documentation and naming convention for hotplug callbacks Srivatsa S. Bhat (Microsoft)
  2026-11-27  7:26 ` [PATCH 1/4] Documentation: core-api/cpuhotplug: Fix a few minor inconsistencies Srivatsa S. Bhat (Microsoft)
@ 2026-11-27  7:26 ` Srivatsa S. Bhat (Microsoft)
  2026-11-27  7:27 ` [PATCH 3/4] cpu/hotplug: Demystify the terms 'BP' and 'AP' in the code Srivatsa S. Bhat (Microsoft)
  2026-11-27  7:27 ` [PATCH 4/4] Documentation: core-api/cpuhotplug: Add naming convention for callbacks Srivatsa S. Bhat (Microsoft)
  3 siblings, 0 replies; 5+ messages in thread
From: Srivatsa S. Bhat (Microsoft) @ 2026-11-27  7:26 UTC (permalink / raw)
  To: Jonathan Corbet, Shuah Khan, Randy Dunlap, Thomas Gleixner,
	Peter Zijlstra
  Cc: linux-doc, linux-kernel, Srivatsa S. Bhat, Prasanna Kumar T S M,
	Saurabh Sengar

Make a few readability improvements and fix trivial inconsistencies in
the comments in include/linux/cpuhotplug.h

Signed-off-by: Srivatsa S. Bhat (Microsoft) <srivatsa@csail.mit.edu>
---
 include/linux/cpuhotplug.h | 69 +++++++++++++++++++++++-----------------------
 1 file changed, 34 insertions(+), 35 deletions(-)

diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h
index 1b6dba159bb2..f51303255bf0 100644
--- a/include/linux/cpuhotplug.h
+++ b/include/linux/cpuhotplug.h
@@ -15,7 +15,7 @@
  * BRINGUP_CPU->AP_OFFLINE	BRINGUP_CPU  <- AP_IDLE_DEAD (idle thread/play_dead)
  *		  |				AP_OFFLINE
  *		  v (IRQ-off)	  ,---------------^
- *		AP_ONLNE	  | (stop_machine)
+ *		AP_ONLINE	  | (stop_machine)
  *		  |		TEARDOWN_CPU <-	AP_ONLINE_IDLE
  *		  |				  ^
  *		  v				  |
@@ -23,9 +23,9 @@
  */
 
 /*
- * CPU hotplug states. The state machine invokes the installed state
+ * CPU hotplug states. The state machine invokes the installed state's
  * startup callbacks sequentially from CPUHP_OFFLINE + 1 to CPUHP_ONLINE
- * during a CPU online operation. During a CPU offline operation the
+ * during a CPU online operation. During a CPU offline operation, the
  * installed teardown callbacks are invoked in the reverse order from
  * CPUHP_ONLINE - 1 down to CPUHP_OFFLINE.
  *
@@ -250,9 +250,9 @@ int __cpuhp_setup_state_cpuslocked(enum cpuhp_state state, const char *name,
 				   int (*teardown)(unsigned int cpu),
 				   bool multi_instance);
 /**
- * cpuhp_setup_state - Setup hotplug state callbacks with calling the @startup
+ * cpuhp_setup_state - Setup hotplug state callbacks and invoke the @startup
  *                     callback
- * @state:	The state for which the calls are installed
+ * @state:	The state for which the callbacks are installed
  * @name:	Name of the callback (will be used in debug output)
  * @startup:	startup callback function or NULL if not required
  * @teardown:	teardown callback function or NULL if not required
@@ -269,10 +269,10 @@ static inline int cpuhp_setup_state(enum cpuhp_state state,
 }
 
 /**
- * cpuhp_setup_state_cpuslocked - Setup hotplug state callbacks with calling
+ * cpuhp_setup_state_cpuslocked - Setup hotplug state callbacks and invoke the
  *				  @startup callback from a cpus_read_lock()
  *				  held region
- * @state:	The state for which the calls are installed
+ * @state:	The state for which the callbacks are installed
  * @name:	Name of the callback (will be used in debug output)
  * @startup:	startup callback function or NULL if not required
  * @teardown:	teardown callback function or NULL if not required
@@ -290,10 +290,10 @@ static inline int cpuhp_setup_state_cpuslocked(enum cpuhp_state state,
 }
 
 /**
- * cpuhp_setup_state_nocalls - Setup hotplug state callbacks without calling the
+ * cpuhp_setup_state_nocalls - Setup hotplug state callbacks without invoking the
  *			       @startup callback
- * @state:	The state for which the calls are installed
- * @name:	Name of the callback.
+ * @state:	The state for which the callbacks are installed
+ * @name:	Name of the callback (will be used in debug output)
  * @startup:	startup callback function or NULL if not required
  * @teardown:	teardown callback function or NULL if not required
  *
@@ -313,9 +313,8 @@ static inline int cpuhp_setup_state_nocalls(enum cpuhp_state state,
  * cpuhp_setup_state_nocalls_cpuslocked - Setup hotplug state callbacks without
  *					  invoking the @startup callback from
  *					  a cpus_read_lock() held region
- *			       callbacks
- * @state:	The state for which the calls are installed
- * @name:	Name of the callback.
+ * @state:	The state for which the callbacks are installed
+ * @name:	Name of the callback (will be used in debug output)
  * @startup:	startup callback function or NULL if not required
  * @teardown:	teardown callback function or NULL if not required
  *
@@ -332,15 +331,15 @@ static inline int cpuhp_setup_state_nocalls_cpuslocked(enum cpuhp_state state,
 }
 
 /**
- * cpuhp_setup_state_multi - Add callbacks for multi state
- * @state:	The state for which the calls are installed
- * @name:	Name of the callback.
+ * cpuhp_setup_state_multi - Add callbacks for multi-instance state
+ * @state:	The state for which the callbacks are installed
+ * @name:	Name of the callback (will be used in debug output)
  * @startup:	startup callback function or NULL if not required
  * @teardown:	teardown callback function or NULL if not required
  *
  * Sets the internal multi_instance flag and prepares a state to work as a multi
  * instance callback. No callbacks are invoked at this point. The callbacks are
- * invoked once an instance for this state are registered via
+ * invoked once an instance for this state is registered via
  * cpuhp_state_add_instance() or cpuhp_state_add_instance_nocalls()
  */
 static inline int cpuhp_setup_state_multi(enum cpuhp_state state,
@@ -361,10 +360,10 @@ int __cpuhp_state_add_instance_cpuslocked(enum cpuhp_state state,
 					  struct hlist_node *node, bool invoke);
 
 /**
- * cpuhp_state_add_instance - Add an instance for a state and invoke startup
- *                            callback.
+ * cpuhp_state_add_instance - Add an instance for a state and invoke its
+ *                            startup callback.
  * @state:	The state for which the instance is installed
- * @node:	The node for this individual state.
+ * @node:	The node for this individual instance.
  *
  * Installs the instance for the @state and invokes the registered startup
  * callback on the online cpus which have already reached the @state. The
@@ -379,12 +378,12 @@ static inline int cpuhp_state_add_instance(enum cpuhp_state state,
 
 /**
  * cpuhp_state_add_instance_nocalls - Add an instance for a state without
- *                                    invoking the startup callback.
+ *                                    invoking its startup callback.
  * @state:	The state for which the instance is installed
- * @node:	The node for this individual state.
+ * @node:	The node for this individual instance.
  *
  * Installs the instance for the @state. The @state must have been earlier
- * marked as multi-instance by cpuhp_setup_state_multi. NOP if SMP=n or
+ * marked as multi-instance by cpuhp_setup_state_multi(). NOP if SMP=n or
  * HOTPLUG_CPU=n.
  */
 static inline int cpuhp_state_add_instance_nocalls(enum cpuhp_state state,
@@ -395,11 +394,11 @@ static inline int cpuhp_state_add_instance_nocalls(enum cpuhp_state state,
 
 /**
  * cpuhp_state_add_instance_nocalls_cpuslocked - Add an instance for a state
- *						 without invoking the startup
+ *						 without invoking its startup
  *						 callback from a cpus_read_lock()
  *						 held region.
  * @state:	The state for which the instance is installed
- * @node:	The node for this individual state.
+ * @node:	The node for this individual instance.
  *
  * Same as cpuhp_state_add_instance_nocalls() except that it must be
  * invoked from within a cpus_read_lock() held region.
@@ -416,7 +415,7 @@ void __cpuhp_remove_state_cpuslocked(enum cpuhp_state state, bool invoke);
 
 /**
  * cpuhp_remove_state - Remove hotplug state callbacks and invoke the teardown
- * @state:	The state for which the calls are removed
+ * @state:	The state for which the callbacks are removed
  *
  * Removes the callback functions and invokes the teardown callback on
  * the online cpus which have already reached the @state.
@@ -429,7 +428,7 @@ static inline void cpuhp_remove_state(enum cpuhp_state state)
 /**
  * cpuhp_remove_state_nocalls - Remove hotplug state callbacks without invoking
  *				the teardown callback
- * @state:	The state for which the calls are removed
+ * @state:	The state for which the callbacks are removed
  */
 static inline void cpuhp_remove_state_nocalls(enum cpuhp_state state)
 {
@@ -439,7 +438,7 @@ static inline void cpuhp_remove_state_nocalls(enum cpuhp_state state)
 /**
  * cpuhp_remove_state_nocalls_cpuslocked - Remove hotplug state callbacks without invoking
  *					   teardown from a cpus_read_lock() held region.
- * @state:	The state for which the calls are removed
+ * @state:	The state for which the callbacks are removed
  *
  * Same as cpuhp_remove_state nocalls() except that it must be invoked
  * from within a cpus_read_lock() held region.
@@ -450,12 +449,12 @@ static inline void cpuhp_remove_state_nocalls_cpuslocked(enum cpuhp_state state)
 }
 
 /**
- * cpuhp_remove_multi_state - Remove hotplug multi state callback
- * @state:	The state for which the calls are removed
+ * cpuhp_remove_multi_state - Remove hotplug multi-instance state callback
+ * @state:	The state for which the callbacks are removed
  *
- * Removes the callback functions from a multi state. This is the reverse of
- * cpuhp_setup_state_multi(). All instances should have been removed before
- * invoking this function.
+ * Removes the callback functions from a multi-instance state. This is
+ * the reverse of cpuhp_setup_state_multi(). All instances should have
+ * been removed before invoking this function.
  */
 static inline void cpuhp_remove_multi_state(enum cpuhp_state state)
 {
@@ -469,7 +468,7 @@ int __cpuhp_state_remove_instance(enum cpuhp_state state,
  * cpuhp_state_remove_instance - Remove hotplug instance from state and invoke
  *                               the teardown callback
  * @state:	The state from which the instance is removed
- * @node:	The node for this individual state.
+ * @node:	The node for this individual instance.
  *
  * Removes the instance and invokes the teardown callback on the online cpus
  * which have already reached @state.
@@ -484,7 +483,7 @@ static inline int cpuhp_state_remove_instance(enum cpuhp_state state,
  * cpuhp_state_remove_instance_nocalls - Remove hotplug instance from state
  *					 without invoking the teardown callback
  * @state:	The state from which the instance is removed
- * @node:	The node for this individual state.
+ * @node:	The node for this individual instance.
  *
  * Removes the instance without invoking the teardown callback.
  */

-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] cpu/hotplug: Demystify the terms 'BP' and 'AP' in the code
  2026-11-27  7:26 [PATCH 0/4] cpu/hotplug: Update documentation and naming convention for hotplug callbacks Srivatsa S. Bhat (Microsoft)
  2026-11-27  7:26 ` [PATCH 1/4] Documentation: core-api/cpuhotplug: Fix a few minor inconsistencies Srivatsa S. Bhat (Microsoft)
  2026-11-27  7:26 ` [PATCH 2/4] cpu/hotplug: Trivial doc updates in cpuhotplug.h Srivatsa S. Bhat (Microsoft)
@ 2026-11-27  7:27 ` Srivatsa S. Bhat (Microsoft)
  2026-11-27  7:27 ` [PATCH 4/4] Documentation: core-api/cpuhotplug: Add naming convention for callbacks Srivatsa S. Bhat (Microsoft)
  3 siblings, 0 replies; 5+ messages in thread
From: Srivatsa S. Bhat (Microsoft) @ 2026-11-27  7:27 UTC (permalink / raw)
  To: Jonathan Corbet, Shuah Khan, Randy Dunlap, Thomas Gleixner,
	Peter Zijlstra
  Cc: linux-doc, linux-kernel, Srivatsa S. Bhat, Prasanna Kumar T S M,
	Saurabh Sengar

The terms 'BP' and 'AP' appear throughout the CPU hotplug code and
documentation, but there is no mention of what these acronyms expand
to and what do they actually represent in the context of the CPU
hotplug state machine.

Provide some background in the code and the docs to demystify these
terms.

Signed-off-by: Srivatsa S. Bhat (Microsoft) <srivatsa@csail.mit.edu>
---
 Documentation/core-api/cpu_hotplug.rst | 20 ++++++++++++++++++++
 include/linux/cpuhotplug.h             |  5 +++++
 2 files changed, 25 insertions(+)

diff --git a/Documentation/core-api/cpu_hotplug.rst b/Documentation/core-api/cpu_hotplug.rst
index 4e228fc00624..fe5385a8bd8e 100644
--- a/Documentation/core-api/cpu_hotplug.rst
+++ b/Documentation/core-api/cpu_hotplug.rst
@@ -143,6 +143,26 @@ at state ``CPUHP_OFFLINE``. This includes:
 The CPU hotplug API
 ===================
 
+CPU roles in CPU hotplug operations
+-----------------------------------
+
+Any CPU hotplug operation involves at least 2 CPUs performing different roles: a
+control CPU that drives the online or offline operation, and a target CPU which
+is actually onlined or offlined as a result.
+
+The CPU which takes the role of a control CPU for a given hotplug operation is
+referred to as BP (Boot Processor), and the target CPU is referred to as AP
+(Application Processor) in the code.
+
+The terms BP and AP make the most literal sense when we consider the very first
+CPU online in the system, where the Boot Processor is already up and running the
+kernel in uniprocessor mode, and onlines the first secondary CPU (i.e.,
+Application Processor). After this step, for any subsequent CPU online or
+offline operation, any CPU can take the role of the control CPU and any CPU can
+be the target. Hence, the terms BP and AP lose their literal meaning but they
+are used as a shorthand in the code for what they represent (i.e., the control
+and the hotplugged CPUs respectively).
+
 CPU hotplug state machine
 -------------------------
 
diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h
index f51303255bf0..52c42db50ec2 100644
--- a/include/linux/cpuhotplug.h
+++ b/include/linux/cpuhotplug.h
@@ -5,6 +5,11 @@
 #include <linux/types.h>
 
 /*
+ * CPU hotplug state machine:
+ *
+ * BP = "Boot Processor" or control CPU for the hotplug operation.
+ * AP = "Application Processor" or "hotplugged" (target) CPU.
+ *
  * CPU-up			CPU-down
  *
  * BP		AP		BP		AP

-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] Documentation: core-api/cpuhotplug: Add naming convention for callbacks
  2026-11-27  7:26 [PATCH 0/4] cpu/hotplug: Update documentation and naming convention for hotplug callbacks Srivatsa S. Bhat (Microsoft)
                   ` (2 preceding siblings ...)
  2026-11-27  7:27 ` [PATCH 3/4] cpu/hotplug: Demystify the terms 'BP' and 'AP' in the code Srivatsa S. Bhat (Microsoft)
@ 2026-11-27  7:27 ` Srivatsa S. Bhat (Microsoft)
  3 siblings, 0 replies; 5+ messages in thread
From: Srivatsa S. Bhat (Microsoft) @ 2026-11-27  7:27 UTC (permalink / raw)
  To: Jonathan Corbet, Shuah Khan, Randy Dunlap, Thomas Gleixner,
	Peter Zijlstra
  Cc: linux-doc, linux-kernel, Srivatsa S. Bhat, Prasanna Kumar T S M,
	Saurabh Sengar

Add a naming convention for the startup and teardown callbacks
registered for CPU hotplug states. Follow the common pattern of
subsys_cpu_mode(), where subsys is the subsystem or driver that is
registering the callback, and mode reflects the state that the
callback is associated with (ex: prepare, starting/dying,
online/offline).

Signed-off-by: Srivatsa S. Bhat (Microsoft) <srivatsa@csail.mit.edu>
---
 Documentation/core-api/cpu_hotplug.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/Documentation/core-api/cpu_hotplug.rst b/Documentation/core-api/cpu_hotplug.rst
index fe5385a8bd8e..ea00859154be 100644
--- a/Documentation/core-api/cpu_hotplug.rst
+++ b/Documentation/core-api/cpu_hotplug.rst
@@ -444,6 +444,16 @@ The @teardown argument is a function pointer to the callback which should
 be invoked during a CPU offline operation. If the usage site does not
 require a teardown callback, set the pointer to NULL.
 
+The naming convention for the @startup and @teardown callback
+functions is "subsys_cpu_mode()". For example: vmstat_cpu_online(),
+trace_rb_cpu_prepare() etc. As with the @name argument outlined above,
+other descriptive function names can also be used instead, if they
+describe the nature of the action performed by that callback better in
+the context of that subsystem (ex: free_vm_stack_cache()). However, if
+you choose to embed the mode in the function's name (i.e., prepare,
+online/offline, starting/dying etc.) as recommended, make sure that it
+aligns with the state that the callback is actually associated with.
+
 The functions differ in the way how the installed callbacks are treated:
 
   * cpuhp_setup_state_nocalls(), cpuhp_setup_state_nocalls_cpuslocked()

-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-27  7:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27  7:26 [PATCH 0/4] cpu/hotplug: Update documentation and naming convention for hotplug callbacks Srivatsa S. Bhat (Microsoft)
2026-11-27  7:26 ` [PATCH 1/4] Documentation: core-api/cpuhotplug: Fix a few minor inconsistencies Srivatsa S. Bhat (Microsoft)
2026-11-27  7:26 ` [PATCH 2/4] cpu/hotplug: Trivial doc updates in cpuhotplug.h Srivatsa S. Bhat (Microsoft)
2026-11-27  7:27 ` [PATCH 3/4] cpu/hotplug: Demystify the terms 'BP' and 'AP' in the code Srivatsa S. Bhat (Microsoft)
2026-11-27  7:27 ` [PATCH 4/4] Documentation: core-api/cpuhotplug: Add naming convention for callbacks Srivatsa S. Bhat (Microsoft)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®