-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cpu/native: fix bug in periph_timer #20009
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
Could this be because we use ITIMER_REAL as clock source, which is affected by adjtime(2) and settimeofday(2)? |
Should this be backported? Probably not a bad idea. |
fd90d58
to
96eef23
Compare
eabef72
to
fd1fd2c
Compare
Yes, indeed! This was actually also my first intuition. But rather than reading the code I did a quick grep for |
Hm I still get
with this (and the patches from #18977) applied |
Maybe the fact that timer_start()/timer_stop() do not stop the value returned by timer_read() from incrementing could also be the reason for this. |
@benpicco: That's expected. Most of the time that bug triggered it was not due to the |
Urgh so are you suggesting there is (at least) a third bug (besides this one and #18977) at play here that makes timeouts unreliable 😩 Please squash btw |
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'm trusting our timer unittests
Yes :) But on the other hand 2/3 of the issue is hopefully solved. (Well, the third bug is the one with the most fallout, though). |
5b2d9b2
to
f9f0c27
Compare
Do we think this can get in the next little while or should we make it a known issue for this release? |
Murdock found quite the bug. I really should give more priority my rewrite of the |
Also use `CLOCK_MONOTONIC` for the timeouts, not just for `timer_read()`. This fixes mismatches between when a timeout occurs and what is expected in the context of the values returned by `timer_read()`.
f9f0c27
to
50b841e
Compare
bors merge |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
A brief note from a workshop, this broke building on Debian 11. |
This fixes RIOT-OS#20009 (comment) (cherry picked from commit 29a00be)
Contribution description
While debugging #18977 (comment) it became obvious that the
periph_timer
innative
is broken and issues early IRQs. This replaces the use ofsetitimer
that cannot use a monotonic clock source withtimer_settime()
.Testing procedure
I have some non-publishable code that tests if the time an ISR fires in terms of
timer_read()
is no earlier than the time expected. This occasionally triggered withmaster
, but I didn't see any of these issues anymore with this PR. I guess I should revive my PR to spice up the periph timer tests and add a polished version of this and let this run for an hour or two.The tests ins
tests/periph/timer*
should still succeed onnative
. (They do for me in a container runningriot/riotbuild
).Issues/PRs references
Found while debugging #18977 (comment)