All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: rkrcmar@redhat.com, wanpeng.li@hotmail.com
Subject: [PATCH 1/3] KVM: lapic: reorganize start_hv_timer
Date: Thu, 29 Jun 2017 18:58:19 +0200	[thread overview]
Message-ID: <1498755501-39602-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1498755501-39602-1-git-send-email-pbonzini@redhat.com>

There are many cases in which the hv timer must be canceled.  Split out
a new function to avoid duplication.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kvm/lapic.c | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index d24c8742d9b0..b6689dcae1da 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1501,24 +1501,38 @@ static void cancel_hv_timer(struct kvm_lapic *apic)
 	preempt_enable();
 }
 
-static bool start_hv_timer(struct kvm_lapic *apic)
+static bool __start_hv_timer(struct kvm_lapic *apic)
 {
-	u64 tscdeadline = apic->lapic_timer.tscdeadline;
+	struct kvm_timer *ktimer = &apic->lapic_timer;
+	int r;
 
-	if ((atomic_read(&apic->lapic_timer.pending) &&
-		!apic_lvtt_period(apic)) ||
-		kvm_x86_ops->set_hv_timer(apic->vcpu, tscdeadline)) {
-		if (apic->lapic_timer.hv_timer_in_use)
-			cancel_hv_timer(apic);
-	} else {
-		apic->lapic_timer.hv_timer_in_use = true;
-		hrtimer_cancel(&apic->lapic_timer.timer);
+	if (!apic_lvtt_period(apic) && atomic_read(&ktimer->pending))
+		return false;
+
+	r = kvm_x86_ops->set_hv_timer(apic->vcpu, ktimer->tscdeadline);
+	if (r < 0)
+		return false;
+
+	ktimer->hv_timer_in_use = true;
+	hrtimer_cancel(&ktimer->timer);
 
-		/* In case the sw timer triggered in the window */
-		if (atomic_read(&apic->lapic_timer.pending) &&
-			!apic_lvtt_period(apic))
+	/*
+	 * Also recheck ktimer->pending, in case the sw timer triggered in
+	 * the window.  For periodic timer, leave the hv timer running for
+	 * simplicity, and the deadline will be recomputed on the next vmexit.
+	 */
+	if (!apic_lvtt_period(apic) && atomic_read(&ktimer->pending))
+		return false;
+	return true;
+}
+
+static bool start_hv_timer(struct kvm_lapic *apic)
+{
+	if (!__start_hv_timer(apic)) {
+		if (apic->lapic_timer.hv_timer_in_use)
 			cancel_hv_timer(apic);
 	}
+
 	trace_kvm_hv_timer_state(apic->vcpu->vcpu_id,
 			apic->lapic_timer.hv_timer_in_use);
 	return apic->lapic_timer.hv_timer_in_use;
-- 
1.8.3.1

  reply	other threads:[~2017-06-29 16:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-29 16:58 [PATCH 0/3] KVM: lapic: optimize injection of already-expired timer Paolo Bonzini
2017-06-29 16:58 ` Paolo Bonzini [this message]
2017-06-29 16:58 ` [PATCH 2/3] KVM: lapic: reorganize restart_apic_timer Paolo Bonzini
2017-06-29 16:58 ` [PATCH 3/3] KVM: LAPIC: Fix lapic timer injection delay Paolo Bonzini
2017-07-02  1:35   ` Wanpeng Li
2017-07-02  1:56     ` Wanpeng Li
2017-07-03  7:30       ` Paolo Bonzini
2017-07-03  8:08         ` Wanpeng Li
2017-07-03  8:16           ` Paolo Bonzini
2017-07-03  8:41             ` Wanpeng Li
2017-06-30  1:30 ` [PATCH 0/3] KVM: lapic: optimize injection of already-expired timer Wanpeng Li

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=1498755501-39602-2-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rkrcmar@redhat.com \
    --cc=wanpeng.li@hotmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.