This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 2d6e09b6a690a2cf3fd1bcc110c50ad454503042 Author: Marco Casaroli <[email protected]> AuthorDate: Mon Nov 2 13:54:58 2026 +0100 sched/sched: Move a running task off a CPU that its affinity excludes. nxsched_running_setpriority() moves the running task to another CPU when its new affinity no longer includes the current CPU. But it did so only when the ready-to-run list was not empty. With an empty list, sched_setaffinity() on the calling task returned with the task still on a CPU outside its affinity. Then a higher priority task on that CPU puts the task back in the ready-to-run list. No CPU of its affinity is told, so the task never runs again. The first case of ostest's spinlock test does these steps (pin itself to CPU0, start a thread pinned to CPU1 at the highest priority); a program with the same steps hangs on qemu-armv8a:nsh_smp with 4 CPUs under TCG when it starts on CPU1. Check the affinity independently of the ready-to-run list. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- sched/sched/sched_setpriority.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index c507656204a..9f1719aa8cd 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -80,12 +80,12 @@ static inline void nxsched_running_setpriority(FAR struct tcb_s *tcb, * CASE 1. The new priority of the running task becomes less than or * equal to the next highest priority ready to run task. * CASE 2. In SMP, the affinity of tcb has changed and no longer includes - * the current cpu. + * the current cpu, also when no other task is ready to run. */ #ifdef CONFIG_SMP - if (nxttcb && (sched_priority <= nxttcb->sched_priority || - (tcb->affinity & (1 << tcb->cpu)) == 0)) + if ((tcb->affinity & (1 << tcb->cpu)) == 0 || + (nxttcb && sched_priority <= nxttcb->sched_priority)) #else if (nxttcb && sched_priority <= nxttcb->sched_priority) #endif
