Skip to contentSkip to conversation

regex/mlx5: add dynamic memory registration to datapath

PATCH Superseded Yuval Avnery 2 participants 5 messages Sep 24, 2020 – Oct 6, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 regex/mlx5: add dynamic memory registration to datapath

From: Yuval Avnery <[email protected]>

Currently job data is being copied to pre-registered buffer. To avoid memcpy on the datapath, use dynamic memory registration.

This change will reduce latency when sending regex jobs. The first few jobs may have high latency due to registration, but assuming all following mbufs will arrive from the same mempool/hugepage, there will be no further memory registration.

---
 drivers/regex/mlx5/mlx5_regex.c          | 13 ++++++++
 drivers/regex/mlx5/mlx5_regex.h          |  4 ++-
 drivers/regex/mlx5/mlx5_regex_control.c  | 16 ++++++++--
 drivers/regex/mlx5/mlx5_regex_fastpath.c | 55 +++++++++-----------------------
 4 files changed, 44 insertions(+), 44 deletions(-)
drivers/regex/mlx5/mlx5_regex.c +13 -0
index 605ebcf..7ecff1e 100644
@@ -109,6 +109,9 @@
 		pci_dev->addr.devid, pci_dev->addr.function);
 }
 
+void mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
+			   mlx5_dereg_mr_t *dereg_mr_cb);
+
 static int
 mlx5_regex_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 		     struct rte_pci_device *pci_dev)
@@ -194,6 +197,16 @@
 	priv->regexdev->device = (struct rte_device *)pci_dev;
 	priv->regexdev->data->dev_private = priv;
 	priv->regexdev->state = RTE_REGEXDEV_READY;
+	mlx5_os_set_reg_mr_cb(&priv->mr_scache.reg_mr_cb,
+			      &priv->mr_scache.dereg_mr_cb);
+	ret = mlx5_mr_btree_init(&priv->mr_scache.cache,
+				 MLX5_MR_BTREE_CACHE_N * 2,
+				 rte_socket_id());
+	if (ret) {
+		DRV_LOG(ERR, "MR init tree failed.");
+	    rte_errno = ENOMEM;
+		goto error;
+	}
 	return 0;
 
 error:
drivers/regex/mlx5/mlx5_regex.h +3 -1
index e1cdf80..9a7353d 100644
@@ -11,6 +11,7 @@
 #include <infiniband/mlx5dv.h>
 
 #include <mlx5_common.h>
+#include <mlx5_common_mr.h>
 
 #include "mlx5_rxp.h"
 
@@ -47,9 +48,9 @@ struct mlx5_regex_qp {
 	uint32_t free_sqs;
 	struct mlx5_regex_job *jobs;
 	struct ibv_mr *metadata;
-	struct ibv_mr *inputs;
 	struct ibv_mr *outputs;
 	size_t ci, pi;
+	struct mlx5_mr_ctrl mr_ctrl;
 };
 
 struct mlx5_regex_db {
@@ -78,6 +79,7 @@ struct mlx5_regex_priv {
 	struct mlx5dv_devx_uar *uar; /* UAR object. */
 	struct ibv_pd *pd;
 	struct mlx5_dbr_page_list dbrpgs; /* Door-bell pages. */
+	struct mlx5_mr_share_cache mr_scache; /* Global shared MR cache. */
 };
 
 /* mlx5_regex.c */
drivers/regex/mlx5/mlx5_regex_control.c +13 -3
index 187c3de..88b3d1a 100644
@@ -10,6 +10,7 @@
 #include <rte_regexdev.h>
 #include <rte_regexdev_core.h>
 #include <rte_regexdev_driver.h>
+#include <rte_dev.h>
 
 #include <mlx5_common.h>
 #include <mlx5_glue.h>
@@ -350,7 +351,7 @@
 			     qp->nb_obj * sizeof(struct mlx5_regex_sq), 64);
 	if (!qp->sqs) {
 		DRV_LOG(ERR, "Can't allocate sq array memory.");
-		rte_errno  = ENOMEM;
+		rte_errno = ENOMEM;
 		return -rte_errno;
 	}
 	log_desc = rte_log2_u32(qp->nb_desc / qp->nb_obj);
@@ -367,16 +368,25 @@
 		}
 	}
 
+	ret = mlx5_mr_btree_init(&qp->mr_ctrl.cache_bh, MLX5_MR_BTREE_CACHE_N,
+				 rte_socket_id());
+	if (ret) {
+		DRV_LOG(ERR, "Error setting up mr btree");
+		goto err_btree;
+	}
+
 	ret = mlx5_regexdev_setup_fastpath(priv, qp_ind);
 	if (ret) {
-		DRV_LOG(ERR, "Fail to setup fastpath.");
+		DRV_LOG(ERR, "Error setting up fastpath");
 		goto err_fp;
 	}
 	return 0;
 
 err_fp:
+	mlx5_mr_btree_free(&qp->mr_ctrl.cache_bh);
+err_btree:
 	for (i = 0; i < qp->nb_obj; i++)
-		ret = regex_ctrl_destroy_sq(priv, qp, i);
+		regex_ctrl_destroy_sq(priv, qp, i);
 err_sq:
 	regex_ctrl_destroy_cq(priv, &qp->cq);
 err_cq:
drivers/regex/mlx5/mlx5_regex_fastpath.c +15 -40

136 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw

Hi Yuval,

Quoted 5 lines

From: Yuval Avnery <[email protected]>

Currently job data is being copied to pre-registered buffer. To avoid memcpy on the datapath, use dynamic memory registration.

Quoted 7 lines

This change will reduce latency when sending regex jobs. The first few jobs may have high latency due to registration, but assuming all following mbufs will arrive from the same mempool/hugepage, there will be no further memory registration.

There is a compilation issue:

	drivers/regex/mlx5/mlx5_regex.c:200:
	undefined reference to `mlx5_os_set_reg_mr_cb'
#2 lore raw

Fixed in version 3
________________________________
From: Thomas Monjalon <[email protected]>
Sent: Sunday, October 4, 2020 10:38 PM
To: Yuval Avnery <[email protected]>
Cc: Ori Kam <[email protected]>; [email protected] <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v2] regex/mlx5: add dynamic memory registration to datapath

Hi Yuval,

Quoted 5 lines

From: Yuval Avnery <[email protected]>

Currently job data is being copied to pre-registered buffer. To avoid memcpy on the datapath, use dynamic memory registration.

Quoted 7 lines

This change will reduce latency when sending regex jobs. The first few jobs may have high latency due to registration, but assuming all following mbufs will arrive from the same mempool/hugepage, there will be no further memory registration.

There is a compilation issue:
drivers/regex/mlx5/mlx5_regex.c:200:
undefined reference to `mlx5_os_set_reg_mr_cb'

#3 lore raw

PATCH v3 1/1 regex/mlx5: add dynamic memory registration to datapath

In reply to Yuval Avnery

From: Yuval Avnery <[email protected]>

Currently job data is being copied to pre-registered buffer. To avoid memcpy on the datapath, use dynamic memory registration.

This change will reduce latency when sending regex jobs. The first few jobs may have high latency due to registration, but assuming all following mbufs will arrive from the same mempool/hugepage, there will be no further memory registration.

---
 drivers/regex/mlx5/mlx5_regex.c          | 10 ++++++
 drivers/regex/mlx5/mlx5_regex.h          |  4 ++-
 drivers/regex/mlx5/mlx5_regex_control.c  | 16 ++++++++--
 drivers/regex/mlx5/mlx5_regex_fastpath.c | 55 +++++++++-----------------------
 4 files changed, 41 insertions(+), 44 deletions(-)
drivers/regex/mlx5/mlx5_regex.c +10 -0
index 605ebcf..35e8ea0 100644
@@ -194,6 +194,16 @@
 	priv->regexdev->device = (struct rte_device *)pci_dev;
 	priv->regexdev->data->dev_private = priv;
 	priv->regexdev->state = RTE_REGEXDEV_READY;
+	priv->mr_scache.reg_mr_cb = mlx5_common_verbs_reg_mr;
+	priv->mr_scache.dereg_mr_cb = mlx5_common_verbs_dereg_mr;
+	ret = mlx5_mr_btree_init(&priv->mr_scache.cache,
+				 MLX5_MR_BTREE_CACHE_N * 2,
+				 rte_socket_id());
+	if (ret) {
+		DRV_LOG(ERR, "MR init tree failed.");
+	    rte_errno = ENOMEM;
+		goto error;
+	}
 	return 0;
 
 error:
drivers/regex/mlx5/mlx5_regex.h +3 -1
index e1cdf80..9a7353d 100644
@@ -11,6 +11,7 @@
 #include <infiniband/mlx5dv.h>
 
 #include <mlx5_common.h>
+#include <mlx5_common_mr.h>
 
 #include "mlx5_rxp.h"
 
@@ -47,9 +48,9 @@ struct mlx5_regex_qp {
 	uint32_t free_sqs;
 	struct mlx5_regex_job *jobs;
 	struct ibv_mr *metadata;
-	struct ibv_mr *inputs;
 	struct ibv_mr *outputs;
 	size_t ci, pi;
+	struct mlx5_mr_ctrl mr_ctrl;
 };
 
 struct mlx5_regex_db {
@@ -78,6 +79,7 @@ struct mlx5_regex_priv {
 	struct mlx5dv_devx_uar *uar; /* UAR object. */
 	struct ibv_pd *pd;
 	struct mlx5_dbr_page_list dbrpgs; /* Door-bell pages. */
+	struct mlx5_mr_share_cache mr_scache; /* Global shared MR cache. */
 };
 
 /* mlx5_regex.c */
drivers/regex/mlx5/mlx5_regex_control.c +13 -3
index 187c3de..88b3d1a 100644
@@ -10,6 +10,7 @@
 #include <rte_regexdev.h>
 #include <rte_regexdev_core.h>
 #include <rte_regexdev_driver.h>
+#include <rte_dev.h>
 
 #include <mlx5_common.h>
 #include <mlx5_glue.h>
@@ -350,7 +351,7 @@
 			     qp->nb_obj * sizeof(struct mlx5_regex_sq), 64);
 	if (!qp->sqs) {
 		DRV_LOG(ERR, "Can't allocate sq array memory.");
-		rte_errno  = ENOMEM;
+		rte_errno = ENOMEM;
 		return -rte_errno;
 	}
 	log_desc = rte_log2_u32(qp->nb_desc / qp->nb_obj);
@@ -367,16 +368,25 @@
 		}
 	}
 
+	ret = mlx5_mr_btree_init(&qp->mr_ctrl.cache_bh, MLX5_MR_BTREE_CACHE_N,
+				 rte_socket_id());
+	if (ret) {
+		DRV_LOG(ERR, "Error setting up mr btree");
+		goto err_btree;
+	}
+
 	ret = mlx5_regexdev_setup_fastpath(priv, qp_ind);
 	if (ret) {
-		DRV_LOG(ERR, "Fail to setup fastpath.");
+		DRV_LOG(ERR, "Error setting up fastpath");
 		goto err_fp;
 	}
 	return 0;
 
 err_fp:
+	mlx5_mr_btree_free(&qp->mr_ctrl.cache_bh);
+err_btree:
 	for (i = 0; i < qp->nb_obj; i++)
-		ret = regex_ctrl_destroy_sq(priv, qp, i);
+		regex_ctrl_destroy_sq(priv, qp, i);
 err_sq:
 	regex_ctrl_destroy_cq(priv, &qp->cq);
 err_cq:
drivers/regex/mlx5/mlx5_regex_fastpath.c +15 -40

136 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#4 lore raw
Quoted 5 lines

From: Yuval Avnery <[email protected]>

Currently job data is being copied to pre-registered buffer. To avoid memcpy on the datapath, use dynamic memory registration.

Quoted 7 lines

This change will reduce latency when sending regex jobs. The first few jobs may have high latency due to registration, but assuming all following mbufs will arrive from the same mempool/hugepage, there will be no further memory registration.

Applied, thanks