This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 8786c814f0022b5f67f24ba3dc107ab6e991f88c Author: zhangyu117 <[email protected]> AuthorDate: Mon Dec 16 15:50:01 2024 +0800 arch/tricore: syscall SYS_switch_context and SYS_restore_context use 0 para after task switch optimization, we can just use g_running_tasks and this_task() without pass params Signed-off-by: zhangyu117 <[email protected]> --- arch/tricore/include/irq.h | 5 +- arch/tricore/src/common/tricore_doirq.c | 19 ++++---- arch/tricore/src/common/tricore_exit.c | 10 +--- arch/tricore/src/common/tricore_internal.h | 5 +- arch/tricore/src/common/tricore_sigdeliver.c | 3 +- arch/tricore/src/common/tricore_svcall.c | 70 +++++++--------------------- 6 files changed, 31 insertions(+), 81 deletions(-) diff --git a/arch/tricore/include/irq.h b/arch/tricore/include/irq.h index 0c1178673d6..f1018dcb667 100644 --- a/arch/tricore/include/irq.h +++ b/arch/tricore/include/irq.h @@ -220,10 +220,9 @@ static inline_function uintptr_t up_getusrsp(void *regs) do { \ if (!up_interrupt_context()) \ { \ - nxsched_switch_context(rtcb, tcb); \ - sys_call2(SYS_switch_context, (uintptr_t)&rtcb->xcp.regs, \ - (uintptr_t)tcb->xcp.regs); \ + sys_call0(SYS_switch_context); \ } \ + UNUSED(rtcb); \ } while (0) /**************************************************************************** diff --git a/arch/tricore/src/common/tricore_doirq.c b/arch/tricore/src/common/tricore_doirq.c index 228cb2de744..02da6543d69 100644 --- a/arch/tricore/src/common/tricore_doirq.c +++ b/arch/tricore/src/common/tricore_doirq.c @@ -46,8 +46,8 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255) { - struct tcb_s *running_task = g_running_tasks[this_cpu()]; - struct tcb_s *tcb; + struct tcb_s **running_task = &g_running_tasks[this_cpu()]; + struct tcb_s *tcb = this_task(); #ifdef CONFIG_SUPPRESS_INTERRUPTS PANIC(); @@ -58,9 +58,9 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255) icr.U = __mfcr(CPU_ICR); regs = tricore_csa2addr(__mfcr(CPU_PCXI)); - if (running_task != NULL) + if (*running_task != NULL) { - running_task->xcp.regs = regs; + (*running_task)->xcp.regs = regs; } board_autoled_on(LED_INIRQ); @@ -77,11 +77,9 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255) irq_dispatch(icr.B.CCPN, regs); - tcb = this_task(); - /* Check for a context switch. */ - if (regs != tcb->xcp.regs) + if (*running_task != tcb) { #ifdef CONFIG_ARCH_ADDRENV /* Make sure that the address environment for the previously @@ -95,15 +93,14 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255) /* Update scheduler parameters */ - nxsched_switch_context(running_task, tcb); + 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. */ - running_task = tcb; - g_running_tasks[this_cpu()] = running_task; + *running_task = tcb; __mtcr(CPU_PCXI, tricore_addr2csa(tcb->xcp.regs)); __isync(); @@ -117,7 +114,7 @@ IFX_INTERRUPT_INTERNAL(tricore_doirq, 0, 255) * and will be marked as NULL to avoid misusage. */ - running_task->xcp.regs = NULL; + (*running_task)->xcp.regs = NULL; board_autoled_off(LED_INIRQ); #endif } diff --git a/arch/tricore/src/common/tricore_exit.c b/arch/tricore/src/common/tricore_exit.c index ffa58ddc381..71201c3b3ec 100644 --- a/arch/tricore/src/common/tricore_exit.c +++ b/arch/tricore/src/common/tricore_exit.c @@ -56,25 +56,17 @@ void up_exit(int status) { - struct tcb_s *tcb = this_task(); - /* Destroy the task at the head of the ready to run list. */ nxtask_exit(); - /* Now, perform the context switch to the new ready-to-run task at the - * head of the list. - */ - - tcb = this_task(); - /* Scheduler parameters will update inside syscall */ g_running_tasks[this_cpu()] = NULL; /* Then switch contexts */ - tricore_fullcontextrestore(tcb->xcp.regs); + tricore_fullcontextrestore(); /* tricore_fullcontextrestore() should not return but could if the software * interrupts are disabled. diff --git a/arch/tricore/src/common/tricore_internal.h b/arch/tricore/src/common/tricore_internal.h index e75faf4d551..4cbc9b1e4b7 100644 --- a/arch/tricore/src/common/tricore_internal.h +++ b/arch/tricore/src/common/tricore_internal.h @@ -129,10 +129,7 @@ #define modreg32(v,m,a) putreg32((getreg32(a) & ~(m)) | ((v) & (m)), (a)) #define modreg64(v,m,a) putreg64((getreg64(a) & ~(m)) | ((v) & (m)), (a)) -/* Context switching */ - -#define tricore_fullcontextrestore(restoreregs) \ - sys_call1(SYS_restore_context, (uintptr_t)restoreregs); +#define tricore_fullcontextrestore() sys_call0(SYS_restore_context) /**************************************************************************** * Public Types diff --git a/arch/tricore/src/common/tricore_sigdeliver.c b/arch/tricore/src/common/tricore_sigdeliver.c index 5149dec75ba..bddb4892985 100644 --- a/arch/tricore/src/common/tricore_sigdeliver.c +++ b/arch/tricore/src/common/tricore_sigdeliver.c @@ -116,5 +116,6 @@ retry: board_autoled_off(LED_SIGNAL); - tricore_fullcontextrestore(regs); + rtcb->xcp.regs = regs; + tricore_fullcontextrestore(); } diff --git a/arch/tricore/src/common/tricore_svcall.c b/arch/tricore/src/common/tricore_svcall.c index 601f754da15..fb1f35c686b 100644 --- a/arch/tricore/src/common/tricore_svcall.c +++ b/arch/tricore/src/common/tricore_svcall.c @@ -56,16 +56,13 @@ void tricore_svcall(volatile void *trap) { - struct tcb_s *running_task; - struct tcb_s *tcb; + struct tcb_s **running_task = &g_running_tasks[this_cpu()]; + struct tcb_s *tcb = this_task(); uintptr_t *regs; uint32_t cmd; regs = (uintptr_t *)__mfcr(CPU_PCXI); - running_task = g_running_tasks[this_cpu()]; - tcb = this_task(); - /* DSYNC instruction should be executed immediately prior to the MTCR */ __dsync(); @@ -78,66 +75,33 @@ void tricore_svcall(volatile void *trap) cmd = regs[REG_D8]; + if (cmd != SYS_restore_context) + { + (*running_task)->xcp.regs = tricore_csa2addr(regs[REG_UPCXI]); + } + else + { + tricore_reclaim_csa(regs[REG_UPCXI]); + } + /* Handle the SVCall according to the command in R0 */ switch (cmd) { - /* R0=SYS_restore_context: This a restore context command: - * - * void tricore_fullcontextrestore(uint32_t *restoreregs) - * noreturn_function; - * - * At this point, the following values are saved in context: - * - * R0 = SYS_restore_context - * R1 = restoreregs - * - * In this case, we simply need to set g_current_regs to restore - * register area referenced in the saved R1. context == g_current_regs - * is the normal exception return. By setting g_current_regs = - * context[R1], we force the return to the saved context referenced - * in R1. - */ + case SYS_switch_context: + nxsched_switch_context(*running_task, tcb); case SYS_restore_context: - { - tricore_reclaim_csa(regs[REG_UPCXI]); - tcb->xcp.regs = (uintptr_t *)regs[REG_D9]; - } - break; - - case SYS_switch_context: - { - *(uintptr_t **)regs[REG_D9] = tricore_csa2addr(regs[REG_UPCXI]); - tcb->xcp.regs = (uintptr_t *)regs[REG_D10]; - } + *running_task = tcb; + regs[REG_UPCXI] = tricore_addr2csa(tcb->xcp.regs); + __isync(); break; default: - { - svcerr("ERROR: Bad SYS call: %d\n", (int)regs[REG_D0]); - } + svcerr("ERROR: Bad SYS call: %d\n", (int)regs[REG_D0]); break; } - if (regs != tcb->xcp.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(); - - regs[REG_UPCXI] = tricore_addr2csa(tcb->xcp.regs); - - __isync(); - } - /* Set irq flag */ up_set_interrupt_context(false);
