-
Notifications
You must be signed in to change notification settings - Fork 8.2k
lib: posix: clock: Prevent early overflows #41814
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
Algorithm was converting uptime to nanoseconds which can easily lead to overflows. Changed algorithm to use milliseconds and nanoseconds for remainder only. Signed-off-by: Krzysztof Chruscinski <[email protected]>
|
As an example: if we have sys clock frequency 32768Hz (nordic case) then uptime ticks converted to nanoseconds will overflow after 156 days. |
@nordic-krch The overflow after 156 would happen only in case of the "fast" algorithm, correct? (Z_TMCVT_USE_FAST_ALGO) |
|
@carlescufi @nordic-krch Shouldn't then the same change be applied to clock_settime? |
|
Next time, we should try to include a test or two in the PR. I'll put one together now. |
You are right. Setting clock has the same weakness. I'm a bit overloaded now so won't be able to provide it. |
No problem, apparently @cfriedt stepped up to do that. @cfriedt May be, it will be of use to you: As for the test, I used back-and-forth conversion, e.g.: It was breaking before introduction of precision formula in #41602 However, using this precision formula introduced some problems with semaphores with timeouts on our NRF91, |
|
@AndreyDodonov-EH - you could always submit a PR. I was actually more concerned with having tests for the changes that have gone in. |
Algorithm was converting uptime to nanoseconds which can easily
lead to overflows. Changed algorithm to use milliseconds and
nanoseconds for remainder only.
Issue is related to #41111 where it has been seen that it can easily overflow due to limitations of conversion algorithm. Even with algorithm fixed in #41602 (with the cost of performance degradation) there were chances that it will overflow.
Signed-off-by: Krzysztof Chruscinski [email protected]