All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joerg Roedel <joro@8bytes.org>
To: Avi Kivity <avi@redhat.com>
Cc: Joerg Roedel <joerg.roedel@amd.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Zachary Amsden <zamsden@redhat.com>,
	kvm@vger.kernel.org
Subject: Re: [PATCH 3/6] KVM: X86: Make tsc_delta calculation a function of guest tsc
Date: Sun, 27 Mar 2011 13:10:50 +0200	[thread overview]
Message-ID: <20110327111050.GD28219@8bytes.org> (raw)
In-Reply-To: <4D8F17FF.8020807@redhat.com>

On Sun, Mar 27, 2011 at 12:57:03PM +0200, Avi Kivity wrote:
> On 03/25/2011 10:44 AM, Joerg Roedel wrote:
>> The calculation of the tsc_delta value to ensure a
>> forward-going tsc for the guest is a function of the
>> host-tsc. This works as long as the guests tsc_khz is equal
>> to the hosts tsc_khz. With tsc-scaling hardware support this
>> is not longer true and the tsc_delta needs to be calculated
>>
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
>> @@ -2126,8 +2126,13 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
>>   	kvm_x86_ops->vcpu_load(vcpu, cpu);
>>   	if (unlikely(vcpu->cpu != cpu) || check_tsc_unstable()) {
>>   		/* Make sure TSC doesn't go backwards */
>> -		s64 tsc_delta = !vcpu->arch.last_host_tsc ? 0 :
>> -				native_read_tsc() - vcpu->arch.last_host_tsc;
>> +		s64 tsc_delta;
>> +		u64 tsc;
>> +
>> +		kvm_get_msr(vcpu, MSR_IA32_TSC,&tsc);
>> +		tsc_delta = !vcpu->arch.last_guest_tsc ? 0 :
>> +			     tsc - vcpu->arch.last_guest_tsc;
>> +
>>   		if (tsc_delta<  0)
>>   			mark_tsc_unstable("KVM discovered backwards TSC");
>>   		if (check_tsc_unstable()) {
>
>
> Patch is correct, but can this really happen?  Won't all machines with  
> scaled tsc also be stable?
>
> Perhaps not multi-board machines.

Yes, all machines with tsc-scaling should also have a stable tsc, so
this patch is not strictly required.
I added this patch as a response to Zachary's thoughts about the values
that need to be passed to adjust_tsc_offset. Zachary mentioned that with
this patch-series the adjust_tsc_offset function will either take the
adjustment in guest-tsc or host-tsc units (which is not problematic if
guest and host tsc have the same frequency).
But with tsc-scaling (and Zachary's upcoming patches) this might become
a problem. So I changed the semantic of adjust_tsc_offset to always take
the adjustment in guest-tsc units. This patch-set converts the one and
only call-site of adjust_tsc_offset where the unit is calculated as a
function of the host-tsc.

	Joerg


  reply	other threads:[~2011-03-27 11:10 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-25  8:44 [PATCH 0/6] TSC scaling support for KVM v3 Joerg Roedel
2011-03-25  8:44 ` [PATCH 1/6] KVM: SVM: Implement infrastructure for TSC_RATE_MSR Joerg Roedel
2011-03-25  8:44 ` [PATCH 2/6] KVM: X86: Let kvm-clock report the right tsc frequency Joerg Roedel
2011-03-25  8:44 ` [PATCH 3/6] KVM: X86: Make tsc_delta calculation a function of guest tsc Joerg Roedel
2011-03-27 10:57   ` Avi Kivity
2011-03-27 11:10     ` Joerg Roedel [this message]
2011-04-16 16:09   ` Jan Kiszka
2011-04-17 12:06     ` Joerg Roedel
2011-04-19  0:02       ` Zachary Amsden
2011-04-19  6:46         ` Roedel, Joerg
2011-04-19  6:49           ` Jan Kiszka
2011-04-19 14:15             ` Zachary Amsden
2011-04-19 14:24               ` Jan Kiszka
2011-04-18  8:03     ` Roedel, Joerg
2011-04-18  9:12       ` Jan Kiszka
2011-04-18  9:25         ` Joerg Roedel
2011-03-25  8:44 ` [PATCH 4/6] KVM: X86: Implement call-back to propagate virtual_tsc_khz Joerg Roedel
2011-03-25  8:44 ` [PATCH 5/6] KVM: X86: Delegate tsc-offset calculation to architecture code Joerg Roedel
2011-03-25  8:44 ` [PATCH 6/6] KVM: X86: Implement userspace interface to set virtual_tsc_khz Joerg Roedel
2011-03-27 10:58 ` [PATCH 0/6] TSC scaling support for KVM v3 Avi Kivity
2011-04-06  7:33 ` Avi Kivity
  -- strict thread matches above, loose matches on Subject: below --
2011-03-24  7:40 [PATCH 0/6][RESEND] TSC scaling support for KVM v2 Joerg Roedel
2011-03-24  7:40 ` [PATCH 3/6] KVM: X86: Make tsc_delta calculation a function of guest tsc Joerg Roedel
2011-03-15  9:36 [PATCH 0/6] TSC scaling support for KVM v2 Joerg Roedel
2011-03-15  9:36 ` [PATCH 3/6] KVM: X86: Make tsc_delta calculation a function of guest tsc Joerg Roedel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110327111050.GD28219@8bytes.org \
    --to=joro@8bytes.org \
    --cc=avi@redhat.com \
    --cc=joerg.roedel@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=zamsden@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.