nuttx/sched: use pid to check idle task

Pid is more appropriate than the flink pointer to determine idle task,
when we want to use other data structure to optimize the task list.
This commit is contained in:
zhangyuan21
2022-10-28 14:22:17 +08:00
committed by Masayuki Ishikawa
parent b353d84742
commit 18266c1012
14 changed files with 17 additions and 15 deletions
+1 -1
View File
@@ -119,7 +119,7 @@ void up_assert(const char *filename, int lineno)
syslog_flush();
if (CURRENT_REGS || rtcb->flink == NULL)
if (CURRENT_REGS || is_idle_task(rtcb))
{
/* Exit the simulation */
+2 -2
View File
@@ -319,7 +319,7 @@ void sched_note_resume(FAR struct tcb_s *tcb)
if (!up_interrupt_context())
{
if (tcb->flink == NULL)
if (is_idle_task(tcb))
{
SEGGER_SYSVIEW_OnIdle();
}
@@ -354,7 +354,7 @@ void sched_note_irqhandler(int irq, FAR void *handler, bool enter)
{
FAR struct tcb_s *tcb = this_task();
if (tcb && tcb->flink != NULL)
if (tcb && !is_idle_task(tcb))
{
SEGGER_SYSVIEW_OnTaskStartExec(tcb->pid);
}
+1 -1
View File
@@ -180,7 +180,7 @@ int nxmq_wait_receive(FAR struct mqueue_inode_s *msgq,
* isn't going to end well.
*/
DEBUGASSERT(NULL != rtcb->flink);
DEBUGASSERT(!is_idle_task(rtcb));
up_block_task(rtcb, TSTATE_WAIT_MQNOTEMPTY);
/* When we resume at this point, either (1) the message queue
+1 -1
View File
@@ -266,7 +266,7 @@ int nxmq_wait_send(FAR struct mqueue_inode_s *msgq, int oflags)
* isn't going to end well.
*/
DEBUGASSERT(NULL != rtcb->flink);
DEBUGASSERT(!is_idle_task(rtcb));
up_block_task(rtcb, TSTATE_WAIT_MQNOTFULL);
/* When we resume at this point, either (1) the message queue
+1 -1
View File
@@ -133,7 +133,7 @@ void pg_miss(void)
* that isn't going to end well.
*/
DEBUGASSERT(NULL != ftcb->flink);
DEBUGASSERT(!is_idle_task(ftcb));
up_block_task(ftcb, TSTATE_WAIT_PAGEFILL);
/* Boost the page fill worker thread priority.
+2
View File
@@ -56,6 +56,8 @@
# define this_task() (current_task(this_cpu()))
#endif
#define is_idle_task(t) ((t)->pid < CONFIG_SMP_NCPUS)
/* This macro returns the running task which may different from this_task()
* during interrupt level context switches.
*/
+1 -1
View File
@@ -95,7 +95,7 @@ bool nxsched_add_readytorun(FAR struct tcb_s *btcb)
* is now the new active task!
*/
DEBUGASSERT(rtcb->lockcount == 0 && btcb->flink != NULL);
DEBUGASSERT(rtcb->lockcount == 0 && !is_idle_task(btcb));
btcb->task_state = TSTATE_TASK_RUNNING;
btcb->flink->task_state = TSTATE_TASK_READYTORUN;
+1 -1
View File
@@ -83,7 +83,7 @@ int nxsched_select_cpu(cpu_set_t affinity)
* IDLE task is always the last task in the assigned task list.
*/
if (rtcb->flink == NULL)
if (is_idle_task(rtcb))
{
/* The IDLE task should always be assigned to this CPU and have
* a priority of zero.
+1 -1
View File
@@ -76,7 +76,7 @@ bool sched_idletask(void)
* different PIDs in the SMP configuration.
*/
return (rtcb->flink == NULL);
return is_idle_task(rtcb);
}
/* We must be on the IDLE thread if we are early in initialization */
+1 -1
View File
@@ -84,7 +84,7 @@ void nxsched_suspend(FAR struct tcb_s *tcb)
* descheduling that isn't going to end well.
*/
DEBUGASSERT(NULL != tcb->flink);
DEBUGASSERT(!is_idle_task(tcb));
up_block_task(tcb, TSTATE_TASK_STOPPED);
}
+1 -1
View File
@@ -707,7 +707,7 @@ void nxsem_add_holder_tcb(FAR struct tcb_s *htcb, FAR sem_t *sem)
* inheritance is effectively disabled.
*/
if (htcb->flink != NULL && (sem->flags & PRIOINHERIT_FLAGS_ENABLE) != 0)
if (!is_idle_task(htcb) && (sem->flags & PRIOINHERIT_FLAGS_ENABLE) != 0)
{
/* Find or allocate a container for this new holder */
+1 -1
View File
@@ -151,7 +151,7 @@ int nxsem_wait(FAR sem_t *sem)
* isn't going to end well.
*/
DEBUGASSERT(NULL != rtcb->flink);
DEBUGASSERT(!is_idle_task(rtcb));
up_block_task(rtcb, TSTATE_WAIT_SEM);
/* When we resume at this point, either (1) the semaphore has been
+1 -1
View File
@@ -122,7 +122,7 @@ int sigsuspend(FAR const sigset_t *set)
* isn't going to end well.
*/
DEBUGASSERT(NULL != rtcb->flink);
DEBUGASSERT(!is_idle_task(rtcb));
up_block_task(rtcb, TSTATE_WAIT_SIG);
/* We are running again, restore the original sigprocmask */
+2 -2
View File
@@ -319,7 +319,7 @@ int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info,
* descheduling that isn't going to end well.
*/
DEBUGASSERT(NULL != rtcb->flink);
DEBUGASSERT(!is_idle_task(rtcb));
up_block_task(rtcb, TSTATE_WAIT_SIG);
/* We no longer need the watchdog */
@@ -336,7 +336,7 @@ int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info,
* descheduling that isn't going to end well.
*/
DEBUGASSERT(NULL != rtcb->flink);
DEBUGASSERT(!is_idle_task(rtcb));
up_block_task(rtcb, TSTATE_WAIT_SIG);
}