Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

10.4 CPU Hotplug State Initialization

To provide architectural support for hotplugging capabilities, Linux declares a _per_cpu variable named cpuhp_state within the private memory zone of each individual CPU core. The type of this variable is defined by the structure struct cpuhp_cpu_state, as shown below:

struct cpuhp_cpu_state {
	enum cpuhp_state	state;
	enum cpuhp_state	target;
	enum cpuhp_state	fail;
	struct task_struct	*thread;
	bool			should_run;
	bool			rollback;
	bool			single;
	bool			bringup;
	struct hlist_node	*node;
	struct hlist_node	*last;
	enum cpuhp_state	cb_state;
	int			result;
	struct completion	done_up;
	struct completion	done_down;
};

Because the first CPU has already commenced the boot sequence, the system must update its local hotplug tracking variable cpuhp_state to mark the state field, which signifies the current operational phase of the hardware component, as online. The function responsible for initializing this initial hotplug state is implemented as follows:

void __init boot_cpu_hotplug_init(void)
{
#ifdef CONFIG_SMP
	cpumask_set_cpu(smp_processor_id(), &cpus_booted_once_mask);
#endif
	this_cpu_write(cpuhp_state.state, CPUHP_ONLINE);
}

Within this procedure, the function cpumask_set_cpu() sets the corresponding bit belonging to the first CPU inside the bitmask cpus_booted_once_mask. Concurrently, this_cpu_write() marks the state field of the per_cpu variable cpuhp_state of the first CPU as CPUHP_ONLINE. By breaking down the ARM-specific implementation of the this_cpu_write(pcp, val) function, it can be determined that this_cpu_write(pcp, val) evaluates as functionally equivalent to:

*(&pcp + _my_cpu_offset()) = val;

Here, _my_cpu_offset() represents the offset value read directly from the TPIDRPRW register of the CP15 coprocessor. As established in the preceding section, the TPIDRPRW register preserves the private memory base offset address of the first CPU; consequently, this_cpu_write() successfully writes the targeted numerical value directly into the private variable space of the first CPU.

Copyright © 2026 Guangzhou eSmart Information Technology Co., Ltd. All Rights Reserved.
All content in this book is copyrighted by the author. For personal learning and exchange only. Commercial use without authorization is strictly prohibited. Email:

✉ 3348194517@qq.com | hai616878@gmail.com