-
Notifications
You must be signed in to change notification settings - Fork 2.1k
sys/ztimer: add auto_adjust module #17633
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
Nice! I think we'd also need a test that checks that if any edit maybe |
I'm not sure, the test can be more picky run more loops or whatever, while the |
that sounds reasonable! Also, the values can vary by +-1 due to whatever factors. |
And what are your thoughts regarding defaults, default on? |
sys/ztimer/init.c
Outdated
if (IS_ACTIVE(CONFIG_ZTIMER_USEC_ADJUST_SLEEP)) { | ||
ZTIMER_USEC->adjust_sleep = CONFIG_ZTIMER_USEC_ADJUST_SLEEP; | ||
} | ||
else if (IS_USED(MODULE_ZTIMER_AUTO_ADJUST)) {} |
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.
These braces don't look like something you intended
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.
Thanks!
hmm. off means, ztimers are late. on means, ztimers are on time, but there's quite some boot delay, and extra code size. Can we quantify those? |
How about auto-on with DEVELHELP (or in some prominent examples like default), and printing a warning to stdout if there are no values (or the values don't match what is measured)? |
I don't like the idea of enabling this with
I don't quite understand this suggestion, you mean in the test? |
There is probable some possible optimization in the init code as well. |
I mean that whenever it is affordable to do this on startup (may not be with develhelp, might be in some example), the measurement should be taken immaterial of whether an adjust value is set or not. Thus, not only missing values will be acted on, but also wrong values. (Messages might be "Warning: No CONFIG_ZTIMER_USEC_ADJUST_SLEEP set. A value of 27 was measured and should be added to the ... configuration" vs. "Warning: The CONFIG_ZTIMER_USEC_ADJUST_SLEEP value of 30 that was configured disagrees with startup measurements that produced a value of 27.") |
Humm but here you are saying you trust the measured at runtime value more than the configured value, and I would rather think the other way around. But I guess this is something to evaluate as well. |
Yeah, I deliberately left that open; stability of the values across settings may play a part in that evaluation. |
Removed as default |
Added, I'll later run tests on the BOARDs I have, but currently busy with another set of tests. |
makefiles/pseudomodules.inc.mk
Outdated
## @defgroup pseudomodule_ztimer_auto_adjust ztimer_auto_adjust | ||
## @brief A module to set on init ztimer->adjust_sleep/adjust_set values | ||
## | ||
## When this module is active (which it is by default), then on init |
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.
This needs to be changed since its not on by default
May I squash? |
this is still the case, no? yeah, you can squash! |
b9f962a
to
c0d4047
Compare
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.
Hmm the test failed on some avr:
|
@fjmolinas might be possible to get the value related/adjusted by using the lenght (sizeof?) of a function containing a JMP/CALL (som avr need to use eijmp (with some reg initialised and some extra long returns) |
@kaspar030 care to take another look? |
@kfessel I think this is still a bit premature optimization, configuring sensible values is still the best option IMO, this would just allow it to work in (mostly) all cases but with this extra boot-up time. |
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.
re-ACK.
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.
avoid reducing to much by default Arduino / AVR common
9d5b998
to
59d069c
Compare
Squashed |
@kaspar030 @kfessel all green! |
Anything holding this one back? |
Thanks! |
Contribution description
ztimer_sleep
andztimer_set
have an overhead themselves and since #14936 both can be compensated for. But in practice very few BOARD's use this value.This PR adds work from @kaspar030 to add a module to auto-configure this values on startup unless there is an existing configuration value, e.g.:
CONFIG_ZTIMER_USEC_ADJUST_SLEEP
andCONFIG_ZTIMER_USEC_ADJUST_SET
. These values have also been documented with this PR.The module is enabled by default but that could be discussed since it increases startup time. I would prefer doing that and having people who care about performance configuring
CONFIG_ZTIMER_USEC_ADJUST%
for their hardware.Testing procedure
This should lead prerry small offsets:
USEMODULE="ztimer_xtimer_compat" BOARD=dwm1001 make -C tests/xtimer_usleep flash test -j
tests/ztimer_overhead
yields the configuration values:BOARD=dwm1001 make -C tests/ztimer_overhead/ flash test -j
Issues/PRs references
Depends on #17632, but could be split out
Part of #17111