Sleep mode (WFI instruction) in ARM Architecture - Time & Space Complexity
We want to understand how the WFI (Wait For Interrupt) instruction affects the processor's execution time.
Specifically, how does the processor's waiting behavior impact the time it takes to resume work?
Analyze the time complexity of the following ARM assembly snippet using WFI.
loop:
WFI ; Wait for interrupt
B loop ; Branch back to loop
This code puts the processor into sleep mode until an interrupt occurs, then loops back to wait again.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: The processor repeatedly executes the WFI instruction inside an infinite loop.
- How many times: This loop runs indefinitely, waiting each time for an interrupt before continuing.
The execution time depends on how often interrupts occur, not on input size.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Waits for 10 interrupts, each waking the processor once |
| 100 | Waits for 100 interrupts, each waking the processor once |
| 1000 | Waits for 1000 interrupts, each waking the processor once |
Pattern observation: The total wait time grows linearly with the number of interrupts, not with any input size.
Time Complexity: O(k)
This means the total time depends on the number of interrupts (k), not on data size.
[X] Wrong: "The WFI instruction speeds up processing by reducing loop time."
[OK] Correct: WFI actually pauses the processor until an interrupt happens, so it does not speed up execution but saves power during idle times.
Understanding how WFI affects execution helps you explain power-saving techniques and interrupt handling in embedded systems.
"What if we replaced WFI with a busy-wait loop checking a flag? How would the time complexity and power use change?"