xtimer: Refactor xtimer_usleep_until and rename to xtimer_periodic_wakeup#5612
xtimer: Refactor xtimer_usleep_until and rename to xtimer_periodic_wakeup#5612kYc0o merged 3 commits intoRIOT-OS:masterfrom
Conversation
| */ | ||
| uint32_t offset = target - now; | ||
|
|
||
| if (offset > (XTIMER_BACKOFF * 2)) { |
There was a problem hiding this comment.
The * 2 was never explained in the original implementation. This may need some tweaking of the board configurations.
There was a problem hiding this comment.
Well, the numbers might have seemed arbitrary, but the logic did serve a purpose: use a relative offset for very small offsets. Seems to me you've dropped that safety net?
There was a problem hiding this comment.
The comment regarding relative offsets never underflowing is not necessarily true, since all timer set calls inside xtimer_core use timer_set_absolute to set the target time.
There was a problem hiding this comment.
Ah, you're right. In my tests it was a lot safer, though.
I hope to fix this completely with #5428.
There was a problem hiding this comment.
I'm a little reluctant to just drop the extra safety, because I did do quite some experimenting to get this stable (non-underflowing). But I'm ok with the other changes.
Would you mind splitting this out of this PR?
There was a problem hiding this comment.
Yes, I'll prepare a PR which keeps the three decisions but introduces a configurable value instead of hard-coding 512 and BACKOFF*2.
|
The biggest functional change here is the removal of the "set relative target time" outcome for offsets in the interval |
|
Code looks OK, I'll test on a pba-d-01-kw2x and give feedback, but I'd like @kaspar030 to look into this big changes. |
|
in tests/saul: I tested most of the changes so far and this is the only problem I have. |
2bd1d0c to
ae6e35a
Compare
|
oops, copy pasta! |
|
Great! Let's Murdock take a look ;) |
| if (!((target < *last_wakeup) && (target > now))) { | ||
| if (now < (*last_wakeup)) { | ||
| /* base timer overflowed between last_wakeup and now */ | ||
| if (!((now < target) && (target < (*last_wakeup)))) { |
There was a problem hiding this comment.
(now < target) is not equivalent to (target > now).
There was a problem hiding this comment.
I don't understand? In C, a < b is equivalent to b > a AFAIK
There was a problem hiding this comment.
Sorry, of course. I'll get coffee.
There was a problem hiding this comment.
The reason I reversed the order of the comparisons was to make it easier to read.
Mathematically, the inner part of the expression is: now < target < last_wakeup
|
As for the risk of underflows, I propose the following:
|
|
Reintroduce the three different outcomes (spin, relative, absolute), but
introduce two new macros for the cutoffs.
ok!
How about |XTIMER_PERIODIC_SPIN|, |XTIMER_PERIODIC_RELATIVE| for the names?
ok!
|XTIMER_PERIODIC_SPIN| would default to |XTIMER_BACKOFF| since that's
what's used in the timer scheduling code for deciding between spinning
or set a new timer target.
Let's not change the semantics in this PR but keep it as cleanup / API
change. Changing the actual values is easy. And really, these magic
values increased stability a lot. ;)
|XTIMER_PERIODIC_RELATIVE| default needs to be experimented with,
measuring the |xtimer_now| value at the point of the call to
|_xtimer_set_absolute| and comparing to |now| should give an indication
of how long the code in |xtimer_periodic_wakeup| takes to execute.
Well, XTIMER_PERIODIC_RELATIVE needs to be higher, as the code is run
with interrupts enabled.
|
|
Actually, what happens if an interrupt fires in the middle of One solution would of course be to only use 64 bit times, but I'm not a fan of using 64 bit numbers throughout on these constrained platforms.. |
|
Introduced the discussed changes |
In #5428 I went that route. It doesn't look too bad [1]. [1] https://github.com/RIOT-OS/RIOT/pull/5428/files#diff-7412db2749b270423cfd5430e69744b9R61 |
|
@kaspar030 you're right, it doesn't look too bad. |
|
Fixed the mistake in time has already passed check |
|
OK to squash? |
|
(should be able to merge before deadline for release 2016.07) |
|
@kaspar030 can you give a last advice before squashing? |
|
So will we postpone this for the next release? |
|
@gebart do you think this PR should be in this release? |
|
I'd like it in as soon as possible, but I think it's more of an enhancement (and clean up) than a bugfix. The only thing that has been missing from this PR is a final review and an ACK. |
|
ACK for the change, if the existing code still works, I think we can merge. -----Original Message----- I'd like it in as soon as possible, but I think it's more of an enhancement than a bugfix. The only thing that has been missing from this PR is a review and an ACK. You are receiving this because you were mentioned. |
|
@gebart can you squash please? |
40fa8e2 to
e777d2f
Compare
|
squashed |
|
should I squash more? |
|
I think is enough. Let's wait for murdock and merge afterwards. |
|
Murdock failed on the doc for |
|
Fixed all Doxygen warnings in xtimer.h except: I think that macro might be going away in a refactoring in next release and it's only used internally in xtimer, I don't think we need to fix that documentation right now. |
|
OK to squash? |
|
OK agree on my side and OK to squash. |
5d96001 to
c0ad83c
Compare
…keup Rewrote conditions for improved readability, and removed magic number 512
|
Squashed doxygen fixes. Ready |
|
Excellent! Murdock green and already ACKED so go! |
This is a clean up of the function
xtimer_usleep_until, which has been renamedxtimer_periodic_wakeupto better reflect the actual purpose of the function.There were some unexplained uses of magic numbers and the function was unnecessarily difficult to understand. The magic numbers have been removed and the conditionals have been refactored to make them easier to read.