schedule: use k_thread_cpu_pin() for CPU affinity#10953
Open
jsarha wants to merge 1 commit into
Open
Conversation
Contributor
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. |
Comment on lines
116
to
118
| #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 |
Contributor
Author
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.
Comment on lines
220
to
222
| #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 |
Comment on lines
220
to
222
| #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 |
Comment on lines
464
to
466
| #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 |
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>
1801dbe to
2779791
Compare
kv2019i
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.