From d89f22eb9841e5529d6719a66ea5e59fd39bf614 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Fri, 29 Nov 2024 11:32:00 +0800 Subject: [PATCH] arm64: remove g_running_tasks[this_cpu()] = NULL reason: We hope to keep g_running_tasks valid forever. Signed-off-by: hujun5 --- arch/arm64/src/common/arm64_exit.c | 2 +- arch/arm64/src/common/arm64_sigdeliver.c | 1 - arch/arm64/src/common/arm64_syscall.c | 85 +++++++++--------------- 3 files changed, 32 insertions(+), 56 deletions(-) diff --git a/arch/arm64/src/common/arm64_exit.c b/arch/arm64/src/common/arm64_exit.c index 2d291a1599..d68b2cbb2e 100644 --- a/arch/arm64/src/common/arm64_exit.c +++ b/arch/arm64/src/common/arm64_exit.c @@ -65,7 +65,7 @@ void up_exit(int status) /* Scheduler parameters will update inside syscall */ - g_running_tasks[this_cpu()] = NULL; + g_running_tasks[this_cpu()] = this_task(); /* Then switch contexts */ diff --git a/arch/arm64/src/common/arm64_sigdeliver.c b/arch/arm64/src/common/arm64_sigdeliver.c index 6c283e43b8..b80a6011b4 100644 --- a/arch/arm64/src/common/arm64_sigdeliver.c +++ b/arch/arm64/src/common/arm64_sigdeliver.c @@ -161,6 +161,5 @@ retry: rtcb->irqcount--; #endif - g_running_tasks[this_cpu()] = NULL; arm64_fullcontextrestore(); } diff --git a/arch/arm64/src/common/arm64_syscall.c b/arch/arm64/src/common/arm64_syscall.c index f969c4eb5d..4ada7b2288 100644 --- a/arch/arm64/src/common/arm64_syscall.c +++ b/arch/arm64/src/common/arm64_syscall.c @@ -162,11 +162,6 @@ uint64_t *arm64_syscall(uint64_t *regs) uint64_t spsr; #endif - if (*running_task != NULL) - { - (*running_task)->xcp.regs = regs; - } - /* Nested interrupts are not supported */ DEBUGASSERT(regs); @@ -175,41 +170,40 @@ uint64_t *arm64_syscall(uint64_t *regs) cmd = regs[REG_X0]; + /* if cmd == SYS_restore_context (*running_task)->xcp.regs is valid + * should not be overwriten + */ + + if (cmd != SYS_restore_context) + { + (*running_task)->xcp.regs = regs; + } + arm64_dump_syscall(__func__, cmd, regs); switch (cmd) { - /* x0 = SYS_restore_context: Restore task context - * - * void arm64_fullcontextrestore(uint64_t *restoreregs) - * noreturn_function; - * - * At this point, the following values are saved in context: - * - * x0 = SYS_restore_context - * x1 = next - */ - case SYS_restore_context: + + /* Update scheduler parameters */ + + nxsched_resume_scheduler(tcb); + + /* Restore the cpu lock */ + + restore_critical_section(tcb, cpu); break; - - /* x0 = SYS_switch_context: This a switch context command: - * - * void arm64_switchcontext(struct tcb_s *prev, struct tcb_s *next); - * - * At this point, the following values are saved in context: - * - * x0 = SYS_switch_context - * x1 = prev - * x2 = next - * - * In this case, we do both: We save the context registers to the save - * register area reference by the saved contents of x1 and then set - * regs to the save register area referenced by the saved - * contents of x2. - */ - case SYS_switch_context: + + /* Update scheduler parameters */ + + nxsched_suspend_scheduler(*running_task); + nxsched_resume_scheduler(tcb); + *running_task = tcb; + + /* Restore the cpu lock */ + + restore_critical_section(tcb, cpu); break; #ifdef CONFIG_BUILD_KERNEL @@ -321,10 +315,6 @@ uint64_t *arm64_syscall(uint64_t *regs) break; } - if (*running_task != tcb) - { - tcb = current_task(cpu); - #ifdef CONFIG_ARCH_ADDRENV /* Make sure that the address environment for the previously * running task is closed down gracefully (data caches dump, @@ -332,24 +322,11 @@ uint64_t *arm64_syscall(uint64_t *regs) * thread at the head of the ready-to-run list. */ - addrenv_switch(NULL); + if (SYS_restore_context == cmd || SYS_switch_context == cmd) + { + addrenv_switch(NULL); + } #endif - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(*running_task); - nxsched_resume_scheduler(tcb); - - /* Record the new "running" task. g_running_tasks[] is only used by - * assertion logic for reporting crashes. - */ - - *running_task = tcb; - - /* Restore the cpu lock */ - - restore_critical_section(tcb, cpu); - } - return tcb->xcp.regs; }