2024-04-10 22:48:21

by Thomas Gleixner

[permalink] [raw]
Subject: [patch V2 09/50] posix-cpu-timers: Handle interval timers correctly in timer_get()

timer_gettime() must return the remaining time to the next expiry of a
timer or 0 if the timer is not armed and no signal pending, but posix CPU
timers fail to forward a timer which is already expired.

Add the required logic to address that.

Signed-off-by: Thomas Gleixner <[email protected]>
---
V2: Split out into new patch to make review simpler - Frederic
---
kernel/time/posix-cpu-timers.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -787,8 +787,24 @@ static int posix_cpu_timer_set(struct k_

static void __posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp, u64 now)
{
- u64 expires = cpu_timer_getexpires(&timer->it.cpu);
+ u64 expires, iv = timer->it_interval;

+ /*
+ * Make sure that interval timers are moved forward for the
+ * following cases:
+ * - Timers which expired, but the signal has not yet been
+ * delivered
+ */
+ if (iv && (timer->it_requeue_pending & REQUEUE_PENDING))
+ expires = bump_cpu_timer(timer, now);
+ else
+ expires = cpu_timer_getexpires(&timer->it.cpu);
+
+ /*
+ * Expired interval timers cannot have a remaining time <= 0.
+ * The kernel has to move them forward so that the next
+ * timer expiry is > @now.
+ */
if (now < expires) {
itp->it_value = ns_to_timespec64(expires - now);
} else {



2024-04-17 22:50:44

by Frederic Weisbecker

[permalink] [raw]
Subject: Re: [patch V2 09/50] posix-cpu-timers: Handle interval timers correctly in timer_get()

Le Thu, Apr 11, 2024 at 12:46:27AM +0200, Thomas Gleixner a ?crit :
> timer_gettime() must return the remaining time to the next expiry of a
> timer or 0 if the timer is not armed and no signal pending, but posix CPU
> timers fail to forward a timer which is already expired.
>
> Add the required logic to address that.
>
> Signed-off-by: Thomas Gleixner <[email protected]>

Reviewed-by: Frederic Weisbecker <[email protected]>