public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Yunhong Jiang <yunhong.jiang@linux.intel.com>, kvm@vger.kernel.org
Cc: mtosatti@redhat.com, rkrcmar@redhat.com, kernellwp@gmail.com
Subject: Re: [RFC PATCH V3 5/5] Utilize the vmx preemption timer for tsc deadline timer
Date: Mon, 6 Jun 2016 14:36:30 +0200	[thread overview]
Message-ID: <291ce5f2-134a-70bb-a794-2977270a2c44@redhat.com> (raw)
In-Reply-To: <1465000951-13343-6-git-send-email-yunhong.jiang@linux.intel.com>



On 04/06/2016 02:42, Yunhong Jiang wrote:
> +void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu)
> +{
> +	struct kvm_lapic *apic = vcpu->arch.apic;
> +
> +	WARN_ON(!apic->lapic_timer.hv_timer_in_use);
> +	WARN_ON(swait_active(&vcpu->wq));
> +	kvm_x86_ops->cancel_hv_timer(vcpu);
> +	apic->lapic_timer.hv_timer_in_use = 0;

Please use "false" here instead of 0.

> +	apic_timer_expired(apic);
> +}
> +EXPORT_SYMBOL_GPL(kvm_lapic_expired_hv_timer);
> +

> 
> +		if (!kvm_x86_ops->set_hv_timer(apic->vcpu, tscdeadline)) {
> +			apic->lapic_timer.hv_timer_in_use = true;
> +			hrtimer_cancel(&apic->lapic_timer.timer);
> +		}
> +
> +		/* In case the sw timer triggered in above small window */
> +		if (atomic_read(&apic->lapic_timer.pending) &&
> +				apic->lapic_timer.hv_timer_in_use)
> +			kvm_x86_ops->cancel_hv_timer(apic->vcpu);

Put this "if" after hrtimer_cancel, and you can avoid the "&&
apic->lapic_timer.hv_timer_in_use".  Also, I think it's clear to add an
extra

	apic->lapic_timer.hv_timer_in_use = false;

here, since you have it in kvm_lapic_expired_hv_timer.

> +void vmx_arm_hv_timer(struct kvm_vcpu *vcpu)
> +{
> +	struct kvm_lapic *apic = vcpu->arch.apic;
> +	u64 tscl;
> +	u32 delta_tsc;
> +
> +	if (!apic->lapic_timer.hv_timer_in_use)

Can you change this to something like vcpu->arch.hv_deadline_tsc != -1
(by adjusting set_hv_timer and cancel_hv_timer)?

> +		return;
> +
> +	tscl = rdtsc();
> +	if (vcpu->arch.hv_deadline_tsc > tscl)
> +		/* sure to be 32 bit only because checked on set_hv_timer */

	/* vmx_set_hv_timer checks that the delta fits in 32 bits */

> +		delta_tsc = (u32)((vcpu->arch.hv_deadline_tsc - tscl) >>
> +			cpu_preemption_timer_multi);
> +	else
> +		delta_tsc = 0;
> +
> +	vmcs_write32(VMX_PREEMPTION_TIMER_VALUE, delta_tsc);
> +}
> +

...

> +		u64 tscl = rdtsc();
>  		s64 tsc_delta = !vcpu->arch.last_host_tsc ? 0 :
> -				rdtsc() - vcpu->arch.last_host_tsc;
> +				tscl - vcpu->arch.last_host_tsc;
>  		if (tsc_delta < 0)
>  			mark_tsc_unstable("KVM discovered backwards TSC");
> +
> +		/*
> +		 * If tsc backwrap, we need update the hv_deadline_tsc,
> +		 * otherwise, the ((hv_deadline_tsc-tsc) >>
> +		 * cpu_preemption_timer_multi) may >32bit on vcpu_run().
> +		 * This may cause deadline_tsc not so accurate, but that's
> +		 * inevitable anyway.
> +		 */
> +		if (tscl < vcpu->arch.hv_orig_tsc) {
> +			vcpu->arch.hv_orig_tsc = tscl;
> +			vcpu->arch.hv_deadline_tsc -=
> +				vcpu->arch.hv_orig_tsc - tscl;
> +		}

Can you instead call vmx_set_hv_timer again (and if it returns an error,
call kvm_lapic_switch_to_sw_timer)?  Perhaps it should even be done
unconditionally on vmx_vcpu_load.

  reply	other threads:[~2016-06-06 12:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-04  0:42 [RFC PATCH V3 0/5] Utilizing VMX preemption for timer virtualization Yunhong Jiang
2016-06-04  0:42 ` [RFC PATCH V3 1/5] Rename the vmx_pre/post_block to pi_pre/post_block Yunhong Jiang
2016-06-04  0:42 ` [RFC PATCH V3 2/5] Add function for left shift and 64 bit division Yunhong Jiang
2016-06-06 12:37   ` Paolo Bonzini
2016-06-04  0:42 ` [RFC PATCH V3 3/5] Utilize the vmx preemption timer Yunhong Jiang
2016-06-06 12:37   ` Paolo Bonzini
2016-06-04  0:42 ` [RFC PATCH V3 4/5] Separate the start_sw_tscdeadline Yunhong Jiang
2016-06-04  0:42 ` [RFC PATCH V3 5/5] Utilize the vmx preemption timer for tsc deadline timer Yunhong Jiang
2016-06-06 12:36   ` Paolo Bonzini [this message]
2016-06-06 12:45 ` [RFC PATCH V3 0/5] Utilizing VMX preemption for timer virtualization Paolo Bonzini
2016-06-06 18:26   ` yunhong jiang
2016-06-07 16:31   ` David Matlack
2016-06-07 19:30   ` David Matlack
2016-06-08  4:18 ` Wanpeng Li
2016-06-13 20:56   ` yunhong jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=291ce5f2-134a-70bb-a794-2977270a2c44@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=yunhong.jiang@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox