On Mon, Mar 18, 2024 at 11:01 AM gavin.liu <[email protected]> wrote:
>
> From: Yuxue Liu <[email protected]>
>
> When there is a ctlq and it doesn't require interrupt
> callbacks,the original method of calculating vectors
> wastes hardware MSI or MSI-X resources as well as system
> IRQ resources. Referencing the per_vq_vectors mode in the
> vp_find_vqs_msix function, calculate the required number
> of vectors based on whether the callback is set.
>
> Signed-off-by: Yuxue Liu <[email protected]>
> ---
> drivers/vdpa/virtio_pci/vp_vdpa.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c
> b/drivers/vdpa/virtio_pci/vp_vdpa.c
> index 281287fae89f..5066970b2570 100644
> --- a/drivers/vdpa/virtio_pci/vp_vdpa.c
> +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
> @@ -160,7 +160,13 @@ static int vp_vdpa_request_irq(struct vp_vdpa *vp_vdpa)
> struct pci_dev *pdev = mdev->pci_dev;
> int i, ret, irq;
> int queues = vp_vdpa->queues;
> - int vectors = queues + 1;
> + int vectors = 0;
> +
> + for (i = 0; i < queues; i++) {
> + if (vp_vdpa->vring[i].cb.callback != NULL)
> + vectors++;
> + }
> + vectors = vectors + 1;
>
> ret = pci_alloc_irq_vectors(pdev, vectors, vectors, PCI_IRQ_MSIX);
> if (ret != vectors) {
> @@ -172,7 +178,7 @@ static int vp_vdpa_request_irq(struct vp_vdpa *vp_vdpa)
>
> vp_vdpa->vectors = vectors;
>
> - for (i = 0; i < queues; i++) {
> + for (i = 0; i < vectors - 1; i++) {
This seems to be buggy. You didn't scan all queues so you will miss
the IRQ for the last queue.
Thanks
> snprintf(vp_vdpa->vring[i].msix_name, VP_VDPA_NAME_SIZE,
> "vp-vdpa[%s]-%d\n", pci_name(pdev), i);
> irq = pci_irq_vector(pdev, i);
> @@ -191,7 +197,7 @@ static int vp_vdpa_request_irq(struct vp_vdpa *vp_vdpa)
>
> snprintf(vp_vdpa->msix_name, VP_VDPA_NAME_SIZE,
> "vp-vdpa[%s]-config\n",
> pci_name(pdev));
> - irq = pci_irq_vector(pdev, queues);
> + irq = pci_irq_vector(pdev, vectors - 1);
> ret = devm_request_irq(&pdev->dev, irq, vp_vdpa_config_handler, 0,
> vp_vdpa->msix_name, vp_vdpa);
> if (ret) {
> @@ -199,7 +205,7 @@ static int vp_vdpa_request_irq(struct vp_vdpa *vp_vdpa)
> "vp_vdpa: fail to request irq for vq %d\n", i);
> goto err;
> }
> - vp_modern_config_vector(mdev, queues);
> + vp_modern_config_vector(mdev, vectors - 1);
> vp_vdpa->config_irq = irq;
>
> return 0;
> --
> 2.43.0
>