10.3 Preparing the Boot CPU
The preparation of the boot CPU is tightly coupled with the specific hardware architecture. Under the ARM architecture, the function responsible for preparing the boot CPU is defined within the file git/arch/arm/kernel/smp.c, and its definition is as follows:
void __init smp_prepare_boot_cpu(void)
{
set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
}
Within this routine, the return value of smp_processor_id() evaluates to 0, which designates the first CPU core to act as the boot CPU. The function per_cpu_offset() is implemented as a macro definition, expressed as #define per_cpu_offset(x) (__per_cpu_offset[x]), and is leveraged to retrieve the base memory offset address of a specific CPU's per_cpu variables within the private memory space. The function set_my_cpu_offset writes this retrieved offset address of the per_cpu variables into the TPIDRPRW register of the CP15 coprocessor. Therefore, the primary objective of the function smp_prepare_boot_cpu(void) is to write the private memory address offset of the first CPU into the CP15 TPIDRPRW register. The TPIDRPRW register preserves the base memory address utilized for storing thread-specific diagnostics and state information.