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

Improve and debug Xtimer #10393

Closed
wants to merge 7 commits into from
Closed

Conversation

Josar
Copy link
Contributor

@Josar Josar commented Nov 15, 2018

This PR is a stack of commits which depends upon each other and are a rework of some things done in #8990.

  1. Tries to handle the same problem as xtimer: Skip ahead when target time has already passed #7629 and xtimer: periodic race #9595 .

  2. _timer_callback changed to only check once for an overflow. Avoiding early firing of xtimer when _next_period is called 2 times. Encountered when testing with xtimer_drift.

  3. xtimer_hang test schould use xtimer_periodic_wakeup instead of sleep. This will ensure that all percentage values are printed.

  4. Using multiple pins to distinguish the threads.

  5. Ensure that worker_thread is higher prior than slacker_thread.

  6. _time_left was not able to calculate the time left for a target which is at the beginning of the next period, but has to be fired in this period because of XTIMER_OVERHEAD.

  7. Xtimer where fired to early when running xtimer_drift. Which was caused by a overflowing llcounter. As the reference was set to now. The function _time_left calculated the wrong time to wait.

See the commit messages for more details.

Following Test run with good results on the jiminy rfr2

xtimer_usleep_short
xtimer_usleep
xtimer_reset
xtimer_remove
xtimer_periodic_wakeup
xtimer_msg_receive_timeout
xtimer_hang
xtimer_drift

rearange test for overflowed base timer.
Previous implementation fired some xtimers one low level timer period too early.
Most probably caused by a double check for overflowed llcounter and calling _next_period():

The issue could be observed on a platform with 16 bit and 125000 Hz xtimer.
So when printing the test sequence every second, the set 1 second timeout
required to have 2 low level counter overflows.

With this changes there is still a drift running xtimer_drift.
But it is not a whole low level counter period.
When sleeping in the main function with xtimer_sleep not every percentage
will be printed as the sleep duration and the processing time added do
not result in full percentage values.

Using xtimer_periodic_wakeup ensures that every integer percentage is printed.
Previously one pin was used for both slacker threads.
For better debugging seperating the threads to use one pin each is better.
When the slacker threads and the worker thread have the same priority
the drift and jitter depend on the workload.
Timer set before the worker thread will be fired before the worker and so
the result is not the timings the system might reach when proper priority
is set. Increasing the priority of the worker thread ensures that the
measureed timings are the achievable timings.
This commit ensures that the _time_left function is able to detect an
overflown llcounter and a target which is in the next period and to
return the correct difference.
When the reference is set to `_xtimer_lltimer_now()` a interrupt at
the verge of the llcounter overflow could lead to early shooting of the xtimer.

Using the target as reference which will be compared to now in `_time_left`
calculates the right time which is left before shooting.
@Josar Josar changed the title Pr/improve xtimer 2 Improve and debug Xtimer Nov 15, 2018
@Josar
Copy link
Contributor Author

Josar commented Nov 15, 2018

@cladmi maybe we can use your mock to show some of this issues.

@miri64 miri64 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: timers Area: timer subsystems labels Nov 19, 2018
@cladmi
Copy link
Contributor

cladmi commented Nov 27, 2018

As I am really not focused on timer, it is hard for me to concentrate on PRs changing many things as it takes a lot of time to review.

It would simplify my task if you could split small parts, still keep the main PR as a reference, but focus on one small part to fix first. The lower level it is, the better as it solves the ground problems first so we can build on top.

@Josar
Copy link
Contributor Author

Josar commented Dec 18, 2018

@cladmi i split out the test and debug related commits to distinct PRs with the intention to take care of the crucial timer related problems after they have been merged. see: #9595 #10173

@Josar
Copy link
Contributor Author

Josar commented Jan 30, 2019

@haukepetersen as posted above, there is still a lot to get into master until we can target the issues the xtimer has and which get observeable on 16bit platforms. Maybe someone will have time to dig into.

ben-postman pushed a commit to ben-postman/RIOT that referenced this pull request May 30, 2019
Once RIOT-OS issue RIOT-OS#10393 (or potentially another, there are many open xtimer
issues), that solution ought to be used instead. The problem is that if the
hardware timer overflows immediately after (or at the same time as) a timer
expires, that the reference time gets set in the wrong period. There appear to
be many issues with xtimer and overflow, however, so a more holistic solution
ought to be applied when one becomes available.
@stale
Copy link

stale bot commented Sep 19, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Sep 19, 2019
@stale stale bot closed this Oct 20, 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 State: stale State: The issue / PR has no activity for >185 days Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants