From bf5dd34deb587434d8241f87ffd524b1c9d8f4ad Mon Sep 17 00:00:00 2001 From: Jue Date: Thu, 3 Nov 2022 14:01:59 +0100 Subject: [PATCH] ztimer/overhead: acquire and release clocks The start/stop overhead that might by introduced by ztimer_acquire() and ztimer_release() called during ztimer_set() resp. ztimer_handler() should not be mesured here. It has its own adjustment field. Furthermore, the overhead mesaurement uses ztimer_now(). It is allowed to called it only after the clock has been acquired. --- sys/ztimer/overhead.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sys/ztimer/overhead.c b/sys/ztimer/overhead.c index c472a150f0..9744a36a06 100644 --- a/sys/ztimer/overhead.c +++ b/sys/ztimer/overhead.c @@ -43,18 +43,21 @@ int32_t ztimer_overhead_set(ztimer_clock_t *clock, uint32_t base) callback_arg_t arg = { .clock = clock, .val = &after }; ztimer_t t = { .callback = _callback, .arg = &arg }; + ztimer_acquire(clock); pre = ztimer_now(clock); ztimer_set(clock, &t, base); while (!after) {} + ztimer_release(clock); return after - pre - base; } int32_t ztimer_overhead_sleep(ztimer_clock_t *clock, uint32_t base) { + ztimer_acquire(clock); uint32_t pre = ztimer_now(clock); - ztimer_sleep(clock, base); uint32_t after = ztimer_now(clock); + ztimer_release(clock); return after - pre - base; }