Skip to content

Commit 4d68562

Browse files
Yuxue Liumstsirkin
Yuxue Liu
authored andcommitted
vp_vdpa: don't allocate unused msix vectors
When there is a ctlq and it doesn't require interrupt callbacks,the original method of calculating vectors wastes hardware msi or msix resources as well as system IRQ resources. When conducting performance testing using testpmd in the guest os, it was found that the performance was lower compared to directly using vfio-pci to passthrough the device In scenarios where the virtio device in the guest os does not utilize interrupts, the vdpa driver still configures the hardware's msix vector. Therefore, the hardware still sends interrupts to the host os. Because of this unnecessary action by the hardware, hardware performance decreases, and it also affects the performance of the host os. Before modification:(interrupt mode) 32: 0 0 0 0 PCI-MSI 32768-edge vp-vdpa[0000:00:02.0]-0 33: 0 0 0 0 PCI-MSI 32769-edge vp-vdpa[0000:00:02.0]-1 34: 0 0 0 0 PCI-MSI 32770-edge vp-vdpa[0000:00:02.0]-2 35: 0 0 0 0 PCI-MSI 32771-edge vp-vdpa[0000:00:02.0]-config After modification:(interrupt mode) 32: 0 0 1 7 PCI-MSI 32768-edge vp-vdpa[0000:00:02.0]-0 33: 36 0 3 0 PCI-MSI 32769-edge vp-vdpa[0000:00:02.0]-1 34: 0 0 0 0 PCI-MSI 32770-edge vp-vdpa[0000:00:02.0]-config Before modification:(virtio pmd mode for guest os) 32: 0 0 0 0 PCI-MSI 32768-edge vp-vdpa[0000:00:02.0]-0 33: 0 0 0 0 PCI-MSI 32769-edge vp-vdpa[0000:00:02.0]-1 34: 0 0 0 0 PCI-MSI 32770-edge vp-vdpa[0000:00:02.0]-2 35: 0 0 0 0 PCI-MSI 32771-edge vp-vdpa[0000:00:02.0]-config After modification:(virtio pmd mode for guest os) 32: 0 0 0 0 PCI-MSI 32768-edge vp-vdpa[0000:00:02.0]-config To verify the use of the virtio PMD mode in the guest operating system, the following patch needs to be applied to QEMU: https://lore.kernel.org/all/[email protected] Signed-off-by: Yuxue Liu <[email protected]> Acked-by: Jason Wang <[email protected]> Reviewed-by: Heng Qi <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 1fa74f2 commit 4d68562

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

drivers/vdpa/virtio_pci/vp_vdpa.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,13 @@ static int vp_vdpa_request_irq(struct vp_vdpa *vp_vdpa)
160160
struct pci_dev *pdev = mdev->pci_dev;
161161
int i, ret, irq;
162162
int queues = vp_vdpa->queues;
163-
int vectors = queues + 1;
163+
int vectors = 1;
164+
int msix_vec = 0;
165+
166+
for (i = 0; i < queues; i++) {
167+
if (vp_vdpa->vring[i].cb.callback)
168+
vectors++;
169+
}
164170

165171
ret = pci_alloc_irq_vectors(pdev, vectors, vectors, PCI_IRQ_MSIX);
166172
if (ret != vectors) {
@@ -173,9 +179,12 @@ static int vp_vdpa_request_irq(struct vp_vdpa *vp_vdpa)
173179
vp_vdpa->vectors = vectors;
174180

175181
for (i = 0; i < queues; i++) {
182+
if (!vp_vdpa->vring[i].cb.callback)
183+
continue;
184+
176185
snprintf(vp_vdpa->vring[i].msix_name, VP_VDPA_NAME_SIZE,
177186
"vp-vdpa[%s]-%d\n", pci_name(pdev), i);
178-
irq = pci_irq_vector(pdev, i);
187+
irq = pci_irq_vector(pdev, msix_vec);
179188
ret = devm_request_irq(&pdev->dev, irq,
180189
vp_vdpa_vq_handler,
181190
0, vp_vdpa->vring[i].msix_name,
@@ -185,21 +194,22 @@ static int vp_vdpa_request_irq(struct vp_vdpa *vp_vdpa)
185194
"vp_vdpa: fail to request irq for vq %d\n", i);
186195
goto err;
187196
}
188-
vp_modern_queue_vector(mdev, i, i);
197+
vp_modern_queue_vector(mdev, i, msix_vec);
189198
vp_vdpa->vring[i].irq = irq;
199+
msix_vec++;
190200
}
191201

192202
snprintf(vp_vdpa->msix_name, VP_VDPA_NAME_SIZE, "vp-vdpa[%s]-config\n",
193203
pci_name(pdev));
194-
irq = pci_irq_vector(pdev, queues);
204+
irq = pci_irq_vector(pdev, msix_vec);
195205
ret = devm_request_irq(&pdev->dev, irq, vp_vdpa_config_handler, 0,
196206
vp_vdpa->msix_name, vp_vdpa);
197207
if (ret) {
198208
dev_err(&pdev->dev,
199-
"vp_vdpa: fail to request irq for vq %d\n", i);
209+
"vp_vdpa: fail to request irq for config: %d\n", ret);
200210
goto err;
201211
}
202-
vp_modern_config_vector(mdev, queues);
212+
vp_modern_config_vector(mdev, msix_vec);
203213
vp_vdpa->config_irq = irq;
204214

205215
return 0;

0 commit comments

Comments
 (0)