Re: [RFC PATCH v2 0/8] timekeeping: Fix draft tracking precision and add feed-forward discipline via vmclock

From: Miroslav Lichvar

Date: Mon May 25 2026 - 04:10:43 EST


On Thu, May 21, 2026 at 10:54:41AM +0100, David Woodhouse wrote:
> On Thu, 2026-05-21 at 08:35 +0200, Miroslav Lichvar wrote:
> > Ok, but I don't see why the phase corrections of the guest need to be
> > in the kernel.
>
> I'm not sure I understand. 
>
> There are no 'phase corrections' as such, except of course that the
> phase of the guest kernel's clock does get corrected, and naturally
> that does have to take effect inside the guest kernel.

I'm referring to these parts of the patches:

delta_ns = timespec64_to_ns(&vmtime) - timespec64_to_ns(&now);
if (delta_ns > 100000000 || delta_ns < -100000000)
do_settimeofday64(&vmtime);

...

/* Compute phase offset at cycle_last and set time_offset to slew */
delta = tk->tkr_mono.cycle_last - ref->counter_value;
ref_frac = mul_u64_u64_shr(delta, ref->period_frac_sec,
ref->period_shift) + ref->time_frac_sec;
ref_err = (s64)mul_u64_u64_shr(ref_frac,
(u64)NSEC_PER_SEC << tk->tkr_mono.shift, 64) -
(s64)tk->tkr_mono.xtime_nsec;
ntp_set_time_offset(tk->id, ref_err >> tk->tkr_mono.shift);

> I think the key here is that this is not a feedback loop based on
> corrections to the existing clock output; this is a feedforward design
> as described in https://dl.acm.org/doi/pdf/10.1109/TNET.2011.2158443

There might be a disagreement on terminology. As the guest clock
cannot be updated synchronously with the host, the tracking cannot be
perfect and there has to be some way to correct for the errors due to
the delay. That's what the code shown above seems to be doing. It's a
feedback loop. It doesn't matter if the offset is calculated directly
or measured.

> It seems that when Julien et al lamented that, "Until now, however,
> there has been a serious practical issue inhibiting feed-forward
> approaches: a lack of kernel support", the basics were actually there
> in the kernel's core timekeeping all along.

>From my point of view, the only missing piece is software timestamping
of packets using other clocks than CLOCK_REALTIME.

> > > And TSC scaling is pretty much x86-specific; other architectures have a
> > > *defined* counter frequency and don't need to support scaling.
> >
> > There can be a software fallback if hardware scaling and/or offset is
> > not supported.
>
> Right. This *is* the software fallback, because the hardware scaling
> and offset aren't sufficient even if we only care about x86 where the
> former is supported.

IMHO it's a solution done at a wrong layer.

--
Miroslav Lichvar