From d0ae4f40f71e0e3f2d95fc521f0b6db43414fbe2 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 27 Sep 2024 13:43:54 +0900 Subject: [PATCH] Revert "arch: change nxsched_suspend/resume_scheduler() called position" This reverts commit 35c8c80a00a99ff0e19d51eaa74165bd830a36f8. because it caused a regression. with esp32-devkitc:knsh, nsh prompt on serial console doesn't seem to accept any input. --- arch/arm/src/arm/arm_doirq.c | 5 --- arch/arm/src/armv6-m/arm_doirq.c | 5 --- arch/arm/src/armv7-a/arm_doirq.c | 5 --- arch/arm/src/armv7-a/arm_syscall.c | 10 ++---- arch/arm/src/armv7-m/arm_doirq.c | 5 --- arch/arm/src/armv7-r/arm_doirq.c | 5 --- arch/arm/src/armv7-r/arm_syscall.c | 8 +---- arch/arm/src/armv8-m/arm_doirq.c | 5 --- arch/arm/src/armv8-r/arm_doirq.c | 8 +---- arch/arm/src/armv8-r/arm_syscall.c | 8 +---- arch/arm/src/common/arm_switchcontext.c | 19 +++++++++++- arch/arm64/src/common/arm64_doirq.c | 5 --- arch/arm64/src/common/arm64_switchcontext.c | 19 +++++++++++- arch/arm64/src/common/arm64_syscall.c | 10 ++---- arch/ceva/src/common/ceva_doirq.c | 5 --- arch/ceva/src/common/ceva_switchcontext.c | 12 +++++++ arch/risc-v/src/common/riscv_doirq.c | 5 --- arch/risc-v/src/common/riscv_switchcontext.c | 12 +++++++ arch/x86/src/qemu/qemu_handlers.c | 5 --- arch/x86_64/src/common/x86_64_switchcontext.c | 21 ++++++++----- arch/x86_64/src/intel64/intel64_handlers.c | 5 --- arch/xtensa/src/common/xtensa_irqdispatch.c | 5 --- arch/xtensa/src/common/xtensa_switchcontext.c | 31 ++++++++++++++++++- 23 files changed, 110 insertions(+), 108 deletions(-) diff --git a/arch/arm/src/arm/arm_doirq.c b/arch/arm/src/arm/arm_doirq.c index 55e056a8ee2ac..6cc7da46bdef2 100644 --- a/arch/arm/src/arm/arm_doirq.c +++ b/arch/arm/src/arm/arm_doirq.c @@ -103,11 +103,6 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) addrenv_switch(NULL); #endif - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(tcb); - /* Record the new "running" task when context switch occurred. * g_running_tasks[] is only used by assertion logic for reporting * crashes. diff --git a/arch/arm/src/armv6-m/arm_doirq.c b/arch/arm/src/armv6-m/arm_doirq.c index 3065a4f4dad09..566d9390a00e3 100644 --- a/arch/arm/src/armv6-m/arm_doirq.c +++ b/arch/arm/src/armv6-m/arm_doirq.c @@ -75,11 +75,6 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) if (regs != tcb->xcp.regs) { - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(tcb); - /* Record the new "running" task when context switch occurred. * g_running_tasks[] is only used by assertion logic for reporting * crashes. diff --git a/arch/arm/src/armv7-a/arm_doirq.c b/arch/arm/src/armv7-a/arm_doirq.c index 97feb8b8f61f6..460bb9a6c478a 100644 --- a/arch/arm/src/armv7-a/arm_doirq.c +++ b/arch/arm/src/armv7-a/arm_doirq.c @@ -98,11 +98,6 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) addrenv_switch(NULL); #endif - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(tcb); - /* Record the new "running" task when context switch occurred. * g_running_tasks[] is only used by assertion logic for reporting * crashes. diff --git a/arch/arm/src/armv7-a/arm_syscall.c b/arch/arm/src/armv7-a/arm_syscall.c index e2791e1817ceb..9a8df57bdd8dd 100644 --- a/arch/arm/src/armv7-a/arm_syscall.c +++ b/arch/arm/src/armv7-a/arm_syscall.c @@ -579,18 +579,12 @@ uint32_t *arm_syscall(uint32_t *regs) addrenv_switch(NULL); #endif - cpu = this_cpu(); - tcb = current_task(cpu); - - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[cpu]); - nxsched_resume_scheduler(tcb); - /* Record the new "running" task. g_running_tasks[] is only used by * assertion logic for reporting crashes. */ + cpu = this_cpu(); + tcb = current_task(cpu); g_running_tasks[cpu] = tcb; /* Restore the cpu lock */ diff --git a/arch/arm/src/armv7-m/arm_doirq.c b/arch/arm/src/armv7-m/arm_doirq.c index 5c31de792ecf0..c1370659c9e74 100644 --- a/arch/arm/src/armv7-m/arm_doirq.c +++ b/arch/arm/src/armv7-m/arm_doirq.c @@ -75,11 +75,6 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) if (regs != tcb->xcp.regs) { - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(tcb); - /* Record the new "running" task when context switch occurred. * g_running_tasks[] is only used by assertion logic for reporting * crashes. diff --git a/arch/arm/src/armv7-r/arm_doirq.c b/arch/arm/src/armv7-r/arm_doirq.c index dae25dd47e852..7b08a7dd56326 100644 --- a/arch/arm/src/armv7-r/arm_doirq.c +++ b/arch/arm/src/armv7-r/arm_doirq.c @@ -77,11 +77,6 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) if (regs != tcb->xcp.regs) { - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(tcb); - /* Record the new "running" task when context switch occurred. * g_running_tasks[] is only used by assertion logic for reporting * crashes. diff --git a/arch/arm/src/armv7-r/arm_syscall.c b/arch/arm/src/armv7-r/arm_syscall.c index d7dcdbcfe9728..66d2181618478 100644 --- a/arch/arm/src/armv7-r/arm_syscall.c +++ b/arch/arm/src/armv7-r/arm_syscall.c @@ -566,17 +566,11 @@ uint32_t *arm_syscall(uint32_t *regs) if (regs != tcb->xcp.regs) { - cpu = this_cpu(); - - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[cpu]); - nxsched_resume_scheduler(tcb); - /* Record the new "running" task. g_running_tasks[] is only used by * assertion logic for reporting crashes. */ + cpu = this_cpu(); g_running_tasks[cpu] = tcb; /* Restore the cpu lock */ diff --git a/arch/arm/src/armv8-m/arm_doirq.c b/arch/arm/src/armv8-m/arm_doirq.c index 3e2fe2e961ff0..e35cbb0eef8cc 100644 --- a/arch/arm/src/armv8-m/arm_doirq.c +++ b/arch/arm/src/armv8-m/arm_doirq.c @@ -124,11 +124,6 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) if (regs != tcb->xcp.regs) { - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(tcb); - /* Record the new "running" task when context switch occurred. * g_running_tasks[] is only used by assertion logic for reporting * crashes. diff --git a/arch/arm/src/armv8-r/arm_doirq.c b/arch/arm/src/armv8-r/arm_doirq.c index 98c5dc4bc22d0..2863292052b90 100644 --- a/arch/arm/src/armv8-r/arm_doirq.c +++ b/arch/arm/src/armv8-r/arm_doirq.c @@ -72,16 +72,10 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) /* Deliver the IRQ */ irq_dispatch(irq, regs); + tcb = this_task(); if (regs != tcb->xcp.regs) { - tcb = this_task(); - - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(tcb); - /* Record the new "running" task when context switch occurred. * g_running_tasks[] is only used by assertion logic for reporting * crashes. diff --git a/arch/arm/src/armv8-r/arm_syscall.c b/arch/arm/src/armv8-r/arm_syscall.c index 285613ed4b057..1f82dc20e7b02 100644 --- a/arch/arm/src/armv8-r/arm_syscall.c +++ b/arch/arm/src/armv8-r/arm_syscall.c @@ -565,17 +565,11 @@ uint32_t *arm_syscall(uint32_t *regs) if (regs != tcb->xcp.regs) { - cpu = this_cpu(); - - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[cpu]); - nxsched_resume_scheduler(tcb); - /* Record the new "running" task. g_running_tasks[] is only used by * assertion logic for reporting crashes. */ + cpu = this_cpu(); g_running_tasks[cpu] = tcb; /* Restore the cpu lock */ diff --git a/arch/arm/src/common/arm_switchcontext.c b/arch/arm/src/common/arm_switchcontext.c index 946e6441c81b2..ab266f29fb8f0 100644 --- a/arch/arm/src/common/arm_switchcontext.c +++ b/arch/arm/src/common/arm_switchcontext.c @@ -55,10 +55,27 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) { + /* Update scheduler parameters */ + + nxsched_suspend_scheduler(rtcb); + /* Are we in an interrupt handler? */ - if (!up_interrupt_context()) + if (up_interrupt_context()) { + /* Update scheduler parameters */ + + nxsched_resume_scheduler(tcb); + } + + /* No, then we will need to perform the user context switch */ + + else + { + /* Update scheduler parameters */ + + nxsched_resume_scheduler(tcb); + /* Switch context to the context of the task at the head of the * ready to run list. */ diff --git a/arch/arm64/src/common/arm64_doirq.c b/arch/arm64/src/common/arm64_doirq.c index 9806c2c41c043..af0a5abe444c2 100644 --- a/arch/arm64/src/common/arm64_doirq.c +++ b/arch/arm64/src/common/arm64_doirq.c @@ -96,11 +96,6 @@ uint64_t *arm64_doirq(int irq, uint64_t * regs) addrenv_switch(NULL); #endif - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(tcb); - /* Record the new "running" task when context switch occurred. * g_running_tasks[] is only used by assertion logic for reporting * crashes. diff --git a/arch/arm64/src/common/arm64_switchcontext.c b/arch/arm64/src/common/arm64_switchcontext.c index 51210b228cc64..b5ab2234d19c3 100644 --- a/arch/arm64/src/common/arm64_switchcontext.c +++ b/arch/arm64/src/common/arm64_switchcontext.c @@ -55,10 +55,27 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) { + /* Update scheduler parameters */ + + nxsched_suspend_scheduler(rtcb); + /* Are we in an interrupt handler? */ - if (!up_interrupt_context()) + if (up_interrupt_context()) { + /* Update scheduler parameters */ + + nxsched_resume_scheduler(tcb); + } + + /* No, then we will need to perform the user context switch */ + + else + { + /* Update scheduler parameters */ + + nxsched_resume_scheduler(tcb); + /* Switch context to the context of the task at the head of the * ready to run list. */ diff --git a/arch/arm64/src/common/arm64_syscall.c b/arch/arm64/src/common/arm64_syscall.c index 5a6c91b0c4c5f..318e7e0cf60f3 100644 --- a/arch/arm64/src/common/arm64_syscall.c +++ b/arch/arm64/src/common/arm64_syscall.c @@ -236,9 +236,6 @@ uint64_t *arm64_syscall_switch(uint64_t * regs) if ((uint64_t *)f_regs != ret_regs) { - cpu = this_cpu(); - 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, @@ -249,15 +246,12 @@ uint64_t *arm64_syscall_switch(uint64_t * regs) addrenv_switch(NULL); #endif - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[cpu]); - nxsched_resume_scheduler(tcb); - /* Record the new "running" task. g_running_tasks[] is only used by * assertion logic for reporting crashes. */ + cpu = this_cpu(); + tcb = current_task(cpu); g_running_tasks[cpu] = tcb; /* Restore the cpu lock */ diff --git a/arch/ceva/src/common/ceva_doirq.c b/arch/ceva/src/common/ceva_doirq.c index c977dc138e8d5..acd5ca82b670c 100644 --- a/arch/ceva/src/common/ceva_doirq.c +++ b/arch/ceva/src/common/ceva_doirq.c @@ -78,11 +78,6 @@ uint32_t *ceva_doirq(int irq, uint32_t *regs) if (regs != up_current_regs()) { - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(this_task()); - /* Record the new "running" task when context switch occurred. * g_running_tasks[] is only used by assertion logic for reporting * crashes. diff --git a/arch/ceva/src/common/ceva_switchcontext.c b/arch/ceva/src/common/ceva_switchcontext.c index 3f5311064f770..4b55564427886 100644 --- a/arch/ceva/src/common/ceva_switchcontext.c +++ b/arch/ceva/src/common/ceva_switchcontext.c @@ -69,6 +69,10 @@ void ceva_switchcontext(uint32_t **saveregs, uint32_t *restoreregs) void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) { + /* Update scheduler parameters */ + + sched_suspend_scheduler(rtcb); + /* Are we in an interrupt handler? */ if (up_current_regs()) @@ -79,6 +83,10 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) rtcb->xcp.regs = up_current_regs(); + /* Update scheduler parameters */ + + sched_resume_scheduler(tcb); + /* Then switch contexts */ up_set_current_regs(tcb->xcp.regs); @@ -88,6 +96,10 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) else { + /* Update scheduler parameters */ + + sched_resume_scheduler(tcb); + /* Switch context to the context of the task at the head of the * ready to run list. */ diff --git a/arch/risc-v/src/common/riscv_doirq.c b/arch/risc-v/src/common/riscv_doirq.c index 23fe5d2bfb30d..895bd910ded1f 100644 --- a/arch/risc-v/src/common/riscv_doirq.c +++ b/arch/risc-v/src/common/riscv_doirq.c @@ -109,11 +109,6 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs) addrenv_switch(NULL); #endif - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(tcb); - /* Record the new "running" task when context switch occurred. * g_running_tasks[] is only used by assertion logic for reporting * crashes. diff --git a/arch/risc-v/src/common/riscv_switchcontext.c b/arch/risc-v/src/common/riscv_switchcontext.c index 16252b8a2ad89..d7df00ef86bea 100644 --- a/arch/risc-v/src/common/riscv_switchcontext.c +++ b/arch/risc-v/src/common/riscv_switchcontext.c @@ -57,6 +57,10 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) { + /* Update scheduler parameters */ + + nxsched_suspend_scheduler(rtcb); + /* Are we in an interrupt handler? */ if (up_interrupt_context()) @@ -67,6 +71,10 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) riscv_savecontext(rtcb); + /* Update scheduler parameters */ + + nxsched_resume_scheduler(tcb); + /* Then switch contexts. Any necessary address environment * changes will be made when the interrupt returns. */ @@ -78,6 +86,10 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) else { + /* Update scheduler parameters */ + + nxsched_resume_scheduler(tcb); + /* Then switch contexts */ riscv_switchcontext(rtcb, tcb); diff --git a/arch/x86/src/qemu/qemu_handlers.c b/arch/x86/src/qemu/qemu_handlers.c index 091d75ff74b11..3e9175ea0e379 100644 --- a/arch/x86/src/qemu/qemu_handlers.c +++ b/arch/x86/src/qemu/qemu_handlers.c @@ -116,11 +116,6 @@ static uint32_t *common_handler(int irq, uint32_t *regs) addrenv_switch(NULL); #endif - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(this_task()); - /* Record the new "running" task when context switch occurred. * g_running_tasks[] is only used by assertion logic for reporting * crashes. diff --git a/arch/x86_64/src/common/x86_64_switchcontext.c b/arch/x86_64/src/common/x86_64_switchcontext.c index 6a31ca1287031..d876f20a30e5b 100644 --- a/arch/x86_64/src/common/x86_64_switchcontext.c +++ b/arch/x86_64/src/common/x86_64_switchcontext.c @@ -59,6 +59,10 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) { int cpu; + /* Update scheduler parameters */ + + nxsched_suspend_scheduler(rtcb); + /* Are we in an interrupt handler? */ if (up_interrupt_context()) @@ -71,6 +75,10 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) x86_64_restore_auxstate(tcb); + /* Update scheduler parameters */ + + nxsched_resume_scheduler(tcb); + /* Then switch contexts. Any necessary address environment * changes will be made when the interrupt returns. */ @@ -86,8 +94,6 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) else if (!up_saveusercontext(rtcb->xcp.regs)) { - cpu = this_cpu(); - x86_64_restore_auxstate(tcb); #ifdef CONFIG_ARCH_ADDRENV @@ -99,20 +105,19 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) addrenv_switch(tcb); #endif + /* Update scheduler parameters */ - /* Restore the cpu lock */ - - restore_critical_section(tcb, cpu); + nxsched_resume_scheduler(tcb); - /* Update scheduler parameters */ + /* Restore the cpu lock */ - nxsched_suspend_scheduler(g_running_tasks[cpu]); - nxsched_resume_scheduler(current_task(cpu)); + restore_critical_section(tcb, this_cpu()); /* Record the new "running" task. g_running_tasks[] is only used by * assertion logic for reporting crashes. */ + cpu = this_cpu(); g_running_tasks[cpu] = current_task(cpu); /* Then switch contexts */ diff --git a/arch/x86_64/src/intel64/intel64_handlers.c b/arch/x86_64/src/intel64/intel64_handlers.c index 4101c0f8a433b..28a77e1c73e3d 100644 --- a/arch/x86_64/src/intel64/intel64_handlers.c +++ b/arch/x86_64/src/intel64/intel64_handlers.c @@ -97,11 +97,6 @@ static uint64_t *common_handler(int irq, uint64_t *regs) addrenv_switch(NULL); #endif - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[cpu]); - nxsched_resume_scheduler(this_task()); - /* Record the new "running" task when context switch occurred. * g_running_tasks[] is only used by assertion logic for reporting * crashes. diff --git a/arch/xtensa/src/common/xtensa_irqdispatch.c b/arch/xtensa/src/common/xtensa_irqdispatch.c index daca91ba3eac8..99856c1ed8bd4 100644 --- a/arch/xtensa/src/common/xtensa_irqdispatch.c +++ b/arch/xtensa/src/common/xtensa_irqdispatch.c @@ -82,11 +82,6 @@ uint32_t *xtensa_irq_dispatch(int irq, uint32_t *regs) addrenv_switch(NULL); #endif - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(this_task()); - /* Record the new "running" task when context switch occurred. * g_running_tasks[] is only used by assertion logic for reporting * crashes. diff --git a/arch/xtensa/src/common/xtensa_switchcontext.c b/arch/xtensa/src/common/xtensa_switchcontext.c index a98e3e1069c37..0f5c4ab865e84 100644 --- a/arch/xtensa/src/common/xtensa_switchcontext.c +++ b/arch/xtensa/src/common/xtensa_switchcontext.c @@ -57,10 +57,39 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) { + /* Update scheduler parameters */ + + nxsched_suspend_scheduler(rtcb); + /* Are we in an interrupt handler? */ - if (!up_current_regs()) + if (up_current_regs()) { + /* Yes, then we have to do things differently. + * Just copy the current_regs into the OLD rtcb. + */ + + xtensa_savestate(rtcb->xcp.regs); + + /* Update scheduler parameters */ + + nxsched_resume_scheduler(tcb); + + /* Then switch contexts. Any necessary address environment + * changes will be made when the interrupt returns. + */ + + xtensa_restorestate(tcb->xcp.regs); + } + + /* No, then we will need to perform the user context switch */ + + else + { + /* Reset scheduler parameters */ + + nxsched_resume_scheduler(tcb); + /* Switch context to the context of the task at the head of the * ready to run list. */