Skip to content

Commit 2779791

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 26917d9 commit 2779791

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

@@ -337,8 +336,7 @@ static int zephyr_domain_thread_init(struct ll_schedule_domain *domain,
337336
K_USER, K_FOREVER);
338337

339338
#ifdef CONFIG_SCHED_CPU_MASK
340-
k_thread_cpu_mask_clear(thread);
341-
k_thread_cpu_mask_enable(thread, core);
339+
k_thread_cpu_pin(thread, core);
342340
#endif
343341
k_thread_name_set(thread, thread_name);
344342

zephyr/edf_schedule.c

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

115115
k_thread_heap_assign(thread, sof_sys_heap_get());
116116
#ifdef CONFIG_SCHED_CPU_MASK
117-
k_thread_cpu_mask_clear(thread);
118-
k_thread_cpu_mask_enable(thread, PLATFORM_PRIMARY_CORE_ID);
117+
k_thread_cpu_pin(thread, PLATFORM_PRIMARY_CORE_ID);
119118
#endif
120119
k_thread_name_set(thread, "edf_workq");
121120

0 commit comments

Comments
 (0)