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


The following commit(s) were added to refs/heads/master by this push:
     new 0b3859521a arch: fix the sched parameter update when exiting
0b3859521a is described below

commit 0b3859521a6d7e0b67388c44c72aa8feb5a2b83b
Author: buxiasen <[email protected]>
AuthorDate: Thu Aug 1 23:05:29 2024 +0800

    arch: fix the sched parameter update when exiting
    
    Signed-off-by: buxiasen <[email protected]>
---
 arch/arm/src/arm/arm_syscall.c         | 6 ++++++
 arch/arm/src/common/arm_exit.c         | 6 ++----
 arch/arm64/src/common/arm64_exit.c     | 6 ++----
 arch/avr/src/common/avr_exit.c         | 1 +
 arch/hc/src/common/hc_exit.c           | 1 +
 arch/mips/src/common/mips_exit.c       | 6 ++----
 arch/misoc/src/lm32/lm32_exit.c        | 2 +-
 arch/misoc/src/minerva/minerva_exit.c  | 2 +-
 arch/or1k/src/common/or1k_exit.c       | 1 +
 arch/renesas/src/common/renesas_exit.c | 3 ++-
 arch/risc-v/src/common/riscv_exit.c    | 8 +-------
 arch/sim/src/sim/sim_exit.c            | 1 +
 arch/sparc/src/common/sparc_exit.c     | 4 ++--
 arch/tricore/src/common/tricore_exit.c | 6 ++----
 arch/x86/src/common/x86_exit.c         | 1 +
 arch/x86_64/src/common/x86_64_exit.c   | 1 +
 arch/xtensa/src/common/xtensa_exit.c   | 6 ++----
 arch/z16/src/common/z16_exit.c         | 1 +
 arch/z80/src/common/z80_exit.c         | 1 +
 sched/sched/sched_suspendscheduler.c   | 7 +++++++
 20 files changed, 38 insertions(+), 32 deletions(-)

diff --git a/arch/arm/src/arm/arm_syscall.c b/arch/arm/src/arm/arm_syscall.c
index be95d916ff..8a5849e4d2 100644
--- a/arch/arm/src/arm/arm_syscall.c
+++ b/arch/arm/src/arm/arm_syscall.c
@@ -152,6 +152,12 @@ uint32_t *arm_syscall(uint32_t *regs)
 
       cpu = this_cpu();
       tcb = current_task(cpu);
+
+      /* Update scheduler parameters */
+
+      nxsched_suspend_scheduler(g_running_tasks[cpu]);
+      nxsched_resume_scheduler(tcb);
+
       g_running_tasks[cpu] = tcb;
 
       /* Restore the cpu lock */
diff --git a/arch/arm/src/common/arm_exit.c b/arch/arm/src/common/arm_exit.c
index 9a41c2231f..f238dfa5f3 100644
--- a/arch/arm/src/common/arm_exit.c
+++ b/arch/arm/src/common/arm_exit.c
@@ -66,11 +66,9 @@ void up_exit(int status)
 
   tcb = this_task();
 
-  /* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases
-   * NOTE: the API also adjusts the global IRQ control for SMP
-   */
+  /* Scheduler parameters will update inside syscall */
 
-  nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = NULL;
 
   /* Then switch contexts */
 
diff --git a/arch/arm64/src/common/arm64_exit.c 
b/arch/arm64/src/common/arm64_exit.c
index a444c80983..ba81dbb97f 100644
--- a/arch/arm64/src/common/arm64_exit.c
+++ b/arch/arm64/src/common/arm64_exit.c
@@ -70,11 +70,9 @@ void up_exit(int status)
 
   tcb = this_task();
 
-  /* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases
-   * NOTE: the API also adjusts the global IRQ control for SMP
-   */
+  /* Scheduler parameters will update inside syscall */
 
-  nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = NULL;
 
   /* Then switch contexts */
 
diff --git a/arch/avr/src/common/avr_exit.c b/arch/avr/src/common/avr_exit.c
index 0e88b87094..c82e02d64c 100644
--- a/arch/avr/src/common/avr_exit.c
+++ b/arch/avr/src/common/avr_exit.c
@@ -68,6 +68,7 @@ void up_exit(int status)
   /* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases */
 
   nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = tcb;
 
 #ifdef CONFIG_ARCH_ADDRENV
   /* Make sure that the address environment for the previously running
diff --git a/arch/hc/src/common/hc_exit.c b/arch/hc/src/common/hc_exit.c
index b7397d41c0..146da1c88e 100644
--- a/arch/hc/src/common/hc_exit.c
+++ b/arch/hc/src/common/hc_exit.c
@@ -67,6 +67,7 @@ void up_exit(int status)
   /* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases */
 
   nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = tcb;
 
 #ifdef CONFIG_ARCH_ADDRENV
   /* Make sure that the address environment for the previously running
diff --git a/arch/mips/src/common/mips_exit.c b/arch/mips/src/common/mips_exit.c
index 0c12040cc8..72f2290c2f 100644
--- a/arch/mips/src/common/mips_exit.c
+++ b/arch/mips/src/common/mips_exit.c
@@ -66,11 +66,9 @@ void up_exit(int status)
 
   tcb = this_task();
 
-  /* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases
-   * NOTE: the API also adjusts the global IRQ control for SMP
-   */
+  /* Scheduler parameters will update inside syscall */
 
-  nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = NULL;
 
   /* Then switch contexts */
 
diff --git a/arch/misoc/src/lm32/lm32_exit.c b/arch/misoc/src/lm32/lm32_exit.c
index 7e3a8723af..8ee9a4b91a 100644
--- a/arch/misoc/src/lm32/lm32_exit.c
+++ b/arch/misoc/src/lm32/lm32_exit.c
@@ -68,7 +68,7 @@ void up_exit(int status)
 
   /* Adjusts time slice for RR & SPORADIC cases */
 
-  nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = NULL;
 
   /* Then switch contexts */
 
diff --git a/arch/misoc/src/minerva/minerva_exit.c 
b/arch/misoc/src/minerva/minerva_exit.c
index ef1d92ecf0..ecc6df21be 100644
--- a/arch/misoc/src/minerva/minerva_exit.c
+++ b/arch/misoc/src/minerva/minerva_exit.c
@@ -68,7 +68,7 @@ void up_exit(int status)
 
   /* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases */
 
-  nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = NULL;
 
   /* Then switch contexts */
 
diff --git a/arch/or1k/src/common/or1k_exit.c b/arch/or1k/src/common/or1k_exit.c
index 25d338c042..a79775f8bf 100644
--- a/arch/or1k/src/common/or1k_exit.c
+++ b/arch/or1k/src/common/or1k_exit.c
@@ -69,6 +69,7 @@ void up_exit(int status)
   /* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases */
 
   nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = tcb;
 
 #ifdef CONFIG_ARCH_ADDRENV
   /* Make sure that the address environment for the previously running
diff --git a/arch/renesas/src/common/renesas_exit.c 
b/arch/renesas/src/common/renesas_exit.c
index 474bf019ea..730888a752 100644
--- a/arch/renesas/src/common/renesas_exit.c
+++ b/arch/renesas/src/common/renesas_exit.c
@@ -64,9 +64,10 @@ void up_exit(int status)
 
   tcb = this_task();
 
-  /* Adjusts time slice for RR & SPORADIC cases */
+  /* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases */
 
   nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = tcb;
 
 #ifdef CONFIG_ARCH_ADDRENV
   /* Make sure that the address environment for the previously running
diff --git a/arch/risc-v/src/common/riscv_exit.c 
b/arch/risc-v/src/common/riscv_exit.c
index 39d17a77c4..fb521e564c 100644
--- a/arch/risc-v/src/common/riscv_exit.c
+++ b/arch/risc-v/src/common/riscv_exit.c
@@ -66,13 +66,7 @@ void up_exit(int status)
 
   tcb = this_task();
 
-  /* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases
-   * NOTE: the API also adjusts the global IRQ control for SMP
-   */
-
-  nxsched_resume_scheduler(tcb);
-
-  /* g_running_tasks is not valid now */
+  /* Scheduler parameters will update inside syscall */
 
   g_running_tasks[this_cpu()] = NULL;
 
diff --git a/arch/sim/src/sim/sim_exit.c b/arch/sim/src/sim/sim_exit.c
index 9d1d8c2567..02ef47a096 100644
--- a/arch/sim/src/sim/sim_exit.c
+++ b/arch/sim/src/sim/sim_exit.c
@@ -68,6 +68,7 @@ void up_exit(int status)
    */
 
   nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = tcb;
 
   /* Restore the cpu lock */
 
diff --git a/arch/sparc/src/common/sparc_exit.c 
b/arch/sparc/src/common/sparc_exit.c
index 80458173f4..fc6c9329fa 100644
--- a/arch/sparc/src/common/sparc_exit.c
+++ b/arch/sparc/src/common/sparc_exit.c
@@ -70,9 +70,9 @@ void up_exit(int status)
 
   tcb = this_task();
 
-  /* Reset scheduler parameters */
+  /* Scheduler parameters will update inside syscall */
 
-  nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = NULL;
 
   /* Then switch contexts */
 
diff --git a/arch/tricore/src/common/tricore_exit.c 
b/arch/tricore/src/common/tricore_exit.c
index 432551b63b..b329ddc509 100644
--- a/arch/tricore/src/common/tricore_exit.c
+++ b/arch/tricore/src/common/tricore_exit.c
@@ -66,11 +66,9 @@ void up_exit(int status)
 
   tcb = this_task();
 
-  /* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases
-   * NOTE: the API also adjusts the global IRQ control for SMP
-   */
+  /* Scheduler parameters will update inside syscall */
 
-  nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = NULL;
 
   /* Then switch contexts */
 
diff --git a/arch/x86/src/common/x86_exit.c b/arch/x86/src/common/x86_exit.c
index 3356a72dde..9db098c501 100644
--- a/arch/x86/src/common/x86_exit.c
+++ b/arch/x86/src/common/x86_exit.c
@@ -70,6 +70,7 @@ void up_exit(int status)
    */
 
   nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = tcb;
 
 #ifdef CONFIG_ARCH_ADDRENV
   /* Make sure that the address environment for the previously running
diff --git a/arch/x86_64/src/common/x86_64_exit.c 
b/arch/x86_64/src/common/x86_64_exit.c
index b222f7a5d3..093f60fcac 100644
--- a/arch/x86_64/src/common/x86_64_exit.c
+++ b/arch/x86_64/src/common/x86_64_exit.c
@@ -69,6 +69,7 @@ void up_exit(int status)
    */
 
   nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = tcb;
 
   /* Context switch, rearrange MMU */
 
diff --git a/arch/xtensa/src/common/xtensa_exit.c 
b/arch/xtensa/src/common/xtensa_exit.c
index fc4f4bdd7d..078ab195e9 100644
--- a/arch/xtensa/src/common/xtensa_exit.c
+++ b/arch/xtensa/src/common/xtensa_exit.c
@@ -66,11 +66,9 @@ void up_exit(int status)
 
   tcb = this_task();
 
-  /* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases
-   * NOTE: the API also adjusts the global IRQ control for SMP
-   */
+  /* Scheduler parameters will update inside syscall */
 
-  nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = NULL;
 
   /* Then switch contexts */
 
diff --git a/arch/z16/src/common/z16_exit.c b/arch/z16/src/common/z16_exit.c
index 93cf3a1e46..21cc90d4e1 100644
--- a/arch/z16/src/common/z16_exit.c
+++ b/arch/z16/src/common/z16_exit.c
@@ -68,6 +68,7 @@ void up_exit(int status)
   /* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases */
 
   nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = tcb;
 
   /* Then switch contexts */
 
diff --git a/arch/z80/src/common/z80_exit.c b/arch/z80/src/common/z80_exit.c
index 80af3eee20..0904e3e252 100644
--- a/arch/z80/src/common/z80_exit.c
+++ b/arch/z80/src/common/z80_exit.c
@@ -70,6 +70,7 @@ void up_exit(int status)
   /* Adjusts time slice for SCHED_RR & SCHED_SPORADIC cases */
 
   nxsched_resume_scheduler(tcb);
+  g_running_tasks[this_cpu()] = tcb;
 
 #ifdef CONFIG_ARCH_ADDRENV
   /* Make sure that the address environment for the previously running
diff --git a/sched/sched/sched_suspendscheduler.c 
b/sched/sched/sched_suspendscheduler.c
index f22119bf1c..e1c1105e1e 100644
--- a/sched/sched/sched_suspendscheduler.c
+++ b/sched/sched/sched_suspendscheduler.c
@@ -61,6 +61,13 @@
 
 void nxsched_suspend_scheduler(FAR struct tcb_s *tcb)
 {
+  /* Handle the task exiting case */
+
+  if (tcb != NULL)
+    {
+      return;
+    }
+
 #ifdef CONFIG_SCHED_SPORADIC
   /* Perform sporadic schedule operations */
 

Reply via email to