On Fri, Jul 05, 2019 at 03:05:24PM +0200, Klemens Nanni wrote:
> Simple reduction here as done in many other places, tested on an ARMv7
> BeagleBone Black with
> 
>       omdog0 at simplebus0 rev 0.1
> 
>       # sysctl kern.watchdog.period=3
>       # sysctl kern.watchdog.auto=0
> 
> which reliably reboots the system after the specified amount of time.
> 
> OK?

This looks incorrect.  If the watchdog period is odd you're truncating
the timeout by one second.

If you convert to milliseconds it's fine to divide by 2, so I suggest
you do that.

Of course, there's still an overflow problem here that we ought to
check for at sysctl(2) time.  But that was here before and I only just
noticed it, so, one issue at a time.

> Index: kern/kern_watchdog.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/kern_watchdog.c,v
> retrieving revision 1.13
> diff -u -p -r1.13 kern_watchdog.c
> --- kern/kern_watchdog.c      9 Jan 2017 17:58:44 -0000       1.13
> +++ kern/kern_watchdog.c      15 Jun 2019 23:42:24 -0000
> @@ -54,7 +54,7 @@ wdog_tickle(void *arg)
>       if (wdog_ctl_cb == NULL)
>               return;
>       (void) (*wdog_ctl_cb)(wdog_ctl_cb_arg, wdog_period);
> -     timeout_add(&wdog_timeout, wdog_period * hz / 2);
> +     timeout_add_sec(&wdog_timeout, wdog_period / 2);
>  }
>  
>  void
> @@ -100,7 +100,7 @@ sysctl_wdog(int *name, u_int namelen, vo
>  
>       if (wdog_auto && wdog_period > 0) {
>               (void) (*wdog_ctl_cb)(wdog_ctl_cb_arg, wdog_period);
> -             timeout_add(&wdog_timeout, wdog_period * hz / 2);
> +             timeout_add_sec(&wdog_timeout, wdog_period / 2);
>       } else
>               timeout_del(&wdog_timeout);
>  
> 

Reply via email to