RE: [patch 19/48] clockevents: Provide support for clocksource coupled comparators

From: Michael Kelley

Date: Mon Mar 23 2026 - 00:24:42 EST


From: Michael Kelley Sent: Tuesday, March 3, 2026 10:45 AM
>
> From: Thomas Gleixner <tglx@xxxxxxxxxx> Sent: Tuesday, February 24, 2026 8:37 AM
> >
> > Some clockevent devices are coupled to the system clocksource by
> > implementing a less than or equal comparator which compares the programmed
> > absolute expiry time against the underlying time counter.
>
> I've been playing with this in linux-next, and particularly to set up the Hyper-V
> TSC page clocksource and Hyper-V timer as coupled. Most Hyper-V guests these days
> are running on hardware that allows using the TSC directly as the clocksource. But
> even if the Hyper-V TSC page clocksource isn't used, the timer is still the Hyper-V
> timer, so the coupling isn't active. However, SEV-SNP and TDX CoCo VMs on Hyper-V
> must use both the Hyper-V TSC page clocksource and the Hyper-V timer, so they
> would benefit from coupling. It's a nice idea!
>

[snip]

> > +
> > +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.
>

Thomas --

Gentle ping. Any thoughts on this? (And on Peter Zijlstra's "deliciously insane"
follow-up?)

Michael