From 379eb425ac297b13d8cf1c9bc5074a6c31ea6b08 Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Tue, 4 Apr 2023 12:42:19 +0300 Subject: [PATCH 1/2] schedule: zephyr_dma_domain: Add macro for DMA domain thread prio This commit adds ZEPHYR_DMA_DOMAIN_THREAD_PRIO macro which holds the value of the thread priority for Zephyr DMA domain. Signed-off-by: Laurentiu Mihalcea --- src/schedule/zephyr_dma_domain.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/schedule/zephyr_dma_domain.c b/src/schedule/zephyr_dma_domain.c index eb0f57ba3467..bca028c886bf 100644 --- a/src/schedule/zephyr_dma_domain.c +++ b/src/schedule/zephyr_dma_domain.c @@ -34,6 +34,7 @@ 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) K_KERNEL_STACK_ARRAY_DEFINE(zephyr_dma_domain_stack, CONFIG_CORE_COUNT, @@ -305,7 +306,7 @@ static int zephyr_dma_domain_register(struct ll_schedule_domain *domain, dt, NULL, NULL, - CONFIG_NUM_PREEMPT_PRIORITIES - 1, + ZEPHYR_DMA_DOMAIN_THREAD_PRIO, 0, K_FOREVER); From 59b485d263944b5a34dd21a95f91d742896e9e26 Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Tue, 4 Apr 2023 12:44:58 +0300 Subject: [PATCH 2/2] 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 bca028c886bf..89f0231a45ce 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,