raiden00pl commented on code in PR #17199:
URL: https://github.com/apache/nuttx/pull/17199#discussion_r3806567534
##########
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());
Review Comment:
@wangchdo @anchao @xiaoxiang781216 are you sure this is correct?
This change breaks `clock_gettime(CLOCK_MONOTONIC)` on `SCHED_TICKLESS`:
`g_system_ticks` is only updated when a timer expiration is processed, so with
no timeout armed the clock does not advance at all.
I found this issue when I was playing with python on intel64, the same can
be reproduced on rv-virt:
```python
>>> import time
>>> time.clock_gettime(time.CLOCK_MONOTONIC) # ~44 s after boot, idle
0.0 # broken: no expiration yet (when
fixed: 43.999)
>>> time.clock_gettime(time.CLOCK_MONOTONIC) # 15 s later, still idle
0.0 # broken: still frozen (when
fixed: 58.984)
>>> time.sleep(2) # first timer expiration
>>> time.clock_gettime(time.CLOCK_MONOTONIC) # 64 s after boot
64.0 # broken: snapped to uptime, freezes again
(when fixed: 63.991)
>>> t = time.monotonic(); time.sleep(0.2); time.monotonic() - t
9.2 # broken: time since previous expiration
(when fixed: 0.205)
```
CLOCK_MONOTONIC needs a live read — restoring `clock_systime_timespec(tp)`
here fixes it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]