Re: [PATCH] timers/itimer: Preserve nonzero remaining time for active timers
From: Frederic Weisbecker
Date: Mon Nov 02 2026 - 17:19:36 EST
Le Mon, Nov 02, 2026 at 09:01:49AM +0200, Avi Weiss a écrit :
> itimer_get_remtime() preserves positive remainders below one
> microsecond, but struct timeval only stores whole microseconds.
> So, for example, the conversion to tv_usec truncates a 500 ns
> remainder to zero, causing getitimer(ITIMER_REAL) to report an
> active timer as disarmed.
>
> Clamp active remainders below one microsecond to one microsecond
> so they remain nonzero after conversion.
>
> Fixes: 2ff678b8da64 ("[PATCH] hrtimer: switch itimers to hrtimer")
> Signed-off-by: Avi Weiss <thnkslprpt@xxxxxxxxx>
> ---
> kernel/time/itimer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/time/itimer.c b/kernel/time/itimer.c
> index 03a32dffc56c..a472a4f8babb 100644
> --- a/kernel/time/itimer.c
> +++ b/kernel/time/itimer.c
> @@ -36,7 +36,7 @@ static struct timespec64 itimer_get_remtime(struct hrtimer *timer)
> * then we return 0 - which is correct.
> */
> if (hrtimer_active(timer)) {
> - if (rem <= 0)
> + if (rem < NSEC_PER_USEC)
> rem = NSEC_PER_USEC;
Right, though at this point it can race with the hrtimer at any point.
But it makes sense to have.
Thanks.
> } else
> rem = 0;
>
> base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e
> --
> 2.43.0
>
--
Frederic Weisbecker
SUSE Labs