This is an automated email from the ASF dual-hosted git repository. ligd pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 7c01281757d6b7bd5729153916edde2890bbc3c9 Author: guoshengyuan1 <[email protected]> AuthorDate: Tue Sep 23 10:19:26 2025 +0800 arm: replace all nxsched_suspend/resume_*** with nxsched_switch_context The arm-m architecture svc call will trigger an interrupt, and the actual context switch is executed after doirq is completed, so only the scheduling information needs to be updated in doirq. In the arm-a/r architecture, interrupts and syscalls are independent, and scheduling information needs to be updated in both locations Co-authored-by: yinshengkai <[email protected]> Signed-off-by: guoshengyuan1 <[email protected]> --- arch/arm/src/arm/arm_doirq.c | 7 ++++--- arch/arm/src/arm/arm_syscall.c | 9 +++++++-- arch/arm/src/armv6-m/arm_doirq.c | 9 ++++++--- arch/arm/src/armv7-a/arm_doirq.c | 7 ++++--- arch/arm/src/armv7-a/arm_syscall.c | 9 +++++++-- arch/arm/src/armv7-m/arm_doirq.c | 9 ++++++--- arch/arm/src/armv7-r/arm_doirq.c | 7 ++++--- arch/arm/src/armv7-r/arm_syscall.c | 9 +++++++-- arch/arm/src/armv8-m/arm_doirq.c | 9 ++++++--- arch/arm/src/armv8-r/arm_doirq.c | 7 ++++--- arch/arm/src/armv8-r/arm_syscall.c | 22 +++++++++++++--------- arch/arm64/src/common/arm64_doirq.c | 7 ++++--- arch/arm64/src/common/arm64_syscall.c | 7 +------ 13 files changed, 73 insertions(+), 45 deletions(-) diff --git a/arch/arm/src/arm/arm_doirq.c b/arch/arm/src/arm/arm_doirq.c index 8273de97beb..28d3fc780d1 100644 --- a/arch/arm/src/arm/arm_doirq.c +++ b/arch/arm/src/arm/arm_doirq.c @@ -88,6 +88,8 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) if (regs != tcb->xcp.regs) { + struct tcb_s **running_task = &g_running_tasks[this_cpu()]; + #ifdef CONFIG_ARCH_ADDRENV /* Make sure that the address environment for the previously * running task is closed down gracefully (data caches dump, @@ -100,15 +102,14 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) /* Update scheduler parameters */ - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(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. */ - g_running_tasks[this_cpu()] = tcb; + *running_task = tcb; regs = tcb->xcp.regs; } diff --git a/arch/arm/src/arm/arm_syscall.c b/arch/arm/src/arm/arm_syscall.c index e549a8b2f98..d1489cea10f 100644 --- a/arch/arm/src/arm/arm_syscall.c +++ b/arch/arm/src/arm/arm_syscall.c @@ -92,10 +92,15 @@ uint32_t *arm_syscall(uint32_t *regs) /* Update scheduler parameters */ - nxsched_resume_scheduler(tcb); + nxsched_switch_context(*running_task, tcb); case SYS_restore_context: - nxsched_suspend_scheduler(*running_task); + + /* No context switch occurs in SYS_restore_context, or the + * context switch has been completed, so there is no + * need to update scheduler parameters. + */ + *running_task = tcb; /* Restore the cpu lock */ diff --git a/arch/arm/src/armv6-m/arm_doirq.c b/arch/arm/src/armv6-m/arm_doirq.c index c3ba52564a2..24ef364482f 100644 --- a/arch/arm/src/armv6-m/arm_doirq.c +++ b/arch/arm/src/armv6-m/arm_doirq.c @@ -102,10 +102,13 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) tcb = this_task(); - /* Update scheduler parameters */ + /* Update scheduler parameters. + * The arm-m architecture svc call will trigger an interrupt, + * and the actual context switch is executed after doirq is completed, + * so only the scheduling information needs to be updated in doirq. + */ - nxsched_suspend_scheduler(*running_task); - nxsched_resume_scheduler(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 diff --git a/arch/arm/src/armv7-a/arm_doirq.c b/arch/arm/src/armv7-a/arm_doirq.c index 2de7bfcc02a..3bed25c02e1 100644 --- a/arch/arm/src/armv7-a/arm_doirq.c +++ b/arch/arm/src/armv7-a/arm_doirq.c @@ -88,6 +88,8 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) if (regs != tcb->xcp.regs) { + struct tcb_s **running_task = &g_running_tasks[this_cpu()]; + #ifdef CONFIG_ARCH_ADDRENV /* Make sure that the address environment for the previously * running task is closed down gracefully (data caches dump, @@ -100,15 +102,14 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) /* Update scheduler parameters */ - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(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. */ - g_running_tasks[this_cpu()] = tcb; + *running_task = tcb; regs = tcb->xcp.regs; } diff --git a/arch/arm/src/armv7-a/arm_syscall.c b/arch/arm/src/armv7-a/arm_syscall.c index f60d4d7f9a9..9bc9fcc4712 100644 --- a/arch/arm/src/armv7-a/arm_syscall.c +++ b/arch/arm/src/armv7-a/arm_syscall.c @@ -270,10 +270,15 @@ uint32_t *arm_syscall(uint32_t *regs) /* Update scheduler parameters */ - nxsched_resume_scheduler(tcb); + nxsched_switch_context(*running_task, tcb); case SYS_restore_context: - nxsched_suspend_scheduler(*running_task); + + /* No context switch occurs in SYS_restore_context, or the + * context switch has been completed, so there is no + * need to update scheduler parameters. + */ + *running_task = 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 9dff88e5143..c3126341e33 100644 --- a/arch/arm/src/armv7-m/arm_doirq.c +++ b/arch/arm/src/armv7-m/arm_doirq.c @@ -102,10 +102,13 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) tcb = this_task(); - /* Update scheduler parameters */ + /* Update scheduler parameters. + * The arm-m architecture svc call will trigger an interrupt, + * and the actual context switch is executed after doirq is completed, + * so only the scheduling information needs to be updated in doirq. + */ - nxsched_suspend_scheduler(*running_task); - nxsched_resume_scheduler(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 diff --git a/arch/arm/src/armv7-r/arm_doirq.c b/arch/arm/src/armv7-r/arm_doirq.c index f4760dcd1d6..f87c4fe7446 100644 --- a/arch/arm/src/armv7-r/arm_doirq.c +++ b/arch/arm/src/armv7-r/arm_doirq.c @@ -77,17 +77,18 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) if (regs != tcb->xcp.regs) { + struct tcb_s **running_task = &g_running_tasks[this_cpu()]; + /* Update scheduler parameters */ - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(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. */ - g_running_tasks[this_cpu()] = tcb; + *running_task = tcb; regs = tcb->xcp.regs; } diff --git a/arch/arm/src/armv7-r/arm_syscall.c b/arch/arm/src/armv7-r/arm_syscall.c index 283c029e1ce..bd2fa08862f 100644 --- a/arch/arm/src/armv7-r/arm_syscall.c +++ b/arch/arm/src/armv7-r/arm_syscall.c @@ -267,10 +267,15 @@ uint32_t *arm_syscall(uint32_t *regs) /* Update scheduler parameters */ - nxsched_resume_scheduler(tcb); + nxsched_switch_context(*running_task, tcb); case SYS_restore_context: - nxsched_suspend_scheduler(*running_task); + + /* No context switch occurs in SYS_restore_context, or the + * context switch has been completed, so there is no + * need to update scheduler parameters. + */ + *running_task = 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 3128090c2b4..a86de9f7e78 100644 --- a/arch/arm/src/armv8-m/arm_doirq.c +++ b/arch/arm/src/armv8-m/arm_doirq.c @@ -113,10 +113,13 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) tcb = this_task(); - /* Update scheduler parameters */ + /* Update scheduler parameters. + * The arm-m architecture svc call will trigger an interrupt, + * and the actual context switch is executed after doirq is completed, + * so only the scheduling information needs to be updated in doirq. + */ - nxsched_suspend_scheduler(*running_task); - nxsched_resume_scheduler(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 diff --git a/arch/arm/src/armv8-r/arm_doirq.c b/arch/arm/src/armv8-r/arm_doirq.c index b8dfe8ce519..69fcffc29e2 100644 --- a/arch/arm/src/armv8-r/arm_doirq.c +++ b/arch/arm/src/armv8-r/arm_doirq.c @@ -78,17 +78,18 @@ uint32_t *arm_doirq(int irq, uint32_t *regs) if (regs != tcb->xcp.regs) { + struct tcb_s **running_task = &g_running_tasks[this_cpu()]; + /* Update scheduler parameters */ - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(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. */ - g_running_tasks[this_cpu()] = tcb; + *running_task = tcb; regs = tcb->xcp.regs; } diff --git a/arch/arm/src/armv8-r/arm_syscall.c b/arch/arm/src/armv8-r/arm_syscall.c index 09e5ac374b8..0aa7af9fcc1 100644 --- a/arch/arm/src/armv8-r/arm_syscall.c +++ b/arch/arm/src/armv8-r/arm_syscall.c @@ -159,7 +159,7 @@ static void dispatch_syscall(void) uint32_t *arm_syscall(uint32_t *regs) { int cpu = this_cpu(); - struct tcb_s *running_task = g_running_tasks[cpu]; + struct tcb_s **running_task = &g_running_tasks[cpu]; struct tcb_s *tcb = this_task(); uint32_t cmd; #ifdef CONFIG_BUILD_PROTECTED @@ -180,13 +180,13 @@ uint32_t *arm_syscall(uint32_t *regs) cmd = regs[REG_R0]; - /* if cmd == SYS_restore_context running_task->xcp.regs is valid + /* if cmd == SYS_restore_context (*running_task)->xcp.regs is valid * should not be overwritten */ if (cmd != SYS_restore_context) { - running_task->xcp.regs = regs; + (*running_task)->xcp.regs = regs; } /* The SVCall software interrupt is called with R0 = system call command @@ -267,12 +267,16 @@ uint32_t *arm_syscall(uint32_t *regs) /* Update scheduler parameters */ - nxsched_resume_scheduler(tcb); + nxsched_switch_context(*running_task, tcb); case SYS_restore_context: - nxsched_suspend_scheduler(running_task); - running_task = tcb; - g_running_tasks[cpu] = running_task; + /* No context switch occurs in SYS_restore_context, or the + * context switch has been completed, so there is no + * need to update scheduler parameters. + */ + + *running_task = tcb; + g_running_tasks[cpu] = *running_task; /* Restore the cpu lock */ @@ -554,11 +558,11 @@ uint32_t *arm_syscall(uint32_t *regs) up_set_interrupt_context(false); - /* running_task->xcp.regs is about to become invalid + /* (*running_task)->xcp.regs is about to become invalid * and will be marked as NULL to avoid misusage. */ - running_task->xcp.regs = NULL; + (*running_task)->xcp.regs = NULL; /* Return the last value of curent_regs. This supports context switches * on return from the exception. That capability is only used with the diff --git a/arch/arm64/src/common/arm64_doirq.c b/arch/arm64/src/common/arm64_doirq.c index ee470050092..5d3043b2d09 100644 --- a/arch/arm64/src/common/arm64_doirq.c +++ b/arch/arm64/src/common/arm64_doirq.c @@ -85,6 +85,8 @@ uint64_t *arm64_doirq(int irq, uint64_t * regs) if (regs != tcb->xcp.regs) { + struct tcb_s **running_task = &g_running_tasks[this_cpu()]; + /* need to do a context switch */ #ifdef CONFIG_ARCH_ADDRENV @@ -99,15 +101,14 @@ uint64_t *arm64_doirq(int irq, uint64_t * regs) /* Update scheduler parameters */ - nxsched_suspend_scheduler(g_running_tasks[this_cpu()]); - nxsched_resume_scheduler(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. */ - g_running_tasks[this_cpu()] = tcb; + *running_task = tcb; regs = tcb->xcp.regs; } diff --git a/arch/arm64/src/common/arm64_syscall.c b/arch/arm64/src/common/arm64_syscall.c index 4e44f5df69b..166dc8963d0 100644 --- a/arch/arm64/src/common/arm64_syscall.c +++ b/arch/arm64/src/common/arm64_syscall.c @@ -187,10 +187,6 @@ uint64_t *arm64_syscall(uint64_t *regs) { case SYS_restore_context: - /* Update scheduler parameters */ - - nxsched_resume_scheduler(tcb); - /* Restore the cpu lock */ restore_critical_section(tcb, cpu); @@ -203,8 +199,7 @@ uint64_t *arm64_syscall(uint64_t *regs) /* Update scheduler parameters */ - nxsched_suspend_scheduler(*running_task); - nxsched_resume_scheduler(tcb); + nxsched_switch_context(*running_task, tcb); *running_task = tcb; /* Restore the cpu lock */
