sync ps/assert output

This commit is contained in:
lilei19 2023-02-17 15:54:57 +08:00 committed by Xiang Xiao
parent 62c15c03d3
commit 77f6319268
5 changed files with 167 additions and 38 deletions

View File

@ -397,32 +397,6 @@ static FAR const struct proc_node_s * const g_groupinfo[] =
};
#define PROC_NGROUPNODES (sizeof(g_groupinfo)/sizeof(FAR const struct proc_node_s * const))
/* Names of task/thread states */
static FAR const char * const g_statenames[] =
{
"Invalid",
"Waiting,Unlock",
"Ready",
#ifdef CONFIG_SMP
"Assigned",
#endif
"Running",
"Inactive",
"Waiting,Semaphore",
"Waiting,Signal"
#if !defined(CONFIG_DISABLE_MQUEUE) || !defined(CONFIG_DISABLE_MQUEUE_SYSV)
, "Waiting,MQ empty"
, "Waiting,MQ full"
#endif
#ifdef CONFIG_PAGING
, "Waiting,Paging fill"
#endif
#ifdef CONFIG_SIG_SIGSTOP_ACTION
, "Stopped"
#endif
};
static FAR const char * const g_ttypenames[4] =
{
"Task",
@ -494,6 +468,7 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile,
{
FAR const char *policy;
FAR const char *name;
char state[32];
size_t remaining;
size_t linesize;
size_t copysize;
@ -584,9 +559,9 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile,
/* Show the thread state */
nxsched_get_stateinfo(tcb, state, sizeof(state));
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
"%-12s%s\n", "State:",
g_statenames[tcb->task_state]);
"%-12s%s\n", "State:", state);
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
&offset);

View File

@ -991,8 +991,7 @@ int nxtask_delete(pid_t pid);
* scheduler.
*
* Input Parameters:
* tcb - The TCB for the task for the task (same as the nxtask_init
* argument).
* tcb - The TCB for the task (same as the nxtask_init argument).
*
* Returned Value:
* None
@ -1392,6 +1391,22 @@ int nxsched_set_affinity(pid_t pid, size_t cpusetsize,
int nxsched_get_stackinfo(pid_t pid, FAR struct stackinfo_s *stackinfo);
/****************************************************************************
* Name: nxsched_get_stateinfo
*
* Description:
* Report information about a thread's state
*
* Input Parameters:
* tcb - The TCB for the task (same as the nxtask_init argument).
* state - User-provided location to return the state information.
* length - The size of the state
*
****************************************************************************/
void nxsched_get_stateinfo(FAR struct tcb_s *tcb, FAR char *state,
size_t length);
/****************************************************************************
* Name: nxsched_waitpid
*

View File

@ -70,6 +70,19 @@
static uint8_t g_last_regs[XCPTCONTEXT_SIZE];
static FAR const char *g_policy[4] =
{
"FIFO", "RR", "SPORADIC"
};
static FAR const char * const g_ttypenames[4] =
{
"Task",
"pthread",
"Kthread",
"Invalid"
};
/****************************************************************************
* Private Functions
****************************************************************************/
@ -221,6 +234,8 @@ static void show_stacks(FAR struct tcb_s *rtcb)
static void dump_task(FAR struct tcb_s *tcb, FAR void *arg)
{
char args[64] = "";
char state[32];
FAR char *s;
#ifdef CONFIG_STACK_COLORATION
size_t stack_filled = 0;
size_t stack_used;
@ -255,13 +270,24 @@ static void dump_task(FAR struct tcb_s *tcb, FAR void *arg)
group_argvstr(tcb, args, sizeof(args));
/* get the task_state */
nxsched_get_stateinfo(tcb, state, sizeof(state));
if ((s = strchr(state, ',')) != NULL)
{
*s = ' ';
}
/* Dump interesting properties of this task */
_alert(" %4d %4d"
_alert(" %4d %5d"
#ifdef CONFIG_SMP
" %4d"
#endif
" %p"
" %3d %-8s %-7s %c%c%c"
" %-18s"
" %08" PRIx32
" %p"
" %7zu"
#ifdef CONFIG_STACK_COLORATION
" %7zu %3zu.%1zu%%%c"
@ -270,10 +296,21 @@ static void dump_task(FAR struct tcb_s *tcb, FAR void *arg)
" %3zu.%01zu%%"
#endif
" %s%s\n"
, tcb->pid, tcb->sched_priority
, tcb->pid
, tcb->group ? tcb->group->tg_pid : -1
#ifdef CONFIG_SMP
, tcb->cpu
#endif
, tcb->sched_priority
, g_policy[(tcb->flags & TCB_FLAG_POLICY_MASK) >>
TCB_FLAG_POLICY_SHIFT]
, g_ttypenames[(tcb->flags & TCB_FLAG_TTYPE_MASK)
>> TCB_FLAG_TTYPE_SHIFT]
, tcb->flags & TCB_FLAG_NONCANCELABLE ? 'N' : '-'
, tcb->flags & TCB_FLAG_CANCEL_PENDING ? 'P' : '-'
, tcb->flags & TCB_FLAG_EXIT_PROCESSING ? 'P' : '-'
, state
, tcb->sigprocmask
, tcb->stack_base_ptr
, tcb->adj_stack_size
#ifdef CONFIG_STACK_COLORATION
@ -325,12 +362,15 @@ static void show_tasks(void)
/* Dump interesting properties of each task in the crash environment */
_alert(" PID PRI"
_alert(" PID GROUP"
#ifdef CONFIG_SMP
" CPU"
#endif
" STACKBASE"
" STACKSIZE"
" PRI POLICY TYPE NPX"
" STATE EVENT"
" SIGMASK"
" STACKBASE"
" STACKSIZE"
#ifdef CONFIG_STACK_COLORATION
" USED FILLED "
#endif
@ -344,7 +384,11 @@ static void show_tasks(void)
# ifdef CONFIG_SMP
" ----"
# endif
" %p"
" --- --------"
" ------- ---"
" ------- ----------"
" --------"
" %p"
" %7u"
# ifdef CONFIG_STACK_COLORATION
" %7zu %3zu.%1zu%%%c"

View File

@ -28,7 +28,7 @@ CSRCS += sched_setscheduler.c sched_getscheduler.c
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
CSRCS += sched_sysinfo.c sched_reprioritizertr.c
CSRCS += sched_sysinfo.c sched_reprioritizertr.c sched_get_stateinfo.c
ifeq ($(CONFIG_PRIORITY_INHERITANCE),y)
CSRCS += sched_reprioritize.c

View File

@ -0,0 +1,95 @@
/****************************************************************************
* sched/sched/sched_get_stateinfo.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <stdio.h>
#include <semaphore.h>
#include <nuttx/mutex.h>
#include "nuttx/sched.h"
/****************************************************************************
* Pre-processor types
****************************************************************************/
/* This is the state info of the task_state field of the TCB */
static FAR const char * const g_statenames[] =
{
"Invalid",
"Waiting,Unlock",
"Ready",
#ifdef CONFIG_SMP
"Assigned",
#endif
"Running",
"Inactive",
"Waiting,Semaphore",
"Waiting,Signal"
#if !defined(CONFIG_DISABLE_MQUEUE) || !defined(CONFIG_DISABLE_MQUEUE_SYSV)
, "Waiting,MQ empty"
, "Waiting,MQ full"
#endif
#ifdef CONFIG_PAGING
, "Waiting,Paging fill"
#endif
#ifdef CONFIG_SIG_SIGSTOP_ACTION
, "Stopped"
#endif
};
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxsched_get_stateinfo
*
* Description:
* Report information about a thread's state
*
* Input Parameters:
* tcb - The TCB for the task (same as the nxtask_init argument).
* state - User-provided location to return the state information.
* length - The size of the state
*
****************************************************************************/
void nxsched_get_stateinfo(FAR struct tcb_s *tcb, FAR char *state,
size_t length)
{
/* if the state is waiting mutex */
if (tcb->task_state == TSTATE_WAIT_SEM &&
((FAR sem_t *)(tcb->waitobj))->flags & SEM_TYPE_MUTEX)
{
snprintf(state, length, "Waiting,Mutex:%d",
((FAR mutex_t *)(tcb->waitobj))->holder);
}
else
{
strlcpy(state, g_statenames[tcb->task_state], length);
}
}