Does WFI always put the processor into low-power sleep?
No. The official semantics define WFI as a wait-for-interrupt hint; an implementation may stall, but it may also legally continue as a NOP.
Wait-for-interrupt hint: an implementation may stall the hart until an interrupt might need service, or legally avoid stalling and continue as a NOP.
WFI informs the implementation that the current hart may be stalled until an interrupt might need service. It is a hint, not a portable low-power guarantee: an implementation may avoid stalling and return as if WFI were a NOP. If a locally enabled interrupt is already pending or later becomes pending, WFI may resume and the corresponding interrupt trap is taken on a following instruction boundary. The privileged architecture also defines the mstatus.TW restriction for lower-privilege WFI execution: an implementation may raise an illegal-instruction exception after an implementation-specific bounded time, and may choose to trap immediately.
Shows the fixed SYSTEM encoding, TW restriction, and ISA-visible WFI behavior: it may stall or may return as a NOP.
This animation does not promise sleep duration, power reduction, wake latency, or scheduling policy; those are not portable WFI ISA semantics.
WFI is a wait hint, not guaranteed sleep. It has no explicit operands and a fixed encoding; execution may stall the hart or may immediately continue as a NOP. Portable software must recheck the wait condition after WFI returns.
Understand this scenario with real code like «wfi # Wait for interrupt».
Understand this scenario with real code like «wfi # Wait for interrupt».
No. The official semantics define WFI as a wait-for-interrupt hint; an implementation may stall, but it may also legally continue as a NOP.
Software should recheck its wait condition or pending state, because WFI may resume for any reason and resumption alone does not guarantee the intended event has been handled.