What is WFI versus WFE?
Short answer: WFI waits for an interrupt or another permitted wake condition. WFE waits for an event or other permitted wake condition; SEV sends an event. Neither is a synchronization primitive by itself.
WFI // idle hint
WFE // event wait hint
SEV // send event
1. WFI: A CPU idle loop may use Wait For Interrupt so the processor can reduce activity until a wake condition occurs.
2. WFE: Wait For Event can be used in a waiting loop. SEV sends an event; a previously recorded event may make WFE return immediately.
3. Practical pattern: Always recheck the shared condition after waking. Wakeups can be unrelated to the expected event, and ordering must be supplied separately.
| WFI | WFE |
|---|---|
| Common in idle paths | Common in event-based wait loops |
| Interrupt-related wakeup | Event or other allowed wakeup |
Interview takeaway: These are architectural hints, not locks or guarantees that the core sleeps for a particular duration.
Event waiting and lost-wakeup considerations
AArch64 maintains an event mechanism used by WFE. An event may already be recorded when WFE executes, in which case the instruction can return immediately. SEV signals an event; SEVL is a local event-setting instruction. WFI and WFE may also be treated as hints or trap under virtualization controls, depending on the architecture and configuration.
A conceptual event-based lock waiter must repeatedly check the lock with the required atomic ordering. The unlock path publishes the released state and follows the matching notification protocol. A plain load followed by WFE without a correct event protocol can miss a state change. Use the OS or architecture's established synchronization primitives rather than inventing a wait loop.
For low-power idle, configure appropriate wake sources and account for pending work, clock/power-domain behavior and wake latency. Neither WFI nor WFE specifies the SoC's eventual power state or guarantees that a particular interrupt has been serviced when execution resumes.