sched/setpriority: handle CPU affinity change for running task - #19687
Open
hujun260 wants to merge 1 commit into
Open
sched/setpriority: handle CPU affinity change for running task#19687hujun260 wants to merge 1 commit into
hujun260 wants to merge 1 commit into
Conversation
When a running task changes its affinity on SMP and is no longer eligible to run on the current CPU, merely delivering an equal-priority scheduling request can leave the task in g_readytorun while the target CPU remains idle. The task then never runs again. Remove the task from its current CPU, add it back to the ready-to-run list so a suitable CPU is selected, and perform the context switch unconditionally. This ensures the task is migrated according to its updated affinity. Fixes: apache#19680 Assisted-by: GitHub Copilot:ppio/pa/gpt-5.6-sol Signed-off-by: hujun5 <hujun5@xiaomi.com>
1 task
xiaoxiang781216
approved these changes
Aug 5, 2026
jerpelea
approved these changes
Aug 5, 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.
Summary
When a running task changes its CPU affinity on SMP and the new mask no longer includes its current CPU,
nxsched_set_priority()requests an equal-priority reschedule on the current CPU. The task can be moved tog_readytorunwithout waking the idle target CPU, leaving it unable to run again.Remove the task from its current CPU, add it back through
nxsched_add_readytorun()so a suitable CPU is selected, and switch context unconditionally when the running task is no longer eligible for its current CPU.Fixes #19680.
Impact
Testing
Build host: Ubuntu Linux, x86-64, GCC.
Target: QEMU ARM64,
qemu-armv8a:nsh_smp, two Cortex-A53 CPUs.Build command:
QEMU command:
A local reproducer starts two equal-priority
SCHED_RRthreads on CPU1. T0 changes its affinity to CPU0 while CPU0 is idle and T1 remains runnable on CPU1.Before this change, T0 never resumes and the test stops after:
After this change, T0 resumes on CPU0:
Code and commit checks:
PR verification Self-Check