SysTick timer for RTOS tick in ARM Architecture - Time & Space Complexity
We want to understand how the time taken by the SysTick timer interrupt grows as the system runs. This helps us see how the RTOS tick affects performance.
What happens to execution time when the SysTick interrupt fires repeatedly?
Analyze the time complexity of the following SysTick interrupt handler code.
SysTick_Handler:
PUSH {LR} ; Save return address
INCREMENT tick_count ; Increase system tick
BL RTOS_Scheduler ; Decide next task
POP {LR} ; Restore return address
BX LR ; Return from interrupt
This code runs every SysTick interrupt to update the system tick and run the scheduler.
Look at what repeats each time the SysTick interrupt occurs.
- Primary operation: The RTOS scheduler call inside the interrupt.
- How many times: Once per SysTick interrupt, which happens regularly (e.g., every 1 ms).
As the number of tasks or system load increases, the scheduler work may grow.
| Input Size (Number of Tasks) | Approx. Operations per Tick |
|---|---|
| 10 | 10 operations |
| 100 | 100 operations |
| 1000 | 1000 operations |
Pattern observation: The scheduler work grows roughly in direct proportion to the number of tasks.
Time Complexity: O(n)
This means the time spent in the SysTick handler grows linearly with the number of tasks the scheduler manages.
[X] Wrong: "The SysTick handler always takes the same time regardless of tasks."
[OK] Correct: The scheduler work depends on how many tasks it checks, so more tasks mean more time spent.
Understanding how interrupt handlers scale with system load is key for embedded systems. It shows you can reason about real-time performance and system responsiveness.
"What if the scheduler used a more efficient data structure to pick the next task? How would the time complexity change?"
Practice
Solution
Step 1: Understand SysTick timer role
The SysTick timer is designed to create periodic interrupts.Step 2: Connect interrupts to RTOS function
These interrupts allow the RTOS to switch tasks regularly.Final Answer:
To generate regular interrupts for task switching -> Option AQuick Check:
SysTick timer = periodic interrupts for RTOS [OK]
- Confusing SysTick with CPU clock speed control
- Thinking SysTick stores data
- Assuming SysTick manages memory
Solution
Step 1: Identify the control register bits
The SysTick CTRL register controls timer and interrupt enabling.Step 2: Enable interrupt by setting TICKINT bit
Setting the TICKINT bit enables SysTick interrupts.Final Answer:
Set the TICKINT bit in the SysTick CTRL register -> Option BQuick Check:
Enable interrupt = set TICKINT bit [OK]
- Clearing ENABLE disables timer, not interrupt
- Writing zero to RELOAD stops timer from counting
- Disabling NVIC stops all interrupts, not just SysTick
Solution
Step 1: Calculate ticks per 1 ms interval
CPU clock = 48,000,000 Hz means 48,000 ticks per 1 ms (since 1 ms = 0.001 s).Step 2: Determine reload value
Reload value = ticks per interval - 1 = 48000 - 1 = 47999.Final Answer:
47999 -> Option AQuick Check:
Reload = (CPU clock * tick interval) - 1 = 47999 [OK]
- Using CPU clock directly without subtracting 1
- Confusing microseconds with milliseconds
- Using too small reload value causing faster ticks
Solution
Step 1: Understand reload value effect
A reload value of 0 means the timer counts from 0 to 0, triggering interrupt immediately.Step 2: Resulting behavior
This causes continuous interrupts with no delay, overwhelming the system.Final Answer:
SysTick will generate interrupts continuously without delay -> Option DQuick Check:
Reload=0 causes continuous interrupts [OK]
- Assuming no interrupts occur with reload 0
- Thinking CPU clock changes due to SysTick
- Expecting system reset from this setting
Solution
Step 1: Recognize effect of CPU clock changes
SysTick timer counts CPU clock cycles, so changing clock speed affects tick timing.Step 2: Adjust reload value accordingly
To keep tick interval constant, reload value must be recalculated based on new CPU clock.Final Answer:
Update the SysTick reload value to match the new CPU clock frequency -> Option CQuick Check:
Adjust reload for clock changes to keep tick timing [OK]
- Ignoring clock changes and keeping reload fixed
- Disabling SysTick breaks RTOS timing
- Changing interrupt priority doesn't fix timing
Ready to prove it?
Pass the test and this pattern moves unknown
