lkml.org 
[lkml]   [2015]   [Oct]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    Date
    SubjectRe: [PATCH 04/12] KVM: x86: Replace call-back set_tsc_khz() with a common function
    On Mon, Oct 5, 2015 at 12:53 PM, Radim Krčmář <rkrcmar@redhat.com> wrote:
    > 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 <haozhong.zhang@intel.com>
    >> ---
    >> 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.

    We can easily avoid losing precision on x86_64 (divq allows a 128-bit
    dividend). 32-bit can just lose the 16 bits of precision (TSC scaling
    is only available on SkyLake, and I'd be surprised if there were
    many hosts running KVM in protected mode on SkyLake :)).

    >
    > Please mention that we are truncating on purpose :)
    > --
    > 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


    \
     
     \ /
      Last update: 2015-10-05 23:01    [W:3.337 / U:0.252 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site