RE: [patch 19/48] clockevents: Provide support for clocksource coupled comparators
From: mhklkml
Date: Mon Mar 23 2026 - 20:29:33 EST
From: Thomas Gleixner <tglx@xxxxxxxxxx> Sent: Monday, March 23, 2026 2:37 PM
>
> On Mon, Mar 23 2026 at 04:24, Michael Kelley wrote:
> >> > +static inline bool clockevent_set_next_coupled(struct clock_event_device
*dev, ktime_t expires)
> >> > +{
> >> > + u64 cycles;
> >> > +
> >> > + if (unlikely(!(dev->features & CLOCK_EVT_FEAT_CLOCKSOURCE_COUPLED)))
> >> > + return false;
> >> > +
> >> > + if (unlikely(!ktime_expiry_to_cycles(dev->cs_id, expires, &cycles)))
> >> > + return false;
> >> > +
> >> > + if (IS_ENABLED(CONFIG_GENERIC_CLOCKEVENTS_COUPLED_INLINE))
> >>
> >> Since COUPLED_INLINE is always selected for x64, there's no way to add the
Hyper-V
> >> clockevent that is coupled but not inline. Adding the machinery to allow a
second
> >> inline clockevent type may not be worth it, but adding a second coupled but not
> >> inline clockevent type on x64 should be supported. Thoughts?
> >>
> >> After fixing the u64 typo, and temporarily not always selecting COUPLED_INLINE
in
> >> arch/x86/Kconfig, the coupled Hyper-V TSC page clocksource and timer seem to
work
> >> correctly, though I'm still doing some testing. I'm also working on counting the
number
> >> of time reads to confirm the expected benefit.
> >
> > Gentle ping. Any thoughts on this? (And on Peter Zijlstra's "deliciously
insane"
> > follow-up?)
>
> Sure, we should be able to support that and I think Peter's suggestion
> is pretty clever. Did you get it working?
>
I got the coupling working with the Hyper-V clocksource and timer in
non-inlined form, and observed the expected reduction in time reads.
That was straightforward.
But I did not try Peter's suggestion, just to keep things simple. The
Hyper-V timer can be loaded with a single wrmsrq just like the TSC
deadline timer, but it's a different MSR that's synthetic and always
traps to the hypervisor. Given the unavoidable overhead of trapping
to the hypervisor, the relative gain of inlining would be small.
Michael