sched/clock: Improve clock implementation with sched ticks functions

Replace direct usage of g_system_ticks with clock_increase_sched_ticks()
   and clock_get_sched_ticks()

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
This commit is contained in:
wangchengdong
2025-10-13 20:44:30 +08:00
committed by Xiang Xiao
parent 54adf5979c
commit 1a22f4bf28
3 changed files with 3 additions and 31 deletions

View File

@@ -376,11 +376,7 @@ void clock_resynchronize(FAR struct timespec *rtc_diff)
clock_t diff_ticks = SEC2TICK(rtc_diff->tv_sec) +
NSEC2TICK(rtc_diff->tv_nsec);
#ifdef CONFIG_SYSTEM_TIME64
atomic64_fetch_add((FAR atomic64_t *)&g_system_ticks, diff_ticks);
#else
atomic_fetch_add((FAR atomic_t *)&g_system_ticks, diff_ticks);
#endif
clock_increase_sched_ticks(diff_ticks);
}
}
#endif

View File

@@ -88,31 +88,7 @@ clock_t clock_systime_ticks(void)
up_timer_gettick(&ticks);
return ticks;
#elif defined(CONFIG_SYSTEM_TIME64)
clock_t sample;
clock_t verify;
/* 64-bit accesses are not atomic on most architectures. The following
* loop samples the 64-bit timer twice and loops in the rare event that
* there was 32-bit rollover between samples.
*
* If there is no 32-bit rollover, then:
*
* - The MS 32-bits of each sample will be the same, and
* - The LS 32-bits of the second sample will be greater than or equal
* to the LS 32-bits for the first sample.
*/
do
{
verify = g_system_ticks;
sample = g_system_ticks;
}
while ((sample & TIMER_MASK32) < (verify & TIMER_MASK32) ||
(sample & ~TIMER_MASK32) != (verify & ~TIMER_MASK32));
return sample;
#else
return g_system_ticks;
return clock_get_sched_ticks();
#endif
}

View File

@@ -81,6 +81,6 @@ void clock_systime_timespec(FAR struct timespec *ts)
defined(CONFIG_SCHED_TICKLESS)
up_timer_gettime(ts);
#else
clock_ticks2time(ts, g_system_ticks);
clock_ticks2time(ts, clock_get_sched_ticks());
#endif
}