From 4057d86e2b68128e81fa9bc65ba1e4131c1c021f Mon Sep 17 00:00:00 2001 From: wangchengdong Date: Mon, 13 Oct 2025 17:44:28 +0800 Subject: [PATCH] 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 wangchengdong@lixiang.com --- 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);