Skip to contentSkip to conversation

add reg and stack dump to booke WD handler

PATCH In review Dave Jiang 4 participants 10 messages Apr 13, 2007 – Apr 27, 2007

Subsystems (2)
lore
Share & tools
lore

Dave Jiang

author
#0 lore raw

PATCH 1/1 add reg and stack dump to booke WD handler

Have the booke watchdog dump some useful information when triggered. Hopefully that'll give the user some hint of what happened rather than just a mysterious reboot.

--

 arch/powerpc/kernel/traps.c |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)
arch/powerpc/kernel/traps.c +34 -1
index f786222..1af83b7 100644
@@ -1108,9 +1108,42 @@ void unrecoverable_exception(struct pt_regs *regs)
  */
 void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
 {
+	unsigned long flags;
+
 	/* Generic WatchdogHandler, implement your own */
 	mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
-	return;
+	oops_enter();
+
+	console_verbose();
+	bust_spinlocks(1);
+	local_save_flags(flags);
+
+	printk(KERN_ERR "PowerPC Book-E Watchdog detected LOCKUP\n");
+	printk(KERN_ERR "Watchdog exception at PC=%lx MSR=%lx\n",
+			regs->nip, regs->msr);
+#ifdef CONFIG_PREEMPT
+	printk(KERN_ERR "PREEMPT ");
+#endif
+#ifdef CONFIG_SMP
+	printk(KERN_ERR "SMP NR_CPUS=%d ", NR_CPUS);
+#endif
+#ifdef CONFIG_DEBUG_PAGEALLOC
+	printk(KERN_ERR "DEBUG_PAGEALLOC ");
+#endif
+#ifdef CONFIG_NUMA
+	printk(KERN_ERR "NUMA ");
+#endif
+	printk(KERN_ERR "%s\n", ppc_md.name ? ppc_md.name : "");
+
+	print_modules();
+	show_regs(regs);
+
+	bust_spinlocks(0);
+
+	printk(KERN_ERR "Wating for hardware watchdog reset...\n");
+	/* spin until hardware reset */
+	while(1)
+		cpu_relax();
 }
 
 void WatchdogException(struct pt_regs *regs)
author
#1 lore raw

Re: oops, forgot to sign off

Have the booke watchdog dump some useful information when triggered. Hopefully that'll give the user some hint of what happened rather than just a mysterious reboot.

--

 arch/powerpc/kernel/traps.c |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)
arch/powerpc/kernel/traps.c +34 -1
index f786222..1af83b7 100644
@@ -1108,9 +1108,42 @@ void unrecoverable_exception(struct pt_regs *regs)
  */
 void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
 {
+	unsigned long flags;
+
 	/* Generic WatchdogHandler, implement your own */
 	mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
-	return;
+	oops_enter();
+
+	console_verbose();
+	bust_spinlocks(1);
+	local_save_flags(flags);
+
+	printk(KERN_ERR "PowerPC Book-E Watchdog detected LOCKUP\n");
+	printk(KERN_ERR "Watchdog exception at PC=%lx MSR=%lx\n",
+			regs->nip, regs->msr);
+#ifdef CONFIG_PREEMPT
+	printk(KERN_ERR "PREEMPT ");
+#endif
+#ifdef CONFIG_SMP
+	printk(KERN_ERR "SMP NR_CPUS=%d ", NR_CPUS);
+#endif
+#ifdef CONFIG_DEBUG_PAGEALLOC
+	printk(KERN_ERR "DEBUG_PAGEALLOC ");
+#endif
+#ifdef CONFIG_NUMA
+	printk(KERN_ERR "NUMA ");
+#endif
+	printk(KERN_ERR "%s\n", ppc_md.name ? ppc_md.name : "");
+
+	print_modules();
+	show_regs(regs);
+
+	bust_spinlocks(0);
+
+	printk(KERN_ERR "Wating for hardware watchdog reset...\n");
+	/* spin until hardware reset */
+	while(1)
+		cpu_relax();
 }
 
 void WatchdogException(struct pt_regs *regs)
#2 lore raw
In reply to Dave Jiang
Quoted 3 lines · Dave Jiang

Have the booke watchdog dump some useful information when triggered. Hopefully that'll give the user some hint of what happened rather than just a mysterious reboot.

Why not do this in drivers/watchdog/booke_wdt.c -- WatchdogHandler() is a weak symbol?

Quoted 11 lines
arch/powerpc/kernel/traps.c +2 -0
index f786222..1af83b7 100644
@@ -1108,9 +1108,42 @@ void unrecoverable_exception(struct pt_regs *regs)
  */
 void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
 {
+	unsigned long flags;
+
 	/* Generic WatchdogHandler, implement your own */

arch/powerpc/kernel/traps.c void unrecoverable_exception(struct pt_regs *regs) · line 1122

Quoted 10 lines
arch/powerpc/kernel/traps.c +8 -1
 	mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
-	return;
+	oops_enter();
+
+	console_verbose();
+	bust_spinlocks(1);
+	local_save_flags(flags);
+
+	printk(KERN_ERR "PowerPC Book-E Watchdog detected LOCKUP\n");
+	printk(KERN_ERR "Watchdog exception at PC=%lx MSR=%lx\n",

This partly duplicates printk() in WatchdogException().

arch/powerpc/kernel/traps.c void unrecoverable_exception(struct pt_regs *regs) · line 1123

Quoted 1 line
arch/powerpc/kernel/traps.c +1 -0
+			regs->nip, regs->msr);

These regs are later dumped by show_regs() anyway.

arch/powerpc/kernel/traps.c void unrecoverable_exception(struct pt_regs *regs) · line 1125

Quoted 2 lines
arch/powerpc/kernel/traps.c +2 -0
+#ifdef CONFIG_PREEMPT
+	printk(KERN_ERR "PREEMPT ");

Does specifying loglevel on non '\n' terminated lines really make sense? I suspect all what you'll get will be ugly output with <3> insterted here and there.

Quoted 8 lines
arch/powerpc/kernel/traps.c +8 -0
+#endif
+#ifdef CONFIG_SMP
+	printk(KERN_ERR "SMP NR_CPUS=%d ", NR_CPUS);
+#endif
+#ifdef CONFIG_DEBUG_PAGEALLOC
+	printk(KERN_ERR "DEBUG_PAGEALLOC ");
+#endif
+#ifdef CONFIG_NUMA

arch/powerpc/kernel/traps.c void unrecoverable_exception(struct pt_regs *regs) · line 1143

Quoted 10 lines
arch/powerpc/kernel/traps.c +10 -0
+	printk(KERN_ERR "NUMA ");
+#endif
+	printk(KERN_ERR "%s\n", ppc_md.name ? ppc_md.name : "");
+
+	print_modules();
+	show_regs(regs);
+
+	bust_spinlocks(0);
+
+	printk(KERN_ERR "Wating for hardware watchdog reset...\n");

A typo here.

arch/powerpc/kernel/traps.c void unrecoverable_exception(struct pt_regs *regs) · line 1146

Quoted 3 lines
arch/powerpc/kernel/traps.c +3 -0
+	/* spin until hardware reset */
+	while(1)
+		cpu_relax();

Not even giving it a chance? That's cruel. :-) Seriously, this seems too specific watchdog behavior to be here.

WBR, Sergei

author
#3 lore raw

Have the booke watchdog dump some useful information when triggered. Hopefully that'll give the user some hint of what happened rather than just a mysterious reboot.

--

Ok here's try 2. Modified the watchdog driver instead per Sergei's suggestion.

 drivers/char/watchdog/booke_wdt.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
drivers/char/watchdog/booke_wdt.c +37 -0
index 0e23f29..90e5301 100644
@@ -23,6 +23,7 @@
 #include <asm/reg_booke.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
+#include <asm/machdep.h>
 
 /* If the kernel parameter wdt_enable=1, the watchdog will be enabled at boot.
  * Also, the wdt_period sets the watchdog timer period timeout.
@@ -47,6 +48,42 @@ u32 booke_wdt_period = WDT_PERIOD_DEFAULT;
 #define WDTP(x)		(TCR_WP(x))
 #endif
 
+void WatchdogHandler(struct pt_regs *regs)
+{
+	unsigned long flags;
+
+	mtspr(SPRN_TCR, mfspr(SPRN_TCR) & ~TCR_WIE);
+	oops_enter();
+
+	console_verbose();
+	bust_spinlocks(1);
+	local_save_flags(flags);
+
+#ifdef CONFIG_PREEMPT
+	printk("PREEMPT ");
+#endif
+#ifdef CONFIG_SMP
+	printk("SMP NR_CPUS=%d ", NR_CPUS);
+#endif
+#ifdef CONFIG_DEBUG_PAGEALLOC
+	printk("DEBUG_PAGEALLOC ");
+#endif
+#ifdef CONFIG_NUMA
+	printk("NUMA ");
+#endif
+	printk("%s\n", ppc_md.name ? ppc_md.name : "");
+
+	print_modules();
+	show_regs(regs);
+
+	bust_spinlocks(0);
+
+	printk(KERN_EMERG "Waiting for hardware watchdog reset...\n");
+	/* spin until hardware reset */
+	while(1)
+		cpu_relax();
+}
+
 /*
  * booke_wdt_ping:
  */
#4 lore raw
Quoted 3 lines · Dave Jiang

Have the booke watchdog dump some useful information when triggered. Hopefully that'll give the user some hint of what happened rather than just a mysterious reboot.

Forgot the signed-off-by again (git-commit -s)

Quoted 4 lines

--

Ok here's try 2. Modified the watchdog driver instead per Sergei's
suggestion.

I'm against having a WatchdogHandler in booke_wdt.c. The idea behind the weak symbol in traps.c is to allow platform code to override the behavior. I'm ok if we put the spew in the generic case.

Also, how are you testing this?

- k

Quoted 61 lines
 drivers/char/watchdog/booke_wdt.c |   37 ++++++++++++++++++++++++++ 
+++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
drivers/char/watchdog/booke_wdt.c +1 -0
index 0e23f29..90e5301 100644
@@ -23,6 +23,7 @@
 #include <asm/reg_booke.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
+#include <asm/machdep.h>
 
 /* If the kernel parameter wdt_enable=1, the watchdog will be  

enabled at boot.
* Also, the wdt_period sets the watchdog timer period timeout.

drivers/char/watchdog/booke_wdt.c +36 -0
@@ -47,6 +48,42 @@ u32 booke_wdt_period = WDT_PERIOD_DEFAULT;
 #define WDTP(x)		(TCR_WP(x))
 #endif
 
+void WatchdogHandler(struct pt_regs *regs)
+{
+	unsigned long flags;
+
+	mtspr(SPRN_TCR, mfspr(SPRN_TCR) & ~TCR_WIE);
+	oops_enter();
+
+	console_verbose();
+	bust_spinlocks(1);
+	local_save_flags(flags);
+
+#ifdef CONFIG_PREEMPT
+	printk("PREEMPT ");
+#endif
+#ifdef CONFIG_SMP
+	printk("SMP NR_CPUS=%d ", NR_CPUS);
+#endif
+#ifdef CONFIG_DEBUG_PAGEALLOC
+	printk("DEBUG_PAGEALLOC ");
+#endif
+#ifdef CONFIG_NUMA
+	printk("NUMA ");
+#endif
+	printk("%s\n", ppc_md.name ? ppc_md.name : "");
+
+	print_modules();
+	show_regs(regs);
+
+	bust_spinlocks(0);
+
+	printk(KERN_EMERG "Waiting for hardware watchdog reset...\n");
+	/* spin until hardware reset */
+	while(1)
+		cpu_relax();
+}
+
 /*
  * booke_wdt_ping:
  */
author
#5 lore raw
Quoted 9 lines · Kumar Gala
Quoted 3 lines · Dave Jiang

Have the booke watchdog dump some useful information when triggered. Hopefully that'll give the user some hint of what happened rather than just a mysterious reboot.

Forgot the signed-off-by again (git-commit -s)

I need to stop doing that! Grrrrr....

Quoted 7 lines
Quoted 4 lines
Signature · 2 lines
 Ok here's try 2. Modified the watchdog driver instead per Sergei's 
suggestion.

I'm against having a WatchdogHandler in booke_wdt.c. The idea behind the weak symbol in traps.c is to allow platform code to override the behavior. I'm ok if we put the spew in the generic case.

Ok, I will put it back in the generic handler.

Quoted 1 line

Also, how are you testing this?

I just stop the userland watchdog daemon and the watchdog timeout kicks in. Of course I could also write a kernel module that takes a spinlock and spin.... I tested on the MPC8548 and seems to work as expected.

#6 lore raw
In reply to Kumar Gala

Hello.

Quoted 8 lines · Kumar Gala
Quoted 6 lines

Have the booke watchdog dump some useful information when triggered. Hopefully that'll give the user some hint of what happened rather than just a mysterious reboot.

Ok here's try 2. Modified the watchdog driver instead per Sergei's
suggestion.

I'm against having a WatchdogHandler in booke_wdt.c. The idea behind the weak symbol in traps.c is to allow platform code to override the behavior.

Hmm, to do what?

Quoted 1 line

I'm ok if we put the spew in the generic case.

Well, I was mostly against putting there while(1) cpu_relax();

Quoted 1 line

Also, how are you testing this?

By enabling the watchdog and not then pinging it, I guess...

Quoted 52 lines
Quoted 52 lines
 drivers/char/watchdog/booke_wdt.c |   37 ++++++++++++++++++++++++++ 
+++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
drivers/char/watchdog/booke_wdt.c +1 -0
index 0e23f29..90e5301 100644
@@ -23,6 +23,7 @@
 #include <asm/reg_booke.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
+#include <asm/machdep.h>
 
 /* If the kernel parameter wdt_enable=1, the watchdog will be  

enabled at boot.
* Also, the wdt_period sets the watchdog timer period timeout.

drivers/char/watchdog/booke_wdt.c +31 -0
@@ -47,6 +48,42 @@ u32 booke_wdt_period = WDT_PERIOD_DEFAULT;
 #define WDTP(x)        (TCR_WP(x))
 #endif
 
+void WatchdogHandler(struct pt_regs *regs)
+{
+    unsigned long flags;
+
+    mtspr(SPRN_TCR, mfspr(SPRN_TCR) & ~TCR_WIE);
+    oops_enter();
+
+    console_verbose();
+    bust_spinlocks(1);
+    local_save_flags(flags);
+
+#ifdef CONFIG_PREEMPT
+    printk("PREEMPT ");
+#endif
+#ifdef CONFIG_SMP
+    printk("SMP NR_CPUS=%d ", NR_CPUS);
+#endif
+#ifdef CONFIG_DEBUG_PAGEALLOC
+    printk("DEBUG_PAGEALLOC ");
+#endif
+#ifdef CONFIG_NUMA
+    printk("NUMA ");
+#endif
+    printk("%s\n", ppc_md.name ? ppc_md.name : "");
+
+    print_modules();
+    show_regs(regs);
+
+    bust_spinlocks(0);
+
+    printk(KERN_EMERG "Waiting for hardware watchdog reset...\n");
Quoted 8 lines

drivers/char/watchdog/booke_wdt.c u32 booke_wdt_period = WDT_PERIOD_DEFAULT; · line 89

Quoted 8 lines
drivers/char/watchdog/booke_wdt.c +5 -0
+    /* spin until hardware reset */
+    while(1)
+        cpu_relax();
+}
+
 /*
  * booke_wdt_ping:
  */

WBR, Sergei

author
#7 lore raw
In reply to Kumar Gala

Have the booke watchdog dump some useful information when triggered. Hopefully that'll give the user some hint of what happened rather than just a mysterious reboot.

---

 arch/powerpc/kernel/traps.c |   32 +++++++++++++++++++++++++++++++-
 1 files changed, 31 insertions(+), 1 deletions(-)
arch/powerpc/kernel/traps.c +31 -1
index f786222..e4d6186 100644
@@ -1108,9 +1108,39 @@ void unrecoverable_exception(struct pt_regs *regs)
  */
 void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
 {
+	unsigned long flags;
+
 	/* Generic WatchdogHandler, implement your own */
 	mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
-	return;
+	oops_enter();
+
+	console_verbose();
+	bust_spinlocks(1);
+	local_save_flags(flags);
+
+#ifdef CONFIG_PREEMPT
+	printk("PREEMPT ");
+#endif
+#ifdef CONFIG_SMP
+	printk("SMP NR_CPUS=%d ", NR_CPUS);
+#endif
+#ifdef CONFIG_DEBUG_PAGEALLOC
+	printk("DEBUG_PAGEALLOC ");
+#endif
+#ifdef CONFIG_NUMA
+	printk("NUMA ");
+#endif
+	printk("%s\n", ppc_md.name ? ppc_md.name : "");
+
+	print_modules();
+	show_regs(regs);
+
+	bust_spinlocks(0);
+
+	printk(KERN_EMERG "Waiting for hardware watchdog reset...\n");
+	/* spin until hardware reset */
+	while(1)
+		cpu_relax();
 }
 
 void WatchdogException(struct pt_regs *regs)
#8 lore raw
Quoted 3 lines · Dave Jiang

Have the booke watchdog dump some useful information when triggered. Hopefully that'll give the user some hint of what happened rather than just a mysterious reboot.

Why not call either die() or panic()? Won't they do what you want?

Paul.

author
#9 lore raw
In reply to Dave Jiang
Quoted 6 lines · Paul Mackerras
Quoted 3 lines · Dave Jiang

Have the booke watchdog dump some useful information when triggered. Hopefully that'll give the user some hint of what happened rather than just a mysterious reboot.

Why not call either die() or panic()? Won't they do what you want?

I think the main thing I'm worried about is kexec. Both panic and die handler can potentially call kexec. The watchdog cannot be killed unless a hardware reset happens. So it is possible that during the boot of the kexec'd kernel the watchdog forces a hardware reset. In fact, the watchdog can actually make kdump rather tricky since the current implementation makes it being kept alive via userland.

I'm thinking that the only way to get around that is to ping the watchdog consistently in something such as the timer interrupt. But then we probably have to move the initialization of the driver into core kernel code and not a char driver. Do we want to do that?

Signature · 6 lines
------------------------------------------------------
Dave Jiang
Software Engineer
MontaVista Software, Inc.
http://www.mvista.com
------------------------------------------------------