This is an automated email from the ASF dual-hosted git repository.

jiuzhudong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 3e29996d9721dd9d8cd3558e72ed39189d21c418
Author: Jukka Laitinen <jukka.laiti...@tii.ae>
AuthorDate: Thu Aug 14 17:33:34 2025 +0300

    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.laiti...@tii.ae>
---
 sched/group/group_continue.c  | 2 +-
 sched/mqueue/mq_rcvinternal.c | 2 +-
 sched/mqueue/mq_sndinternal.c | 2 +-
 sched/mqueue/mq_waitirq.c     | 2 +-
 sched/mqueue/msgrcv.c         | 2 +-
 sched/mqueue/msgsnd.c         | 2 +-
 sched/paging/pg_worker.c      | 8 ++++----
 sched/semaphore/sem_post.c    | 2 +-
 sched/semaphore/sem_waitirq.c | 2 +-
 sched/signal/sig_dispatch.c   | 6 +++---
 sched/signal/sig_timedwait.c  | 4 ++--
 sched/task/task_activate.c    | 2 +-
 12 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/sched/group/group_continue.c b/sched/group/group_continue.c
index 70f9c508b8d..63aa35ac1ce 100644
--- a/sched/group/group_continue.c
+++ b/sched/group/group_continue.c
@@ -77,7 +77,7 @@ static int group_continue_handler(pid_t pid, FAR void *arg)
 
       if (nxsched_add_readytorun(rtcb))
         {
-          up_switch_context(rtcb, tcb);
+          up_switch_context(this_task(), tcb);
         }
     }
 
diff --git a/sched/mqueue/mq_rcvinternal.c b/sched/mqueue/mq_rcvinternal.c
index 8ddac55429c..4cbb638880a 100644
--- a/sched/mqueue/mq_rcvinternal.c
+++ b/sched/mqueue/mq_rcvinternal.c
@@ -267,7 +267,7 @@ void nxmq_notify_receive(FAR struct mqueue_inode_s *msgq)
 
       if (nxsched_add_readytorun(btcb))
         {
-          up_switch_context(btcb, rtcb);
+          up_switch_context(this_task(), rtcb);
         }
     }
 }
diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c
index 0f36d4b04a9..661ada915bd 100644
--- a/sched/mqueue/mq_sndinternal.c
+++ b/sched/mqueue/mq_sndinternal.c
@@ -300,7 +300,7 @@ void nxmq_notify_send(FAR struct mqueue_inode_s *msgq)
 
       if (nxsched_add_readytorun(btcb))
         {
-          up_switch_context(btcb, rtcb);
+          up_switch_context(this_task(), rtcb);
         }
     }
 }
diff --git a/sched/mqueue/mq_waitirq.c b/sched/mqueue/mq_waitirq.c
index db59c721640..d9649078129 100644
--- a/sched/mqueue/mq_waitirq.c
+++ b/sched/mqueue/mq_waitirq.c
@@ -107,6 +107,6 @@ void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode)
 
   if (nxsched_add_readytorun(wtcb))
     {
-      up_switch_context(wtcb, rtcb);
+      up_switch_context(this_task(), rtcb);
     }
 }
diff --git a/sched/mqueue/msgrcv.c b/sched/mqueue/msgrcv.c
index 6823169510a..a67cfd13d9c 100644
--- a/sched/mqueue/msgrcv.c
+++ b/sched/mqueue/msgrcv.c
@@ -266,7 +266,7 @@ ssize_t msgrcv(int msqid, FAR void *msgp, size_t msgsz, 
long msgtyp,
 
       if (nxsched_add_readytorun(btcb))
         {
-          up_switch_context(btcb, rtcb);
+          up_switch_context(this_task(), rtcb);
         }
     }
 
diff --git a/sched/mqueue/msgsnd.c b/sched/mqueue/msgsnd.c
index 4384af24b19..6ddd94b9776 100644
--- a/sched/mqueue/msgsnd.c
+++ b/sched/mqueue/msgsnd.c
@@ -259,7 +259,7 @@ int msgsnd(int msqid, FAR const void *msgp, size_t msgsz, 
int msgflg)
 
           if (nxsched_add_readytorun(btcb))
             {
-              up_switch_context(btcb, rtcb);
+              up_switch_context(this_task(), rtcb);
             }
         }
     }
diff --git a/sched/paging/pg_worker.c b/sched/paging/pg_worker.c
index bd554046667..c7816369a3d 100644
--- a/sched/paging/pg_worker.c
+++ b/sched/paging/pg_worker.c
@@ -297,7 +297,7 @@ static inline bool pg_dequeue(void)
 
           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))
     {
-      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))
                 {
-                  up_switch_context(g_pftcb, wtcb);
+                  up_switch_context(this_task(), wtcb);
                 }
 
               /* 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))
             {
-              up_switch_context(g_pftcb, wtcb);
+              up_switch_context(this_task(), wtcb);
             }
         }
 
diff --git a/sched/semaphore/sem_post.c b/sched/semaphore/sem_post.c
index ae048194929..cbf5758f67e 100644
--- a/sched/semaphore/sem_post.c
+++ b/sched/semaphore/sem_post.c
@@ -221,7 +221,7 @@ int nxsem_post_slow(FAR sem_t *sem)
 
           if (nxsched_add_readytorun(stcb))
             {
-              up_switch_context(stcb, rtcb);
+              up_switch_context(this_task(), rtcb);
             }
         }
     }
diff --git a/sched/semaphore/sem_waitirq.c b/sched/semaphore/sem_waitirq.c
index 3fc13297978..1b38b3faaa4 100644
--- a/sched/semaphore/sem_waitirq.c
+++ b/sched/semaphore/sem_waitirq.c
@@ -125,6 +125,6 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
 
   if (nxsched_add_readytorun(wtcb))
     {
-      up_switch_context(wtcb, rtcb);
+      up_switch_context(this_task(), rtcb);
     }
 }
diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c
index 12a6bb62140..82867e31ee0 100644
--- a/sched/signal/sig_dispatch.c
+++ b/sched/signal/sig_dispatch.c
@@ -556,7 +556,7 @@ int nxsig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t 
*info,
 
           if (nxsched_add_readytorun(stcb))
             {
-              up_switch_context(stcb, rtcb);
+              up_switch_context(this_task(), rtcb);
             }
 
 #ifdef CONFIG_LIB_SYSCALL
@@ -614,7 +614,7 @@ int nxsig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t 
*info,
 
           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))
             {
-              up_switch_context(stcb, rtcb);
+              up_switch_context(this_task(), rtcb);
             }
 #endif
         }
diff --git a/sched/signal/sig_timedwait.c b/sched/signal/sig_timedwait.c
index 4a0ce54ab7e..fb94a9295fc 100644
--- a/sched/signal/sig_timedwait.c
+++ b/sched/signal/sig_timedwait.c
@@ -117,7 +117,7 @@ static void nxsig_timeout(wdparm_t arg)
 
       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))
         {
-          up_switch_context(wtcb, rtcb);
+          up_switch_context(this_task(), rtcb);
         }
     }
 
diff --git a/sched/task/task_activate.c b/sched/task/task_activate.c
index 5c71f9131b8..727d1acad15 100644
--- a/sched/task/task_activate.c
+++ b/sched/task/task_activate.c
@@ -95,7 +95,7 @@ void nxtask_activate(FAR struct tcb_s *tcb)
 
   if (nxsched_add_readytorun(tcb))
     {
-      up_switch_context(tcb, rtcb);
+      up_switch_context(this_task(), rtcb);
     }
 
   leave_critical_section(flags);

Reply via email to