[U-Boot-Users] [PATCH] lwmon5 watchdog: limit trigger rate

Wolfgang Denk
2008-04-22T14:24:52Z

From: Yuri Tikhonov <yur@emcraft.com>

Limit the rate of h/w watch-dog triggering on the LWMON5 board by
the CONFIG_WD_MAX_RATE value.

Note that an earlier version of this patch which used microseconds
instead of ticks dis not work. The problem was that we used
usec2ticks() to convert microseconds into ticks. usec2ticks() uses
get_tbclk(), which in turn calls get_sys_info(). It turns out that
this function does a lot of prolonged operations (like divisions)
which take too much time so we do not trigger the watchdog in time,
and it resets the system.

Signed-off-by: Yuri Tikhonov <yur@emcraft.com>
---
board/lwmon5/lwmon5.c | 18 ++++++++++++++++++
include/asm-ppc/global_data.h | 3 +++
include/configs/lwmon5.h | 1 +
3 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/board/lwmon5/lwmon5.c b/board/lwmon5/lwmon5.c
index e5fa259..b63fbdc 100644
--- a/board/lwmon5/lwmon5.c
+++ b/board/lwmon5/lwmon5.c
@@ -476,6 +476,24 @@ int is_pci_host(struct pci_controller *hose)
void hw_watchdog_reset(void)
{
int val;
+#if defined(CONFIG_WD_MAX_RATE)
+ unsigned long long ct = get_ticks();
+
+ /*
+ * Don't allow watch-dog triggering more frequently than
+ * the predefined value CONFIG_WD_MAX_RATE [ticks].
+ */
+ if (ct >= gd->wdt_last) {
+ if ((ct - gd->wdt_last) < CONFIG_WD_MAX_RATE)
+ return;
+ } else {
+ /* Time base counter had been reset */
+ if (((unsigned long long)(-1) - gd->wdt_last + ct) <
+ CONFIG_WD_MAX_RATE)
+ return;
+ }
+ gd->wdt_last = get_ticks();
+#endif

/*
* Toggle watchdog output
diff --git a/include/asm-ppc/global_data.h b/include/asm-ppc/global_data.h
index e07092b..4657604 100644
--- a/include/asm-ppc/global_data.h
+++ b/include/asm-ppc/global_data.h
@@ -155,6 +155,9 @@ typedef struct global_data {
#if defined(CONFIG_LWMON) || defined(CONFIG_LWMON5)
unsigned long kbd_status;
#endif
+#if defined(CONFIG_WD_MAX_RATE)
+ unsigned long long wdt_last; /* trace watch-dog triggering rate */
+#endif
void **jt; /* jump table */
} gd_t;

diff --git a/include/configs/lwmon5.h b/include/configs/lwmon5.h
index ced7ba6..58f078b 100644
--- a/include/configs/lwmon5.h
+++ b/include/configs/lwmon5.h
@@ -455,6 +455,7 @@

#define CONFIG_HW_WATCHDOG 1 /* Use external HW-Watchdog */
#define CONFIG_WD_PERIOD 40000 /* in usec */
+#define CONFIG_WD_MAX_RATE 66600 /* in ticks */

/*
* For booting Linux, the board info and command line data
--
1.5.4.2