From 9f42537fc7e08149d08c0b4df95ca4bf9398bea2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 4 Dec 2023 10:33:28 -0800 Subject: [PATCH] kernel: Use k_us_to_cyc_ceil32 in k_busy_wait Replace open-coded time conversion with the macro which as that will usually use a constant divide or multiply. Signed-off-by: Keith Packard --- kernel/busy_wait.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/kernel/busy_wait.c b/kernel/busy_wait.c index 4bb94ca04d..cb7c993437 100644 --- a/kernel/busy_wait.c +++ b/kernel/busy_wait.c @@ -21,13 +21,7 @@ void z_impl_k_busy_wait(uint32_t usec_to_wait) arch_busy_wait(usec_to_wait); #elif defined(CONFIG_SYS_CLOCK_EXISTS) uint32_t start_cycles = k_cycle_get_32(); - - /* use 64-bit math to prevent overflow when multiplying */ - uint32_t cycles_to_wait = (uint32_t)( - (uint64_t)usec_to_wait * - (uint64_t)sys_clock_hw_cycles_per_sec() / - (uint64_t)USEC_PER_SEC - ); + uint32_t cycles_to_wait = k_us_to_cyc_ceil32(usec_to_wait); for (;;) { uint32_t current_cycles = k_cycle_get_32();