kernel/hrtimer: Ignore slack time for RT tasks
cover kernel/hrtimer: Ignore slack time for RT tasks
Hi,
Patch 2 simply ignores any user passed slack time in the case of RT/DL tasks for schedule_hrtimeout_range, which is aligned to what nanosleep(2) already does.
Thanks!
Davidlohr Bueso (2):
kernel/hrtimer: Rely on rt_task() for DL tasks too kernel/hrtimer: Ignore slack time for RT tasks
kernel/time/hrtimer.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
Signature · 1 line
2.39.0
PATCH 1/2 kernel/hrtimer: Rely on rt_task() for DL tasks too
Having dl_task() is redundant, trivially simplify.
--- kernel/time/hrtimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/hrtimer.c +1 -1
@@ -2089,7 +2089,7 @@ long hrtimer_nanosleep(ktime_t rqtp, const enum hrtimer_mode mode,u64 slack; slack = current->timer_slack_ns; -if (dl_task (current) ||rt_task (current)) +if (rt_task (current)) slack =0 ;hrtimer_init_sleeper_on_stack (&t, clockid, mode);
Signature · 1 line
2.39.0
Re: [PATCH 1/2] kernel/hrtimer: Rely on rt_task() for DL tasks too
On Mon, Jan 23 2023 at 09:32, Davidlohr Bueso wrote:
'kernel/hrtimer:' is not the correct prefix. Hint:
git log --oneline path/to/file
I fixed that up for you this time....
[tip: timers/core] hrtimer: Rely on rt_task() for DL tasks too
In reply to Davidlohr BuesoThe following commit has been merged into the timers/core branch of tip:
The following commit has been merged into the timers/core branch of tip:
Commit-ID: c14fd3dcacaa480394d3ac0b4a91a7d17a4b5516 Gitweb: https://git.kernel.org/tip/c14fd3dcacaa480394d3ac0b4a91a7d17a4b5516 Author: Davidlohr Bueso <[email protected]> AuthorDate: Mon, 23 Jan 2023 09:32:05 -08:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 31 Jan 2023 11:23:07 +01:00
hrtimer: Rely on rt_task() for DL tasks too
Checking dl_task() is redundant as rt_task() returns true for deadline tasks too.
--- kernel/time/hrtimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/hrtimer.c +1 -1
@@ -2089,7 +2089,7 @@ long hrtimer_nanosleep(ktime_t rqtp, const enum hrtimer_mode mode,u64 slack; slack = current->timer_slack_ns; -if (dl_task (current) ||rt_task (current)) +if (rt_task (current)) slack =0 ;hrtimer_init_sleeper_on_stack (&t, clockid, mode);
PATCH 2/2 kernel/hrtimer: Ignore slack time for RT tasks
In reply to Davidlohr BuesoWhile 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.
--- kernel/time/hrtimer.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
kernel/time/hrtimer.c +11 -3
@@ -2270,7 +2270,7 @@ void __init hrtimers_init(void)/** * schedule_hrtimeout_range_clock - sleep until timeout * @expires: timeout value (ktime_t) -* @delta: slack in expires timeout (ktime_t) +* @delta: slack in expires timeout (ktime_t) for SCHED_OTHER tasks * @mode: timer mode * @clock_id: timer clock to be used */
@@ -2297,6 +2297,13 @@ schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta,return -EINTR ; } +/* +* Override any slack passed by the user if under +* rt contraints. +*/ +if (rt_task (current)) + delta =0 ; +hrtimer_init_sleeper_on_stack (&t, clock_id, mode);hrtimer_set_expires_range_ns (&t.timer, *expires, delta);hrtimer_sleeper_start_expires (&t, mode);
@@ -2316,7 +2323,7 @@ EXPORT_SYMBOL_GPL(schedule_hrtimeout_range_clock);/** * schedule_hrtimeout_range - sleep until timeout * @expires: timeout value (ktime_t) -* @delta: slack in expires timeout (ktime_t) +* @delta: slack in expires timeout (ktime_t) for SCHED_OTHER tasks * @mode: timer mode * * Make the current task sleep until the given expiry time has
@@ -2324,7 +2331,8 @@ EXPORT_SYMBOL_GPL(schedule_hrtimeout_range_clock);* the current task state has been set (see set_current_state()). * * The @delta argument gives the kernel the freedom to schedule the -* actual wakeup to a time that is both power and performance friendly. +* actual wakeup to a time that is both power and performance friendly +* for regular (non RT/DL) tasks. * The kernel give the normal best effort behavior for "@expires+@delta", * but may decide to fire the timer earlier, but no earlier than @expires. *
Signature · 1 line
2.39.0
[tip: timers/core] hrtimer: Ignore slack time for RT tasks in schedule_hrtimeout_range()
The following commit has been merged into the timers/core branch of tip:
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 0c52310f260014d95c1310364379772cb74cf82d Gitweb: https://git.kernel.org/tip/0c52310f260014d95c1310364379772cb74cf82d Author: Davidlohr Bueso <[email protected]> AuthorDate: Mon, 23 Jan 2023 09:32:06 -08:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 31 Jan 2023 11:23:07 +01:00
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.
--- kernel/time/hrtimer.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
kernel/time/hrtimer.c +11 -3
@@ -2272,7 +2272,7 @@ void __init hrtimers_init(void)/** * schedule_hrtimeout_range_clock - sleep until timeout * @expires: timeout value (ktime_t) -* @delta: slack in expires timeout (ktime_t) +* @delta: slack in expires timeout (ktime_t) for SCHED_OTHER tasks * @mode: timer mode * @clock_id: timer clock to be used */
@@ -2299,6 +2299,13 @@ schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta,return -EINTR ; } +/* +* Override any slack passed by the user if under +* rt contraints. +*/ +if (rt_task (current)) + delta =0 ; +hrtimer_init_sleeper_on_stack (&t, clock_id, mode);hrtimer_set_expires_range_ns (&t.timer, *expires, delta);hrtimer_sleeper_start_expires (&t, mode);
@@ -2318,7 +2325,7 @@ EXPORT_SYMBOL_GPL(schedule_hrtimeout_range_clock);/** * schedule_hrtimeout_range - sleep until timeout * @expires: timeout value (ktime_t) -* @delta: slack in expires timeout (ktime_t) +* @delta: slack in expires timeout (ktime_t) for SCHED_OTHER tasks * @mode: timer mode * * Make the current task sleep until the given expiry time has
@@ -2326,7 +2333,8 @@ EXPORT_SYMBOL_GPL(schedule_hrtimeout_range_clock);* the current task state has been set (see set_current_state()). * * The @delta argument gives the kernel the freedom to schedule the -* actual wakeup to a time that is both power and performance friendly. +* actual wakeup to a time that is both power and performance friendly +* for regular (non RT/DL) tasks. * The kernel give the normal best effort behavior for "@expires+@delta", * but may decide to fire the timer earlier, but no earlier than @expires. *