Fix set_timeout for big timeout values
Subsystems (2)
PATCH 1/1 Fix set_timeout for big timeout values
This patch implements the documented behavior: if max_hw_heartbeat_ms is implemented, the minimum of the set_timeout argument and max_hw_heartbeat_ms should be used.
Previously only the first 7 bits were used and the input argument was returned.
--- drivers/watchdog/imx2_wdt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/watchdog/imx2_wdt.c +4 -2
@@ -178,9 +178,11 @@ static void __imx2_wdt_set_timeout(struct watchdog_device *wdog,static int imx2_wdt_set_timeout (struct watchdog_device *wdog,unsigned int new_timeout) { -__imx2_wdt_set_timeout (wdog, new_timeout); +unsigned int actual; - wdog->timeout = new_timeout; + actual =min (new_timeout, wdog->max_hw_heartbeat_ms *1000 ); +__imx2_wdt_set_timeout (wdog, actual); + wdog->timeout = actual;return 0 ; }
Signature · 1 line
2.7.4
Guenter Roeck
maintainerQuoted 16 lines · Georg Hofmann
This patch implements the documented behavior: if
max_hw_heartbeat_msis implemented, the minimum of theset_timeoutargument andmax_hw_heartbeat_msshould be used.
Previously only the first 7 bits were used and the input argument was returned.Signed-off-by Georg Hofmann <[email protected]>--- drivers/watchdog/imx2_wdt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/watchdog/imx2_wdt.c +0
-0
drivers/watchdog/imx2_wdt.c static void __imx2_wdt_set_timeout(struct watchdog_device *wdog, · line 185
Quoted 10 lines
drivers/watchdog/imx2_wdt.c +4
-2@@ -178,9 +178,11 @@ static void __imx2_wdt_set_timeout(struct watchdog_device *wdog,static int imx2_wdt_set_timeout (struct watchdog_device *wdog,unsigned int new_timeout) { -__imx2_wdt_set_timeout (wdog, new_timeout); +unsigned int actual; - wdog->timeout = new_timeout; + actual =min (new_timeout, wdog->max_hw_heartbeat_ms *1000 ); +__imx2_wdt_set_timeout (wdog, actual); + wdog->timeout = actual;
That defeats the purpose of having an internal maximum. wdog->timeout should still be set to the requested value.
Guenter
----- Original Message -----
Quoted 38 lines
From: "Guenter Roeck" <[email protected]>
To: "Georg Hofmann" <[email protected]>, [email protected]
Cc: [email protected]
Sent: Saturday, April 6, 2019 3:25:44 PM
Subject: Re: [PATCH] Fixset_timeoutfor big timeout valuesQuoted 17 lines · Georg Hofmann
This patch implements the documented behavior: if
max_hw_heartbeat_msis implemented, the minimum of theset_timeoutargument andmax_hw_heartbeat_msshould be used.
Previously only the first 7 bits were used and the input argument was returned.Signed-off-by Georg Hofmann <[email protected]>--- drivers/watchdog/imx2_wdt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/watchdog/imx2_wdt.c +0
-0@@ -178,9 +178,11 @@ static void __imx2_wdt_set_timeout(struct watchdog_device *wdog,drivers/watchdog/imx2_wdt.c static void __imx2_wdt_set_timeout(struct watchdog_device · line 186
Quoted 10 lines
drivers/watchdog/imx2_wdt.c +4
-2static int imx2_wdt_set_timeout (struct watchdog_device *wdog,unsigned int new_timeout) { -__imx2_wdt_set_timeout (wdog, new_timeout); +unsigned int actual; - wdog->timeout = new_timeout; + actual =min (new_timeout, wdog->max_hw_heartbeat_ms *1000 ); +__imx2_wdt_set_timeout (wdog, actual); + wdog->timeout = actual;That defeats the purpose of having an internal maximum.
wdog->timeoutshould still be set to the requested value.
Quoted 1 line
Guenter
Hi,
I don't understand, the internal maximum is max_hw_heartbeat_ms. I have used the same code as other watchdog drivers (e.g. aspeed_wdt.c, loongson1_wdt.c, ...).
I have submitted this patch because I was writing a userspace
program and I expected a different behavior on the ioctl.
The watchdog documentation says (Documentation/watchdog/watchdog-api.txt):
Setting and getting the timeout:
For some drivers it is possible to modify the watchdog timeout on the fly with the SETTIMEOUT ioctl, those drivers have the WDIOF_SETTIMEOUT flag set in their option field. The argument is an integer representing the timeout in seconds. The driver returns the real timeout used in the same variable, and this timeout might differ from the requested one due to limitation of the hardware.
int timeout = 45;
ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
printf("The timeout was set to %d seconds\n", timeout);This example might actually print "The timeout was set to 60 seconds" if the device has a granularity of minutes for its timeout.
As the watchdog core driver reads the timeout just after write, I have to set the applied value to timeout.
Initially I thought I should get a error message if the timeout can't be applied, but the documentation describes another behavior.
Georg
Guenter Roeck
maintainerQuoted 63 lines · Georg Hofmann
----- Original Message -----
Quoted 38 lines
From: "Guenter Roeck" <[email protected]>
To: "Georg Hofmann" <[email protected]>, [email protected]
Cc: [email protected]
Sent: Saturday, April 6, 2019 3:25:44 PM
Subject: Re: [PATCH] Fixset_timeoutfor big timeout valuesQuoted 17 lines · Georg Hofmann
This patch implements the documented behavior: if
max_hw_heartbeat_msis implemented, the minimum of theset_timeoutargument andmax_hw_heartbeat_msshould be used.
Previously only the first 7 bits were used and the input argument was returned.Signed-off-by Georg Hofmann <[email protected]>--- drivers/watchdog/imx2_wdt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/watchdog/imx2_wdt.c +0
-0@@ -178,9 +178,11 @@ static void __imx2_wdt_set_timeout(struct watchdog_device *wdog,drivers/watchdog/imx2_wdt.c static void __imx2_wdt_set_timeout(struct watchdog_device · line 186
Quoted 10 lines
drivers/watchdog/imx2_wdt.c +4
-2static int imx2_wdt_set_timeout (struct watchdog_device *wdog,unsigned int new_timeout) { -__imx2_wdt_set_timeout (wdog, new_timeout); +unsigned int actual; - wdog->timeout = new_timeout; + actual =min (new_timeout, wdog->max_hw_heartbeat_ms *1000 ); +__imx2_wdt_set_timeout (wdog, actual); + wdog->timeout = actual;That defeats the purpose of having an internal maximum.
wdog->timeoutshould still be set to the requested value.Quoted 1 line
Guenter
Hi,
I don't understand, the internal maximum is
max_hw_heartbeat_ms. I have used the same code as other watchdog drivers (e.g.aspeed_wdt.c,loongson1_wdt.c, ...).I have submitted this patch because I was writing a userspace
program and I expected a different behavior on the ioctl.
The watchdog documentation says (Documentation/watchdog/watchdog-api.txt):
Setting and getting the timeout:For some drivers it is possible to modify the watchdog timeout on the fly with the SETTIMEOUT ioctl, those drivers have the
WDIOF_SETTIMEOUTflag set in their option field. The argument is an integer representing the timeout in seconds. The driver returns the real timeout used in the same variable, and this timeout might differ from the requested one due to limitation of the hardware.int timeout = 45; ioctl(fd, WDIOC_SETTIMEOUT, &timeout); printf("The timeout was set to %d seconds\n", timeout);
Quoted 9 lines
This example might actually print "The timeout was set to 60 seconds" if the device has a granularity of minutes for its timeout.
As the watchdog core driver reads the timeout just after write, I have to set the applied value to timeout.
Initially I thought I should get a error message if the timeout can't be applied, but the documentation describes another behavior.
The whole point of max_hw_heartbeat_ms is to be able to specify a larger timeout than the maximum supported by the hardware. In extreme cases, max_hw_heartbeat_ms could be as low as 1 second (or less). Limiting wdog->timeout to that value is identical to not having max_hw_heartbeat_ms in the first place, and thus quite pointless.
aspeed_wdt.c does _not_ set wdd->timeout to the 'actual' value. loongson1_wdt.c doesn't do it either. If any other driver does it, it is wrong.
Your patch is almost correct, except it should keep "wdog->timeout = new_timeout;".
Guenter
----- Original Message -----
Quoted 86 lines
From: "Guenter Roeck" <[email protected]>
To: "Georg Hofmann" <[email protected]>
Cc: [email protected], [email protected]
Sent: Saturday, April 6, 2019 5:46:08 PM
Subject: Re: [PATCH] Fixset_timeoutfor big timeout valuesQuoted 63 lines · Georg Hofmann
----- Original Message -----
Quoted 38 lines
From: "Guenter Roeck" <[email protected]>
To: "Georg Hofmann" <[email protected]>, [email protected]
Cc: [email protected]
Sent: Saturday, April 6, 2019 3:25:44 PM
Subject: Re: [PATCH] Fixset_timeoutfor big timeout valuesQuoted 17 lines · Georg Hofmann
This patch implements the documented behavior: if
max_hw_heartbeat_msis implemented, the minimum of theset_timeoutargument andmax_hw_heartbeat_msshould be used.
Previously only the first 7 bits were used and the input argument was returned.Signed-off-by Georg Hofmann <[email protected]>--- drivers/watchdog/imx2_wdt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/watchdog/imx2_wdt.c +0
-0@@ -178,9 +178,11 @@ static void __imx2_wdt_set_timeout(struct watchdog_device *wdog,drivers/watchdog/imx2_wdt.c static void __imx2_wdt_set_timeout(struct watchdog_device · line 186
Quoted 10 lines
drivers/watchdog/imx2_wdt.c +4
-2static int imx2_wdt_set_timeout (struct watchdog_device *wdog,unsigned int new_timeout) { -__imx2_wdt_set_timeout (wdog, new_timeout); +unsigned int actual; - wdog->timeout = new_timeout; + actual =min (new_timeout, wdog->max_hw_heartbeat_ms *1000 ); +__imx2_wdt_set_timeout (wdog, actual); + wdog->timeout = actual;That defeats the purpose of having an internal maximum.
wdog->timeoutshould still be set to the requested value.Quoted 1 line
Guenter
Hi,
I don't understand, the internal maximum is
max_hw_heartbeat_ms. I have used the same code as other watchdog drivers (e.g.aspeed_wdt.c,loongson1_wdt.c, ...).I have submitted this patch because I was writing a userspace
program and I expected a different behavior on the ioctl.
The watchdog documentation says (Documentation/watchdog/watchdog-api.txt):
Setting and getting the timeout:For some drivers it is possible to modify the watchdog timeout on the fly with the SETTIMEOUT ioctl, those drivers have the
WDIOF_SETTIMEOUTflag set in their option field. The argument is an integer representing the timeout in seconds. The driver returns the real timeout used in the same variable, and this timeout might differ from the requested one due to limitation of the hardware.int timeout = 45; ioctl(fd, WDIOC_SETTIMEOUT, &timeout); printf("The timeout was set to %d seconds\n", timeout);Quoted 9 lines
This example might actually print "The timeout was set to 60 seconds" if the device has a granularity of minutes for its timeout.
As the watchdog core driver reads the timeout just after write, I have to set the applied value to timeout.
Initially I thought I should get a error message if the timeout can't be applied, but the documentation describes another behavior.
The whole point of
max_hw_heartbeat_msis to be able to specify a larger timeout than the maximum supported by the hardware. In extreme cases,max_hw_heartbeat_mscould be as low as 1 second (or less). Limitingwdog->timeoutto that value is identical to not havingmax_hw_heartbeat_msin the first place, and thus quite pointless.
Quoted 8 lines
aspeed_wdt.cdoes _not_ setwdd->timeoutto the 'actual' value.loongson1_wdt.cdoesn't do it either. If any other driver does it, it is wrong.Your patch is almost correct, except it should keep "
wdog->timeout=new_timeout;".Guenter
ah, ok, I missed that. I will change test it and than resend the patch. Thanks for your time.
Georg