Skip to content

KVM: Remaining body of TSC emulation work (Zachary Amsden)

Marcelo Tosatti kvm 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest8 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8Infrastructure for software and hardware based TSC rate scalingarch/x86/include/asm/kvm_host.h arch/x86/kvm/lapic.c arch/x86/kvm/svm.c +2 more+67 -611 reply
2/8Improve TSC offset matchingarch/x86/include/asm/kvm_host.h arch/x86/kvm/x86.c+23 -150 replies
3/8Leave TSC synchronization window open with each new syncarch/x86/kvm/x86.c+0 -10 replies
4/8Fix last_guest_tsc / tsc_offset semanticsarch/x86/kvm/x86.c+6 -40 replies
5/8Add last_host_tsc tracking back to KVMarch/x86/include/asm/kvm_host.h arch/x86/kvm/x86.c+4 -80 replies
6/8Allow adjust_tsc_offset to be in host or guest cyclesarch/x86/include/asm/kvm_host.h arch/x86/kvm/svm.c arch/x86/kvm/vmx.c +1 more+19 -40 replies
7/8Dont mark TSC unstable due to S4 suspendarch/x86/include/asm/kvm_host.h arch/x86/kvm/x86.c+89 -53 replies
8/8Track TSC synchronization in generationsarch/x86/include/asm/kvm_host.h arch/x86/kvm/x86.c+40 -110 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [patch 0/8] KVM: Remaining body of TSC emulation work (Zachary Amsden)

Rebase Zachary's last TSC series. From his original email:

"This is the remaining bulk of work I have related to TSC emulation. In summary, I believe this fixes all known issues with TSC. A few rather subtle issues are cleaned up, S4 suspend is fixed, and the API for adjust_tsc_offset is expanded to take arguments in either guest cycles or optionally host cycles. The final patch adds software TSC emulation, with a configurable default setting.

Note that TSC trapping will only be used when other methods fail due to unstable TSC or lack of scaling hardware. With the improved offset matching, I was even able to get SMP guests to boot with a TSC clock; cycle testing showed a maximum backwards leap of around 0.25 ms, which is actually fairly good. With the last patch applied, software TSC emulation kicks in and the backwards TSC count even on my broken hardware dropped to zero.

Some of this code (the S4 suspend compensation) has already been ported into RHEL to fix various bugs - however upstream had diverged a bit from the original course I planned; I had to add a few things that had been optimized out of upstream back in (last_host_tsc).

In the course of doing this, I think the new code looks much cleaner, with well documented and easy to understand variables. Yes, there are a lot of tracking variables to maintain this whole infrastructure - and yes, some of them appear to be redundant of easily computable from others - but in actuality, the information they provide is easy to understand, and the resulting code is much easier to verify than a complex system where some quantities may be undefined or computed on the fly and thus causing subtle races. "

The last patch which introduces TSC trapping has not been included:
it unconditionally enables TSC trapping if the guest frequency differs from the host or the host TSC is unstable. It should instead use tsc catchup if the guest frequency is higher than the host. Also, there is no need for trapping if the guest is using kvmclock.