• Michael S. Tsirkin's avatar
    KVM guest: guest side for eoi avoidance · ab9cf499
    Michael S. Tsirkin authored
    The idea is simple: there's a bit, per APIC, in guest memory,
    that tells the guest that it does not need EOI.
    Guest tests it using a single est and clear operation - this is
    necessary so that host can detect interrupt nesting - and if set, it can
    skip the EOI MSR.
    
    I run a simple microbenchmark to show exit reduction
    (note: for testing, need to apply follow-up patch
    'kvm: host side for eoi optimization' + a qemu patch
     I posted separately, on host):
    
    Before:
    
    Performance counter stats for 'sleep 1s':
    
                47,357 kvm:kvm_entry                                                [99.98%]
                     0 kvm:kvm_hypercall                                            [99.98%]
                     0 kvm:kvm_hv_hypercall                                         [99.98%]
                 5,001 kvm:kvm_pio                                                  [99.98%]
                     0 kvm:kvm_cpuid                                                [99.98%]
                22,124 kvm:kvm_apic                                                 [99.98%]
                49,849 kvm:kvm_exit                                                 [99.98%]
                21,115 kvm:kvm_inj_virq                                             [99.98%]
                     0 kvm:kvm_inj_exception                                        [99.98%]
                     0 kvm:kvm_page_fault                                           [99.98%]
                22,937 kvm:kvm_msr                                                  [99.98%]
                     0 kvm:kvm_cr                                                   [99.98%]
                     0 kvm:kvm_pic_set_irq                                          [99.98%]
                     0 kvm:kvm_apic_ipi                                             [99.98%]
                22,207 kvm:kvm_apic_accept_irq                                      [99.98%]
                22,421 kvm:kvm_eoi                                                  [99.98%]
                     0 kvm:kvm_pv_eoi                                               [99.99%]
                     0 kvm:kvm_nested_vmrun                                         [99.99%]
                     0 kvm:kvm_nested_intercepts                                    [99.99%]
                     0 kvm:kvm_nested_vmexit                                        [99.99%]
                     0 kvm:kvm_nested_vmexit_inject                                    [99.99%]
                     0 kvm:kvm_nested_intr_vmexit                                    [99.99%]
                     0 kvm:kvm_invlpga                                              [99.99%]
                     0 kvm:kvm_skinit                                               [99.99%]
                    57 kvm:kvm_emulate_insn                                         [99.99%]
                     0 kvm:vcpu_match_mmio                                          [99.99%]
                     0 kvm:kvm_userspace_exit                                       [99.99%]
                     2 kvm:kvm_set_irq                                              [99.99%]
                     2 kvm:kvm_ioapic_set_irq                                       [99.99%]
                23,609 kvm:kvm_msi_set_irq                                          [99.99%]
                     1 kvm:kvm_ack_irq                                              [99.99%]
                   131 kvm:kvm_mmio                                                 [99.99%]
                   226 kvm:kvm_fpu                                                  [100.00%]
                     0 kvm:kvm_age_page                                             [100.00%]
                     0 kvm:kvm_try_async_get_page                                    [100.00%]
                     0 kvm:kvm_async_pf_doublefault                                    [100.00%]
                     0 kvm:kvm_async_pf_not_present                                    [100.00%]
                     0 kvm:kvm_async_pf_ready                                       [100.00%]
                     0 kvm:kvm_async_pf_completed
    
           1.002100578 seconds time elapsed
    
    After:
    
     Performance counter stats for 'sleep 1s':
    
                28,354 kvm:kvm_entry                                                [99.98%]
                     0 kvm:kvm_hypercall                                            [99.98%]
                     0 kvm:kvm_hv_hypercall                                         [99.98%]
                 1,347 kvm:kvm_pio                                                  [99.98%]
                     0 kvm:kvm_cpuid                                                [99.98%]
                 1,931 kvm:kvm_apic                                                 [99.98%]
                29,595 kvm:kvm_exit                                                 [99.98%]
                24,884 kvm:kvm_inj_virq                                             [99.98%]
                     0 kvm:kvm_inj_exception                                        [99.98%]
                     0 kvm:kvm_page_fault                                           [99.98%]
                 1,986 kvm:kvm_msr                                                  [99.98%]
                     0 kvm:kvm_cr                                                   [99.98%]
                     0 kvm:kvm_pic_set_irq                                          [99.98%]
                     0 kvm:kvm_apic_ipi                                             [99.99%]
                25,953 kvm:kvm_apic_accept_irq                                      [99.99%]
                26,132 kvm:kvm_eoi                                                  [99.99%]
                26,593 kvm:kvm_pv_eoi                                               [99.99%]
                     0 kvm:kvm_nested_vmrun                                         [99.99%]
                     0 kvm:kvm_nested_intercepts                                    [99.99%]
                     0 kvm:kvm_nested_vmexit                                        [99.99%]
                     0 kvm:kvm_nested_vmexit_inject                                    [99.99%]
                     0 kvm:kvm_nested_intr_vmexit                                    [99.99%]
                     0 kvm:kvm_invlpga                                              [99.99%]
                     0 kvm:kvm_skinit                                               [99.99%]
                   284 kvm:kvm_emulate_insn                                         [99.99%]
                    68 kvm:vcpu_match_mmio                                          [99.99%]
                    68 kvm:kvm_userspace_exit                                       [99.99%]
                     2 kvm:kvm_set_irq                                              [99.99%]
                     2 kvm:kvm_ioapic_set_irq                                       [99.99%]
                28,288 kvm:kvm_msi_set_irq                                          [99.99%]
                     1 kvm:kvm_ack_irq                                              [99.99%]
                   131 kvm:kvm_mmio                                                 [100.00%]
                   588 kvm:kvm_fpu                                                  [100.00%]
                     0 kvm:kvm_age_page                                             [100.00%]
                     0 kvm:kvm_try_async_get_page                                    [100.00%]
                     0 kvm:kvm_async_pf_doublefault                                    [100.00%]
                     0 kvm:kvm_async_pf_not_present                                    [100.00%]
                     0 kvm:kvm_async_pf_ready                                       [100.00%]
                     0 kvm:kvm_async_pf_completed
    
           1.002039622 seconds time elapsed
    
    We see that # of exits is almost halved.
    Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
    Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
    ab9cf499
kvm_para.h 5.68 KB