schedule: use k_thread_cpu_pin() for CPU affinity#10953
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates SOF’s Zephyr scheduling-related thread affinity setup to avoid a transient zero CPU mask state that can assert under Zephyr’s CONFIG_SCHED_CPU_MASK_PIN_ONLY invariant enforcement, by switching from k_thread_cpu_mask_clear() + k_thread_cpu_mask_enable() to k_thread_cpu_pin().
Changes:
- Replace clear+enable CPU-mask sequences with
k_thread_cpu_pin()in EDF workqueue init and LL/DMA domain thread creation. - (Intended) Eliminate transient zero-mask state that can trigger Zephyr assertions with newer scheduler checks.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
zephyr/edf_schedule.c |
Pins the EDF workqueue thread using k_thread_cpu_pin() instead of clear+enable. |
src/schedule/zephyr_domain.c |
Pins the LL domain thread using k_thread_cpu_pin() in the kernel-space path. |
src/schedule/zephyr_dma_domain.c |
Pins the DMA domain thread using k_thread_cpu_pin() instead of clear+enable. |
| #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 |
There was a problem hiding this comment.
That is annother fix, not the one this PR is fixing. And the only reason that may cause k_thread_cpu_pin() to fail is that thread is already running, which is obviously not the case here, so check is quite futile.
| #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 |
| #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 |
| #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 |
1801dbe to
2779791
Compare
|
@jsarha can you check CI thanks ! |
|
SOFCI TEST |
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>
2779791 to
cf3ae00
Compare
|
Rebased to retrigger the CI tests. |
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.
This PR together with zephyrproject-rtos/zephyr#111955 should make SOF boot again with latest Zephyr and asserts enabled.