sched/clock: fix stale CLOCK_MONOTONIC on SCHED_TICKLESS - #19905
Merged
Conversation
clock_gettime(CLOCK_MONOTONIC) reads g_system_ticks, which is only refreshed when a timer expiration is processed. On SCHED_TICKLESS an idle system has no timeout armed, so the clock returns 0 before the first expiration and a frozen value afterwards. This regressed in commit c7b6442, which switched CLOCK_MONOTONIC to the sched tick counter to exclude suspended time. Excluding suspend time needs explicit accounting maintained by PM code, the tick counter cannot provide it on tickless. Restore the live read. On non-tickless builds clock_systime_timespec() falls back to the same tick counter, so behavior there is unchanged. Verified on qemu-intel64, nrf52840-dk and rv-virt. Signed-off-by: raiden00pl <raiden00@railab.me> Assisted-by: Claude Code
raiden00pl
requested review from
GUIDINGLI,
jerpelea and
xiaoxiang781216
as code owners
August 20, 2026 09:49
Member
Author
|
Contributor
acassis
approved these changes
Aug 20, 2026
xiaoxiang781216
approved these changes
Aug 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
clock_gettime(CLOCK_MONOTONIC) reads g_system_ticks, which is only refreshed when a timer expiration is processed. On SCHED_TICKLESS an idle system has no timeout armed, so the clock returns 0 before the first expiration and a frozen value afterwards.
This regressed in commit c7b6442, which switched CLOCK_MONOTONIC to the sched tick counter to exclude suspended time. Excluding suspend time needs explicit accounting maintained by PM code, the tick counter cannot provide it on tickless.
Restore the live read. On non-tickless builds clock_systime_timespec() falls back to the same tick counter, so behavior there is unchanged.
Impact
fix issue from #17199 (comment)
Testing
verified on qemu-intel64, nrf52840-dk and rv-virt.
CPython 3.13 REPL on
qemu-intel64:python(SCHED_TICKLESS, TSC deadline timer), system idle at the prompt between reads: