[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v6 02/36] KVM: x86: Improve accuracy of KVM clock when TSC scaling is in force



On Fri, Jul 03, 2026, David Woodhouse wrote:
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index f14009f25a3b..b2446c04a076 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -950,7 +950,7 @@ struct kvm_vcpu_arch {
>       gpa_t time;
>       s8  pvclock_tsc_shift;
>       u32 pvclock_tsc_mul;
> -     unsigned int hw_tsc_khz;
> +     u64 hw_tsc_hz;
>       struct gfn_to_pfn_cache pv_time;
>       /* set guest stopped flag in pvclock flags field */
>       bool pvclock_set_guest_stopped_request;
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index e69156b54cff..621d950ec692 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -2131,7 +2131,7 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 
> *ebx,
>                               *ecx = vcpu->arch.pvclock_tsc_mul;
>                               *edx = vcpu->arch.pvclock_tsc_shift;
>                       } else if (index == 2) {
> -                             *eax = vcpu->arch.hw_tsc_khz;
> +                             *eax = div_u64(vcpu->arch.hw_tsc_hz, 1000);

Kinda silly, but s/1000/HZ_PER_KHZ.

>                       }
>               }
>       } else {
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 0550359ed798..dbcff49cd561 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3314,7 +3314,8 @@ static void kvm_setup_guest_pvclock(struct 
> pvclock_vcpu_time_info *ref_hv_clock,
>  int kvm_guest_time_update(struct kvm_vcpu *v)
>  {
>       struct pvclock_vcpu_time_info hv_clock = {};
> -     unsigned long flags, tgt_tsc_khz;
> +     unsigned long flags;
> +     u64 tgt_tsc_hz;
>       unsigned seq;
>       struct kvm_vcpu_arch *vcpu = &v->arch;
>       struct kvm_arch *ka = &v->kvm->arch;
> @@ -3340,8 +3341,8 @@ int kvm_guest_time_update(struct kvm_vcpu *v)
>  
>       /* Keep irq disabled to prevent changes to the clock */
>       local_irq_save(flags);
> -     tgt_tsc_khz = get_cpu_tsc_khz();
> -     if (unlikely(tgt_tsc_khz == 0)) {
> +     tgt_tsc_hz = (u64)get_cpu_tsc_khz() * 1000;

Here too.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.