nuttx/sched/clock
chao an d8b4d53444 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.

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>
2026-03-03 11:01:02 -05:00
..
clock.c
clock.h
clock_adjtime.c
clock_delay.c
clock_getres.c
clock_gettime.c
clock_initialize.c
clock_notifier.c
clock_perf.c
clock_realtime2absticks.c
clock_sched_ticks.c
clock_settime.c
clock_systime_ticks.c
clock_systime_timespec.c
clock_timekeeping.c
clock_timekeeping.h
CMakeLists.txt
Make.defs