ARM多核處理器啟動過程分析
說明:
該流程圖按照代碼執(zhí)行時間順序劃分為4部分:
1.Bootloader在圖片上半部,最先啟動;
2.Kernel在圖片下半部,由bootloader引導(dǎo)啟動;
3.CPU0執(zhí)行流程在圖片左半部,bootloader代碼會進行判斷,先行啟動CPU0;
4. Secondary CPUs在圖片右半部,由CPU喚醒
具體啟動流程如下:
1.在bootloader啟動時,會判斷執(zhí)行代碼的是否為CPU0,如果不是,則執(zhí)行wfe等待CPU0發(fā)出sev指令喚醒。如果是CPU0,則繼續(xù)進行初始化工作。
mrs x4,mpidr_el1
tst x4,#15//testwether the current cpu is CPU0, ie. mpidr_el1=15
b.eq 2f
/*
* Secondary CPUs
*/
1: wfe
ldr x4, mbox
cbz x4, 1b//if x4==0(ie. The value in address of mbox is 0) dead loop,or jump to x4
br x4 // branch to thegiven address
2:…… //UART initialisation (38400 8N1)
以上mbox的地址在Makefile中寫定,是0x8000fff8,該地址處初始狀態(tài)內(nèi)容為全0。上面代碼判斷,若mbox地址處內(nèi)容為0,則死循環(huán);如果不為0則直接跳轉(zhuǎn)到該地址所包含內(nèi)容處執(zhí)行。
2.在dts中,對cpu-release-addr進行賦值,將其地址設(shè)為0x8000fff8。即只要往該地址寫入相應(yīng)的值,例如地址A,并且發(fā)送sev指令,就能將次級CPU喚醒,并跳轉(zhuǎn)到A地址處執(zhí)行。
cpu-release-addr = <0x0 0x8000fff8>;
3. 內(nèi)核中smp_prepare_cpus 函數(shù)對0x8000fff8地址處內(nèi)容進行了賦值,其值為函數(shù)secondary_holding_pen 的地址:
release_addr = __va(cpu_release_addr[cpu]);
release_addr[0] = (void*)__pa(secondary_holding_pen);//write function address to mbox
以上代碼執(zhí)行完后發(fā)送sev指令,喚醒其他次級CPU執(zhí)行secondary_holding_pen函數(shù):
/*
* Send an event to wake up the secondaries.
*/
sev();
4. secondary cpu 執(zhí)行secondary_holding_pen()函數(shù)時都會去判斷當(dāng)前CPU的ID,并與secondary_holding_pen_release變量做比對,如果相等,則執(zhí)行進一步初始化,否則執(zhí)行WFE等待;
secondary_holding_pen_release變量的修改過程由CPU0調(diào)用smp_init()函數(shù)進行。該函數(shù)首先為相應(yīng)CPU綁定一個idle線程,然后修改secondary_holding_pen_release的值(其值即CPU0欲喚醒的CPU的ID),最后發(fā)送sev指令,喚醒相應(yīng)CPU執(zhí)行idle線程。
secondary_holding_pen()函數(shù)代碼如下:
/*
* This provides a"holding pen" for platforms to hold all secondary
* cores are helduntil were ready for them to initialise.
*/
ENTRY(secondary_holding_pen)
bl el2_setup // Drop to EL1
mrs x0, mpidr_el1
and x0, x0, #15 // CPU number
adr x1, 1b
ldp x2, x3, [x1]
sub x1, x1, x2
add x3, x3, x1
pen: ldr x4, [x3]
cmp x4,x0
b.eq secondary_startup
wfe
b pen
ENDPROC(secondary_holding_pen)
附錄:
內(nèi)核中啟動secondary cpus函數(shù)調(diào)用過程大致如下:
start_kernel èrest_initèkernel_inièkernel_init_freeable èsmp_init() kernel/smp.c line 649, 由CPU0激活剩余的處理器
cpu_upè_cpu_up()è__cpu_up ()èboot_secondary ()èwrite_pen_release該函數(shù)中有一句:secondary_holding_pen_release = val; 然后發(fā)送sev指令,激活剩余處理器。
評論