From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753149AbbJETyQ (ORCPT ); Mon, 5 Oct 2015 15:54:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43521 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752193AbbJETxd (ORCPT ); Mon, 5 Oct 2015 15:53:33 -0400 Date: Mon, 5 Oct 2015 21:53:26 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Haozhong Zhang 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 Subject: Re: [PATCH 04/12] KVM: x86: Replace call-back set_tsc_khz() with a common function 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 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: X-Mailing-List: linux-kernel@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 :)