* [PATCH v2] KVM: LAPIC: Loose fluctuation filter for auto tune lapic_timer_advance_ns
@ 2019-09-26 0:54 Wanpeng Li
2019-09-26 10:25 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: Wanpeng Li @ 2019-09-26 0:54 UTC (permalink / raw)
To: linux-kernel, kvm
Cc: Paolo Bonzini, Radim Krčmář,
Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel
From: Wanpeng Li <wanpengli@tencent.com>
5000 guest cycles delta is easy to encounter on desktop, per-vCPU
lapic_timer_advance_ns always keeps at 1000ns initial value, lets
loose fluctuation filter a bit to make auto tune can make some
progress.
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
v1 -> v2:
* separate defines for ns vs cycles
arch/x86/kvm/lapic.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 3a3a685..7bfc3c0 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -66,9 +66,10 @@
#define X2APIC_BROADCAST 0xFFFFFFFFul
static bool lapic_timer_advance_dynamic __read_mostly;
-#define LAPIC_TIMER_ADVANCE_ADJUST_MIN 100
-#define LAPIC_TIMER_ADVANCE_ADJUST_MAX 5000
-#define LAPIC_TIMER_ADVANCE_ADJUST_INIT 1000
+#define LAPIC_TIMER_ADVANCE_EXPIRE_MIN 100
+#define LAPIC_TIMER_ADVANCE_EXPIRE_MAX 10000
+#define LAPIC_TIMER_ADVANCE_NS_INIT 1000
+#define LAPIC_TIMER_ADVANCE_NS_MAX 5000
/* step-by-step approximation to mitigate fluctuation */
#define LAPIC_TIMER_ADVANCE_ADJUST_STEP 8
@@ -1488,8 +1489,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_EXPIRE_MAX ||
+ abs(advance_expire_delta) < LAPIC_TIMER_ADVANCE_EXPIRE_MIN)
return;
/* too early */
@@ -1504,8 +1505,8 @@ static inline void adjust_lapic_timer_advance(struct kvm_vcpu *vcpu,
timer_advance_ns += ns/LAPIC_TIMER_ADVANCE_ADJUST_STEP;
}
- if (unlikely(timer_advance_ns > LAPIC_TIMER_ADVANCE_ADJUST_MAX))
- timer_advance_ns = LAPIC_TIMER_ADVANCE_ADJUST_INIT;
+ if (unlikely(timer_advance_ns > LAPIC_TIMER_ADVANCE_NS_MAX))
+ timer_advance_ns = LAPIC_TIMER_ADVANCE_NS_INIT;
apic->lapic_timer.timer_advance_ns = timer_advance_ns;
}
@@ -2302,7 +2303,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu, int timer_advance_ns)
HRTIMER_MODE_ABS_HARD);
apic->lapic_timer.timer.function = apic_timer_fn;
if (timer_advance_ns == -1) {
- apic->lapic_timer.timer_advance_ns = LAPIC_TIMER_ADVANCE_ADJUST_INIT;
+ apic->lapic_timer.timer_advance_ns = LAPIC_TIMER_ADVANCE_NS_INIT;
lapic_timer_advance_dynamic = true;
} else {
apic->lapic_timer.timer_advance_ns = timer_advance_ns;
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] KVM: LAPIC: Loose fluctuation filter for auto tune lapic_timer_advance_ns
2019-09-26 0:54 [PATCH v2] KVM: LAPIC: Loose fluctuation filter for auto tune lapic_timer_advance_ns Wanpeng Li
@ 2019-09-26 10:25 ` Paolo Bonzini
2019-09-26 10:34 ` Wanpeng Li
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2019-09-26 10:25 UTC (permalink / raw)
To: Wanpeng Li, linux-kernel, kvm
Cc: Radim Krčmář,
Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel
On 26/09/19 02:54, Wanpeng Li wrote:
> -#define LAPIC_TIMER_ADVANCE_ADJUST_MIN 100
> -#define LAPIC_TIMER_ADVANCE_ADJUST_MAX 5000
> -#define LAPIC_TIMER_ADVANCE_ADJUST_INIT 1000
> +#define LAPIC_TIMER_ADVANCE_EXPIRE_MIN 100
> +#define LAPIC_TIMER_ADVANCE_EXPIRE_MAX 10000
> +#define LAPIC_TIMER_ADVANCE_NS_INIT 1000
> +#define LAPIC_TIMER_ADVANCE_NS_MAX 5000
I think the old #define value is good. What about:
-#define LAPIC_TIMER_ADVANCE_ADJUST_MIN 100
-#define LAPIC_TIMER_ADVANCE_ADJUST_MAX 5000
-#define LAPIC_TIMER_ADVANCE_ADJUST_INIT 1000
+#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
?
Thanks,
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] KVM: LAPIC: Loose fluctuation filter for auto tune lapic_timer_advance_ns
2019-09-26 10:25 ` Paolo Bonzini
@ 2019-09-26 10:34 ` Wanpeng Li
0 siblings, 0 replies; 3+ messages in thread
From: Wanpeng Li @ 2019-09-26 10:34 UTC (permalink / raw)
To: Paolo Bonzini
Cc: LKML, kvm, Radim Krčmář,
Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel
On Thu, 26 Sep 2019 at 18:25, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 26/09/19 02:54, Wanpeng Li wrote:
> > -#define LAPIC_TIMER_ADVANCE_ADJUST_MIN 100
> > -#define LAPIC_TIMER_ADVANCE_ADJUST_MAX 5000
> > -#define LAPIC_TIMER_ADVANCE_ADJUST_INIT 1000
> > +#define LAPIC_TIMER_ADVANCE_EXPIRE_MIN 100
> > +#define LAPIC_TIMER_ADVANCE_EXPIRE_MAX 10000
> > +#define LAPIC_TIMER_ADVANCE_NS_INIT 1000
> > +#define LAPIC_TIMER_ADVANCE_NS_MAX 5000
>
> I think the old #define value is good. What about:
>
> -#define LAPIC_TIMER_ADVANCE_ADJUST_MIN 100
> -#define LAPIC_TIMER_ADVANCE_ADJUST_MAX 5000
> -#define LAPIC_TIMER_ADVANCE_ADJUST_INIT 1000
> +#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
Looks good, I guess you can update the patch during apply. :)
Wanpeng
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-09-26 10:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-26 0:54 [PATCH v2] KVM: LAPIC: Loose fluctuation filter for auto tune lapic_timer_advance_ns Wanpeng Li
2019-09-26 10:25 ` Paolo Bonzini
2019-09-26 10:34 ` Wanpeng Li
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.