From f78834aa233f8935acf4016ec7d412f13e6f54a2 Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Tue, 4 Apr 2023 12:44:58 +0300 Subject: [PATCH] schedule: zephyr_dma_domain: Make Zephyr DMA domain's thread priority higher Zephyr DMA domain thread should have a higher priority than the logging thread. Not meeting this criteria may cause problems such as buzzing noises after resuming a paused stream. This was the case on i.MX93. Signed-off-by: Laurentiu Mihalcea --- src/schedule/zephyr_dma_domain.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/schedule/zephyr_dma_domain.c b/src/schedule/zephyr_dma_domain.c index bca028c88..89f0231a4 100644 --- a/src/schedule/zephyr_dma_domain.c +++ b/src/schedule/zephyr_dma_domain.c @@ -34,7 +34,34 @@ LOG_MODULE_DECLARE(ll_schedule, CONFIG_SOF_LOG_LEVEL); #define SEM_LIMIT 1 #define ZEPHYR_PDOMAIN_STACK_SIZE 8192 -#define ZEPHYR_DMA_DOMAIN_THREAD_PRIO (CONFIG_NUM_PREEMPT_PRIORITIES - 1) + +#if CONFIG_LOG_PROCESS_THREAD_CUSTOM_PRIORITY +#define ZEPHYR_DMA_DOMAIN_THREAD_PRIO (CONFIG_LOG_PROCESS_THREAD_PRIORITY - 1) +#else +#define ZEPHYR_DMA_DOMAIN_THREAD_PRIO (K_LOWEST_APPLICATION_THREAD_PRIO - 1) +#endif /* CONFIG_LOG_PROCESS_THREAD_CUSTOM_PRIORITY */ + +/* sanity check regarding the DMA domain's priority. + * + * VERY IMPORTANT: the Zephyr DMA domain's thread priority needs to be + * higher than the logging thread's. If this criteria is not met then + * issues such as buzzing noise when PAUSING/RESUMING a stream due to + * the SAI being underrun may appear. We also want to keep Zephyr DMA + * domain's thread priority in the preemptible range so as to not + * disturb the other Zephyr threads used by SOF (preferably the Zephyr + * DMA domain's thread priority should be lower than the lowest priority + * of the threads used by SOF which is 1 (EDF_SCHEDULER)). + * + * The Zephyr DMA domain's thread priority is unimportant as long as it + * meets the above criteria but we'll make it one less than the logging + * thread's for cases where the user might want to change the logging + * thread's priority. + * + * TODO: this message and the BUILD_ASSERT message need to be updated if + * the lowest priority used by the SOF threads is changed. + */ +BUILD_ASSERT(ZEPHYR_DMA_DOMAIN_THREAD_PRIO >= 0, + "Invalid DMA domain thread priority. Please make sure that logging threads priority is >= 1 or, preferably, >= 3"); K_KERNEL_STACK_ARRAY_DEFINE(zephyr_dma_domain_stack, CONFIG_CORE_COUNT,