casaroli commented on code in PR #21393:
URL: https://github.com/apache/nuttx/pull/21393#discussion_r4452938769
##########
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))
Review Comment:
In SMP `nxttcb` is the head of the ready-to-run list (line 73), and it is
NULL when no other task is ready to run. Then the old condition is false, so a
`sched_setaffinity()` that removes the current CPU does not move the caller.
Test: a task that pins itself to each other CPU in turn still runs on its old
CPU in all 30 checks on master (qemu-armv8a:nsh_smp, 4 CPUs), and in none with
this change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]