Re: [patch 03/12] hrtimer: Use hrtimer_start_expires_user() for hrtimer sleepers
From: Peter Zijlstra
Date: Tue Apr 07 2026 - 06:00:29 EST
On Tue, Apr 07, 2026 at 10:54:27AM +0200, Thomas Gleixner wrote:
> Most hrtimer sleepers are user controlled and user space can hand arbitrary
> expiry values in as long as they are valid timespecs. If the expiry value
> is in the past then this requires a full loop through reprogramming the
> clock event device, taking the hrtimer interrupt, waking the task and
> reprogram again.
>
> Use hrtimer_start_expires_user() which avoids the full round trip by
> checking the timer for expiry on enqueue.
>
> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
> Cc: Anna-Maria Behnsen <anna-maria@xxxxxxxxxxxxx>
> Cc: Frederic Weisbecker <frederic@xxxxxxxxxx>
Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> ---
> kernel/time/hrtimer.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> --- a/kernel/time/hrtimer.c
> +++ b/kernel/time/hrtimer.c
> @@ -2152,7 +2152,11 @@ void hrtimer_sleeper_start_expires(struc
> if (IS_ENABLED(CONFIG_PREEMPT_RT) && sl->timer.is_hard)
> mode |= HRTIMER_MODE_HARD;
>
> - hrtimer_start_expires(&sl->timer, mode);
> + /* If already expired, clear the task pointer and set current state to running */
> + if (!hrtimer_start_expires_user(&sl->timer, mode)) {
> + sl->task = NULL;
> + __set_current_state(TASK_RUNNING);
> + }
> }
> EXPORT_SYMBOL_GPL(hrtimer_sleeper_start_expires);
>
>