-
Notifications
You must be signed in to change notification settings - Fork 7.4k
API to correlate system time with external time sources #28977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cf4b874
to
58a5323
Compare
Some notes on the design, with a few questions that should be answered before it's ready to merge:
What is this?There's already a It then adds API under The API does not automatically do time maintenance. Something has to invoke Why isn't this
|
58a5323
to
b86fa43
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just reviewed the documentation for now. I will try to find the time to review the rest within the next week.
doc/reference/misc/timeutil.rst
Outdated
offsets separately. | ||
|
||
The inverse transformation is not standardized: APIs like ``mktime()`` | ||
expect information about time zones. Zephyr module provides this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which zephyr module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/module//. It's from lib/os, which doesn't have a module name.
I'll clean this up in the next push.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
doc/reference/misc/timeutil.rst
Outdated
====================== | ||
|
||
The :option:`CONFIG_TIMEUTIL_REALTIME` flag enables API that allows | ||
zephyr to provide the current civil ("real") time that advances aligned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zephyr to provide the current civil ("real") time that advances aligned | |
zephyr to provide the current civil ("wall clock") time that advances aligned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made it both, since absent conflicting consensus "real" is the name currently used for this timescale.
lib/os/Kconfig
Outdated
config TIMEUTIL_REALTIME | ||
bool "Support conversion between local and civil time" | ||
help | ||
When true API is provided that enables applications to read | ||
the current time based on maintained offsets and skews | ||
between the local tick clock and an external time source, | ||
possibly an RTC. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the rationale behind the CONFIG_TIMEUTIL_REALTIME
naming? "Real time" may be confusing here (Zephyr is a Real-Time Operating System).
Have you considered CONFIG_TIMEUTIL_CIVIL_TIME
? Same goes for the naming of the API functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but the consensus interpretation of "civil time" is the local time, which is almost always UTC plus an offset (that generally changes twice a year).
I'm not entirely bound to that decision. Options I've considered include:
- civil time (implies a local time zone time scale)
- calendar time (implies a representation, not a time scale)
- wall clock
- timescale
- real time
none of which are wonderful. I went with REALTIME
because it's what CLOCK_REALTIME
on a POSIX system gives you, which is UTC, and I think that the most likely use of these functions will be to produce something that approximates or provides a capability similar to CLOCK_REALTIME
. So: timeutil_realtime_
.
If "realtime" is too confusing because Zephyr is a "real-time operating system" (it's not), then we can come up with a consensus alternative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is confusing because realtime term is subjective, from the designation alone, everyone could understand something different about what for example timeutil_realtime_get()
does. Maybe CONFIG_TIMEUTIL_CTS/timeutil_cts_get()
, for civil time scale (144c887#diff-ca1507f5fcb1d2e792a8c80442ab64038f0e5d9939a38e6015b1f1b5d28a8431R34) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CTS in Bluetooth is "Current Time Service", which is one of the potential sources for "real" time data. So I think that spelling would be confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is less confusing than REALTIME, at least for me :-)
5939917
to
d655c60
Compare
@pabigot Would it be feasible to drop the |
I tried that. The dynamic range due to the need to translate between different frequencies causes problems even with 64-bit integer math. There are overflows and underflows during the intermediate calculation that makes the skew estimate horribly unstable even when the clocks are stable. This ties to #29569 in that while this is proposed to be in |
d655c60
to
c417693
Compare
Provide data structures to capture a timestamp in two different clocks, monitor the drift between those clocks, and using a base instant with estimated drift convert between the clocks. This provides the core technology to convert between system uptime and an external continuous time scale like TAI (UTC without applying leap seconds). Signed-off-by: Peter A. Bigot <[email protected]>
d7dddb4
to
88a6a46
Compare
Describe the role of these APIs, key concepts that they depend on, and expose the low-level API. Signed-off-by: Peter Bigot <[email protected]>
Provide a demonstration of using the timeutil skew infrastructure to measure the relative error of the two clock sources on Nordic boards. Signed-off-by: Peter Bigot <[email protected]>
88a6a46
to
dc60797
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR has content I've been working on for about six months, to locally timestamp sensor observations with standard time rather than time-since boot.
It provides data structures to capture a timestamp in two different clocks, monitor the drift between those clocks, and using a base instant with estimated drift convert between the clocks. This provides the core technology to convert between system uptime and an external continuous time scale like TAI (UTC without applying leap seconds).
A sample is provided that demonstrates using this technology to measure local clock error between Nordic HFCLK and LFCLK.
There are some questions in the first comment that need to be resolved. There are also some follow-on commits that will be submitted separately after this seems to be going forward: