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

7.6 Initializing the Primary Boot CPU

The primary bootstrap lifecycle of an operating system kernel is coordinated and driven forward by a single central processing core—universally designated as CPU Core 0. Therefore, the kernel must explicitly initialize and register this initial execution core within its tracking matrices. The early optimization routine tasked with registering the primary bootstrap processor is declared as boot_cpu_init(), which is maintained within the core subsystem file linux/kernel/cpu.c with the following implementation:

void __init boot_cpu_init(void)
{
   int cpu = smp_processor_id();
   set_cpu_online(cpu, true);
   set_cpu_active(cpu, true);
   set_cpu_present(cpu, true);
   set_cpu_possible(cpu, true);
#ifdef CONFIG_SMP
   __boot_cpu_id = cpu;
#endif
}

The individual function calls encapsulated within this initialization routine update and manipulate distinct CPU bitmask topologies: __cpu_online_mask, __cpu_active_mask, __cpu_present_mask, and __cpu_possible_mask. Toggling the corresponding bit fields to true registers the active core state as online, active, physically present in the current system bus, and legally available for symmetric multiprocessing allocations, respectively.

The programmatic prefix token __init placed before the function return type specifies a specialized compiler section macro attribute. This token instructs the compiler to place the executable machine code of the routine exclusively inside the .init.text section. Memory blocks allocated to this temporary section are utilized strictly during early system architecture bring-up and are completely freed, purged, and recycled back into the global kernel memory pool once the system completes its booting cycles.

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