]> git.droids-corp.org - dpdk.git/commitdiff
common/mlx5: add global MR cache create function
authorMichael Baum <michaelba@nvidia.com>
Tue, 19 Oct 2021 20:55:58 +0000 (23:55 +0300)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 21 Oct 2021 13:57:24 +0000 (15:57 +0200)
Add function for global shared MR cache structure initialization.
This function include:
 - btree initialization.
 - set callbacks for reg and dereg MR.

Signed-off-by: Michael Baum <michaelba@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
15 files changed:
drivers/common/mlx5/linux/mlx5_common_verbs.c
drivers/common/mlx5/mlx5_common_mr.c
drivers/common/mlx5/mlx5_common_mr.h
drivers/common/mlx5/version.map
drivers/common/mlx5/windows/mlx5_common_os.c
drivers/common/mlx5/windows/mlx5_common_os.h
drivers/compress/mlx5/mlx5_compress.c
drivers/crypto/mlx5/mlx5_crypto.c
drivers/net/mlx5/linux/mlx5_os.c
drivers/net/mlx5/linux/mlx5_verbs.c
drivers/net/mlx5/linux/mlx5_verbs.h
drivers/net/mlx5/mlx5.c
drivers/net/mlx5/mlx5.h
drivers/net/mlx5/windows/mlx5_os.c
drivers/regex/mlx5/mlx5_regex.c

index 519cb8d056aa114c69a7ce300d237d66ecf363df..cf2f7ecbf31a04861d76d3336cbb13e34c86e3ca 100644 (file)
@@ -142,3 +142,18 @@ mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
                memset(pmd_mr, 0, sizeof(*pmd_mr));
        }
 }
+
+/**
+ * Set the reg_mr and dereg_mr callbacks.
+ *
+ * @param[out] reg_mr_cb
+ *   Pointer to reg_mr func
+ * @param[out] dereg_mr_cb
+ *   Pointer to dereg_mr func
+ */
+void
+mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, mlx5_dereg_mr_t *dereg_mr_cb)
+{
+       *reg_mr_cb = mlx5_common_verbs_reg_mr;
+       *dereg_mr_cb = mlx5_common_verbs_dereg_mr;
+}
index b4f2b81b1b4cfc319973fa29165dc01f2dbc0fd1..8e05a47eed6ea02304f1338e7fe93c823bfce972 100644 (file)
@@ -199,7 +199,7 @@ mr_btree_insert(struct mlx5_mr_btree *bt, struct mr_cache_entry *entry)
  * @return
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
-int
+static int
 mlx5_mr_btree_init(struct mlx5_mr_btree *bt, int n, int socket)
 {
        if (bt == NULL) {
@@ -1044,6 +1044,29 @@ mlx5_mr_release_cache(struct mlx5_mr_share_cache *share_cache)
        mlx5_mr_garbage_collect(share_cache);
 }
 
+/**
+ * Initialize global MR cache of a device.
+ *
+ * @param share_cache
+ *   Pointer to a global shared MR cache.
+ * @param socket
+ *   NUMA socket on which memory must be allocated.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_mr_create_cache(struct mlx5_mr_share_cache *share_cache, int socket)
+{
+       /* Set the reg_mr and dereg_mr callback functions */
+       mlx5_os_set_reg_mr_cb(&share_cache->reg_mr_cb,
+                             &share_cache->dereg_mr_cb);
+       rte_rwlock_init(&share_cache->rwlock);
+       /* Initialize B-tree and allocate memory for global MR cache table. */
+       return mlx5_mr_btree_init(&share_cache->cache,
+                                 MLX5_MR_BTREE_CACHE_N * 2, socket);
+}
+
 /**
  * Flush all of the local cache entries.
  *
index 1392d9b55a068d5dc5f4f6e29341ae77044d451b..36689dfb546b30ca0677c2e0669c09da060ba19d 100644 (file)
@@ -128,8 +128,6 @@ __rte_internal
 int mlx5_mr_ctrl_init(struct mlx5_mr_ctrl *mr_ctrl, uint32_t *dev_gen_ptr,
                      int socket);
 __rte_internal
-int mlx5_mr_btree_init(struct mlx5_mr_btree *bt, int n, int socket);
-__rte_internal
 void mlx5_mr_btree_free(struct mlx5_mr_btree *bt);
 __rte_internal
 void mlx5_mr_btree_dump(struct mlx5_mr_btree *bt __rte_unused);
@@ -145,6 +143,8 @@ uint32_t mlx5_mr_mempool2mr_bh(struct mlx5_mr_share_cache *share_cache,
 __rte_internal
 void mlx5_mr_release_cache(struct mlx5_mr_share_cache *mr_cache);
 __rte_internal
+int mlx5_mr_create_cache(struct mlx5_mr_share_cache *share_cache, int socket);
+__rte_internal
 void mlx5_mr_dump_cache(struct mlx5_mr_share_cache *share_cache __rte_unused);
 __rte_internal
 void mlx5_mr_rebuild_cache(struct mlx5_mr_share_cache *share_cache);
@@ -183,6 +183,10 @@ __rte_internal
 void
 mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);
 
+__rte_internal
+void
+mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, mlx5_dereg_mr_t *dereg_mr_cb);
+
 __rte_internal
 void
 mlx5_mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb);
index 04a494dc67f8fe5535910a6974816e240a2e37f8..89c99c772e81265f14bc8775e29f5f5b74147a53 100644 (file)
@@ -109,7 +109,7 @@ INTERNAL {
        mlx5_mr_addr2mr_bh;
        mlx5_mr_btree_dump;
        mlx5_mr_btree_free;
-       mlx5_mr_btree_init;
+       mlx5_mr_create_cache;
        mlx5_mr_create_primary;
        mlx5_mr_ctrl_init;
        mlx5_mr_dump_cache;
@@ -136,10 +136,9 @@ INTERNAL {
        mlx5_nl_vlan_vmwa_create; # WINDOWS_NO_EXPORT
        mlx5_nl_vlan_vmwa_delete; # WINDOWS_NO_EXPORT
 
-       mlx5_os_dereg_mr;
-       mlx5_os_reg_mr;
        mlx5_os_umem_dereg;
        mlx5_os_umem_reg;
+       mlx5_os_set_reg_mr_cb;
 
        mlx5_realloc;
 
index 4d0f1e92e365c81e92e6f9a30d8ca1ed060af04c..44e8ebec2b3ff0c00511dc0e7350534223b1791c 100644 (file)
@@ -317,7 +317,7 @@ mlx5_os_umem_dereg(void *pumem)
  * @return
  *   0 on successful registration, -1 otherwise
  */
-int
+static int
 mlx5_os_reg_mr(void *pd,
               void *addr, size_t length, struct mlx5_pmd_mr *pmd_mr)
 {
@@ -365,7 +365,7 @@ mlx5_os_reg_mr(void *pd,
  * @param[in] pmd_mr
  *  Pointer to PMD mr object
  */
-void
+static void
 mlx5_os_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
 {
        if (pmd_mr && pmd_mr->mkey)
@@ -374,3 +374,19 @@ mlx5_os_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
                claim_zero(mlx5_os_umem_dereg(pmd_mr->obj));
        memset(pmd_mr, 0, sizeof(*pmd_mr));
 }
+
+/**
+ * Set the reg_mr and dereg_mr callbacks.
+ *
+ * @param[out] reg_mr_cb
+ *   Pointer to reg_mr func
+ * @param[out] dereg_mr_cb
+ *   Pointer to dereg_mr func
+ *
+ */
+void
+mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, mlx5_dereg_mr_t *dereg_mr_cb)
+{
+       *reg_mr_cb = mlx5_os_reg_mr;
+       *dereg_mr_cb = mlx5_os_dereg_mr;
+}
index c99645aefdcfb9e9cdaad15aea4ef6c4c92198c6..3afce56cd90b550c3b9e644be7cfe31649a4c6d8 100644 (file)
@@ -253,9 +253,5 @@ __rte_internal
 void *mlx5_os_umem_reg(void *ctx, void *addr, size_t size, uint32_t access);
 __rte_internal
 int mlx5_os_umem_dereg(void *pumem);
-__rte_internal
-int mlx5_os_reg_mr(void *pd,
-                  void *addr, size_t length, struct mlx5_pmd_mr *pmd_mr);
-__rte_internal
-void mlx5_os_dereg_mr(struct mlx5_pmd_mr *pmd_mr);
+
 #endif /* RTE_PMD_MLX5_COMMON_OS_H_ */
index 66b80a46c3c59f72a12ddb2120218506c250be73..c36db0c062a93b98128c06ca22baaf56c8c32655 100644 (file)
@@ -799,16 +799,13 @@ mlx5_compress_dev_probe(struct mlx5_common_device *cdev)
                rte_compressdev_pmd_destroy(priv->compressdev);
                return -1;
        }
-       if (mlx5_mr_btree_init(&priv->mr_scache.cache,
-                            MLX5_MR_BTREE_CACHE_N * 2, rte_socket_id()) != 0) {
+       if (mlx5_mr_create_cache(&priv->mr_scache, rte_socket_id()) != 0) {
                DRV_LOG(ERR, "Failed to allocate shared cache MR memory.");
                mlx5_compress_uar_release(priv);
                rte_compressdev_pmd_destroy(priv->compressdev);
                rte_errno = ENOMEM;
                return -rte_errno;
        }
-       priv->mr_scache.reg_mr_cb = mlx5_common_verbs_reg_mr;
-       priv->mr_scache.dereg_mr_cb = mlx5_common_verbs_dereg_mr;
        /* Register callback function for global shared MR cache management. */
        if (TAILQ_EMPTY(&mlx5_compress_priv_list))
                rte_mem_event_callback_register("MLX5_MEM_EVENT_CB",
index 77f0688ba090d681d3314f5a267e59a707cf9789..6cf6889d215c1fdf0595f891fb356bdbc5373e73 100644 (file)
@@ -974,16 +974,13 @@ mlx5_crypto_dev_probe(struct mlx5_common_device *cdev)
                rte_cryptodev_pmd_destroy(priv->crypto_dev);
                return -1;
        }
-       if (mlx5_mr_btree_init(&priv->mr_scache.cache,
-                            MLX5_MR_BTREE_CACHE_N * 2, rte_socket_id()) != 0) {
+       if (mlx5_mr_create_cache(&priv->mr_scache, rte_socket_id()) != 0) {
                DRV_LOG(ERR, "Failed to allocate shared cache MR memory.");
                mlx5_crypto_uar_release(priv);
                rte_cryptodev_pmd_destroy(priv->crypto_dev);
                rte_errno = ENOMEM;
                return -rte_errno;
        }
-       priv->mr_scache.reg_mr_cb = mlx5_common_verbs_reg_mr;
-       priv->mr_scache.dereg_mr_cb = mlx5_common_verbs_dereg_mr;
        priv->keytag = rte_cpu_to_be_64(devarg_prms.keytag);
        priv->max_segs_num = devarg_prms.max_segs_num;
        priv->umr_wqe_size = sizeof(struct mlx5_wqe_umr_bsf_seg) +
index 6ee0257d338b5b760fa0acd0bd52b17ab928964b..7bed7da7bfb92c431d6c8e9b0cd9c6b3d58a8bb9 100644 (file)
@@ -2851,23 +2851,6 @@ mlx5_os_read_dev_stat(struct mlx5_priv *priv, const char *ctr_name,
        return 1;
 }
 
-/**
- * Set the reg_mr and dereg_mr call backs
- *
- * @param reg_mr_cb[out]
- *   Pointer to reg_mr func
- * @param dereg_mr_cb[out]
- *   Pointer to dereg_mr func
- *
- */
-void
-mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
-                     mlx5_dereg_mr_t *dereg_mr_cb)
-{
-       *reg_mr_cb = mlx5_mr_verbs_ops.reg_mr;
-       *dereg_mr_cb = mlx5_mr_verbs_ops.dereg_mr;
-}
-
 /**
  * Remove a MAC address from device
  *
index fb10dd08390f85c41bc6f47d6ae3691f26afb471..4779b37aa653a645ef11f059078f5df7390dbd88 100644 (file)
 #include <mlx5_utils.h>
 #include <mlx5_malloc.h>
 
-/**
- * Register mr. Given protection domain pointer, pointer to addr and length
- * register the memory region.
- *
- * @param[in] pd
- *   Pointer to protection domain context.
- * @param[in] addr
- *   Pointer to memory start address.
- * @param[in] length
- *   Length of the memory to register.
- * @param[out] pmd_mr
- *   pmd_mr struct set with lkey, address, length and pointer to mr object
- *
- * @return
- *   0 on successful registration, -1 otherwise
- */
-static int
-mlx5_reg_mr(void *pd, void *addr, size_t length,
-                struct mlx5_pmd_mr *pmd_mr)
-{
-       return mlx5_common_verbs_reg_mr(pd, addr, length, pmd_mr);
-}
-
-/**
- * Deregister mr. Given the mlx5 pmd MR - deregister the MR
- *
- * @param[in] pmd_mr
- *   pmd_mr struct set with lkey, address, length and pointer to mr object
- *
- */
-static void
-mlx5_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
-{
-       mlx5_common_verbs_dereg_mr(pmd_mr);
-}
-
-/* verbs operations. */
-const struct mlx5_mr_ops mlx5_mr_verbs_ops = {
-       .reg_mr = mlx5_reg_mr,
-       .dereg_mr = mlx5_dereg_mr,
-};
-
 /**
  * Modify Rx WQ vlan stripping offload
  *
index f7e8e2fe982fc34d6c841345bd19bce826b8256f..829d9fa7387378e4cd676cfdaf986b7b3fdfef73 100644 (file)
@@ -12,7 +12,5 @@ void mlx5_txq_ibv_obj_release(struct mlx5_txq_obj *txq_obj);
 int mlx5_rxq_ibv_obj_dummy_lb_create(struct rte_eth_dev *dev);
 void mlx5_rxq_ibv_obj_dummy_lb_release(struct rte_eth_dev *dev);
 
-/* Verbs ops struct */
-extern const struct mlx5_mr_ops mlx5_mr_verbs_ops;
 extern struct mlx5_obj_ops ibv_obj_ops;
 #endif /* RTE_PMD_MLX5_VERBS_H_ */
index 7fc2ca734571960776b13b3f82d8d14dfe709e70..977b4fb13a40643c3f2954bd6978b4ad0d0d9a6c 100644 (file)
@@ -1381,15 +1381,11 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
         * At this point the device is not added to the memory
         * event list yet, context is just being created.
         */
-       err = mlx5_mr_btree_init(&sh->share_cache.cache,
-                                MLX5_MR_BTREE_CACHE_N * 2,
-                                sh->numa_node);
+       err = mlx5_mr_create_cache(&sh->share_cache, sh->numa_node);
        if (err) {
                err = rte_errno;
                goto error;
        }
-       mlx5_os_set_reg_mr_cb(&sh->share_cache.reg_mr_cb,
-                             &sh->share_cache.dereg_mr_cb);
        mlx5_os_dev_shared_handler_install(sh);
        if (LIST_EMPTY(&mlx5_dev_ctx_list)) {
                err = mlx5_flow_os_init_workspace_once();
index bc00b21b414b935a2e2e8160def804f433a9a6a7..119abc36495c184dcc7da46b11bd2b589eca2be1 100644 (file)
@@ -1354,12 +1354,6 @@ struct mlx5_obj_ops {
 
 #define MLX5_RSS_HASH_FIELDS_LEN RTE_DIM(mlx5_rss_hash_fields)
 
-/* MR operations structure. */
-struct mlx5_mr_ops {
-       mlx5_reg_mr_t reg_mr;
-       mlx5_dereg_mr_t dereg_mr;
-};
-
 struct mlx5_priv {
        struct rte_eth_dev_data *dev_data;  /* Pointer to device data. */
        struct mlx5_dev_ctx_shared *sh; /* Shared device context. */
@@ -1759,8 +1753,6 @@ void mlx5_os_free_shared_dr(struct mlx5_priv *priv);
 int mlx5_os_net_probe(struct mlx5_common_device *cdev);
 void mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh);
 void mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh);
-void mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
-                          mlx5_dereg_mr_t *dereg_mr_cb);
 void mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
 int mlx5_os_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
                         uint32_t index);
index 3660aae32236b63a5ee0d5de1376db4eca700acb..8442dbd445e002fba3ddb4f4851b4ba43d5aa8cf 100644 (file)
@@ -963,21 +963,4 @@ mlx5_os_net_probe(struct mlx5_common_device *cdev)
        return 0;
 }
 
-/**
- * Set the reg_mr and dereg_mr call backs
- *
- * @param reg_mr_cb[out]
- *   Pointer to reg_mr func
- * @param dereg_mr_cb[out]
- *   Pointer to dereg_mr func
- *
- */
-void
-mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
-                     mlx5_dereg_mr_t *dereg_mr_cb)
-{
-       *reg_mr_cb = mlx5_os_reg_mr;
-       *dereg_mr_cb = mlx5_os_dereg_mr;
-}
-
 const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops = {0};
index 91fb9310621e8c50f24c32148d3a7fa7dc1922ac..b39181ebb57869c5d98da3871c2a3861420fdf1f 100644 (file)
@@ -194,11 +194,7 @@ mlx5_regex_dev_probe(struct mlx5_common_device *cdev)
        priv->regexdev->device = cdev->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());
+       ret = mlx5_mr_create_cache(&priv->mr_scache, rte_socket_id());
        if (ret) {
                DRV_LOG(ERR, "MR init tree failed.");
            rte_errno = ENOMEM;