* KVM: VMX: optimize APIC EOI
@ 2010-06-14 22:30 Marcelo Tosatti
2010-06-15 4:33 ` Avi Kivity
0 siblings, 1 reply; 2+ messages in thread
From: Marcelo Tosatti @ 2010-06-14 22:30 UTC (permalink / raw)
To: Avi Kivity, Gleb Natapov; +Cc: kvm
Use information provided in exit_qualification to shortcut EOI path.
Reduces EOI latency from 4k to 2k cycles on Nehalem.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: kvm/arch/x86/kvm/lapic.c
===================================================================
--- kvm.orig/arch/x86/kvm/lapic.c
+++ kvm/arch/x86/kvm/lapic.c
@@ -1279,3 +1279,9 @@ int kvm_hv_vapic_msr_read(struct kvm_vcp
return 0;
}
+
+void kvm_lapic_set_eoi(struct kvm_vcpu *vcpu)
+{
+ apic_set_eoi(vcpu->arch.apic);
+}
+EXPORT_SYMBOL_GPL(kvm_lapic_set_eoi);
Index: kvm/arch/x86/kvm/lapic.h
===================================================================
--- kvm.orig/arch/x86/kvm/lapic.h
+++ kvm/arch/x86/kvm/lapic.h
@@ -52,6 +52,8 @@ int kvm_x2apic_msr_read(struct kvm_vcpu
int kvm_hv_vapic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data);
int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
+void kvm_lapic_set_eoi(struct kvm_vcpu *vcpu);
+
static inline bool kvm_hv_vapic_assist_page_enabled(struct kvm_vcpu *vcpu)
{
return vcpu->arch.hv_vapic & HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE;
Index: kvm/arch/x86/kvm/vmx.c
===================================================================
--- kvm.orig/arch/x86/kvm/vmx.c
+++ kvm/arch/x86/kvm/vmx.c
@@ -3395,6 +3395,17 @@ static int handle_wbinvd(struct kvm_vcpu
static int handle_apic_access(struct kvm_vcpu *vcpu)
{
+ unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
+ int access_type, offset;
+
+ access_type = (exit_qualification >> 12) & 0xf;
+ offset = exit_qualification & 0xfff;
+ if (access_type == 1 && offset == APIC_EOI) {
+ kvm_lapic_set_eoi(vcpu);
+ skip_emulated_instruction(vcpu);
+ return 1;
+ }
+
return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE;
}
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: KVM: VMX: optimize APIC EOI
2010-06-14 22:30 KVM: VMX: optimize APIC EOI Marcelo Tosatti
@ 2010-06-15 4:33 ` Avi Kivity
0 siblings, 0 replies; 2+ messages in thread
From: Avi Kivity @ 2010-06-15 4:33 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: Gleb Natapov, kvm
On 06/15/2010 01:30 AM, Marcelo Tosatti wrote:
> Use information provided in exit_qualification to shortcut EOI path.
>
> Reduces EOI latency from 4k to 2k cycles on Nehalem.
>
>
This already came up once - IIRC from Eddie Dong.
>
> static int handle_apic_access(struct kvm_vcpu *vcpu)
> {
> + unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
> + int access_type, offset;
> +
> + access_type = (exit_qualification>> 12)& 0xf;
> + offset = exit_qualification& 0xfff;
> + if (access_type == 1&& offset == APIC_EOI) {
> + kvm_lapic_set_eoi(vcpu);
> + skip_emulated_instruction(vcpu);
> + return 1;
> + }
> +
> return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE;
> }
>
>
This fails if the instruction is STOS, MOVS, or a RMW instruction as it
doesn't update registers and flags.
We could try to do tricks to detect this, but we already have x2apic for
Linux and the corresponding Hyper-V extension, which improve a lot of
other stuff, at least for newer guests.
\
--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-06-15 4:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-14 22:30 KVM: VMX: optimize APIC EOI Marcelo Tosatti
2010-06-15 4:33 ` Avi Kivity
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox