The ARM Cortex architecture provides two instructions for entering sleep or low power mode – WFE (Wait For Event) and WFI (Wait For Interrupt). Understanding the differences between WFE and WFI is important for optimizing power consumption and wakeup latency in ARM-based systems.
What is WFE?
WFE (Wait For Event) instructs the processor to enter a low power state until a wakeup event occurs. The processor may power down unused components while waiting for the event. WFE only responds to events generated by another processor core in a multi-core system. Events that trigger wakeup include:
- Setting the CPU’s event flag register by another core
- Executing a SEV instruction on another core
- Asserting the physical CPU’s wakeup interrupt
WFE is used for synchronizing between cores in a multi-core ARM system. The instruction can minimize power consumption while waiting on operations running on other cores.
What is WFI?
WFI (Wait For Interrupt) also puts the processor into a low power state until resumed by an interrupt. However, WFI can be awakened by interrupts from any source, including:
- Interrupts from internal system peripherals
- External interrupts from GPIO pins
- Virtual interrupts from a hypervisor
- Physical CPU wakeup interrupts
WFI allows the processor to enter low power mode while waiting for any interrupt event in the system. This makes it more flexible than WFE for system-wide low power states.
Key Differences Between WFE and WFI
The main differences between WFE and WFI are:
- Event Sources – WFE only wakes up on events from other cores. WFI wakes up on any interrupt.
- Latency – WFE has lower wakeup latency as it only needs to check core internal events.
- Coordination – WFE is used for synchronization between cores. WFI can independently enter low power mode.
- Power Savings – WFI allows full system power down; WFE only affects the CPU/cluster.
WFE Detailed Behavior
The steps the processor takes when executing a WFE instruction are:
- Check if an event flag is already set for this processor – if yes, exit immediately
- Suspend execution and enter low power state
- Monitor event flag register and wakeup interrupt signals
- When event flag or interrupt detected, exit low power state
- Clear the event flag
- Resume execution after WFE instruction
The processor may power gate unused internal components while waiting for the wake event. However, it continues to monitor event flag registers and wakeup interrupts.
WFI Detailed Behavior
When executing a WFI instruction, the processor will:
- Check for any pending interrupts – if found, exit immediately
- Enter low power state, disabling interrupts
- Monitor incoming external, peripheral, virtual, and physical wakeup interrupts
- On receiving a valid interrupt, exit low power state
- Re-enable interrupt handling and fetch next instruction after WFI
WFI allows full system power down, except for interrupt monitoring logic. Interrupts are disabled during WFI to avoid immediately waking the processor again.
Using WFE and WFI in ARM Systems
The ARM Architecture Reference Manual recommends using WFE for core-to-core synchronization and WFI for general low power states waiting for any interrupt. Some usage examples include:
- Use WFE when signaling between cores, for example with mutexes or semaphores.
- Use WFE in a multicore interrupt handler to wake up other cores.
- Use WFI when idling a core that is waiting for a peripheral or external interrupt.
- Use WFI when entering low power mode in a single core system.
Software should use WFE and WFI whenever the processor does not need to actively run instructions. Preventing unwanted clocking and power usage can significantly reduce energy consumption.
Considerations When Using WFE vs WFI
There are some key considerations when deciding between using WFE or WFI:
- Wakeup latency – WFE has lower latency as it only monitors core events.
- Coordination overhead – WFE requires managing event flags between cores.
- Peripheral readiness – Peripherals may require initialization code to run after WFI.
- Interrupt sources – WFI can wake from more sources than WFE.
- Power savings – WFI allows full system suspend; WFE only affects the CPU cluster.
So in summary, WFE has lower overhead and latency but works best for core synchronization. WFI provides greater flexibility and power savings when waiting for interrupts.
The ARM WFE and WFI instructions both allow entering low power states until a resume event occurs. However, WFE focuses on multi-core coordination by waiting for events from other cores. WFI provides more flexibility by waiting for any interrupt. Understanding their differences allows optimally utilizing these instructions to reduce power consumption in ARM devices.