4
votes

How does a WFE instruction work ? What I have read is that it makes processor wait for an IRQ /FIQ/event/....

But what happens when you get an IRQ, does the irq_fault_handler vector executes on getting an interrupt or instruction subsequent to the WFE is executed ?

2

2 Answers

8
votes

WFE is conceptually equivalent to

while (!event_has_occurred) /*do nothing*/;

except that it turns the CPU off instead of running a tight loop.

Several things that can interrupt a WFE, including not only an interrupt but also an explicit wake up event from another CPU (in a multicore processor).

If an interrupt happens during WFE, the usual things happens. The processor switches to IRQ or FIQ mode, jumps to the IRQ or FIQ handler, and the address of the WFE instruction (plus the usual offset of 8) is placed in lr.

If the CPU was waken up by an explicit wake up event, the execution proceeds with the next instruction after the WFE.

Think of WFE as a very long NOP which only completes when some external event happens.

0
votes

It should also be stressed that WFE is "just" a hint instruction, i.e.: a compliant implementation could treat it as a NOP rather than going to sleep.

Therefore, you almost always need to surround it with a loop.

The following answer provides a minimal bare-metal assembly example that illustrates how WFE is typically used to wait for an event from another CPU: What does multicore assembly language look like?