From 3ffd7ea370bde84f67f81ee5f6e052364198dbf4 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Mon, 30 Nov 2026 21:53:15 +0000 Subject: [PATCH] zephyr: use the Zephyr time and delay calls directly The Zephyr versions of these SOF time and delay helpers only forwarded to a Zephyr call: - sys_cycle_get_64_rate() returned CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC, use sys_clock_hw_cycles_per_sec() instead. It is the same constant unless the timer driver reads its rate at runtime, in which case the wallclock rate now matches the rate that the cycle conversions use. - sof_cycle_get_64_atomic() and sof_cycle_get_64_safe() were aliases of sof_cycle_get_64(). The two DMA domains were the last users of the first one, the second one had no users, and the host versions had no users either. - wait_delay(), wait_delay_us() and wait_delay_ms() wrapped k_busy_wait(). Call k_busy_wait() in the detect test, the AMD ACP 7.x clock code and poll_for_register_delay(). poll_for_register_delay() and wait_for_interrupt() stay for the i.MX and AMD IPC drivers until those move to Zephyr. The host keeps its own wait_delay*() for its k_sleep() stubs. No functional change. With one inline function less, GCC allocates registers and lays out branches differently in default_detect_test() and poll_for_register_delay(); the other objects are unchanged. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- posix/include/rtos/timer.h | 10 ---------- src/kernel/platform/amd/acp_7_x/lib/clk.c | 10 +++++----- src/samples/audio/detect_test.c | 4 ++-- src/schedule/dma_multi_chan_domain.c | 2 +- src/schedule/dma_single_chan_domain.c | 4 ++-- zephyr/include/rtos/timer.h | 7 ------- zephyr/include/rtos/wait.h | 16 ---------------- zephyr/wrapper.c | 4 ++-- 8 files changed, 12 insertions(+), 45 deletions(-) diff --git a/posix/include/rtos/timer.h b/posix/include/rtos/timer.h index 9087cde5c438..9ae2689c47fd 100644 --- a/posix/include/rtos/timer.h +++ b/posix/include/rtos/timer.h @@ -108,16 +108,6 @@ static inline uint64_t sof_cycle_get_64(void) return platform_timer_get(timer_get()); } -static inline uint64_t sof_cycle_get_64_atomic(void) -{ - return platform_timer_get_atomic(timer_get()); -} - -static inline uint64_t sof_cycle_get_64_safe(void) -{ - return platform_safe_get_time(timer_get()); -} - /* get timestamp for host stream DMA position */ void platform_host_timestamp(struct comp_dev *host, struct sof_ipc_stream_posn *posn); diff --git a/src/kernel/platform/amd/acp_7_x/lib/clk.c b/src/kernel/platform/amd/acp_7_x/lib/clk.c index d11471988d66..a23e762ce676 100644 --- a/src/kernel/platform/amd/acp_7_x/lib/clk.c +++ b/src/kernel/platform/amd/acp_7_x/lib/clk.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -303,7 +303,7 @@ static uint32_t acp_pmfw_poll_response(uint32_t msg, uint32_t arg) if (resp || sof_cycle_get_64() >= deadline) { break; } - wait_delay_us(1000);/*1ms delay to avoid busy loop*/ + k_busy_wait(1000);/*1ms delay to avoid busy loop*/ } while (sof_cycle_get_64() < deadline); elapsed_us = (uint32_t)k_cyc_to_us_floor64(sof_cycle_get_64() - start); @@ -340,7 +340,7 @@ static void acp_clk_dfsbypass_request(uint32_t req_bit, uint32_t timeout_cnt) if (!(value & req_bit)) { return; } - wait_delay_us(CLK_POLL_DELAY_US); + k_busy_wait(CLK_POLL_DELAY_US); } tr_warn(&acp_clk_tr, "DFS bypass request 0x%x still pending: cntl 0x%x", @@ -538,7 +538,7 @@ uint32_t acp_clk_update_dfs_did(uint32_t did, uint32_t clk_type) } else if (clk_type == acp_sclk_clock) { acp_cpl_audioclk_dfs_did_update(true, 10, did); } - wait_delay_us(ACP_CLK_MEASURE_SETTLE_US); + k_busy_wait(ACP_CLK_MEASURE_SETTLE_US); acp_log_current_aclk("D0"); acp_get_current_clk(acp_aclk_clock, (float *)&updated_clk); return updated_clk; @@ -675,7 +675,7 @@ static void acp_log_agt_clk(const char *state, const char *name, acp_clock_type_ static void acp_log_current_aclk(const char *state) { acp_clk_tick_cnt_enable(); - wait_delay_us(ACP_CLK_MEASURE_SETTLE_US); + k_busy_wait(ACP_CLK_MEASURE_SETTLE_US); acp_log_agt_clk(state, "ACLK", acp_aclk_clock); acp_log_agt_clk(state, "AUDIOCLK", acp_sclk_clock); } diff --git a/src/samples/audio/detect_test.c b/src/samples/audio/detect_test.c index a37ee0cfa640..aab84ed3788f 100644 --- a/src/samples/audio/detect_test.c +++ b/src/samples/audio/detect_test.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -225,7 +225,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); - wait_delay(cycles_per_frame); + k_busy_wait(k_cyc_to_us_floor64(cycles_per_frame)); } /* perform detection within current period */ diff --git a/src/schedule/dma_multi_chan_domain.c b/src/schedule/dma_multi_chan_domain.c index fec3ad3ecae9..3a2988391b00 100644 --- a/src/schedule/dma_multi_chan_domain.c +++ b/src/schedule/dma_multi_chan_domain.c @@ -324,7 +324,7 @@ static bool dma_multi_chan_domain_is_pending(struct ll_schedule_domain *domain, /* it's too soon for this task */ if (!pipe_task->registrable && pipe_task->task.start > - sof_cycle_get_64_atomic()) + sof_cycle_get_64()) continue; } diff --git a/src/schedule/dma_single_chan_domain.c b/src/schedule/dma_single_chan_domain.c index 0852c954b4cd..866c957590ea 100644 --- a/src/schedule/dma_single_chan_domain.c +++ b/src/schedule/dma_single_chan_domain.c @@ -451,7 +451,7 @@ static void dma_single_chan_domain_set(struct ll_schedule_domain *domain, return; if (dma_domain->channel_changed) { - domain->next_tick = sof_cycle_get_64_atomic(); + domain->next_tick = sof_cycle_get_64(); dma_domain->channel_changed = false; } else { @@ -488,7 +488,7 @@ static void dma_single_chan_domain_clear(struct ll_schedule_domain *domain) static bool dma_single_chan_domain_is_pending(struct ll_schedule_domain *domain, struct task *task, struct comp_dev **comp) { - return task->start <= sof_cycle_get_64_atomic(); + return task->start <= sof_cycle_get_64(); } /** diff --git a/zephyr/include/rtos/timer.h b/zephyr/include/rtos/timer.h index c430859823bb..2f221d593c25 100644 --- a/zephyr/include/rtos/timer.h +++ b/zephyr/include/rtos/timer.h @@ -28,13 +28,6 @@ static inline uint64_t sof_cycle_get_64(void) return k_ticks_to_cyc_floor64(k_uptime_ticks()); } -static inline uint64_t sys_cycle_get_64_rate(void) -{ - return CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC; -} - -#define sof_cycle_get_64_safe() sof_cycle_get_64() -#define sof_cycle_get_64_atomic() sof_cycle_get_64() #define platform_timer_stop(x) /* get timestamp for host stream DMA position */ diff --git a/zephyr/include/rtos/wait.h b/zephyr/include/rtos/wait.h index 2a8bd2086c27..885752ad2f55 100644 --- a/zephyr/include/rtos/wait.h +++ b/zephyr/include/rtos/wait.h @@ -11,22 +11,6 @@ #include #include #include -#include - -static inline void wait_delay_us(uint64_t us) -{ - k_busy_wait(us); -} - -static inline void wait_delay(uint64_t number_of_clks) -{ - k_busy_wait(k_cyc_to_us_floor64(number_of_clks)); -} - -static inline void wait_delay_ms(uint64_t ms) -{ - k_busy_wait(ms * 1000); -} int poll_for_register_delay(uint32_t reg, uint32_t mask, uint32_t val, uint64_t us); diff --git a/zephyr/wrapper.c b/zephyr/wrapper.c index f57231c1582f..be787bd6d58a 100644 --- a/zephyr/wrapper.c +++ b/zephyr/wrapper.c @@ -259,7 +259,7 @@ void platform_dai_timestamp(struct comp_dev *dai, /* get SSP wallclock - DAI sets this to stream start value */ #ifndef CONFIG_SOF_USERSPACE_LL posn->wallclock = sof_cycle_get_64() - posn->wallclock; - posn->wallclock_hz = sys_cycle_get_64_rate(); + posn->wallclock_hz = sys_clock_hw_cycles_per_sec(); #else posn->wallclock = k_uptime_ticks() - posn->wallclock; posn->wallclock_hz = CONFIG_SYS_CLOCK_TICKS_PER_SEC; @@ -322,7 +322,7 @@ int poll_for_register_delay(uint32_t reg, uint32_t mask, reg, mask, val, (uint32_t)us); return -EIO; } - wait_delay(delta); + k_busy_wait(k_cyc_to_us_floor64(delta)); } return 0; }