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
unix/mphal: use CLOCK_MONOTONIC for ticks_ms/us #4715
Conversation
While gettimeofday() isn't guaranteed to be increasing, clock_gettime() isn't guaranteed to exist at all. |
Is there an alternative? gettimeofday() coupled with NTP on a system can cause random unintended sideffects for code that assumes ticks_ms() is always increasing. |
What specific issue are you facing?
Unix port of MicroPython is intended to support as wide selection of Unix-like OSes as possible. E.g. that XENIX or AIX versions of 1985 or something. |
In our application, we use |
Thanks, So:
The alternative is to select gettimeofday() vs clock_gettime() via #ifdef. |
How should that #ifdef look like? |
It should allow to use either gettimeofday() of clock_gettime() for implementation of those functions. |
It might work to use the following to select the implementation (untested): #if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK)
// use clock_gettime
#else
// use gettimeofday
#endif |
@mzakharocsc I'm happy to make the #if changes and merge if you aren't able to. |
ba960b5
to
115d3b1
Compare
Updated with #ifdefs |
Thanks for updating the PR. Merged in ced340d |
Using gettimeofday for ticks_ms/us is not guaranteed to be increasing, which is contrary to the documentation. Using CLOCK_MONOTONIC fixes this.