From 9428f953b792463464cbd17dd6eef2def3d1c2e7 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Mon, 6 Jan 2025 12:42:41 +0100 Subject: [PATCH] ipc: move delayed IPC sending to the primary core Low level IPC processing should be confined to the primary core. Move delayed IPC sending to a dedicated work queue with core 0 affinity. Fixes: #8165 Signed-off-by: Guennadi Liakhovetski --- src/ipc/ipc-common.c | 21 ++++++++++++++++++++- zephyr/Kconfig | 6 ++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ipc/ipc-common.c b/src/ipc/ipc-common.c index e9de1efdd2a0..ebe80f3af9e2 100644 --- a/src/ipc/ipc-common.c +++ b/src/ipc/ipc-common.c @@ -170,6 +170,11 @@ void ipc_send_queued_msg(void) k_spin_unlock(&ipc->lock, key); } +#ifdef __ZEPHYR__ +static struct k_work_q ipc_send_wq; +static K_THREAD_STACK_DEFINE(ipc_send_wq_stack, CONFIG_STACK_SIZE_IPC_TX); +#endif + static void schedule_ipc_worker(void) { /* @@ -179,7 +184,7 @@ static void schedule_ipc_worker(void) #ifdef __ZEPHYR__ struct ipc *ipc = ipc_get(); - k_work_schedule(&ipc->z_delayed_work, K_USEC(IPC_PERIOD_USEC)); + k_work_schedule_for_queue(&ipc_send_wq, &ipc->z_delayed_work, K_USEC(IPC_PERIOD_USEC)); #endif } @@ -305,6 +310,20 @@ int ipc_init(struct sof *sof) #endif #ifdef __ZEPHYR__ + struct k_thread *thread = &ipc_send_wq.thread; + + k_work_queue_start(&ipc_send_wq, + ipc_send_wq_stack, + K_THREAD_STACK_SIZEOF(ipc_send_wq_stack), + 1, NULL); + + k_thread_suspend(thread); + + k_thread_cpu_pin(thread, PLATFORM_PRIMARY_CORE_ID); + k_thread_name_set(thread, "ipc_send_wq"); + + k_thread_resume(thread); + k_work_init_delayable(&sof->ipc->z_delayed_work, ipc_work_handler); #endif diff --git a/zephyr/Kconfig b/zephyr/Kconfig index cb33046bd42a..ec3629935e53 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -96,4 +96,10 @@ config STACK_SIZE_EDF help EDF scheduler work-queue thread stack size. Keep a power of 2. +config STACK_SIZE_IPC_TX + int "IPC sender stack size" + default 2048 + help + IPC sender work-queue thread stack size. Keep a power of 2. + endif