Skip to content

{bp-18486} sched/tickless: Fix CLOCK_MONOTONIC always 0 by updating sched ticks#18617

Merged
xiaoxiang781216 merged 1 commit into
apache:releases/12.13from
jerpelea:bp-18486
Mar 27, 2026
Merged

{bp-18486} sched/tickless: Fix CLOCK_MONOTONIC always 0 by updating sched ticks#18617
xiaoxiang781216 merged 1 commit into
apache:releases/12.13from
jerpelea:bp-18486

Conversation

@jerpelea
Copy link
Copy Markdown
Contributor

Summary

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.

Impact

RELEASE

Testing

CI

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>
@github-actions github-actions Bot added Area: OS Components OS Components issues Size: M The size of the change in this PR is medium labels Mar 27, 2026
@xiaoxiang781216 xiaoxiang781216 merged commit bd69071 into apache:releases/12.13 Mar 27, 2026
3 checks passed
@jerpelea jerpelea deleted the bp-18486 branch May 20, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants