public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Ryan Harper <ryanh@us.ibm.com>
Cc: kvm-devel@lists.sourceforge.net
Subject: Re: [RFC][PATCH] svm.c: tsc unsigned delta calculation
Date: Wed, 07 May 2008 17:29:44 -0500	[thread overview]
Message-ID: <48222D58.1080908@codemonkey.ws> (raw)
In-Reply-To: <20080507220102.GQ17938@us.ibm.com>

Ryan Harper wrote:
> I've been playing around with smp guests on a couple amd systems and
> I've also seen some of the smp/locking issues which lead me to dig into
> some of the tsc code.  The svm_cpu_load, the tsc_offset calc will
> generate a massively large tsc_offset if we're switching cpus and
> tsc_this is ahead of the host_tsc value (delta would normally be
> negative, but since it's unsigned, we get a huge positive number).
>
> svm_vcpu_load()
> ...
>     rdtscll(tsc_this);
>     delta = vcpu->arch.host_tsc - tsc_this;
>     svm->vmcb->control.tsc_offset += delta;
>   

This math will work out fine since the very large number will generate 
an overflow and the result will be identical to if we were using s64s.  
We're using u64s because that's how the tsc_offset is defined by hardware.

> This is handled a little differently on Intel (in vmx.c) where there is
> a check:
>
>     if (tsc_this < vcpu->arch.host_tsc)
>         /* do delta and new offset calc */
>   

So what your patch really does is change the behavior of the tsc_offset 
to increase the guest's TSC by a potentially large amount depending on 
how out of sync the TSC is on CPU migration.

The question is why this would make things work out better for you..

Do you have Gerd's kvm-clock most recent patch applied?

Regards,

Anthony Liguori

> This check makes sense to me in that we only need to ensure that we
> don't go backwards which means that unless the new cpu is behind the
> current vcpu's host_tsc, we can skip a new delta calc.  If the check
> doesn't make sense then we'll need to do the math with s64s.
>
> Attached patch fixed the case where an idle guest was live-locked.
>
>   


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

  reply	other threads:[~2008-05-07 22:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-07 22:01 [RFC][PATCH] svm.c: tsc unsigned delta calculation Ryan Harper
2008-05-07 22:29 ` Anthony Liguori [this message]
2008-05-13 10:11 ` 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=48222D58.1080908@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=ryanh@us.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox