Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <dave@stgolabs.net>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20230123173206.6764-3-dave@stgolabs.net

authored by

Davidlohr Bueso and committed by
Thomas Gleixner
0c52310f c14fd3dc

+11 -3
+11 -3
kernel/time/hrtimer.c
··· 2272 2272 /** 2273 2273 * schedule_hrtimeout_range_clock - sleep until timeout 2274 2274 * @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 2276 2276 * @mode: timer mode 2277 2277 * @clock_id: timer clock to be used 2278 2278 */ ··· 2299 2299 return -EINTR; 2300 2300 } 2301 2301 2302 + /* 2303 + * Override any slack passed by the user if under 2304 + * rt contraints. 2305 + */ 2306 + if (rt_task(current)) 2307 + delta = 0; 2308 + 2302 2309 hrtimer_init_sleeper_on_stack(&t, clock_id, mode); 2303 2310 hrtimer_set_expires_range_ns(&t.timer, *expires, delta); 2304 2311 hrtimer_sleeper_start_expires(&t, mode); ··· 2325 2318 /** 2326 2319 * schedule_hrtimeout_range - sleep until timeout 2327 2320 * @expires: timeout value (ktime_t) 2328 - * @delta: slack in expires timeout (ktime_t) 2321 + * @delta: slack in expires timeout (ktime_t) for SCHED_OTHER tasks 2329 2322 * @mode: timer mode 2330 2323 * 2331 2324 * Make the current task sleep until the given expiry time has ··· 2333 2326 * the current task state has been set (see set_current_state()). 2334 2327 * 2335 2328 * The @delta argument gives the kernel the freedom to schedule the 2336 - * actual wakeup to a time that is both power and performance friendly. 2329 + * actual wakeup to a time that is both power and performance friendly 2330 + * for regular (non RT/DL) tasks. 2337 2331 * The kernel give the normal best effort behavior for "@expires+@delta", 2338 2332 * but may decide to fire the timer earlier, but no earlier than @expires. 2339 2333 *