[Bug] Use CLOCK_MONOTONIC
where available instead of CLOCK_REALTIME
#270
Labels
bug
Something isn't working
CLOCK_MONOTONIC
where available instead of CLOCK_REALTIME
#270
Describe the bug
The PR #269 brought my attention to the fact that
z_clock_now()
usesclock_gettime(CLOCK_REALTIME...)
on most posix-like platforms. But POSIX specifies thatCLOCK_MONOTONIC
is the only one appropriate for usage as a relative timing reference, because it will never go backwards as a result of callingclock_settime()
. In practice, this is definitely true on Linux systems, and is also true in the Zephyr implementation. The esp-idf implementation looks like it has the same properties.So in practice, relative timing (the most common usage of time in embedded systems at the library / protocol level) should only ever use
CLOCK_MONOTONIC
, andCLOCK_REALTIME
should only ever be used when the use case is actually user-level wall-clock time.To reproduce
Sorry, but I haven't tried this out in actual practice... but it's pretty widely-known best practices for embedded posix-like systems.
clock_settime()
, in simulation of an NTP update, etc.System info
Any posix-like system using
CLOCK_REALTIME
.The text was updated successfully, but these errors were encountered: