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: introduce xtimer_msleep() #15076
Conversation
cb7ebc0
to
c11e7c9
Compare
btw, there is a coccinelle script that can recognize "xtimer_(, ..., foo * MSEC_IN_USEC)" and convert that to "ztimer_(ZTIMER_MSEC, ...)". |
btw.: what was the rationale for having |
I cannot answer what the rationale was, but I can point out some advantage of this decision: This decouples the choice of the hardware to run on from the time unit used. E.g. let's say I have a PTP clock an a E.g. in a sensor netowrk I might indeed want measurements to be performed completely synchronized, so in terms of the synchronized PTP clock - even if the period changes whenever the clock is adjusted. |
What @maribu said. ZTIMER_USEC is just a name (ptr) that by convention points to a ztimer clock that provides usec ticks. |
c11e7c9
to
459e66c
Compare
Being honest, I think that xtimer_msleep(3); is simply more readable than xtimer_usleep(3 * US_PER_MS); Just for that reason, we should IMO get this in. That this will make people using |
+1 |
1 similar comment
+1 |
sys/include/ztimer/xtimer_compat.h
Outdated
static inline void xtimer_msleep(uint32_t milliseconds) | ||
{ | ||
if (IS_ACTIVE(MODULE_ZTIMER_MSEC)) { | ||
ztimer_sleep(ZTIMER_MSEC, milliseconds); | ||
} else { | ||
while (milliseconds > (UINT32_MAX / 1000LU)) { | ||
ztimer_sleep(ZTIMER_USEC, UINT32_MAX); | ||
seconds -= UINT32_MAX / 1000LU; | ||
} | ||
ztimer_sleep(ZTIMER_USEC, milliseconds * 1000LU); | ||
} |
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 would IMO now justify an ztimer_msleep()
as helper - for when the user really doesn't care on which hardware the timer is set. But that should be another discussion in another PR.
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.
why not just depend on ztimer msec?
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 helper would do the intermediate wakeups N times for N ztimer_msleep instances. ztimer_sleep(ZTIMER_MSEC, ...
would mitigate that.
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.
Hmm, is there a use case for using ztimer
without ztimer_msec
?
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.
well, if nothing uses it, no need to include it. but that's not the point here, there's no case (or there should not be one) where ztime_msec is not available.
Add a function that sleeps for ms instead of µs. This will make the conversion to ztimer easier for users as now there is a direct mapping to ZTIMER_MSEC.
f9067c5
to
ca193cf
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. I really like _ztimer_sleep_scale()
, which should improve both readability and the opportunities of the compiler to optimize the code.
yeah. maybe move it to be a public ztimer function? |
@@ -172,6 +172,11 @@ static inline void xtimer_spin(xtimer_ticks32_t ticks) { | |||
_xtimer_spin(ticks.ticks32); | |||
} | |||
|
|||
static inline void xtimer_msleep(uint32_t milliseconds) | |||
{ | |||
_xtimer_tsleep64(_xtimer_ticks_from_usec64(milliseconds * US_PER_MS)); |
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.
Hm now I wonder: will this now have a worse overhead than calling xtimer_usleep(ms * US_PER_MS)
because here 64 bit arithmetic will be involved?
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.
Rather than worrying about xtimer
, let's push ztimer
forward :-)
Contribution description
Add a function that sleeps for ms instead of µs.
This will make the conversion to ztimer easier for users as now there is a direct mapping to
ZTIMER_MSEC
.Testing procedure
Issues/PRs references