All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: seabios@seabios.org, Gerd Hoffmann <kraxel@redhat.com>,
	kvm@vger.kernel.org
Subject: Re: [PATCH] tsc: use kvmclock for calibration
Date: Thu, 9 Aug 2012 15:59:00 -0300	[thread overview]
Message-ID: <20120809185900.GD20889@amt.cnet> (raw)
In-Reply-To: <5023B2C4.90302@redhat.com>

On Thu, Aug 09, 2012 at 03:53:24PM +0300, Avi Kivity wrote:
> On 08/09/2012 02:57 PM, Gerd Hoffmann wrote:
> > Use kvmclock for tsc calibration when running on kvm.  Without this the
> > tsc frequency calibrated by seabios can be *way* off in case the virtual
> > machine is booted on a loaded host.  I've seen seabios calibrating 27
> > instead of ca. 2800 MHz, resulting in timeouts being to short by factor
> > 100.  Which in turn leads to disk I/O errors due to timeouts, especially
> > as I/O requests tend to take a bit longer than usual on a loaded box ...
> 
> > +
> > +struct pvclock_vcpu_time_info {
> > +	u32   version;
> > +	u32   pad0;
> > +	u64   tsc_timestamp;
> > +	u64   system_time;
> > +	u32   tsc_to_system_mul;
> > +	s8    tsc_shift;
> > +	u8    flags;
> > +	u8    pad[2];
> > +} PACKED;
> > +
> > +
> > +u64 kvm_tsc_khz(void)
> > +{
> > +    u32 eax, ebx, ecx, edx, msr;
> > +    struct pvclock_vcpu_time_info time;
> > +    u32 addr = (u32)(&time);
> > +    u64 khz;
> > +
> > +    /* check presence and figure msr number */
> > +    cpuid(KVM_CPUID_FEATURES, &eax, &ebx, &ecx, &edx);
> > +    if (eax & KVM_FEATURE_CLOCKSOURCE2) {
> > +        msr = MSR_KVM_SYSTEM_TIME_NEW;
> > +    } else if (eax & KVM_FEATURE_CLOCKSOURCE) {
> > +        msr = MSR_KVM_SYSTEM_TIME;
> > +    } else {
> > +        return 0;
> > +    }
> > +
> > +    /* ask kvm hypervisor to fill struct */
> > +    memset(&time, 0, sizeof(time));
> > +    wrmsr(msr, addr | 1);
> 
> How can this work?  There is a 64-byte alignment requirement.
> 
> > +    wrmsr(msr, 0);
> > +    if (time.version < 2 || time.tsc_to_system_mul == 0)
> > +        return 0;
> > +
> > +    /* go figure tsc frequency */
> > +    khz = pvclock_tsc_khz(&time);
> > +    dprintf(1, "Using kvmclock, msr 0x%x, tsc %d MHz\n",
> > +            msr, (u32)khz / 1000);
> > +    return khz;
> 
> That's a meaningless number.  You can be migrated to a cpu or a machine
> with very different tsc.

Thats why there exists hardware tsc frequency scaling and the software
equivalent for that on kvm.

> You want accurate time on kvm, don't use the tsc.
> 
> 
> -- 
> error compiling committee.c: too many arguments to function
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2012-08-09 18:59 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-09 11:57 [PATCH] tsc: use kvmclock for calibration Gerd Hoffmann
2012-08-09 12:53 ` Avi Kivity
2012-08-09 13:25   ` [SeaBIOS] " Fred .
2012-08-09 13:57   ` Gerd Hoffmann
2012-08-09 14:01     ` Avi Kivity
2012-08-09 14:05       ` Avi Kivity
2012-08-09 14:12         ` Gerd Hoffmann
2012-08-09 14:17           ` Avi Kivity
2012-08-09 14:18       ` Gerd Hoffmann
2012-08-09 14:20         ` Avi Kivity
2012-08-09 19:02           ` Marcelo Tosatti
2012-08-12 10:56             ` Avi Kivity
2012-08-09 19:09       ` Marcelo Tosatti
2012-08-10  7:18         ` Gleb Natapov
2012-08-10  7:30           ` Gleb Natapov
2012-08-10  8:10         ` Gerd Hoffmann
2012-08-10 21:26           ` Marcelo Tosatti
2012-08-13 10:37             ` Gerd Hoffmann
2012-08-13 10:46               ` Gleb Natapov
2012-08-13 12:55                 ` [SeaBIOS] " Fred .
2012-08-12  9:00           ` Avi Kivity
2012-08-09 18:59   ` Marcelo Tosatti [this message]
2012-08-12  9:01     ` 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=20120809185900.GD20889@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=avi@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=seabios@seabios.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 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.