lkml.org 
[lkml]   [2024]   [Apr]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    Date
    SubjectRe: [PATCH 02/10] KVM: x86: Improve accuracy of KVM clock when TSC scaling is in force
    On 18/04/2024 20:34, David Woodhouse wrote:
    > From: David Woodhouse <dwmw@amazon.co.uk>
    >
    > The kvm_guest_time_update() function scales the host TSC frequency to
    > the guest's using kvm_scale_tsc() and the v->arch.l1_tsc_scaling_ratio
    > scaling ratio previously calculated for that vCPU. Then calcuates the
    > scaling factors for the KVM clock itself based on that guest TSC
    > frequency.
    >
    > However, it uses kHz as the unit when scaling, and then multiplies by
    > 1000 only at the end.
    >
    > With a host TSC frequency of 3000MHz and a guest set to 2500MHz, the
    > result of kvm_scale_tsc() will actually come out at 2,499,999kHz. So
    > the KVM clock advertised to the guest is based on a frequency of
    > 2,499,999,000 Hz.
    >
    > By using Hz as the unit from the beginning, the KVM clock would be based
    > on a more accurate frequency of 2,499,999,999 Hz in this example.
    >
    > Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
    > Fixes: 78db6a503796 ("KVM: x86: rewrite handling of scaled TSC for kvmclock")
    > ---
    > arch/x86/include/asm/kvm_host.h | 2 +-
    > arch/x86/kvm/x86.c | 17 +++++++++--------
    > arch/x86/kvm/xen.c | 2 +-
    > 3 files changed, 11 insertions(+), 10 deletions(-)
    >

    Reviewed-by: Paul Durrant <paul@xen.org>


    \
     
     \ /
      Last update: 2024-04-19 17:30    [W:4.042 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site