Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 3 additions & 28 deletions fs/procfs/fs_procfsproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
19 changes: 17 additions & 2 deletions include/nuttx/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,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
Expand Down Expand Up @@ -1391,6 +1390,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
*
Expand Down
58 changes: 51 additions & 7 deletions sched/misc/assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
****************************************************************************/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -344,7 +384,11 @@ static void show_tasks(void)
# ifdef CONFIG_SMP
" ----"
# endif
" %p"
" --- --------"
" ------- ---"
" ------- ----------"
" --------"
" %p"
" %7u"
# ifdef CONFIG_STACK_COLORATION
" %7zu %3zu.%1zu%%%c"
Expand Down
2 changes: 1 addition & 1 deletion sched/sched/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
95 changes: 95 additions & 0 deletions sched/sched/sched_get_stateinfo.c
Original file line number Diff line number Diff line change
@@ -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);
}
}