All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vp_vdpa: fix the method of calculating vectors
@ 2024-03-18  3:01 gavin.liu
  2024-03-18  4:06 ` Jason Wang
  0 siblings, 1 reply; 2+ messages in thread
From: gavin.liu @ 2024-03-18  3:01 UTC (permalink / raw)
  To: jasowang, mst; +Cc: xuanzhuo, virtualization, angus.chen, yuxue.liu

From: Yuxue Liu <yuxue.liu@jaguarmicro.com>

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 <yuxue.liu@jaguarmicro.com>
---
 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++) {
 		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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] vp_vdpa: fix the method of calculating vectors
  2024-03-18  3:01 [PATCH] vp_vdpa: fix the method of calculating vectors gavin.liu
@ 2024-03-18  4:06 ` Jason Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Wang @ 2024-03-18  4:06 UTC (permalink / raw)
  To: gavin.liu; +Cc: mst, xuanzhuo, virtualization, angus.chen, yuxue.liu

On Mon, Mar 18, 2024 at 11:01 AM gavin.liu <gavin.liu@jaguarmicro.com> wrote:
>
> From: Yuxue Liu <yuxue.liu@jaguarmicro.com>
>
> 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 <yuxue.liu@jaguarmicro.com>
> ---
>  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
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-18  4:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-18  3:01 [PATCH] vp_vdpa: fix the method of calculating vectors gavin.liu
2024-03-18  4:06 ` Jason Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.