mirror of
https://github.com/apache/nuttx.git
synced 2026-05-24 07:46:16 +08:00
sched: remove nxsched_suspend/resume_scheduler
move both suspned and resume logic to nxsched_switch_context Co-authored-by: yinshengkai <yinshengkai@xiaomi.com> Signed-off-by: guoshengyuan1 <guoshengyuan1@xiaomi.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
+1
-10
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 <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
|
||||
#include <nuttx/sched_note.h>
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* 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(tcb));
|
||||
DEBUGVERIFY(nxsched_suspend_sporadic(from));
|
||||
}
|
||||
if ((to->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_SPORADIC)
|
||||
{
|
||||
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 */
|
||||
Reference in New Issue
Block a user