-
Notifications
You must be signed in to change notification settings - Fork 2.1k
tests/xtimer_usleep: fail with negative offsets #11493
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
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.
The issue is is not the test, the test is correct.
When we say sleep 10us it should sleep at least 10s10us.
There is an issue in sys/include/xtimer/tick_conversion.h where for some configuration if you say, give me the number of ticks for 1s it returns less than enough ticks for 1s so sleeps 0.9something which is wrong.
|
Aha!, thanks for the clarification @cladmi. When you say there is an issue with I'll close this PR after pointing or opening an issue (if there isn't one already). |
More like "as close to 10us as possible". 9.99us is more accurate than 10.02. |
@cladmi @kaspar030 So what is actually the expected behavior: This in not clear from the documentation., which ever the case I think we should make it more explicit. |
So in a timesloted networking protocol if I say: I may just send in the previous timeslot everytime. I do not feel it more accurate to send a message before I am allowed to. That MUST be documented in the API and tell how to proceed if one wants to be sure that he can do: From the timer libraries I remember, they were all more ensuring it is done at least after/waits longer than the time specified. Like |
I think we need to keep the timescales in context. I'd expect my timer subsystem to quantize any real time interval to the to the closest hardware timer tick instead of always rounding up. That would make it at most +/- half a tick wrong, being spot on on average. Always rounding up would mean it is between 0 and a whole tick late (half a tick on average). Your argumentation for a timeslot would shift the problem to the end of the timeslot (always rounding up might make the protocol exceed its timeslot every time). In practice, we're talking +- 0-15us vs +0-30us for a 32kHz timer quantized to 1000000us. The better option here is to either work with the low-level ticks or chose a faster timer. Or chose one that corrects in software via spinning, but that is inefficient. I think we agree that the timer peripheral itself must not sleep too little. Is that the issue here? |
What is too little? Is -15us too little? |
|
Returning before, whatever the amount is, is not what I would expect as a user and it is not what the API says. If my resolution is 30us, I know I cannot get better precision than a few multiple of 30us. Also I should take into account all the delays to know what I should have in the worst case and I must deal with the worst case as it can happen. If my precision is lower that what I need, I am screwed. The usage currently assumes there is a way to have a timer after an expired time.
And here it also happened after 30us So here code using And for the precision, you can only assume the guarantee that can happen in the worst case. If one high priority thread can do small sleeps, a lower priority thread should already assume it can be descheduled for With timing, I would only consider the worst case. |
|
Murdock hangs on this PR for over 8 hours so I requeued it. |
|
Just to chime in, I think the time should wait at least the time specified (both for sleep functions and for timer periph functions). A case is if you expect something to be triggered after your sleep but you wake up too early you take the value of a previous event. If everyone agrees on that then we probably shouldn't merge the test change or, if everyone disagrees (at least on the sleep perspective), we should update the docs to say this is the behaviour of sleep as my assumption for sleep is at least not about... Maybe update the docs either way... |
This illustrates why trying to hit the point as precisely as possible (maybe ahead of time) doesn't really gain anything.
This would only be true if there were no delays introduced such as with the above effect of (de)scheduling. As "spot on" can not be guaranteed anyway I'd also vote for "wait at least for the provided duration". |
Ok, you guys have convinced me. +1 for never sleeping too little, as in, |
f2e6661 to
b124a02
Compare
|
Ok so we have an agreement over the expected behaviour for Nonetheless since the expect REGEX is not capturing negative values it is failing whatever negative value it is getting but not in the right way. I have changed the test so the lower bound is equal to TARGET_TIME and the upper bound keeps the 5% margin. The result is having the test fail as: Instead of: @cladmi @kaspar030 Does this change make sense? |
|
I am running the test on many boards right now. I would like to have the explanation that the time for Otherwise I agree with the change. |
|
I ran the test successfully on:
And it failed as expected on |
Only need to update commit message, otherwise I agree.
- xtimer_usleep(timeout) should sleep for at least timeout us. Negative offset, i.e. sleeping less than the specified time is incorrect.
b124a02 to
a687a26
Compare
@cladmi not sure what you mean by not beeing in the past, in xtimer_usleep(timeout) timeout is always in the future. I did add more detail in the commit stating that sleeping less that the specified time is incorrect behavior. |
|
Sorry, I meant in the past from the expected end time, your comment said it correctly. |
cladmi
left a comment
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.
ACK, review and tested. It now fails with an appropriate message on the frdm-kw41w.
Contribution description
This PR modifies xtimer_usleep automated test to recognize negative offset with respect to target sleep time.
When reviewing #11044 I realized tests/xtimer_usleep
wasn't passing because the python script was not recognizing negative integers as acceptable values for the timer offset, this is done now.was failing because of a pexpect timeout and not because of negative offsets (sleeping less than the specified time).Testing procedure
With frdm-kw41z or usb-kw41z (or any board witch would produce negative offset with respect to the target usleep time)
→ make -C tests/xtimer_usleep BOARD=usb-kw41z flash testFailed without this PR, succeeds with it.Failes correctly with this PRIssues/PRs references