You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by je...@apache.org on 2023/07/31 12:45:26 UTC

[nuttx] branch master updated: watchdog: add CONFIG_WATCHDOG_PANIC_NOTIFIER for panic notifier

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 835a2a8801 watchdog: add CONFIG_WATCHDOG_PANIC_NOTIFIER for panic notifier
835a2a8801 is described below

commit 835a2a8801b307fba60cd1a4d1919fb0b030764b
Author: Bowen Wang <wa...@xiaomi.com>
AuthorDate: Sat Jul 22 11:44:10 2023 +0800

    watchdog: add CONFIG_WATCHDOG_PANIC_NOTIFIER for panic notifier
    
    wdog_notifier() will be called in _assert to keep the crash scene
    as mush as possible, which is useful for debug.
    
    But once disable the watchdog, the hardware watchdog can not reboot
    the system too. If a crash happened in the _assert (e.g. the tcb sp
    has been corrupted, system will crash again in tack stack dump),
    system will crashing forever and can not reboot.
    
    So add a config to disable this feature by default and can be enable
    if anyone need it.
    
    Signed-off-by: Bowen Wang <wa...@xiaomi.com>
---
 drivers/timers/Kconfig    | 7 +++++++
 drivers/timers/watchdog.c | 8 ++++++++
 2 files changed, 15 insertions(+)

diff --git a/drivers/timers/Kconfig b/drivers/timers/Kconfig
index 28f5264172..a8434ac8ad 100644
--- a/drivers/timers/Kconfig
+++ b/drivers/timers/Kconfig
@@ -392,6 +392,13 @@ config WATCHDOG_MAGIC_V
 	---help---
 		The watchdog can be stopped by writing 'V' to the watchdog's device node
 
+config WATCHDOG_PANIC_NOTIFIER
+	bool "Enable watchdog panic notifier"
+	default n
+	---help---
+		When system PANIC, wdog_notifier() will be callled to disable the watchdog,
+		this is an useful option for debug if you want to keep crash scene.
+
 menuconfig WATCHDOG_AUTOMONITOR
 	bool "Auto-monitor"
 	---help---
diff --git a/drivers/timers/watchdog.c b/drivers/timers/watchdog.c
index 648e0ffbf2..fb2aa20e1a 100644
--- a/drivers/timers/watchdog.c
+++ b/drivers/timers/watchdog.c
@@ -76,9 +76,11 @@
 
 struct watchdog_upperhalf_s
 {
+#ifdef CONFIG_WATCHDOG_PANIC_NOTIFIER
   /* When a crash occurs, stop the watchdog */
 
   struct notifier_block nb;
+#endif
 #ifdef CONFIG_WATCHDOG_AUTOMONITOR
 #  if defined(CONFIG_WATCHDOG_AUTOMONITOR_BY_ONESHOT)
   FAR struct oneshot_lowerhalf_s *oneshot;
@@ -300,6 +302,7 @@ static void watchdog_automonitor_stop(FAR struct watchdog_upperhalf_s *upper)
 }
 #endif
 
+#ifdef CONFIG_WATCHDOG_PANIC_NOTIFIER
 static int wdog_notifier(FAR struct notifier_block *nb, unsigned long action,
                          FAR void *data)
 {
@@ -317,6 +320,7 @@ static int wdog_notifier(FAR struct notifier_block *nb, unsigned long action,
 
   return 0;
 }
+#endif
 
 /****************************************************************************
  * Name: wdog_open
@@ -778,8 +782,10 @@ FAR void *watchdog_register(FAR const char *path,
   watchdog_automonitor_start(upper);
 #endif
 
+#ifdef CONFIG_WATCHDOG_PANIC_NOTIFIER
   upper->nb.notifier_call = wdog_notifier;
   panic_notifier_chain_register(&upper->nb);
+#endif
 
   return (FAR void *)upper;
 
@@ -835,7 +841,9 @@ void watchdog_unregister(FAR void *handle)
   /* Unregister the watchdog timer device */
 
   unregister_driver(upper->path);
+#ifdef CONFIG_WATCHDOG_PANIC_NOTIFIER
   panic_notifier_chain_unregister(&upper->nb);
+#endif
 
   /* Then free all of the driver resources */