Skip to contentSkip to conversation

allow opting out of WATCHDOG_RESET() from timer interrupt

PATCH Superseded Rasmus Villemoes 3 participants 6 messages Apr 14, 2021 – Apr 27, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover allow opting out of WATCHDOG_RESET() from timer interrupt

This is a resend of v3 from a year ago. Please consider applying.

v4: rebase to current master.

v3: add fixup patch for mpc83xx_timer, add documentation hunk to README, also update m68k instead of only ppc.

v2: add documentation comment

Rasmus Villemoes (2):
timer: mpc83xx_timer: fix build with CONFIG_{HW_,}WATCHDOG allow opting out of WATCHDOG_RESET() from timer interrupt

 README                        | 9 +++++++++
 arch/m68k/lib/time.c          | 2 +-
 arch/powerpc/lib/interrupts.c | 2 +-
 drivers/timer/mpc83xx_timer.c | 6 +++++-
 4 files changed, 16 insertions(+), 3 deletions(-)
Signature · 1 line
2.29.2
#1 lore raw

PATCH v4 1/2 timer: mpc83xx_timer: fix build with CONFIG_{HW_, }WATCHDOG

The code, which is likely copied from arch/powerpc/lib/interrupts.c, lacks a fallback definition of CONFIG_SYS_WATCHDOG_FREQ and refers to a non-existing timestamp variable - obviously priv->timestamp is meant.

---
 drivers/timer/mpc83xx_timer.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/timer/mpc83xx_timer.c +5 -1
index f4f6e90387..9adb4b4cab 100644
@@ -20,6 +20,10 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#ifndef CONFIG_SYS_WATCHDOG_FREQ
+#define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2)
+#endif
+
 /**
  * struct mpc83xx_timer_priv - Private data structure for MPC83xx timer driver
  * @decrementer_count: Value to which the decrementer register should be re-set
@@ -171,7 +175,7 @@ void timer_interrupt(struct pt_regs *regs)
 	priv->timestamp++;
 
 #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
-	if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
+	if ((priv->timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
 		WATCHDOG_RESET();
 #endif    /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
 
Signature · 1 line
2.29.2
#2 lore raw

PATCH v4 2/2 allow opting out of WATCHDOG_RESET() from timer interrupt

In reply to Rasmus Villemoes

Having WATCHDOG_RESET() called automatically from the timer interrupt runs counter to the idea of a watchdog device - if the board runs into an infinite loops with interrupts still enabled, the watchdog will never fire.

When using CONFIG_(SPL_)WDT, the watchdog_reset function is a lot more complicated than just poking a few SOC-specific registers - it involves accessing all kinds of global data, and if the interrupt happens at the wrong time (say, in the middle of an WATCHDOG_RESET() call from ordinary code), that can end up corrupting said global data.

Allow the board to opt out of calling WATCHDOG_RESET() from the timer interrupt handler by setting CONFIG_SYS_WATCHDOG_FREQ to 0 - as that setting is currently nonsensical (it would be compile-time divide-by-zero), it cannot affect any existing boards.

Add documentation for both the existing and extended meaning of CONFIG_SYS_WATCHDOG_FREQ.

---
 README                        | 9 +++++++++
 arch/m68k/lib/time.c          | 2 +-
 arch/powerpc/lib/interrupts.c | 2 +-
 drivers/timer/mpc83xx_timer.c | 2 +-
 4 files changed, 12 insertions(+), 3 deletions(-)
README +9 -0
index a565748e43..ad13092bbb 100644
@@ -747,6 +747,15 @@ The following options need to be configured:
 		SoC, then define this variable and provide board
 		specific code for the "hw_watchdog_reset" function.
 
+		CONFIG_SYS_WATCHDOG_FREQ
+		Some platforms automatically call WATCHDOG_RESET()
+		from the timer interrupt handler every
+		CONFIG_SYS_WATCHDOG_FREQ interrupts. If not set by the
+		board configuration file, a default of CONFIG_SYS_HZ/2
+		(i.e. 500) is used. Setting CONFIG_SYS_WATCHDOG_FREQ
+		to 0 disables calling WATCHDOG_RESET() from the timer
+		interrupt.
+
 - Real-Time Clock:
 
 		When CONFIG_CMD_DATE is selected, the type of the RTC
arch/m68k/lib/time.c +1 -1
index cbe29e72a8..ebb2ac54db 100644
@@ -71,7 +71,7 @@ void dtimer_interrupt(void *not_used)
 		timestamp++;
 
 		#if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
-		if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0) {
+		if (CONFIG_SYS_WATCHDOG_FREQ && (timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0) {
 			WATCHDOG_RESET ();
 		}
 		#endif    /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
arch/powerpc/lib/interrupts.c +1 -1
index 73f270002c..5ba4cd0c13 100644
@@ -80,7 +80,7 @@ void timer_interrupt(struct pt_regs *regs)
 	timestamp++;
 
 #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
-	if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
+	if (CONFIG_SYS_WATCHDOG_FREQ && (timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
 		WATCHDOG_RESET ();
 #endif    /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
 
drivers/timer/mpc83xx_timer.c +1 -1
index 9adb4b4cab..952293195f 100644
@@ -175,7 +175,7 @@ void timer_interrupt(struct pt_regs *regs)
 	priv->timestamp++;
 
 #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
-	if ((priv->timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
+	if (CONFIG_SYS_WATCHDOG_FREQ && (priv->timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
 		WATCHDOG_RESET();
 #endif    /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
 
Signature · 1 line
2.29.2
#3 lore raw

v4 cover allow opting out of WATCHDOG_RESET() from timer interrupt

In reply to Rasmus Villemoes
Quoted 13 lines · Rasmus Villemoes

This is a resend of v3 from a year ago. Please consider applying.

v4: rebase to current master.

v3: add fixup patch for mpc83xx_timer, add documentation hunk to README, also update m68k instead of only ppc.

v2: add documentation comment

Rasmus Villemoes (2):
timer: mpc83xx_timer: fix build with CONFIG_{HW_,}WATCHDOG allow opting out of WATCHDOG_RESET() from timer interrupt

Quoted 6 lines
 README                        | 9 +++++++++
 arch/m68k/lib/time.c          | 2 +-
 arch/powerpc/lib/interrupts.c | 2 +-
 drivers/timer/mpc83xx_timer.c | 6 +++++-
 4 files changed, 16 insertions(+), 3 deletions(-)

ping

#4 lore raw

v4 cover allow opting out of WATCHDOG_RESET() from timer interrupt

Quoted 14 lines · Rasmus Villemoes
Quoted 13 lines · Rasmus Villemoes

This is a resend of v3 from a year ago. Please consider applying.

v4: rebase to current master.

v3: add fixup patch for mpc83xx_timer, add documentation hunk to README, also update m68k instead of only ppc.

v2: add documentation comment

Rasmus Villemoes (2):
timer: mpc83xx_timer: fix build with CONFIG_{HW_,}WATCHDOG allow opting out of WATCHDOG_RESET() from timer interrupt

Quoted 8 lines
Quoted 6 lines
 README                        | 9 +++++++++
 arch/m68k/lib/time.c          | 2 +-
 arch/powerpc/lib/interrupts.c | 2 +-
 drivers/timer/mpc83xx_timer.c | 6 +++++-
 4 files changed, 16 insertions(+), 3 deletions(-)

ping

As watchdog stuff, Stefan?

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210426/c17b1c39/attachment.sig>
#5 lore raw

v4 cover allow opting out of WATCHDOG_RESET() from timer interrupt

Quoted 22 lines · Tom Rini
Quoted 21 lines · Rasmus Villemoes
Quoted 19 lines · Rasmus Villemoes

This is a resend of v3 from a year ago. Please consider applying.

v4: rebase to current master.

v3: add fixup patch for mpc83xx_timer, add documentation hunk to README, also update m68k instead of only ppc.

v2: add documentation comment

Rasmus Villemoes (2):
timer: mpc83xx_timer: fix build with CONFIG_{HW_,}WATCHDOG allow opting out of WATCHDOG_RESET() from timer interrupt

  README                        | 9 +++++++++
  arch/m68k/lib/time.c          | 2 +-
  arch/powerpc/lib/interrupts.c | 2 +-
  drivers/timer/mpc83xx_timer.c | 6 +++++-
  4 files changed, 16 insertions(+), 3 deletions(-)
Quoted 3 lines
Quoted 1 line

ping

As watchdog stuff, Stefan?

Looks good. I've pulled all ready WDT related patches and will send the pull request shortly.

Thanks,
Stefan