diff --git a/arch/arm/src/arm/arm_doirq.c b/arch/arm/src/arm/arm_doirq.c index 6cc7da46bdef2..55e056a8ee2ac 100644 --- a/arch/arm/src/arm/arm_doirq.c +++ b/arch/arm/src/arm/arm_doirq.c @@ -103,6 +103,11 @@ 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 566d9390a00e3..3065a4f4dad09 100644 --- a/arch/arm/src/armv6-m/arm_doirq.c +++ b/arch/arm/src/armv6-m/arm_doirq.c @@ -75,6 +75,11 @@ 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 460bb9a6c478a..97feb8b8f61f6 100644 --- a/arch/arm/src/armv7-a/arm_doirq.c +++ b/arch/arm/src/armv7-a/arm_doirq.c @@ -98,6 +98,11 @@ 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 9a8df57bdd8dd..e2791e1817ceb 100644 --- a/arch/arm/src/armv7-a/arm_syscall.c +++ b/arch/arm/src/armv7-a/arm_syscall.c @@ -579,12 +579,18 @@ 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 c1370659c9e74..5c31de792ecf0 100644 --- a/arch/arm/src/armv7-m/arm_doirq.c +++ b/arch/arm/src/armv7-m/arm_doirq.c @@ -75,6 +75,11 @@ 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 7b08a7dd56326..dae25dd47e852 100644 --- a/arch/arm/src/armv7-r/arm_doirq.c +++ b/arch/arm/src/armv7-r/arm_doirq.c @@ -77,6 +77,11 @@ 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 66d2181618478..d7dcdbcfe9728 100644 --- a/arch/arm/src/armv7-r/arm_syscall.c +++ b/arch/arm/src/armv7-r/arm_syscall.c @@ -566,11 +566,17 @@ 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 e35cbb0eef8cc..3e2fe2e961ff0 100644 --- a/arch/arm/src/armv8-m/arm_doirq.c +++ b/arch/arm/src/armv8-m/arm_doirq.c @@ -124,6 +124,11 @@ 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 2863292052b90..98c5dc4bc22d0 100644 --- a/arch/arm/src/armv8-r/arm_doirq.c +++ b/arch/arm/src/armv8-r/arm_doirq.c @@ -72,10 +72,16 @@ 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 1f82dc20e7b02..285613ed4b057 100644 --- a/arch/arm/src/armv8-r/arm_syscall.c +++ b/arch/arm/src/armv8-r/arm_syscall.c @@ -565,11 +565,17 @@ 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 ab266f29fb8f0..946e6441c81b2 100644 --- a/arch/arm/src/common/arm_switchcontext.c +++ b/arch/arm/src/common/arm_switchcontext.c @@ -55,27 +55,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()) + 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 af0a5abe444c2..9806c2c41c043 100644 --- a/arch/arm64/src/common/arm64_doirq.c +++ b/arch/arm64/src/common/arm64_doirq.c @@ -96,6 +96,11 @@ 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 b5ab2234d19c3..51210b228cc64 100644 --- a/arch/arm64/src/common/arm64_switchcontext.c +++ b/arch/arm64/src/common/arm64_switchcontext.c @@ -55,27 +55,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()) + 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 318e7e0cf60f3..5a6c91b0c4c5f 100644 --- a/arch/arm64/src/common/arm64_syscall.c +++ b/arch/arm64/src/common/arm64_syscall.c @@ -236,6 +236,9 @@ 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, @@ -246,12 +249,15 @@ 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 acd5ca82b670c..c977dc138e8d5 100644 --- a/arch/ceva/src/common/ceva_doirq.c +++ b/arch/ceva/src/common/ceva_doirq.c @@ -78,6 +78,11 @@ 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 4b55564427886..3f5311064f770 100644 --- a/arch/ceva/src/common/ceva_switchcontext.c +++ b/arch/ceva/src/common/ceva_switchcontext.c @@ -69,10 +69,6 @@ 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()) @@ -83,10 +79,6 @@ 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); @@ -96,10 +88,6 @@ 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 895bd910ded1f..23fe5d2bfb30d 100644 --- a/arch/risc-v/src/common/riscv_doirq.c +++ b/arch/risc-v/src/common/riscv_doirq.c @@ -109,6 +109,11 @@ 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 d7df00ef86bea..16252b8a2ad89 100644 --- a/arch/risc-v/src/common/riscv_switchcontext.c +++ b/arch/risc-v/src/common/riscv_switchcontext.c @@ -57,10 +57,6 @@ 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()) @@ -71,10 +67,6 @@ 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. */ @@ -86,10 +78,6 @@ 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 3e9175ea0e379..091d75ff74b11 100644 --- a/arch/x86/src/qemu/qemu_handlers.c +++ b/arch/x86/src/qemu/qemu_handlers.c @@ -116,6 +116,11 @@ 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 d876f20a30e5b..6a31ca1287031 100644 --- a/arch/x86_64/src/common/x86_64_switchcontext.c +++ b/arch/x86_64/src/common/x86_64_switchcontext.c @@ -59,10 +59,6 @@ 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()) @@ -75,10 +71,6 @@ 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. */ @@ -94,6 +86,8 @@ 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 @@ -105,19 +99,20 @@ void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) addrenv_switch(tcb); #endif - /* Update scheduler parameters */ - - nxsched_resume_scheduler(tcb); /* Restore the cpu lock */ - restore_critical_section(tcb, this_cpu()); + restore_critical_section(tcb, cpu); + + /* Update scheduler parameters */ + + nxsched_suspend_scheduler(g_running_tasks[cpu]); + nxsched_resume_scheduler(current_task(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 28a77e1c73e3d..4101c0f8a433b 100644 --- a/arch/x86_64/src/intel64/intel64_handlers.c +++ b/arch/x86_64/src/intel64/intel64_handlers.c @@ -97,6 +97,11 @@ 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 99856c1ed8bd4..daca91ba3eac8 100644 --- a/arch/xtensa/src/common/xtensa_irqdispatch.c +++ b/arch/xtensa/src/common/xtensa_irqdispatch.c @@ -82,6 +82,11 @@ 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 0f5c4ab865e84..a98e3e1069c37 100644 --- a/arch/xtensa/src/common/xtensa_switchcontext.c +++ b/arch/xtensa/src/common/xtensa_switchcontext.c @@ -57,39 +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_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. */