diff mbox series

[vhost,v2,09/10] vdpa/mlx5: Small improvement for change_num_qps()

Message ID 20240816090159.1967650-10-dtatulea@nvidia.com (mailing list archive)
State New, archived
Headers show
Series vdpa/mlx5: Parallelize device suspend/resume | expand

Commit Message

Dragos Tatulea Aug. 16, 2024, 9:01 a.m. UTC
change_num_qps() has a lot of multiplications by 2 to convert
the number of VQ pairs to number of VQs. This patch simplifies
the code by doing the VQP -> VQ count conversion at the beginning
in a variable.

Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

Comments

Eugenio Perez Martin Aug. 28, 2024, 12:48 p.m. UTC | #1
On Fri, Aug 16, 2024 at 11:03 AM Dragos Tatulea <dtatulea@nvidia.com> wrote:
>
> change_num_qps() has a lot of multiplications by 2 to convert
> the number of VQ pairs to number of VQs. This patch simplifies
> the code by doing the VQP -> VQ count conversion at the beginning
> in a variable.
>
> Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
> Reviewed-by: Tariq Toukan <tariqt@nvidia.com>

Acked-by: Eugenio Pérez <eperezma@redhat.com>

> ---
>  drivers/vdpa/mlx5/net/mlx5_vnet.c | 21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 65063c507130..d1a01c229110 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -2219,16 +2219,17 @@ static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
>  static int change_num_qps(struct mlx5_vdpa_dev *mvdev, int newqps)
>  {
>         struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
> -       int cur_qps = ndev->cur_num_vqs / 2;
> +       int cur_vqs = ndev->cur_num_vqs;
> +       int new_vqs = newqps * 2;
>         int err;
>         int i;
>
> -       if (cur_qps > newqps) {
> -               err = modify_rqt(ndev, 2 * newqps);
> +       if (cur_vqs > new_vqs) {
> +               err = modify_rqt(ndev, new_vqs);
>                 if (err)
>                         return err;
>
> -               for (i = ndev->cur_num_vqs - 1; i >= 2 * newqps; i--) {
> +               for (i = cur_vqs - 1; i >= new_vqs; i--) {
>                         struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[i];
>
>                         if (is_resumable(ndev))
> @@ -2237,27 +2238,27 @@ static int change_num_qps(struct mlx5_vdpa_dev *mvdev, int newqps)
>                                 teardown_vq(ndev, mvq);
>                 }
>
> -               ndev->cur_num_vqs = 2 * newqps;
> +               ndev->cur_num_vqs = new_vqs;
>         } else {
> -               ndev->cur_num_vqs = 2 * newqps;
> -               for (i = cur_qps * 2; i < 2 * newqps; i++) {
> +               ndev->cur_num_vqs = new_vqs;
> +               for (i = cur_vqs; i < new_vqs; i++) {
>                         struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[i];
>
>                         err = mvq->initialized ? resume_vq(ndev, mvq) : setup_vq(ndev, mvq, true);
>                         if (err)
>                                 goto clean_added;
>                 }
> -               err = modify_rqt(ndev, 2 * newqps);
> +               err = modify_rqt(ndev, new_vqs);
>                 if (err)
>                         goto clean_added;
>         }
>         return 0;
>
>  clean_added:
> -       for (--i; i >= 2 * cur_qps; --i)
> +       for (--i; i >= cur_vqs; --i)
>                 teardown_vq(ndev, &ndev->vqs[i]);
>
> -       ndev->cur_num_vqs = 2 * cur_qps;
> +       ndev->cur_num_vqs = cur_vqs;
>
>         return err;
>  }
> --
> 2.45.1
>
diff mbox series

Patch

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 65063c507130..d1a01c229110 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -2219,16 +2219,17 @@  static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
 static int change_num_qps(struct mlx5_vdpa_dev *mvdev, int newqps)
 {
 	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-	int cur_qps = ndev->cur_num_vqs / 2;
+	int cur_vqs = ndev->cur_num_vqs;
+	int new_vqs = newqps * 2;
 	int err;
 	int i;
 
-	if (cur_qps > newqps) {
-		err = modify_rqt(ndev, 2 * newqps);
+	if (cur_vqs > new_vqs) {
+		err = modify_rqt(ndev, new_vqs);
 		if (err)
 			return err;
 
-		for (i = ndev->cur_num_vqs - 1; i >= 2 * newqps; i--) {
+		for (i = cur_vqs - 1; i >= new_vqs; i--) {
 			struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[i];
 
 			if (is_resumable(ndev))
@@ -2237,27 +2238,27 @@  static int change_num_qps(struct mlx5_vdpa_dev *mvdev, int newqps)
 				teardown_vq(ndev, mvq);
 		}
 
-		ndev->cur_num_vqs = 2 * newqps;
+		ndev->cur_num_vqs = new_vqs;
 	} else {
-		ndev->cur_num_vqs = 2 * newqps;
-		for (i = cur_qps * 2; i < 2 * newqps; i++) {
+		ndev->cur_num_vqs = new_vqs;
+		for (i = cur_vqs; i < new_vqs; i++) {
 			struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[i];
 
 			err = mvq->initialized ? resume_vq(ndev, mvq) : setup_vq(ndev, mvq, true);
 			if (err)
 				goto clean_added;
 		}
-		err = modify_rqt(ndev, 2 * newqps);
+		err = modify_rqt(ndev, new_vqs);
 		if (err)
 			goto clean_added;
 	}
 	return 0;
 
 clean_added:
-	for (--i; i >= 2 * cur_qps; --i)
+	for (--i; i >= cur_vqs; --i)
 		teardown_vq(ndev, &ndev->vqs[i]);
 
-	ndev->cur_num_vqs = 2 * cur_qps;
+	ndev->cur_num_vqs = cur_vqs;
 
 	return err;
 }