sched: After nxsched_add_readytorun, change first parameter to up_switch_context to this_task()

Change every occurence of up_switch_context to use this_task() as the first parameter.

"nxsched_add_readytorun" returns "true" if context switch is required. "nxsched_add_readytorun"
typically could only switch the assigned/running task to the one which is passed in as parameter.
But this is not strictly guaranteed in SMP; if other CPUs tweak with affinities or priorities,
it may be possible that the running task after the call is changed, but is some other
task from the readytorun list (and it should be, if there is higher priority one available or the
affinity of the added task prevents it to be scheduled in, but the previous head of the readytorun
list should run.

this_task() is always the correct one to switch to, since it always points to the tcb which was
just switched in by the nxsched_add_readytorun.

This is also a precursor to re-writing the SMP queue logic to remove pending lists for SMP.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
This commit is contained in:
Jukka Laitinen 2025-08-14 17:33:34 +03:00 committed by Donny(董九柱)
parent f55e6f6383
commit 3e29996d97
12 changed files with 18 additions and 18 deletions

View file

@ -77,7 +77,7 @@ static int group_continue_handler(pid_t pid, FAR void *arg)
if (nxsched_add_readytorun(rtcb)) if (nxsched_add_readytorun(rtcb))
{ {
up_switch_context(rtcb, tcb); up_switch_context(this_task(), tcb);
} }
} }

View file

@ -267,7 +267,7 @@ void nxmq_notify_receive(FAR struct mqueue_inode_s *msgq)
if (nxsched_add_readytorun(btcb)) if (nxsched_add_readytorun(btcb))
{ {
up_switch_context(btcb, rtcb); up_switch_context(this_task(), rtcb);
} }
} }
} }

View file

@ -300,7 +300,7 @@ void nxmq_notify_send(FAR struct mqueue_inode_s *msgq)
if (nxsched_add_readytorun(btcb)) if (nxsched_add_readytorun(btcb))
{ {
up_switch_context(btcb, rtcb); up_switch_context(this_task(), rtcb);
} }
} }
} }

View file

@ -107,6 +107,6 @@ void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode)
if (nxsched_add_readytorun(wtcb)) if (nxsched_add_readytorun(wtcb))
{ {
up_switch_context(wtcb, rtcb); up_switch_context(this_task(), rtcb);
} }
} }

View file

@ -266,7 +266,7 @@ ssize_t msgrcv(int msqid, FAR void *msgp, size_t msgsz, long msgtyp,
if (nxsched_add_readytorun(btcb)) if (nxsched_add_readytorun(btcb))
{ {
up_switch_context(btcb, rtcb); up_switch_context(this_task(), rtcb);
} }
} }

View file

@ -259,7 +259,7 @@ int msgsnd(int msqid, FAR const void *msgp, size_t msgsz, int msgflg)
if (nxsched_add_readytorun(btcb)) if (nxsched_add_readytorun(btcb))
{ {
up_switch_context(btcb, rtcb); up_switch_context(this_task(), rtcb);
} }
} }
} }

View file

@ -297,7 +297,7 @@ static inline bool pg_dequeue(void)
if (nxsched_add_readytorun(g_pftcb)) if (nxsched_add_readytorun(g_pftcb))
{ {
up_switch_context(g_pftcb, wtcb); up_switch_context(this_task(), wtcb);
} }
} }
} }
@ -494,7 +494,7 @@ static inline void pg_fillcomplete(void)
if (nxsched_add_readytorun(g_pftcb)) if (nxsched_add_readytorun(g_pftcb))
{ {
up_switch_context(g_pftcb, wtcb); up_switch_context(this_task(), wtcb);
} }
} }
@ -597,7 +597,7 @@ int pg_worker(int argc, FAR char *argv[])
if (nxsched_add_readytorun(g_pftcb)) if (nxsched_add_readytorun(g_pftcb))
{ {
up_switch_context(g_pftcb, wtcb); up_switch_context(this_task(), wtcb);
} }
/* Yes .. Start the next asynchronous fill. Check the return /* Yes .. Start the next asynchronous fill. Check the return
@ -682,7 +682,7 @@ int pg_worker(int argc, FAR char *argv[])
if (nxsched_add_readytorun(g_pftcb)) if (nxsched_add_readytorun(g_pftcb))
{ {
up_switch_context(g_pftcb, wtcb); up_switch_context(this_task(), wtcb);
} }
} }

View file

@ -221,7 +221,7 @@ int nxsem_post_slow(FAR sem_t *sem)
if (nxsched_add_readytorun(stcb)) if (nxsched_add_readytorun(stcb))
{ {
up_switch_context(stcb, rtcb); up_switch_context(this_task(), rtcb);
} }
} }
} }

View file

@ -125,6 +125,6 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
if (nxsched_add_readytorun(wtcb)) if (nxsched_add_readytorun(wtcb))
{ {
up_switch_context(wtcb, rtcb); up_switch_context(this_task(), rtcb);
} }
} }

View file

@ -556,7 +556,7 @@ int nxsig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info,
if (nxsched_add_readytorun(stcb)) if (nxsched_add_readytorun(stcb))
{ {
up_switch_context(stcb, rtcb); up_switch_context(this_task(), rtcb);
} }
#ifdef CONFIG_LIB_SYSCALL #ifdef CONFIG_LIB_SYSCALL
@ -614,7 +614,7 @@ int nxsig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info,
if (nxsched_add_readytorun(stcb)) if (nxsched_add_readytorun(stcb))
{ {
up_switch_context(stcb, rtcb); up_switch_context(this_task(), rtcb);
} }
} }
@ -674,7 +674,7 @@ int nxsig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info,
if (nxsched_add_readytorun(stcb)) if (nxsched_add_readytorun(stcb))
{ {
up_switch_context(stcb, rtcb); up_switch_context(this_task(), rtcb);
} }
#endif #endif
} }

View file

@ -117,7 +117,7 @@ static void nxsig_timeout(wdparm_t arg)
if (nxsched_add_readytorun(wtcb)) if (nxsched_add_readytorun(wtcb))
{ {
up_switch_context(wtcb, rtcb); up_switch_context(this_task(), rtcb);
} }
} }
@ -185,7 +185,7 @@ void nxsig_wait_irq(FAR struct tcb_s *wtcb, int errcode)
if (nxsched_add_readytorun(wtcb)) if (nxsched_add_readytorun(wtcb))
{ {
up_switch_context(wtcb, rtcb); up_switch_context(this_task(), rtcb);
} }
} }

View file

@ -95,7 +95,7 @@ void nxtask_activate(FAR struct tcb_s *tcb)
if (nxsched_add_readytorun(tcb)) if (nxsched_add_readytorun(tcb))
{ {
up_switch_context(tcb, rtcb); up_switch_context(this_task(), rtcb);
} }
leave_critical_section(flags); leave_critical_section(flags);