0
0
ARM Architectureknowledge~5 mins

Sleep mode (WFI instruction) in ARM Architecture - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Sleep mode (WFI instruction)
O(k)
Understanding Time 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?

Scenario Under Consideration

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 Repeating Operations

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.
How Execution Grows With Input

The execution time depends on how often interrupts occur, not on input size.

Input Size (n)Approx. Operations
10Waits for 10 interrupts, each waking the processor once
100Waits for 100 interrupts, each waking the processor once
1000Waits 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.

Final Time Complexity

Time Complexity: O(k)

This means the total time depends on the number of interrupts (k), not on data size.

Common Mistake

[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.

Interview Connect

Understanding how WFI affects execution helps you explain power-saving techniques and interrupt handling in embedded systems.

Self-Check

"What if we replaced WFI with a busy-wait loop checking a flag? How would the time complexity and power use change?"