vdpa/mlx5: move virtual doorbell alloc to probe
authorMatan Azrad <matan@mellanox.com>
Tue, 24 Mar 2020 14:24:34 +0000 (14:24 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 21 Apr 2020 11:57:08 +0000 (13:57 +0200)
The configure and close operations may be called a lot of time by vhost
library according to the virtio connections in the guest.

VAR is the device memory space for the virtio queues doorbells.
Each VAR page can be shared for more than one queue while its owner must
synchronize the writes to it.

The mlx5 driver allocates single VAR page for all its queues.

Therefore, it is better to allocate it in probe device level instead of
creating and destroying it per new connection.

Signed-off-by: Matan Azrad <matan@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
drivers/vdpa/mlx5/mlx5_vdpa.c
drivers/vdpa/mlx5/mlx5_vdpa_virtq.c

index 0a9f31a..0991e5a 100644 (file)
@@ -447,6 +447,11 @@ mlx5_vdpa_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
        priv->ctx = ctx;
        priv->dev_addr.pci_addr = pci_dev->addr;
        priv->dev_addr.type = VDPA_ADDR_PCI;
+       priv->var = mlx5_glue->dv_alloc_var(ctx, 0);
+       if (!priv->var) {
+               DRV_LOG(ERR, "Failed to allocate VAR %u.\n", errno);
+               goto error;
+       }
        priv->id = rte_vdpa_register_device(&priv->dev_addr, &mlx5_vdpa_ops);
        if (priv->id < 0) {
                DRV_LOG(ERR, "Failed to register vDPA device.");
@@ -461,8 +466,11 @@ mlx5_vdpa_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
        return 0;
 
 error:
-       if (priv)
+       if (priv) {
+               if (priv->var)
+                       mlx5_glue->dv_free_var(priv->var);
                rte_free(priv);
+       }
        if (ctx)
                mlx5_glue->close_device(ctx);
        return -rte_errno;
@@ -499,6 +507,10 @@ mlx5_vdpa_pci_remove(struct rte_pci_device *pci_dev)
        if (found) {
                if (priv->configured)
                        mlx5_vdpa_dev_close(priv->vid);
+               if (priv->var) {
+                       mlx5_glue->dv_free_var(priv->var);
+                       priv->var = NULL;
+               }
                mlx5_glue->close_device(priv->ctx);
                rte_free(priv);
        }
index cb2d61b..dd37016 100644 (file)
@@ -105,10 +105,6 @@ mlx5_vdpa_virtqs_release(struct mlx5_vdpa_priv *priv)
                claim_zero(munmap(priv->virtq_db_addr, priv->var->length));
                priv->virtq_db_addr = NULL;
        }
-       if (priv->var) {
-               mlx5_glue->dv_free_var(priv->var);
-               priv->var = NULL;
-       }
        priv->features = 0;
 }
 
@@ -350,11 +346,6 @@ mlx5_vdpa_virtqs_prepare(struct mlx5_vdpa_priv *priv)
                DRV_LOG(ERR, "Failed to configure negotiated features.");
                return -1;
        }
-       priv->var = mlx5_glue->dv_alloc_var(priv->ctx, 0);
-       if (!priv->var) {
-               DRV_LOG(ERR, "Failed to allocate VAR %u.\n", errno);
-               return -1;
-       }
        /* Always map the entire page. */
        priv->virtq_db_addr = mmap(NULL, priv->var->length, PROT_READ |
                                   PROT_WRITE, MAP_SHARED, priv->ctx->cmd_fd,