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 c62861d383278bec0068081fb18260713d032124
Author: guoshengyuan1 <[email protected]>
AuthorDate: Thu Sep 25 19:56:42 2025 +0800

    sched: remove nxsched_suspend/resume_scheduler
    
    move both suspned and resume logic to nxsched_switch_context
    
    Co-authored-by: yinshengkai <[email protected]>
    Signed-off-by: guoshengyuan1 <[email protected]>
---
 Kconfig                                            |  2 +-
 include/nuttx/sched.h                              | 67 ----------------------
 sched/Kconfig                                      | 14 -----
 sched/sched/CMakeLists.txt                         | 13 +----
 sched/sched/Make.defs                              | 11 +---
 sched/sched/sched.h                                |  2 +
 ...ed_suspendscheduler.c => sched_switchcontext.c} | 59 ++++++++-----------
 7 files changed, 29 insertions(+), 139 deletions(-)

diff --git a/Kconfig b/Kconfig
index 1c1d808e3f8..a6cb1a255ec 100644
--- a/Kconfig
+++ b/Kconfig
@@ -2457,7 +2457,7 @@ config STACK_COLORATION
 
 config STACKCHECK_SOFTWARE
        bool "Software detection of stack overflow"
-       depends on STACK_COLORATION && DEBUG_ASSERTIONS && 
SCHED_SUSPENDSCHEDULER
+       depends on STACK_COLORATION && DEBUG_ASSERTIONS
        ---help---
                When switching contexts, it will detect whether a stack 
overflow occurs.
                Two methods are used here.
diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h
index 218ac30d4a6..7bf37127e4f 100644
--- a/include/nuttx/sched.h
+++ b/include/nuttx/sched.h
@@ -1214,73 +1214,6 @@ struct binary_s;  /* Forward reference */
 int group_exitinfo(pid_t pid, FAR struct binary_s *bininfo);
 #endif
 
-/****************************************************************************
- * Name: nxsched_resume_scheduler
- *
- * Description:
- *   Called by architecture specific implementations that block task
- *   execution.
- *   This function prepares the scheduler for the thread that is about to be
- *   restarted.
- *
- * Input Parameters:
- *   tcb - The TCB of the thread to be restarted.
- *
- * Returned Value:
- *   None
- *
- ****************************************************************************/
-
-#if defined(CONFIG_SCHED_RESUMESCHEDULER)
-void nxsched_resume_scheduler(FAR struct tcb_s *tcb);
-#else
-#  define nxsched_resume_scheduler(tcb)
-#endif
-
-/****************************************************************************
- * Name: nxsched_suspend_scheduler
- *
- * Description:
- *   Called by architecture specific implementations to resume task
- *   execution.
- *   This function performs scheduler operations for the thread that is about
- *   to be suspended.
- *
- * Input Parameters:
- *   tcb - The TCB of the thread to be restarted.
- *
- * Returned Value:
- *   None
- *
- ****************************************************************************/
-
-#ifdef CONFIG_SCHED_SUSPENDSCHEDULER
-void nxsched_suspend_scheduler(FAR struct tcb_s *tcb);
-#else
-#  define nxsched_suspend_scheduler(tcb)
-#endif
-
-/****************************************************************************
- * Name: nxsched_switch_context
- *
- * Description:
- *   This function is used to switch context between two tasks.
- *
- * Input Parameters:
- *   from - The TCB of the task to be suspended.
- *   to   - The TCB of the task to be resumed.
- *
- * Returned Value:
- *   None
- ****************************************************************************/
-
-static inline void nxsched_switch_context(FAR struct tcb_s *from,
-                                          FAR struct tcb_s *to)
-{
-  nxsched_suspend_scheduler(from);
-  nxsched_resume_scheduler(to);
-}
-
 /****************************************************************************
  * Name: nxsched_get_param
  *
diff --git a/sched/Kconfig b/sched/Kconfig
index 194dac51888..63425307305 100644
--- a/sched/Kconfig
+++ b/sched/Kconfig
@@ -653,8 +653,6 @@ config RR_INTERVAL
 config SCHED_SPORADIC
        bool "Support sporadic scheduling"
        default n
-       select SCHED_SUSPENDSCHEDULER
-       select SCHED_RESUMESCHEDULER
        ---help---
                Build in additional logic to support sporadic scheduling
                (SCHED_SPORADIC).
@@ -917,14 +915,6 @@ endmenu # Pthread Options
 
 menu "Performance Monitoring"
 
-config SCHED_SUSPENDSCHEDULER
-       bool
-       default n
-
-config SCHED_RESUMESCHEDULER
-       bool
-       default n
-
 config SCHED_IRQMONITOR
        bool "Enable IRQ monitoring"
        default n
@@ -938,8 +928,6 @@ config SCHED_CRITMONITOR
        bool "Enable Critical Section monitoring"
        default n
        depends on FS_PROCFS
-       select SCHED_SUSPENDSCHEDULER
-       select SCHED_RESUMESCHEDULER
        select IRQCOUNT
        ---help---
                Enables logic that monitors the duration of time that a thread 
keeps
@@ -1185,8 +1173,6 @@ config SCHED_PROFILE_TICKSPERSEC
 menuconfig SCHED_INSTRUMENTATION
        bool "System performance monitor hooks"
        default n
-       select SCHED_SUSPENDSCHEDULER
-       select SCHED_RESUMESCHEDULER
        ---help---
                Enables instrumentation in scheduler to monitor system 
performance.
                If enabled, then the board-specific logic must provide the 
following
diff --git a/sched/sched/CMakeLists.txt b/sched/sched/CMakeLists.txt
index dc9d061be8e..83df2678436 100644
--- a/sched/sched/CMakeLists.txt
+++ b/sched/sched/CMakeLists.txt
@@ -46,7 +46,8 @@ set(SRCS
     sched_get_stackinfo.c
     sched_get_tls.c
     sched_sysinfo.c
-    sched_get_stateinfo.c)
+    sched_get_stateinfo.c
+    sched_switchcontext.c)
 
 if(CONFIG_PRIORITY_INHERITANCE)
   list(APPEND SRCS sched_reprioritize.c)
@@ -78,16 +79,6 @@ if(CONFIG_SCHED_SPORADIC)
   list(APPEND SRCS sched_sporadic.c)
 endif()
 
-if(CONFIG_SCHED_SUSPENDSCHEDULER)
-  list(APPEND SRCS sched_suspendscheduler.c)
-endif()
-
-if(NOT "${CONFIG_RR_INTERVAL}" STREQUAL "0")
-  list(APPEND SRCS sched_resumescheduler.c)
-elseif(CONFIG_SCHED_RESUMESCHEDULER)
-  list(APPEND SRCS sched_resumescheduler.c)
-endif()
-
 if(NOT CONFIG_SCHED_CPULOAD_NONE)
   list(APPEND SRCS sched_cpuload.c)
   if(CONFIG_CPULOAD_ONESHOT)
diff --git a/sched/sched/Make.defs b/sched/sched/Make.defs
index 3ee5b68033d..be076eca23d 100644
--- a/sched/sched/Make.defs
+++ b/sched/sched/Make.defs
@@ -30,6 +30,7 @@ CSRCS += sched_yield.c sched_rrgetinterval.c sched_foreach.c
 CSRCS += sched_lock.c sched_unlock.c sched_lockcount.c
 CSRCS += sched_idletask.c sched_self.c sched_get_stackinfo.c sched_get_tls.c
 CSRCS += sched_sysinfo.c sched_get_stateinfo.c sched_getcpu.c
+CSRCS += sched_switchcontext.c
 
 ifeq ($(CONFIG_PRIORITY_INHERITANCE),y)
 CSRCS += sched_reprioritize.c
@@ -61,16 +62,6 @@ ifeq ($(CONFIG_SCHED_SPORADIC),y)
 CSRCS += sched_sporadic.c
 endif
 
-ifeq ($(CONFIG_SCHED_SUSPENDSCHEDULER),y)
-CSRCS += sched_suspendscheduler.c
-endif
-
-ifneq ($(CONFIG_RR_INTERVAL),0)
-CSRCS += sched_resumescheduler.c
-else ifeq ($(CONFIG_SCHED_RESUMESCHEDULER),y)
-CSRCS += sched_resumescheduler.c
-endif
-
 ifneq ($(CONFIG_SCHED_CPULOAD_NONE),y)
 CSRCS += sched_cpuload.c
 ifeq ($(CONFIG_CPULOAD_ONESHOT),y)
diff --git a/sched/sched/sched.h b/sched/sched/sched.h
index 7f1124b05bf..3d414f1e3fd 100644
--- a/sched/sched/sched.h
+++ b/sched/sched/sched.h
@@ -413,6 +413,8 @@ void nxsched_process_cpuload_ticks(clock_t ticks);
 
 /* Critical section monitor */
 
+void nxsched_switch_context(FAR struct tcb_s *from, FAR struct tcb_s *to);
+
 #ifdef CONFIG_SCHED_CRITMONITOR
 void nxsched_resume_critmon(FAR struct tcb_s *tcb);
 void nxsched_suspend_critmon(FAR struct tcb_s *tcb);
diff --git a/sched/sched/sched_suspendscheduler.c 
b/sched/sched/sched_switchcontext.c
similarity index 64%
rename from sched/sched/sched_suspendscheduler.c
rename to sched/sched/sched_switchcontext.c
index 02f35ba52b6..9b866272a27 100644
--- a/sched/sched/sched_suspendscheduler.c
+++ b/sched/sched/sched_switchcontext.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * sched/sched/sched_suspendscheduler.c
+ * sched/sched/sched_switchcontext.c
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -24,61 +24,43 @@
  * Included Files
  ****************************************************************************/
 
-#include <nuttx/config.h>
-
-#include <time.h>
-#include <assert.h>
+#include "sched/sched.h"
 
-#include <nuttx/arch.h>
-#include <nuttx/sched.h>
-#include <nuttx/clock.h>
 #include <nuttx/sched_note.h>
 
-#include "clock/clock.h"
-#include "sched/sched.h"
-
-#ifdef CONFIG_SCHED_SUSPENDSCHEDULER
 
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: nxsched_suspend_scheduler
+ * Name: nxsched_switch_context
  *
  * Description:
- *   Called by architecture specific implementations that starts task
- *   execution.  This function prepares the scheduler for the thread that is
- *   about to be restarted.
+ *   This function is used to switch context between two tasks.
  *
  * Input Parameters:
- *   tcb - The TCB of the thread that is being suspended.
+ *   from - The TCB of the task to be suspended.
+ *   to   - The TCB of the task to be resumed.
  *
  * Returned Value:
  *   None
  *
  ****************************************************************************/
 
-void nxsched_suspend_scheduler(FAR struct tcb_s *tcb)
+void nxsched_switch_context(FAR struct tcb_s *from, FAR struct tcb_s *to)
 {
-  /* Handle the task exiting case */
-
-  if (tcb == NULL)
-    {
-      return;
-    }
-
 #ifdef CONFIG_STACKCHECK_SOFTWARE
-  if (tcb->xcp.regs)
+  if (from->xcp.regs)
     {
-      uintptr_t sp = up_getusrsp(tcb->xcp.regs);
-      uintptr_t top = (uintptr_t)tcb->stack_base_ptr + tcb->adj_stack_size;
-      uintptr_t bottom = (uintptr_t)tcb->stack_base_ptr;
+      uintptr_t sp = up_getusrsp(from->xcp.regs);
+      uintptr_t top = (uintptr_t)from->stack_base_ptr + from->adj_stack_size;
+      uintptr_t bottom = (uintptr_t)from->stack_base_ptr;
       DEBUGASSERT(sp > bottom && sp <= top);
     }
 
 #if CONFIG_STACKCHECK_MARGIN > 0
-    DEBUGASSERT(up_check_tcbstack(tcb, CONFIG_STACKCHECK_MARGIN) == 0);
+    DEBUGASSERT(up_check_tcbstack(from, CONFIG_STACKCHECK_MARGIN) == 0);
 #endif
 
 #endif
@@ -86,20 +68,25 @@ void nxsched_suspend_scheduler(FAR struct tcb_s *tcb)
 #ifdef CONFIG_SCHED_SPORADIC
   /* Perform sporadic schedule operations */
 
-  if ((tcb->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_SPORADIC)
+  if ((from->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_SPORADIC)
+    {
+      DEBUGVERIFY(nxsched_suspend_sporadic(from));
+    }
+  if ((to->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_SPORADIC)
     {
-      DEBUGVERIFY(nxsched_suspend_sporadic(tcb));
+      DEBUGVERIFY(nxsched_resume_sporadic(to));
     }
 #endif
 
   /* Indicate that the task has been suspended */
 
 #ifdef CONFIG_SCHED_CRITMONITOR
-  nxsched_suspend_critmon(tcb);
+  nxsched_suspend_critmon(from);
+  nxsched_resume_critmon(to);
 #endif
+
 #ifdef CONFIG_SCHED_INSTRUMENTATION
-  sched_note_suspend(tcb);
+  sched_note_suspend(from);
+  sched_note_resume(to);
 #endif
 }
-
-#endif /* CONFIG_SCHED_SUSPENDSCHEDULER */

Reply via email to