


23 Jun 2025

5 min read
High Level Design of Timeouts in Zephyr
-Sayooj K Karun

23 Jun 2025

5 min read
High Level Design of Timeouts in Zephyr
-Sayooj K Karun
Sayooj K Karun
Staff Engineer
Follow Us

A timeout is a software event scheduled to occur after a specific number of kernel ticks. It’s used to:
| Component | Description |
|---|---|
| timeout_list | Sorted linked list of all active timeouts (sooner first). |
| curr_tick | Software-maintained tick counter (keep in sync with hardware timer). |
| timeout_lock | Spinlock for protecting timeout list access in SMP.ISR-safe manner. |
| _timeout struct | Kernel object representing a timeout. Often embedded inside other objects. |
`sys_clock_announce()` or `z_clock_announce()` is the mechanism by which the hardware tells the kernel how many ticks have elapsed.
It “announces” time progression, and the kernel responds by:
This separation lets the kernel remain platform-independent, while the SoC-specific timer code just needs to call the `announce()` function when needed.
k_sleep(K_MSEC(100));
Internally:

Add a timeout to the kernel’s `timeout_list` in a sorted position based on when it should expire.
To ensure only the soonest timeout affects the next hardware timer interrupt, improving power efficiency.
Cancel a previously added timeout(e.g., thread woke up early or was aborted).
Used when a timeout was set for a thread or timer, but it no longer needs to wait.
Update the hardware timer to fire at the appropriate time (next timeout tick).
Called by the hardware timer ISR to tell the kernel that ticks have passed.
For each timeout where dticks <= curr_tick, remove and call its callback.
Used internally by the kernel to figure out when the next timeout will expire.
z_clock_announce(ticks) is called by the hardware to notify that N ticks have passed since the last call. But a lot could have happened during those ticks. Many timeouts may have expired.
If Zephyr were to process all expired timeouts at once, it could:
Zephyr limits how many ticks are processed in one call to z_clock_announce(), using announce_remaining variable.
This is especially helpful when the system wakes up from deep sleep, say, 50 ticks passed. It avoids monopoly over CPU by timer right after CPU wakes up.
A configuration in Zephyr that allows the kernel to stop tracking ticks precisely when the system is in idle or power-saving states. (CONFIG_SYSTEM_CLOCK_SLOPPY_IDLE)
In normal operation, the kernel:
But when sloppy idle is enabled:
Example:
If system was idle for 60 ms:
Because tick precision is lost. Events that should have happened at tick 20, 40 and 60 all appears to happen at 60. This is okay for some apps, but not for precise timers.

A timeout is a software event scheduled to occur after a specific number of kernel ticks. It’s used to:
| Component | Description |
|---|---|
| timeout_list | Sorted linked list of all active timeouts (sooner first). |
| curr_tick | Software-maintained tick counter (keep in sync with hardware timer). |
| timeout_lock | Spinlock for protecting timeout list access in SMP.ISR-safe manner. |
| _timeout struct | Kernel object representing a timeout. Often embedded inside other objects. |
`sys_clock_announce()` or `z_clock_announce()` is the mechanism by which the hardware tells the kernel how many ticks have elapsed.
It “announces” time progression, and the kernel responds by:
This separation lets the kernel remain platform-independent, while the SoC-specific timer code just needs to call the `announce()` function when needed.
k_sleep(K_MSEC(100));
Internally:

Add a timeout to the kernel’s `timeout_list` in a sorted position based on when it should expire.
To ensure only the soonest timeout affects the next hardware timer interrupt, improving power efficiency.
Cancel a previously added timeout(e.g., thread woke up early or was aborted).
Used when a timeout was set for a thread or timer, but it no longer needs to wait.
Update the hardware timer to fire at the appropriate time (next timeout tick).
Called by the hardware timer ISR to tell the kernel that ticks have passed.
For each timeout where dticks <= curr_tick, remove and call its callback.
Used internally by the kernel to figure out when the next timeout will expire.
z_clock_announce(ticks) is called by the hardware to notify that N ticks have passed since the last call. But a lot could have happened during those ticks. Many timeouts may have expired.
If Zephyr were to process all expired timeouts at once, it could:
Zephyr limits how many ticks are processed in one call to z_clock_announce(), using announce_remaining variable.
This is especially helpful when the system wakes up from deep sleep, say, 50 ticks passed. It avoids monopoly over CPU by timer right after CPU wakes up.
A configuration in Zephyr that allows the kernel to stop tracking ticks precisely when the system is in idle or power-saving states. (CONFIG_SYSTEM_CLOCK_SLOPPY_IDLE)
In normal operation, the kernel:
But when sloppy idle is enabled:
Example:
If system was idle for 60 ms:
Because tick precision is lost. Events that should have happened at tick 20, 40 and 60 all appears to happen at 60. This is okay for some apps, but not for precise timers.
Recommended Blogs


14 May 2025

5 min read
Exploring Zephyr RTOS: A Lightweight, Scalable Real-Time Operating System for the Modern IoT Era


21 May 2025

5 min read
Zephyr OS Security: Architecture, Features, and the Future of IoT Security


15 Oct 2025

5 min read
Edge AI: Intelligence at the Frontier of Computing
Build with the Most Trusted Engineering Partner
Delivers cutting-edge embedded solutions, from firmware development to wireless protocols, ensuring reliability and innovation.
Copyright © 2026
Privacy Policy
Terms of Service

Delivers cutting-edge embedded solutions, from firmware development to wireless protocols, ensuring reliability and innovation.
Privacy Policy
Terms of Service
Copyright © 2026