From c7b6442974545b92476615ef048633609d828e5b Mon Sep 17 00:00:00 2001 From: wangchengdong Date: Mon, 13 Oct 2025 20:57:43 +0800 Subject: [PATCH] sched/clock: Improve CLOCK_MONOTONIC nxclock_gettime() Improve nxclock_gettime(), to get the system time excluding the time that the system is suspended, when the clockid is CLOCK_MONOTONIC Signed-off-by: Chengdong Wang wangchengdong@lixiang.com --- sched/clock/clock_gettime.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sched/clock/clock_gettime.c b/sched/clock/clock_gettime.c index ebebef61a49..89ebde17665 100644 --- a/sched/clock/clock_gettime.c +++ b/sched/clock/clock_gettime.c @@ -88,10 +88,18 @@ static clock_t clock_process_runtime(FAR struct tcb_s *tcb) void nxclock_gettime(clockid_t clock_id, FAR struct timespec *tp) { - if (clock_id == CLOCK_MONOTONIC || clock_id == CLOCK_BOOTTIME) + if (clock_id == CLOCK_MONOTONIC) { /* The the time elapsed since the timer was initialized at power on - * reset. + * reset, excluding the time that the system is suspended. + */ + + clock_ticks2time(tp, clock_get_sched_ticks()); + } + else if (clock_id == CLOCK_BOOTTIME) + { + /* The the time elapsed since the timer was initialized at power on + * reset, including the time that the system is suspended.. */ clock_systime_timespec(tp);