Skip to contentSkip to conversation

watchdog: Handle timer wrap around

PATCH New Chris Packham 2 participants 3 messages Feb 24, 2020 – Mar 16, 2020 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: Handle timer wrap around

On some platforms/architectures the value from get_timer() can wrap. This is particularly problematic when long-running code needs to measure a time difference as is the case with watchdog_reset() which tries to avoid tickling the watchdog too frequently.

Use time_after() from time.h instead of a plain > comparison to avoid any issues with the time wrapping on a system that has been sitting in u-boot for a long time.

---

 drivers/watchdog/wdt-uclass.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/watchdog/wdt-uclass.c +2 -1
index cf1c52747397..d9e4dc7cb8a4 100644
@@ -7,6 +7,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <hang.h>
+#include <time.h>
 #include <wdt.h>
 #include <dm/device-internal.h>
 #include <dm/lists.h>
@@ -83,7 +84,7 @@ void watchdog_reset(void)
 
 	/* Do not reset the watchdog too often */
 	now = get_timer(0);
-	if (now > next_reset) {
+	if (time_after(now, next_reset)) {
 		next_reset = now + 1000;	/* reset every 1000ms */
 		wdt_reset(gd->watchdog_dev);
 	}
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 watchdog: Handle timer wrap around

Quoted 10 lines · Chris Packham

On some platforms/architectures the value from get_timer() can wrap. This is particularly problematic when long-running code needs to measure a time difference as is the case with watchdog_reset() which tries to avoid tickling the watchdog too frequently.

Use time_after() from time.h instead of a plain > comparison to avoid any issues with the time wrapping on a system that has been sitting in u-boot for a long time.

Thanks,
Stefan

#2 lore raw

PATCH 1/1 watchdog: Handle timer wrap around

In reply to Chris Packham
Quoted 10 lines · Chris Packham

On some platforms/architectures the value from get_timer() can wrap. This is particularly problematic when long-running code needs to measure a time difference as is the case with watchdog_reset() which tries to avoid tickling the watchdog too frequently.

Use time_after() from time.h instead of a plain > comparison to avoid any issues with the time wrapping on a system that has been sitting in u-boot for a long time.

Applied to u-boot-marvell/master.

Thanks,
Stefan