-
Notifications
You must be signed in to change notification settings - Fork 7.4k
kernel: Do not use sys_clock_ticks_per_sec in _ms_to_ticks() #9073
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
kernel: Do not use sys_clock_ticks_per_sec in _ms_to_ticks() #9073
Conversation
823649f
to
c0e9d4b
Compare
Codecov Report
@@ Coverage Diff @@
## master #9073 +/- ##
==========================================
+ Coverage 52.35% 52.94% +0.58%
==========================================
Files 201 201
Lines 25290 25303 +13
Branches 5286 5288 +2
==========================================
+ Hits 13240 13396 +156
+ Misses 9965 9786 -179
- Partials 2085 2121 +36
Continue to review full report at Codecov.
|
@andrewboie, @andyross: Some advice needed. This PR introduces a correct a round up in _ms_to_ticks(), which fixes a shorter than expected sleep time when sleep over several ticks was requested. However this round-up introduced another errors which are visible here: https://app.shippable.com/github/zephyrproject-rtos/zephyr/runs/19362/5/tests The tests fail because
What do you think? |
Not having looked at the code: my preference would be to fix the test. Hyper-tight tolerances on timer behavior is always going to cause problems. The relevant standards (this is a POSIX test) don't general promise that anyway. |
@andyross: I have one more question: At the moment the _ms_to_ticks() rounds up, while __ticks_to_ms() rounds down. As result, the |
I don't. And I'd be terrified to change it lest we break something subtle that relies on positive-definite timer intervals or something. Really the whole low level timer subsystem needs rework. I'm looking at it right not just in the context of spinlockification and realizing there's a bunch of odd cruft in there. |
What I noted while working on #8896, is that we are often changing units. It works perfectly as long as there is no rounding during this conversion (or rounding is in the same direction, but this just hides the problem). IMHO a lot of issues popping up on nRF5x platform are related to loss of accuracy during these conversions. Are there any plans to remove ticks from the Zephyr and leave tickess as only supported mode? |
The _update_time_slice_before_swap() function directly compared _time_slice_duration (expressed in ms) with value returned by _get_remaining_program_time() which used ticks as a time unit. Moreover, the _time_slice_duration was also used as an argument for _set_time(), which expects time expressed in ticks. This commit ensures that the same unit (ticks) is used in comparsion and timer adjustments. Signed-off-by: Piotr Zięcik <[email protected]>
The time slicing settings was kept in milliseconds while all related operations was based on ticks. Continuous back and forth conversion between ticks and milliseconds introduced an accumulating error due to rounding in _ms_to_ticks() and __ticks_to_ms(). As result configured time slice duration was not achieved. This commit removes excessive ticks <-> ms conversion by using ticks as time unit for all operations related to time slicing. Also, it fixes zephyrproject-rtos#8896 as well as zephyrproject-rtos#8897. Signed-off-by: Piotr Zięcik <[email protected]>
c0e9d4b
to
1132fd5
Compare
1132fd5
to
249fd21
Compare
The value of sys_clock_ticks_per_sec is obtained using simple integer division with rounding toward zero. As result using this variable in _ms_to_ticks() introduces some error. This commit eliminates sys_clock_ticks_per_sec from equation used in _ms_to_ticks() removing introduced error. Also, this commit fixes zephyrproject-rtos#8895. Signed-off-by: Piotr Zięcik <[email protected]>
This commit replaces exact time compassion by a range check, allowing the tests to pass on platforms which needs rounding in __ticks_to_ms() and _ms_to_ticks(). Signed-off-by: Piotr Zięcik <[email protected]>
178bf48
to
262daf1
Compare
@pizi-nordic I am just wondering; does this PR overlap with #9137 ? |
hmm, something went wrong, I forgot it was on top of other patches that were already merged, now commits appear twice! |
The value of sys_clock_ticks_per_sec is obtained using
simple integer division with rounding toward zero. As result
using this variable in _ms_to_ticks() introduces some error.
This PR eliminates sys_clock_ticks_per_sec from equation
used in _ms_to_ticks() removing introduced error.
Also, this PR fixes #8895.
Please note, that this PR is based on top of #9137.