From 79e83298bce551b64a5e51a50ed9fe2b17f002f9 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 15 Nov 2024 10:42:13 +0200 Subject: [PATCH 1/4] idc: use wait_delay instead of idelay Prepare to remove idelay() use from generic code, so it can be removed from the SOF rtos abstraction layer. Signed-off-by: Kai Vehmanen --- src/idc/idc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/idc/idc.c b/src/idc/idc.c index 3661900164b2..7fe0988788ea 100644 --- a/src/idc/idc.c +++ b/src/idc/idc.c @@ -88,7 +88,7 @@ int idc_wait_in_blocking_mode(uint32_t target_core, bool (*cond)(int)) while (!cond(target_core)) { /* spin here so other core can access IO and timers freely */ - idelay(8192); + wait_delay(8192); if (deadline < sof_cycle_get_64()) break; From 00bebe01a261d8cf018c9ba4a05a1e0c92afa3fb Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 15 Nov 2024 10:51:48 +0200 Subject: [PATCH 2/4] samples: audio: detect_test: use wait_delay instead of idelay Prepare to remove idelay() use from generic code, so it can be removed from the SOF rtos abstraction layer. Signed-off-by: Kai Vehmanen --- src/samples/audio/detect_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/samples/audio/detect_test.c b/src/samples/audio/detect_test.c index 0b7d12d8914c..35270b60f275 100644 --- a/src/samples/audio/detect_test.c +++ b/src/samples/audio/detect_test.c @@ -223,7 +223,7 @@ static void default_detect_test(struct comp_dev *dev, /* assuming count is a processing frame size in samples */ cycles_per_frame = (cd->config.load_mips * 1000000 * count) / audio_stream_get_rate(source); - idelay(cycles_per_frame); + wait_delay(cycles_per_frame); } /* perform detection within current period */ From d34b3c33b3b98cbdfd9396b1cec1b91f27edf646 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 15 Nov 2024 10:52:46 +0200 Subject: [PATCH 3/4] zephyr: lib/cpu: use k_busy_wait instead of idelay Prepare to remove idelay() use from generic code, so it can be removed from the SOF rtos abstraction layer. This is Zephyr specific code, so k_busy_wait() can be used directly. Signed-off-by: Kai Vehmanen --- zephyr/lib/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zephyr/lib/cpu.c b/zephyr/lib/cpu.c index ef6ad5529f89..79946cc039f1 100644 --- a/zephyr/lib/cpu.c +++ b/zephyr/lib/cpu.c @@ -235,7 +235,7 @@ void cpu_disable_core(int id) /* Waiting for secondary core to enter idle state */ while (arch_cpu_active(id) && (k_cycle_get_64() < timeout)) - idelay(PLATFORM_DEFAULT_DELAY); + k_busy_wait(1); if (arch_cpu_active(id)) { tr_err(&zephyr_tr, "core %d did not enter idle state", id); From 9a6ba391a3bb577e00e0c3c7d92fcc0b4088e2be Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 15 Nov 2024 10:58:32 +0200 Subject: [PATCH 4/4] zephyr: rtos: implement wait_delay variants with k_busy_wait Implement wait_delay*() variants with k_busy_wait(). If some target requires to customize the busy wait implementation, this can be done with Zephyr CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT. Remove idelay() as this is no longer used in generic SOF code. Signed-off-by: Kai Vehmanen --- zephyr/include/rtos/wait.h | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/zephyr/include/rtos/wait.h b/zephyr/include/rtos/wait.h index f57e963fd1ed..4741e0c9aa8c 100644 --- a/zephyr/include/rtos/wait.h +++ b/zephyr/include/rtos/wait.h @@ -11,34 +11,22 @@ #include #include #include +#include #include -/* TODO: use equivalent Zephyr */ -static inline void idelay(int n) +static inline void wait_delay_us(uint64_t us) { - while (n--) - __asm__ volatile("nop"); + k_busy_wait(us); } -/* DSP default delay in cycles - all platforms use this today */ -#define PLATFORM_DEFAULT_DELAY 12 - static inline void wait_delay(uint64_t number_of_clks) { - uint64_t timeout = sof_cycle_get_64() + number_of_clks; - - while (sof_cycle_get_64() < timeout) - idelay(PLATFORM_DEFAULT_DELAY); + k_busy_wait(k_cyc_to_us_floor64(number_of_clks)); } static inline void wait_delay_ms(uint64_t ms) { - wait_delay(k_ms_to_cyc_ceil64(ms)); -} - -static inline void wait_delay_us(uint64_t us) -{ - wait_delay(k_us_to_cyc_ceil64(us)); + k_busy_wait(ms * 1000); } int poll_for_register_delay(uint32_t reg, uint32_t mask,