From cf3ae008afe75ec0ef3d749c579e2d1caba713b1 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Wed, 24 Jun 2026 16:34:34 +0300 Subject: [PATCH] schedule: use k_thread_cpu_pin() for CPU affinity Replace the k_thread_cpu_mask_clear() + k_thread_cpu_mask_enable() sequence with a single k_thread_cpu_pin() call. The clear-then-enable pattern momentarily leaves the thread with a zero CPU mask, which is invalid under CONFIG_SCHED_CPU_MASK_PIN_ONLY and triggers an assertion after Zephyr commit 7798570a031d ("kernel: sched: enforce non-zero CPU mask invariant in PIN_ONLY mode"). k_thread_cpu_pin() atomically sets exactly one bit in the mask, avoiding the transient zero-mask state. Signed-off-by: Jyri Sarha --- src/schedule/zephyr_dma_domain.c | 3 +-- src/schedule/zephyr_domain.c | 6 ++---- zephyr/edf_schedule.c | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/schedule/zephyr_dma_domain.c b/src/schedule/zephyr_dma_domain.c index 9bb76660ab29..50901ef7b2af 100644 --- a/src/schedule/zephyr_dma_domain.c +++ b/src/schedule/zephyr_dma_domain.c @@ -462,8 +462,7 @@ static int zephyr_dma_domain_register(struct ll_schedule_domain *domain, K_FOREVER); #ifdef CONFIG_SCHED_CPU_MASK - k_thread_cpu_mask_clear(thread); - k_thread_cpu_mask_enable(thread, core); + k_thread_cpu_pin(thread, core); #endif k_thread_name_set(thread, thread_name); diff --git a/src/schedule/zephyr_domain.c b/src/schedule/zephyr_domain.c index 3837f0b135c6..c878e1972c49 100644 --- a/src/schedule/zephyr_domain.c +++ b/src/schedule/zephyr_domain.c @@ -218,8 +218,7 @@ static int zephyr_domain_register(struct ll_schedule_domain *domain, NULL, CONFIG_LL_THREAD_PRIORITY, 0, K_FOREVER); #ifdef CONFIG_SCHED_CPU_MASK - k_thread_cpu_mask_clear(thread); - k_thread_cpu_mask_enable(thread, core); + k_thread_cpu_pin(thread, core); #endif k_thread_name_set(thread, thread_name); @@ -345,8 +344,7 @@ static int zephyr_domain_thread_init(struct ll_schedule_domain *domain, K_USER, K_FOREVER); #ifdef CONFIG_SCHED_CPU_MASK - k_thread_cpu_mask_clear(thread); - k_thread_cpu_mask_enable(thread, core); + k_thread_cpu_pin(thread, core); #endif k_thread_name_set(thread, thread_name); diff --git a/zephyr/edf_schedule.c b/zephyr/edf_schedule.c index a14ed31d060d..c15f36b7be58 100644 --- a/zephyr/edf_schedule.c +++ b/zephyr/edf_schedule.c @@ -117,8 +117,7 @@ __cold int scheduler_init_edf(void) k_thread_heap_assign(thread, sof_sys_heap_get()); #ifdef CONFIG_SCHED_CPU_MASK - k_thread_cpu_mask_clear(thread); - k_thread_cpu_mask_enable(thread, PLATFORM_PRIMARY_CORE_ID); + k_thread_cpu_pin(thread, PLATFORM_PRIMARY_CORE_ID); #endif k_thread_name_set(thread, "edf_workq");