kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kvm: lapic: add module parameters for LAPIC_TIMER_ADVANCE_ADJUST_MAX/MIN
@ 2021-03-03  2:09 lihaiwei.kernel
  2021-03-03  2:39 ` Haiwei Li
  0 siblings, 1 reply; 6+ messages in thread
From: lihaiwei.kernel @ 2021-03-03  2:09 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: pbonzini, seanjc, vkuznets, wanpengli, jmattson, joro, Haiwei Li

From: Haiwei Li <lihaiwei@tencent.com>

In my test environment, advance_expire_delta is frequently greater than
the fixed LAPIC_TIMER_ADVANCE_ADJUST_MAX. And this will hinder the
adjustment.

Adding module parameters for LAPIC_TIMER_ADVANCE_ADJUST_MAX/MIN, so they
can be dynamically adjusted.

Signed-off-by: Haiwei Li <lihaiwei@tencent.com>
---
 arch/x86/kvm/lapic.c | 6 ++----
 arch/x86/kvm/x86.c   | 8 ++++++++
 arch/x86/kvm/x86.h   | 3 +++
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 45d40bf..730c657 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -61,8 +61,6 @@
 #define APIC_VECTORS_PER_REG		32
 
 static bool lapic_timer_advance_dynamic __read_mostly;
-#define LAPIC_TIMER_ADVANCE_ADJUST_MIN	100	/* clock cycles */
-#define LAPIC_TIMER_ADVANCE_ADJUST_MAX	10000	/* clock cycles */
 #define LAPIC_TIMER_ADVANCE_NS_INIT	1000
 #define LAPIC_TIMER_ADVANCE_NS_MAX     5000
 /* step-by-step approximation to mitigate fluctuation */
@@ -1563,8 +1561,8 @@ static inline void adjust_lapic_timer_advance(struct kvm_vcpu *vcpu,
 	u64 ns;
 
 	/* Do not adjust for tiny fluctuations or large random spikes. */
-	if (abs(advance_expire_delta) > LAPIC_TIMER_ADVANCE_ADJUST_MAX ||
-	    abs(advance_expire_delta) < LAPIC_TIMER_ADVANCE_ADJUST_MIN)
+	if (abs(advance_expire_delta) > lapic_timer_advance_adjust_cycles_max ||
+	    abs(advance_expire_delta) < lapic_timer_advance_adjust_cycles_min)
 		return;
 
 	/* too early */
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 828de7d..3bd8d19 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -176,6 +176,14 @@
 int __read_mostly pi_inject_timer = -1;
 module_param(pi_inject_timer, bint, S_IRUGO | S_IWUSR);
 
+u64 __read_mostly lapic_timer_advance_adjust_cycles_max = 10000;
+module_param(lapic_timer_advance_adjust_cycles_max, ullong, S_IRUGO | S_IWUSR);
+EXPORT_SYMBOL_GPL(lapic_timer_advance_adjust_cycles_max);
+
+u64 __read_mostly lapic_timer_advance_adjust_cycles_min = 100;
+module_param(lapic_timer_advance_adjust_cycles_min, ullong, S_IRUGO | S_IWUSR);
+EXPORT_SYMBOL_GPL(lapic_timer_advance_adjust_cycles_min);
+
 /*
  * Restoring the host value for MSRs that are only consumed when running in
  * usermode, e.g. SYSCALL MSRs and TSC_AUX, can be deferred until the CPU
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index ee6e010..3f7eca0 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -305,6 +305,9 @@ static inline bool kvm_mpx_supported(void)
 
 extern int pi_inject_timer;
 
+extern u64 lapic_timer_advance_adjust_cycles_max;
+extern u64 lapic_timer_advance_adjust_cycles_min;
+
 extern struct static_key kvm_no_apic_vcpu;
 
 extern bool report_ignored_msrs;
-- 
1.8.3.1


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

end of thread, other threads:[~2021-03-13  1:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03  2:09 [PATCH] kvm: lapic: add module parameters for LAPIC_TIMER_ADVANCE_ADJUST_MAX/MIN lihaiwei.kernel
2021-03-03  2:39 ` Haiwei Li
2021-03-09 23:42   ` Sean Christopherson
2021-03-10  9:15     ` Haiwei Li
2021-03-13  0:58       ` Sean Christopherson
2021-03-13  1:31         ` Haiwei Li

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).