Skip to content

Commit cf3ae00

Browse files
author
Jyri Sarha
committed
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 <jyri.sarha@linux.intel.com>
1 parent e9bfc2f commit cf3ae00

3 files changed

Lines changed: 4 additions & 8 deletions

File tree

src/schedule/zephyr_dma_domain.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,7 @@ static int zephyr_dma_domain_register(struct ll_schedule_domain *domain,
462462
K_FOREVER);
463463

464464
#ifdef CONFIG_SCHED_CPU_MASK
465-
k_thread_cpu_mask_clear(thread);
466-
k_thread_cpu_mask_enable(thread, core);
465+
k_thread_cpu_pin(thread, core);
467466
#endif
468467
k_thread_name_set(thread, thread_name);
469468

src/schedule/zephyr_domain.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ static int zephyr_domain_register(struct ll_schedule_domain *domain,
218218
NULL, CONFIG_LL_THREAD_PRIORITY, 0, K_FOREVER);
219219

220220
#ifdef CONFIG_SCHED_CPU_MASK
221-
k_thread_cpu_mask_clear(thread);
222-
k_thread_cpu_mask_enable(thread, core);
221+
k_thread_cpu_pin(thread, core);
223222
#endif
224223
k_thread_name_set(thread, thread_name);
225224

@@ -345,8 +344,7 @@ static int zephyr_domain_thread_init(struct ll_schedule_domain *domain,
345344
K_USER, K_FOREVER);
346345

347346
#ifdef CONFIG_SCHED_CPU_MASK
348-
k_thread_cpu_mask_clear(thread);
349-
k_thread_cpu_mask_enable(thread, core);
347+
k_thread_cpu_pin(thread, core);
350348
#endif
351349
k_thread_name_set(thread, thread_name);
352350

zephyr/edf_schedule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ __cold int scheduler_init_edf(void)
117117

118118
k_thread_heap_assign(thread, sof_sys_heap_get());
119119
#ifdef CONFIG_SCHED_CPU_MASK
120-
k_thread_cpu_mask_clear(thread);
121-
k_thread_cpu_mask_enable(thread, PLATFORM_PRIMARY_CORE_ID);
120+
k_thread_cpu_pin(thread, PLATFORM_PRIMARY_CORE_ID);
122121
#endif
123122
k_thread_name_set(thread, "edf_workq");
124123

0 commit comments

Comments
 (0)