linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: LAPIC: Reset timer_advance_ns if timer mode switch
@ 2020-08-28  1:35 Wanpeng Li
  2020-08-31 12:48 ` Vitaly Kuznetsov
  2020-09-02 21:23 ` Sean Christopherson
  0 siblings, 2 replies; 6+ messages in thread
From: Wanpeng Li @ 2020-08-28  1:35 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

From: Wanpeng Li <wanpengli@tencent.com>

per-vCPU timer_advance_ns should be set to 0 if timer mode is not tscdeadline 
otherwise we waste cpu cycles in the function lapic_timer_int_injected(), 
especially on AMD platform which doesn't support tscdeadline mode. We can 
reset timer_advance_ns to the initial value if switch back to tscdealine 
timer mode.

Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
 arch/x86/kvm/lapic.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 654649b..abc296d 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1499,10 +1499,16 @@ static void apic_update_lvtt(struct kvm_lapic *apic)
 			kvm_lapic_set_reg(apic, APIC_TMICT, 0);
 			apic->lapic_timer.period = 0;
 			apic->lapic_timer.tscdeadline = 0;
+			if (timer_mode == APIC_LVT_TIMER_TSCDEADLINE &&
+				lapic_timer_advance_dynamic)
+				apic->lapic_timer.timer_advance_ns = LAPIC_TIMER_ADVANCE_NS_INIT;
 		}
 		apic->lapic_timer.timer_mode = timer_mode;
 		limit_periodic_timer_frequency(apic);
 	}
+	if (timer_mode != APIC_LVT_TIMER_TSCDEADLINE &&
+		lapic_timer_advance_dynamic)
+		apic->lapic_timer.timer_advance_ns = 0;
 }
 
 /*
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-09-04 16:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-28  1:35 [PATCH] KVM: LAPIC: Reset timer_advance_ns if timer mode switch Wanpeng Li
2020-08-31 12:48 ` Vitaly Kuznetsov
2020-09-01  3:25   ` Wanpeng Li
2020-09-02 21:23 ` Sean Christopherson
2020-09-03 10:57   ` Wanpeng Li
2020-09-04 16:06     ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).