Skip to content

Commit 0c52310

Browse files
Davidlohr BuesoKAGA-KOKO
authored andcommitted
hrtimer: Ignore slack time for RT tasks in schedule_hrtimeout_range()
While in theory the timer can be triggered before expires + delta, for the cases of RT tasks they really have no business giving any lenience for extra slack time, so override any passed value by the user and always use zero for schedule_hrtimeout_range() calls. Furthermore, this is similar to what the nanosleep(2) family already does with current->timer_slack_ns. Signed-off-by: Davidlohr Bueso <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent c14fd3d commit 0c52310

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

kernel/time/hrtimer.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,7 @@ void __init hrtimers_init(void)
22722272
/**
22732273
* schedule_hrtimeout_range_clock - sleep until timeout
22742274
* @expires: timeout value (ktime_t)
2275-
* @delta: slack in expires timeout (ktime_t)
2275+
* @delta: slack in expires timeout (ktime_t) for SCHED_OTHER tasks
22762276
* @mode: timer mode
22772277
* @clock_id: timer clock to be used
22782278
*/
@@ -2299,6 +2299,13 @@ schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta,
22992299
return -EINTR;
23002300
}
23012301

2302+
/*
2303+
* Override any slack passed by the user if under
2304+
* rt contraints.
2305+
*/
2306+
if (rt_task(current))
2307+
delta = 0;
2308+
23022309
hrtimer_init_sleeper_on_stack(&t, clock_id, mode);
23032310
hrtimer_set_expires_range_ns(&t.timer, *expires, delta);
23042311
hrtimer_sleeper_start_expires(&t, mode);
@@ -2318,15 +2325,16 @@ EXPORT_SYMBOL_GPL(schedule_hrtimeout_range_clock);
23182325
/**
23192326
* schedule_hrtimeout_range - sleep until timeout
23202327
* @expires: timeout value (ktime_t)
2321-
* @delta: slack in expires timeout (ktime_t)
2328+
* @delta: slack in expires timeout (ktime_t) for SCHED_OTHER tasks
23222329
* @mode: timer mode
23232330
*
23242331
* Make the current task sleep until the given expiry time has
23252332
* elapsed. The routine will return immediately unless
23262333
* the current task state has been set (see set_current_state()).
23272334
*
23282335
* The @delta argument gives the kernel the freedom to schedule the
2329-
* actual wakeup to a time that is both power and performance friendly.
2336+
* actual wakeup to a time that is both power and performance friendly
2337+
* for regular (non RT/DL) tasks.
23302338
* The kernel give the normal best effort behavior for "@expires+@delta",
23312339
* but may decide to fire the timer earlier, but no earlier than @expires.
23322340
*

0 commit comments

Comments
 (0)