From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Oleksii Kurochko <oleksii.kurochko@gmail.com>
Subject: Re: [PATCH for-4.21 02/10] x86/HPET: disable unused channels
Date: Thu, 16 Oct 2025 18:28:19 +0200 [thread overview]
Message-ID: <aPEdI78ySE2eFPnA@Mac.lan> (raw)
In-Reply-To: <39b3cdbe-636c-4b9d-9134-d42f8a369c4a@suse.com>
On Thu, Oct 16, 2025 at 05:55:30PM +0200, Jan Beulich wrote:
> On 16.10.2025 17:34, Roger Pau Monné wrote:
> > On Thu, Oct 16, 2025 at 01:57:41PM +0200, Jan Beulich wrote:
> >> On 16.10.2025 13:42, Roger Pau Monné wrote:
> >>> On Thu, Oct 16, 2025 at 09:31:42AM +0200, Jan Beulich wrote:
> >>>> Keeping channels enabled when they're unused is only causing problems:
> >>>> Extra interrupts harm performance, and extra nested interrupts could even
> >>>> have caused worse problems.
> >>>>
> >>>> Note that no explicit "enable" is necessary - that's implicitly done by
> >>>> set_channel_irq_affinity() once the channel goes into use again.
> >>>>
> >>>> Along with disabling the counter, also "clear" the channel's "next event",
> >>>> for it to be properly written by whatever the next user is going to want
> >>>> (possibly avoiding too early an IRQ).
> >>>>
> >>>> Further, along the same lines, don't enable channels early when starting
> >>>> up an IRQ. This similarly should happen no earlier than from
> >>>> set_channel_irq_affinity() (here: once a channel goes into use the very
> >>>> first time). This eliminates a single instance of
> >>>>
> >>>> (XEN) [VT-D]INTR-REMAP: Request device [0000:00:1f.0] fault index 0
> >>>> (XEN) [VT-D]INTR-REMAP: reason 25 - Blocked a compatibility format interrupt request
> >>>>
> >>>> during boot. (Why exactly there's only one instance, when we use multiple
> >>>> counters and hence multiple IRQs, I can't tell. My understanding would be
> >>>> that this was due to __hpet_setup_msi_irq() being called only after
> >>>> request_irq() [and hence the .startup handler], yet that should have
> >>>> affected all channels.)
> >>>>
> >>>> Fixes: 3ba523ff957c ("CPUIDLE: enable MSI capable HPET for timer broadcast")
> >>>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> >>>> ---
> >>>> A window still remains for IRQs to be caused by stale comparator values:
> >>>> hpet_attach_channel() is called ahead of reprogram_hpet_evt_channel().
> >>>> Should we also write the comparator to "far into the future"?
> >>>
> >>> It might be helpful to reprogram the comparator as far ahead as
> >>> possible in hpet_attach_channel() ahead of enabling it, or
> >>> alternatively in hpet_detach_channel().
> >>
> >> The downside is yet another (slow) MMIO access. Hence why I didn't make
> >> such a change right away. Plus I wasn't quite sure about the locking there:
> >> Imo if we did so, it would be better if the lock wasn't dropped
> >> intermediately.
> >>
> >>>> @@ -542,6 +540,8 @@ static void hpet_detach_channel(unsigned
> >>>> spin_unlock_irq(&ch->lock);
> >>>> else if ( (next = cpumask_first(ch->cpumask)) >= nr_cpu_ids )
> >>>> {
> >>>> + hpet_disable_channel(ch);
> >>>> + ch->next_event = STIME_MAX;
> >>>> ch->cpu = -1;
> >>>> clear_bit(HPET_EVT_USED_BIT, &ch->flags);
> >>>> spin_unlock_irq(&ch->lock);
> >>>
> >>> I'm a bit confused with what the HPET code does here (don't know
> >>> enough about it, and there are no comments). Why is the timer rotated
> >>> to a CPU in ch->cpumask once disabled, instead of just being plain
> >>> disabled?
> >>
> >> Because it will still be needed by the other CPUs that the channel is
> >> shared with.
> >
> > Yeah, missed that part, the channel is migrated to a different CPU. I
> > wonder however: since an active channel can be migrated around between
> > CPUs, isn't there a risk of the timer firing just in the middle of
> > migration (when interrupt generation is disabled), and hence Xen
> > possibly missing a deadline?
> >
> > In hpet_broadcast_exit() we need to check whether the timer has
> > expired after the migration, and manually trigger a broadcast if
> > needed. This also risks doing to broadcasts also back-to-back, but
> > it's the only option I see to avoid missing a deadline.
> >
> > Maybe there's something I'm missing, this is all fairly complex.
>
> set_channel_irq_affinity() invokes handle_hpet_broadcast() to cover that
> case.
Oh, indeed, sorry for the fuzz then.
Thanks, Roger.
next prev parent reply other threads:[~2025-10-16 16:28 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-16 7:30 [PATCH for-4.21 00/10] x86/HPET: broadcast IRQ and other improvements Jan Beulich
2025-10-16 7:31 ` [PATCH for-4.21 01/10] x86/HPET: limit channel changes Jan Beulich
2025-10-16 10:24 ` Roger Pau Monné
2025-10-16 11:47 ` Jan Beulich
2025-10-16 15:07 ` Roger Pau Monné
2025-10-16 15:16 ` Jan Beulich
2025-10-16 15:25 ` Roger Pau Monné
2025-10-17 9:23 ` Roger Pau Monné
2025-10-17 9:55 ` Jan Beulich
2025-10-16 7:31 ` [PATCH for-4.21 02/10] x86/HPET: disable unused channels Jan Beulich
2025-10-16 11:42 ` Roger Pau Monné
2025-10-16 11:57 ` Jan Beulich
2025-10-16 15:34 ` Roger Pau Monné
2025-10-16 15:55 ` Jan Beulich
2025-10-16 16:28 ` Roger Pau Monné [this message]
2025-10-16 16:31 ` Roger Pau Monné
2025-10-17 6:08 ` Jan Beulich
2025-10-17 6:10 ` Jan Beulich
2025-10-16 7:32 ` [PATCH for-4.21 03/10] x86/HPET: use single, global, low-priority vector for broadcast IRQ Jan Beulich
2025-10-16 16:27 ` Roger Pau Monné
2025-10-17 7:15 ` Jan Beulich
2025-10-17 8:20 ` Roger Pau Monné
2025-10-20 5:53 ` Jan Beulich
2025-10-20 15:49 ` Roger Pau Monné
2025-10-20 16:05 ` Jan Beulich
2025-10-21 8:37 ` Roger Pau Monné
2025-10-16 17:01 ` Andrew Cooper
2025-10-17 6:23 ` Jan Beulich
2025-10-16 7:32 ` [PATCH for-4.21 04/10] x86/HPET: ignore "stale" IRQs Jan Beulich
2025-10-17 9:19 ` Roger Pau Monné
2025-10-17 9:57 ` Jan Beulich
2025-10-17 12:13 ` Roger Pau Monné
2025-10-16 7:32 ` [PATCH 05/10] x86/HPET: avoid indirect call to event handler Jan Beulich
2025-10-16 7:33 ` [PATCH 06/10] x86/HPET: make another channel flags update atomic Jan Beulich
2025-10-16 7:33 ` [PATCH 07/10] x86/HPET: move legacy tick IRQ count adjustment Jan Beulich
2025-10-16 7:34 ` [PATCH 08/10] x86/HPET: shrink IRQ-descriptor locked region in set_channel_irq_affinity() Jan Beulich
2025-10-16 7:34 ` [PATCH 09/10] x86/HPET: reduce hpet_next_event() call sites Jan Beulich
2025-10-16 7:35 ` [PATCH 10/10] x86/HPET: don't use hardcoded 0 for "long timeout" Jan Beulich
2025-10-16 10:05 ` [PATCH for-4.21 00/10] x86/HPET: broadcast IRQ and other improvements Roger Pau Monné
2025-10-16 10:41 ` Jan Beulich
2025-10-17 16:03 ` Oleksii Kurochko
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=aPEdI78ySE2eFPnA@Mac.lan \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=oleksii.kurochko@gmail.com \
--cc=xen-devel@lists.xenproject.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.