Re: [PATCH v3] clocksource: Skip watchdog check for large watchdog intervals

From: Jiri Wiesner
Date: Wed Jan 24 2024 - 11:48:24 EST


On Wed, Jan 24, 2024 at 08:03:42AM -0800, Paul E. McKenney wrote:
> On Mon, Jan 22, 2024 at 06:23:50PM +0100, Jiri Wiesner wrote:
> > diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
> > index c108ed8a9804..3052b1f1168e 100644
> > --- a/kernel/time/clocksource.c
> > +++ b/kernel/time/clocksource.c
> > @@ -99,6 +99,7 @@ static u64 suspend_start;
> > * Interval: 0.5sec.
> > */
> > #define WATCHDOG_INTERVAL (HZ >> 1)
> > +#define WATCHDOG_INTERVAL_MAX_NS ((2 * WATCHDOG_INTERVAL) * (NSEC_PER_SEC / HZ))
>
> We need something here to force 64-bit arithmetic on 32-bit systems
> correct?

I think it is not strictly necessary because
(2 * HZ / 2) * (NSEC_PER_SEC / HZ) = HZ * (NSEC_PER_SEC / HZ)
so even a 32-bit integer would not overflow when NSEC_PER_SEC / HZ is
bracketed. But I could make a change to:
+#define WATCHDOG_INTERVAL_MAX_NS ((int64_t)(2ULL * WATCHDOG_INTERVAL * NSEC_PER_SEC / HZ))
to make it explicit and remove the risk of overflow if the constant was
increased (for testing purposes for instance).
--
Jiri Wiesner
SUSE Labs