From mboxrd@z Thu Jan 1 00:00:00 1970 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Subject: Re: [PATCH 04/12] KVM: x86: Replace call-back set_tsc_khz() with a common function Date: Mon, 5 Oct 2015 21:53:26 +0200 Message-ID: <20151005195325.GA4508@potion.brq.redhat.com> References: <1443418691-24050-1-git-send-email-haozhong.zhang@intel.com> <1443418691-24050-5-git-send-email-haozhong.zhang@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, Gleb Natapov , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Joerg Roedel , Wanpeng Li , Xiao Guangrong , Mihai =?utf-8?B?RG9uyJt1?= , Andy Lutomirski , Kai Huang , linux-kernel@vger.kernel.org To: Haozhong Zhang Return-path: Content-Disposition: inline In-Reply-To: <1443418691-24050-5-git-send-email-haozhong.zhang@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org 2015-09-28 13:38+0800, Haozhong Zhang: > Both VMX and SVM propagate virtual_tsc_khz in the same way, so this > patch removes the call-back set_tsc_khz() and replaces it with a common > function. > > Signed-off-by: Haozhong Zhang > --- > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > +static void set_tsc_khz(struct kvm_vcpu *vcpu, u32 user_tsc_khz, bool scale) > +{ > + u64 ratio, khz; | [...] > + khz = user_tsc_khz; I'd use "user_tsc_khz" directly. > + /* TSC scaling required - calculate ratio */ > + shift = (kvm_tsc_scaling_ratio_frac_bits <= 32) ? > + kvm_tsc_scaling_ratio_frac_bits : 32; > + ratio = khz << shift; > + do_div(ratio, tsc_khz); > + ratio <<= (kvm_tsc_scaling_ratio_frac_bits - shift); VMX is losing 16 bits by this operation; normal fixed point division could get us a smaller drift (and an one-liner here) ... at 4.3 GHz, 32 instead of 48 bits after decimal point translate to one "lost" TSC tick per second, in the worst case. Please mention that we are truncating on purpose :)