public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: KVM list <kvm@vger.kernel.org>
Subject: Re: [PATCH] Fix kvmclock on !constant_tsc boxes.
Date: Sat, 7 Feb 2009 05:14:03 -0200	[thread overview]
Message-ID: <20090207071403.GA6301@amt.cnet> (raw)
In-Reply-To: <4989C7B4.10508@redhat.com>

Hi Gerd,

On Wed, Feb 04, 2009 at 05:52:04PM +0100, Gerd Hoffmann wrote:
> kvmclock currently falls apart on machines without constant tsc.
> This patch fixes it.  Changes:
> 
>   * keep tsc frequency in a per-cpu variable.
>   * handle kvmclock update using a new request flag, thus checking
>     whenever we need an update each time we enter guest context.
>   * use a cpufreq notifier to track frequency changes and force
>     kvmclock updates.
>   * send ipis to kick cpu out of guest context if needed to make
>     sure the guest doesn't see stale values.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  arch/x86/kvm/x86.c       |   99 +++++++++++++++++++++++++++++++++++++++++++---
>  include/linux/kvm_host.h |    1 +
>  2 files changed, 94 insertions(+), 6 deletions(-)
> 

> +	spin_lock(&kvm_lock);
> +	list_for_each_entry(kvm, &vm_list, vm_list) {
> +		for (i = 0; i < KVM_MAX_VCPUS; ++i) {
> +			vcpu = kvm->vcpus[i];
> +			if (!vcpu)
> +				continue;
> +			if (vcpu->cpu != freq->cpu)
> +				continue;
> +			if (!kvm_request_guest_time_update(vcpu))
> +				continue;
> +			if (vcpu->cpu != smp_processor_id())
> +				send_ipi++;
> +		}
> +	}
> +	spin_unlock(&kvm_lock);

The loop is cold hearted, but Juan's cleanups can be worked for 2.6.30
merge window. Given how many people have hit the bug better have
something non invasive until then.

> +
> +	if (freq->old < freq->new  &&  send_ipi) {

Can you fix the whitespace breakage please?

> +		smp_call_function_single(freq->cpu, bounce_off, NULL, 1);
> +	}
> +        return 0;
> +}

  reply	other threads:[~2009-02-08  5:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-04 16:52 [PATCH] Fix kvmclock on !constant_tsc boxes Gerd Hoffmann
2009-02-07  7:14 ` Marcelo Tosatti [this message]
2009-02-08  6:08 ` Marcelo Tosatti
2009-02-09 20:15   ` Marcelo Tosatti
2009-02-11 13:14     ` Avi Kivity

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=20090207071403.GA6301@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    /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