Skip to content
  • Longpeng (Mike)'s avatar
    dc580d51
    vfio: defer to commit kvm irq routing when enable msi/msix · dc580d51
    Longpeng (Mike) authored
    
    
    In migration resume phase, all unmasked msix vectors need to be
    setup when loading the VF state. However, the setup operation would
    take longer if the VM has more VFs and each VF has more unmasked
    vectors.
    
    The hot spot is kvm_irqchip_commit_routes, it'll scan and update
    all irqfds that are already assigned each invocation, so more
    vectors means need more time to process them.
    
    vfio_pci_load_config
      vfio_msix_enable
        msix_set_vector_notifiers
          for (vector = 0; vector < dev->msix_entries_nr; vector++) {
            vfio_msix_vector_do_use
              vfio_add_kvm_msi_virq
                kvm_irqchip_commit_routes <-- expensive
          }
    
    We can reduce the cost by only committing once outside the loop.
    The routes are cached in kvm_state, we commit them first and then
    bind irqfd for each vector.
    
    The test VM has 128 vcpus and 8 VF (each one has 65 vectors),
    we measure the cost of the vfio_msix_enable for each VF, and
    we can see 90+% costs can be reduce.
    
    VF      Count of irqfds[*]  Original        With this patch
    
    1st           65            8               2
    2nd           130           15              2
    3rd           195           22              2
    4th           260           24              3
    5th           325           36              2
    6th           390           44              3
    7th           455           51              3
    8th           520           58              4
    Total                       258ms           21ms
    
    [*] Count of irqfds
    How many irqfds that already assigned and need to process in this
    round.
    
    The optimization can be applied to msi type too.
    
    Signed-off-by: default avatarLongpeng(Mike) <longpeng2@huawei.com>
    Link: https://lore.kernel.org/r/20220326060226.1892-6-longpeng2@huawei.com
    
    
    Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
    dc580d51
    vfio: defer to commit kvm irq routing when enable msi/msix
    Longpeng (Mike) authored
    
    
    In migration resume phase, all unmasked msix vectors need to be
    setup when loading the VF state. However, the setup operation would
    take longer if the VM has more VFs and each VF has more unmasked
    vectors.
    
    The hot spot is kvm_irqchip_commit_routes, it'll scan and update
    all irqfds that are already assigned each invocation, so more
    vectors means need more time to process them.
    
    vfio_pci_load_config
      vfio_msix_enable
        msix_set_vector_notifiers
          for (vector = 0; vector < dev->msix_entries_nr; vector++) {
            vfio_msix_vector_do_use
              vfio_add_kvm_msi_virq
                kvm_irqchip_commit_routes <-- expensive
          }
    
    We can reduce the cost by only committing once outside the loop.
    The routes are cached in kvm_state, we commit them first and then
    bind irqfd for each vector.
    
    The test VM has 128 vcpus and 8 VF (each one has 65 vectors),
    we measure the cost of the vfio_msix_enable for each VF, and
    we can see 90+% costs can be reduce.
    
    VF      Count of irqfds[*]  Original        With this patch
    
    1st           65            8               2
    2nd           130           15              2
    3rd           195           22              2
    4th           260           24              3
    5th           325           36              2
    6th           390           44              3
    7th           455           51              3
    8th           520           58              4
    Total                       258ms           21ms
    
    [*] Count of irqfds
    How many irqfds that already assigned and need to process in this
    round.
    
    The optimization can be applied to msi type too.
    
    Signed-off-by: default avatarLongpeng(Mike) <longpeng2@huawei.com>
    Link: https://lore.kernel.org/r/20220326060226.1892-6-longpeng2@huawei.com
    
    
    Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
Loading