[tip: timers/core] hrtimer: Use hrtimer_start_expires_user() for hrtimer sleepers
From: tip-bot2 for Thomas Gleixner
Date: Fri May 01 2026 - 15:45:29 EST
The following commit has been merged into the timers/core branch of tip:
Commit-ID: b40c927345a91e687eac4c3c5ca03a99643cd0c4
Gitweb: https://git.kernel.org/tip/b40c927345a91e687eac4c3c5ca03a99643cd0c4
Author: Thomas Gleixner <tglx@xxxxxxxxxx>
AuthorDate: Wed, 08 Apr 2026 13:53:52 +02:00
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Fri, 01 May 2026 21:36:11 +02:00
hrtimer: Use hrtimer_start_expires_user() for hrtimer sleepers
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>
Tested-by: Calvin Owens <calvin@xxxxxxxxxx>
Reviewed-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Link: https://patch.msgid.link/20260408114952.062400833@xxxxxxxxxx
---
kernel/time/hrtimer.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 79aaac4..8cfc7aa 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -2315,7 +2315,11 @@ void hrtimer_sleeper_start_expires(struct hrtimer_sleeper *sl, enum hrtimer_mode
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);