From 070ad15f14dea13f569a3f22a8674b5936e76eeb Mon Sep 17 00:00:00 2001 From: chenhonglin Date: Fri, 24 Sep 2021 18:10:30 +0800 Subject: [PATCH] sched/sched_setpriority.c: Fix CPU affinity issues in SMP THOR-208 In "nxsched_nexttcb": the task may not running on this_cpu, and rtrtcb->affinity(the affinity of the task in g_readytorun) may not include the current cpu which should be the tcb->cpu. Signed-off-by: chenhonglin Change-Id: I2523c9431b480a3afeb29a9260804c5b37e91d4b --- sched/sched/sched_setpriority.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c index 842926fc7df..a8a1b6d3605 100644 --- a/sched/sched/sched_setpriority.c +++ b/sched/sched/sched_setpriority.c @@ -58,7 +58,6 @@ static FAR struct tcb_s *nxsched_nexttcb(FAR struct tcb_s *tcb) { FAR struct tcb_s *nxttcb = (FAR struct tcb_s *)tcb->flink; FAR struct tcb_s *rtrtcb; - int cpu = this_cpu(); /* Which task should run next? It will be either the next tcb in the * assigned task list (nxttcb) or a TCB in the g_readytorun list. We can @@ -69,12 +68,12 @@ static FAR struct tcb_s *nxsched_nexttcb(FAR struct tcb_s *tcb) * then use the 'nxttcb' which will probably be the IDLE thread. */ - if (!nxsched_islocked_global() && !irq_cpu_locked(cpu)) + if (!nxsched_islocked_global() && !irq_cpu_locked(this_cpu())) { /* Search for the highest priority task that can run on this CPU. */ for (rtrtcb = (FAR struct tcb_s *)g_readytorun.head; - rtrtcb != NULL && !CPU_ISSET(cpu, &rtrtcb->affinity); + rtrtcb != NULL && !CPU_ISSET(tcb->cpu, &rtrtcb->affinity); rtrtcb = (FAR struct tcb_s *)rtrtcb->flink); /* Return the TCB from the readyt-to-run list if it is the next