x86: tsc: fix L2 guest always in tsc_early clocksource
Subsystems (2)
Quoted 9 lines · On Tue, Apr 24, 2018 at 09:56:52AM +0800, [email protected] wrote:
Quoted 7 lines · Peng Hao
Quoted 4 lines
In L2 guest
tsc_read_refsalways returnULLONG_MAX, and that will calltsc_refine_calibration_workperiodly. So L2 guest will read acpi timer port0x608periodly.
The patch will let it out of "if(tsc_start == -1){}" infinite loop.Help me out a little. What's an L2 guest?
kvm nested virtual machine.
So why not say nested guest? I though someone did a new hypervisor based on L4 or so and called it L2 for funnies.
Quoted 8 lines
Quoted 2 lines
So if the whole TSC sync has no way of ever working; what is your patch doing? How is the actual TSC calibrated?
It exists a period loop in
tsc_refine_calibration_work:tsc_start=tsc_read_refs()= -1,so it callschedule_delayed_work(&tsc_irqwork,HZ), thentsc_start=tsc_read_refs()= -1 ....
during the process it accesses0x608periodly and it is unnecessary and just influencees performance for L2 guest. The patch let it out of the period loop and changes from early-tsc to tsc clocksource.So it will not access ioport0x608periodly.
Can you please teach your mailer to wrap at 78 chars?
Quoted 1 line
The kvmclock give a interface
kvm_get_tsc_khzto get thetsc_khz.
But why are you getting to tsc_refine_calibration_work() in the first place? If kvm_get_tsc_khz() returns a known good value, it should set X86_FEATURE_TSC_KNOWN_FREQ such that we don't attempt to 'refine' things.
Something like the below perhaps?
--- arch/x86/kernel/kvmclock.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/x86/kernel/kvmclock.c +7 -0
@@ -138,6 +138,13 @@ static unsigned long kvm_get_tsc_khz(void) src = &hv_clock[cpu].pvti; tsc_khz =pvclock_tsc_khz (src);put_cpu (); + +/* +* TSC frequency is reported by the host; calibration against (virtual) +* HPET/PM-timer in a guest is dodgy and will not be accurate. +*/ +setup_force_cpu_cap (X86_FEATURE_TSC_KNOWN_FREQ ); +return tsc_khz; }