On 12/06/2013 11:22 PM, Marcelo Tosatti wrote:
On Fri, Dec 06, 2013 at 05:24:18PM +0900, Fernando Luis Vázquez Cao wrote:
I also wanted to make sure that the initialization that we do
in kvm_arch_vcpu_postcreate on power up and the subsequent
TSC writeback work well together, but I didn't have time to
test it (reading the code, I would say that the TSC generation
counter may end up being increased a few times but the TSCs
would eventually converge).
A basic test should be fine, because the matching code is in use
today.

I applied my two patches to QEMU and I did some testing
with SMP guests (4 VCPUs).

When the host's TSC is stable all the TSC offsets are matched
as expected:

   [ 4544.779699] kvm: VCPU 0 new tsc generation 1, clock 0
   [ 4544.799691] kvm: VCPU 1 matched tsc offset for 0
   [ 4544.835687] kvm: VCPU 2 matched tsc offset for 0
   [ 4544.882229] kvm: VCPU 3 matched tsc offset for 0
   [ 4544.983740] kvm: VCPU 0 matched tsc offset for 0
   [ 4545.015727] kvm: VCPU 1 matched tsc offset for 0
   [ 4545.031762] kvm: VCPU 2 matched tsc offset for 0
   [ 4545.043756] kvm: VCPU 3 matched tsc offset for 0
   [ 4545.382113] kvm: VCPU 0 matched tsc offset for 0
   [ 4545.382138] kvm: VCPU 1 matched tsc offset for 0
   [ 4545.382155] kvm: VCPU 2 matched tsc offset for 0
   [ 4545.382171] kvm: VCPU 3 matched tsc offset for 0

Regarding unstable TSC hosts, I created one by executing

   TSCBSP=`rdmsr -d -p 0 16`; sleep 1s; wrmsr -p 0 16 $TSCBSP

as you suggested. After doing this KVM will adjust the TSC
offsets to make up for the deltas on the host side:

   [ 5232.172074] kvm: VCPU 0 new tsc generation 1, clock 0
[ 5232.180759] kvm: SMP vm created on host with unstable TSC; guest TSC will not be reliable
   [ 5232.204069] kvm: VCPU 1 adjusted tsc offset by 105344
   [ 5232.268070] kvm: VCPU 2 adjusted tsc offset by 210721
   [ 5232.332066] kvm: VCPU 3 adjusted tsc offset by 210708
   [ 5232.444127] kvm: VCPU 0 adjusted tsc offset by 368959
   [ 5232.458448] kvm: VCPU 1 adjusted tsc offset by 47158
   [ 5232.470400] kvm: VCPU 2 adjusted tsc offset by 39352
   [ 5232.482359] kvm: VCPU 3 adjusted tsc offset by 39371
   [ 5232.875343] kvm: VCPU 0 adjusted tsc offset by 1293878
   [ 5232.875371] kvm: VCPU 1 adjusted tsc offset by 121
   [ 5232.875392] kvm: VCPU 2 adjusted tsc offset by 69
   [ 5232.875412] kvm: VCPU 3 adjusted tsc offset by 62

But despite KVM's efforts on the guest side the check in
check_tsc_sync_source() fails and the TSC is marked unstable:

   tsc: Marking TSC unstable due to check_tsc_sync_source failed

By the way, without my patches applied to QEMU the end result
is the same:

   [  266.300068] kvm: VCPU 0 new tsc generation 1, clock 0
[ 266.308746] kvm: SMP vm created on host with unstable TSC; guest TSC will not be reliable
   [  266.332067] kvm: VCPU 1 adjusted tsc offset by 105354
   [  266.396065] kvm: VCPU 2 adjusted tsc offset by 210714
   [  266.428273] kvm: VCPU 3 adjusted tsc offset by 106045

In other words, things seem to be working as expected.

- Fernando

Reply via email to