Re: [RFC PATCH] x86, kvm: use kvmclock to compute TSC deadline value

From: Andy Lutomirski
Date: Wed Jul 06 2016 - 09:02:05 EST


On Jul 5, 2016 1:36 PM, "Paolo Bonzini" <pbonzini@xxxxxxxxxx> wrote:
>
> Bad things happen if a guest using the TSC deadline timer is migrated.
> The guest doesn't re-calibrate the TSC after migration, and the
> TSC frequency can and will change unless your processor supports TSC
> scaling (on Intel this is only Skylake) or your data center is perfectly
> homogeneous.
>
> The solution in this patch is to skip tsc_khz, and instead derive the
> frequency from kvmclock's (mult, shift) pair. Because kvmclock
> parameters convert from tsc to nanoseconds, this needs a division
> but that's the least of our problems when the TSC_DEADLINE_MSR write
> costs 2000 clock cycles. Luckily tsc_khz is really used by very little
> outside the tsc clocksource (which kvmclock replaces) and the TSC
> deadline timer.

I'm wondering if it would be more straightforward to blacklist the
APIC timer entirely (on KVM guests that have the TSC deadline
capability) and to instead offer a paravirt clockevent that still uses
the deadline timer under the hood. After all, these systems should be
mostly quirk-free, so I imagine that the whole implementation would
only be a few lines of code.