sched/assert: Dump the global state only when it's a fatal error

and merge assert_end into _assert

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-12-25 02:48:25 +08:00 committed by Masayuki Ishikawa
parent d1497a8d08
commit d5f729ed25
2 changed files with 44 additions and 59 deletions

View file

@ -3911,10 +3911,10 @@ config BOARD_RESET_ON_ASSERT
depends on BOARDCTL_RESET
---help---
== 0 up_assert never reset the machine
>= 1 up_assert from interrupt handler or IDLE thread will reset the
machine
>= 1 up_assert from interrupt handler or kernel thread will reset
the machine
>= 2 up_assert from user or kernel thread will reset the machine.
The default behavior is just to kill the asserting thread.
The default behavior just kill the asserting thread.
config BOARD_ASSERT_RESET_VALUE
int "Board reset argument"

View file

@ -431,47 +431,6 @@ static void show_tasks(void)
#endif
}
/****************************************************************************
* Name: assert_end
****************************************************************************/
static void assert_end(FAR struct tcb_s *rtcb)
{
/* Flush any buffered SYSLOG data */
syslog_flush();
/* Are we in an interrupt handler or the idle task? */
if (up_interrupt_context() || rtcb->flink == NULL)
{
#if CONFIG_BOARD_RESET_ON_ASSERT >= 1
board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE);
#endif
/* Disable interrupts on this CPU */
up_irq_save();
#ifdef CONFIG_SMP
/* Try (again) to stop activity on other CPUs */
spin_trylock(&g_cpu_irqlock);
#endif
for (; ; )
{
up_mdelay(250);
}
}
else
{
#if CONFIG_BOARD_RESET_ON_ASSERT >= 2
board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE);
#endif
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
@ -479,21 +438,23 @@ static void assert_end(FAR struct tcb_s *rtcb)
void _assert(FAR const char *filename, int linenum)
{
FAR struct tcb_s *rtcb = running_task();
bool fatal = false;
/* Flush any buffered SYSLOG data (from prior to the assertion) */
syslog_flush();
#if CONFIG_BOARD_RESET_ON_ASSERT < 2
if (!up_interrupt_context() && rtcb->flink != NULL)
if (up_interrupt_context() ||
(rtcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL)
{
panic_notifier_call_chain(PANIC_TASK, NULL);
fatal = true;
}
else
#else
fatal = true;
#endif
{
panic_notifier_call_chain(PANIC_KERNEL, NULL);
}
panic_notifier_call_chain(fatal ? PANIC_KERNEL : PANIC_TASK, NULL);
#ifdef CONFIG_SMP
# if CONFIG_TASK_NAME_SIZE > 0
@ -513,10 +474,6 @@ void _assert(FAR const char *filename, int linenum)
# endif
#endif
/* Flush any buffered SYSLOG data (from the above) */
syslog_flush();
/* Show back trace */
#ifdef CONFIG_SCHED_BACKTRACE
@ -539,17 +496,45 @@ void _assert(FAR const char *filename, int linenum)
show_stacks(rtcb);
#endif
show_tasks();
/* Flush any buffered SYSLOG data */
syslog_flush();
if (fatal)
{
show_tasks();
#ifdef CONFIG_ARCH_USBDUMP
/* Dump USB trace data */
/* Dump USB trace data */
usbtrace_enumerate(assert_tracecallback, NULL);
usbtrace_enumerate(assert_tracecallback, NULL);
#endif
#ifdef CONFIG_BOARD_CRASHDUMP
board_crashdump(up_getsp(), rtcb, filename, linenum);
board_crashdump(up_getsp(), rtcb, filename, linenum);
#endif
assert_end(rtcb);
/* Flush any buffered SYSLOG data */
syslog_flush();
#if CONFIG_BOARD_RESET_ON_ASSERT >= 1
board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE);
#else
/* Disable interrupts on this CPU */
up_irq_save();
# ifdef CONFIG_SMP
/* Try (again) to stop activity on other CPUs */
spin_trylock(&g_cpu_irqlock);
# endif
for (; ; )
{
up_mdelay(250);
}
#endif
}
}