Table of Contents
WFE/SEV
Introduce WFE/WFET, SEV/SEVL instructions.
- These instructions are used to implement the following mechanisms for power saving (Put a PE into low-power state that is IMPLEMENTATION DEFINED).
- Wait for event (WFE/WFET, SEV/SEVL)
- The working mechanism of WFE/WFET, SEV/SEVL is based on the Event register(1). Each PE has a bit in the Event register corresponding to it.
- The Event register can only be cleared by WFE/WFET, but can be set by SEV/SEVL or other mechanisms (This means that the WFE/WFET can be completed when these cases occur.).
- SEV/SEVL cannot wake up a PE that has been placed in a low power state by the WFI or WFIT.
Wait for event
The Event Register
When the PE executes WFE or WFET, all of the following apply.
- If the Event register is clear, then the PE can enter the low-power state.
- If the Event register is set, then all of the following apply:
- The PE does not suspend operation.
- The Event register is cleared.
- The WFE or WFET instruction completes immediately.
The Event Register for a PE is set by any of the following:
- A Send Event instruction, SEV, executed by any PE in the system.
- A Send Event Local instruction, SEVL, executed by the PE.
- An exception return.
- The clearing of the global monitor for the PE.
- An event from a Generic Timer event stream.
- An event sent by some IMPLEMENTATION DEFINED mechanism.
The Send Event instructions
- SEV, Send Event: Causes an event to be signaled to all PEs in a multiprocessor system.(2)
- SEVL, Send Event Local: Causes an event to be signaled locally without requiring the event to be signaled to other PEs in a multiprocessor system.
Why need SEVL?
In ARMv8-A A64, the WFE instruction is unconditional. So I think there are two typical ways to implement the lock function, with or without SEVL.
The first way (without SEVL) is:
func spin_lock
MOV w2, #1
loop:
LDXR w1, [x0]
CBNZ w1, sleep
STXR w1, w2, [x0]
CBZ w1, end
B loop
sleep:
WFE
B loop
end:
ret
endfunc spin_lock
The second way (with SEVL) is:
func spin_lock
MOV w2, #1
SEVL
l1:
WFE
l2:
LDXR w1, [x0]
CBNZ w1, l1
STXR w1, w2, [x0]
CBNZ w1, l2
RET
endfunc spin_lock
As the first way listed above, I think the lock function will still work fine with just WFE. Therefore, I still don't understand why ARM designed it. Maybe it can be used for efficiency or other scenarios.
Further Reading
-
- D1.6. Mechanisms for entering a low-power state
- B2.9.2. Exclusive access instructions and Shareable memory locations