From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: [PATCH 0/2] Fix build on i386 due to the latest tsc changes Date: Sat, 18 Feb 2012 10:46:13 -0200 Message-ID: <20120218124613.GA7009@amt.cnet> References: <1329400083-22070-1-git-send-email-avi@redhat.com> <4F3D0A64.60603@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:9905 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751896Ab2BRMvB (ORCPT ); Sat, 18 Feb 2012 07:51:01 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q1ICp0fK009094 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 18 Feb 2012 07:51:01 -0500 Content-Disposition: inline In-Reply-To: <4F3D0A64.60603@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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.