Re: [PATCH v3] ipc: Update semtimedop() to use hrtimer

From: Davidlohr Bueso
Date: Fri Apr 29 2022 - 14:04:37 EST


On Fri, 29 Apr 2022, Thomas Gleixner wrote:

No. What I meant is a function which handles this internally, not an inline
function which has to be invoked on various call sites.

Originally I was also thinking about it on a per-user basis, but
after more thought I agree it's better if it is done by the hrtimer.

Something like so?

Thanks,
Davidlohr

---------------8<-----------------------------------------------------
[PATCH] hrtimer: Ignore slack time for RT tasks

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.

Signed-off-by: Davidlohr Bueso <dave@xxxxxxxxxxxx>
---
kernel/time/hrtimer.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 0ea8702eb516..5ef0f1651040 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -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);
@@ -2326,6 +2333,7 @@ schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta,
* actual wakeup to a time that is both power and performance friendly.
* The kernel give the normal best effort behavior for "@expires+@delta",
* but may decide to fire the timer earlier, but no earlier than @expires.
+ * For scenarios under realtime constraints, @delta is always zero.
*
* You can set the task state as follows -
*
--
2.36.0