-
Notifications
You must be signed in to change notification settings - Fork 102
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
reconsider use of CLOCK_MONOTONIC_RAW #43
Comments
From my understanding of the clocks, CLOCK_MONOTONIC start from some unspecified time, and is always monotonic (i.e. never goes backwards). However, it can be slewed based on adjtime() (basically NTP). CLOCK_MONOTONIC_RAW is the same, except it will never be slewed. The question we have to answer is what we want rcutils_steady_time_now() to represent. If we want it to represent "system time", plus or minus an offset, then we should use CLOCK_MONOTONIC. If we want it to always march forward at the same rate, we should use CLOCK_MONOTONIC_RAW. This article also has a decent explanation. |
Hmm, it would be interesting to see what I will guess that Window's is more like monotonic raw as we have it implemented since it uses the performance ticks to calculate it (I think). It would be great if someone could summarize what the similar functions out there do for "steady". |
OK, here's a summary of what is going on (as far as I can tell): rcutils_steady_time_now():
std::chrono:
There is one other thing to consider, which is time spent during suspend. For instance, on Linux, CLOCK_MONOTONIC does not "tick" during suspend (https://stackoverflow.com/questions/6360210/androidlinux-uptime-using-clock-monotonic), but I believe on Windows, QueryPerformanceCounter does (https://stackoverflow.com/questions/24330496/how-do-i-create-monotonic-clock-on-windows-which-doesnt-tick-during-suspend). Again, MacOS documentation is lacking, so it is hard to tell, but it seems like mach_absolute_time() does not "tick" during suspend. (I just found this PEP, which lays all of this out nicely: https://www.python.org/dev/peps/pep-0418/#monotonic-clocks) So, with all of the background above, it is worth looking into the expectations of the current users of rcutils_steady_time_now().
So, given all the above, here are my conclusions/recommendations:
This is really long, so I'll quit there. Thoughts? |
Sounds good to me, though it's a shame that Window's behavior and Linux's behavior might differ. Also I think it is a bit academic because we're unlikely to have many timers which run long enough to be significantly affected by the slewing or not slewing, e.g. a slew of a few microseconds is unlikely to affect a timer for many seconds or even minutes. |
@clalancette have all the action items of this issue been addressed ? if so should we close this ? |
No, because we're still using monotonic raw in our linux implementation. Also, we've not updated our macOS code to look like |
Thanks for the summary 👍 |
Hi, any updates on this? |
It's not something I've had time to work on. Though I would definitely be willing to do a review if someone else can fix the Linux and macOS implementations. |
This is a duplicate of ros2/rcl#110, and originally came from a discussion at ros/roscpp_core#55 (comment)
The text was updated successfully, but these errors were encountered: