The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] hrtimer: Refresh softirq deadline after clock changes in low-res mode
@ 2026-11-01 17:23 Avi Weiss
  2026-11-04 16:51 ` Frederic Weisbecker
  2026-11-09 19:53 ` [tip: timers/core] " tip-bot2 for Avi Weiss
  0 siblings, 2 replies; 3+ messages in thread
From: Avi Weiss @ 2026-11-01 17:23 UTC (permalink / raw)
  To: anna-maria; +Cc: frederic, tglx, mingo, linux-kernel, Avi Weiss

In periodic low-resolution mode, hrtimer_run_queues() updates the clock
base offsets at each tick but does not refresh softirq_expires_next.
When CLOCK_REALTIME is moved forward, an expired soft hrtimer can
therefore remain pending until the old monotonic deadline is reached.

Reevaluate the next expiry when hrtimer_update_base() observes a new
clock-was-set sequence, before checking whether to raise HRTIMER_SOFTIRQ.

Fixes: 5da70160462e ("hrtimer: Implement support for softirq based hrtimers")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
 kernel/time/hrtimer.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 17dd38a6cee7..5d1df371e931 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -2289,6 +2289,7 @@ void hrtimer_run_queues(void)
 	struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
 	unsigned long flags;
 	ktime_t now;
+	unsigned int seq;
 
 	if (hrtimer_hres_active(cpu_base))
 		return;
@@ -2306,7 +2307,10 @@ void hrtimer_run_queues(void)
 	}
 
 	raw_spin_lock_irqsave(&cpu_base->lock, flags);
+	seq = cpu_base->clock_was_set_seq;
 	now = hrtimer_update_base(cpu_base);
+	if (seq != cpu_base->clock_was_set_seq)
+		hrtimer_update_next_event(cpu_base);
 
 	if (!ktime_before(now, cpu_base->softirq_expires_next)) {
 		cpu_base->softirq_expires_next = KTIME_MAX;

base-commit: cbbddb6b08cc9900a87cccaa9b22bbe06aa4f50a
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] hrtimer: Refresh softirq deadline after clock changes in low-res mode
  2026-11-01 17:23 [PATCH] hrtimer: Refresh softirq deadline after clock changes in low-res mode Avi Weiss
@ 2026-11-04 16:51 ` Frederic Weisbecker
  2026-11-09 19:53 ` [tip: timers/core] " tip-bot2 for Avi Weiss
  1 sibling, 0 replies; 3+ messages in thread
From: Frederic Weisbecker @ 2026-11-04 16:51 UTC (permalink / raw)
  To: Avi Weiss; +Cc: anna-maria, tglx, mingo, linux-kernel

Le Sun, Nov 01, 2026 at 07:23:44PM +0200, Avi Weiss a écrit :
> In periodic low-resolution mode, hrtimer_run_queues() updates the clock
> base offsets at each tick but does not refresh softirq_expires_next.
> When CLOCK_REALTIME is moved forward, an expired soft hrtimer can
> therefore remain pending until the old monotonic deadline is reached.
> 
> Reevaluate the next expiry when hrtimer_update_base() observes a new
> clock-was-set sequence, before checking whether to raise HRTIMER_SOFTIRQ.
> 
> Fixes: 5da70160462e ("hrtimer: Implement support for softirq based hrtimers")
> Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
> ---
>  kernel/time/hrtimer.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
> index 17dd38a6cee7..5d1df371e931 100644
> --- a/kernel/time/hrtimer.c
> +++ b/kernel/time/hrtimer.c
> @@ -2289,6 +2289,7 @@ void hrtimer_run_queues(void)
>  	struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
>  	unsigned long flags;
>  	ktime_t now;
> +	unsigned int seq;
>  
>  	if (hrtimer_hres_active(cpu_base))
>  		return;
> @@ -2306,7 +2307,10 @@ void hrtimer_run_queues(void)
>  	}
>  
>  	raw_spin_lock_irqsave(&cpu_base->lock, flags);
> +	seq = cpu_base->clock_was_set_seq;
>  	now = hrtimer_update_base(cpu_base);
> +	if (seq != cpu_base->clock_was_set_seq)
> +		hrtimer_update_next_event(cpu_base);

It took some time for me to understand the issue because retrigger_next_event()
takes care of that already.

But if the clock is set and hrtimer_run_queues() happens to run before the base
is locked and update_needs_ipi() is called, the IPI won't happen.

It could be worth adding that to the changelog.

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>

-- 
Frederic Weisbecker
SUSE Labs

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: timers/core] hrtimer: Refresh softirq deadline after clock changes in low-res mode
  2026-11-01 17:23 [PATCH] hrtimer: Refresh softirq deadline after clock changes in low-res mode Avi Weiss
  2026-11-04 16:51 ` Frederic Weisbecker
@ 2026-11-09 19:53 ` tip-bot2 for Avi Weiss
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Avi Weiss @ 2026-11-09 19:53 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Avi Weiss, Thomas Gleixner, Frederic Weisbecker, x86,
	linux-kernel

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     84a9b8de48d91d2624474360911f6bf71bf7d77e
Gitweb:        https://git.kernel.org/tip/84a9b8de48d91d2624474360911f6bf71bf7d77e
Author:        Avi Weiss <thnkslprpt@gmail.com>
AuthorDate:    Sun, 01 Nov 2026 19:23:44 +02:00
Committer:     Thomas Gleixner <tglx@kernel.org>
CommitterDate: Mon, 09 Nov 2026 20:50:03 +01:00

hrtimer: Refresh softirq deadline after clock changes in low-res mode

In periodic low-resolution mode, hrtimer_run_queues() updates the clock
base offsets at each tick but does not refresh softirq_expires_next.
When CLOCK_REALTIME is moved forward, an expired soft hrtimer can
therefore remain pending until the old monotonic deadline is reached.

Reevaluate the next expiry when hrtimer_update_base() observes a new
clock-was-set sequence, before checking whether to raise HRTIMER_SOFTIRQ.

Fixes: 5da70160462e ("hrtimer: Implement support for softirq based hrtimers")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Link: https://patch.msgid.link/20261101172344.426489-1-thnkslprpt@gmail.com
---
 kernel/time/hrtimer.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 6d7a0d8..d48ffa4 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -2293,6 +2293,7 @@ void hrtimer_run_queues(void)
 	struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
 	unsigned long flags;
 	ktime_t now;
+	unsigned int seq;
 
 	if (hrtimer_hres_active(cpu_base))
 		return;
@@ -2310,7 +2311,10 @@ void hrtimer_run_queues(void)
 	}
 
 	raw_spin_lock_irqsave(&cpu_base->lock, flags);
+	seq = cpu_base->clock_was_set_seq;
 	now = hrtimer_update_base(cpu_base);
+	if (seq != cpu_base->clock_was_set_seq)
+		hrtimer_update_next_event(cpu_base);
 
 	if (!ktime_before(now, cpu_base->softirq_expires_next)) {
 		cpu_base->softirq_expires_next = KTIME_MAX;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-09 19:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-01 17:23 [PATCH] hrtimer: Refresh softirq deadline after clock changes in low-res mode Avi Weiss
2026-11-04 16:51 ` Frederic Weisbecker
2026-11-09 19:53 ` [tip: timers/core] " tip-bot2 for Avi Weiss

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox