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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4057d86e2b6 arch/tricore: Place nxsched_switch_context() at the 
correct location
4057d86e2b6 is described below

commit 4057d86e2b68128e81fa9bc65ba1e4131c1c021f
Author: wangchengdong <[email protected]>
AuthorDate: Mon Oct 13 17:44:28 2025 +0800

    arch/tricore: Place nxsched_switch_context() at the correct location
    
       The current implementation does not call
       nxsched_switch_context() exactly when a
       task switch occurs.
    
       This patch fixes the issue by placing the
       call at the correct location.
    
    Signed-off-by: Chengdong Wang [email protected]
---
 arch/tricore/src/common/tricore_svcall.c        | 13 ++++++++++++-
 arch/tricore/src/common/tricore_switchcontext.c |  4 ----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/arch/tricore/src/common/tricore_svcall.c 
b/arch/tricore/src/common/tricore_svcall.c
index a6040cf4693..575a43eebf5 100644
--- a/arch/tricore/src/common/tricore_svcall.c
+++ b/arch/tricore/src/common/tricore_svcall.c
@@ -56,11 +56,18 @@
 
 void tricore_svcall(volatile void *trap)
 {
+  struct tcb_s *running_task;
+  struct tcb_s *tcb;
+  int cpu = this_cpu();
+
   uintptr_t *regs;
   uint32_t cmd;
 
   regs = (uintptr_t *)__mfcr(CPU_PCXI);
 
+  running_task = g_running_tasks[cpu];
+  tcb = this_task();
+
   /* DSYNC instruction should be executed immediately prior to the MTCR */
 
   __dsync();
@@ -115,12 +122,16 @@ void tricore_svcall(volatile void *trap)
 
   if (regs != up_current_regs())
     {
+      /* Update scheduler parameters */
+
+      nxsched_switch_context(running_task, tcb);
+
       /* Record the new "running" task when context switch occurred.
        * g_running_tasks[] is only used by assertion logic for reporting
        * crashes.
        */
 
-      g_running_tasks[this_cpu()] = this_task();
+      g_running_tasks[cpu] = this_task();
 
       regs[REG_UPCXI] = (uintptr_t)up_current_regs();
 
diff --git a/arch/tricore/src/common/tricore_switchcontext.c 
b/arch/tricore/src/common/tricore_switchcontext.c
index 47aefd036eb..7d08421a8ff 100644
--- a/arch/tricore/src/common/tricore_switchcontext.c
+++ b/arch/tricore/src/common/tricore_switchcontext.c
@@ -80,10 +80,6 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb)
 
   else
     {
-      /* Update scheduler parameters */
-
-      nxsched_switch_context(rtcb, tcb);
-
       /* Then switch contexts */
 
       tricore_switchcontext(&rtcb->xcp.regs, tcb->xcp.regs);

Reply via email to