From: Haiwei Li <lihaiwei@xxxxxxxxxxx> 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@xxxxxxxxxxx> --- 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