From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 0/2] Fix build on i386 due to the latest tsc changes
Date: Sat, 18 Feb 2012 10:46:13 -0200 [thread overview]
Message-ID: <20120218124613.GA7009@amt.cnet> (raw)
In-Reply-To: <4F3D0A64.60603@redhat.com>
On Thu, Feb 16, 2012 at 03:53:40PM +0200, Avi Kivity wrote:
> On 02/16/2012 03:48 PM, Avi Kivity wrote:
> > The code fixed by the second patch looks suspect though:
> >
> > nsdiff = data - kvm->arch.last_tsc_write;
> > nsdiff = (nsdiff * 1000) / vcpu->arch.virtual_tsc_khz;
> >
> > before the division, nsdiff is in tsc units. Dividing it by
> > tsc_khz/1000 is equivalent to multiplying it by 1000000 and dividing it by
> > tsc_hz, so the result is in units of mega-seconds. I expect we want
> >
>
> Actually it results in units of microseconds, while we want nanoseconds.
>
> So maybe the correct code is
>
> nsdiff = (nsdiff * 1000000) / vcpu->arch.virtual_tsc_khz;
>
> returning nanoseconds.
>
> I note that if the guest writes a large value into the tsc, this breaks.
You are right, the division is wrong. I'll fix it and run some tests
later. Nice catch.
prev parent reply other threads:[~2012-02-18 12:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-16 13:48 [PATCH 0/2] Fix build on i386 due to the latest tsc changes Avi Kivity
2012-02-16 13:48 ` [PATCH 1/2] KVM: Fix 64-bit division in kvm_set_tsc_khz() Avi Kivity
2012-02-16 13:48 ` [PATCH 2/2] KVM: Fix 64-bit division in kvm_write_tsc() Avi Kivity
2012-02-16 13:53 ` [PATCH 0/2] Fix build on i386 due to the latest tsc changes Avi Kivity
2012-02-18 12:46 ` Marcelo Tosatti [this message]
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=20120218124613.GA7009@amt.cnet \
--to=mtosatti@redhat.com \
--cc=avi@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