sched/tickless: Fix CLOCK_MONOTONIC always 0 by updating sched ticks#18486
Merged
linguini1 merged 1 commit intoapache:masterfrom Mar 3, 2026
Merged
sched/tickless: Fix CLOCK_MONOTONIC always 0 by updating sched ticks#18486linguini1 merged 1 commit intoapache:masterfrom
linguini1 merged 1 commit intoapache:masterfrom
Conversation
Contributor
Author
|
cc @wangchdo |
wangchdo
reviewed
Mar 3, 2026
Fix the issue where clock_gettime(CLOCK_MONOTONIC) always returns 0 in
tickless mode, caused by the scheduler tick counter (g_system_ticks) not
being updated with the actual timer ticks.
1. Add clock_update_sched_ticks() function to sched/clock/clock_sched_ticks.c:
a. This function directly sets the system tick counter to a specific value
(vs incrementing in clock_increase_sched_ticks), with full documentation
matching the existing code style.
b. Uses seqlock to ensure thread-safe access to g_system_ticks.
2. Call clock_update_sched_ticks() in nxsched_process_timer() (sched_processtickless.c):
a. Syncs the scheduler tick counter with the actual timer ticks retrieved via up_timer_gettick().
With this fix, g_system_ticks is properly updated in tickless mode,
and clock_gettime(CLOCK_MONOTONIC) returns the correct non-zero monotonic time.
Signed-off-by: chao an <anchao.archer@bytedance.com>
wangchdo
approved these changes
Mar 3, 2026
xiaoxiang781216
approved these changes
Mar 3, 2026
simbit18
approved these changes
Mar 3, 2026
linguini1
approved these changes
Mar 3, 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
sched/tickless: Fix CLOCK_MONOTONIC always 0 by updating sched ticks
Fix the issue where clock_gettime(CLOCK_MONOTONIC) always returns 0 in
tickless mode, caused by the scheduler tick counter (g_system_ticks) not
being updated with the actual timer ticks.
Add clock_update_sched_ticks() function to sched/clock/clock_sched_ticks.c:
a. This function directly sets the system tick counter to a specific value
(vs incrementing in clock_increase_sched_ticks), with full documentation
matching the existing code style.
b. Uses seqlock to ensure thread-safe access to g_system_ticks.
Call clock_update_sched_ticks() in nxsched_process_timer() (sched_processtickless.c):
a. Syncs the scheduler tick counter with the actual timer ticks retrieved via up_timer_gettick().
With this fix, g_system_ticks is properly updated in tickless mode,
and clock_gettime(CLOCK_MONOTONIC) returns the correct non-zero monotonic time.
Signed-off-by: chao an anchao.archer@bytedance.com
Impact
sched/tickless
Testing
sim/nsh:
enable config:
+CONFIG_SCHED_TICKLESS=y
+CONFIG_SYSLOG_TIMESTAMP=y
print syslog in exmaple hello:
Before this patch:
after this patch: