Skip to content

Commit

Permalink
common/mlx5: add mempool registration facilities
Browse files Browse the repository at this point in the history
Add internal API to register mempools, that is, to create memory
regions (MR) for their memory and store them in a separate database.
Implementation deals with multi-process, so that class drivers don't
need to. Each protection domain has its own database. Memory regions
can be shared within a database if they represent a single hugepage
covering one or more mempools entirely.

Add internal API to lookup an MR key for an address that belongs
to a known mempool. It is a responsibility of a class driver
to extract the mempool from an mbuf.

Signed-off-by: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
  • Loading branch information
dkozlyuk authored and tmonjalo committed Oct 19, 2021
1 parent 11541c5 commit 690b2a8
Show file tree
Hide file tree
Showing 5 changed files with 666 additions and 0 deletions.
50 changes: 50 additions & 0 deletions drivers/common/mlx5/mlx5_common_mp.c
Expand Up @@ -54,6 +54,56 @@ mlx5_mp_req_mr_create(struct mlx5_mp_id *mp_id, uintptr_t addr)
return ret;
}

/**
* @param mp_id
* ID of the MP process.
* @param share_cache
* Shared MR cache.
* @param pd
* Protection domain.
* @param mempool
* Mempool to register or unregister.
* @param reg
* True to register the mempool, False to unregister.
*/
int
mlx5_mp_req_mempool_reg(struct mlx5_mp_id *mp_id,
struct mlx5_mr_share_cache *share_cache, void *pd,
struct rte_mempool *mempool, bool reg)
{
struct rte_mp_msg mp_req;
struct rte_mp_msg *mp_res;
struct rte_mp_reply mp_rep;
struct mlx5_mp_param *req = (struct mlx5_mp_param *)mp_req.param;
struct mlx5_mp_arg_mempool_reg *arg = &req->args.mempool_reg;
struct mlx5_mp_param *res;
struct timespec ts = {.tv_sec = MLX5_MP_REQ_TIMEOUT_SEC, .tv_nsec = 0};
enum mlx5_mp_req_type type;
int ret;

MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_SECONDARY);
type = reg ? MLX5_MP_REQ_MEMPOOL_REGISTER :
MLX5_MP_REQ_MEMPOOL_UNREGISTER;
mp_init_msg(mp_id, &mp_req, type);
arg->share_cache = share_cache;
arg->pd = pd;
arg->mempool = mempool;
ret = rte_mp_request_sync(&mp_req, &mp_rep, &ts);
if (ret) {
DRV_LOG(ERR, "port %u request to primary process failed",
mp_id->port_id);
return -rte_errno;
}
MLX5_ASSERT(mp_rep.nb_received == 1);
mp_res = &mp_rep.msgs[0];
res = (struct mlx5_mp_param *)mp_res->param;
ret = res->result;
if (ret)
rte_errno = -ret;
mlx5_free(mp_rep.msgs);
return ret;
}

/**
* Request Verbs queue state modification to the primary process.
*
Expand Down
14 changes: 14 additions & 0 deletions drivers/common/mlx5/mlx5_common_mp.h
Expand Up @@ -14,6 +14,8 @@
enum mlx5_mp_req_type {
MLX5_MP_REQ_VERBS_CMD_FD = 1,
MLX5_MP_REQ_CREATE_MR,
MLX5_MP_REQ_MEMPOOL_REGISTER,
MLX5_MP_REQ_MEMPOOL_UNREGISTER,
MLX5_MP_REQ_START_RXTX,
MLX5_MP_REQ_STOP_RXTX,
MLX5_MP_REQ_QUEUE_STATE_MODIFY,
Expand All @@ -33,6 +35,12 @@ struct mlx5_mp_arg_queue_id {
uint16_t queue_id; /* DPDK queue ID. */
};

struct mlx5_mp_arg_mempool_reg {
struct mlx5_mr_share_cache *share_cache;
void *pd; /* NULL for MLX5_MP_REQ_MEMPOOL_UNREGISTER */
struct rte_mempool *mempool;
};

/* Pameters for IPC. */
struct mlx5_mp_param {
enum mlx5_mp_req_type type;
Expand All @@ -41,6 +49,8 @@ struct mlx5_mp_param {
RTE_STD_C11
union {
uintptr_t addr; /* MLX5_MP_REQ_CREATE_MR */
struct mlx5_mp_arg_mempool_reg mempool_reg;
/* MLX5_MP_REQ_MEMPOOL_(UN)REGISTER */
struct mlx5_mp_arg_queue_state_modify state_modify;
/* MLX5_MP_REQ_QUEUE_STATE_MODIFY */
struct mlx5_mp_arg_queue_id queue_id;
Expand Down Expand Up @@ -91,6 +101,10 @@ void mlx5_mp_uninit_secondary(const char *name);
__rte_internal
int mlx5_mp_req_mr_create(struct mlx5_mp_id *mp_id, uintptr_t addr);
__rte_internal
int mlx5_mp_req_mempool_reg(struct mlx5_mp_id *mp_id,
struct mlx5_mr_share_cache *share_cache, void *pd,
struct rte_mempool *mempool, bool reg);
__rte_internal
int mlx5_mp_req_queue_state_modify(struct mlx5_mp_id *mp_id,
struct mlx5_mp_arg_queue_state_modify *sm);
__rte_internal
Expand Down

0 comments on commit 690b2a8

Please sign in to comment.