]> www.infradead.org Git - linux.git/commitdiff
posix-cpu-timers: Handle interval timers correctly in timer_get()
authorThomas Gleixner <tglx@linutronix.de>
Mon, 10 Jun 2024 16:42:16 +0000 (18:42 +0200)
committerFrederic Weisbecker <frederic@kernel.org>
Mon, 29 Jul 2024 19:57:34 +0000 (21:57 +0200)
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 <tglx@linutronix.de>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
kernel/time/posix-cpu-timers.c

index 5aac0886bbc763da82156c398b8bcfbe85449313..92222ca89f499eeed2642cbda5bff7f0e6b4178f 100644 (file)
@@ -787,8 +787,24 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
 
 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 {