sys/ztimer: allow compensation of ztimer_sleep() overhead#14936
sys/ztimer: allow compensation of ztimer_sleep() overhead#14936fjmolinas merged 3 commits intoRIOT-OS:masterfrom
Conversation
|
btw, this is a first step towards making this automatic in ztimer's auto_init(). |
|
Some testing:
In the test I had to change : diff --git a/tests/xtimer_usleep/tests/01-run.py b/tests/xtimer_usleep/tests/01-run.py
index f629096073..8bd57295c8 100755
--- a/tests/xtimer_usleep/tests/01-run.py
+++ b/tests/xtimer_usleep/tests/01-run.py
@@ -35,7 +35,7 @@ def testfunc(child):
sleep_time = int(child.match.group(1))
exp = int(child.match.group(2))
upper_bound = exp + (exp * INTERNAL_JITTER)
- if not (exp < sleep_time < upper_bound):
+ if not (exp <= sleep_time < upper_bound):
delta = (upper_bound-exp)
error = min(upper_bound-sleep_time, sleep_time-exp)
raise InvalidTimeout("Invalid timeout %d, expected %d < timeout < %d" |
|
@kaspar030 some nitpicks otherwise it seems to work as advertised, one comment though regarding the |
yes there is. it should be set so "min" is 0, to guarantee "at least X" semantics. well, I think we specified this to be +- one, so -1 in some rare cases might still be acceptable. not sure. |
8feb83c to
6437b38
Compare
fixed. interesting, the test previously failed on zero offset... |
Would it be possible to add a short mention to the |
I intend to do more docs on this in the follow-up PR, which will hopefully just figure out the values automagically on each boot. |
OK, but I intend to quote you on this! |
|
@kaspar030 please squash! |
6437b38 to
ec65e8a
Compare
|
all green! |
|
thanks for the review! |
Contribution description
ztimer_sleep()can take considerable overhead.This PR introduces a per-clock field
adjust_sleepthat allows compensating this overhead.It can be configured for ztimer_usec by setting CONFIG_ZTIMER_USEC_ADJUST_SLEEP.
For consistency reasons, the corresponding adjust value field for "ztimer_set()" has been renamed from just "adjust" to "adjust_set", the config option CONFIG_ZTIMER_USEC_ADJUST_SET.
The sleep value is used in addition to the set value.
Testing procedure
run tests/ztimer_overhead, not down "min" value, recompile with
CFLAGS += -DCONFIG_ZTIMER_USEC_ADJUST_SET=<min>run tests/xtimer_usleep compiled with
CFLAGS += -DCONFIG_ZTIMER_USEC_ADJUST_SET=<min>andUSEMODULE+=ztimer_xtimer_compat, note offset valuere-run tests/xtimer_usleep compiled with
CFLAGS += -DCONFIG_ZTIMER_USEC_ADJUST_SET=<min>andUSEMODULE+=ztimer_xtimer_compat, andCFLAGS += -DCONFIG_ZTIMER_USEC_ADJUST_SLEEP=<offset>The offset should now be closer to zero.
Issues/PRs references