From: Thomas Gleixner <tglx@linutronix.de>
To: Peter Zijlstra <peterz@infradead.org>
Cc: arnd@arndb.de, anna-maria@linutronix.de, frederic@kernel.org,
peterz@infradead.org, luto@kernel.org, mingo@redhat.com,
juri.lelli@redhat.com, vincent.guittot@linaro.org,
dietmar.eggemann@arm.com, rostedt@goodmis.org,
bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
linux-kernel@vger.kernel.org, oliver.sang@intel.com
Subject: Re: [PATCH v2 5/6] entry,hrtimer: Push reprogramming timers into the interrupt return path
Date: Mon, 02 Feb 2026 15:37:13 +0100 [thread overview]
Message-ID: <878qdbfbza.ffs@tglx> (raw)
In-Reply-To: <20260121162508.011240183@infradead.org>
On Wed, Jan 21 2026 at 17:20, Peter Zijlstra wrote:
> while (ti_work & EXIT_TO_USER_MODE_WORK_LOOP) {
>
> + /*
> + * If hrtimer need re-arming, do so before enabling IRQs,
> + * except when a reschedule is needed, in that case schedule()
> + * will do this.
> + */
> + if ((ti_work & (_TIF_NEED_RESCHED |
> + _TIF_NEED_RESCHED_LAZY |
> + _TIF_HRTIMER_REARM)) == _TIF_HRTIMER_REARM)
> + hrtimer_rearm();
Two things I'm not convinced that they are handled correctly:
1) Interrupts
After reenabling interrupts and before reaching schedule() an
interrupt comes in and runs soft interrupt processing for a while
on the way back, which delays the update until that processing
completes.
2) Time slice extension
When the time slice is granted this will not rearm the clockevent
device unless the slice hrtimer becomes the first expiring timer
on that CPU, but even then that misses the full reevaluation of
the next timer event.
> -static void __hrtimer_rearm(struct hrtimer_cpu_base *cpu_base, ktime_t now)
> +static void __hrtimer_rearm(struct hrtimer_cpu_base *cpu_base,
> + ktime_t now, ktime_t expires_next)
> {
> - ktime_t expires_next = hrtimer_update_next_event(cpu_base);
> -
> cpu_base->expires_next = expires_next;
> cpu_base->in_hrtirq = 0;
>
> @@ -1970,9 +1969,30 @@ void hrtimer_interrupt(struct clock_even
> cpu_base->hang_detected = 1;
> }
>
> - __hrtimer_rearm(cpu_base, now);
> +#ifdef TIF_HRTIMER_REARM
> + set_thread_flag(TIF_HRTIMER_REARM);
> +#else
> + __hrtimer_rearm(cpu_base, now, expires_next);
> +#endif
in hrtimer.h where you already have the #ifdef TIF_HRTIMER_REARM
section:
static inline bool hrtimer_set_rearm_delayed()
{
set_thread_flag(TIF_HRTIMER_REARM);
return true;
}
and a empty stub returning false for the other case then this becomes:
if (!hrtimer_set_rearm_delayed())
hrtimer_rearm(...);
and the ugly ifdef in the code goes away.
> raw_spin_unlock_irqrestore(&cpu_base->lock, flags);
> }
> +
> +#ifdef TIF_HRTIMER_REARM
> +void _hrtimer_rearm(void)
Grr. I had to read this five times to figure out that we now have
hrtimer_rearm()
_hrtimer_rearm()
__hrtimer_rearm()
You clearly ran out of characters to make that obvious:
hrtimer_rearm_delayed()
hrtimer_rearm()
hrtimer_do_rearm()
or something like that.
Thanks,
tglx
next prev parent reply other threads:[~2026-02-02 14:37 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-21 16:20 [PATCH v2 0/6] hrtimer/sched: Improve hrtick Peter Zijlstra
2026-01-21 16:20 ` [PATCH v2 1/6] sched/eevdf: Fix HRTICK duration Peter Zijlstra
2026-01-22 10:53 ` Juri Lelli
2026-02-05 8:38 ` Peter Zijlstra
2026-01-21 16:20 ` [PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns() Peter Zijlstra
2026-01-22 11:00 ` Juri Lelli
2026-02-02 12:28 ` Thomas Gleixner
2026-01-21 16:20 ` [PATCH v2 3/6] hrtimer,sched: Add fuzzy hrtimer mode for HRTICK Peter Zijlstra
2026-01-22 13:12 ` Juri Lelli
2026-01-23 20:04 ` Steven Rostedt
2026-02-02 14:02 ` Thomas Gleixner
2026-01-21 16:20 ` [PATCH v2 4/6] hrtimer: Re-arrange hrtimer_interrupt() Peter Zijlstra
2026-02-02 14:05 ` Thomas Gleixner
2026-01-21 16:20 ` [PATCH v2 5/6] entry,hrtimer: Push reprogramming timers into the interrupt return path Peter Zijlstra
2026-01-23 20:08 ` Steven Rostedt
2026-01-23 21:04 ` Peter Zijlstra
2026-02-02 14:37 ` Thomas Gleixner [this message]
2026-02-02 16:33 ` Peter Zijlstra
2026-02-02 23:28 ` Thomas Gleixner
2026-02-03 8:14 ` Thomas Gleixner
2026-02-04 13:58 ` Peter Zijlstra
2026-01-21 16:20 ` [PATCH v2 6/6] sched: Default enable HRTICK Peter Zijlstra
2026-01-21 22:24 ` Phil Auld
2026-01-22 11:40 ` Peter Zijlstra
2026-01-22 12:31 ` Phil Auld
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878qdbfbza.ffs@tglx \
--to=tglx@linutronix.de \
--cc=anna-maria@linutronix.de \
--cc=arnd@arndb.de \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=frederic@kernel.org \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=oliver.sang@intel.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox