You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2022/12/29 02:50:36 UTC

[nuttx] branch master updated (6992a8f4cc -> d5f729ed25)

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

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


    from 6992a8f4cc sched: group: Fix memory corruption in group_leave.c
     new 5f99e482b5 sched/assert: Don't call running_task more than once
     new d1497a8d08 sched/assert: Don't call up_check_tcbstack for the kernel stack
     new d5f729ed25 sched/assert: Dump the global state only when it's a fatal error

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 boards/Kconfig      |   6 +--
 sched/misc/assert.c | 147 ++++++++++++++++++++++------------------------------
 2 files changed, 64 insertions(+), 89 deletions(-)


[nuttx] 01/03: sched/assert: Don't call running_task more than once

Posted by ma...@apache.org.
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 5f99e482b5cfd9696fdd7d65100bdd69a2fbeff7
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Dec 17 02:34:26 2022 +0800

    sched/assert: Don't call running_task more than once
    
    and fix some minor style issue
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 sched/misc/assert.c | 51 +++++++++++++++++++++++----------------------------
 1 file changed, 23 insertions(+), 28 deletions(-)

diff --git a/sched/misc/assert.c b/sched/misc/assert.c
index 95a00b7925..d2da0ccf94 100644
--- a/sched/misc/assert.c
+++ b/sched/misc/assert.c
@@ -27,15 +27,16 @@
 #include <nuttx/arch.h>
 #include <nuttx/board.h>
 #include <nuttx/irq.h>
+#include <nuttx/tls.h>
+
 #include <nuttx/panic_notifier.h>
-#include <nuttx/usb/usbdev_trace.h>
 #include <nuttx/syslog/syslog.h>
-#include <nuttx/tls.h>
+#include <nuttx/usb/usbdev_trace.h>
 
 #include <assert.h>
 #include <debug.h>
+#include <stdio.h>
 #include <stdint.h>
-#include <stdlib.h>
 
 #include "irq/irq.h"
 #include "sched/sched.h"
@@ -97,10 +98,10 @@ static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg)
 #ifdef CONFIG_ARCH_STACKDUMP
 
 /****************************************************************************
- * Name: stackdump
+ * Name: stack_dump
  ****************************************************************************/
 
-static void stackdump(uintptr_t sp, uintptr_t stack_top)
+static void stack_dump(uintptr_t sp, uintptr_t stack_top)
 {
   uintptr_t stack;
 
@@ -132,7 +133,7 @@ static void dump_stack(FAR const char *tag, uintptr_t sp,
 
   if (sp >= base && sp < top)
     {
-      stackdump(sp, top);
+      stack_dump(sp, top);
     }
   else
     {
@@ -143,8 +144,8 @@ static void dump_stack(FAR const char *tag, uintptr_t sp,
 #ifdef CONFIG_STACK_COLORATION
           size_t remain = size - used;
 
-          base  += remain;
-          size  -= remain;
+          base += remain;
+          size -= remain;
 #endif
 
 #if CONFIG_ARCH_STACKDUMP_MAX_LENGTH > 0
@@ -154,7 +155,7 @@ static void dump_stack(FAR const char *tag, uintptr_t sp,
             }
 #endif
 
-          stackdump(base, base + size);
+          stack_dump(base, base + size);
         }
     }
 }
@@ -163,9 +164,8 @@ static void dump_stack(FAR const char *tag, uintptr_t sp,
  * Name: showstacks
  ****************************************************************************/
 
-static void showstacks(void)
+static void show_stacks(FAR struct tcb_s *rtcb)
 {
-  FAR struct tcb_s *rtcb = running_task();
   uintptr_t sp = up_getsp();
 
   /* Get the limits on the interrupt stack memory */
@@ -369,8 +369,6 @@ static void dump_task(FAR struct tcb_s *tcb, FAR void *arg)
 #ifdef CONFIG_SCHED_BACKTRACE
 static void dump_backtrace(FAR struct tcb_s *tcb, FAR void *arg)
 {
-  /* Show back trace */
-
   sched_dumpstack(tcb->pid);
 }
 #endif
@@ -379,10 +377,9 @@ static void dump_backtrace(FAR struct tcb_s *tcb, FAR void *arg)
  * Name: showtasks
  ****************************************************************************/
 
-static void showtasks(void)
+static void show_tasks(void)
 {
-#if CONFIG_ARCH_INTERRUPTSTACK > 0
-#  ifdef CONFIG_STACK_COLORATION
+#if CONFIG_ARCH_INTERRUPTSTACK > 0 && defined(CONFIG_STACK_COLORATION)
   size_t stack_used = up_check_intstack();
   size_t stack_filled = 0;
 
@@ -393,7 +390,6 @@ static void showtasks(void)
       stack_filled = 10 * 100 *
                      stack_used / CONFIG_ARCH_INTERRUPTSTACK;
     }
-#  endif
 #endif
 
   /* Dump interesting properties of each task in the crash environment */
@@ -444,7 +440,7 @@ static void showtasks(void)
  * Name: assert_end
  ****************************************************************************/
 
-static void assert_end(void)
+static void assert_end(FAR struct tcb_s *rtcb)
 {
   /* Flush any buffered SYSLOG data */
 
@@ -452,7 +448,7 @@ static void assert_end(void)
 
   /* Are we in an interrupt handler or the idle task? */
 
-  if (up_interrupt_context() || running_task()->flink == NULL)
+  if (up_interrupt_context() || rtcb->flink == NULL)
     {
 #if CONFIG_BOARD_RESET_ON_ASSERT >= 1
       board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE);
@@ -507,19 +503,18 @@ void _assert(FAR const char *filename, int linenum)
 #ifdef CONFIG_SMP
 #  if CONFIG_TASK_NAME_SIZE > 0
   _alert("Assertion failed CPU%d at file: %s:%d task: %s %p\n",
-         up_cpu_index(), filename, linenum, rtcb->name,
-         rtcb->entry.main);
+         up_cpu_index(), filename, linenum, rtcb->name, rtcb->entry.main);
 #  else
-  _alert("Assertion failed CPU%d at file: %s:%d\n",
-         up_cpu_index(), filename, linenum);
+  _alert("Assertion failed CPU%d at file: %s:%d task: %p\n",
+         up_cpu_index(), filename, linenum, rtcb->entry.main);
 #  endif
 #else
 #  if CONFIG_TASK_NAME_SIZE > 0
   _alert("Assertion failed at file: %s:%d task: %s %p\n",
          filename, linenum, rtcb->name, rtcb->entry.main);
 #  else
-  _alert("Assertion failed at file: %s:%d\n",
-         filename, linenum);
+  _alert("Assertion failed at file: %s:%d task: %p\n",
+         filename, linenum, rtcb->entry.main);
 #  endif
 #endif
 
@@ -546,10 +541,10 @@ void _assert(FAR const char *filename, int linenum)
     }
 
 #ifdef CONFIG_ARCH_STACKDUMP
-  showstacks();
+  show_stacks(rtcb);
 #endif
 
-  showtasks();
+  show_tasks();
 
 #ifdef CONFIG_ARCH_USBDUMP
   /* Dump USB trace data */
@@ -561,5 +556,5 @@ void _assert(FAR const char *filename, int linenum)
   board_crashdump(up_getsp(), rtcb, filename, linenum);
 #endif
 
-  assert_end();
+  assert_end(rtcb);
 }


[nuttx] 02/03: sched/assert: Don't call up_check_tcbstack for the kernel stack

Posted by ma...@apache.org.
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 d1497a8d084375ea75747b999e7df110d59beb5b
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Dec 25 01:09:18 2022 +0800

    sched/assert: Don't call up_check_tcbstack for the kernel stack
    
    since up_check_tcbstack only check the userspace stack color
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 sched/misc/assert.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/sched/misc/assert.c b/sched/misc/assert.c
index d2da0ccf94..087e6f3a43 100644
--- a/sched/misc/assert.c
+++ b/sched/misc/assert.c
@@ -205,12 +205,7 @@ static void show_stacks(FAR struct tcb_s *rtcb)
   dump_stack("Kernel", sp,
              (uintptr_t)rtcb->xcp.kstack,
              CONFIG_ARCH_KERNEL_STACKSIZE,
-#  ifdef CONFIG_STACK_COLORATION
-             up_check_tcbstack(rtcb),
-#  else
-             0,
-#  endif
-             false);
+             0, false);
 #endif
 }
 


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

Posted by ma...@apache.org.
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 <xi...@xiaomi.com>
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 <xi...@xiaomi.com>
---
 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
+    }
 }