在Linux系統中,對於多核的ARM晶片而言,Bootrom代碼中,CPU0會率先起來,引導Bootloader和Linux核心執行,而其他的核則在上電時Bootrom一般將自身置於WFI或者WFE狀態,並等待CPU0給其發CPU核間中斷(IPI)或事件(一般透過SEV指令)喚醒之。一個典型的啟動過程如下圖:
被CPU0喚醒的CPUn可以在運行過程中進行熱插拔。譬如運行如下命令即可卸載CPU1並且將CPU1上的任務全部遷移到其他CPU:
# echo 0 > /sys/devices/system/cpu/cpu1/online
同樣地,運行如下命令可以再次啟動CPU1:
# echo 1 > /sys/devices/system/cpu/cpu1/online
之後CPU1會主動參與系統中各個CPU之間要運行任務的負載平衡工作。
CPU0喚醒其他 CPU的動作在核心中被封裝為一個smp_operations的結構體,該結構體的成員如下:
83struct smp_operations {
84#ifdef CONFIG_SMP
85 /*
86 * Setup the set of possible CPUs (via set_cpu_possible)
87 */
88 void (*smp_init_cpus)(void);
89 /*
90 * Initialize cpu_possible map, and enable coherency
91 */
92 void (*smp_prepare_cpus)(unsigned int max_cpus);
93
94 /*
95 * Perform platform specific initialisation of the specified CPU.
96 */
97 void (*smp_secondary_init)(unsigned int cpu);
98 /*
99 * Boot a secondary CPU, and assign it the specified idle task.
100 * This also gives us the initial stack to use for this CPU.
101 */
102 int (*smp_boot_secondary)(unsigned int cpu, struct task_struct *idle);
103#ifdef CONFIG_HOTPLUG_CPU
104 int (*cpu_kill)(unsigned int cpu);
105 void (*cpu_die)(unsigned int cpu);
106 int (*cpu_disable)(unsigned int cpu);
107#endif
108#endif
109};