1. 程式人生 > >arm 待機指令 WFI和WFE

arm 待機指令 WFI和WFE

百度百科上對於待機的解釋:
待機是將當前處於執行狀態的資料儲存在記憶體中,機器只對記憶體供電,而硬碟、螢幕和CPU等部件則停止供電。由於資料儲存在速度快的記憶體中,因此進入等待狀態和喚醒的速度比較快。
對於手機而言,待機就是除了DDR保持低頻重新整理,維護DDR中資料以外,其他的外圍裝置都斷電,cpu core也進入low power 模式,
停止工作,等待外部事件喚醒。


arm core進入待機依賴兩個arm 指令,WFI(Wait for interrupt)和WFE(Wait for event)。
這兩個指令都可以使cpu core進入低電模式,但是也有細微差別,
具體看下arm解釋。


Wait for Event WFE:
If the event register is currently set, WFE (Wait For Event) clears it and returns immediately. If the event register is not set, the processor suspends execution (Clock is stopped) until one of the following events take place:
An IRQ interrupt, unless masked by the CPSR I Bit
An FIQ interrupt, unless masked by the CPSR F Bit
A Debug Entry request made to the processor and Debug is enabled
An event is signaled by another processor using Send Event.
Another MP11 CPU return from exception.


Wait for Interrupt WFI:
WFI (Wait For Interrupt) makes the processor suspend execution (Clock is stopped) until one of the following events take place:
An IRQ interrupt
An FIQ interrupt
A Debug Entry request made to the processor.


對WFI來說,執行WFI指令後,ARM core會立即進入low-power standby state,直到有WFI Wakeup events發生。
而WFE則稍微不同,執行WFE指令後,根據Event Register(一個單bit的暫存器,每個PE一個)的狀態,有兩種情況:如果Event Register為1,該指令會把它清零,然後執行完成(不會standby);如果Event Register為0,和WFI類似,進入low-power standby state,直到有WFE Wakeup events發生。


而在系統待機時候,當執行完task freeze,所有device suspend後,執行WFI指令進入待機狀態,然後等待外圍中斷喚醒。