From 2779791040828159bfccacbc9d9e5891f6068c7e 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 ef649f975be8..69fc6d9129e8 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); @@ -337,8 +336,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 1a0231426c27..d18fbb6e0c5c 100644 --- a/zephyr/edf_schedule.c +++ b/zephyr/edf_schedule.c @@ -114,8 +114,7 @@ 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");