This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 612f9a07dd9 sched/clock: fix stale CLOCK_MONOTONIC on SCHED_TICKLESS
612f9a07dd9 is described below
commit 612f9a07dd9f2c9be7e32971a7b6c268701d78d3
Author: raiden00pl <[email protected]>
AuthorDate: Tue Aug 18 15:05:40 2026 +0200
sched/clock: fix stale CLOCK_MONOTONIC on SCHED_TICKLESS
clock_gettime(CLOCK_MONOTONIC) reads g_system_ticks, which is only
refreshed when a timer expiration is processed. On SCHED_TICKLESS an
idle system has no timeout armed, so the clock returns 0 before the
first expiration and a frozen value afterwards.
This regressed in commit c7b6442974, which switched CLOCK_MONOTONIC to
the sched tick counter to exclude suspended time. Excluding suspend time
needs explicit accounting maintained by PM code, the tick counter cannot
provide it on tickless.
Restore the live read. On non-tickless builds clock_systime_timespec()
falls back to the same tick counter, so behavior there is unchanged.
Verified on qemu-intel64, nrf52840-dk and rv-virt.
Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
---
sched/clock/clock_gettime.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/sched/clock/clock_gettime.c b/sched/clock/clock_gettime.c
index b2897cb1c2d..29047b7d68c 100644
--- a/sched/clock/clock_gettime.c
+++ b/sched/clock/clock_gettime.c
@@ -97,18 +97,11 @@ int nxclock_gettime(clockid_t clock_id, FAR struct timespec
*tp)
return -EINVAL;
}
- if (clock_id == CLOCK_MONOTONIC)
+ if (clock_id == CLOCK_MONOTONIC || clock_id == CLOCK_BOOTTIME)
{
- /* The the time elapsed since the timer was initialized at power on
- * 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..
+ /* The time elapsed since the timer was initialized at power on
+ * reset. Must be a live read: the sched tick counter is frozen
+ * while no timeout is armed on SCHED_TICKLESS.
*/
clock_systime_timespec(tp);