From: "Srivatsa S. Bhat (Microsoft)" <srivatsa@csail.mit.edu>
To: Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Thomas Gleixner <tglx@kernel.org>,
Peter Zijlstra <peterz@infradead.org>
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
"Srivatsa S. Bhat" <srivatsa@csail.mit.edu>,
Prasanna Kumar T S M <ptsm@linux.microsoft.com>,
Saurabh Sengar <ssengar@linux.microsoft.com>
Subject: [PATCH 1/4] Documentation: core-api/cpuhotplug: Fix a few minor inconsistencies
Date: Fri, 27 Nov 2026 12:56:58 +0530 [thread overview]
Message-ID: <20261127-docs-cpuhp-v1-1-a34a2c9f66fa@csail.mit.edu> (raw)
In-Reply-To: <20261127-docs-cpuhp-v1-0-a34a2c9f66fa@csail.mit.edu>
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
next prev parent reply other threads:[~2026-11-27 7:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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) [this message]
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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127-docs-cpuhp-v1-1-a34a2c9f66fa@csail.mit.edu \
--to=srivatsa@csail.mit.edu \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=ptsm@linux.microsoft.com \
--cc=rdunlap@infradead.org \
--cc=skhan@linuxfoundation.org \
--cc=ssengar@linux.microsoft.com \
--cc=tglx@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®