arch/risc-v: enhance the task dump

add irq stack information
add cpu loading

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2021-12-22 12:05:08 +08:00 committed by Gustavo Henrique Nihei
parent a0b61bbf6f
commit 362fe2c6f8
2 changed files with 274 additions and 57 deletions

View file

@ -123,43 +123,93 @@ static inline void riscv_registerdump(volatile uint32_t *regs)
#endif
/****************************************************************************
* Name: riscv_taskdump
* Name: riscv_dump_task
****************************************************************************/
#if defined(CONFIG_STACK_COLORATION) || defined(CONFIG_SCHED_BACKTRACE)
static void riscv_taskdump(struct tcb_s *tcb, void *arg)
static void riscv_dump_task(struct tcb_s *tcb, void *arg)
{
#ifdef CONFIG_STACK_COLORATION
uint32_t stack_filled = 0;
uint32_t stack_used;
#endif
#ifdef CONFIG_SCHED_CPULOAD
struct cpuload_s cpuload;
uint32_t fracpart;
uint32_t intpart;
uint32_t tmp;
clock_cpuload(tcb->pid, &cpuload);
if (cpuload.total > 0)
{
tmp = (1000 * cpuload.active) / cpuload.total;
intpart = tmp / 10;
fracpart = tmp - 10 * intpart;
}
else
{
intpart = 0;
fracpart = 0;
}
#endif
#ifdef CONFIG_STACK_COLORATION
stack_used = up_check_tcbstack(tcb);
if (tcb->adj_stack_size > 0 && stack_used > 0)
{
/* Use fixed-point math with one decimal place */
stack_filled = 10 * 100 * stack_used / tcb->adj_stack_size;
}
#endif
/* Dump interesting properties of this task */
_alert(
#if CONFIG_TASK_NAME_SIZE > 0
"%s: "
#endif
"PID=%d "
_alert(" %4d %4d"
#ifdef CONFIG_STACK_COLORATION
"Stack Used=%lu of %lu\n",
#else
"Stack=%lu\n",
" %7lu"
#endif
" %7lu"
#ifdef CONFIG_STACK_COLORATION
" %3" PRId32 ".%1" PRId32 "%%%c"
#endif
#ifdef CONFIG_SCHED_CPULOAD
" %3" PRId32 ".%01" PRId32 "%%"
#endif
#if CONFIG_TASK_NAME_SIZE > 0
tcb->name,
" %s"
#endif
tcb->pid,
"\n",
tcb->pid, tcb->sched_priority,
#ifdef CONFIG_STACK_COLORATION
(unsigned long)up_check_tcbstack(tcb),
#endif
(unsigned long)tcb->adj_stack_size);
(unsigned long)tcb->adj_stack_size
#ifdef CONFIG_STACK_COLORATION
, stack_filled / 10, stack_filled % 10,
(stack_filled >= 10 * 80 ? '!' : ' ')
#endif
#ifdef CONFIG_SCHED_CPULOAD
, intpart, fracpart
#endif
#if CONFIG_TASK_NAME_SIZE > 0
, tcb->name
#endif
);
}
/* Show back trace */
/****************************************************************************
* Name: riscv_dump_backtrace
****************************************************************************/
#ifdef CONFIG_SCHED_BACKTRACE
static void riscv_dump_backtrace(struct tcb_s *tcb, void *arg)
{
/* Show back trace */
sched_dumpstack(tcb->pid);
#endif
/* Dump the registers */
riscv_registerdump(tcb->xcp.regs);
}
#endif
/****************************************************************************
* Name: riscv_showtasks
@ -167,13 +217,71 @@ static void riscv_taskdump(struct tcb_s *tcb, void *arg)
static inline void riscv_showtasks(void)
{
#if CONFIG_ARCH_INTERRUPTSTACK > 15
# ifdef CONFIG_STACK_COLORATION
uint32_t stack_used = up_check_intstack();
uint32_t stack_filled = 0;
if ((CONFIG_ARCH_INTERRUPTSTACK & ~15) > 0 && stack_used > 0)
{
/* Use fixed-point math with one decimal place */
stack_filled = 10 * 100 *
stack_used / (CONFIG_ARCH_INTERRUPTSTACK & ~15);
}
# endif
#endif
/* Dump interesting properties of each task in the crash environment */
nxsched_foreach(riscv_taskdump, NULL);
}
#else
# define riscv_showtasks()
_alert(" PID PRI"
#ifdef CONFIG_STACK_COLORATION
" USED"
#endif
" STACK"
#ifdef CONFIG_STACK_COLORATION
" FILLED "
#endif
#ifdef CONFIG_SCHED_CPULOAD
" CPU"
#endif
#if CONFIG_TASK_NAME_SIZE > 0
" COMMAND"
#endif
"\n");
#if CONFIG_ARCH_INTERRUPTSTACK > 15
_alert(" ---- ----"
# ifdef CONFIG_STACK_COLORATION
" %7lu"
# endif
" %7lu"
# ifdef CONFIG_STACK_COLORATION
" %3" PRId32 ".%1" PRId32 "%%%c"
# endif
# ifdef CONFIG_SCHED_CPULOAD
" ----"
# endif
# if CONFIG_TASK_NAME_SIZE > 0
" irq"
# endif
"\n"
# ifdef CONFIG_STACK_COLORATION
, (unsigned long)stack_used
# endif
, (unsigned long)(CONFIG_ARCH_INTERRUPTSTACK & ~15)
# ifdef CONFIG_STACK_COLORATION
, stack_filled / 10, stack_filled % 10,
(stack_filled >= 10 * 80 ? '!' : ' ')
# endif
);
#endif
nxsched_foreach(riscv_dump_task, NULL);
#ifdef CONFIG_SCHED_BACKTRACE
nxsched_foreach(riscv_dump_backtrace, NULL);
#endif
}
/****************************************************************************
* Name: riscv_dumpstate

View file

@ -132,63 +132,171 @@ static inline void riscv_registerdump(volatile uintptr_t *regs)
}
/****************************************************************************
* Name: up_taskdump
* Name: riscv_dump_task
****************************************************************************/
#if defined(CONFIG_STACK_COLORATION) || defined(CONFIG_SCHED_BACKTRACE)
static void up_taskdump(struct tcb_s *tcb, void *arg)
static void riscv_dump_task(struct tcb_s *tcb, void *arg)
{
#ifdef CONFIG_STACK_COLORATION
uint32_t stack_filled = 0;
uint32_t stack_used;
#endif
#ifdef CONFIG_SCHED_CPULOAD
struct cpuload_s cpuload;
uint32_t fracpart;
uint32_t intpart;
uint32_t tmp;
clock_cpuload(tcb->pid, &cpuload);
if (cpuload.total > 0)
{
tmp = (1000 * cpuload.active) / cpuload.total;
intpart = tmp / 10;
fracpart = tmp - 10 * intpart;
}
else
{
intpart = 0;
fracpart = 0;
}
#endif
#ifdef CONFIG_STACK_COLORATION
stack_used = up_check_tcbstack(tcb);
if (tcb->adj_stack_size > 0 && stack_used > 0)
{
/* Use fixed-point math with one decimal place */
stack_filled = 10 * 100 * stack_used / tcb->adj_stack_size;
}
#endif
/* Dump interesting properties of this task */
_alert(
#if CONFIG_TASK_NAME_SIZE > 0
"%s: "
#endif
"PID=%d "
_alert(" %4d %4d"
#ifdef CONFIG_STACK_COLORATION
"Stack Used=%lu of %lu\n",
#else
"Stack=%lu\n",
" %7lu"
#endif
" %7lu"
#ifdef CONFIG_STACK_COLORATION
" %3" PRId32 ".%1" PRId32 "%%%c"
#endif
#ifdef CONFIG_SCHED_CPULOAD
" %3" PRId32 ".%01" PRId32 "%%"
#endif
#if CONFIG_TASK_NAME_SIZE > 0
tcb->name,
" %s"
#endif
tcb->pid,
"\n",
tcb->pid, tcb->sched_priority,
#ifdef CONFIG_STACK_COLORATION
(unsigned long)up_check_tcbstack(tcb),
#endif
(unsigned long)tcb->adj_stack_size);
(unsigned long)tcb->adj_stack_size
#ifdef CONFIG_STACK_COLORATION
, stack_filled / 10, stack_filled % 10,
(stack_filled >= 10 * 80 ? '!' : ' ')
#endif
#ifdef CONFIG_SCHED_CPULOAD
, intpart, fracpart
#endif
#if CONFIG_TASK_NAME_SIZE > 0
, tcb->name
#endif
);
}
/* Show back trace */
/****************************************************************************
* Name: riscv_dump_backtrace
****************************************************************************/
#ifdef CONFIG_SCHED_BACKTRACE
static void riscv_dump_backtrace(struct tcb_s *tcb, void *arg)
{
/* Show back trace */
sched_dumpstack(tcb->pid);
}
#endif
/* Dump the registers */
riscv_registerdump(tcb->xcp.regs);
}
/****************************************************************************
* Name: up_showtasks
* Name: riscv_showtasks
****************************************************************************/
static inline void up_showtasks(void)
static inline void riscv_showtasks(void)
{
#if CONFIG_ARCH_INTERRUPTSTACK > 15
# ifdef CONFIG_STACK_COLORATION
uint32_t stack_used = up_check_intstack();
uint32_t stack_filled = 0;
if ((CONFIG_ARCH_INTERRUPTSTACK & ~15) > 0 && stack_used > 0)
{
/* Use fixed-point math with one decimal place */
stack_filled = 10 * 100 *
stack_used / (CONFIG_ARCH_INTERRUPTSTACK & ~15);
}
# endif
#endif
/* Dump interesting properties of each task in the crash environment */
nxsched_foreach(up_taskdump, NULL);
}
#else
# define up_showtasks()
_alert(" PID PRI"
#ifdef CONFIG_STACK_COLORATION
" USED"
#endif
" STACK"
#ifdef CONFIG_STACK_COLORATION
" FILLED "
#endif
#ifdef CONFIG_SCHED_CPULOAD
" CPU"
#endif
#if CONFIG_TASK_NAME_SIZE > 0
" COMMAND"
#endif
"\n");
#if CONFIG_ARCH_INTERRUPTSTACK > 15
_alert(" ---- ----"
# ifdef CONFIG_STACK_COLORATION
" %7lu"
# endif
" %7lu"
# ifdef CONFIG_STACK_COLORATION
" %3" PRId32 ".%1" PRId32 "%%%c"
# endif
# ifdef CONFIG_SCHED_CPULOAD
" ----"
# endif
# if CONFIG_TASK_NAME_SIZE > 0
" irq"
# endif
"\n"
# ifdef CONFIG_STACK_COLORATION
, (unsigned long)stack_used
# endif
, (unsigned long)(CONFIG_ARCH_INTERRUPTSTACK & ~15)
# ifdef CONFIG_STACK_COLORATION
, stack_filled / 10, stack_filled % 10,
(stack_filled >= 10 * 80 ? '!' : ' ')
# endif
);
#endif
nxsched_foreach(riscv_dump_task, NULL);
#ifdef CONFIG_SCHED_BACKTRACE
nxsched_foreach(riscv_dump_backtrace, NULL);
#endif
}
/****************************************************************************
* Name: up_dumpstate
* Name: riscv_dumpstate
****************************************************************************/
static void up_dumpstate(void)
static void riscv_dumpstate(void)
{
struct tcb_s *rtcb = running_task();
uint64_t sp = up_getsp();
@ -273,7 +381,8 @@ static void up_dumpstate(void)
riscv_stackdump(sp, ustackbase + ustacksize);
}
}
#else
# define riscv_dumpstate()
#endif /* CONFIG_ARCH_STACKDUMP */
/****************************************************************************
@ -376,7 +485,7 @@ void up_assert(const char *filename, int lineno)
#endif
#endif
up_dumpstate();
riscv_dumpstate();
#ifdef CONFIG_SMP
/* Show the CPU number */
@ -386,7 +495,7 @@ void up_assert(const char *filename, int lineno)
/* Dump the state of all tasks (if available) */
up_showtasks();
riscv_showtasks();
#ifdef CONFIG_ARCH_USBDUMP
/* Dump USB trace data */