Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1332145 > unrolled thread

Re: [PATCH 2/4] KVM: x86: rewrite handling of scaled TSC for kvmclock

Started byMarcelo Tosatti <mtosatti@redhat.com>
First post2016-02-11 16:30 +0100
Last post2016-02-11 16:30 +0100
Articles 1 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH 2/4] KVM: x86: rewrite handling of scaled TSC for kvmclock Marcelo Tosatti <mtosatti@redhat.com> - 2016-02-11 16:30 +0100

#1332145 — Re: [PATCH 2/4] KVM: x86: rewrite handling of scaled TSC for kvmclock

FromMarcelo Tosatti <mtosatti@redhat.com>
Date2016-02-11 16:30 +0100
SubjectRe: [PATCH 2/4] KVM: x86: rewrite handling of scaled TSC for kvmclock
Message-ID<r11lU-2aN-3@gated-at.bofh.it>
On Mon, Feb 08, 2016 at 04:18:29PM +0100, Paolo Bonzini wrote:
> This is the same as before:
> 
>     kvm_scale_tsc(tgt_tsc_khz)
>         = tgt_tsc_khz * ratio
>         = tgt_tsc_khz * user_tsc_khz / tsc_khz   (see set_tsc_khz)
>         = user_tsc_khz                           (see kvm_guest_time_update)
>         = vcpu->arch.virtual_tsc_khz             (see kvm_set_tsc_khz)
> 
> However, computing it through kvm_scale_tsc makes it possible
> to include the NTP correction in tgt_tsc_khz, as done in the
> next patch.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/kvm/x86.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 1ca2b44f70bb..6db3c219795b 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -1713,7 +1713,7 @@ static void kvm_gen_update_masterclock(struct kvm *kvm)
>  
>  static int kvm_guest_time_update(struct kvm_vcpu *v)
>  {
> -	unsigned long flags, this_tsc_khz, tgt_tsc_khz;
> +	unsigned long flags, tgt_tsc_khz;
>  	struct kvm_vcpu_arch *vcpu = &v->arch;
>  	struct kvm_arch *ka = &v->kvm->arch;
>  	s64 kernel_ns;
> @@ -1739,8 +1739,8 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
>  
>  	/* Keep irq disabled to prevent changes to the clock */
>  	local_irq_save(flags);
> -	this_tsc_khz = __this_cpu_read(cpu_tsc_khz);
> -	if (unlikely(this_tsc_khz == 0)) {
> +	tgt_tsc_khz = __this_cpu_read(cpu_tsc_khz);
> +	if (unlikely(tgt_tsc_khz == 0)) {
>  		local_irq_restore(flags);
>  		kvm_make_request(KVM_REQ_CLOCK_UPDATE, v);
>  		return 1;
> @@ -1775,13 +1775,14 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
>  	if (!vcpu->pv_time_enabled)
>  		return 0;
>  
> -	if (unlikely(vcpu->hw_tsc_khz != this_tsc_khz)) {
> -		tgt_tsc_khz = kvm_has_tsc_control ?
> -			vcpu->virtual_tsc_khz : this_tsc_khz;
> +	if (kvm_has_tsc_control)
> +		tgt_tsc_khz = kvm_scale_tsc(v, tgt_tsc_khz);
> +
> +	if (unlikely(vcpu->hw_tsc_khz != tgt_tsc_khz)) {
>  		kvm_get_time_scale(NSEC_PER_SEC / 1000, tgt_tsc_khz,
>  				   &vcpu->hv_clock.tsc_shift,
>  				   &vcpu->hv_clock.tsc_to_system_mul);
> -		vcpu->hw_tsc_khz = this_tsc_khz;
> +		vcpu->hw_tsc_khz = tgt_tsc_khz;
>  	}
>  
>  	/* With all the info we got, fill in the values */
> -- 
> 1.8.3.1
> 

Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web