This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Difference between WFI and WFE

Hi Experts,

What is the difference between WFE and WFI instructions ?

I am able to interpret WFI is like when the physical interrupt signal is activated then the processor wakes up and similarly how the event is detected in ARM  V8 ?

  • In ways they quite similar, the difference comes down to how they are used.

    WFI - wait for interrupt

    The processor will enter standby, and wake on the next interrupt.

    WFI - wait for event

    The processor will enter standby, and wake on the next interrupt OR event.

    "Events" can be generated in a number of ways, for example by executing SEV or by via the Generic Timer Event Stream.

    WFI is typically used in idle loops, or as part of the process of entering a deeper sleep (e.g. shut down mode).

    WFE is often used in spin-locks.  Spin-locks are typically used for resources that are only held for a short period.  So if a thread attempts to lock a spin-lock and finds it already taken, it will "spin" until it becomes available.  Actually spinning is wasteful, so the lock function could use WFE to enter standby.  An "event" is generated when the other thread releases the spin-lock, causing the waiting thread to wake and re-attempt the lock. It's important to note that there is no additional information in an event.  That is, you don't know which spin-lock was released, hence the waking thread has to re-attempt the lock.  It might fail, and re-enter stand-by.

    NOTE: There some other subtle differences between the two, which I haven't gone into.  Such as the effect of the interrupt masking bits, which is different for WFE/WFI.  If you want that level of detail, you should see the ARM ARM.

  • Hello,

    to generate an event, there are mainly two ways.

    One is to execute SEV or SEVL instruction.

    Another is to assert EVENT I pin of a cpu core.

    The method to drive EVENTI pin is SOC device specific.

    Best regards,

    Yasuhiko Koumoto.