Skip to content
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

xtimer: Fix backoff condition in _xtimer_set_absolute #7628

Closed

Conversation

jnohlgard
Copy link
Member

When the target is inside the next long_period, the previous condition
was incorrect. The new condition should give the same result regardless
of whether there is a long_period tick coming soon or not.

When the target is inside the next long_period, the previous condition
was incorrect. The new condition should give the same result regardless
of whether there is a long_period tick coming soon or not.
@jnohlgard jnohlgard added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: timers Area: timer subsystems labels Sep 20, 2017
@jnohlgard jnohlgard added this to the Release 2017.10 milestone Sep 20, 2017
if ((target >= now) && ((target - XTIMER_BACKOFF) < now)) {
/* The (target - now) difference works across the long tick rollover, there
* is no need to check for (target > now) first. */
if ((target - now) < XTIMER_BACKOFF) {
/* backoff */
xtimer_spin_until(target + XTIMER_BACKOFF);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side question, which bothered me for some time: why add XTIMER_BACKOFF here (again?). Assuming XTIMER_BACKOFF is 50us (default for many boards), and I use something like xtimer_usleep(40) the result is that my apps actually sleep 90us right? Though its more likely that the target time of 40us ahead has already (or nearly) passed by the time this call gets here, anyway, but still this seems wrong to do here, or not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for adding a backoff here is that there is a non-zero amount of time that has passed between the _xtimer_now call and the xtimer_spin_until call, so there is a risk that target is already in the past, which will make the system spin for a full lltimer cycle instead of just returning. This is not an ideal solution though, but I don't have any better ideas at the moment.

@jnohlgard jnohlgard added the Discussion: contested The item of discussion was contested label Sep 24, 2017
@jnohlgard
Copy link
Member Author

This change removes a safeguard against setting timers in the past (the now < target check), but it should be mitigated by #7630

@smlng
Copy link
Member

smlng commented Jan 16, 2019

superseded by #9211, hence closing

@smlng smlng closed this Jan 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: timers Area: timer subsystems CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Discussion: contested The item of discussion was contested Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants