sched: sched: Simplify the scheduling logic in nxsched_add_readytorun() for SMP

test:
We can use qemu for testing.
compiling
make distclean -j20; ./tools/configure.sh -l qemu-armv8a:nsh_smp ;make -j20 running
qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic -machine virt,virtualization=on,gic-version=3 -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel ./nuttx

We have also tested this patch on other ARM hardware platforms.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2023-12-12 21:58:23 +08:00 committed by Xiang Xiao
parent 8d3d93e001
commit 03895f1073
1 changed files with 2 additions and 18 deletions

View File

@ -165,6 +165,7 @@ bool nxsched_add_readytorun(FAR struct tcb_s *btcb)
{ {
/* Yes.. that is the CPU we must use */ /* Yes.. that is the CPU we must use */
task_state = TSTATE_TASK_ASSIGNED;
cpu = btcb->cpu; cpu = btcb->cpu;
} }
else else
@ -173,6 +174,7 @@ bool nxsched_add_readytorun(FAR struct tcb_s *btcb)
* (possibly its IDLE task). * (possibly its IDLE task).
*/ */
task_state = TSTATE_TASK_READYTORUN;
cpu = nxsched_select_cpu(btcb->affinity); cpu = nxsched_select_cpu(btcb->affinity);
} }
@ -191,24 +193,6 @@ bool nxsched_add_readytorun(FAR struct tcb_s *btcb)
task_state = TSTATE_TASK_RUNNING; task_state = TSTATE_TASK_RUNNING;
} }
/* If it will not be running, but is locked to a CPU, then it will be in
* the assigned state.
*/
else if ((btcb->flags & TCB_FLAG_CPU_LOCKED) != 0)
{
task_state = TSTATE_TASK_ASSIGNED;
cpu = btcb->cpu;
}
/* Otherwise, it will be ready-to-run, but not not yet running */
else
{
task_state = TSTATE_TASK_READYTORUN;
cpu = 0; /* CPU does not matter */
}
/* If the selected state is TSTATE_TASK_RUNNING, then we would like to /* If the selected state is TSTATE_TASK_RUNNING, then we would like to
* start running the task. Be we cannot do that if pre-emption is * start running the task. Be we cannot do that if pre-emption is
* disabled. If the selected state is TSTATE_TASK_READYTORUN, then it * disabled. If the selected state is TSTATE_TASK_READYTORUN, then it