This is an automated email from the ASF dual-hosted git repository.

masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit d5f729ed25ceebf9684b765d438ca385d606b9be
Author: Xiang Xiao <[email protected]>
AuthorDate: Sun Dec 25 02:48:25 2022 +0800

    sched/assert: Dump the global state only when it's a fatal error
    
    and merge assert_end into _assert
    
    Signed-off-by: Xiang Xiao <[email protected]>
---
 boards/Kconfig      |  6 ++--
 sched/misc/assert.c | 97 ++++++++++++++++++++++-------------------------------
 2 files changed, 44 insertions(+), 59 deletions(-)

diff --git a/boards/Kconfig b/boards/Kconfig
index e1af5f2576..8c0955c031 100644
--- a/boards/Kconfig
+++ b/boards/Kconfig
@@ -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"
diff --git a/sched/misc/assert.c b/sched/misc/assert.c
index 087e6f3a43..6e0686df6b 100644
--- a/sched/misc/assert.c
+++ b/sched/misc/assert.c
@@ -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
+    }
 }

Reply via email to