cpu/native: fix bug in periph_timer#20009
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 |
benpicco
left a comment
There was a problem hiding this comment.
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_timerinnativeis broken and issues early IRQs. This replaces the use ofsetitimerthat 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)