net/mlx5: implicit mempool registration
cover net/mlx5: implicit mempool registration
MLX5 hardware has its internal IOMMU where PMD registers the memory. On the data path, PMD translates VA into a key consumed by the device IOMMU. It is impractical for the PMD to register all allocated memory because of increased lookup cost both in HW and SW. Most often mbuf memory comes from mempools, so if PMD tracks them, it can almost always have mbuf memory registered before an mbuf hits the PMD. This patchset adds such tracking in the PMD and internal API to support it.
Please see [1] for a more thorough explanation of the patch 2/4 and how it can be useful outside of the MLX5 PMD.
Dmitry Kozlyuk (4):
mempool: add event callbacks
mempool: add non-IO flag
common/mlx5: add mempool registration facilities net/mlx5: support mempool registration
doc/guides/nics/mlx5.rst | 11 + doc/guides/rel_notes/release_21_11.rst | 9 + drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 564 +++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 ++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/linux/mlx5_os.h | 2 + drivers/net/mlx5/mlx5.c | 128 ++++++ drivers/net/mlx5/mlx5.h | 13 + drivers/net/mlx5/mlx5_mr.c | 27 ++ drivers/net/mlx5/mlx5_trigger.c | 10 +- lib/mempool/rte_mempool.c | 153 ++++++- lib/mempool/rte_mempool.h | 60 +++ lib/mempool/version.map | 8 + 17 files changed, 1110 insertions(+), 9 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/4 mempool: add event callbacks
Performance of MLX5 PMD of different classes can benefit if PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track mempool creation and destruction after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Add an internal API to register callback for mempool lify cycle events, currently RTE_MEMPOOL_EVENT_CREATE and RTE_MEMPOOL_EVENT_DESTROY:
* rte_mempool_event_callback_register()
* rte_mempool_event_callback_unregister()
--- lib/mempool/rte_mempool.c | 153 ++++++++++++++++++++++++++++++++++++-- lib/mempool/rte_mempool.h | 56 ++++++++++++++ lib/mempool/version.map | 8 ++ 3 files changed, 212 insertions(+), 5 deletions(-)
lib/mempool/rte_mempool.c +148 -5
@@ -42,6 +42,18 @@ static struct rte_tailq_elem rte_mempool_tailq = { };EAL_REGISTER_TAILQ (rte_mempool_tailq) +TAILQ_HEAD (mempool_callback_list, rte_tailq_entry); + +static struct rte_tailq_elem callback_tailq = { + .name ="RTE_MEMPOOL_CALLBACK" , +}; +EAL_REGISTER_TAILQ (callback_tailq) + +/* Invoke all registered mempool event callbacks. */ +static void +mempool_event_callback_invoke (enum rte_mempool_event event, +struct rte_mempool *mp); +#define CACHE_FLUSHTHRESH_MULTIPLIER 1.5#define CALC_CACHE_FLUSHTHRESH (c) \ ((typeof(c))((c) * CACHE_FLUSHTHRESH_MULTIPLIER))
@@ -722,6 +734,7 @@ rte_mempool_free(struct rte_mempool *mp) }rte_mcfg_tailq_write_unlock (); +mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_DESTROY , mp);rte_mempool_trace_free (mp);rte_mempool_free_memchunks (mp);rte_mempool_ops_free (mp);
@@ -778,10 +791,10 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache) }/* create an empty mempool */ -struct rte_mempool * -rte_mempool_create_empty (const char *name,unsigned n,unsigned elt_size, -unsigned cache_size,unsigned private_data_size, -int socket_id,unsigned flags) +static struct rte_mempool * +mempool_create_empty (const char *name,unsigned int n, +unsigned int elt_size,unsigned int cache_size, +unsigned int private_data_size,int socket_id,unsigned int flags) {char mz_name[RTE_MEMZONE_NAMESIZE ];struct rte_mempool_list *mempool_list;
@@ -915,6 +928,19 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,return NULL ; } +struct rte_mempool * +rte_mempool_create_empty (const char *name,unsigned int n, +unsigned int elt_size,unsigned int cache_size, +unsigned int private_data_size,int socket_id,unsigned int flags) +{ +struct rte_mempool *mp; + + mp =mempool_create_empty (name, n, elt_size, cache_size, + private_data_size, socket_id, flags); +mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_CREATE , mp); +return mp; +} +/* create the mempool */ struct rte_mempool * rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
@@ -926,7 +952,7 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,int ret;struct rte_mempool *mp; - mp =rte_mempool_create_empty (name, n, elt_size, cache_size, + mp =mempool_create_empty (name, n, elt_size, cache_size, private_data_size, socket_id, flags);if (mp ==NULL )return NULL ;
@@ -958,6 +984,8 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,if (obj_init)rte_mempool_obj_iter (mp, obj_init, obj_init_arg); +mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_CREATE , mp); +rte_mempool_trace_create (name, n, elt_size, cache_size, private_data_size, mp_init, mp_init_arg, obj_init, obj_init_arg, flags, mp);
@@ -1343,3 +1371,118 @@ void rte_mempool_walk(void (*func)(struct rte_mempool *, void *),rte_mcfg_mempool_read_unlock (); } + +struct mempool_callback { +rte_mempool_event_callback *func; +void *arg; +}; + +static void +mempool_event_callback_invoke (enum rte_mempool_event event, +struct rte_mempool *mp) +{ +struct mempool_callback_list *list; +struct rte_tailq_entry *te; +void *tmp_te; + +rte_mcfg_tailq_read_lock (); + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + TAILQ_FOREACH_SAFE(te, list, next, tmp_te) { +struct mempool_callback *cb = te->data; +rte_mcfg_tailq_read_unlock (); + cb->func (event, mp, cb->arg); +rte_mcfg_tailq_read_lock (); + } +rte_mcfg_tailq_read_unlock (); +} + +int +rte_mempool_event_callback_register (rte_mempool_event_callback *func, +void *arg) +{ +struct mempool_callback_list *list; +struct rte_tailq_entry *te =NULL ; +struct mempool_callback *cb; +void *tmp_te; +int ret; + +rte_mcfg_mempool_read_lock (); +rte_mcfg_tailq_write_lock (); + + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + TAILQ_FOREACH_SAFE(te, list, next, tmp_te) { +struct mempool_callback *cb = + (struct mempool_callback *)te->data; +if (cb->func == func && cb->arg == arg) { + ret = -EEXIST ; + goto exit; + } + } + + te =rte_zmalloc ("MEMPOOL_TAILQ_ENTRY" ,sizeof (*te),0 ); +if (te ==NULL ) { +RTE_LOG (ERR ,MEMPOOL , +"Cannot allocate event callback tailq entry!\n" ); + ret = -ENOMEM ; + goto exit; + } + + cb =rte_malloc ("MEMPOOL_EVENT_CALLBACK" ,sizeof (*cb),0 ); +if (cb ==NULL ) { +RTE_LOG (ERR ,MEMPOOL , +"Cannot allocate event callback!\n" ); +rte_free (te); + ret = -ENOMEM ; + goto exit; + } + + cb->func = func; + cb->arg = arg; + te->data = cb; +TAILQ_INSERT_TAIL (list, te, next); + ret =0 ; + +exit: +rte_mcfg_tailq_write_unlock (); +rte_mcfg_mempool_read_unlock (); + rte_errno = -ret; +return ret; +} + +int +rte_mempool_event_callback_unregister (rte_mempool_event_callback *func, +void *arg) +{ +struct mempool_callback_list *list; +struct rte_tailq_entry *te =NULL ; +struct mempool_callback *cb; +int ret; + +if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) { + rte_errno =EPERM ; +return -1 ; + } + +rte_mcfg_mempool_read_lock (); +rte_mcfg_tailq_write_lock (); + ret = -ENOENT ; + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + TAILQ_FOREACH(te, list, next) { + cb = (struct mempool_callback *)te->data; +if (cb->func == func && cb->arg == arg) +break ; + } +if (te !=NULL ) { +TAILQ_REMOVE (list, te, next); + ret =0 ; + } +rte_mcfg_tailq_write_unlock (); +rte_mcfg_mempool_read_unlock (); + +if (ret ==0 ) { +rte_free (te); +rte_free (cb); + } + rte_errno = -ret; +return ret; +}
lib/mempool/rte_mempool.h +56 -0
62 lines not on this page · raw message
lib/mempool/version.map +8 -0
@@ -64,3 +64,11 @@ EXPERIMENTAL { __rte_mempool_trace_ops_free; __rte_mempool_trace_set_ops_byname; }; + +INTERNAL { + global: + + # added in 21.11 + rte_mempool_event_callback_register; + rte_mempool_event_callback_unregister; +};
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH 1/4] mempool: add event callbacks
Quoted 10 lines · Dmitry Kozlyuk
Performance of MLX5 PMD of different classes can benefit if PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track mempool creation and destruction after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Quoted 7 lines
Add an internal API to register callback for mempool lify cycle events, currently
RTE_MEMPOOL_EVENT_CREATEandRTE_MEMPOOL_EVENT_DESTROY:
*rte_mempool_event_callback_register()
*rte_mempool_event_callback_unregister()Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Matan Azrad <[email protected]>
Quoted 295 lines
--- lib/mempool/rte_mempool.c | 153 ++++++++++++++++++++++++++++++++++++-- lib/mempool/rte_mempool.h | 56 ++++++++++++++ lib/mempool/version.map | 8 ++ 3 files changed, 212 insertions(+), 5 deletions(-)lib/mempool/rte_mempool.c +148
-5@@ -42,6 +42,18 @@ static struct rte_tailq_elem rte_mempool_tailq = { };EAL_REGISTER_TAILQ (rte_mempool_tailq) +TAILQ_HEAD (mempool_callback_list, rte_tailq_entry); + +static struct rte_tailq_elem callback_tailq = { + .name ="RTE_MEMPOOL_CALLBACK" , +}; +EAL_REGISTER_TAILQ (callback_tailq) + +/* Invoke all registered mempool event callbacks. */ +static void +mempool_event_callback_invoke (enum rte_mempool_event event, +struct rte_mempool *mp); +#define CACHE_FLUSHTHRESH_MULTIPLIER 1.5#define CALC_CACHE_FLUSHTHRESH (c) \ ((typeof(c))((c) * CACHE_FLUSHTHRESH_MULTIPLIER))@@ -722,6 +734,7 @@ rte_mempool_free(struct rte_mempool *mp) }rte_mcfg_tailq_write_unlock (); +mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_DESTROY , mp);rte_mempool_trace_free (mp);rte_mempool_free_memchunks (mp);rte_mempool_ops_free (mp);@@ -778,10 +791,10 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache) }/* create an empty mempool */ -struct rte_mempool * -rte_mempool_create_empty (const char *name,unsigned n,unsigned elt_size, -unsigned cache_size,unsigned private_data_size, -int socket_id,unsigned flags) +static struct rte_mempool * +mempool_create_empty (const char *name,unsigned int n, +unsigned int elt_size,unsigned int cache_size, +unsigned int private_data_size,int socket_id,unsigned int flags) {char mz_name[RTE_MEMZONE_NAMESIZE ];struct rte_mempool_list *mempool_list;@@ -915,6 +928,19 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,return NULL ; } +struct rte_mempool * +rte_mempool_create_empty (const char *name,unsigned int n, +unsigned int elt_size,unsigned int cache_size, +unsigned int private_data_size,int socket_id,unsigned int flags) +{ +struct rte_mempool *mp; + + mp =mempool_create_empty (name, n, elt_size, cache_size, + private_data_size, socket_id, flags); +mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_CREATE , mp); +return mp; +} +/* create the mempool */ struct rte_mempool * rte_mempool_create(const char *name, unsigned n, unsigned elt_size,@@ -926,7 +952,7 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,int ret;struct rte_mempool *mp; - mp =rte_mempool_create_empty (name, n, elt_size, cache_size, + mp =mempool_create_empty (name, n, elt_size, cache_size, private_data_size, socket_id, flags);if (mp ==NULL )return NULL ;@@ -958,6 +984,8 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,if (obj_init)rte_mempool_obj_iter (mp, obj_init, obj_init_arg); +mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_CREATE , mp); +rte_mempool_trace_create (name, n, elt_size, cache_size, private_data_size, mp_init, mp_init_arg, obj_init, obj_init_arg, flags, mp);@@ -1343,3 +1371,118 @@ void rte_mempool_walk(void (*func)(struct rte_mempool *, void *),rte_mcfg_mempool_read_unlock (); } + +struct mempool_callback { +rte_mempool_event_callback *func; +void *arg; +}; + +static void +mempool_event_callback_invoke (enum rte_mempool_event event, +struct rte_mempool *mp) +{ +struct mempool_callback_list *list; +struct rte_tailq_entry *te; +void *tmp_te; + +rte_mcfg_tailq_read_lock (); + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + TAILQ_FOREACH_SAFE(te, list, next, tmp_te) { +struct mempool_callback *cb = te->data; +rte_mcfg_tailq_read_unlock (); + cb->func (event, mp, cb->arg); +rte_mcfg_tailq_read_lock (); + } +rte_mcfg_tailq_read_unlock (); +} + +int +rte_mempool_event_callback_register (rte_mempool_event_callback *func, +void *arg) +{ +struct mempool_callback_list *list; +struct rte_tailq_entry *te =NULL ; +struct mempool_callback *cb; +void *tmp_te; +int ret; + +rte_mcfg_mempool_read_lock (); +rte_mcfg_tailq_write_lock (); + + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + TAILQ_FOREACH_SAFE(te, list, next, tmp_te) { +struct mempool_callback *cb = + (struct mempool_callback *)te->data; +if (cb->func == func && cb->arg == arg) { + ret = -EEXIST ; + goto exit; + } + } + + te =rte_zmalloc ("MEMPOOL_TAILQ_ENTRY" ,sizeof (*te),0 ); +if (te ==NULL ) { +RTE_LOG (ERR ,MEMPOOL , +"Cannot allocate event callback tailq entry!\n" ); + ret = -ENOMEM ; + goto exit; + } + + cb =rte_malloc ("MEMPOOL_EVENT_CALLBACK" ,sizeof (*cb),0 ); +if (cb ==NULL ) { +RTE_LOG (ERR ,MEMPOOL , +"Cannot allocate event callback!\n" ); +rte_free (te); + ret = -ENOMEM ; + goto exit; + } + + cb->func = func; + cb->arg = arg; + te->data = cb; +TAILQ_INSERT_TAIL (list, te, next); + ret =0 ; + +exit: +rte_mcfg_tailq_write_unlock (); +rte_mcfg_mempool_read_unlock (); + rte_errno = -ret; +return ret; +} + +int +rte_mempool_event_callback_unregister (rte_mempool_event_callback *func, +void *arg) +{ +struct mempool_callback_list *list; +struct rte_tailq_entry *te =NULL ; +struct mempool_callback *cb; +int ret; + +if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) { + rte_errno =EPERM ; +return -1 ; + } + +rte_mcfg_mempool_read_lock (); +rte_mcfg_tailq_write_lock (); + ret = -ENOENT ; + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + TAILQ_FOREACH(te, list, next) { + cb = (struct mempool_callback *)te->data; +if (cb->func == func && cb->arg == arg) +break ; + } +if (te !=NULL ) { +TAILQ_REMOVE (list, te, next); + ret =0 ; + } +rte_mcfg_tailq_write_unlock (); +rte_mcfg_mempool_read_unlock (); + +if (ret ==0 ) { +rte_free (te); +rte_free (cb); + } + rte_errno = -ret; +return ret; +}lib/mempool/rte_mempool.h +56
-0@@ -1775,6 +1775,62 @@ void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),int rte_mempool_get_page_size (struct rte_mempool *mp,size_t *pg_sz); +/** +* Mempool event type. +* @internal +*/ +enum rte_mempool_event { +/** Occurs after a successful mempool creation. */ +RTE_MEMPOOL_EVENT_CREATE =0 , +/** Occurs before destruction of a mempool begins. */ +RTE_MEMPOOL_EVENT_DESTROY =1 , +}; + +/** +* @internal +* Mempool event callback. +*/ +typedef void (rte_mempool_event_callback )( +enum rte_mempool_event event, +struct rte_mempool *mp, +void *arg); + +/** +* @internal +* Register a callback invoked on mempool life cycle event. +* Callbacks will be invoked in the process that creates the mempool. +* +* @param cb +* Callback function. +* @param cb_arg +* User data. +* +* @return +* 0 on success, negative on failure and rte_errno is set. +*/ +__rte_internal +int +rte_mempool_event_callback_register (rte_mempool_event_callback *cb, +void *cb_arg); + +/** +* @internal +* Unregister a callback added with rte_mempool_event_callback_register(). +* @p cb and @p arg must exactly match registration parameters. +* +* @param cb +* Callback function. +* @param cb_arg +* User data. +* +* @return +* 0 on success, negative on failure and rte_errno is set. +*/ +__rte_internal +int +rte_mempool_event_callback_unregister (rte_mempool_event_callback *cb, +void *cb_arg); + #ifdef __cplusplus }#endif lib/mempool/version.map +8
-1@@ -64,3 +64,11 @@ EXPERIMENTAL { __rte_mempool_trace_ops_free; __rte_mempool_trace_set_ops_byname; }; + +INTERNAL { + global: + + # added in 21.11 + rte_mempool_event_callback_register; + rte_mempool_event_callback_unregister; +}; --2.25.1
PATCH 2/4 mempool: add non-IO flag
In reply to Dmitry KozlyukMempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add MEMPOOL_F_NON_IO flag to mark such mempools.
--- doc/guides/rel_notes/release_21_11.rst | 3 +++ lib/mempool/rte_mempool.h | 4 ++++ 2 files changed, 7 insertions(+)
doc/guides/rel_notes/release_21_11.rst +3 -0
@@ -84,6 +84,9 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA). + ABI Changes -----------
lib/mempool/rte_mempool.h +4 -0
@@ -263,6 +263,7 @@ struct rte_mempool {#define MEMPOOL_F_SC_GET 0x0008/**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010/**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020/**< Don't need IOVA contiguous objs. */ +#define MEMPOOL_F_NON_IO 0x0040/**< Not used for device IO (DMA). */ /** * @internal When debug is enabled, store some statistics.
@@ -992,6 +993,9 @@ typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);* "single-consumer". Otherwise, it is "multi-consumers". * - MEMPOOL_F_NO_IOVA_CONTIG: If set, allocated objects won't * necessarily be contiguous in IO memory. +* - MEMPOOL_F_NO_IO: If set, the mempool is considered to be +* never used for device IO, i.e. DMA operations, +* which may affect some PMD behavior. * @return * The pointer to the new allocated mempool, on success. NULL on error * with rte_errno set appropriately. Possible rte_errno values include:
Signature · 1 line
2.25.1
PATCH 3/4 common/mlx5: add mempool registration facilities
In reply to Dmitry KozlyukAdd 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.
--- drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 564 +++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + 5 files changed, 650 insertions(+)
drivers/common/mlx5/mlx5_common_mp.c +50 -0
@@ -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. *
drivers/common/mlx5/mlx5_common_mp.h +14 -0
@@ -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 ,
@@ -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;
@@ -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;
@@ -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
drivers/common/mlx5/mlx5_common_mr.c +564 -0
580 lines not on this page · raw message
drivers/common/mlx5/mlx5_common_mr.h +17 -0
@@ -13,6 +13,7 @@#include <rte_rwlock.h> #include <rte_bitmap.h> +#include <rte_mbuf.h> #include <rte_memory.h> #include "mlx5_glue.h"
@@ -75,6 +76,7 @@ struct mlx5_mr_ctrl { } __rte_packed;LIST_HEAD (mlx5_mr_list, mlx5_mr); +LIST_HEAD (mlx5_mempool_reg_list, mlx5_mempool_reg);/* Global per-device MR cache. */ struct mlx5_mr_share_cache {
@@ -83,6 +85,7 @@ struct mlx5_mr_share_cache {struct mlx5_mr_btree cache;/* Global MR cache table. */ struct mlx5_mr_list mr_list;/* Registered MR list. */ struct mlx5_mr_list mr_free_list;/* Freed MR list. */ +struct mlx5_mempool_reg_list mempool_reg_list;/* Mempool database. */ mlx5_reg_mr_t reg_mr_cb;/* Callback to reg_mr func */ mlx5_dereg_mr_t dereg_mr_cb;/* Callback to dereg_mr func */ } __rte_packed;
@@ -136,6 +139,10 @@ uint32_t mlx5_mr_addr2mr_bh(void *pd, struct mlx5_mp_id *mp_id,struct mlx5_mr_ctrl *mr_ctrl, uintptr_t addr, unsigned int mr_ext_memseg_en);__rte_internal +uint32_t mlx5_mr_mempool2mr_bh(struct mlx5_mr_share_cache *share_cache, +struct mlx5_mr_ctrl *mr_ctrl, +struct rte_mempool *mp,uintptr_t addr); +__rte_internal void mlx5_mr_release_cache(struct mlx5_mr_share_cache *mr_cache);__rte_internal void mlx5_mr_dump_cache(struct mlx5_mr_share_cache *share_cache __rte_unused);
@@ -179,4 +186,14 @@ mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);__rte_internal voidmlx5_mr_free (struct mlx5_mr *mr,mlx5_dereg_mr_t dereg_mr_cb); + +__rte_internal +int +mlx5_mr_mempool_register (struct mlx5_mr_share_cache *share_cache,void *pd, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +__rte_internal +int +mlx5_mr_mempool_unregister (struct mlx5_mr_share_cache *share_cache, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +#endif /* RTE_PMD_MLX5_COMMON_MR_H_ */
drivers/common/mlx5/version.map +5 -0
@@ -149,4 +149,9 @@ INTERNAL { mlx5_realloc; mlx5_translate_port_name; # WINDOWS_NO_EXPORT + + mlx5_mr_mempool_register; + mlx5_mr_mempool_unregister; + mlx5_mp_req_mempool_reg; + mlx5_mr_mempool2mr_bh; };
Signature · 1 line
2.25.1
PATCH 4/4 net/mlx5: support mempool registration
In reply to Dmitry KozlyukWhen the first port in a given protection domain (PD) starts, install a mempool event callback for this PD and register all existing memory regions (MR) for it. When the last port in a PD closes, remove the callback and unregister all mempools for this PD.
On TX slow path, i.e. when an MR key for the address of the buffer to send is not in the local cache, first try to retrieve it from the database of registered mempools. Supported are direct and indirect mbufs, as well as externally-attached ones from MLX5 MPRQ feature. Lookup in the database of non-mempool memory is used as the last resort.
--- doc/guides/nics/mlx5.rst | 11 +++ doc/guides/rel_notes/release_21_11.rst | 6 ++ drivers/net/mlx5/linux/mlx5_mp_os.c | 44 +++++++++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/linux/mlx5_os.h | 2 + drivers/net/mlx5/mlx5.c | 128 +++++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 13 +++ drivers/net/mlx5/mlx5_mr.c | 27 ++++++ drivers/net/mlx5/mlx5_trigger.c | 10 +- 9 files changed, 241 insertions(+), 4 deletions(-)
doc/guides/nics/mlx5.rst +11 -0
@@ -1001,6 +1001,17 @@ Driver options Enabled by default. +- ``mr_mempool_reg_en`` parameter [int] + + A nonzero value enables implicit registration of DMA memory of all mempools + except those having ``MEMPOOL_F_NON_IO``. The effect is that when a packet + from a mempool is transmitted, its memory is already registered for DMA + in the PMD and no registration will happen on the data path. The tradeoff is + extra work on the creation of each mempool and increased HW resource use + if some mempools are not used with MLX5 devices. + + Enabled by default. + - ``representor`` parameter [list] This parameter can be used to instantiate DPDK Ethernet devices from
doc/guides/rel_notes/release_21_11.rst +6 -0
@@ -55,6 +55,12 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Updated Mellanox mlx5 driver.** + + Updated the Mellanox mlx5 driver with new features and improvements, including: + + * Added implicit mempool registration to avoid data path hiccups (opt-out). + Removed Items -------------
drivers/net/mlx5/linux/mlx5_mp_os.c +44 -0
56 lines not on this page · raw message
drivers/net/mlx5/linux/mlx5_os.c +2 -2
@@ -1034,8 +1034,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, err =mlx5_proc_priv_init (eth_dev);if (err)return NULL ; - mp_id.port_id = eth_dev->data->port_id; -strlcpy (mp_id.name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +mlx5_mp_id_init (&mp_id, eth_dev->data->port_id);/* Receive command fd from primary process */ err =mlx5_mp_req_verbs_cmd_fd (&mp_id);if (err <0 )
@@ -2136,6 +2135,7 @@ mlx5_os_config_default(struct mlx5_dev_config *config) config->txqs_inline =MLX5_ARG_UNSET ; config->vf_nl_en =1 ; config->mr_ext_memseg_en =1 ; + config->mr_mempool_reg_en =1 ; config->mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; config->mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; config->dv_esw_en =1 ;
drivers/net/mlx5/linux/mlx5_os.h +2 -0
@@ -20,5 +20,7 @@ enum {#define MLX5_NAMESIZE IF_NAMESIZEint mlx5_auxiliary_get_ifindex (const char *sf_name); +void mlx5_mempool_event_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *arg);#endif /* RTE_PMD_MLX5_OS_H_ */
drivers/net/mlx5/mlx5.c +128 -0
164 lines not on this page · raw message
drivers/net/mlx5/mlx5.h +13 -0
@@ -155,6 +155,13 @@ struct mlx5_flow_dump_ack {/** Key string for IPC. */ #define MLX5_MP_NAME "net_mlx5_mp" +/** Initialize a multi-process ID. */ +static inline void +mlx5_mp_id_init (struct mlx5_mp_id *mp_id,uint16_t port_id) +{ + mp_id->port_id = port_id; +strlcpy (mp_id->name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +}LIST_HEAD (mlx5_dev_list, mlx5_dev_ctx_shared);
@@ -175,6 +182,9 @@ struct mlx5_local_data {extern struct mlx5_shared_data *mlx5_shared_data; +/* Exposed to copy into the shared data in OS-specific module. */ +extern int mlx5_net_mempool_slot; +/* Dev ops structs */ extern const struct eth_dev_ops mlx5_dev_ops;extern const struct eth_dev_ops mlx5_dev_sec_ops;
@@ -270,6 +280,8 @@ struct mlx5_dev_config { unsigned int dv_miss_info:1; /* restore packet after partial hw miss */ unsigned int allow_duplicate_pattern:1;/* Allow/Prevent the duplicate rules pattern. */ + unsigned int mr_mempool_reg_en:1; +/* Allow/prevent implicit mempool memory registration. */ struct {unsigned int enabled:1 ;/* Whether MPRQ is enabled. */ unsigned int stride_num_n;/* Number of strides. */
@@ -1497,6 +1509,7 @@ struct mlx5_dev_ctx_shared * mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, const struct mlx5_dev_config *config);void mlx5_free_shared_dev_ctx (struct mlx5_dev_ctx_shared *sh); +int mlx5_dev_ctx_shared_mempool_subscribe (struct mlx5_dev_ctx_shared *sh);void mlx5_free_table_hash_list (struct mlx5_priv *priv);int mlx5_alloc_table_hash_list (struct mlx5_priv *priv); void mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
drivers/net/mlx5/mlx5_mr.c +27 -0
@@ -128,9 +128,36 @@ mlx5_tx_addr2mr_bh(struct mlx5_txq_data *txq, uintptr_t addr)uint32_t mlx5_tx_mb2mr_bh (struct mlx5_txq_data *txq,struct rte_mbuf *mb) { +struct mlx5_txq_ctrl *txq_ctrl = + container_of(txq, struct mlx5_txq_ctrl, txq); +struct mlx5_mr_ctrl *mr_ctrl = &txq->mr_ctrl; +struct mlx5_priv *priv = txq_ctrl->priv;uintptr_t addr = (uintptr_t )mb->buf_addr;uint32_t lkey; +if (priv->config.mr_mempool_reg_en) { +struct rte_mempool *mp =NULL ; +struct mlx5_mprq_buf *buf; + +if (!RTE_MBUF_HAS_EXTBUF (mb)) { + mp =mlx5_mb2mp (mb); + }else if (mb->shinfo->free_cb == mlx5_mprq_buf_free_cb) { +/* Recover MPRQ mempool. */ + buf = mb->shinfo->fcb_opaque; + mp = buf->mp; + } +if (mp !=NULL ) { + lkey =mlx5_mr_mempool2mr_bh (&priv->sh->share_cache, + mr_ctrl, mp, addr); +/* +* Lookup can only fail on invalid input, e.g. "addr" +* is not from "mp" or "mp" has MEMPOOL_F_NON_IO set. +*/ +if (lkey !=UINT32_MAX ) +return lkey; + } +/* Fallback for generic mechanism in corner cases. */ + } lkey =mlx5_tx_addr2mr_bh (txq, addr);if (lkey ==UINT32_MAX && rte_errno ==ENXIO ) {/* Mempool may have externally allocated memory. */
drivers/net/mlx5/mlx5_trigger.c +8 -2
@@ -1124,6 +1124,13 @@ mlx5_dev_start(struct rte_eth_dev *dev) dev->data->port_id, strerror(rte_errno)); goto error; } +if (priv->config.mr_mempool_reg_en) { +if (mlx5_dev_ctx_shared_mempool_subscribe (priv->sh) !=0 ) { +DRV_LOG (ERR ,"port %u failed to subscribe for mempool life cycle: %s" , + dev->data->port_id,rte_strerror (rte_errno)); + goto error; + } + }rte_wmb (); dev->tx_pkt_burst =mlx5_select_tx_function (dev); dev->rx_pkt_burst =mlx5_select_rx_function (dev);
@@ -1193,11 +1200,10 @@ mlx5_dev_stop(struct rte_eth_dev *dev)if (priv->obj_ops.lb_dummy_queue_release) priv->obj_ops.lb_dummy_queue_release (dev);mlx5_txpp_stop (dev); -return 0 ; } -/** +/* * Enable traffic flows configured by control plane * * @param dev
Signature · 1 line
2.25.1
cover net/mlx5: implicit mempool registration
In reply to Dmitry KozlyukFrom: Dmitry Kozlyuk <[email protected]>
MLX5 hardware has its internal IOMMU where PMD registers the memory. On the data path, PMD translates VA into a key consumed by the device IOMMU. It is impractical for the PMD to register all allocated memory because of increased lookup cost both in HW and SW. Most often mbuf memory comes from mempools, so if PMD tracks them, it can almost always have mbuf memory registered before an mbuf hits the PMD. This patchset adds such tracking in the PMD and internal API to support it.
Please see [1] for a more thorough explanation of the patch 2/4 and how it can be useful outside of the MLX5 PMD.
v2 (internal review and testing):
1. Change tracked mempool event from being created (CREATE) to being fully populated (READY), which is the state PMD is interested in.
2. Unit test the new mempool callback API.
3. Remove bogus "error" messages in normal conditions.
4. Fixes in PMD.
Dmitry Kozlyuk (4):
mempool: add event callbacks
mempool: add non-IO flag
common/mlx5: add mempool registration facilities net/mlx5: support mempool registration
app/test/test_mempool.c | 75 ++++ doc/guides/nics/mlx5.rst | 11 + doc/guides/rel_notes/release_21_11.rst | 9 + drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 ++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++ drivers/net/mlx5/mlx5.h | 10 + drivers/net/mlx5/mlx5_mr.c | 120 ++--- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 +- drivers/net/mlx5/mlx5_rxq.c | 13 + drivers/net/mlx5/mlx5_trigger.c | 77 +++- drivers/net/mlx5/windows/mlx5_os.c | 1 + lib/mempool/rte_mempool.c | 143 +++++- lib/mempool/rte_mempool.h | 60 +++ lib/mempool/version.map | 8 + 21 files changed, 1297 insertions(+), 119 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/4 mempool: add event callbacks
From: Dmitry Kozlyuk <[email protected]>
Performance of MLX5 PMD of different classes can benefit if PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track creation and destruction of mempools after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Add an internal API to register callback for mempool lify cycle events, currently RTE_MEMPOOL_EVENT_READY (after populating)
and RTE_MEMPOOL_EVENT_DESTROY (before freeing):
* rte_mempool_event_callback_register()
* rte_mempool_event_callback_unregister()
Provide a unit test for the new API.
--- app/test/test_mempool.c | 75 ++++++++++++++++++++ lib/mempool/rte_mempool.c | 143 +++++++++++++++++++++++++++++++++++++- lib/mempool/rte_mempool.h | 56 +++++++++++++++ lib/mempool/version.map | 8 +++ 4 files changed, 279 insertions(+), 3 deletions(-)
app/test/test_mempool.c +75 -0
@@ -14,6 +14,7 @@#include <rte_common.h> #include <rte_log.h> #include <rte_debug.h> +#include <rte_errno.h> #include <rte_memory.h> #include <rte_launch.h> #include <rte_cycles.h>
@@ -471,6 +472,74 @@ test_mp_mem_init(struct rte_mempool *mp, data->ret =0 ; } +struct test_mempool_events_data { +struct rte_mempool *mp; +enum rte_mempool_event event; +bool invoked; +}; + +static void +test_mempool_events_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *arg) +{ +struct test_mempool_events_data *data = arg; + + data->mp = mp; + data->event = event; + data->invoked = true; +} + +static int +test_mempool_events (int (*populate)(struct rte_mempool *mp)) +{ +struct test_mempool_events_data data; +struct rte_mempool *mp; +int ret; + + ret =rte_mempool_event_callback_register (NULL , &data); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Registered a NULL callback" ); + +memset (&data,0 ,sizeof (data)); + ret =rte_mempool_event_callback_register (test_mempool_events_cb, + &data); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to register the callback: %s" , +rte_strerror (rte_errno)); + + mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create an empty mempool: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data.invoked, false, +"Callback invoked on an empty mempool creation" ); + +rte_mempool_set_ops_byname (mp,rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp->size,"Failed to populate the mempool: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data.invoked, true, +"Callback not invoked on an empty mempool population" ); +RTE_TEST_ASSERT_EQUAL (data.event,RTE_MEMPOOL_EVENT_READY , +"Wrong callback invoked, expected READY" ); +RTE_TEST_ASSERT_EQUAL (data.mp, mp, +"Callback invoked for a wrong mempool" ); + +memset (&data,0 ,sizeof (data)); +rte_mempool_free (mp); +RTE_TEST_ASSERT_EQUAL (data.invoked, true, +"Callback not invoked on mempool destruction" ); +RTE_TEST_ASSERT_EQUAL (data.event,RTE_MEMPOOL_EVENT_DESTROY , +"Wrong callback invoked, expected DESTROY" ); +RTE_TEST_ASSERT_EQUAL (data.mp, mp, +"Callback invoked for a wrong mempool" ); + + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, + &data); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister the callback: %s" , +rte_strerror (rte_errno)); +return 0 ; +} +static int test_mempool (void ) {
@@ -645,6 +714,12 @@ test_mempool(void)if (test_mempool_basic (default_pool,1 ) <0 )GOTO_ERR (ret, err); +/* test mempool event callbacks */ +if (test_mempool_events (rte_mempool_populate_default) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events (rte_mempool_populate_anon) <0 ) +GOTO_ERR (ret, err); +rte_mempool_list_dump (stdout); ret =0 ;
lib/mempool/rte_mempool.c +140 -3
170 lines not on this page · raw message
lib/mempool/rte_mempool.h +56 -0
62 lines not on this page · raw message
lib/mempool/version.map +8 -0
@@ -64,3 +64,11 @@ EXPERIMENTAL { __rte_mempool_trace_ops_free; __rte_mempool_trace_set_ops_byname; }; + +INTERNAL { + global: + + # added in 21.11 + rte_mempool_event_callback_register; + rte_mempool_event_callback_unregister; +};
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v2 1/4] mempool: add event callbacks
29/09/2021 16:52, [email protected]:
Quoted 10 lines
From: Dmitry Kozlyuk <[email protected]>
Performance of MLX5 PMD of different classes can benefit if PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track creation and destruction of mempools after the forwarding starts but before an mbuf from the new mempool is sent to the device.
I'm not sure this introduction about mlx5 is appropriate.
Quoted 1 line
Add an internal API to register callback for mempool lify cycle events,
lify -> life
Quoted 5 lines
currently
RTE_MEMPOOL_EVENT_READY(after populating) andRTE_MEMPOOL_EVENT_DESTROY(before freeing):
*rte_mempool_event_callback_register()
*rte_mempool_event_callback_unregister()Provide a unit test for the new API.
[...]
lib/mempool/rte_mempool.c rte_mempool_cache_free(struct rte_mempool_cache *cache) · line 801
Quoted 6 lines
lib/mempool/rte_mempool.c +3
-3-rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, - unsigned cache_size, unsigned private_data_size, - int socket_id, unsigned flags) +rte_mempool_create_empty(const char *name, unsigned int n, + unsigned int elt_size, unsigned int cache_size, + unsigned int private_data_size, int socket_id, unsigned int flags)
This change looks unrelated.
lib/mempool/rte_mempool.h void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg), · line 1787
Quoted 6 lines
lib/mempool/rte_mempool.h +6
-0+enum rte_mempool_event { +/** Occurs after a mempool is successfully populated. */ +RTE_MEMPOOL_EVENT_READY =0 , +/** Occurs before destruction of a mempool begins. */ +RTE_MEMPOOL_EVENT_DESTROY =1 , +};
These events look OK.
lib/mempool/rte_mempool.h void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg), · line 1796
Quoted 4 lines
lib/mempool/rte_mempool.h +4
-0+typedef void (rte_mempool_event_callback )( +enum rte_mempool_event event, +struct rte_mempool *mp, +void *arg);
Instead of "arg", I prefer the name "user_data".
PATCH v2 2/4 mempool: add non-IO flag
In reply to [email protected]From: Dmitry Kozlyuk <[email protected]>
Mempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add MEMPOOL_F_NON_IO flag to mark such mempools.
--- doc/guides/rel_notes/release_21_11.rst | 3 +++ lib/mempool/rte_mempool.h | 4 ++++ 2 files changed, 7 insertions(+)
doc/guides/rel_notes/release_21_11.rst +3 -0
@@ -155,6 +155,9 @@ API Changes the crypto/security operation. This field will be used to communicate events such as soft expiry with IPsec in lookaside mode. +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA). + ABI Changes -----------
lib/mempool/rte_mempool.h +4 -0
@@ -263,6 +263,7 @@ struct rte_mempool {#define MEMPOOL_F_SC_GET 0x0008/**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010/**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020/**< Don't need IOVA contiguous objs. */ +#define MEMPOOL_F_NON_IO 0x0040/**< Not used for device IO (DMA). */ /** * @internal When debug is enabled, store some statistics.
@@ -992,6 +993,9 @@ typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);* "single-consumer". Otherwise, it is "multi-consumers". * - MEMPOOL_F_NO_IOVA_CONTIG: If set, allocated objects won't * necessarily be contiguous in IO memory. +* - MEMPOOL_F_NO_IO: If set, the mempool is considered to be +* never used for device IO, i.e. DMA operations, +* which may affect some PMD behavior. * @return * The pointer to the new allocated mempool, on success. NULL on error * with rte_errno set appropriately. Possible rte_errno values include:
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v2 2/4] mempool: add non-IO flag
29/09/2021 16:52, [email protected]:
Quoted 18 lines
From: Dmitry Kozlyuk <[email protected]>
Mempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add
MEMPOOL_F_NON_IOflag to mark such mempools.Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Matan Azrad <[email protected]>--- doc/guides/rel_notes/release_21_11.rst | 3 +++ lib/mempool/rte_mempool.h | 4 ++++ 2 files changed, 7 insertions(+)doc/guides/rel_notes/release_21_11.rst +0
-0
doc/guides/rel_notes/release_21_11.rst API Changes · line 156
Quoted 2 lines
doc/guides/rel_notes/release_21_11.rst +2
-0@@ -155,6 +155,9 @@ API Changes +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA).
This is not a breaking change, but I am OK to add this note. Any other opinion?
doc/guides/rel_notes/release_21_11.rst API Changes · line 161
Quoted 5 lines
doc/guides/rel_notes/release_21_11.rst +4
-0+#define MEMPOOL_F_NON_IO 0x0040 /**< Not used for device IO (DMA). */ + * - MEMPOOL_F_NO_IO: If set, the mempool is considered to be + * never used for device IO, i.e. DMA operations, + * which may affect some PMD behavior.
Not limited to PMD, it may affect some libs.
I would reword the last line like this:
"No impact on mempool behaviour, but it is a hint for other components."
Re: [dpdk-dev] [PATCH v2 2/4] mempool: add non-IO flag
Quoted 14 lines · Thomas Monjalon
29/09/2021 16:52, [email protected]:
Quoted 13 lines
From: Dmitry Kozlyuk <[email protected]>
Mempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add
MEMPOOL_F_NON_IOflag to mark such mempools.Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Matan Azrad <[email protected]>--- doc/guides/rel_notes/release_21_11.rst | 3 +++ lib/mempool/rte_mempool.h | 4 ++++ 2 files changed, 7 insertions(+)
Quoted 10 lines
doc/guides/rel_notes/release_21_11.rst API Changes · line 156
Quoted 7 lines
doc/guides/rel_notes/release_21_11.rst +2
-0@@ -155,6 +155,9 @@ API Changes +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA).This is not a breaking change, but I am OK to add this note. Any other opinion?
Why is it in API changes section? Shouldn't it be in "New Features"?
PATCH v2 3/4 common/mlx5: add mempool registration facilities
In reply to [email protected]From: Dmitry Kozlyuk <[email protected]>
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.
--- drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + 5 files changed, 666 insertions(+)
drivers/common/mlx5/mlx5_common_mp.c +50 -0
@@ -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. *
drivers/common/mlx5/mlx5_common_mp.h +14 -0
@@ -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 ,
@@ -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;
@@ -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;
@@ -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
drivers/common/mlx5/mlx5_common_mr.c +580 -0
596 lines not on this page · raw message
drivers/common/mlx5/mlx5_common_mr.h +17 -0
@@ -13,6 +13,7 @@#include <rte_rwlock.h> #include <rte_bitmap.h> +#include <rte_mbuf.h> #include <rte_memory.h> #include "mlx5_glue.h"
@@ -75,6 +76,7 @@ struct mlx5_mr_ctrl { } __rte_packed;LIST_HEAD (mlx5_mr_list, mlx5_mr); +LIST_HEAD (mlx5_mempool_reg_list, mlx5_mempool_reg);/* Global per-device MR cache. */ struct mlx5_mr_share_cache {
@@ -83,6 +85,7 @@ struct mlx5_mr_share_cache {struct mlx5_mr_btree cache;/* Global MR cache table. */ struct mlx5_mr_list mr_list;/* Registered MR list. */ struct mlx5_mr_list mr_free_list;/* Freed MR list. */ +struct mlx5_mempool_reg_list mempool_reg_list;/* Mempool database. */ mlx5_reg_mr_t reg_mr_cb;/* Callback to reg_mr func */ mlx5_dereg_mr_t dereg_mr_cb;/* Callback to dereg_mr func */ } __rte_packed;
@@ -136,6 +139,10 @@ uint32_t mlx5_mr_addr2mr_bh(void *pd, struct mlx5_mp_id *mp_id,struct mlx5_mr_ctrl *mr_ctrl, uintptr_t addr, unsigned int mr_ext_memseg_en);__rte_internal +uint32_t mlx5_mr_mempool2mr_bh(struct mlx5_mr_share_cache *share_cache, +struct mlx5_mr_ctrl *mr_ctrl, +struct rte_mempool *mp,uintptr_t addr); +__rte_internal void mlx5_mr_release_cache(struct mlx5_mr_share_cache *mr_cache);__rte_internal void mlx5_mr_dump_cache(struct mlx5_mr_share_cache *share_cache __rte_unused);
@@ -179,4 +186,14 @@ mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);__rte_internal voidmlx5_mr_free (struct mlx5_mr *mr,mlx5_dereg_mr_t dereg_mr_cb); + +__rte_internal +int +mlx5_mr_mempool_register (struct mlx5_mr_share_cache *share_cache,void *pd, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +__rte_internal +int +mlx5_mr_mempool_unregister (struct mlx5_mr_share_cache *share_cache, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +#endif /* RTE_PMD_MLX5_COMMON_MR_H_ */
drivers/common/mlx5/version.map +5 -0
@@ -149,4 +149,9 @@ INTERNAL { mlx5_realloc; mlx5_translate_port_name; # WINDOWS_NO_EXPORT + + mlx5_mr_mempool_register; + mlx5_mr_mempool_unregister; + mlx5_mp_req_mempool_reg; + mlx5_mr_mempool2mr_bh; };
Signature · 1 line
2.25.1
PATCH v2 4/4 net/mlx5: support mempool registration
In reply to [email protected]From: Dmitry Kozlyuk <[email protected]>
When the first port in a given protection domain (PD) starts, install a mempool event callback for this PD and register all existing memory regions (MR) for it. When the last port in a PD closes, remove the callback and unregister all mempools for this PD. This behavior can be switched off with a new devarg: mr_mempool_reg_en.
On TX slow path, i.e. when an MR key for the address of the buffer to send is not in the local cache, first try to retrieve it from the database of registered mempools. Supported are direct and indirect mbufs, as well as externally-attached ones from MLX5 MPRQ feature. Lookup in the database of non-mempool memory is used as the last resort.
RX mempools are registered regardless of the devarg value. On RX data path only the local cache and the mempool database is used. If implicit mempool registration is disabled, these mempools are unregistered at port stop, releasing the MRs.
--- doc/guides/nics/mlx5.rst | 11 ++ doc/guides/rel_notes/release_21_11.rst | 6 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 +++++++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 10 ++ drivers/net/mlx5/mlx5_mr.c | 120 +++++-------------- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 ++-- drivers/net/mlx5/mlx5_rxq.c | 13 +++ drivers/net/mlx5/mlx5_trigger.c | 77 +++++++++++-- drivers/net/mlx5/windows/mlx5_os.c | 1 + 12 files changed, 345 insertions(+), 116 deletions(-)
doc/guides/nics/mlx5.rst +11 -0
@@ -1001,6 +1001,17 @@ Driver options Enabled by default. +- ``mr_mempool_reg_en`` parameter [int] + + A nonzero value enables implicit registration of DMA memory of all mempools + except those having ``MEMPOOL_F_NON_IO``. The effect is that when a packet + from a mempool is transmitted, its memory is already registered for DMA + in the PMD and no registration will happen on the data path. The tradeoff is + extra work on the creation of each mempool and increased HW resource use + if some mempools are not used with MLX5 devices. + + Enabled by default. + - ``representor`` parameter [list] This parameter can be used to instantiate DPDK Ethernet devices from
doc/guides/rel_notes/release_21_11.rst +6 -0
@@ -106,6 +106,12 @@ New Features * Added tests to validate packets hard expiry. * Added tests to verify tunnel header verification in IPsec inbound. +* **Updated Mellanox mlx5 driver.** + + Updated the Mellanox mlx5 driver with new features and improvements, including: + + * Added implicit mempool registration to avoid data path hiccups (opt-out). + Removed Items -------------
drivers/net/mlx5/linux/mlx5_mp_os.c +44 -0
56 lines not on this page · raw message
drivers/net/mlx5/linux/mlx5_os.c +2 -2
@@ -1034,8 +1034,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, err =mlx5_proc_priv_init (eth_dev);if (err)return NULL ; - mp_id.port_id = eth_dev->data->port_id; -strlcpy (mp_id.name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +mlx5_mp_id_init (&mp_id, eth_dev->data->port_id);/* Receive command fd from primary process */ err =mlx5_mp_req_verbs_cmd_fd (&mp_id);if (err <0 )
@@ -2133,6 +2132,7 @@ mlx5_os_config_default(struct mlx5_dev_config *config) config->txqs_inline =MLX5_ARG_UNSET ; config->vf_nl_en =1 ; config->mr_ext_memseg_en =1 ; + config->mr_mempool_reg_en =1 ; config->mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; config->mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; config->dv_esw_en =1 ;
drivers/net/mlx5/mlx5.c +152 -0
188 lines not on this page · raw message
drivers/net/mlx5/mlx5.h +10 -0
@@ -155,6 +155,13 @@ struct mlx5_flow_dump_ack {/** Key string for IPC. */ #define MLX5_MP_NAME "net_mlx5_mp" +/** Initialize a multi-process ID. */ +static inline void +mlx5_mp_id_init (struct mlx5_mp_id *mp_id,uint16_t port_id) +{ + mp_id->port_id = port_id; +strlcpy (mp_id->name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +}LIST_HEAD (mlx5_dev_list, mlx5_dev_ctx_shared);
@@ -270,6 +277,8 @@ struct mlx5_dev_config { unsigned int dv_miss_info:1; /* restore packet after partial hw miss */ unsigned int allow_duplicate_pattern:1;/* Allow/Prevent the duplicate rules pattern. */ + unsigned int mr_mempool_reg_en:1; +/* Allow/prevent implicit mempool memory registration. */ struct {unsigned int enabled:1 ;/* Whether MPRQ is enabled. */ unsigned int stride_num_n;/* Number of strides. */
@@ -1497,6 +1506,7 @@ struct mlx5_dev_ctx_shared * mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, const struct mlx5_dev_config *config);void mlx5_free_shared_dev_ctx (struct mlx5_dev_ctx_shared *sh); +int mlx5_dev_ctx_shared_mempool_subscribe (struct rte_eth_dev *dev);void mlx5_free_table_hash_list (struct mlx5_priv *priv);int mlx5_alloc_table_hash_list (struct mlx5_priv *priv); void mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
drivers/net/mlx5/mlx5_mr.c +27 -93
138 lines not on this page · raw message
drivers/net/mlx5/mlx5_mr.h +0 -2
@@ -22,7 +22,5 @@void mlx5_mr_mem_event_cb (enum rte_mem_event event_type,const void *addr,size_t len,void *arg); -int mlx5_mr_update_mp (struct rte_eth_dev *dev,struct mlx5_mr_ctrl *mr_ctrl, -struct rte_mempool *mp);#endif /* RTE_PMD_MLX5_MR_H_ */
drivers/net/mlx5/mlx5_rx.h +14 -7
@@ -275,13 +275,11 @@ uint16_t mlx5_rx_burst_vec(void *dpdk_rxq, struct rte_mbuf **pkts,uint16_t mlx5_rx_burst_mprq_vec (void *dpdk_rxq,struct rte_mbuf **pkts,uint16_t pkts_n); -/* mlx5_mr.c */ - -uint32_t mlx5_rx_addr2mr_bh (struct mlx5_rxq_data *rxq,uintptr_t addr); +static int mlx5_rxq_mprq_enabled (struct mlx5_rxq_data *rxq);/** -* Query LKey from a packet buffer for Rx. No need to flush local caches for Rx -* as mempool is pre-configured and static. +* Query LKey from a packet buffer for Rx. No need to flush local caches +* as the Rx mempool database entries are valid for the lifetime of the queue. * * @param rxq * Pointer to Rx queue structure.
@@ -290,11 +288,14 @@ uint32_t mlx5_rx_addr2mr_bh(struct mlx5_rxq_data *rxq, uintptr_t addr);* * @return * Searched LKey on success, UINT32_MAX on no match. +* This function always succeeds on valid input. */ static __rte_always_inline uint32_tmlx5_rx_addr2mr (struct mlx5_rxq_data *rxq,uintptr_t addr) {struct mlx5_mr_ctrl *mr_ctrl = &rxq->mr_ctrl; +struct mlx5_rxq_ctrl *rxq_ctrl; +struct rte_mempool *mp;uint32_t lkey;/* Linear search on MR cache array. */
@@ -302,8 +303,14 @@ mlx5_rx_addr2mr(struct mlx5_rxq_data *rxq, uintptr_t addr) MLX5_MR_CACHE_N, addr);if (likely (lkey !=UINT32_MAX ))return lkey; -/* Take slower bottom-half (Binary Search) on miss. */ -return mlx5_rx_addr2mr_bh (rxq, addr); +/* +* Slower search in the mempool database on miss. +* During queue creation rxq->sh is not yet set, so we use rxq_ctrl. +*/ + rxq_ctrl = container_of(rxq, struct mlx5_rxq_ctrl, rxq); + mp =mlx5_rxq_mprq_enabled (rxq) ? rxq->mprq_mp : rxq->mp; +return mlx5_mr_mempool2mr_bh (&rxq_ctrl->priv->sh->share_cache, + mr_ctrl, mp, addr); }#define mlx5_rx_mb2mr (rxq, mb) mlx5_rx_addr2mr(rxq, (uintptr_t)((mb)->buf_addr))
drivers/net/mlx5/mlx5_rxq.c +13 -0
@@ -1165,6 +1165,7 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)unsigned int strd_sz_n =0 ;unsigned int i;unsigned int n_ibv =0 ; +int ret;if (!mlx5_mprq_enabled (dev))return 0 ;
@@ -1244,6 +1245,16 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev) rte_errno =ENOMEM ;return -rte_errno; } + ret =mlx5_mr_mempool_register (&priv->sh->share_cache, priv->sh->pd, + mp, &priv->mp_id); +if (ret <0 && rte_errno !=EEXIST ) { + ret = rte_errno; +DRV_LOG (ERR ,"port %u failed to register a mempool for Multi-Packet RQ" , + dev->data->port_id); +rte_mempool_free (mp); + rte_errno = ret; +return -rte_errno; + } priv->mprq_mp = mp; exit:/* Set mempool for each Rx queue. */
@@ -1446,6 +1457,8 @@ mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,/* rte_errno is already set. */ goto error; } +/* Rx queues don't use this pointer, but we want a valid structure. */ + tmpl->rxq.mr_ctrl.dev_gen_ptr = &priv->sh->share_cache.dev_gen; tmpl->socket = socket;if (dev->data->dev_conf.intr_conf.rxq) tmpl->irq =1 ;
drivers/net/mlx5/mlx5_trigger.c +65 -12
95 lines not on this page · raw message
drivers/net/mlx5/windows/mlx5_os.c +1 -0
@@ -1116,6 +1116,7 @@ mlx5_os_net_probe(struct rte_device *dev) dev_config.txqs_inline =MLX5_ARG_UNSET ; dev_config.vf_nl_en =0 ; dev_config.mr_ext_memseg_en =1 ; + dev_config.mr_mempool_reg_en =1 ; dev_config.mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; dev_config.mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; dev_config.dv_esw_en =0 ;
Signature · 1 line
2.25.1
v3 cover net/mlx5: implicit mempool registration
In reply to [email protected]MLX5 hardware has its internal IOMMU where PMD registers the memory. On the data path, PMD translates VA into a key consumed by the device IOMMU. It is impractical for the PMD to register all allocated memory because of increased lookup cost both in HW and SW. Most often mbuf memory comes from mempools, so if PMD tracks them, it can almost always have mbuf memory registered before an mbuf hits the PMD. This patchset adds such tracking in the PMD and internal API to support it.
Please see [1] for a more thorough explanation of the patch 2/4 and how it can be useful outside of the MLX5 PMD.
v3: Improve wording and naming; fix typos (Thomas).
v2 (internal review and testing):
1. Change tracked mempool event from being created (CREATE) to being fully populated (READY), which is the state PMD is interested in.
2. Unit test the new mempool callback API.
3. Remove bogus "error" messages in normal conditions.
4. Fixes in PMD.
Dmitry Kozlyuk (4):
mempool: add event callbacks
mempool: add non-IO flag
common/mlx5: add mempool registration facilities net/mlx5: support mempool registration
app/test/test_mempool.c | 75 ++++ doc/guides/nics/mlx5.rst | 11 + doc/guides/rel_notes/release_21_11.rst | 9 + drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 ++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++ drivers/net/mlx5/mlx5.h | 10 + drivers/net/mlx5/mlx5_mr.c | 120 ++--- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 +- drivers/net/mlx5/mlx5_rxq.c | 13 + drivers/net/mlx5/mlx5_trigger.c | 77 +++- drivers/net/mlx5/windows/mlx5_os.c | 1 + lib/mempool/rte_mempool.c | 137 ++++++ lib/mempool/rte_mempool.h | 60 +++ lib/mempool/version.map | 8 + 21 files changed, 1294 insertions(+), 116 deletions(-)
Signature · 1 line
2.25.1
PATCH v3 1/4 mempool: add event callbacks
Data path performance can benefit if the PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track creation and destruction of mempools after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Add an internal API to register callback for mempool life cycle events:
* rte_mempool_event_callback_register()
* rte_mempool_event_callback_unregister()
Currently tracked events are:
* RTE_MEMPOOL_EVENT_READY (after populating a mempool)
* RTE_MEMPOOL_EVENT_DESTROY (before freeing a mempool) Provide a unit test for the new API.
--- app/test/test_mempool.c | 75 +++++++++++++++++++++ lib/mempool/rte_mempool.c | 137 ++++++++++++++++++++++++++++++++++++++ lib/mempool/rte_mempool.h | 56 ++++++++++++++++ lib/mempool/version.map | 8 +++ 4 files changed, 276 insertions(+)
app/test/test_mempool.c +75 -0
@@ -14,6 +14,7 @@#include <rte_common.h> #include <rte_log.h> #include <rte_debug.h> +#include <rte_errno.h> #include <rte_memory.h> #include <rte_launch.h> #include <rte_cycles.h>
@@ -471,6 +472,74 @@ test_mp_mem_init(struct rte_mempool *mp, data->ret =0 ; } +struct test_mempool_events_data { +struct rte_mempool *mp; +enum rte_mempool_event event; +bool invoked; +}; + +static void +test_mempool_events_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *arg) +{ +struct test_mempool_events_data *data = arg; + + data->mp = mp; + data->event = event; + data->invoked = true; +} + +static int +test_mempool_events (int (*populate)(struct rte_mempool *mp)) +{ +struct test_mempool_events_data data; +struct rte_mempool *mp; +int ret; + + ret =rte_mempool_event_callback_register (NULL , &data); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Registered a NULL callback" ); + +memset (&data,0 ,sizeof (data)); + ret =rte_mempool_event_callback_register (test_mempool_events_cb, + &data); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to register the callback: %s" , +rte_strerror (rte_errno)); + + mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create an empty mempool: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data.invoked, false, +"Callback invoked on an empty mempool creation" ); + +rte_mempool_set_ops_byname (mp,rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp->size,"Failed to populate the mempool: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data.invoked, true, +"Callback not invoked on an empty mempool population" ); +RTE_TEST_ASSERT_EQUAL (data.event,RTE_MEMPOOL_EVENT_READY , +"Wrong callback invoked, expected READY" ); +RTE_TEST_ASSERT_EQUAL (data.mp, mp, +"Callback invoked for a wrong mempool" ); + +memset (&data,0 ,sizeof (data)); +rte_mempool_free (mp); +RTE_TEST_ASSERT_EQUAL (data.invoked, true, +"Callback not invoked on mempool destruction" ); +RTE_TEST_ASSERT_EQUAL (data.event,RTE_MEMPOOL_EVENT_DESTROY , +"Wrong callback invoked, expected DESTROY" ); +RTE_TEST_ASSERT_EQUAL (data.mp, mp, +"Callback invoked for a wrong mempool" ); + + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, + &data); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister the callback: %s" , +rte_strerror (rte_errno)); +return 0 ; +} +static int test_mempool (void ) {
@@ -645,6 +714,12 @@ test_mempool(void)if (test_mempool_basic (default_pool,1 ) <0 )GOTO_ERR (ret, err); +/* test mempool event callbacks */ +if (test_mempool_events (rte_mempool_populate_default) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events (rte_mempool_populate_anon) <0 ) +GOTO_ERR (ret, err); +rte_mempool_list_dump (stdout); ret =0 ;
lib/mempool/rte_mempool.c +137 -0
158 lines not on this page · raw message
lib/mempool/rte_mempool.h +56 -0
62 lines not on this page · raw message
lib/mempool/version.map +8 -0
@@ -64,3 +64,11 @@ EXPERIMENTAL { __rte_mempool_trace_ops_free; __rte_mempool_trace_set_ops_byname; }; + +INTERNAL { + global: + + # added in 21.11 + rte_mempool_event_callback_register; + rte_mempool_event_callback_unregister; +};
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v3 1/4] mempool: add event callbacks
Quoted 8 lines · Dmitry Kozlyuk
Data path performance can benefit if the PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track creation and destruction of mempools after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Quoted 7 lines
Add an internal API to register callback for mempool life cycle events:
*rte_mempool_event_callback_register()
*rte_mempool_event_callback_unregister()
Currently tracked events are:
*RTE_MEMPOOL_EVENT_READY(after populating a mempool)
*RTE_MEMPOOL_EVENT_DESTROY(before freeing a mempool) Provide a unit test for the new API.
Good idea.
Quoted 2 lines
Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Matan Azrad <[email protected]>
[snip]
I think it would be very useful to test two callbacks as well including new mempool creation after one of callbacks unregister. Plus register/unregister callbacks from a callback itself. Feel free to drop it, since increasing test coverage is almost endless :)
Quoted 5 lines
lib/mempool/rte_mempool.h +0
-0
lib/mempool/rte_mempool.h void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg), · line 1782
Quoted 9 lines
lib/mempool/rte_mempool.h +6
-0@@ -1774,6 +1774,62 @@ void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),int rte_mempool_get_page_size (struct rte_mempool *mp,size_t *pg_sz); +/** +* Mempool event type. +* @internal +*/ +enum rte_mempool_event { +/** Occurs after a mempool is successfully populated. */
successfully -> fully ?
Quoted 6 lines
lib/mempool/rte_mempool.h +6
-0+RTE_MEMPOOL_EVENT_READY =0 , +/** Occurs before destruction of a mempool begins. */ + RTE_MEMPOOL_EVENT_DESTROY = 1, +}; + +/**
lib/mempool/rte_mempool.h void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg), · line 1798
Quoted 10 lines
lib/mempool/rte_mempool.h +10
-0+* @internal +* Mempool event callback. +*/ +typedef void (rte_mempool_event_callback )( +enum rte_mempool_event event, +struct rte_mempool *mp, +void *user_data); + +/** +* @internal
I'd like to understand why the API is internal (not experimental). I think reasons should be clear from function description.
Quoted 54 lines
lib/mempool/rte_mempool.h +34
-0+* Register a callback invoked on mempool life cycle event. +* Callbacks will be invoked in the process that creates the mempool. +* +* @param func +* Callback function. +* @param user_data +* User data. +* +* @return +* 0 on success, negative on failure and rte_errno is set. +*/ +__rte_internal +int +rte_mempool_event_callback_register (rte_mempool_event_callback *func, +void *user_data); + +/** +* @internal +* Unregister a callback added with rte_mempool_event_callback_register(). +* @p func and @p user_data must exactly match registration parameters. +* +* @param func +* Callback function. +* @param user_data +* User data. +* +* @return +* 0 on success, negative on failure and rte_errno is set. +*/ +__rte_internal +int +rte_mempool_event_callback_unregister (rte_mempool_event_callback *func, +void *user_data); + #ifdef __cplusplus }#endif lib/mempool/version.map +8
-0@@ -64,3 +64,11 @@ EXPERIMENTAL { __rte_mempool_trace_ops_free; __rte_mempool_trace_set_ops_byname; }; + +INTERNAL { + global: + + # added in 21.11 + rte_mempool_event_callback_register; + rte_mempool_event_callback_unregister; +};
Re: [dpdk-dev] [PATCH v3 1/4] mempool: add event callbacks
Quoted 7 lines · Dmitry Kozlyuk
Quoted 2 lines
Data path performance can benefit if the PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD.
[...]
I'd like to understand why the API is internal (not experimental). I think reasons should be clear from function description.
My reasoning was that PMDs need this API while applications don't. PMDs may need to deal with any mempools and don't control their creation, while the application knows which mempools it creates and doesn't care about internal mempools PMDs might create. But maybe I was wrong and there are applications that want to use mbufs from those internal mempools for non-DPDK IO, something SPDK-like. I'll add a note about that in the description and make them experimental.
Re: [dpdk-dev] [PATCH v3 1/4] mempool: add event callbacks
Quoted 10 lines · Dmitry Kozlyuk
Quoted 7 lines · Dmitry Kozlyuk
Quoted 2 lines
Data path performance can benefit if the PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD.
[...]
I'd like to understand why the API is internal (not experimental). I think reasons should be clear from function description.
My reasoning was that PMDs need this API while applications don't. PMDs may need to deal with any mempools and don't control their creation, while the application knows which mempools it creates and doesn't care about internal mempools PMDs might create. But maybe I was wrong and there are applications that want to use mbufs from those internal mempools for non-DPDK IO, something SPDK-like. I'll add a note about that in the description and make them experimental.
It is a good explanation. Thanks.
May be it is safer to keep it internal until
we find the first external user.
PATCH v3 2/4 mempool: add non-IO flag
In reply to Dmitry KozlyukMempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add MEMPOOL_F_NON_IO flag to mark such mempools.
Discussion: https://mails.dpdk.org/archives/dev/2021-August/216654.html
--- doc/guides/rel_notes/release_21_11.rst | 3 +++ lib/mempool/rte_mempool.h | 4 ++++ 2 files changed, 7 insertions(+)
doc/guides/rel_notes/release_21_11.rst +3 -0
@@ -208,6 +208,9 @@ API Changes the crypto/security operation. This field will be used to communicate events such as soft expiry with IPsec in lookaside mode. +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA). + ABI Changes -----------
lib/mempool/rte_mempool.h +4 -0
@@ -262,6 +262,7 @@ struct rte_mempool {#define MEMPOOL_F_SC_GET 0x0008/**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010/**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020/**< Don't need IOVA contiguous objs. */ +#define MEMPOOL_F_NON_IO 0x0040/**< Not used for device IO (DMA). */ /** * @internal When debug is enabled, store some statistics.
@@ -991,6 +992,9 @@ typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);* "single-consumer". Otherwise, it is "multi-consumers". * - MEMPOOL_F_NO_IOVA_CONTIG: If set, allocated objects won't * necessarily be contiguous in IO memory. +* - MEMPOOL_F_NON_IO: If set, the mempool is considered to be +* never used for device IO, i.e. for DMA operations. +* It's a hint to other components and does not affect the mempool behavior. * @return * The pointer to the new allocated mempool, on success. NULL on error * with rte_errno set appropriately. Possible rte_errno values include:
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v3 2/4] mempool: add non-IO flag
Quoted 32 lines · Dmitry Kozlyuk
Mempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add
MEMPOOL_F_NON_IOflag to mark such mempools.
Discussion: https://mails.dpdk.org/archives/dev/2021-August/216654.htmlSigned-off-by Dmitry Kozlyuk <[email protected]>Acked-by Matan Azrad <[email protected]>--- doc/guides/rel_notes/release_21_11.rst | 3 +++ lib/mempool/rte_mempool.h | 4 ++++ 2 files changed, 7 insertions(+)doc/guides/rel_notes/release_21_11.rst +3
-0@@ -208,6 +208,9 @@ API Changes the crypto/security operation. This field will be used to communicate events such as soft expiry with IPsec in lookaside mode. +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA). + ABI Changes -----------lib/mempool/rte_mempool.h +0
-0
lib/mempool/rte_mempool.h struct rte_mempool { · line 265
Quoted 4 lines
lib/mempool/rte_mempool.h +1
-0@@ -262,6 +262,7 @@ struct rte_mempool {#define MEMPOOL_F_SC_GET 0x0008/**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010/**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020/**< Don't need IOVA contiguous objs. */ +#define MEMPOOL_F_NON_IO 0x0040/**< Not used for device IO (DMA). */
Since it is the hint, How about changing the flag to MEMPOOL_F_HINT_NON_IO. Otherwise, it looks good to me.
Quoted 16 lines
lib/mempool/rte_mempool.h +3
-1/** * @internal When debug is enabled, store some statistics. @@ -991,6 +992,9 @@ typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);* "single-consumer". Otherwise, it is "multi-consumers". * - MEMPOOL_F_NO_IOVA_CONTIG: If set, allocated objects won't * necessarily be contiguous in IO memory. +* - MEMPOOL_F_NON_IO: If set, the mempool is considered to be +* never used for device IO, i.e. for DMA operations. +* It's a hint to other components and does not affect the mempool behavior. * @return * The pointer to the new allocated mempool, on success. NULL on error * with rte_errno set appropriately. Possible rte_errno values include: -- 2.25.1
Re: [dpdk-dev] [PATCH v3 2/4] mempool: add non-IO flag
In reply to Dmitry KozlyukQuoted 31 lines · Dmitry Kozlyuk
Mempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add
MEMPOOL_F_NON_IOflag to mark such mempools.
Discussion: https://mails.dpdk.org/archives/dev/2021-August/216654.htmlSigned-off-by Dmitry Kozlyuk <[email protected]>Acked-by Matan Azrad <[email protected]>--- doc/guides/rel_notes/release_21_11.rst | 3 +++ lib/mempool/rte_mempool.h | 4 ++++ 2 files changed, 7 insertions(+)doc/guides/rel_notes/release_21_11.rst +3
-0@@ -208,6 +208,9 @@ API Changes the crypto/security operation. This field will be used to communicate events such as soft expiry with IPsec in lookaside mode. +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA). + ABI Changes -----------lib/mempool/rte_mempool.h +0
-0
lib/mempool/rte_mempool.h struct rte_mempool { · line 265
Quoted 4 lines
lib/mempool/rte_mempool.h +1
-0@@ -262,6 +262,7 @@ struct rte_mempool {#define MEMPOOL_F_SC_GET 0x0008/**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010/**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020/**< Don't need IOVA contiguous objs. */ +#define MEMPOOL_F_NON_IO 0x0040/**< Not used for device IO (DMA). */
Doesn't it imply MEMPOOL_F_NO_IOVA_CONTIG? Shouldn't it reject mempool population with not RTE_BAD_IOVA iova parameter?
I see that it is just a hint, but just trying to make full picture consistent.
As the second thought: isn't iova==RTE_BAD_IOVA
sufficient as a hint?
Quoted 14 lines
lib/mempool/rte_mempool.h +3
-0/** * @internal When debug is enabled, store some statistics. @@ -991,6 +992,9 @@ typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);* "single-consumer". Otherwise, it is "multi-consumers". * - MEMPOOL_F_NO_IOVA_CONTIG: If set, allocated objects won't * necessarily be contiguous in IO memory. +* - MEMPOOL_F_NON_IO: If set, the mempool is considered to be +* never used for device IO, i.e. for DMA operations. +* It's a hint to other components and does not affect the mempool behavior. * @return * The pointer to the new allocated mempool, on success. NULL on error * with rte_errno set appropriately. Possible rte_errno values include:
Re: [dpdk-dev] [PATCH v3 2/4] mempool: add non-IO flag
Quoted 5 lines
[...]
Quoted 1 line
+#define
MEMPOOL_F_NON_IO0x0040/**< Not used for device IO(DMA). */
Doesn't it imply
MEMPOOL_F_NO_IOVA_CONTIG?
Let's leave this explicit. NO_IOVA_CONFIG could result in MEMZONE_IOVA_CONTIG (although it doesn't now), which can affect how many pages are used, which may affect performance due to TLB caches.
Quoted 6 lines
Shouldn't it reject mempool population with not
RTE_BAD_IOVAiova parameter?I see that it is just a hint, but just trying to make full picture consistent.
As the second thought: isn't iova==RTE_BAD_IOVA sufficient as a hint?
1. It looks true that if RTE_BAD_IOVA is used, we can infer it's a non-IO mempool.
2. The new flag is needed or at least handly, because otherwise to check this property of a mempool, but how? Allocating a test mbuf is doable but looks like a hack. Or we can pass this information to the callback, complicating its signature. Do you think it's better?
3. Theoretically, user may want to use mempools for objects that are used for IO, but not with DPDK. In this case IOVA will be valid, but the flag can also be set.
So I'd keep the flag and also infer it for RTE_BAD_IOVA, but allow normal IOVA. What do you think?
Re: [dpdk-dev] [PATCH v3 2/4] mempool: add non-IO flag
Quoted 7 lines · Dmitry Kozlyuk
Quoted 5 lines
[...]
Quoted 1 line
+#define
MEMPOOL_F_NON_IO0x0040/**< Not used for device IO(DMA). */
Doesn't it imply
MEMPOOL_F_NO_IOVA_CONTIG?Let's leave this explicit.
NO_IOVA_CONFIGcould result inMEMZONE_IOVA_CONTIG(although it doesn't now), which can affect how many pages are used, which may affect performance due to TLB caches.
It sounds like a usage of a side effect of MEMPOOL_F_NO_IOVA_CONTIG absence. It does not sound good.
Quoted 10 lines
Quoted 7 lines
Shouldn't it reject mempool population with not
RTE_BAD_IOVAiova parameter?I see that it is just a hint, but just trying to make full picture consistent.
As the second thought: isn't iova==RTE_BAD_IOVA sufficient as a hint?
1. It looks true that if
RTE_BAD_IOVAis used, we can infer it's a non-IO mempool.
2. The new flag is needed or at least handly, because otherwise to check this property of a mempool, but how? Allocating a test mbuf is doable but looks like a hack. Or we can pass this information to the callback, complicating its signature. Do you think it's better?
mempool knows it when the mempool is populated. So, it can just set the flag itself.
Quoted 1 line
3. Theoretically, user may want to use mempools for objects that are used for IO, but not with DPDK. In this case IOVA will be valid, but the flag can also be set.
It sounds very artificial. Also in this case I guess MEMPOOL_F_NON_IO should be clear anyway.
Quoted 4 lines
So I'd keep the flag and also infer it for
RTE_BAD_IOVA, but allow normal IOVA. What do you think?
Re: [dpdk-dev] [PATCH v3 2/4] mempool: add non-IO flag
Quoted 16 lines
-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: 12 октября 2021 г. 15:53
To: Dmitry Kozlyuk <[email protected]>; [email protected]
Cc: NBU-Contact-Thomas Monjalon <[email protected]>; Matan Azrad <[email protected]>; Olivier Matz <[email protected]>
Subject: Re: [PATCH v3 2/4] mempool: add non-IO flagExternal email: Use caution opening links or attachments
Quoted 4 lines · Dmitry Kozlyuk
Quoted 4 lines
[...]
Quoted 1 line
+#define
MEMPOOL_F_NON_IO0x0040/**< Not used for device IO(DMA). */
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Doesn't it imply
MEMPOOL_F_NO_IOVA_CONTIG?Let's leave this explicit.
NO_IOVA_CONFIGcould result in
MEMZONE_IOVA_CONTIG(although it doesn't now), which can affect how many pages are used, which may affect performance due to TLB caches.It sounds like a usage of a side effect of
MEMPOOL_F_NO_IOVA_CONTIGabsence. It does not sound good.
I agree, but my point is that behavior should not change when specifying a hint flag. NO_IOVA_CONTIG => NON_IO is feasible, NON_IO => NO_IOVA_CONTIG is against the declared NON_IO properties.
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Shouldn't it reject mempool population with not
RTE_BAD_IOVAiova parameter?I see that it is just a hint, but just trying to make full picture consistent.
As the second thought: isn't iova==RTE_BAD_IOVA sufficient as a hint?
1. It looks true that if
RTE_BAD_IOVAis used, we can infer it's a non-IO
Quoted 8 lines
mempool.
Quoted 1 line
2. The new flag is needed or at least handly, because otherwise to check this
property of a mempool, but how? Allocating a test mbuf is doable but looks like a hack. Or we can pass this information to the callback, complicating its signature. Do you think it's better?
mempool knows it when the mempool is populated.
So, it can just set the flag itself.
Of course, I'm only arguing that to analyze mempool properties this flag is needed, even if the user isn't supposed to set it themselves. Looks like we agree on this one.
Quoted 6 lines
Quoted 1 line
3. Theoretically, user may want to use mempools for objects that are used for
IO, but not with DPDK. In this case IOVA will be valid, but the flag can also be set.
It sounds very artificial.
Also in this case I guessMEMPOOL_F_NON_IOshould be clear anyway.
I see NON_IO as a hint to DPDK components, not sure about non-DPDK ones. But since there isn't a use case indeed, the flag doesn't need to eb exposed now.
To summarize:
1. MEMPOOL_F_NON_IO is considered internal, like MEMPOOL_F_CREATED.
2. It is set automatically:
a) for MEMPOOL_F_NO_IOVA_CONTIG mempools;
b) if RTE_BAD_IOVA is used to populate.
I doubt HINT should be added to the name, because it's not a hint, it's a conclusion.
PATCH v3 3/4 common/mlx5: add mempool registration facilities
In reply to Dmitry KozlyukAdd 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.
--- drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + 5 files changed, 666 insertions(+)
drivers/common/mlx5/mlx5_common_mp.c +50 -0
@@ -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. *
drivers/common/mlx5/mlx5_common_mp.h +14 -0
@@ -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 ,
@@ -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;
@@ -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;
@@ -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
drivers/common/mlx5/mlx5_common_mr.c +580 -0
596 lines not on this page · raw message
drivers/common/mlx5/mlx5_common_mr.h +17 -0
@@ -13,6 +13,7 @@#include <rte_rwlock.h> #include <rte_bitmap.h> +#include <rte_mbuf.h> #include <rte_memory.h> #include "mlx5_glue.h"
@@ -75,6 +76,7 @@ struct mlx5_mr_ctrl { } __rte_packed;LIST_HEAD (mlx5_mr_list, mlx5_mr); +LIST_HEAD (mlx5_mempool_reg_list, mlx5_mempool_reg);/* Global per-device MR cache. */ struct mlx5_mr_share_cache {
@@ -83,6 +85,7 @@ struct mlx5_mr_share_cache {struct mlx5_mr_btree cache;/* Global MR cache table. */ struct mlx5_mr_list mr_list;/* Registered MR list. */ struct mlx5_mr_list mr_free_list;/* Freed MR list. */ +struct mlx5_mempool_reg_list mempool_reg_list;/* Mempool database. */ mlx5_reg_mr_t reg_mr_cb;/* Callback to reg_mr func */ mlx5_dereg_mr_t dereg_mr_cb;/* Callback to dereg_mr func */ } __rte_packed;
@@ -136,6 +139,10 @@ uint32_t mlx5_mr_addr2mr_bh(void *pd, struct mlx5_mp_id *mp_id,struct mlx5_mr_ctrl *mr_ctrl, uintptr_t addr, unsigned int mr_ext_memseg_en);__rte_internal +uint32_t mlx5_mr_mempool2mr_bh(struct mlx5_mr_share_cache *share_cache, +struct mlx5_mr_ctrl *mr_ctrl, +struct rte_mempool *mp,uintptr_t addr); +__rte_internal void mlx5_mr_release_cache(struct mlx5_mr_share_cache *mr_cache);__rte_internal void mlx5_mr_dump_cache(struct mlx5_mr_share_cache *share_cache __rte_unused);
@@ -179,4 +186,14 @@ mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);__rte_internal voidmlx5_mr_free (struct mlx5_mr *mr,mlx5_dereg_mr_t dereg_mr_cb); + +__rte_internal +int +mlx5_mr_mempool_register (struct mlx5_mr_share_cache *share_cache,void *pd, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +__rte_internal +int +mlx5_mr_mempool_unregister (struct mlx5_mr_share_cache *share_cache, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +#endif /* RTE_PMD_MLX5_COMMON_MR_H_ */
drivers/common/mlx5/version.map +5 -0
@@ -152,4 +152,9 @@ INTERNAL { mlx5_realloc; mlx5_translate_port_name; # WINDOWS_NO_EXPORT + + mlx5_mr_mempool_register; + mlx5_mr_mempool_unregister; + mlx5_mp_req_mempool_reg; + mlx5_mr_mempool2mr_bh; };
Signature · 1 line
2.25.1
PATCH v3 4/4 net/mlx5: support mempool registration
In reply to Dmitry KozlyukWhen the first port in a given protection domain (PD) starts, install a mempool event callback for this PD and register all existing memory regions (MR) for it. When the last port in a PD closes, remove the callback and unregister all mempools for this PD. This behavior can be switched off with a new devarg: mr_mempool_reg_en.
On TX slow path, i.e. when an MR key for the address of the buffer to send is not in the local cache, first try to retrieve it from the database of registered mempools. Supported are direct and indirect mbufs, as well as externally-attached ones from MLX5 MPRQ feature. Lookup in the database of non-mempool memory is used as the last resort.
RX mempools are registered regardless of the devarg value. On RX data path only the local cache and the mempool database is used. If implicit mempool registration is disabled, these mempools are unregistered at port stop, releasing the MRs.
--- doc/guides/nics/mlx5.rst | 11 ++ doc/guides/rel_notes/release_21_11.rst | 6 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 +++++++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 10 ++ drivers/net/mlx5/mlx5_mr.c | 120 +++++-------------- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 ++-- drivers/net/mlx5/mlx5_rxq.c | 13 +++ drivers/net/mlx5/mlx5_trigger.c | 77 +++++++++++-- drivers/net/mlx5/windows/mlx5_os.c | 1 + 12 files changed, 345 insertions(+), 116 deletions(-)
doc/guides/nics/mlx5.rst +11 -0
@@ -1001,6 +1001,17 @@ Driver options Enabled by default. +- ``mr_mempool_reg_en`` parameter [int] + + A nonzero value enables implicit registration of DMA memory of all mempools + except those having ``MEMPOOL_F_NON_IO``. The effect is that when a packet + from a mempool is transmitted, its memory is already registered for DMA + in the PMD and no registration will happen on the data path. The tradeoff is + extra work on the creation of each mempool and increased HW resource use + if some mempools are not used with MLX5 devices. + + Enabled by default. + - ``representor`` parameter [list] This parameter can be used to instantiate DPDK Ethernet devices from
doc/guides/rel_notes/release_21_11.rst +6 -0
@@ -141,6 +141,12 @@ New Features * Added tests to validate packets hard expiry. * Added tests to verify tunnel header verification in IPsec inbound. +* **Updated Mellanox mlx5 driver.** + + Updated the Mellanox mlx5 driver with new features and improvements, including: + + * Added implicit mempool registration to avoid data path hiccups (opt-out). + Removed Items -------------
drivers/net/mlx5/linux/mlx5_mp_os.c +44 -0
56 lines not on this page · raw message
drivers/net/mlx5/linux/mlx5_os.c +2 -2
@@ -1034,8 +1034,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, err =mlx5_proc_priv_init (eth_dev);if (err)return NULL ; - mp_id.port_id = eth_dev->data->port_id; -strlcpy (mp_id.name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +mlx5_mp_id_init (&mp_id, eth_dev->data->port_id);/* Receive command fd from primary process */ err =mlx5_mp_req_verbs_cmd_fd (&mp_id);if (err <0 )
@@ -2133,6 +2132,7 @@ mlx5_os_config_default(struct mlx5_dev_config *config) config->txqs_inline =MLX5_ARG_UNSET ; config->vf_nl_en =1 ; config->mr_ext_memseg_en =1 ; + config->mr_mempool_reg_en =1 ; config->mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; config->mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; config->dv_esw_en =1 ;
drivers/net/mlx5/mlx5.c +152 -0
188 lines not on this page · raw message
drivers/net/mlx5/mlx5.h +10 -0
@@ -155,6 +155,13 @@ struct mlx5_flow_dump_ack {/** Key string for IPC. */ #define MLX5_MP_NAME "net_mlx5_mp" +/** Initialize a multi-process ID. */ +static inline void +mlx5_mp_id_init (struct mlx5_mp_id *mp_id,uint16_t port_id) +{ + mp_id->port_id = port_id; +strlcpy (mp_id->name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +}LIST_HEAD (mlx5_dev_list, mlx5_dev_ctx_shared);
@@ -270,6 +277,8 @@ struct mlx5_dev_config { unsigned int dv_miss_info:1; /* restore packet after partial hw miss */ unsigned int allow_duplicate_pattern:1;/* Allow/Prevent the duplicate rules pattern. */ + unsigned int mr_mempool_reg_en:1; +/* Allow/prevent implicit mempool memory registration. */ struct {unsigned int enabled:1 ;/* Whether MPRQ is enabled. */ unsigned int stride_num_n;/* Number of strides. */
@@ -1498,6 +1507,7 @@ struct mlx5_dev_ctx_shared * mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, const struct mlx5_dev_config *config);void mlx5_free_shared_dev_ctx (struct mlx5_dev_ctx_shared *sh); +int mlx5_dev_ctx_shared_mempool_subscribe (struct rte_eth_dev *dev);void mlx5_free_table_hash_list (struct mlx5_priv *priv);int mlx5_alloc_table_hash_list (struct mlx5_priv *priv); void mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
drivers/net/mlx5/mlx5_mr.c +27 -93
138 lines not on this page · raw message
drivers/net/mlx5/mlx5_mr.h +0 -2
@@ -22,7 +22,5 @@void mlx5_mr_mem_event_cb (enum rte_mem_event event_type,const void *addr,size_t len,void *arg); -int mlx5_mr_update_mp (struct rte_eth_dev *dev,struct mlx5_mr_ctrl *mr_ctrl, -struct rte_mempool *mp);#endif /* RTE_PMD_MLX5_MR_H_ */
drivers/net/mlx5/mlx5_rx.h +14 -7
@@ -275,13 +275,11 @@ uint16_t mlx5_rx_burst_vec(void *dpdk_rxq, struct rte_mbuf **pkts,uint16_t mlx5_rx_burst_mprq_vec (void *dpdk_rxq,struct rte_mbuf **pkts,uint16_t pkts_n); -/* mlx5_mr.c */ - -uint32_t mlx5_rx_addr2mr_bh (struct mlx5_rxq_data *rxq,uintptr_t addr); +static int mlx5_rxq_mprq_enabled (struct mlx5_rxq_data *rxq);/** -* Query LKey from a packet buffer for Rx. No need to flush local caches for Rx -* as mempool is pre-configured and static. +* Query LKey from a packet buffer for Rx. No need to flush local caches +* as the Rx mempool database entries are valid for the lifetime of the queue. * * @param rxq * Pointer to Rx queue structure.
@@ -290,11 +288,14 @@ uint32_t mlx5_rx_addr2mr_bh(struct mlx5_rxq_data *rxq, uintptr_t addr);* * @return * Searched LKey on success, UINT32_MAX on no match. +* This function always succeeds on valid input. */ static __rte_always_inline uint32_tmlx5_rx_addr2mr (struct mlx5_rxq_data *rxq,uintptr_t addr) {struct mlx5_mr_ctrl *mr_ctrl = &rxq->mr_ctrl; +struct mlx5_rxq_ctrl *rxq_ctrl; +struct rte_mempool *mp;uint32_t lkey;/* Linear search on MR cache array. */
@@ -302,8 +303,14 @@ mlx5_rx_addr2mr(struct mlx5_rxq_data *rxq, uintptr_t addr) MLX5_MR_CACHE_N, addr);if (likely (lkey !=UINT32_MAX ))return lkey; -/* Take slower bottom-half (Binary Search) on miss. */ -return mlx5_rx_addr2mr_bh (rxq, addr); +/* +* Slower search in the mempool database on miss. +* During queue creation rxq->sh is not yet set, so we use rxq_ctrl. +*/ + rxq_ctrl = container_of(rxq, struct mlx5_rxq_ctrl, rxq); + mp =mlx5_rxq_mprq_enabled (rxq) ? rxq->mprq_mp : rxq->mp; +return mlx5_mr_mempool2mr_bh (&rxq_ctrl->priv->sh->share_cache, + mr_ctrl, mp, addr); }#define mlx5_rx_mb2mr (rxq, mb) mlx5_rx_addr2mr(rxq, (uintptr_t)((mb)->buf_addr))
drivers/net/mlx5/mlx5_rxq.c +13 -0
@@ -1162,6 +1162,7 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)unsigned int strd_sz_n =0 ;unsigned int i;unsigned int n_ibv =0 ; +int ret;if (!mlx5_mprq_enabled (dev))return 0 ;
@@ -1241,6 +1242,16 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev) rte_errno =ENOMEM ;return -rte_errno; } + ret =mlx5_mr_mempool_register (&priv->sh->share_cache, priv->sh->pd, + mp, &priv->mp_id); +if (ret <0 && rte_errno !=EEXIST ) { + ret = rte_errno; +DRV_LOG (ERR ,"port %u failed to register a mempool for Multi-Packet RQ" , + dev->data->port_id); +rte_mempool_free (mp); + rte_errno = ret; +return -rte_errno; + } priv->mprq_mp = mp; exit:/* Set mempool for each Rx queue. */
@@ -1443,6 +1454,8 @@ mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,/* rte_errno is already set. */ goto error; } +/* Rx queues don't use this pointer, but we want a valid structure. */ + tmpl->rxq.mr_ctrl.dev_gen_ptr = &priv->sh->share_cache.dev_gen; tmpl->socket = socket;if (dev->data->dev_conf.intr_conf.rxq) tmpl->irq =1 ;
drivers/net/mlx5/mlx5_trigger.c +65 -12
95 lines not on this page · raw message
drivers/net/mlx5/windows/mlx5_os.c +1 -0
@@ -1116,6 +1116,7 @@ mlx5_os_net_probe(struct rte_device *dev) dev_config.txqs_inline =MLX5_ARG_UNSET ; dev_config.vf_nl_en =0 ; dev_config.mr_ext_memseg_en =1 ; + dev_config.mr_mempool_reg_en =1 ; dev_config.mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; dev_config.mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; dev_config.dv_esw_en =0 ;
Signature · 1 line
2.25.1
v4 cover net/mlx5: implicit mempool registration
In reply to Dmitry KozlyukMLX5 hardware has its internal IOMMU where PMD registers the memory. On the data path, PMD translates VA into a key consumed by the device IOMMU. It is impractical for the PMD to register all allocated memory because of increased lookup cost both in HW and SW. Most often mbuf memory comes from mempools, so if PMD tracks them, it can almost always have mbuf memory registered before an mbuf hits the PMD. This patchset adds such tracking in the PMD and internal API to support it.
Please see [1] for the discussion of the patch 2/4 and how it can be useful outside of the MLX5 PMD.
v4: (Andrew)
1. Improve mempool event callbacks unit tests and documentation.
2. Make MEMPOOL_F_NON_IO internal and automatically inferred. Add unit tests for the inference logic.
v3: Improve wording and naming; fix typos (Thomas).
v2 (internal review and testing):
1. Change tracked mempool event from being created (CREATE) to being fully populated (READY), which is the state PMD is interested in.
2. Unit test the new mempool callback API.
3. Remove bogus "error" messages in normal conditions.
4. Fixes in PMD.
Dmitry Kozlyuk (4):
mempool: add event callbacks
mempool: add non-IO flag
common/mlx5: add mempool registration facilities net/mlx5: support mempool registration
app/test/test_mempool.c | 285 ++++++++++++ doc/guides/nics/mlx5.rst | 13 + doc/guides/rel_notes/release_21_11.rst | 9 + drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 ++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++ drivers/net/mlx5/mlx5.h | 10 + drivers/net/mlx5/mlx5_mr.c | 120 ++--- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 +- drivers/net/mlx5/mlx5_rxq.c | 13 + drivers/net/mlx5/mlx5_trigger.c | 77 +++- drivers/net/mlx5/windows/mlx5_os.c | 1 + lib/mempool/rte_mempool.c | 139 ++++++ lib/mempool/rte_mempool.h | 66 +++ lib/mempool/version.map | 8 + 21 files changed, 1514 insertions(+), 116 deletions(-)
Signature · 1 line
2.25.1
PATCH v4 1/4 mempool: add event callbacks
Data path performance can benefit if the PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track creation and destruction of mempools after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Add an API to register callback for mempool life cycle events:
* rte_mempool_event_callback_register()
* rte_mempool_event_callback_unregister()
Currently tracked events are:
* RTE_MEMPOOL_EVENT_READY (after populating a mempool)
* RTE_MEMPOOL_EVENT_DESTROY (before freeing a mempool) Provide a unit test for the new API.
The new API is internal, because it is primarily demanded by PMDs that may need to deal with any mempools and do not control their creation, while an application, on the other hand, knows which mempools it creates and doesn't care about internal mempools PMDs might create.
--- app/test/test_mempool.c | 209 ++++++++++++++++++++++++++++++++++++++ lib/mempool/rte_mempool.c | 137 +++++++++++++++++++++++++ lib/mempool/rte_mempool.h | 61 +++++++++++ lib/mempool/version.map | 8 ++ 4 files changed, 415 insertions(+)
app/test/test_mempool.c +209 -0
@@ -14,6 +14,7 @@#include <rte_common.h> #include <rte_log.h> #include <rte_debug.h> +#include <rte_errno.h> #include <rte_memory.h> #include <rte_launch.h> #include <rte_cycles.h>
@@ -471,6 +472,206 @@ test_mp_mem_init(struct rte_mempool *mp, data->ret =0 ; } +struct test_mempool_events_data { +struct rte_mempool *mp; +enum rte_mempool_event event; +bool invoked; +}; + +static void +test_mempool_events_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *user_data) +{ +struct test_mempool_events_data *data = user_data; + + data->mp = mp; + data->event = event; + data->invoked = true; +} + +static int +test_mempool_events (int (*populate)(struct rte_mempool *mp)) +{ +static const size_t CB_NUM =3 ; +static const size_t MP_NUM =2 ; + +struct test_mempool_events_data data[CB_NUM ]; +struct rte_mempool *mp[MP_NUM ]; +char name[RTE_MEMPOOL_NAMESIZE ]; +size_t i, j; +int ret; + +for (i =0 ; i <CB_NUM ; i++) { + ret =rte_mempool_event_callback_register + (test_mempool_events_cb, &data[i]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to register the callback %zu: %s" , + i,rte_strerror (rte_errno)); + } + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, mp); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Unregistered a non-registered callback" ); +/* NULL argument has no special meaning in this API. */ + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, +NULL ); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Unregistered a non-registered callback with NULL argument" ); + +/* Create mempool 0 that will be observed by all callbacks. */ +memset (&data,0 ,sizeof (data)); +strcpy (name,"empty0" ); + mp[0 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp[0 ],"Cannot create mempool %s: %s" , + name,rte_strerror (rte_errno)); +for (j =0 ; j <CB_NUM ; j++) +RTE_TEST_ASSERT_EQUAL (data[j].invoked, false, +"Callback %zu invoked on %s mempool creation" , + j, name); + +rte_mempool_set_ops_byname (mp[0 ],rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp[0 ]); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp[0 ]->size,"Failed to populate mempool %s: %s" , + name,rte_strerror (rte_errno)); +for (j =0 ; j <CB_NUM ; j++) { +RTE_TEST_ASSERT_EQUAL (data[j].invoked, true, +"Callback %zu not invoked on mempool %s population" , + j, name); +RTE_TEST_ASSERT_EQUAL (data[j].event, +RTE_MEMPOOL_EVENT_READY , +"Wrong callback invoked, expected READY" ); +RTE_TEST_ASSERT_EQUAL (data[j].mp, mp[0 ], +"Callback %zu invoked for a wrong mempool instead of %s" , + j, name); + } + +/* Check that unregistered callback 0 observes no events. */ + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, + &data[0 ]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister callback 0: %s" , +rte_strerror (rte_errno)); +memset (&data,0 ,sizeof (data)); +strcpy (name,"empty1" ); + mp[1 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp[1 ],"Cannot create mempool %s: %s" , + name,rte_strerror (rte_errno)); +rte_mempool_set_ops_byname (mp[1 ],rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp[1 ]); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp[1 ]->size,"Failed to populate mempool %s: %s" , + name,rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data[0 ].invoked, false, +"Unregistered callback 0 invoked on %s mempool populaton" , + name); + +for (i =0 ; i <MP_NUM ; i++) { +memset (&data,0 ,sizeof (data)); +sprintf (name,"empty%zu" , i); +rte_mempool_free (mp[i]); +for (j =1 ; j <CB_NUM ; j++) { +RTE_TEST_ASSERT_EQUAL (data[j].invoked, true, +"Callback %zu not invoked on mempool %s destruction" , + j, name); +RTE_TEST_ASSERT_EQUAL (data[j].event, +RTE_MEMPOOL_EVENT_DESTROY , +"Wrong callback invoked, expected DESTROY" ); +RTE_TEST_ASSERT_EQUAL (data[j].mp, mp[i], +"Callback %zu invoked for a wrong mempool instead of %s" , + j, name); + } +RTE_TEST_ASSERT_EQUAL (data[0 ].invoked, false, +"Unregistered callback 0 invoked on %s mempool destruction" , + name); + } + +for (j =1 ; j <CB_NUM ; j++) { + ret =rte_mempool_event_callback_unregister + (test_mempool_events_cb, &data[j]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister the callback %zu: %s" , + j,rte_strerror (rte_errno)); + } +return 0 ; +} + +struct test_mempool_events_safety_data { +bool invoked; +int (*api_func)(rte_mempool_event_callback *func,void *user_data); +rte_mempool_event_callback *cb_func; +void *cb_user_data; +int ret; +}; + +static void +test_mempool_events_safety_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *user_data) +{ +struct test_mempool_events_safety_data *data = user_data; + +RTE_SET_USED (event); +RTE_SET_USED (mp); + data->invoked = true; + data->ret = data->api_func (data->cb_func, data->cb_user_data); +} + +static int +test_mempool_events_safety (void ) +{ +struct test_mempool_events_data data; +struct test_mempool_events_safety_data sdata[2 ]; +struct rte_mempool *mp; +size_t i; +int ret; + +/* removes itself */ + sdata[0 ].api_func = rte_mempool_event_callback_unregister; + sdata[0 ].cb_func = test_mempool_events_safety_cb; + sdata[0 ].cb_user_data = &sdata[0 ]; + sdata[0 ].ret =-1 ; +rte_mempool_event_callback_register (test_mempool_events_safety_cb, + &sdata[0 ]); +/* inserts a callback after itself */ + sdata[1 ].api_func = rte_mempool_event_callback_register; + sdata[1 ].cb_func = test_mempool_events_cb; + sdata[1 ].cb_user_data = &data; + sdata[1 ].ret =-1 ; +rte_mempool_event_callback_register (test_mempool_events_safety_cb, + &sdata[1 ]); + + mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create mempool: %s" , +rte_strerror (rte_errno)); +memset (&data,0 ,sizeof (data)); + ret =rte_mempool_populate_default (mp); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp->size,"Failed to populate mempool: %s" , +rte_strerror (rte_errno)); + +RTE_TEST_ASSERT_EQUAL (sdata[0 ].ret,0 ,"Callback failed to unregister itself: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (sdata[1 ].ret,0 ,"Failed to insert a new callback: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data.invoked, false, +"Inserted callback is invoked on mempool population" ); + +memset (&data,0 ,sizeof (data)); + sdata[0 ].invoked = false; +rte_mempool_free (mp); +RTE_TEST_ASSERT_EQUAL (sdata[0 ].invoked, false, +"Callback that unregistered itself was called" ); +RTE_TEST_ASSERT_EQUAL (sdata[1 ].ret, -EEXIST , +"New callback inserted twice" ); +RTE_TEST_ASSERT_EQUAL (data.invoked, true, +"Inserted callback is not invoked on mempool destruction" ); + +/* cleanup, don't care which callbacks are already removed */ +rte_mempool_event_callback_unregister (test_mempool_events_cb, &data); +for (i =0 ; i <RTE_DIM (sdata); i++) +rte_mempool_event_callback_unregister + (test_mempool_events_safety_cb, + &sdata[i]); +return 0 ; +} +static int test_mempool (void ) {
@@ -645,6 +846,14 @@ test_mempool(void)if (test_mempool_basic (default_pool,1 ) <0 )GOTO_ERR (ret, err); +/* test mempool event callbacks */ +if (test_mempool_events (rte_mempool_populate_default) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events (rte_mempool_populate_anon) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events_safety () <0 ) +GOTO_ERR (ret, err); +rte_mempool_list_dump (stdout); ret =0 ;
lib/mempool/rte_mempool.c +137 -0
158 lines not on this page · raw message
lib/mempool/rte_mempool.h +61 -0
67 lines not on this page · raw message
lib/mempool/version.map +8 -0
@@ -64,3 +64,11 @@ EXPERIMENTAL { __rte_mempool_trace_ops_free; __rte_mempool_trace_set_ops_byname; }; + +INTERNAL { + global: + + # added in 21.11 + rte_mempool_event_callback_register; + rte_mempool_event_callback_unregister; +};
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v4 1/4] mempool: add event callbacks
Quoted 20 lines · Dmitry Kozlyuk
Data path performance can benefit if the PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track creation and destruction of mempools after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Add an API to register callback for mempool life cycle events:
*rte_mempool_event_callback_register()
*rte_mempool_event_callback_unregister()
Currently tracked events are:
*RTE_MEMPOOL_EVENT_READY(after populating a mempool)
*RTE_MEMPOOL_EVENT_DESTROY(before freeing a mempool) Provide a unit test for the new API.
The new API is internal, because it is primarily demanded by PMDs that may need to deal with any mempools and do not control their creation, while an application, on the other hand, knows which mempools it creates and doesn't care about internal mempools PMDs might create.
Quoted 2 lines
Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Matan Azrad <[email protected]>
With below review notes processed
[snip]
Quoted 4 lines
lib/mempool/rte_mempool.c +0
-0
[snip]
Quoted 20 lines
lib/mempool/rte_mempool.c +5
-0@@ -360,6 +372,10 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +/* Report the mempool as ready only when fully populated. */ +if (mp->populated_size >= mp->size) +mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_READY , mp); +rte_mempool_trace_populate_iova (mp, vaddr, iova, len, free_cb, opaque);return i;@@ -722,6 +738,7 @@ rte_mempool_free(struct rte_mempool *mp) }rte_mcfg_tailq_write_unlock (); +mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_DESTROY , mp);rte_mempool_trace_free (mp);rte_mempool_free_memchunks (mp);rte_mempool_ops_free (mp);
lib/mempool/rte_mempool.c void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), · line 1364
Quoted 5 lines
lib/mempool/rte_mempool.c +2
-0@@ -1343,3 +1360,123 @@ void rte_mempool_walk(void (*func)(struct rte_mempool *, void *),rte_mcfg_mempool_read_unlock (); } + +struct mempool_callback {
It sounds like it is a mempool callback itself.
Consider: mempool_event_callback_data.
I think this way it will be consistent.
Quoted 83 lines
lib/mempool/rte_mempool.c +83
-0+rte_mempool_event_callback *func; +void *user_data; +}; + +static void +mempool_event_callback_invoke (enum rte_mempool_event event, +struct rte_mempool *mp) +{ +struct mempool_callback_list *list; +struct rte_tailq_entry *te; +void *tmp_te; + +rte_mcfg_tailq_read_lock (); + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + RTE_TAILQ_FOREACH_SAFE(te, list, next, tmp_te) { +struct mempool_callback *cb = te->data; +rte_mcfg_tailq_read_unlock (); + cb->func (event, mp, cb->user_data); +rte_mcfg_tailq_read_lock (); + } +rte_mcfg_tailq_read_unlock (); +} + +int +rte_mempool_event_callback_register (rte_mempool_event_callback *func, +void *user_data) +{ +struct mempool_callback_list *list; +struct rte_tailq_entry *te =NULL ; +struct mempool_callback *cb; +void *tmp_te; +int ret; + +if (func ==NULL ) { + rte_errno =EINVAL ; +return -rte_errno; + } + +rte_mcfg_mempool_read_lock (); +rte_mcfg_tailq_write_lock (); + + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + RTE_TAILQ_FOREACH_SAFE(te, list, next, tmp_te) { +struct mempool_callback *cb = + (struct mempool_callback *)te->data; +if (cb->func == func && cb->user_data == user_data) { + ret = -EEXIST ; + goto exit; + } + } + + te =rte_zmalloc ("MEMPOOL_TAILQ_ENTRY" ,sizeof (*te),0 ); +if (te ==NULL ) { +RTE_LOG (ERR ,MEMPOOL , +"Cannot allocate event callback tailq entry!\n" ); + ret = -ENOMEM ; + goto exit; + } + + cb =rte_malloc ("MEMPOOL_EVENT_CALLBACK" ,sizeof (*cb),0 ); +if (cb ==NULL ) { +RTE_LOG (ERR ,MEMPOOL , +"Cannot allocate event callback!\n" ); +rte_free (te); + ret = -ENOMEM ; + goto exit; + } + + cb->func = func; + cb->user_data = user_data; + te->data = cb; +TAILQ_INSERT_TAIL (list, te, next); + ret =0 ; + +exit: +rte_mcfg_tailq_write_unlock (); +rte_mcfg_mempool_read_unlock (); + rte_errno = -ret; +return ret; +} + +int +rte_mempool_event_callback_unregister(rte_mempool_event_callback *func,
lib/mempool/rte_mempool.c void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), · line 1457
Quoted 10 lines
lib/mempool/rte_mempool.c +10
-0+ void *user_data) +{ +struct mempool_callback_list *list; +struct rte_tailq_entry *te =NULL ; +struct mempool_callback *cb; +int ret; + +if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) { + rte_errno =EPERM ; +return -1 ;
The function should behave consistencly. Below you return negative error. Here just -1. I think it would be more constent to return -rte_errno here.
lib/mempool/rte_mempool.c void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), · line 1469
Quoted 12 lines
lib/mempool/rte_mempool.c +12
-0+ } + +rte_mcfg_mempool_read_lock (); +rte_mcfg_tailq_write_lock (); + ret = -ENOENT ; + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + TAILQ_FOREACH(te, list, next) { + cb = (struct mempool_callback *)te->data; +if (cb->func == func && cb->user_data == user_data) +break ; + } +if (te !=NULL ) {
Here we rely on the fact that TAILQ_FOREACH() exists with te==NULL in the case of no such entry. I'd suggest to avoid the assumption. I.e. do below two lines above before break and have not the if condition her at all.
Quoted 18 lines
lib/mempool/rte_mempool.c +13
-0+TAILQ_REMOVE (list, te, next); + ret =0 ; + } +rte_mcfg_tailq_write_unlock (); +rte_mcfg_mempool_read_unlock (); + +if (ret ==0 ) { +rte_free (te); +rte_free (cb); + } + rte_errno = -ret; +return ret; +}lib/mempool/rte_mempool.h +0
-0
lib/mempool/rte_mempool.h void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg), · line 1779
Quoted 6 lines
lib/mempool/rte_mempool.h +3
-0@@ -1774,6 +1774,67 @@ void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),int rte_mempool_get_page_size (struct rte_mempool *mp,size_t *pg_sz); +/** +* Mempool event type. +* @internal
Shouldn't internal go first?
lib/mempool/rte_mempool.h void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg), · line 1782
Quoted 3 lines
lib/mempool/rte_mempool.h +3
-0+*/ +enum rte_mempool_event { +/** Occurs after a mempool is successfully populated. */
successfully -> fully ?
Quoted 4 lines
lib/mempool/rte_mempool.h +4
-0+RTE_MEMPOOL_EVENT_READY =0 , +/** Occurs before destruction of a mempool begins. */ + RTE_MEMPOOL_EVENT_DESTROY = 1, +};
[snip]
Re: [dpdk-dev] [PATCH v4 1/4] mempool: add event callbacks
Quoted 7 lines
-----Original Message-----
From: Andrew Rybchenko <[email protected]> [...]
With below review notes processedReviewed-by Andrew Rybchenko <[email protected]>
Thanks for the comments, I'll fix them all, just a small note below FYI.
Quoted 11 lines
lib/mempool/rte_mempool.c void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), · line 1469
Quoted 10 lines
lib/mempool/rte_mempool.c +10
-0+rte_mcfg_mempool_read_lock (); +rte_mcfg_tailq_write_lock (); + ret = -ENOENT ; + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + TAILQ_FOREACH(te, list, next) { + cb = (struct mempool_callback *)te->data; +if (cb->func == func && cb->user_data == user_data) +break ; + } +if (te !=NULL ) {
Quoted 4 lines
Here we rely on the fact that
TAILQ_FOREACH()exists with te==NULL in the case of no such entry. I'd suggest to avoid the assumption. I.e. do below two lines above before break and have not the if condition her at all.
Since you asked the question, the code is non-obvious, so I'll change it. FWIW, man 3 tailq:
TAILQ_FOREACH() traverses the queue referenced by head in the forward direction, assigning each element in turn to var. var is set to NULL if the loop completes normally, or if there were no elements.
Re: [dpdk-dev] [PATCH v4 1/4] mempool: add event callbacks
In reply to Andrew RybchenkoQuoted 8 lines
Quoted 3 lines
+/**
+ * Mempool event type.
+ * @internalShouldn't internal go first?
Quoted 2 lines
+ */
+enumrte_mempool_event{
It really should, but I had to keep it this way because otherwise Doxygen fails on multiple systems:
[3110/3279] Generating doxygen with a custom command
FAILED: doc/api/html/root/dpdk/doc/api/generate_doxygen.sh doc/api/doxy-api.conf doc/api/html /root/dpdk/doc/api/doxy-html-custom.sh/root/dpdk/lib/mempool/rte_mempool.h:1778: error: Member rte_mempool_event (enumeration) of file rte_mempool.h is not documented.
(warning treated as error, aborting now)/root/dpdk/doc/api/generate_doxygen.sh: line 12: 51733 Segmentation fault
(core dumped) doxygen "${DOXYCONF}" > $OUT_FILERe: [dpdk-dev] [PATCH v4 1/4] mempool: add event callbacks
In reply to Dmitry KozlyukHi Dmitry,
Quoted 28 lines · Dmitry Kozlyuk
Data path performance can benefit if the PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track creation and destruction of mempools after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Add an API to register callback for mempool life cycle events:
*rte_mempool_event_callback_register()
*rte_mempool_event_callback_unregister()
Currently tracked events are:
*RTE_MEMPOOL_EVENT_READY(after populating a mempool)
*RTE_MEMPOOL_EVENT_DESTROY(before freeing a mempool) Provide a unit test for the new API.
The new API is internal, because it is primarily demanded by PMDs that may need to deal with any mempools and do not control their creation, while an application, on the other hand, knows which mempools it creates and doesn't care about internal mempools PMDs might create.Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Matan Azrad <[email protected]>--- app/test/test_mempool.c | 209 ++++++++++++++++++++++++++++++++++++++ lib/mempool/rte_mempool.c | 137 +++++++++++++++++++++++++ lib/mempool/rte_mempool.h | 61 +++++++++++ lib/mempool/version.map | 8 ++ 4 files changed, 415 insertions(+)
(...)
Quoted 22 lines
lib/mempool/rte_mempool.c +12
-0@@ -42,6 +42,18 @@ static struct rte_tailq_elem rte_mempool_tailq = { };EAL_REGISTER_TAILQ (rte_mempool_tailq) +TAILQ_HEAD (mempool_callback_list, rte_tailq_entry); + +static struct rte_tailq_elem callback_tailq = { + .name ="RTE_MEMPOOL_CALLBACK" , +}; +EAL_REGISTER_TAILQ (callback_tailq) + +/* Invoke all registered mempool event callbacks. */ +static void +mempool_event_callback_invoke (enum rte_mempool_event event, +struct rte_mempool *mp); +#define CACHE_FLUSHTHRESH_MULTIPLIER 1.5#define CALC_CACHE_FLUSHTHRESH (c) \ ((typeof(c))((c) * CACHE_FLUSHTHRESH_MULTIPLIER))
lib/mempool/rte_mempool.c rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, · line 378
Quoted 7 lines
lib/mempool/rte_mempool.c +4
-0@@ -360,6 +372,10 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +/* Report the mempool as ready only when fully populated. */ +if (mp->populated_size >= mp->size) +mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_READY , mp); +
One small comment here. I think it does not happen today, but in the future, something that could happen is:
- create empty mempool
- populate mempool
- use mempool
- populate mempool with more objects
- use mempool
I've seen one usage there: https://www.youtube.com/watch?v=SzQFn9tm4Sw
In that case, it would require a POPULATE event instead of a MEMPOOL_CREATE event.
Enhancing the documentation to better explain when the callback is invoked looks enough to me for the moment.
Quoted 26 lines
lib/mempool/rte_mempool.c +12
-0rte_mempool_trace_populate_iova (mp, vaddr, iova, len, free_cb, opaque);return i;@@ -722,6 +738,7 @@ rte_mempool_free(struct rte_mempool *mp) }rte_mcfg_tailq_write_unlock (); +mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_DESTROY , mp);rte_mempool_trace_free (mp);rte_mempool_free_memchunks (mp);rte_mempool_ops_free (mp);@@ -1343,3 +1360,123 @@ void rte_mempool_walk(void (*func)(struct rte_mempool *, void *),rte_mcfg_mempool_read_unlock (); } + +struct mempool_callback { +rte_mempool_event_callback *func; +void *user_data; +}; + +static void +mempool_event_callback_invoke (enum rte_mempool_event event, +struct rte_mempool *mp) +{ +struct mempool_callback_list *list;
lib/mempool/rte_mempool.c void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), · line 1383
Quoted 10 lines
lib/mempool/rte_mempool.c +10
-0+struct rte_tailq_entry *te; +void *tmp_te; + +rte_mcfg_tailq_read_lock (); + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + RTE_TAILQ_FOREACH_SAFE(te, list, next, tmp_te) { +struct mempool_callback *cb = te->data; +rte_mcfg_tailq_read_unlock (); + cb->func (event, mp, cb->user_data); +rte_mcfg_tailq_read_lock ();
I think it is dangerous to unlock the list before invoking the callback. During that time, another thread can remove the next mempool callback, and the next iteration will access to a freed element, causing an undefined behavior.
Is it a problem to keep the lock held during the callback invocation?
I see that you have a test for this, and that you wrote a comment in the documentation:
* rte_mempool_event_callback_register() may be called from within the callback,
* but the callbacks registered this way will not be invoked for the same event.
* rte_mempool_event_callback_unregister() may only be safely called
* to remove the running callback.
But is there a use-case for this?
If no, I'll tend to say that we can document that it is not allowed to create, free or list mempools or register cb from the callback.
Quoted 65 lines
lib/mempool/rte_mempool.c +65
-0+ } +rte_mcfg_tailq_read_unlock (); +} + +int +rte_mempool_event_callback_register (rte_mempool_event_callback *func, +void *user_data) +{ +struct mempool_callback_list *list; +struct rte_tailq_entry *te =NULL ; +struct mempool_callback *cb; +void *tmp_te; +int ret; + +if (func ==NULL ) { + rte_errno =EINVAL ; +return -rte_errno; + } + +rte_mcfg_mempool_read_lock (); +rte_mcfg_tailq_write_lock (); + + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + RTE_TAILQ_FOREACH_SAFE(te, list, next, tmp_te) { +struct mempool_callback *cb = + (struct mempool_callback *)te->data; +if (cb->func == func && cb->user_data == user_data) { + ret = -EEXIST ; + goto exit; + } + } + + te =rte_zmalloc ("MEMPOOL_TAILQ_ENTRY" ,sizeof (*te),0 ); +if (te ==NULL ) { +RTE_LOG (ERR ,MEMPOOL , +"Cannot allocate event callback tailq entry!\n" ); + ret = -ENOMEM ; + goto exit; + } + + cb =rte_malloc ("MEMPOOL_EVENT_CALLBACK" ,sizeof (*cb),0 ); +if (cb ==NULL ) { +RTE_LOG (ERR ,MEMPOOL , +"Cannot allocate event callback!\n" ); +rte_free (te); + ret = -ENOMEM ; + goto exit; + } + + cb->func = func; + cb->user_data = user_data; + te->data = cb; +TAILQ_INSERT_TAIL (list, te, next); + ret =0 ; + +exit: +rte_mcfg_tailq_write_unlock (); +rte_mcfg_mempool_read_unlock (); + rte_errno = -ret; +return ret; +} + +int +rte_mempool_event_callback_unregister (rte_mempool_event_callback *func, +void *user_data)
lib/mempool/rte_mempool.c void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), · line 1458
Quoted 10 lines
lib/mempool/rte_mempool.c +10
-0+{ +struct mempool_callback_list *list; +struct rte_tailq_entry *te =NULL ; +struct mempool_callback *cb; +int ret; + +if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) { + rte_errno =EPERM ; +return -1 ; + }
The help of the register function says
* Callbacks will be invoked in the process that creates the mempool.
So registration is allowed from primary or secondary process. Can't a secondary process destroys the callback it has loaded?
lib/mempool/rte_mempool.c void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), · line 1404
Quoted 3 lines
lib/mempool/rte_mempool.c +3
-0+ +rte_mcfg_mempool_read_lock (); +rte_mcfg_tailq_write_lock ();
I don't understand why there are 2 locks here.
After looking at the code, I think the locking model is already incorrect in current mempool code:
rte_mcfg_tailq_write_lock() is used in create and free to protect the
access to the mempool tailq
rte_mcfg_mempool_write_lock() is used in create(), to protect from
concurrent creation (with same name for instance), but I doubt it is absolutly needed, because memzone_reserve is already protected.
rte_mcfg_mempool_read_lock() is used in dump functions, but to me
it should use rte_mcfg_tailq_read_lock() instead. Currently, doing a dump and a free concurrently can cause a crash because they are not using the same lock.
In your case, I suggest to use only one lock to protect the callback list. I think it can be rte_mcfg_tailq_*_lock().
Re: [dpdk-dev] [PATCH v4 1/4] mempool: add event callbacks
[...]
Quoted 19 lines
Review rte_mempool_populate_iova(struct rte_mempool *mp,
Quoted 1 line
(quoted diff) +0
-0@@ -360,6 +372,10 @@ rte_mempool_populate_iova(struct rte_mempool *mp,char *vaddr,
lib/mempool/rte_mempool.c rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
Quoted 6 lines
lib/mempool/rte_mempool.c +3
-0STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +/* Report the mempool as ready only when fully populated. */ +if (mp->populated_size >= mp->size) + mempool_event_callback_invoke(RTE_MEMPOOL_EVENT_READY,mp);
Review rte_mempool_populate_iova(struct rte_mempool *mp, · line 378
Quoted 1 line
(quoted diff) +1
-0+One small comment here. I think it does not happen today, but in the future, something that could happen is:
- create empty mempool
- populate mempool
- use mempool
- populate mempool with more objects
- use mempool
Quoted 4 lines
I've seen one usage there: https://www.youtube.com/watch?v=SzQFn9tm4Sw
In that case, it would require a POPULATE event instead of a
MEMPOOL_CREATEevent.
That's a troublesome case.
Technically it can be only one POPULATE event called on each population, even an incomplete one, and the callback can check populated_size vs size. However, I'd keep the READY event indeed, because it's the common case, and the first consumer of the feature, mlx5 PMD, can handle corner cases. It is also a little more efficient. POPULATE can be added later.
Quoted 2 lines
Enhancing the documentation to better explain when the callback is invoked looks enough to me for the moment.
Per Andrew's suggestion, it will say:
"Occurs after a mempool is fully populated".
I hope this is clear enough.
Quoted 34 lines
[...]
Quoted 5 lines
lib/mempool/rte_mempool.c +5
-0+static void +mempool_event_callback_invoke (enum rte_mempool_event event, +struct rte_mempool *mp) +{ +struct mempool_callback_list *list;lib/mempool/rte_mempool.c void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), · line 1383
Quoted 10 lines
lib/mempool/rte_mempool.c +10
-0+struct rte_tailq_entry *te; +void *tmp_te; + +rte_mcfg_tailq_read_lock (); + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + RTE_TAILQ_FOREACH_SAFE(te, list, next, tmp_te) { +struct mempool_callback *cb = te->data; +rte_mcfg_tailq_read_unlock (); + cb->func (event, mp, cb->user_data); +rte_mcfg_tailq_read_lock ();I think it is dangerous to unlock the list before invoking the callback. During that time, another thread can remove the next mempool callback, and the next iteration will access to a freed element, causing an undefined behavior.
Is it a problem to keep the lock held during the callback invocation?
I see that you have a test for this, and that you wrote a comment in the documentation:
*
rte_mempool_event_callback_register()may be called from within the
callback,
* but the callbacks registered this way will not be invoked for the same
event.
*rte_mempool_event_callback_unregister()may only be safely called
* to remove the running callback.
Quoted 3 lines
But is there a use-case for this?
If no, I'll tend to say that we can document that it is not allowed to create, free or list mempools or register cb from the callback.
There is no use-case, but I'd argue for releasing the lock. This lock is taken by rte_xxx_create() functions in many libraries, so the restriction is wider and, worse, it is not strictly limited.
Quoted 17 lines
[...]
lib/mempool/rte_mempool.c void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), · line 1458
Quoted 13 lines
lib/mempool/rte_mempool.c +13
-0+int +rte_mempool_event_callback_unregister (rte_mempool_event_callback *func, +void *user_data) +{ +struct mempool_callback_list *list; +struct rte_tailq_entry *te =NULL ; +struct mempool_callback *cb; +int ret; + +if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) { + rte_errno =EPERM ; +return -1 ; + }The help of the register function says
* Callbacks will be invoked in the process that creates the mempool.
BTW, this is another bug, it should be "populates", not "creates".
Quoted 19 lines
So registration is allowed from primary or secondary process. Can't a secondary process destroys the callback it has loaded?
lib/mempool/rte_mempool.c void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), · line 1404
Quoted 3 lines
lib/mempool/rte_mempool.c +3
-0+ +rte_mcfg_mempool_read_lock (); +rte_mcfg_tailq_write_lock ();I don't understand why there are 2 locks here.
After looking at the code, I think the locking model is already incorrect in current mempool code:
rte_mcfg_tailq_write_lock()is used in create and free to protect the
access to the mempool tailq
rte_mcfg_mempool_write_lock()is used increate(), to protect from
concurrent creation (with same name for instance), but I doubt it is absolutly needed, becausememzone_reserveis already protected.
Quoted 7 lines
rte_mcfg_mempool_read_lock()is used in dump functions, but to me
it should userte_mcfg_tailq_read_lock()instead. Currently, doing a dump and a free concurrently can cause a crash because they are not using the same lock.In your case, I suggest to use only one lock to protect the callback list. I think it can be rte_mcfg_tailq_*_lock().
Thanks, I will double-check the locking.
Re: [dpdk-dev] [PATCH v4 1/4] mempool: add event callbacks
On Fri, Oct 15, 2021 at 01:07:42PM +0000, Dmitry Kozlyuk wrote:
[...]
Quoted 33 lines
Quoted 33 lines
Quoted 5 lines
lib/mempool/rte_mempool.c +5
-0+static void +mempool_event_callback_invoke (enum rte_mempool_event event, +struct rte_mempool *mp) +{ +struct mempool_callback_list *list;lib/mempool/rte_mempool.c void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), · line 1383
Quoted 10 lines
lib/mempool/rte_mempool.c +10
-0+struct rte_tailq_entry *te; +void *tmp_te; + +rte_mcfg_tailq_read_lock (); + list =RTE_TAILQ_CAST (callback_tailq.head, mempool_callback_list); + RTE_TAILQ_FOREACH_SAFE(te, list, next, tmp_te) { +struct mempool_callback *cb = te->data; +rte_mcfg_tailq_read_unlock (); + cb->func (event, mp, cb->user_data); +rte_mcfg_tailq_read_lock ();I think it is dangerous to unlock the list before invoking the callback. During that time, another thread can remove the next mempool callback, and the next iteration will access to a freed element, causing an undefined behavior.
Is it a problem to keep the lock held during the callback invocation?
I see that you have a test for this, and that you wrote a comment in the documentation:
*
rte_mempool_event_callback_register()may be called from within the
callback,
* but the callbacks registered this way will not be invoked for the same
event.
*rte_mempool_event_callback_unregister()may only be safely called
* to remove the running callback.
Quoted 7 lines
Quoted 3 lines
But is there a use-case for this?
If no, I'll tend to say that we can document that it is not allowed to create, free or list mempools or register cb from the callback.There is no use-case, but I'd argue for releasing the lock. This lock is taken by
rte_xxx_create()functions in many libraries, so the restriction is wider and, worse, it is not strictly limited.
Yes... I honnestly don't understand why every library uses the same lock rte_mcfg_tailq if the only code that accesses the list is in the library itself. Maybe I'm missing something.
I have the impression that having only one mempool lock for all usages in mempool would be simpler and more specific. It would allow to keep the lock held while invoking the callbacks without blocking accesses to the other libs, and would also solve the problem described below.
Quoted 48 lines
Quoted 17 lines
[...]
lib/mempool/rte_mempool.c void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), · line 1458
Quoted 13 lines
lib/mempool/rte_mempool.c +13
-0+int +rte_mempool_event_callback_unregister (rte_mempool_event_callback *func, +void *user_data) +{ +struct mempool_callback_list *list; +struct rte_tailq_entry *te =NULL ; +struct mempool_callback *cb; +int ret; + +if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) { + rte_errno =EPERM ; +return -1 ; + }The help of the register function says
* Callbacks will be invoked in the process that creates the mempool.BTW, this is another bug, it should be "populates", not "creates".
Quoted 19 lines
So registration is allowed from primary or secondary process. Can't a secondary process destroys the callback it has loaded?
lib/mempool/rte_mempool.c void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), · line 1404
Quoted 3 lines
lib/mempool/rte_mempool.c +3
-0+ +rte_mcfg_mempool_read_lock (); +rte_mcfg_tailq_write_lock ();I don't understand why there are 2 locks here.
After looking at the code, I think the locking model is already incorrect in current mempool code:
rte_mcfg_tailq_write_lock()is used in create and free to protect the
access to the mempool tailq
rte_mcfg_mempool_write_lock()is used increate(), to protect from
concurrent creation (with same name for instance), but I doubt it is absolutly needed, becausememzone_reserveis already protected.Quoted 7 lines
rte_mcfg_mempool_read_lock()is used in dump functions, but to me
it should userte_mcfg_tailq_read_lock()instead. Currently, doing a dump and a free concurrently can cause a crash because they are not using the same lock.In your case, I suggest to use only one lock to protect the callback list. I think it can be rte_mcfg_tailq_*_lock().
Thanks, I will double-check the locking.
PATCH v4 2/4 mempool: add non-IO flag
In reply to Dmitry KozlyukMempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add MEMPOOL_F_NON_IO flag to mark such mempools automatically if their objects are not contiguous or IOVA are not available. Components can inspect this flag in order to optimize their memory management.
Discussion: https://mails.dpdk.org/archives/dev/2021-August/216654.html
--- app/test/test_mempool.c | 76 ++++++++++++++++++++++++++ doc/guides/rel_notes/release_21_11.rst | 3 + lib/mempool/rte_mempool.c | 2 + lib/mempool/rte_mempool.h | 5 ++ 4 files changed, 86 insertions(+)
app/test/test_mempool.c +76 -0
@@ -672,6 +672,74 @@ test_mempool_events_safety(void)return 0 ; } +static int +test_mempool_flag_non_io_set_when_no_iova_contig_set (void ) +{ +struct rte_mempool *mp; +int ret; + + mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,MEMPOOL_F_NO_IOVA_CONTIG ); +RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create mempool: %s" , +rte_strerror (rte_errno)); +rte_mempool_set_ops_byname (mp,rte_mbuf_best_mempool_ops (),NULL ); + ret =rte_mempool_populate_default (mp); +RTE_TEST_ASSERT (ret >0 ,"Failed to populate mempool: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT (mp->flags &MEMPOOL_F_NON_IO , +"NON_IO flag is not set when NO_IOVA_CONTIG is set" ); +rte_mempool_free (mp); +return 0 ; +} + +static int +test_mempool_flag_non_io_set_when_populated_with_bad_iova (void ) +{ +void *addr; +size_t size =1 <<16 ; +struct rte_mempool *mp; +int ret; + + addr =rte_malloc ("test_mempool" , size,0 ); +RTE_TEST_ASSERT_NOT_NULL (addr,"Cannot allocate memory" ); + mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create mempool: %s" , +rte_strerror (rte_errno)); + ret =rte_mempool_populate_iova (mp, addr,RTE_BAD_IOVA , size, +NULL ,NULL ); +/* The flag must be inferred even if population isn't full. */ +RTE_TEST_ASSERT (ret >0 ,"Failed to populate mempool: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT (mp->flags &MEMPOOL_F_NON_IO , +"NON_IO flag is not set when mempool is populated with RTE_BAD_IOVA" ); +rte_mempool_free (mp); +rte_free (addr); +return 0 ; +} + +static int +test_mempool_flag_non_io_unset_by_default (void ) +{ +struct rte_mempool *mp; +int ret; + + mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create mempool: %s" , +rte_strerror (rte_errno)); + ret =rte_mempool_populate_default (mp); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp->size,"Failed to populate mempool: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT (!(mp->flags &MEMPOOL_F_NON_IO ), +"NON_IO flag is set by default" ); +rte_mempool_free (mp); +return 0 ; +} +static int test_mempool (void ) {
@@ -854,6 +922,14 @@ test_mempool(void)if (test_mempool_events_safety () <0 )GOTO_ERR (ret, err); +/* test NON_IO flag inference */ +if (test_mempool_flag_non_io_unset_by_default () <0 ) +GOTO_ERR (ret, err); +if (test_mempool_flag_non_io_set_when_no_iova_contig_set () <0 ) +GOTO_ERR (ret, err); +if (test_mempool_flag_non_io_set_when_populated_with_bad_iova () <0 ) +GOTO_ERR (ret, err); +rte_mempool_list_dump (stdout); ret =0 ;
doc/guides/rel_notes/release_21_11.rst +3 -0
@@ -226,6 +226,9 @@ API Changes the crypto/security operation. This field will be used to communicate events such as soft expiry with IPsec in lookaside mode. +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA). + ABI Changes -----------
lib/mempool/rte_mempool.c +2 -0
@@ -371,6 +371,8 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +if (iova ==RTE_BAD_IOVA ) + mp->flags |=MEMPOOL_F_NON_IO ;/* Report the mempool as ready only when fully populated. */ if (mp->populated_size >= mp->size)
lib/mempool/rte_mempool.h +5 -0
@@ -262,6 +262,8 @@ struct rte_mempool {#define MEMPOOL_F_SC_GET 0x0008/**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010/**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020/**< Don't need IOVA contiguous objs. */ +#define MEMPOOL_F_NON_IO 0x0040 +/**< Internal: pool is not usable for device IO (DMA). */ /** * @internal When debug is enabled, store some statistics.
@@ -991,6 +993,9 @@ typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);* "single-consumer". Otherwise, it is "multi-consumers". * - MEMPOOL_F_NO_IOVA_CONTIG: If set, allocated objects won't * necessarily be contiguous in IO memory. +* - MEMPOOL_F_NON_IO: If set, the mempool is considered to be +* never used for device IO, i.e. for DMA operations. +* It's a hint to other components and does not affect the mempool behavior. * @return * The pointer to the new allocated mempool, on success. NULL on error * with rte_errno set appropriately. Possible rte_errno values include:
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
Quoted 9 lines · Dmitry Kozlyuk
Mempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add
MEMPOOL_F_NON_IOflag to mark such mempools automatically if their objects are not contiguous or IOVA are not available. Components can inspect this flag in order to optimize their memory management.
Discussion: https://mails.dpdk.org/archives/dev/2021-August/216654.htmlSigned-off-by Dmitry Kozlyuk <[email protected]>Acked-by Matan Azrad <[email protected]>
See review notes below. With review notes processed:
[snip]
Quoted 19 lines
doc/guides/rel_notes/release_21_11.rst +3
-0@@ -226,6 +226,9 @@ API Changes the crypto/security operation. This field will be used to communicate events such as soft expiry with IPsec in lookaside mode. +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA). + ABI Changes -----------lib/mempool/rte_mempool.c +0
-0
lib/mempool/rte_mempool.c rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, · line 375
Quoted 5 lines
lib/mempool/rte_mempool.c +2
-0@@ -371,6 +371,8 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +if (iova ==RTE_BAD_IOVA ) + mp->flags |=MEMPOOL_F_NON_IO ;
As I understand rte_mempool_populate_iova() may be called few times for one mempool. The flag must be set if all invocations are done with RTE_BAD_IOVA. So, it should be set by default and just removed when iova != RTE_BAD_IOVA happens.
Yes, it is a corner case. May be it makes sense to cover it by unit test as well.
lib/mempool/rte_mempool.h struct rte_mempool { · line 266
Quoted 13 lines
lib/mempool/rte_mempool.c +0
-0/* Report the mempool as ready only when fully populated. */ if (mp->populated_size >= mp->size)lib/mempool/rte_mempool.h +2
-0@@ -262,6 +262,8 @@ struct rte_mempool {#define MEMPOOL_F_SC_GET 0x0008/**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010/**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020/**< Don't need IOVA contiguous objs. */ +#define MEMPOOL_F_NON_IO 0x0040 +/**< Internal: pool is not usable for device IO (DMA). */
Please, put the documentation before the define. /** Internal: pool is not usable for device IO (DMA). */
#define MEMPOOL_F_NON_IO 0x0040
lib/mempool/rte_mempool.h typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *); · line 998
Quoted 10 lines
lib/mempool/rte_mempool.h +3
-0/** * @internal When debug is enabled, store some statistics. @@ -991,6 +993,9 @@ typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);* "single-consumer". Otherwise, it is "multi-consumers". * - MEMPOOL_F_NO_IOVA_CONTIG: If set, allocated objects won't * necessarily be contiguous in IO memory. +* - MEMPOOL_F_NON_IO: If set, the mempool is considered to be +* never used for device IO, i.e. for DMA operations. +* It's a hint to other components and does not affect the mempool behavior.
I tend to say that it should not be here if the flag is internal.
Quoted 4 lines
lib/mempool/rte_mempool.h +0
-0* @return * The pointer to the new allocated mempool, on success. NULL on error * with rte_errno set appropriately. Possible rte_errno values include:
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
Quoted 10 lines
-----Original Message-----
From: Andrew Rybchenko <[email protected]> [...]Quoted 7 lines
lib/mempool/rte_mempool.c +0
-0@@ -371,6 +371,8 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
Quoted 9 lines
lib/mempool/rte_mempool.c rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, · line 375
Quoted 4 lines
lib/mempool/rte_mempool.c +2
-0STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +if (iova ==RTE_BAD_IOVA ) + mp->flags |=MEMPOOL_F_NON_IO ;As I understand
rte_mempool_populate_iova()may be called few times for one mempool. The flag must be set if all invocations are done withRTE_BAD_IOVA. So, it should be set by default and just removed when iova !=RTE_BAD_IOVAhappens.
I don't agree at all. If any object of the pool is unsuitable for IO, the pool cannot be considered suitable for IO. So if there's a single invocation with RTE_BAD_IOVA, the flag must be set forever.
Quoted 2 lines
Yes, it is a corner case. May be it makes sense to cover it by unit test as well.
True for either your logic or mine, I'll add it.
Ack on the rest of the comments, thanks.
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
Quoted 20 lines · Dmitry Kozlyuk
Quoted 10 lines
-----Original Message-----
From: Andrew Rybchenko <[email protected]> [...]Quoted 7 lines
lib/mempool/rte_mempool.c +0
-0@@ -371,6 +371,8 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,Quoted 9 lines
lib/mempool/rte_mempool.c rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, · line 375
Quoted 4 lines
lib/mempool/rte_mempool.c +2
-0STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +if (iova ==RTE_BAD_IOVA ) + mp->flags |=MEMPOOL_F_NON_IO ;As I understand
rte_mempool_populate_iova()may be called few times for one mempool. The flag must be set if all invocations are done withRTE_BAD_IOVA. So, it should be set by default and just removed when iova !=RTE_BAD_IOVAhappens.
Quoted 3 lines
I don't agree at all. If any object of the pool is unsuitable for IO, the pool cannot be considered suitable for IO. So if there's a single invocation with
RTE_BAD_IOVA, the flag must be set forever.
If so, some objects may be used for IO, some cannot be used. What should happen if an application allocates an object which is suitable for IO and try to use it this way?
Quoted 8 lines
Quoted 3 lines
Yes, it is a corner case. May be it makes sense to cover it by unit test as well.
True for either your logic or mine, I'll add it.
Ack on the rest of the comments, thanks.
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
Quoted 32 lines
-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: 15 октября 2021 г. 12:34
To: Dmitry Kozlyuk <[email protected]>; [email protected]
Cc: Matan Azrad <[email protected]>; Olivier Matz <[email protected]>
Subject: Re: [PATCH v4 2/4] mempool: add non-IO flagExternal email: Use caution opening links or attachments
Quoted 19 lines · Dmitry Kozlyuk
Quoted 18 lines
-----Original Message-----
From: Andrew Rybchenko <[email protected]> [...]lib/mempool/rte_mempool.c rte_mempool_populate_iova(struct rte_mempool · line 376
Quoted 11 lines
lib/mempool/rte_mempool.c +2
-0@@ -371,6 +371,8 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +if (iova ==RTE_BAD_IOVA ) + mp->flags |=MEMPOOL_F_NON_IO ;As I understand
rte_mempool_populate_iova()may be called few times for one mempool. The flag must be set if all invocations are done withRTE_BAD_IOVA. So, it should be set by default and just removed when iova !=RTE_BAD_IOVAhappens.
Quoted 7 lines
Quoted 3 lines
I don't agree at all. If any object of the pool is unsuitable for IO, the pool cannot be considered suitable for IO. So if there's a single invocation with
RTE_BAD_IOVA, the flag must be set forever.If so, some objects may be used for IO, some cannot be used. What should happen if an application allocates an object which is suitable for IO and try to use it this way?
Never mind, I was thinking in v1 mode when the application marked mempools as not suitable for IO. Since now they're marked automatically, you're correct:
the flag must be set if and only if there is no chance
that objects from this pool will be used for IO.
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
In reply to Andrew RybchenkoQuoted 21 lines · Andrew Rybchenko
Quoted 20 lines · Dmitry Kozlyuk
Quoted 19 lines
-----Original Message-----
From: Andrew Rybchenko <[email protected]> [...]lib/mempool/rte_mempool.c rte_mempool_populate_iova(struct rte_mempool *mp, · line 376
Quoted 11 lines
lib/mempool/rte_mempool.c +2
-0@@ -371,6 +371,8 @@ rte_mempool_populate_iova(struct rte_mempool *mp,char *vaddr, STAILQ_INSERT_TAIL(&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +if (iova ==RTE_BAD_IOVA ) + mp->flags |=MEMPOOL_F_NON_IO ;As I understand
rte_mempool_populate_iova()may be called few times for one mempool. The flag must be set if all invocations are done withRTE_BAD_IOVA. So, it should be set by default and just removed when iova !=RTE_BAD_IOVAhappens.
Quoted 7 lines
Quoted 3 lines
I don't agree at all. If any object of the pool is unsuitable for IO, the pool cannot be considered suitable for IO. So if there's a single invocation with
RTE_BAD_IOVA, the flag must be set forever.If so, some objects may be used for IO, some cannot be used. What should happen if an application allocates an object which is suitable for IO and try to use it this way?
If the application can predict if the allocated object is usable for IO before allocating it, I would be surprised to have it used for IO. I agree with Dmitry here.
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
Quoted 38 lines
-----Original Message-----
From: Olivier Matz <[email protected]>
Sent: 15 октября 2021 г. 12:43
To: Andrew Rybchenko <[email protected]>
Cc: Dmitry Kozlyuk <[email protected]>; [email protected]; Matan Azrad <[email protected]>
Subject: Re: [PATCH v4 2/4] mempool: add non-IO flagExternal email: Use caution opening links or attachments
Quoted 24 lines · Andrew Rybchenko
Quoted 22 lines · Dmitry Kozlyuk
Quoted 9 lines
-----Original Message-----
From: Andrew Rybchenko <[email protected]> [...]Quoted 7 lines
lib/mempool/rte_mempool.c +0
-0@@ -371,6 +371,8 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,Quoted 9 lines
lib/mempool/rte_mempool.c rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, · line 375
Quoted 4 lines
lib/mempool/rte_mempool.c +2
-0STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +if (iova ==RTE_BAD_IOVA ) + mp->flags |=MEMPOOL_F_NON_IO ;As I understand
rte_mempool_populate_iova()may be called few times for one mempool. The flag must be set if all invocations are done withRTE_BAD_IOVA. So, it should be set by default and just removed when iova !=RTE_BAD_IOVAhappens.I don't agree at all. If any object of the pool is unsuitable for IO, the pool cannot be considered suitable for IO. So if there's a single invocation with
RTE_BAD_IOVA, the flag must be set forever.
Quoted 7 lines
Quoted 3 lines
If so, some objects may be used for IO, some cannot be used. What should happen if an application allocates an object which is suitable for IO and try to use it this way?
If the application can predict if the allocated object is usable for IO before allocating it, I would be surprised to have it used for IO. I agree with Dmitry here.
The flag hints to components, PMDs before all,
that objects from this mempool will never be used for IO,
so that the component can save some memory mapping or DMA configuration. If the flag is set when even a single object may be used for IO, the consumer of the flag will not be ready for that. Whatever a corner case it is, Andrew is correct.
There is a subtle difference between "pool is not usable" (as described now) and "objects from this mempool will never be used" (as stated above), I'll highlight it in the flag description.
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
Quoted 46 lines · Dmitry Kozlyuk
Quoted 38 lines
-----Original Message-----
From: Olivier Matz <[email protected]>
Sent: 15 октября 2021 г. 12:43
To: Andrew Rybchenko <[email protected]>
Cc: Dmitry Kozlyuk <[email protected]>; [email protected]; Matan Azrad <[email protected]>
Subject: Re: [PATCH v4 2/4] mempool: add non-IO flagExternal email: Use caution opening links or attachments
Quoted 24 lines · Andrew Rybchenko
Quoted 22 lines · Dmitry Kozlyuk
Quoted 9 lines
-----Original Message-----
From: Andrew Rybchenko <[email protected]> [...]Quoted 7 lines
lib/mempool/rte_mempool.c +0
-0@@ -371,6 +371,8 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,Quoted 9 lines
lib/mempool/rte_mempool.c rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, · line 375
Quoted 4 lines
lib/mempool/rte_mempool.c +2
-0STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +if (iova ==RTE_BAD_IOVA ) + mp->flags |=MEMPOOL_F_NON_IO ;As I understand
rte_mempool_populate_iova()may be called few times for one mempool. The flag must be set if all invocations are done withRTE_BAD_IOVA. So, it should be set by default and just removed when iova !=RTE_BAD_IOVAhappens.I don't agree at all. If any object of the pool is unsuitable for IO, the pool cannot be considered suitable for IO. So if there's a single invocation with
RTE_BAD_IOVA, the flag must be set forever.Quoted 7 lines
Quoted 3 lines
If so, some objects may be used for IO, some cannot be used. What should happen if an application allocates an object which is suitable for IO and try to use it this way?
If the application can predict if the allocated object is usable for IO before allocating it, I would be surprised to have it used for IO. I agree with Dmitry here.
Quoted 9 lines
The flag hints to components, PMDs before all,
that objects from this mempool will never be used for IO,
so that the component can save some memory mapping or DMA configuration. If the flag is set when even a single object may be used for IO, the consumer of the flag will not be ready for that. Whatever a corner case it is, Andrew is correct.
There is a subtle difference between "pool is not usable" (as described now) and "objects from this mempool will never be used" (as stated above), I'll highlight it in the flag description.
OK, agreed, thanks.
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
In reply to Dmitry KozlyukHello Dmitry,
Quoted 14 lines · Dmitry Kozlyuk
lib/mempool/rte_mempool.h +2
-0@@ -262,6 +262,8 @@ struct rte_mempool {#define MEMPOOL_F_SC_GET 0x0008/**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010/**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020/**< Don't need IOVA contiguous objs. */ +#define MEMPOOL_F_NON_IO 0x0040 +/**< Internal: pool is not usable for device IO (DMA). */ /** * @internal When debug is enabled, store some statistics.
lib/mempool/rte_mempool.h typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *); · line 1001
Quoted 9 lines
lib/mempool/rte_mempool.h +3
-0@@ -991,6 +993,9 @@ typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);* "single-consumer". Otherwise, it is "multi-consumers". * - MEMPOOL_F_NO_IOVA_CONTIG: If set, allocated objects won't * necessarily be contiguous in IO memory. +* - MEMPOOL_F_NON_IO: If set, the mempool is considered to be +* never used for device IO, i.e. for DMA operations. +* It's a hint to other components and does not affect the mempool behavior. * @return * The pointer to the new allocated mempool, on success. NULL on error * with rte_errno set appropriately. Possible rte_errno values include:
- When rebasing on main, you probably won't be able to call this new flag. The diff should be something like:
app/test/test_mempool.c +1 -1
@@ -214,7 +214,7 @@ static int test_mempool_creation_with_unknown_flag(void)MEMPOOL_ELT_SIZE ,0 ,0 ,NULL ,NULL ,NULL ,NULL , - SOCKET_ID_ANY, MEMPOOL_F_NO_IOVA_CONTIG << 1); + SOCKET_ID_ANY, MEMPOOL_F_NON_IO << 1);if (mp_cov !=NULL ) {rte_mempool_free (mp_cov);
lib/mempool/rte_mempool.c +1 -0
@@ -802,6 +802,7 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache) | MEMPOOL_F_SC_GET \ | MEMPOOL_F_POOL_CREATED \ | MEMPOOL_F_NO_IOVA_CONTIG \ + | MEMPOOL_F_NON_IO \ )/* create an empty mempool */ struct rte_mempool *
- While grepping, I noticed that proc-info also dumps mempool flags. This could be something to enhance, maybe amending current rte_mempool_dump() and having this tool use it.
But for now, can you update this tool too?
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
Hello David,
Quoted 23 lines
[...]
- When rebasing on main, you probably won't be able to call this new flag. The diff should be something like:app/test/test_mempool.c index renamed from app/test/test_mempool.c +0
-0
d886f4800c..35c80291fa100644app/test/test_mempool.c +1
-1@@ -214,7 +214,7 @@ static inttest_mempool_creation_with_unknown_flag (void ) MEMPOOL_ELT_SIZE, 0, 0,NULL ,NULL ,NULL ,NULL , - SOCKET_ID_ANY, MEMPOOL_F_NO_IOVA_CONTIG << 1); + SOCKET_ID_ANY, MEMPOOL_F_NON_IO << 1);if (mp_cov !=NULL ) {rte_mempool_free(mp_cov); diff --git
a/lib/mempool/rte_mempool.cb/lib/mempool/rte_mempool.cindex8d5f99f7e7..27d197fe86100644
lib/mempool/rte_mempool.c rte_mempool_cache_free(struct rte_mempool_cache · line 806
Quoted 5 lines
lib/mempool/rte_mempool.c +1
-0@@ -802,6 +802,7 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache) |MEMPOOL_F_SC_GET \ |MEMPOOL_F_POOL_CREATED \ |MEMPOOL_F_NO_IOVA_CONTIG \ + |MEMPOOL_F_NON_IO \
I wonder why CREATED and NON_IO should be listed here:
they are not supposed to be passed by the user, which is what MEMPOOL_KNOWN_FLAGS is used for. The same question stands for the test code. Could you confirm your suggestion?
Quoted 9 lines
lib/mempool/rte_mempool.c +0
-0)/* create an empty mempool */ struct
rte_mempool*- While grepping, I noticed that proc-info also dumps mempool flags. This could be something to enhance, maybe amending current
rte_mempool_dump()and having this tool use it.
But for now, can you update this tool too?
I will, thanks for the hints.
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
Quoted 8 lines · Dmitry Kozlyuk
Quoted 8 lines
a/lib/mempool/rte_mempool.cb/lib/mempool/rte_mempool.cindex8d5f99f7e7..27d197fe86100644lib/mempool/rte_mempool.c +0
-0@@ -802,6 +802,7 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache) |MEMPOOL_F_SC_GET \ |MEMPOOL_F_POOL_CREATED \
Quoted 8 lines
lib/mempool/rte_mempool.c rte_mempool_cache_free(struct rte_mempool_cache *cache) · line 805
Quoted 2 lines
lib/mempool/rte_mempool.c +1
-0| MEMPOOL_F_NO_IOVA_CONTIG \ + |MEMPOOL_F_NON_IO \I wonder why CREATED and
NON_IOshould be listed here:
they are not supposed to be passed by the user, which is whatMEMPOOL_KNOWN_FLAGSis used for. The same question stands for the test code. Could you confirm your suggestion?
There was no distinction in the API for valid flags so far, and indeed I did not pay attention to MEMPOOL_F_POOL_CREATED and its internal aspect.
(That's the problem when mixing stuff together)
We could separate internal and exposed flags in different fields, but it seems overkill.
It would be seen as an API change too, if application were checking for this flag.
So let's keep this as is.
As you suggest, we should exclude those internal flags from KNOWN_FLAGS (probably rename it too), and we will have to export this define for the unit test since the check had been written with contiguous valid flags in mind.
If your new flag is internal only, I agree we must skip it.
I'll prepare a patch for mempool.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
Quoted 23 lines · David Marchand
Quoted 8 lines · Dmitry Kozlyuk
Quoted 8 lines
a/lib/mempool/rte_mempool.cb/lib/mempool/rte_mempool.cindex8d5f99f7e7..27d197fe86100644lib/mempool/rte_mempool.c +0
-0@@ -802,6 +802,7 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache) |MEMPOOL_F_SC_GET \ |MEMPOOL_F_POOL_CREATED \Quoted 8 lines
lib/mempool/rte_mempool.c rte_mempool_cache_free(struct rte_mempool_cache *cache) · line 805
Quoted 2 lines
lib/mempool/rte_mempool.c +1
-0| MEMPOOL_F_NO_IOVA_CONTIG \ + |MEMPOOL_F_NON_IO \I wonder why CREATED and
NON_IOshould be listed here:
they are not supposed to be passed by the user, which is whatMEMPOOL_KNOWN_FLAGSis used for. The same question stands for the test code. Could you confirm your suggestion?There was no distinction in the API for valid flags so far, and indeed I did not pay attention to
MEMPOOL_F_POOL_CREATEDand its internal aspect.
(That's the problem when mixing stuff together)
Quoted 8 lines
We could separate internal and exposed flags in different fields, but it seems overkill.
It would be seen as an API change too, if application were checking for this flag.
So let's keep this as is.As you suggest, we should exclude those internal flags from
KNOWN_FLAGS(probably rename it too), and we will have to export this
I suggest RTE_MEMPOOL_VALID_USER_FLAGS for the name
Quoted 9 lines
define for the unit test since the check had been written with contiguous valid flags in mind.
If your new flag is internal only, I agree we must skip it.I'll prepare a patch for mempool.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
In reply to Dmitry KozlyukHi Dmitry,
Quoted 34 lines · Dmitry Kozlyuk
Mempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add
MEMPOOL_F_NON_IOflag to mark such mempools automatically if their objects are not contiguous or IOVA are not available. Components can inspect this flag in order to optimize their memory management.
Discussion: https://mails.dpdk.org/archives/dev/2021-August/216654.htmlSigned-off-by Dmitry Kozlyuk <[email protected]>Acked-by Matan Azrad <[email protected]>--- app/test/test_mempool.c | 76 ++++++++++++++++++++++++++ doc/guides/rel_notes/release_21_11.rst | 3 + lib/mempool/rte_mempool.c | 2 + lib/mempool/rte_mempool.h | 5 ++ 4 files changed, 86 insertions(+)app/test/test_mempool.c +10
-0@@ -672,6 +672,74 @@ test_mempool_events_safety(void)return 0 ; } +static int +test_mempool_flag_non_io_set_when_no_iova_contig_set (void ) +{ +struct rte_mempool *mp; +int ret; + + mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,MEMPOOL_F_NO_IOVA_CONTIG ); + RTE_TEST_ASSERT_NOT_NULL(mp, "Cannot create mempool: %s",
app/test/test_mempool.c test_mempool_events_safety(void) · line 694
Quoted 10 lines
app/test/test_mempool.c +10
-0+ rte_strerror(rte_errno)); +rte_mempool_set_ops_byname (mp,rte_mbuf_best_mempool_ops (),NULL ); + ret =rte_mempool_populate_default (mp); +RTE_TEST_ASSERT (ret >0 ,"Failed to populate mempool: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT (mp->flags &MEMPOOL_F_NON_IO , +"NON_IO flag is not set when NO_IOVA_CONTIG is set" ); +rte_mempool_free (mp); +return 0 ; +}
One comment that also applies to the previous patch. Using RTE_TEST_ASSERT_*() is convenient to test a condition, display an error message and return on error in one operation. But here it can cause a leak on test failure.
I don't know what is the best approach to solve the issue. Having equivalent test macros that do "goto fail" instead of "return -1" would help here. I mean something like:
RTE_TEST_ASSERT_GOTO_*(cond, label, fmt, ...)
What do you think?
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
Quoted 29 lines
[...]
app/test/test_mempool.c test_mempool_events_safety(void)
Quoted 9 lines
app/test/test_mempool.c +9
-0+static int +test_mempool_flag_non_io_set_when_no_iova_contig_set (void ) +{ +struct rte_mempool *mp; +int ret; + + mp = rte_mempool_create_empty("empty", MEMPOOL_SIZE, + MEMPOOL_ELT_SIZE, 0, 0, + SOCKET_ID_ANY,
MEMPOOL_F_NO_IOVA_CONTIG);app/test/test_mempool.c test_mempool_events_safety(void)
Quoted 8 lines
app/test/test_mempool.c +8
-0+RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create mempool: %s" , +rte_strerror (rte_errno)); +rte_mempool_set_ops_byname (mp,rte_mbuf_best_mempool_ops (),NULL ); + ret =rte_mempool_populate_default (mp); +RTE_TEST_ASSERT (ret >0 ,"Failed to populate mempool: %s" , +rte_strerror (rte_errno)); + RTE_TEST_ASSERT(mp->flags & MEMPOOL_F_NON_IO, + "NON_IO flag is not set when NO_IOVA_CONTIG isset");
app/test/test_mempool.c test_mempool_events_safety(void) · line 694
Quoted 3 lines
app/test/test_mempool.c +3
-0+rte_mempool_free (mp); +return 0 ; +}One comment that also applies to the previous patch. Using RTE_TEST_ASSERT_*() is convenient to test a condition, display an error message and return on error in one operation. But here it can cause a leak on test failure.
Quoted 6 lines
I don't know what is the best approach to solve the issue. Having equivalent test macros that do "goto fail" instead of "return -1" would help here. I mean something like:
RTE_TEST_ASSERT_GOTO_*(cond, label, fmt, ...)What do you think?
This can work with existing macros:
#define TEST_TRACE_FAILURE(...) goto fail
Because of "trace" in the name it looks a bit like a hijacking. Probably the macro should be named TEST_HANDLE_FAILURE to suggest broader usages than just tracing,
but for now it looks the most neat way.
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
Quoted 36 lines · Dmitry Kozlyuk
Quoted 29 lines
[...]
app/test/test_mempool.c test_mempool_events_safety(void)
Quoted 9 lines
app/test/test_mempool.c +9
-0+static int +test_mempool_flag_non_io_set_when_no_iova_contig_set (void ) +{ +struct rte_mempool *mp; +int ret; + + mp = rte_mempool_create_empty("empty", MEMPOOL_SIZE, + MEMPOOL_ELT_SIZE, 0, 0, + SOCKET_ID_ANY,
MEMPOOL_F_NO_IOVA_CONTIG);app/test/test_mempool.c test_mempool_events_safety(void)
Quoted 8 lines
app/test/test_mempool.c +8
-0+RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create mempool: %s" , +rte_strerror (rte_errno)); +rte_mempool_set_ops_byname (mp,rte_mbuf_best_mempool_ops (),NULL ); + ret =rte_mempool_populate_default (mp); +RTE_TEST_ASSERT (ret >0 ,"Failed to populate mempool: %s" , +rte_strerror (rte_errno)); + RTE_TEST_ASSERT(mp->flags & MEMPOOL_F_NON_IO, + "NON_IO flag is not set when NO_IOVA_CONTIG isset");
app/test/test_mempool.c test_mempool_events_safety(void) · line 694
Quoted 3 lines
app/test/test_mempool.c +3
-0+rte_mempool_free (mp); +return 0 ; +}One comment that also applies to the previous patch. Using RTE_TEST_ASSERT_*() is convenient to test a condition, display an error message and return on error in one operation. But here it can cause a leak on test failure.
Quoted 6 lines
I don't know what is the best approach to solve the issue. Having equivalent test macros that do "goto fail" instead of "return -1" would help here. I mean something like:
RTE_TEST_ASSERT_GOTO_*(cond, label, fmt, ...)What do you think?
Quoted 8 lines
This can work with existing macros:
#define TEST_TRACE_FAILURE(...) goto failBecause of "trace" in the name it looks a bit like a hijacking. Probably the macro should be named
TEST_HANDLE_FAILUREto suggest broader usages than just tracing,
but for now it looks the most neat way.
That would work for me.
What about introducing another macro for this usage, that would be "return -1" by default and that can be overridden?
Re: [dpdk-dev] [PATCH v4 2/4] mempool: add non-IO flag
Quoted 53 lines
-----Original Message-----
From: Olivier Matz <[email protected]>
Sent: 15 октября 2021 г. 16:43
To: Dmitry Kozlyuk <[email protected]>
Cc: [email protected]; Andrew Rybchenko <[email protected]>; Matan Azrad <[email protected]>
Subject: Re: [PATCH v4 2/4] mempool: add non-IO flagExternal email: Use caution opening links or attachments
Quoted 11 lines · Dmitry Kozlyuk
Quoted 11 lines
[...]
app/test/test_mempool.c test_mempool_events_safety(void)
Quoted 9 lines
app/test/test_mempool.c +9
-0+static int +test_mempool_flag_non_io_set_when_no_iova_contig_set (void ) +{ +struct rte_mempool *mp; +int ret; + + mp = rte_mempool_create_empty("empty", MEMPOOL_SIZE, + MEMPOOL_ELT_SIZE, 0, 0, + SOCKET_ID_ANY,
MEMPOOL_F_NO_IOVA_CONTIG);Quoted 3 lines
Quoted 3 lines
app/test/test_mempool.c test_mempool_events_safety(void)
Quoted 3 lines
app/test/test_mempool.c +3
-0+RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create mempool: %s" , +rte_strerror (rte_errno)); + rte_mempool_set_ops_byname(mp, rte_mbuf_best_mempool_ops(),NULL);
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
app/test/test_mempool.c +5
-0+ ret =rte_mempool_populate_default (mp); +RTE_TEST_ASSERT (ret >0 ,"Failed to populate mempool: %s" , +rte_strerror (rte_errno)); + RTE_TEST_ASSERT(mp->flags & MEMPOOL_F_NON_IO, + "NON_IO flag is not set when NO_IOVA_CONTIG isQuoted 7 lines
Quoted 7 lines
set");
app/test/test_mempool.c test_mempool_events_safety(void) · line 694
Quoted 3 lines
app/test/test_mempool.c +3
-0+rte_mempool_free (mp); +return 0 ; +}One comment that also applies to the previous patch. Using RTE_TEST_ASSERT_*() is convenient to test a condition, display an
error
Quoted 5 lines
Quoted 5 lines
message and return on error in one operation. But here it can cause a leak on test failure.
I don't know what is the best approach to solve the issue. Having equivalent test macros that do "goto fail" instead of "return -1"
would
Quoted 7 lines
Quoted 4 lines
help here. I mean something like:
RTE_TEST_ASSERT_GOTO_*(cond, label, fmt, ...)What do you think?
This can work with existing macros:
Quoted 8 lines
Quoted 6 lines
#define TEST_TRACE_FAILURE(...) goto failBecause of "trace" in the name it looks a bit like a hijacking. Probably the macro should be named
TEST_HANDLE_FAILUREto suggest broader usages than just tracing,
but for now it looks the most neat way.That would work for me.
Did so in v9.
Quoted 2 lines
What about introducing another macro for this usage, that would be "return -1" by default and that can be overridden?
I like this suggestion by itself.
While implementing the solution with RTE_TEST_TRACE_FAILURE() I didn't like the hustle with #ifdef/#pragma push/pop_macro. At least some of them could be hidden, need to play with macros before suggesting something clean.
PATCH v4 3/4 common/mlx5: add mempool registration facilities
In reply to Dmitry KozlyukAdd 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.
--- drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + 5 files changed, 666 insertions(+)
drivers/common/mlx5/mlx5_common_mp.c +50 -0
@@ -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. *
drivers/common/mlx5/mlx5_common_mp.h +14 -0
@@ -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 ,
@@ -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;
@@ -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;
@@ -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
drivers/common/mlx5/mlx5_common_mr.c +580 -0
596 lines not on this page · raw message
drivers/common/mlx5/mlx5_common_mr.h +17 -0
@@ -13,6 +13,7 @@#include <rte_rwlock.h> #include <rte_bitmap.h> +#include <rte_mbuf.h> #include <rte_memory.h> #include "mlx5_glue.h"
@@ -75,6 +76,7 @@ struct mlx5_mr_ctrl { } __rte_packed;LIST_HEAD (mlx5_mr_list, mlx5_mr); +LIST_HEAD (mlx5_mempool_reg_list, mlx5_mempool_reg);/* Global per-device MR cache. */ struct mlx5_mr_share_cache {
@@ -83,6 +85,7 @@ struct mlx5_mr_share_cache {struct mlx5_mr_btree cache;/* Global MR cache table. */ struct mlx5_mr_list mr_list;/* Registered MR list. */ struct mlx5_mr_list mr_free_list;/* Freed MR list. */ +struct mlx5_mempool_reg_list mempool_reg_list;/* Mempool database. */ mlx5_reg_mr_t reg_mr_cb;/* Callback to reg_mr func */ mlx5_dereg_mr_t dereg_mr_cb;/* Callback to dereg_mr func */ } __rte_packed;
@@ -136,6 +139,10 @@ uint32_t mlx5_mr_addr2mr_bh(void *pd, struct mlx5_mp_id *mp_id,struct mlx5_mr_ctrl *mr_ctrl, uintptr_t addr, unsigned int mr_ext_memseg_en);__rte_internal +uint32_t mlx5_mr_mempool2mr_bh(struct mlx5_mr_share_cache *share_cache, +struct mlx5_mr_ctrl *mr_ctrl, +struct rte_mempool *mp,uintptr_t addr); +__rte_internal void mlx5_mr_release_cache(struct mlx5_mr_share_cache *mr_cache);__rte_internal void mlx5_mr_dump_cache(struct mlx5_mr_share_cache *share_cache __rte_unused);
@@ -179,4 +186,14 @@ mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);__rte_internal voidmlx5_mr_free (struct mlx5_mr *mr,mlx5_dereg_mr_t dereg_mr_cb); + +__rte_internal +int +mlx5_mr_mempool_register (struct mlx5_mr_share_cache *share_cache,void *pd, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +__rte_internal +int +mlx5_mr_mempool_unregister (struct mlx5_mr_share_cache *share_cache, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +#endif /* RTE_PMD_MLX5_COMMON_MR_H_ */
drivers/common/mlx5/version.map +5 -0
@@ -152,4 +152,9 @@ INTERNAL { mlx5_realloc; mlx5_translate_port_name; # WINDOWS_NO_EXPORT + + mlx5_mr_mempool_register; + mlx5_mr_mempool_unregister; + mlx5_mp_req_mempool_reg; + mlx5_mr_mempool2mr_bh; };
Signature · 1 line
2.25.1
PATCH v4 4/4 net/mlx5: support mempool registration
In reply to Dmitry KozlyukWhen the first port in a given protection domain (PD) starts, install a mempool event callback for this PD and register all existing memory regions (MR) for it. When the last port in a PD closes, remove the callback and unregister all mempools for this PD. This behavior can be switched off with a new devarg: mr_mempool_reg_en.
On TX slow path, i.e. when an MR key for the address of the buffer to send is not in the local cache, first try to retrieve it from the database of registered mempools. Supported are direct and indirect mbufs, as well as externally-attached ones from MLX5 MPRQ feature. Lookup in the database of non-mempool memory is used as the last resort.
RX mempools are registered regardless of the devarg value. On RX data path only the local cache and the mempool database is used. If implicit mempool registration is disabled, these mempools are unregistered at port stop, releasing the MRs.
--- doc/guides/nics/mlx5.rst | 13 +++ doc/guides/rel_notes/release_21_11.rst | 6 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 +++++++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 10 ++ drivers/net/mlx5/mlx5_mr.c | 120 +++++-------------- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 ++-- drivers/net/mlx5/mlx5_rxq.c | 13 +++ drivers/net/mlx5/mlx5_trigger.c | 77 +++++++++++-- drivers/net/mlx5/windows/mlx5_os.c | 1 + 12 files changed, 347 insertions(+), 116 deletions(-)
doc/guides/nics/mlx5.rst +13 -0
@@ -1001,6 +1001,19 @@ Driver options Enabled by default. +- ``mr_mempool_reg_en`` parameter [int] + + A nonzero value enables implicit registration of DMA memory of all mempools + except those having ``MEMPOOL_F_NON_IO``. This flag is set automatically + for mempools populated with non-contiguous objects or those without IOVA. + The effect is that when a packet from a mempool is transmitted, + its memory is already registered for DMA in the PMD and no registration + will happen on the data path. The tradeoff is extra work on the creation + of each mempool and increased HW resource use if some mempools + are not used with MLX5 devices. + + Enabled by default. + - ``representor`` parameter [list] This parameter can be used to instantiate DPDK Ethernet devices from
doc/guides/rel_notes/release_21_11.rst +6 -0
@@ -159,6 +159,12 @@ New Features * Added tests to verify tunnel header verification in IPsec inbound. * Added tests to verify inner checksum. +* **Updated Mellanox mlx5 driver.** + + Updated the Mellanox mlx5 driver with new features and improvements, including: + + * Added implicit mempool registration to avoid data path hiccups (opt-out). + Removed Items -------------
drivers/net/mlx5/linux/mlx5_mp_os.c +44 -0
56 lines not on this page · raw message
drivers/net/mlx5/linux/mlx5_os.c +2 -2
@@ -1034,8 +1034,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, err =mlx5_proc_priv_init (eth_dev);if (err)return NULL ; - mp_id.port_id = eth_dev->data->port_id; -strlcpy (mp_id.name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +mlx5_mp_id_init (&mp_id, eth_dev->data->port_id);/* Receive command fd from primary process */ err =mlx5_mp_req_verbs_cmd_fd (&mp_id);if (err <0 )
@@ -2133,6 +2132,7 @@ mlx5_os_config_default(struct mlx5_dev_config *config) config->txqs_inline =MLX5_ARG_UNSET ; config->vf_nl_en =1 ; config->mr_ext_memseg_en =1 ; + config->mr_mempool_reg_en =1 ; config->mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; config->mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; config->dv_esw_en =1 ;
drivers/net/mlx5/mlx5.c +152 -0
188 lines not on this page · raw message
drivers/net/mlx5/mlx5.h +10 -0
@@ -155,6 +155,13 @@ struct mlx5_flow_dump_ack {/** Key string for IPC. */ #define MLX5_MP_NAME "net_mlx5_mp" +/** Initialize a multi-process ID. */ +static inline void +mlx5_mp_id_init (struct mlx5_mp_id *mp_id,uint16_t port_id) +{ + mp_id->port_id = port_id; +strlcpy (mp_id->name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +}LIST_HEAD (mlx5_dev_list, mlx5_dev_ctx_shared);
@@ -270,6 +277,8 @@ struct mlx5_dev_config { unsigned int dv_miss_info:1; /* restore packet after partial hw miss */ unsigned int allow_duplicate_pattern:1;/* Allow/Prevent the duplicate rules pattern. */ + unsigned int mr_mempool_reg_en:1; +/* Allow/prevent implicit mempool memory registration. */ struct {unsigned int enabled:1 ;/* Whether MPRQ is enabled. */ unsigned int stride_num_n;/* Number of strides. */
@@ -1498,6 +1507,7 @@ struct mlx5_dev_ctx_shared * mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, const struct mlx5_dev_config *config);void mlx5_free_shared_dev_ctx (struct mlx5_dev_ctx_shared *sh); +int mlx5_dev_ctx_shared_mempool_subscribe (struct rte_eth_dev *dev);void mlx5_free_table_hash_list (struct mlx5_priv *priv);int mlx5_alloc_table_hash_list (struct mlx5_priv *priv); void mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
drivers/net/mlx5/mlx5_mr.c +27 -93
138 lines not on this page · raw message
drivers/net/mlx5/mlx5_mr.h +0 -2
@@ -22,7 +22,5 @@void mlx5_mr_mem_event_cb (enum rte_mem_event event_type,const void *addr,size_t len,void *arg); -int mlx5_mr_update_mp (struct rte_eth_dev *dev,struct mlx5_mr_ctrl *mr_ctrl, -struct rte_mempool *mp);#endif /* RTE_PMD_MLX5_MR_H_ */
drivers/net/mlx5/mlx5_rx.h +14 -7
@@ -275,13 +275,11 @@ uint16_t mlx5_rx_burst_vec(void *dpdk_rxq, struct rte_mbuf **pkts,uint16_t mlx5_rx_burst_mprq_vec (void *dpdk_rxq,struct rte_mbuf **pkts,uint16_t pkts_n); -/* mlx5_mr.c */ - -uint32_t mlx5_rx_addr2mr_bh (struct mlx5_rxq_data *rxq,uintptr_t addr); +static int mlx5_rxq_mprq_enabled (struct mlx5_rxq_data *rxq);/** -* Query LKey from a packet buffer for Rx. No need to flush local caches for Rx -* as mempool is pre-configured and static. +* Query LKey from a packet buffer for Rx. No need to flush local caches +* as the Rx mempool database entries are valid for the lifetime of the queue. * * @param rxq * Pointer to Rx queue structure.
@@ -290,11 +288,14 @@ uint32_t mlx5_rx_addr2mr_bh(struct mlx5_rxq_data *rxq, uintptr_t addr);* * @return * Searched LKey on success, UINT32_MAX on no match. +* This function always succeeds on valid input. */ static __rte_always_inline uint32_tmlx5_rx_addr2mr (struct mlx5_rxq_data *rxq,uintptr_t addr) {struct mlx5_mr_ctrl *mr_ctrl = &rxq->mr_ctrl; +struct mlx5_rxq_ctrl *rxq_ctrl; +struct rte_mempool *mp;uint32_t lkey;/* Linear search on MR cache array. */
@@ -302,8 +303,14 @@ mlx5_rx_addr2mr(struct mlx5_rxq_data *rxq, uintptr_t addr) MLX5_MR_CACHE_N, addr);if (likely (lkey !=UINT32_MAX ))return lkey; -/* Take slower bottom-half (Binary Search) on miss. */ -return mlx5_rx_addr2mr_bh (rxq, addr); +/* +* Slower search in the mempool database on miss. +* During queue creation rxq->sh is not yet set, so we use rxq_ctrl. +*/ + rxq_ctrl = container_of(rxq, struct mlx5_rxq_ctrl, rxq); + mp =mlx5_rxq_mprq_enabled (rxq) ? rxq->mprq_mp : rxq->mp; +return mlx5_mr_mempool2mr_bh (&rxq_ctrl->priv->sh->share_cache, + mr_ctrl, mp, addr); }#define mlx5_rx_mb2mr (rxq, mb) mlx5_rx_addr2mr(rxq, (uintptr_t)((mb)->buf_addr))
drivers/net/mlx5/mlx5_rxq.c +13 -0
@@ -1162,6 +1162,7 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)unsigned int strd_sz_n =0 ;unsigned int i;unsigned int n_ibv =0 ; +int ret;if (!mlx5_mprq_enabled (dev))return 0 ;
@@ -1241,6 +1242,16 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev) rte_errno =ENOMEM ;return -rte_errno; } + ret =mlx5_mr_mempool_register (&priv->sh->share_cache, priv->sh->pd, + mp, &priv->mp_id); +if (ret <0 && rte_errno !=EEXIST ) { + ret = rte_errno; +DRV_LOG (ERR ,"port %u failed to register a mempool for Multi-Packet RQ" , + dev->data->port_id); +rte_mempool_free (mp); + rte_errno = ret; +return -rte_errno; + } priv->mprq_mp = mp; exit:/* Set mempool for each Rx queue. */
@@ -1443,6 +1454,8 @@ mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,/* rte_errno is already set. */ goto error; } +/* Rx queues don't use this pointer, but we want a valid structure. */ + tmpl->rxq.mr_ctrl.dev_gen_ptr = &priv->sh->share_cache.dev_gen; tmpl->socket = socket;if (dev->data->dev_conf.intr_conf.rxq) tmpl->irq =1 ;
drivers/net/mlx5/mlx5_trigger.c +65 -12
95 lines not on this page · raw message
drivers/net/mlx5/windows/mlx5_os.c +1 -0
@@ -1116,6 +1116,7 @@ mlx5_os_net_probe(struct rte_device *dev) dev_config.txqs_inline =MLX5_ARG_UNSET ; dev_config.vf_nl_en =0 ; dev_config.mr_ext_memseg_en =1 ; + dev_config.mr_mempool_reg_en =1 ; dev_config.mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; dev_config.mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; dev_config.dv_esw_en =0 ;
Signature · 1 line
2.25.1
v5 cover net/mlx5: implicit mempool registration
In reply to Dmitry KozlyukMLX5 hardware has its internal IOMMU where PMD registers the memory. On the data path, PMD translates VA into a key consumed by the device IOMMU. It is impractical for the PMD to register all allocated memory because of increased lookup cost both in HW and SW. Most often mbuf memory comes from mempools, so if PMD tracks them, it can almost always have mbuf memory registered before an mbuf hits the PMD. This patchset adds such tracking in the PMD and internal API to support it.
Please see [1] for the discussion of the patch 2/4 and how it can be useful outside of the MLX5 PMD.
v5:
1. Change non-IO flag inference + various fixes (Andrew).
1. Fix callback unregistration from secondary processes (Olivier).
2. Support non-IO flag in proc-dump (David).
3. Fix the usage of locks (Olivier).
4. Avoid resource leaks in unit test (Olivier).
v4: (Andrew)
1. Improve mempool event callbacks unit tests and documentation.
2. Make MEMPOOL_F_NON_IO internal and automatically inferred. Add unit tests for the inference logic.
v3: Improve wording and naming; fix typos (Thomas).
v2 (internal review and testing):
1. Change tracked mempool event from being created (CREATE) to being fully populated (READY), which is the state PMD is interested in.
2. Unit test the new mempool callback API.
3. Remove bogus "error" messages in normal conditions.
4. Fixes in PMD.
Dmitry Kozlyuk (4):
mempool: add event callbacks
mempool: add non-IO flag
common/mlx5: add mempool registration facilities net/mlx5: support mempool registration
app/proc-info/main.c | 4 +- app/test/test_mempool.c | 360 +++++++++++++++ doc/guides/nics/mlx5.rst | 13 + doc/guides/rel_notes/release_21_11.rst | 9 + drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 ++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++ drivers/net/mlx5/mlx5.h | 10 + drivers/net/mlx5/mlx5_mr.c | 120 ++--- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 +- drivers/net/mlx5/mlx5_rxq.c | 13 + drivers/net/mlx5/mlx5_trigger.c | 77 +++- drivers/net/mlx5/windows/mlx5_os.c | 1 + lib/mempool/rte_mempool.c | 134 ++++++ lib/mempool/rte_mempool.h | 64 +++ lib/mempool/version.map | 8 + 22 files changed, 1585 insertions(+), 117 deletions(-)
Signature · 1 line
2.25.1
PATCH v5 1/4 mempool: add event callbacks
Data path performance can benefit if the PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track creation and destruction of mempools after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Add an API to register callback for mempool life cycle events:
* rte_mempool_event_callback_register()
* rte_mempool_event_callback_unregister()
Currently tracked events are:
* RTE_MEMPOOL_EVENT_READY (after populating a mempool)
* RTE_MEMPOOL_EVENT_DESTROY (before freeing a mempool) Provide a unit test for the new API.
The new API is internal, because it is primarily demanded by PMDs that may need to deal with any mempools and do not control their creation, while an application, on the other hand, knows which mempools it creates and doesn't care about internal mempools PMDs might create.
--- app/test/test_mempool.c | 248 ++++++++++++++++++++++++++++++++++++++ lib/mempool/rte_mempool.c | 124 +++++++++++++++++++ lib/mempool/rte_mempool.h | 62 ++++++++++ lib/mempool/version.map | 8 ++ 4 files changed, 442 insertions(+)
app/test/test_mempool.c +248 -0
@@ -14,6 +14,7 @@#include <rte_common.h> #include <rte_log.h> #include <rte_debug.h> +#include <rte_errno.h> #include <rte_memory.h> #include <rte_launch.h> #include <rte_cycles.h>
@@ -489,6 +490,245 @@ test_mp_mem_init(struct rte_mempool *mp, data->ret =0 ; } +struct test_mempool_events_data { +struct rte_mempool *mp; +enum rte_mempool_event event; +bool invoked; +}; + +static void +test_mempool_events_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *user_data) +{ +struct test_mempool_events_data *data = user_data; + + data->mp = mp; + data->event = event; + data->invoked = true; +} + +static int +test_mempool_events (int (*populate)(struct rte_mempool *mp)) +{ +#pragma push_macro("RTE_TEST_TRACE_FAILURE") +#undef RTE_TEST_TRACE_FAILURE +#define RTE_TEST_TRACE_FAILURE (...) do { goto fail; } while (0) + +static const size_t CB_NUM =3 ; +static const size_t MP_NUM =2 ; + +struct test_mempool_events_data data[CB_NUM ]; +struct rte_mempool *mp[MP_NUM ], *freed; +char name[RTE_MEMPOOL_NAMESIZE ]; +size_t i, j; +int ret; + +memset (mp,0 ,sizeof (mp)); +for (i =0 ; i <CB_NUM ; i++) { + ret =rte_mempool_event_callback_register + (test_mempool_events_cb, &data[i]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to register the callback %zu: %s" , + i,rte_strerror (rte_errno)); + } + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, mp); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Unregistered a non-registered callback" ); +/* NULL argument has no special meaning in this API. */ + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, +NULL ); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Unregistered a non-registered callback with NULL argument" ); + +/* Create mempool 0 that will be observed by all callbacks. */ +memset (&data,0 ,sizeof (data)); +strcpy (name,"empty0" ); + mp[0 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp[0 ],"Cannot create mempool %s: %s" , + name,rte_strerror (rte_errno)); +for (j =0 ; j <CB_NUM ; j++) +RTE_TEST_ASSERT_EQUAL (data[j].invoked, false, +"Callback %zu invoked on %s mempool creation" , + j, name); + +rte_mempool_set_ops_byname (mp[0 ],rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp[0 ]); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp[0 ]->size,"Failed to populate mempool %s: %s" , + name,rte_strerror (rte_errno)); +for (j =0 ; j <CB_NUM ; j++) { +RTE_TEST_ASSERT_EQUAL (data[j].invoked, true, +"Callback %zu not invoked on mempool %s population" , + j, name); +RTE_TEST_ASSERT_EQUAL (data[j].event, +RTE_MEMPOOL_EVENT_READY , +"Wrong callback invoked, expected READY" ); +RTE_TEST_ASSERT_EQUAL (data[j].mp, mp[0 ], +"Callback %zu invoked for a wrong mempool instead of %s" , + j, name); + } + +/* Check that unregistered callback 0 observes no events. */ + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, + &data[0 ]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister callback 0: %s" , +rte_strerror (rte_errno)); +memset (&data,0 ,sizeof (data)); +strcpy (name,"empty1" ); + mp[1 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp[1 ],"Cannot create mempool %s: %s" , + name,rte_strerror (rte_errno)); +rte_mempool_set_ops_byname (mp[1 ],rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp[1 ]); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp[1 ]->size,"Failed to populate mempool %s: %s" , + name,rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data[0 ].invoked, false, +"Unregistered callback 0 invoked on %s mempool populaton" , + name); + +for (i =0 ; i <MP_NUM ; i++) { +memset (&data,0 ,sizeof (data)); +sprintf (name,"empty%zu" , i); +rte_mempool_free (mp[i]); +/* +* Save pointer to check that it was passed to the callback, +* but put NULL into the array in case cleanup is called early. +*/ + freed = mp[i]; + mp[i] =NULL ; +for (j =1 ; j <CB_NUM ; j++) { +RTE_TEST_ASSERT_EQUAL (data[j].invoked, true, +"Callback %zu not invoked on mempool %s destruction" , + j, name); +RTE_TEST_ASSERT_EQUAL (data[j].event, +RTE_MEMPOOL_EVENT_DESTROY , +"Wrong callback invoked, expected DESTROY" ); +RTE_TEST_ASSERT_EQUAL (data[j].mp, freed, +"Callback %zu invoked for a wrong mempool instead of %s" , + j, name); + } +RTE_TEST_ASSERT_EQUAL (data[0 ].invoked, false, +"Unregistered callback 0 invoked on %s mempool destruction" , + name); + } + +for (j =1 ; j <CB_NUM ; j++) { + ret =rte_mempool_event_callback_unregister + (test_mempool_events_cb, &data[j]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister the callback %zu: %s" , + j,rte_strerror (rte_errno)); + } +return TEST_SUCCESS ; + +fail: +for (j =0 ; j <CB_NUM ; j++) +rte_mempool_event_callback_unregister + (test_mempool_events_cb, &data[j]); +for (i =0 ; i <MP_NUM ; i++) +rte_mempool_free (mp[i]); +return TEST_FAILED ; + +#pragma pop_macro("RTE_TEST_TRACE_FAILURE") +} + +struct test_mempool_events_safety_data { +bool invoked; +int (*api_func)(rte_mempool_event_callback *func,void *user_data); +rte_mempool_event_callback *cb_func; +void *cb_user_data; +int ret; +}; + +static void +test_mempool_events_safety_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *user_data) +{ +struct test_mempool_events_safety_data *data = user_data; + +RTE_SET_USED (event); +RTE_SET_USED (mp); + data->invoked = true; + data->ret = data->api_func (data->cb_func, data->cb_user_data); +} + +static int +test_mempool_events_safety (void ) +{ +#pragma push_macro("RTE_TEST_TRACE_FAILURE") +#undef RTE_TEST_TRACE_FAILURE +#define RTE_TEST_TRACE_FAILURE (...) do { \ + ret = TEST_FAILED; \ + goto exit; \ + } while (0) + +struct test_mempool_events_data data; +struct test_mempool_events_safety_data sdata[2 ]; +struct rte_mempool *mp; +size_t i; +int ret; + +/* removes itself */ + sdata[0 ].api_func = rte_mempool_event_callback_unregister; + sdata[0 ].cb_func = test_mempool_events_safety_cb; + sdata[0 ].cb_user_data = &sdata[0 ]; + sdata[0 ].ret =-1 ; +rte_mempool_event_callback_register (test_mempool_events_safety_cb, + &sdata[0 ]); +/* inserts a callback after itself */ + sdata[1 ].api_func = rte_mempool_event_callback_register; + sdata[1 ].cb_func = test_mempool_events_cb; + sdata[1 ].cb_user_data = &data; + sdata[1 ].ret =-1 ; +rte_mempool_event_callback_register (test_mempool_events_safety_cb, + &sdata[1 ]); + + mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create mempool: %s" , +rte_strerror (rte_errno)); +memset (&data,0 ,sizeof (data)); + ret =rte_mempool_populate_default (mp); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp->size,"Failed to populate mempool: %s" , +rte_strerror (rte_errno)); + +RTE_TEST_ASSERT_EQUAL (sdata[0 ].ret,0 ,"Callback failed to unregister itself: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (sdata[1 ].ret,0 ,"Failed to insert a new callback: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data.invoked, false, +"Inserted callback is invoked on mempool population" ); + +memset (&data,0 ,sizeof (data)); + sdata[0 ].invoked = false; +rte_mempool_free (mp); + mp =NULL ; +RTE_TEST_ASSERT_EQUAL (sdata[0 ].invoked, false, +"Callback that unregistered itself was called" ); +RTE_TEST_ASSERT_EQUAL (sdata[1 ].ret, -EEXIST , +"New callback inserted twice" ); +RTE_TEST_ASSERT_EQUAL (data.invoked, true, +"Inserted callback is not invoked on mempool destruction" ); + +rte_mempool_event_callback_unregister (test_mempool_events_cb, &data); +for (i =0 ; i <RTE_DIM (sdata); i++) +rte_mempool_event_callback_unregister + (test_mempool_events_safety_cb, &sdata[i]); + ret =TEST_SUCCESS ; + +exit: +/* cleanup, don't care which callbacks are already removed */ +rte_mempool_event_callback_unregister (test_mempool_events_cb, &data); +for (i =0 ; i <RTE_DIM (sdata); i++) +rte_mempool_event_callback_unregister + (test_mempool_events_safety_cb, &sdata[i]); +/* in case of failure before the planned destruction */ +rte_mempool_free (mp); +return ret; + +#pragma pop_macro("RTE_TEST_TRACE_FAILURE") +} +static int test_mempool (void ) {
@@ -666,6 +906,14 @@ test_mempool(void)if (test_mempool_basic (default_pool,1 ) <0 )GOTO_ERR (ret, err); +/* test mempool event callbacks */ +if (test_mempool_events (rte_mempool_populate_default) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events (rte_mempool_populate_anon) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events_safety () <0 ) +GOTO_ERR (ret, err); +rte_mempool_list_dump (stdout); ret =0 ;
lib/mempool/rte_mempool.c +124 -0
145 lines not on this page · raw message
lib/mempool/rte_mempool.h +62 -0
68 lines not on this page · raw message
lib/mempool/version.map +8 -0
@@ -64,3 +64,11 @@ EXPERIMENTAL { __rte_mempool_trace_ops_free; __rte_mempool_trace_set_ops_byname; }; + +INTERNAL { + global: + + # added in 21.11 + rte_mempool_event_callback_register; + rte_mempool_event_callback_unregister; +};
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v5 1/4] mempool: add event callbacks
Quoted 20 lines · Dmitry Kozlyuk
Data path performance can benefit if the PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track creation and destruction of mempools after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Add an API to register callback for mempool life cycle events:
*rte_mempool_event_callback_register()
*rte_mempool_event_callback_unregister()
Currently tracked events are:
*RTE_MEMPOOL_EVENT_READY(after populating a mempool)
*RTE_MEMPOOL_EVENT_DESTROY(before freeing a mempool) Provide a unit test for the new API.
The new API is internal, because it is primarily demanded by PMDs that may need to deal with any mempools and do not control their creation, while an application, on the other hand, knows which mempools it creates and doesn't care about internal mempools PMDs might create.
Quoted 4 lines
Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Matan Azrad <[email protected]>Reviewed-by Andrew Rybchenko <[email protected]>---
PATCH v5 2/4 mempool: add non-IO flag
In reply to Dmitry KozlyukMempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add MEMPOOL_F_NON_IO flag to mark such mempools automatically
a) if their objects are not contiguous;
b) if IOVA is not available for any object.
Other components can inspect this flag
in order to optimize their memory management.
Discussion: https://mails.dpdk.org/archives/dev/2021-August/216654.html
--- app/proc-info/main.c | 4 +- app/test/test_mempool.c | 112 +++++++++++++++++++++++++ doc/guides/rel_notes/release_21_11.rst | 3 + lib/mempool/rte_mempool.c | 10 +++ lib/mempool/rte_mempool.h | 2 + 5 files changed, 130 insertions(+), 1 deletion(-)
app/proc-info/main.c +3 -1
@@ -1296,6 +1296,7 @@ show_mempool(char *name)"\t -- SP put (%c), SC get (%c)\n" "\t -- Pool created (%c)\n" "\t -- No IOVA config (%c)\n" , +"\t -- Not used for IO (%c)\n" , ptr->name, ptr->socket_id, (flags & MEMPOOL_F_NO_SPREAD) ? 'y' : 'n',
@@ -1303,7 +1304,8 @@ show_mempool(char *name) (flags &MEMPOOL_F_SP_PUT ) ?'y' :'n' , (flags &MEMPOOL_F_SC_GET ) ?'y' :'n' , (flags &MEMPOOL_F_POOL_CREATED ) ?'y' :'n' , - (flags & MEMPOOL_F_NO_IOVA_CONTIG) ? 'y' : 'n'); + (flags &MEMPOOL_F_NO_IOVA_CONTIG ) ?'y' :'n' , + (flags & MEMPOOL_F_NON_IO) ? 'y' : 'n'); printf(" - Size %u Cache %u element %u\n" " - header %u trailer %u\n" " - private data size %u\n",
app/test/test_mempool.c +112 -0
130 lines not on this page · raw message
doc/guides/rel_notes/release_21_11.rst +3 -0
@@ -229,6 +229,9 @@ API Changes the crypto/security operation. This field will be used to communicate events such as soft expiry with IPsec in lookaside mode. +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA). + ABI Changes -----------
lib/mempool/rte_mempool.c +10 -0
@@ -372,6 +372,10 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +/* At least some objects in the pool can now be used for IO. */ +if (iova !=RTE_BAD_IOVA ) + mp->flags &= ~MEMPOOL_F_NON_IO ; +/* Report the mempool as ready only when fully populated. */ if (mp->populated_size >= mp->size)mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_READY , mp);
@@ -851,6 +855,12 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,return NULL ; } +/* +* No objects in the pool can be used for IO until it's populated +* with at least some objects with valid IOVA. +*/ + flags |=MEMPOOL_F_NON_IO ; +/* "no cache align" imply "no spread" */ if (flags &MEMPOOL_F_NO_CACHE_ALIGN ) flags |=MEMPOOL_F_NO_SPREAD ;
lib/mempool/rte_mempool.h +2 -0
@@ -257,6 +257,8 @@ struct rte_mempool {#define MEMPOOL_F_SC_GET 0x0008/**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010/**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020/**< Don't need IOVA contiguous objs. */ +/** Internal: no object from the pool can be used for device IO (DMA). */ +#define MEMPOOL_F_NON_IO 0x0040/** * @internal When debug is enabled, store some statistics.
Signature · 1 line
2.25.1
PATCH v5 3/4 common/mlx5: add mempool registration facilities
In reply to Dmitry KozlyukAdd 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.
--- drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + 5 files changed, 666 insertions(+)
drivers/common/mlx5/mlx5_common_mp.c +50 -0
@@ -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. *
drivers/common/mlx5/mlx5_common_mp.h +14 -0
@@ -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 ,
@@ -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;
@@ -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;
@@ -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
drivers/common/mlx5/mlx5_common_mr.c +580 -0
596 lines not on this page · raw message
drivers/common/mlx5/mlx5_common_mr.h +17 -0
@@ -13,6 +13,7 @@#include <rte_rwlock.h> #include <rte_bitmap.h> +#include <rte_mbuf.h> #include <rte_memory.h> #include "mlx5_glue.h"
@@ -75,6 +76,7 @@ struct mlx5_mr_ctrl { } __rte_packed;LIST_HEAD (mlx5_mr_list, mlx5_mr); +LIST_HEAD (mlx5_mempool_reg_list, mlx5_mempool_reg);/* Global per-device MR cache. */ struct mlx5_mr_share_cache {
@@ -83,6 +85,7 @@ struct mlx5_mr_share_cache {struct mlx5_mr_btree cache;/* Global MR cache table. */ struct mlx5_mr_list mr_list;/* Registered MR list. */ struct mlx5_mr_list mr_free_list;/* Freed MR list. */ +struct mlx5_mempool_reg_list mempool_reg_list;/* Mempool database. */ mlx5_reg_mr_t reg_mr_cb;/* Callback to reg_mr func */ mlx5_dereg_mr_t dereg_mr_cb;/* Callback to dereg_mr func */ } __rte_packed;
@@ -136,6 +139,10 @@ uint32_t mlx5_mr_addr2mr_bh(void *pd, struct mlx5_mp_id *mp_id,struct mlx5_mr_ctrl *mr_ctrl, uintptr_t addr, unsigned int mr_ext_memseg_en);__rte_internal +uint32_t mlx5_mr_mempool2mr_bh(struct mlx5_mr_share_cache *share_cache, +struct mlx5_mr_ctrl *mr_ctrl, +struct rte_mempool *mp,uintptr_t addr); +__rte_internal void mlx5_mr_release_cache(struct mlx5_mr_share_cache *mr_cache);__rte_internal void mlx5_mr_dump_cache(struct mlx5_mr_share_cache *share_cache __rte_unused);
@@ -179,4 +186,14 @@ mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);__rte_internal voidmlx5_mr_free (struct mlx5_mr *mr,mlx5_dereg_mr_t dereg_mr_cb); + +__rte_internal +int +mlx5_mr_mempool_register (struct mlx5_mr_share_cache *share_cache,void *pd, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +__rte_internal +int +mlx5_mr_mempool_unregister (struct mlx5_mr_share_cache *share_cache, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +#endif /* RTE_PMD_MLX5_COMMON_MR_H_ */
drivers/common/mlx5/version.map +5 -0
@@ -152,4 +152,9 @@ INTERNAL { mlx5_realloc; mlx5_translate_port_name; # WINDOWS_NO_EXPORT + + mlx5_mr_mempool_register; + mlx5_mr_mempool_unregister; + mlx5_mp_req_mempool_reg; + mlx5_mr_mempool2mr_bh; };
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v5 3/4] common/mlx5: add mempool registration facilities
Quoted 7 lines · Dmitry Kozlyuk
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.
Quoted 7 lines
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 <[email protected]>Acked-by Matan Azrad <[email protected]>---
PATCH v5 4/4 net/mlx5: support mempool registration
In reply to Dmitry KozlyukWhen the first port in a given protection domain (PD) starts, install a mempool event callback for this PD and register all existing memory regions (MR) for it. When the last port in a PD closes, remove the callback and unregister all mempools for this PD. This behavior can be switched off with a new devarg: mr_mempool_reg_en.
On TX slow path, i.e. when an MR key for the address of the buffer to send is not in the local cache, first try to retrieve it from the database of registered mempools. Supported are direct and indirect mbufs, as well as externally-attached ones from MLX5 MPRQ feature. Lookup in the database of non-mempool memory is used as the last resort.
RX mempools are registered regardless of the devarg value. On RX data path only the local cache and the mempool database is used. If implicit mempool registration is disabled, these mempools are unregistered at port stop, releasing the MRs.
--- doc/guides/nics/mlx5.rst | 13 +++ doc/guides/rel_notes/release_21_11.rst | 6 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 +++++++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 10 ++ drivers/net/mlx5/mlx5_mr.c | 120 +++++-------------- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 ++-- drivers/net/mlx5/mlx5_rxq.c | 13 +++ drivers/net/mlx5/mlx5_trigger.c | 77 +++++++++++-- drivers/net/mlx5/windows/mlx5_os.c | 1 + 12 files changed, 347 insertions(+), 116 deletions(-)
doc/guides/nics/mlx5.rst +13 -0
@@ -1001,6 +1001,19 @@ Driver options Enabled by default. +- ``mr_mempool_reg_en`` parameter [int] + + A nonzero value enables implicit registration of DMA memory of all mempools + except those having ``MEMPOOL_F_NON_IO``. This flag is set automatically + for mempools populated with non-contiguous objects or those without IOVA. + The effect is that when a packet from a mempool is transmitted, + its memory is already registered for DMA in the PMD and no registration + will happen on the data path. The tradeoff is extra work on the creation + of each mempool and increased HW resource use if some mempools + are not used with MLX5 devices. + + Enabled by default. + - ``representor`` parameter [list] This parameter can be used to instantiate DPDK Ethernet devices from
doc/guides/rel_notes/release_21_11.rst +6 -0
@@ -159,6 +159,12 @@ New Features * Added tests to verify tunnel header verification in IPsec inbound. * Added tests to verify inner checksum. +* **Updated Mellanox mlx5 driver.** + + Updated the Mellanox mlx5 driver with new features and improvements, including: + + * Added implicit mempool registration to avoid data path hiccups (opt-out). + Removed Items -------------
drivers/net/mlx5/linux/mlx5_mp_os.c +44 -0
56 lines not on this page · raw message
drivers/net/mlx5/linux/mlx5_os.c +2 -2
@@ -1034,8 +1034,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, err =mlx5_proc_priv_init (eth_dev);if (err)return NULL ; - mp_id.port_id = eth_dev->data->port_id; -strlcpy (mp_id.name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +mlx5_mp_id_init (&mp_id, eth_dev->data->port_id);/* Receive command fd from primary process */ err =mlx5_mp_req_verbs_cmd_fd (&mp_id);if (err <0 )
@@ -2133,6 +2132,7 @@ mlx5_os_config_default(struct mlx5_dev_config *config) config->txqs_inline =MLX5_ARG_UNSET ; config->vf_nl_en =1 ; config->mr_ext_memseg_en =1 ; + config->mr_mempool_reg_en =1 ; config->mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; config->mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; config->dv_esw_en =1 ;
drivers/net/mlx5/mlx5.c +152 -0
188 lines not on this page · raw message
drivers/net/mlx5/mlx5.h +10 -0
@@ -155,6 +155,13 @@ struct mlx5_flow_dump_ack {/** Key string for IPC. */ #define MLX5_MP_NAME "net_mlx5_mp" +/** Initialize a multi-process ID. */ +static inline void +mlx5_mp_id_init (struct mlx5_mp_id *mp_id,uint16_t port_id) +{ + mp_id->port_id = port_id; +strlcpy (mp_id->name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +}LIST_HEAD (mlx5_dev_list, mlx5_dev_ctx_shared);
@@ -270,6 +277,8 @@ struct mlx5_dev_config { unsigned int dv_miss_info:1; /* restore packet after partial hw miss */ unsigned int allow_duplicate_pattern:1;/* Allow/Prevent the duplicate rules pattern. */ + unsigned int mr_mempool_reg_en:1; +/* Allow/prevent implicit mempool memory registration. */ struct {unsigned int enabled:1 ;/* Whether MPRQ is enabled. */ unsigned int stride_num_n;/* Number of strides. */
@@ -1498,6 +1507,7 @@ struct mlx5_dev_ctx_shared * mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, const struct mlx5_dev_config *config);void mlx5_free_shared_dev_ctx (struct mlx5_dev_ctx_shared *sh); +int mlx5_dev_ctx_shared_mempool_subscribe (struct rte_eth_dev *dev);void mlx5_free_table_hash_list (struct mlx5_priv *priv);int mlx5_alloc_table_hash_list (struct mlx5_priv *priv); void mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
drivers/net/mlx5/mlx5_mr.c +27 -93
138 lines not on this page · raw message
drivers/net/mlx5/mlx5_mr.h +0 -2
@@ -22,7 +22,5 @@void mlx5_mr_mem_event_cb (enum rte_mem_event event_type,const void *addr,size_t len,void *arg); -int mlx5_mr_update_mp (struct rte_eth_dev *dev,struct mlx5_mr_ctrl *mr_ctrl, -struct rte_mempool *mp);#endif /* RTE_PMD_MLX5_MR_H_ */
drivers/net/mlx5/mlx5_rx.h +14 -7
@@ -275,13 +275,11 @@ uint16_t mlx5_rx_burst_vec(void *dpdk_rxq, struct rte_mbuf **pkts,uint16_t mlx5_rx_burst_mprq_vec (void *dpdk_rxq,struct rte_mbuf **pkts,uint16_t pkts_n); -/* mlx5_mr.c */ - -uint32_t mlx5_rx_addr2mr_bh (struct mlx5_rxq_data *rxq,uintptr_t addr); +static int mlx5_rxq_mprq_enabled (struct mlx5_rxq_data *rxq);/** -* Query LKey from a packet buffer for Rx. No need to flush local caches for Rx -* as mempool is pre-configured and static. +* Query LKey from a packet buffer for Rx. No need to flush local caches +* as the Rx mempool database entries are valid for the lifetime of the queue. * * @param rxq * Pointer to Rx queue structure.
@@ -290,11 +288,14 @@ uint32_t mlx5_rx_addr2mr_bh(struct mlx5_rxq_data *rxq, uintptr_t addr);* * @return * Searched LKey on success, UINT32_MAX on no match. +* This function always succeeds on valid input. */ static __rte_always_inline uint32_tmlx5_rx_addr2mr (struct mlx5_rxq_data *rxq,uintptr_t addr) {struct mlx5_mr_ctrl *mr_ctrl = &rxq->mr_ctrl; +struct mlx5_rxq_ctrl *rxq_ctrl; +struct rte_mempool *mp;uint32_t lkey;/* Linear search on MR cache array. */
@@ -302,8 +303,14 @@ mlx5_rx_addr2mr(struct mlx5_rxq_data *rxq, uintptr_t addr) MLX5_MR_CACHE_N, addr);if (likely (lkey !=UINT32_MAX ))return lkey; -/* Take slower bottom-half (Binary Search) on miss. */ -return mlx5_rx_addr2mr_bh (rxq, addr); +/* +* Slower search in the mempool database on miss. +* During queue creation rxq->sh is not yet set, so we use rxq_ctrl. +*/ + rxq_ctrl = container_of(rxq, struct mlx5_rxq_ctrl, rxq); + mp =mlx5_rxq_mprq_enabled (rxq) ? rxq->mprq_mp : rxq->mp; +return mlx5_mr_mempool2mr_bh (&rxq_ctrl->priv->sh->share_cache, + mr_ctrl, mp, addr); }#define mlx5_rx_mb2mr (rxq, mb) mlx5_rx_addr2mr(rxq, (uintptr_t)((mb)->buf_addr))
drivers/net/mlx5/mlx5_rxq.c +13 -0
@@ -1162,6 +1162,7 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)unsigned int strd_sz_n =0 ;unsigned int i;unsigned int n_ibv =0 ; +int ret;if (!mlx5_mprq_enabled (dev))return 0 ;
@@ -1241,6 +1242,16 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev) rte_errno =ENOMEM ;return -rte_errno; } + ret =mlx5_mr_mempool_register (&priv->sh->share_cache, priv->sh->pd, + mp, &priv->mp_id); +if (ret <0 && rte_errno !=EEXIST ) { + ret = rte_errno; +DRV_LOG (ERR ,"port %u failed to register a mempool for Multi-Packet RQ" , + dev->data->port_id); +rte_mempool_free (mp); + rte_errno = ret; +return -rte_errno; + } priv->mprq_mp = mp; exit:/* Set mempool for each Rx queue. */
@@ -1443,6 +1454,8 @@ mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,/* rte_errno is already set. */ goto error; } +/* Rx queues don't use this pointer, but we want a valid structure. */ + tmpl->rxq.mr_ctrl.dev_gen_ptr = &priv->sh->share_cache.dev_gen; tmpl->socket = socket;if (dev->data->dev_conf.intr_conf.rxq) tmpl->irq =1 ;
drivers/net/mlx5/mlx5_trigger.c +65 -12
95 lines not on this page · raw message
drivers/net/mlx5/windows/mlx5_os.c +1 -0
@@ -1116,6 +1116,7 @@ mlx5_os_net_probe(struct rte_device *dev) dev_config.txqs_inline =MLX5_ARG_UNSET ; dev_config.vf_nl_en =0 ; dev_config.mr_ext_memseg_en =1 ; + dev_config.mr_mempool_reg_en =1 ; dev_config.mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; dev_config.mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; dev_config.dv_esw_en =0 ;
Signature · 1 line
2.25.1
v6 cover net/mlx5: implicit mempool registration
In reply to Dmitry KozlyukMLX5 hardware has its internal IOMMU where PMD registers the memory. On the data path, PMD translates VA into a key consumed by the device IOMMU. It is impractical for the PMD to register all allocated memory because of increased lookup cost both in HW and SW. Most often mbuf memory comes from mempools, so if PMD tracks them, it can almost always have mbuf memory registered before an mbuf hits the PMD. This patchset adds such tracking in the PMD and internal API to support it.
Please see [1] for the discussion of the patch 2/4 and how it can be useful outside of the MLX5 PMD.
v6:
Fix compilation issue in proc-info (CI).
v5:
1. Change non-IO flag inference + various fixes (Andrew).
1. Fix callback unregistration from secondary processes (Olivier).
2. Support non-IO flag in proc-dump (David).
3. Fix the usage of locks (Olivier).
4. Avoid resource leaks in unit test (Olivier).
v4: (Andrew)
1. Improve mempool event callbacks unit tests and documentation.
2. Make MEMPOOL_F_NON_IO internal and automatically inferred. Add unit tests for the inference logic.
v3: Improve wording and naming; fix typos (Thomas).
v2 (internal review and testing):
1. Change tracked mempool event from being created (CREATE) to being fully populated (READY), which is the state PMD is interested in.
2. Unit test the new mempool callback API.
3. Remove bogus "error" messages in normal conditions.
4. Fixes in PMD.
Dmitry Kozlyuk (4):
mempool: add event callbacks
mempool: add non-IO flag
common/mlx5: add mempool registration facilities net/mlx5: support mempool registration
app/proc-info/main.c | 6 +- app/test/test_mempool.c | 360 +++++++++++++++ doc/guides/nics/mlx5.rst | 13 + doc/guides/rel_notes/release_21_11.rst | 9 + drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 ++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++ drivers/net/mlx5/mlx5.h | 10 + drivers/net/mlx5/mlx5_mr.c | 120 ++--- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 +- drivers/net/mlx5/mlx5_rxq.c | 13 + drivers/net/mlx5/mlx5_trigger.c | 77 +++- drivers/net/mlx5/windows/mlx5_os.c | 1 + lib/mempool/rte_mempool.c | 134 ++++++ lib/mempool/rte_mempool.h | 64 +++ lib/mempool/version.map | 8 + 22 files changed, 1586 insertions(+), 118 deletions(-)
Signature · 1 line
2.25.1
PATCH v6 1/4 mempool: add event callbacks
Data path performance can benefit if the PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track creation and destruction of mempools after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Add an API to register callback for mempool life cycle events:
* rte_mempool_event_callback_register()
* rte_mempool_event_callback_unregister()
Currently tracked events are:
* RTE_MEMPOOL_EVENT_READY (after populating a mempool)
* RTE_MEMPOOL_EVENT_DESTROY (before freeing a mempool) Provide a unit test for the new API.
The new API is internal, because it is primarily demanded by PMDs that may need to deal with any mempools and do not control their creation, while an application, on the other hand, knows which mempools it creates and doesn't care about internal mempools PMDs might create.
--- app/test/test_mempool.c | 248 ++++++++++++++++++++++++++++++++++++++ lib/mempool/rte_mempool.c | 124 +++++++++++++++++++ lib/mempool/rte_mempool.h | 62 ++++++++++ lib/mempool/version.map | 8 ++ 4 files changed, 442 insertions(+)
app/test/test_mempool.c +248 -0
@@ -14,6 +14,7 @@#include <rte_common.h> #include <rte_log.h> #include <rte_debug.h> +#include <rte_errno.h> #include <rte_memory.h> #include <rte_launch.h> #include <rte_cycles.h>
@@ -489,6 +490,245 @@ test_mp_mem_init(struct rte_mempool *mp, data->ret =0 ; } +struct test_mempool_events_data { +struct rte_mempool *mp; +enum rte_mempool_event event; +bool invoked; +}; + +static void +test_mempool_events_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *user_data) +{ +struct test_mempool_events_data *data = user_data; + + data->mp = mp; + data->event = event; + data->invoked = true; +} + +static int +test_mempool_events (int (*populate)(struct rte_mempool *mp)) +{ +#pragma push_macro("RTE_TEST_TRACE_FAILURE") +#undef RTE_TEST_TRACE_FAILURE +#define RTE_TEST_TRACE_FAILURE (...) do { goto fail; } while (0) + +static const size_t CB_NUM =3 ; +static const size_t MP_NUM =2 ; + +struct test_mempool_events_data data[CB_NUM ]; +struct rte_mempool *mp[MP_NUM ], *freed; +char name[RTE_MEMPOOL_NAMESIZE ]; +size_t i, j; +int ret; + +memset (mp,0 ,sizeof (mp)); +for (i =0 ; i <CB_NUM ; i++) { + ret =rte_mempool_event_callback_register + (test_mempool_events_cb, &data[i]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to register the callback %zu: %s" , + i,rte_strerror (rte_errno)); + } + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, mp); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Unregistered a non-registered callback" ); +/* NULL argument has no special meaning in this API. */ + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, +NULL ); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Unregistered a non-registered callback with NULL argument" ); + +/* Create mempool 0 that will be observed by all callbacks. */ +memset (&data,0 ,sizeof (data)); +strcpy (name,"empty0" ); + mp[0 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp[0 ],"Cannot create mempool %s: %s" , + name,rte_strerror (rte_errno)); +for (j =0 ; j <CB_NUM ; j++) +RTE_TEST_ASSERT_EQUAL (data[j].invoked, false, +"Callback %zu invoked on %s mempool creation" , + j, name); + +rte_mempool_set_ops_byname (mp[0 ],rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp[0 ]); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp[0 ]->size,"Failed to populate mempool %s: %s" , + name,rte_strerror (rte_errno)); +for (j =0 ; j <CB_NUM ; j++) { +RTE_TEST_ASSERT_EQUAL (data[j].invoked, true, +"Callback %zu not invoked on mempool %s population" , + j, name); +RTE_TEST_ASSERT_EQUAL (data[j].event, +RTE_MEMPOOL_EVENT_READY , +"Wrong callback invoked, expected READY" ); +RTE_TEST_ASSERT_EQUAL (data[j].mp, mp[0 ], +"Callback %zu invoked for a wrong mempool instead of %s" , + j, name); + } + +/* Check that unregistered callback 0 observes no events. */ + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, + &data[0 ]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister callback 0: %s" , +rte_strerror (rte_errno)); +memset (&data,0 ,sizeof (data)); +strcpy (name,"empty1" ); + mp[1 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp[1 ],"Cannot create mempool %s: %s" , + name,rte_strerror (rte_errno)); +rte_mempool_set_ops_byname (mp[1 ],rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp[1 ]); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp[1 ]->size,"Failed to populate mempool %s: %s" , + name,rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data[0 ].invoked, false, +"Unregistered callback 0 invoked on %s mempool populaton" , + name); + +for (i =0 ; i <MP_NUM ; i++) { +memset (&data,0 ,sizeof (data)); +sprintf (name,"empty%zu" , i); +rte_mempool_free (mp[i]); +/* +* Save pointer to check that it was passed to the callback, +* but put NULL into the array in case cleanup is called early. +*/ + freed = mp[i]; + mp[i] =NULL ; +for (j =1 ; j <CB_NUM ; j++) { +RTE_TEST_ASSERT_EQUAL (data[j].invoked, true, +"Callback %zu not invoked on mempool %s destruction" , + j, name); +RTE_TEST_ASSERT_EQUAL (data[j].event, +RTE_MEMPOOL_EVENT_DESTROY , +"Wrong callback invoked, expected DESTROY" ); +RTE_TEST_ASSERT_EQUAL (data[j].mp, freed, +"Callback %zu invoked for a wrong mempool instead of %s" , + j, name); + } +RTE_TEST_ASSERT_EQUAL (data[0 ].invoked, false, +"Unregistered callback 0 invoked on %s mempool destruction" , + name); + } + +for (j =1 ; j <CB_NUM ; j++) { + ret =rte_mempool_event_callback_unregister + (test_mempool_events_cb, &data[j]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister the callback %zu: %s" , + j,rte_strerror (rte_errno)); + } +return TEST_SUCCESS ; + +fail: +for (j =0 ; j <CB_NUM ; j++) +rte_mempool_event_callback_unregister + (test_mempool_events_cb, &data[j]); +for (i =0 ; i <MP_NUM ; i++) +rte_mempool_free (mp[i]); +return TEST_FAILED ; + +#pragma pop_macro("RTE_TEST_TRACE_FAILURE") +} + +struct test_mempool_events_safety_data { +bool invoked; +int (*api_func)(rte_mempool_event_callback *func,void *user_data); +rte_mempool_event_callback *cb_func; +void *cb_user_data; +int ret; +}; + +static void +test_mempool_events_safety_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *user_data) +{ +struct test_mempool_events_safety_data *data = user_data; + +RTE_SET_USED (event); +RTE_SET_USED (mp); + data->invoked = true; + data->ret = data->api_func (data->cb_func, data->cb_user_data); +} + +static int +test_mempool_events_safety (void ) +{ +#pragma push_macro("RTE_TEST_TRACE_FAILURE") +#undef RTE_TEST_TRACE_FAILURE +#define RTE_TEST_TRACE_FAILURE (...) do { \ + ret = TEST_FAILED; \ + goto exit; \ + } while (0) + +struct test_mempool_events_data data; +struct test_mempool_events_safety_data sdata[2 ]; +struct rte_mempool *mp; +size_t i; +int ret; + +/* removes itself */ + sdata[0 ].api_func = rte_mempool_event_callback_unregister; + sdata[0 ].cb_func = test_mempool_events_safety_cb; + sdata[0 ].cb_user_data = &sdata[0 ]; + sdata[0 ].ret =-1 ; +rte_mempool_event_callback_register (test_mempool_events_safety_cb, + &sdata[0 ]); +/* inserts a callback after itself */ + sdata[1 ].api_func = rte_mempool_event_callback_register; + sdata[1 ].cb_func = test_mempool_events_cb; + sdata[1 ].cb_user_data = &data; + sdata[1 ].ret =-1 ; +rte_mempool_event_callback_register (test_mempool_events_safety_cb, + &sdata[1 ]); + + mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create mempool: %s" , +rte_strerror (rte_errno)); +memset (&data,0 ,sizeof (data)); + ret =rte_mempool_populate_default (mp); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp->size,"Failed to populate mempool: %s" , +rte_strerror (rte_errno)); + +RTE_TEST_ASSERT_EQUAL (sdata[0 ].ret,0 ,"Callback failed to unregister itself: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (sdata[1 ].ret,0 ,"Failed to insert a new callback: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data.invoked, false, +"Inserted callback is invoked on mempool population" ); + +memset (&data,0 ,sizeof (data)); + sdata[0 ].invoked = false; +rte_mempool_free (mp); + mp =NULL ; +RTE_TEST_ASSERT_EQUAL (sdata[0 ].invoked, false, +"Callback that unregistered itself was called" ); +RTE_TEST_ASSERT_EQUAL (sdata[1 ].ret, -EEXIST , +"New callback inserted twice" ); +RTE_TEST_ASSERT_EQUAL (data.invoked, true, +"Inserted callback is not invoked on mempool destruction" ); + +rte_mempool_event_callback_unregister (test_mempool_events_cb, &data); +for (i =0 ; i <RTE_DIM (sdata); i++) +rte_mempool_event_callback_unregister + (test_mempool_events_safety_cb, &sdata[i]); + ret =TEST_SUCCESS ; + +exit: +/* cleanup, don't care which callbacks are already removed */ +rte_mempool_event_callback_unregister (test_mempool_events_cb, &data); +for (i =0 ; i <RTE_DIM (sdata); i++) +rte_mempool_event_callback_unregister + (test_mempool_events_safety_cb, &sdata[i]); +/* in case of failure before the planned destruction */ +rte_mempool_free (mp); +return ret; + +#pragma pop_macro("RTE_TEST_TRACE_FAILURE") +} +static int test_mempool (void ) {
@@ -666,6 +906,14 @@ test_mempool(void)if (test_mempool_basic (default_pool,1 ) <0 )GOTO_ERR (ret, err); +/* test mempool event callbacks */ +if (test_mempool_events (rte_mempool_populate_default) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events (rte_mempool_populate_anon) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events_safety () <0 ) +GOTO_ERR (ret, err); +rte_mempool_list_dump (stdout); ret =0 ;
lib/mempool/rte_mempool.c +124 -0
145 lines not on this page · raw message
lib/mempool/rte_mempool.h +62 -0
68 lines not on this page · raw message
lib/mempool/version.map +8 -0
@@ -64,3 +64,11 @@ EXPERIMENTAL { __rte_mempool_trace_ops_free; __rte_mempool_trace_set_ops_byname; }; + +INTERNAL { + global: + + # added in 21.11 + rte_mempool_event_callback_register; + rte_mempool_event_callback_unregister; +};
Signature · 1 line
2.25.1
PATCH v6 2/4 mempool: add non-IO flag
In reply to Dmitry KozlyukMempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add MEMPOOL_F_NON_IO flag to mark such mempools automatically
a) if their objects are not contiguous;
b) if IOVA is not available for any object.
Other components can inspect this flag
in order to optimize their memory management.
Discussion: https://mails.dpdk.org/archives/dev/2021-August/216654.html
--- app/proc-info/main.c | 6 +- app/test/test_mempool.c | 112 +++++++++++++++++++++++++ doc/guides/rel_notes/release_21_11.rst | 3 + lib/mempool/rte_mempool.c | 10 +++ lib/mempool/rte_mempool.h | 2 + 5 files changed, 131 insertions(+), 2 deletions(-)
app/proc-info/main.c +4 -2
@@ -1295,7 +1295,8 @@ show_mempool(char *name)"\t -- No cache align (%c)\n" "\t -- SP put (%c), SC get (%c)\n" "\t -- Pool created (%c)\n" -"\t -- No IOVA config (%c)\n" , +"\t -- No IOVA config (%c)\n" +"\t -- Not used for IO (%c)\n" , ptr->name, ptr->socket_id, (flags & MEMPOOL_F_NO_SPREAD) ? 'y' : 'n',
@@ -1303,7 +1304,8 @@ show_mempool(char *name) (flags &MEMPOOL_F_SP_PUT ) ?'y' :'n' , (flags &MEMPOOL_F_SC_GET ) ?'y' :'n' , (flags &MEMPOOL_F_POOL_CREATED ) ?'y' :'n' , - (flags & MEMPOOL_F_NO_IOVA_CONTIG) ? 'y' : 'n'); + (flags &MEMPOOL_F_NO_IOVA_CONTIG ) ?'y' :'n' , + (flags & MEMPOOL_F_NON_IO) ? 'y' : 'n'); printf(" - Size %u Cache %u element %u\n" " - header %u trailer %u\n" " - private data size %u\n",
app/test/test_mempool.c +112 -0
130 lines not on this page · raw message
doc/guides/rel_notes/release_21_11.rst +3 -0
@@ -229,6 +229,9 @@ API Changes the crypto/security operation. This field will be used to communicate events such as soft expiry with IPsec in lookaside mode. +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA). + ABI Changes -----------
lib/mempool/rte_mempool.c +10 -0
@@ -372,6 +372,10 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +/* At least some objects in the pool can now be used for IO. */ +if (iova !=RTE_BAD_IOVA ) + mp->flags &= ~MEMPOOL_F_NON_IO ; +/* Report the mempool as ready only when fully populated. */ if (mp->populated_size >= mp->size)mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_READY , mp);
@@ -851,6 +855,12 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,return NULL ; } +/* +* No objects in the pool can be used for IO until it's populated +* with at least some objects with valid IOVA. +*/ + flags |=MEMPOOL_F_NON_IO ; +/* "no cache align" imply "no spread" */ if (flags &MEMPOOL_F_NO_CACHE_ALIGN ) flags |=MEMPOOL_F_NO_SPREAD ;
lib/mempool/rte_mempool.h +2 -0
@@ -257,6 +257,8 @@ struct rte_mempool {#define MEMPOOL_F_SC_GET 0x0008/**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010/**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020/**< Don't need IOVA contiguous objs. */ +/** Internal: no object from the pool can be used for device IO (DMA). */ +#define MEMPOOL_F_NON_IO 0x0040/** * @internal When debug is enabled, store some statistics.
Signature · 1 line
2.25.1
PATCH v6 3/4 common/mlx5: add mempool registration facilities
In reply to Dmitry KozlyukAdd 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.
--- drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + 5 files changed, 666 insertions(+)
drivers/common/mlx5/mlx5_common_mp.c +50 -0
@@ -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. *
drivers/common/mlx5/mlx5_common_mp.h +14 -0
@@ -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 ,
@@ -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;
@@ -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;
@@ -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
drivers/common/mlx5/mlx5_common_mr.c +580 -0
596 lines not on this page · raw message
drivers/common/mlx5/mlx5_common_mr.h +17 -0
@@ -13,6 +13,7 @@#include <rte_rwlock.h> #include <rte_bitmap.h> +#include <rte_mbuf.h> #include <rte_memory.h> #include "mlx5_glue.h"
@@ -75,6 +76,7 @@ struct mlx5_mr_ctrl { } __rte_packed;LIST_HEAD (mlx5_mr_list, mlx5_mr); +LIST_HEAD (mlx5_mempool_reg_list, mlx5_mempool_reg);/* Global per-device MR cache. */ struct mlx5_mr_share_cache {
@@ -83,6 +85,7 @@ struct mlx5_mr_share_cache {struct mlx5_mr_btree cache;/* Global MR cache table. */ struct mlx5_mr_list mr_list;/* Registered MR list. */ struct mlx5_mr_list mr_free_list;/* Freed MR list. */ +struct mlx5_mempool_reg_list mempool_reg_list;/* Mempool database. */ mlx5_reg_mr_t reg_mr_cb;/* Callback to reg_mr func */ mlx5_dereg_mr_t dereg_mr_cb;/* Callback to dereg_mr func */ } __rte_packed;
@@ -136,6 +139,10 @@ uint32_t mlx5_mr_addr2mr_bh(void *pd, struct mlx5_mp_id *mp_id,struct mlx5_mr_ctrl *mr_ctrl, uintptr_t addr, unsigned int mr_ext_memseg_en);__rte_internal +uint32_t mlx5_mr_mempool2mr_bh(struct mlx5_mr_share_cache *share_cache, +struct mlx5_mr_ctrl *mr_ctrl, +struct rte_mempool *mp,uintptr_t addr); +__rte_internal void mlx5_mr_release_cache(struct mlx5_mr_share_cache *mr_cache);__rte_internal void mlx5_mr_dump_cache(struct mlx5_mr_share_cache *share_cache __rte_unused);
@@ -179,4 +186,14 @@ mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);__rte_internal voidmlx5_mr_free (struct mlx5_mr *mr,mlx5_dereg_mr_t dereg_mr_cb); + +__rte_internal +int +mlx5_mr_mempool_register (struct mlx5_mr_share_cache *share_cache,void *pd, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +__rte_internal +int +mlx5_mr_mempool_unregister (struct mlx5_mr_share_cache *share_cache, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +#endif /* RTE_PMD_MLX5_COMMON_MR_H_ */
drivers/common/mlx5/version.map +5 -0
@@ -152,4 +152,9 @@ INTERNAL { mlx5_realloc; mlx5_translate_port_name; # WINDOWS_NO_EXPORT + + mlx5_mr_mempool_register; + mlx5_mr_mempool_unregister; + mlx5_mp_req_mempool_reg; + mlx5_mr_mempool2mr_bh; };
Signature · 1 line
2.25.1
PATCH v6 4/4 net/mlx5: support mempool registration
In reply to Dmitry KozlyukWhen the first port in a given protection domain (PD) starts, install a mempool event callback for this PD and register all existing memory regions (MR) for it. When the last port in a PD closes, remove the callback and unregister all mempools for this PD. This behavior can be switched off with a new devarg: mr_mempool_reg_en.
On TX slow path, i.e. when an MR key for the address of the buffer to send is not in the local cache, first try to retrieve it from the database of registered mempools. Supported are direct and indirect mbufs, as well as externally-attached ones from MLX5 MPRQ feature. Lookup in the database of non-mempool memory is used as the last resort.
RX mempools are registered regardless of the devarg value. On RX data path only the local cache and the mempool database is used. If implicit mempool registration is disabled, these mempools are unregistered at port stop, releasing the MRs.
--- doc/guides/nics/mlx5.rst | 13 +++ doc/guides/rel_notes/release_21_11.rst | 6 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 +++++++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 10 ++ drivers/net/mlx5/mlx5_mr.c | 120 +++++-------------- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 ++-- drivers/net/mlx5/mlx5_rxq.c | 13 +++ drivers/net/mlx5/mlx5_trigger.c | 77 +++++++++++-- drivers/net/mlx5/windows/mlx5_os.c | 1 + 12 files changed, 347 insertions(+), 116 deletions(-)
doc/guides/nics/mlx5.rst +13 -0
@@ -1001,6 +1001,19 @@ Driver options Enabled by default. +- ``mr_mempool_reg_en`` parameter [int] + + A nonzero value enables implicit registration of DMA memory of all mempools + except those having ``MEMPOOL_F_NON_IO``. This flag is set automatically + for mempools populated with non-contiguous objects or those without IOVA. + The effect is that when a packet from a mempool is transmitted, + its memory is already registered for DMA in the PMD and no registration + will happen on the data path. The tradeoff is extra work on the creation + of each mempool and increased HW resource use if some mempools + are not used with MLX5 devices. + + Enabled by default. + - ``representor`` parameter [list] This parameter can be used to instantiate DPDK Ethernet devices from
doc/guides/rel_notes/release_21_11.rst +6 -0
@@ -159,6 +159,12 @@ New Features * Added tests to verify tunnel header verification in IPsec inbound. * Added tests to verify inner checksum. +* **Updated Mellanox mlx5 driver.** + + Updated the Mellanox mlx5 driver with new features and improvements, including: + + * Added implicit mempool registration to avoid data path hiccups (opt-out). + Removed Items -------------
drivers/net/mlx5/linux/mlx5_mp_os.c +44 -0
56 lines not on this page · raw message
drivers/net/mlx5/linux/mlx5_os.c +2 -2
@@ -1034,8 +1034,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, err =mlx5_proc_priv_init (eth_dev);if (err)return NULL ; - mp_id.port_id = eth_dev->data->port_id; -strlcpy (mp_id.name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +mlx5_mp_id_init (&mp_id, eth_dev->data->port_id);/* Receive command fd from primary process */ err =mlx5_mp_req_verbs_cmd_fd (&mp_id);if (err <0 )
@@ -2133,6 +2132,7 @@ mlx5_os_config_default(struct mlx5_dev_config *config) config->txqs_inline =MLX5_ARG_UNSET ; config->vf_nl_en =1 ; config->mr_ext_memseg_en =1 ; + config->mr_mempool_reg_en =1 ; config->mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; config->mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; config->dv_esw_en =1 ;
drivers/net/mlx5/mlx5.c +152 -0
188 lines not on this page · raw message
drivers/net/mlx5/mlx5.h +10 -0
@@ -155,6 +155,13 @@ struct mlx5_flow_dump_ack {/** Key string for IPC. */ #define MLX5_MP_NAME "net_mlx5_mp" +/** Initialize a multi-process ID. */ +static inline void +mlx5_mp_id_init (struct mlx5_mp_id *mp_id,uint16_t port_id) +{ + mp_id->port_id = port_id; +strlcpy (mp_id->name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +}LIST_HEAD (mlx5_dev_list, mlx5_dev_ctx_shared);
@@ -270,6 +277,8 @@ struct mlx5_dev_config { unsigned int dv_miss_info:1; /* restore packet after partial hw miss */ unsigned int allow_duplicate_pattern:1;/* Allow/Prevent the duplicate rules pattern. */ + unsigned int mr_mempool_reg_en:1; +/* Allow/prevent implicit mempool memory registration. */ struct {unsigned int enabled:1 ;/* Whether MPRQ is enabled. */ unsigned int stride_num_n;/* Number of strides. */
@@ -1498,6 +1507,7 @@ struct mlx5_dev_ctx_shared * mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, const struct mlx5_dev_config *config);void mlx5_free_shared_dev_ctx (struct mlx5_dev_ctx_shared *sh); +int mlx5_dev_ctx_shared_mempool_subscribe (struct rte_eth_dev *dev);void mlx5_free_table_hash_list (struct mlx5_priv *priv);int mlx5_alloc_table_hash_list (struct mlx5_priv *priv); void mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
drivers/net/mlx5/mlx5_mr.c +27 -93
138 lines not on this page · raw message
drivers/net/mlx5/mlx5_mr.h +0 -2
@@ -22,7 +22,5 @@void mlx5_mr_mem_event_cb (enum rte_mem_event event_type,const void *addr,size_t len,void *arg); -int mlx5_mr_update_mp (struct rte_eth_dev *dev,struct mlx5_mr_ctrl *mr_ctrl, -struct rte_mempool *mp);#endif /* RTE_PMD_MLX5_MR_H_ */
drivers/net/mlx5/mlx5_rx.h +14 -7
@@ -275,13 +275,11 @@ uint16_t mlx5_rx_burst_vec(void *dpdk_rxq, struct rte_mbuf **pkts,uint16_t mlx5_rx_burst_mprq_vec (void *dpdk_rxq,struct rte_mbuf **pkts,uint16_t pkts_n); -/* mlx5_mr.c */ - -uint32_t mlx5_rx_addr2mr_bh (struct mlx5_rxq_data *rxq,uintptr_t addr); +static int mlx5_rxq_mprq_enabled (struct mlx5_rxq_data *rxq);/** -* Query LKey from a packet buffer for Rx. No need to flush local caches for Rx -* as mempool is pre-configured and static. +* Query LKey from a packet buffer for Rx. No need to flush local caches +* as the Rx mempool database entries are valid for the lifetime of the queue. * * @param rxq * Pointer to Rx queue structure.
@@ -290,11 +288,14 @@ uint32_t mlx5_rx_addr2mr_bh(struct mlx5_rxq_data *rxq, uintptr_t addr);* * @return * Searched LKey on success, UINT32_MAX on no match. +* This function always succeeds on valid input. */ static __rte_always_inline uint32_tmlx5_rx_addr2mr (struct mlx5_rxq_data *rxq,uintptr_t addr) {struct mlx5_mr_ctrl *mr_ctrl = &rxq->mr_ctrl; +struct mlx5_rxq_ctrl *rxq_ctrl; +struct rte_mempool *mp;uint32_t lkey;/* Linear search on MR cache array. */
@@ -302,8 +303,14 @@ mlx5_rx_addr2mr(struct mlx5_rxq_data *rxq, uintptr_t addr) MLX5_MR_CACHE_N, addr);if (likely (lkey !=UINT32_MAX ))return lkey; -/* Take slower bottom-half (Binary Search) on miss. */ -return mlx5_rx_addr2mr_bh (rxq, addr); +/* +* Slower search in the mempool database on miss. +* During queue creation rxq->sh is not yet set, so we use rxq_ctrl. +*/ + rxq_ctrl = container_of(rxq, struct mlx5_rxq_ctrl, rxq); + mp =mlx5_rxq_mprq_enabled (rxq) ? rxq->mprq_mp : rxq->mp; +return mlx5_mr_mempool2mr_bh (&rxq_ctrl->priv->sh->share_cache, + mr_ctrl, mp, addr); }#define mlx5_rx_mb2mr (rxq, mb) mlx5_rx_addr2mr(rxq, (uintptr_t)((mb)->buf_addr))
drivers/net/mlx5/mlx5_rxq.c +13 -0
@@ -1162,6 +1162,7 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)unsigned int strd_sz_n =0 ;unsigned int i;unsigned int n_ibv =0 ; +int ret;if (!mlx5_mprq_enabled (dev))return 0 ;
@@ -1241,6 +1242,16 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev) rte_errno =ENOMEM ;return -rte_errno; } + ret =mlx5_mr_mempool_register (&priv->sh->share_cache, priv->sh->pd, + mp, &priv->mp_id); +if (ret <0 && rte_errno !=EEXIST ) { + ret = rte_errno; +DRV_LOG (ERR ,"port %u failed to register a mempool for Multi-Packet RQ" , + dev->data->port_id); +rte_mempool_free (mp); + rte_errno = ret; +return -rte_errno; + } priv->mprq_mp = mp; exit:/* Set mempool for each Rx queue. */
@@ -1443,6 +1454,8 @@ mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,/* rte_errno is already set. */ goto error; } +/* Rx queues don't use this pointer, but we want a valid structure. */ + tmpl->rxq.mr_ctrl.dev_gen_ptr = &priv->sh->share_cache.dev_gen; tmpl->socket = socket;if (dev->data->dev_conf.intr_conf.rxq) tmpl->irq =1 ;
drivers/net/mlx5/mlx5_trigger.c +65 -12
95 lines not on this page · raw message
drivers/net/mlx5/windows/mlx5_os.c +1 -0
@@ -1116,6 +1116,7 @@ mlx5_os_net_probe(struct rte_device *dev) dev_config.txqs_inline =MLX5_ARG_UNSET ; dev_config.vf_nl_en =0 ; dev_config.mr_ext_memseg_en =1 ; + dev_config.mr_mempool_reg_en =1 ; dev_config.mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; dev_config.mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; dev_config.dv_esw_en =0 ;
Signature · 1 line
2.25.1
v7 cover net/mlx5: implicit mempool registration
In reply to Dmitry KozlyukMLX5 hardware has its internal IOMMU where PMD registers the memory. On the data path, PMD translates VA into a key consumed by the device IOMMU. It is impractical for the PMD to register all allocated memory because of increased lookup cost both in HW and SW. Most often mbuf memory comes from mempools, so if PMD tracks them, it can almost always have mbuf memory registered before an mbuf hits the PMD. This patchset adds such tracking in the PMD and internal API to support it.
Please see [1] for the discussion of the patch 2/4 and how it can be useful outside of the MLX5 PMD.
v7 (internal CI):
1. Fix unit test compilation issues with GCC.
2. Keep rte_mempool_event description non-internal: Doxygen treats it as not documented otherwise, "doc" target fails.
v6:
Fix compilation issue in proc-info (CI).
v5:
1. Change non-IO flag inference + various fixes (Andrew).
2. Fix callback unregistration from secondary processes (Olivier).
3. Support non-IO flag in proc-dump (David).
4. Fix the usage of locks (Olivier).
5. Avoid resource leaks in unit test (Olivier).
v4: (Andrew)
1. Improve mempool event callbacks unit tests and documentation.
2. Make MEMPOOL_F_NON_IO internal and automatically inferred. Add unit tests for the inference logic.
v3: Improve wording and naming; fix typos (Thomas).
v2 (internal review and testing):
1. Change tracked mempool event from being created (CREATE) to being fully populated (READY), which is the state PMD is interested in.
2. Unit test the new mempool callback API.
3. Remove bogus "error" messages in normal conditions.
4. Fixes in PMD.
Dmitry Kozlyuk (4):
mempool: add event callbacks
mempool: add non-IO flag
common/mlx5: add mempool registration facilities net/mlx5: support mempool registration
app/proc-info/main.c | 6 +- app/test/test_mempool.c | 360 +++++++++++++++ doc/guides/nics/mlx5.rst | 13 + doc/guides/rel_notes/release_21_11.rst | 9 + drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 ++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++ drivers/net/mlx5/mlx5.h | 10 + drivers/net/mlx5/mlx5_mr.c | 120 ++--- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 +- drivers/net/mlx5/mlx5_rxq.c | 13 + drivers/net/mlx5/mlx5_trigger.c | 77 +++- drivers/net/mlx5/windows/mlx5_os.c | 1 + lib/mempool/rte_mempool.c | 134 ++++++ lib/mempool/rte_mempool.h | 64 +++ lib/mempool/version.map | 8 + 22 files changed, 1586 insertions(+), 118 deletions(-)
Signature · 1 line
2.25.1
PATCH v7 1/4 mempool: add event callbacks
Data path performance can benefit if the PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track creation and destruction of mempools after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Add an API to register callback for mempool life cycle events:
* rte_mempool_event_callback_register()
* rte_mempool_event_callback_unregister()
Currently tracked events are:
* RTE_MEMPOOL_EVENT_READY (after populating a mempool)
* RTE_MEMPOOL_EVENT_DESTROY (before freeing a mempool) Provide a unit test for the new API.
The new API is internal, because it is primarily demanded by PMDs that may need to deal with any mempools and do not control their creation, while an application, on the other hand, knows which mempools it creates and doesn't care about internal mempools PMDs might create.
--- app/test/test_mempool.c | 248 ++++++++++++++++++++++++++++++++++++++ lib/mempool/rte_mempool.c | 124 +++++++++++++++++++ lib/mempool/rte_mempool.h | 62 ++++++++++ lib/mempool/version.map | 8 ++ 4 files changed, 442 insertions(+)
app/test/test_mempool.c +248 -0
@@ -14,6 +14,7 @@#include <rte_common.h> #include <rte_log.h> #include <rte_debug.h> +#include <rte_errno.h> #include <rte_memory.h> #include <rte_launch.h> #include <rte_cycles.h>
@@ -489,6 +490,245 @@ test_mp_mem_init(struct rte_mempool *mp, data->ret =0 ; } +struct test_mempool_events_data { +struct rte_mempool *mp; +enum rte_mempool_event event; +bool invoked; +}; + +static void +test_mempool_events_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *user_data) +{ +struct test_mempool_events_data *data = user_data; + + data->mp = mp; + data->event = event; + data->invoked = true; +} + +static int +test_mempool_events (int (*populate)(struct rte_mempool *mp)) +{ +#pragma push_macro("RTE_TEST_TRACE_FAILURE") +#undef RTE_TEST_TRACE_FAILURE +#define RTE_TEST_TRACE_FAILURE (...) do { goto fail; } while (0) + +static const size_t CB_NUM =3 ; +static const size_t MP_NUM =2 ; + +struct test_mempool_events_data data[CB_NUM ]; +struct rte_mempool *mp[MP_NUM ], *freed; +char name[RTE_MEMPOOL_NAMESIZE ]; +size_t i, j; +int ret; + +memset (mp,0 ,sizeof (mp)); +for (i =0 ; i <CB_NUM ; i++) { + ret =rte_mempool_event_callback_register + (test_mempool_events_cb, &data[i]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to register the callback %zu: %s" , + i,rte_strerror (rte_errno)); + } + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, mp); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Unregistered a non-registered callback" ); +/* NULL argument has no special meaning in this API. */ + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, +NULL ); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Unregistered a non-registered callback with NULL argument" ); + +/* Create mempool 0 that will be observed by all callbacks. */ +memset (&data,0 ,sizeof (data)); +strcpy (name,"empty0" ); + mp[0 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp[0 ],"Cannot create mempool %s: %s" , + name,rte_strerror (rte_errno)); +for (j =0 ; j <CB_NUM ; j++) +RTE_TEST_ASSERT_EQUAL (data[j].invoked, false, +"Callback %zu invoked on %s mempool creation" , + j, name); + +rte_mempool_set_ops_byname (mp[0 ],rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp[0 ]); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp[0 ]->size,"Failed to populate mempool %s: %s" , + name,rte_strerror (rte_errno)); +for (j =0 ; j <CB_NUM ; j++) { +RTE_TEST_ASSERT_EQUAL (data[j].invoked, true, +"Callback %zu not invoked on mempool %s population" , + j, name); +RTE_TEST_ASSERT_EQUAL (data[j].event, +RTE_MEMPOOL_EVENT_READY , +"Wrong callback invoked, expected READY" ); +RTE_TEST_ASSERT_EQUAL (data[j].mp, mp[0 ], +"Callback %zu invoked for a wrong mempool instead of %s" , + j, name); + } + +/* Check that unregistered callback 0 observes no events. */ + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, + &data[0 ]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister callback 0: %s" , +rte_strerror (rte_errno)); +memset (&data,0 ,sizeof (data)); +strcpy (name,"empty1" ); + mp[1 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp[1 ],"Cannot create mempool %s: %s" , + name,rte_strerror (rte_errno)); +rte_mempool_set_ops_byname (mp[1 ],rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp[1 ]); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp[1 ]->size,"Failed to populate mempool %s: %s" , + name,rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data[0 ].invoked, false, +"Unregistered callback 0 invoked on %s mempool populaton" , + name); + +for (i =0 ; i <MP_NUM ; i++) { +memset (&data,0 ,sizeof (data)); +sprintf (name,"empty%zu" , i); +rte_mempool_free (mp[i]); +/* +* Save pointer to check that it was passed to the callback, +* but put NULL into the array in case cleanup is called early. +*/ + freed = mp[i]; + mp[i] =NULL ; +for (j =1 ; j <CB_NUM ; j++) { +RTE_TEST_ASSERT_EQUAL (data[j].invoked, true, +"Callback %zu not invoked on mempool %s destruction" , + j, name); +RTE_TEST_ASSERT_EQUAL (data[j].event, +RTE_MEMPOOL_EVENT_DESTROY , +"Wrong callback invoked, expected DESTROY" ); +RTE_TEST_ASSERT_EQUAL (data[j].mp, freed, +"Callback %zu invoked for a wrong mempool instead of %s" , + j, name); + } +RTE_TEST_ASSERT_EQUAL (data[0 ].invoked, false, +"Unregistered callback 0 invoked on %s mempool destruction" , + name); + } + +for (j =1 ; j <CB_NUM ; j++) { + ret =rte_mempool_event_callback_unregister + (test_mempool_events_cb, &data[j]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister the callback %zu: %s" , + j,rte_strerror (rte_errno)); + } +return TEST_SUCCESS ; + +fail: +for (j =0 ; j <CB_NUM ; j++) +rte_mempool_event_callback_unregister + (test_mempool_events_cb, &data[j]); +for (i =0 ; i <MP_NUM ; i++) +rte_mempool_free (mp[i]); +return TEST_FAILED ; + +#pragma pop_macro("RTE_TEST_TRACE_FAILURE") +} + +struct test_mempool_events_safety_data { +bool invoked; +int (*api_func)(rte_mempool_event_callback *func,void *user_data); +rte_mempool_event_callback *cb_func; +void *cb_user_data; +int ret; +}; + +static void +test_mempool_events_safety_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *user_data) +{ +struct test_mempool_events_safety_data *data = user_data; + +RTE_SET_USED (event); +RTE_SET_USED (mp); + data->invoked = true; + data->ret = data->api_func (data->cb_func, data->cb_user_data); +} + +static int +test_mempool_events_safety (void ) +{ +#pragma push_macro("RTE_TEST_TRACE_FAILURE") +#undef RTE_TEST_TRACE_FAILURE +#define RTE_TEST_TRACE_FAILURE (...) do { \ + ret = TEST_FAILED; \ + goto exit; \ + } while (0) + +struct test_mempool_events_data data; +struct test_mempool_events_safety_data sdata[2 ]; +struct rte_mempool *mp; +size_t i; +int ret; + +/* removes itself */ + sdata[0 ].api_func = rte_mempool_event_callback_unregister; + sdata[0 ].cb_func = test_mempool_events_safety_cb; + sdata[0 ].cb_user_data = &sdata[0 ]; + sdata[0 ].ret =-1 ; +rte_mempool_event_callback_register (test_mempool_events_safety_cb, + &sdata[0 ]); +/* inserts a callback after itself */ + sdata[1 ].api_func = rte_mempool_event_callback_register; + sdata[1 ].cb_func = test_mempool_events_cb; + sdata[1 ].cb_user_data = &data; + sdata[1 ].ret =-1 ; +rte_mempool_event_callback_register (test_mempool_events_safety_cb, + &sdata[1 ]); + + mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create mempool: %s" , +rte_strerror (rte_errno)); +memset (&data,0 ,sizeof (data)); + ret =rte_mempool_populate_default (mp); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp->size,"Failed to populate mempool: %s" , +rte_strerror (rte_errno)); + +RTE_TEST_ASSERT_EQUAL (sdata[0 ].ret,0 ,"Callback failed to unregister itself: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (sdata[1 ].ret,0 ,"Failed to insert a new callback: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data.invoked, false, +"Inserted callback is invoked on mempool population" ); + +memset (&data,0 ,sizeof (data)); + sdata[0 ].invoked = false; +rte_mempool_free (mp); + mp =NULL ; +RTE_TEST_ASSERT_EQUAL (sdata[0 ].invoked, false, +"Callback that unregistered itself was called" ); +RTE_TEST_ASSERT_EQUAL (sdata[1 ].ret, -EEXIST , +"New callback inserted twice" ); +RTE_TEST_ASSERT_EQUAL (data.invoked, true, +"Inserted callback is not invoked on mempool destruction" ); + +rte_mempool_event_callback_unregister (test_mempool_events_cb, &data); +for (i =0 ; i <RTE_DIM (sdata); i++) +rte_mempool_event_callback_unregister + (test_mempool_events_safety_cb, &sdata[i]); + ret =TEST_SUCCESS ; + +exit: +/* cleanup, don't care which callbacks are already removed */ +rte_mempool_event_callback_unregister (test_mempool_events_cb, &data); +for (i =0 ; i <RTE_DIM (sdata); i++) +rte_mempool_event_callback_unregister + (test_mempool_events_safety_cb, &sdata[i]); +/* in case of failure before the planned destruction */ +rte_mempool_free (mp); +return ret; + +#pragma pop_macro("RTE_TEST_TRACE_FAILURE") +} +static int test_mempool (void ) {
@@ -666,6 +906,14 @@ test_mempool(void)if (test_mempool_basic (default_pool,1 ) <0 )GOTO_ERR (ret, err); +/* test mempool event callbacks */ +if (test_mempool_events (rte_mempool_populate_default) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events (rte_mempool_populate_anon) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events_safety () <0 ) +GOTO_ERR (ret, err); +rte_mempool_list_dump (stdout); ret =0 ;
lib/mempool/rte_mempool.c +124 -0
145 lines not on this page · raw message
lib/mempool/rte_mempool.h +62 -0
68 lines not on this page · raw message
lib/mempool/version.map +8 -0
@@ -64,3 +64,11 @@ EXPERIMENTAL { __rte_mempool_trace_ops_free; __rte_mempool_trace_set_ops_byname; }; + +INTERNAL { + global: + + # added in 21.11 + rte_mempool_event_callback_register; + rte_mempool_event_callback_unregister; +};
Signature · 1 line
2.25.1
PATCH v7 2/4 mempool: add non-IO flag
In reply to Dmitry KozlyukMempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add MEMPOOL_F_NON_IO flag to mark such mempools automatically
a) if their objects are not contiguous;
b) if IOVA is not available for any object.
Other components can inspect this flag
in order to optimize their memory management.
Discussion: https://mails.dpdk.org/archives/dev/2021-August/216654.html
--- app/proc-info/main.c | 6 +- app/test/test_mempool.c | 112 +++++++++++++++++++++++++ doc/guides/rel_notes/release_21_11.rst | 3 + lib/mempool/rte_mempool.c | 10 +++ lib/mempool/rte_mempool.h | 2 + 5 files changed, 131 insertions(+), 2 deletions(-)
app/proc-info/main.c +4 -2
@@ -1295,7 +1295,8 @@ show_mempool(char *name)"\t -- No cache align (%c)\n" "\t -- SP put (%c), SC get (%c)\n" "\t -- Pool created (%c)\n" -"\t -- No IOVA config (%c)\n" , +"\t -- No IOVA config (%c)\n" +"\t -- Not used for IO (%c)\n" , ptr->name, ptr->socket_id, (flags & MEMPOOL_F_NO_SPREAD) ? 'y' : 'n',
@@ -1303,7 +1304,8 @@ show_mempool(char *name) (flags &MEMPOOL_F_SP_PUT ) ?'y' :'n' , (flags &MEMPOOL_F_SC_GET ) ?'y' :'n' , (flags &MEMPOOL_F_POOL_CREATED ) ?'y' :'n' , - (flags & MEMPOOL_F_NO_IOVA_CONTIG) ? 'y' : 'n'); + (flags &MEMPOOL_F_NO_IOVA_CONTIG ) ?'y' :'n' , + (flags & MEMPOOL_F_NON_IO) ? 'y' : 'n'); printf(" - Size %u Cache %u element %u\n" " - header %u trailer %u\n" " - private data size %u\n",
app/test/test_mempool.c +112 -0
130 lines not on this page · raw message
doc/guides/rel_notes/release_21_11.rst +3 -0
@@ -229,6 +229,9 @@ API Changes the crypto/security operation. This field will be used to communicate events such as soft expiry with IPsec in lookaside mode. +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA). + ABI Changes -----------
lib/mempool/rte_mempool.c +10 -0
@@ -372,6 +372,10 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +/* At least some objects in the pool can now be used for IO. */ +if (iova !=RTE_BAD_IOVA ) + mp->flags &= ~MEMPOOL_F_NON_IO ; +/* Report the mempool as ready only when fully populated. */ if (mp->populated_size >= mp->size)mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_READY , mp);
@@ -851,6 +855,12 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,return NULL ; } +/* +* No objects in the pool can be used for IO until it's populated +* with at least some objects with valid IOVA. +*/ + flags |=MEMPOOL_F_NON_IO ; +/* "no cache align" imply "no spread" */ if (flags &MEMPOOL_F_NO_CACHE_ALIGN ) flags |=MEMPOOL_F_NO_SPREAD ;
lib/mempool/rte_mempool.h +2 -0
@@ -257,6 +257,8 @@ struct rte_mempool {#define MEMPOOL_F_SC_GET 0x0008/**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010/**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020/**< Don't need IOVA contiguous objs. */ +/** Internal: no object from the pool can be used for device IO (DMA). */ +#define MEMPOOL_F_NON_IO 0x0040/** * @internal When debug is enabled, store some statistics.
Signature · 1 line
2.25.1
PATCH v7 3/4 common/mlx5: add mempool registration facilities
In reply to Dmitry KozlyukAdd 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.
--- drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + 5 files changed, 666 insertions(+)
drivers/common/mlx5/mlx5_common_mp.c +50 -0
@@ -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. *
drivers/common/mlx5/mlx5_common_mp.h +14 -0
@@ -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 ,
@@ -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;
@@ -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;
@@ -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
drivers/common/mlx5/mlx5_common_mr.c +580 -0
596 lines not on this page · raw message
drivers/common/mlx5/mlx5_common_mr.h +17 -0
@@ -13,6 +13,7 @@#include <rte_rwlock.h> #include <rte_bitmap.h> +#include <rte_mbuf.h> #include <rte_memory.h> #include "mlx5_glue.h"
@@ -75,6 +76,7 @@ struct mlx5_mr_ctrl { } __rte_packed;LIST_HEAD (mlx5_mr_list, mlx5_mr); +LIST_HEAD (mlx5_mempool_reg_list, mlx5_mempool_reg);/* Global per-device MR cache. */ struct mlx5_mr_share_cache {
@@ -83,6 +85,7 @@ struct mlx5_mr_share_cache {struct mlx5_mr_btree cache;/* Global MR cache table. */ struct mlx5_mr_list mr_list;/* Registered MR list. */ struct mlx5_mr_list mr_free_list;/* Freed MR list. */ +struct mlx5_mempool_reg_list mempool_reg_list;/* Mempool database. */ mlx5_reg_mr_t reg_mr_cb;/* Callback to reg_mr func */ mlx5_dereg_mr_t dereg_mr_cb;/* Callback to dereg_mr func */ } __rte_packed;
@@ -136,6 +139,10 @@ uint32_t mlx5_mr_addr2mr_bh(void *pd, struct mlx5_mp_id *mp_id,struct mlx5_mr_ctrl *mr_ctrl, uintptr_t addr, unsigned int mr_ext_memseg_en);__rte_internal +uint32_t mlx5_mr_mempool2mr_bh(struct mlx5_mr_share_cache *share_cache, +struct mlx5_mr_ctrl *mr_ctrl, +struct rte_mempool *mp,uintptr_t addr); +__rte_internal void mlx5_mr_release_cache(struct mlx5_mr_share_cache *mr_cache);__rte_internal void mlx5_mr_dump_cache(struct mlx5_mr_share_cache *share_cache __rte_unused);
@@ -179,4 +186,14 @@ mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);__rte_internal voidmlx5_mr_free (struct mlx5_mr *mr,mlx5_dereg_mr_t dereg_mr_cb); + +__rte_internal +int +mlx5_mr_mempool_register (struct mlx5_mr_share_cache *share_cache,void *pd, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +__rte_internal +int +mlx5_mr_mempool_unregister (struct mlx5_mr_share_cache *share_cache, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +#endif /* RTE_PMD_MLX5_COMMON_MR_H_ */
drivers/common/mlx5/version.map +5 -0
@@ -152,4 +152,9 @@ INTERNAL { mlx5_realloc; mlx5_translate_port_name; # WINDOWS_NO_EXPORT + + mlx5_mr_mempool_register; + mlx5_mr_mempool_unregister; + mlx5_mp_req_mempool_reg; + mlx5_mr_mempool2mr_bh; };
Signature · 1 line
2.25.1
PATCH v7 4/4 net/mlx5: support mempool registration
In reply to Dmitry KozlyukWhen the first port in a given protection domain (PD) starts, install a mempool event callback for this PD and register all existing memory regions (MR) for it. When the last port in a PD closes, remove the callback and unregister all mempools for this PD. This behavior can be switched off with a new devarg: mr_mempool_reg_en.
On TX slow path, i.e. when an MR key for the address of the buffer to send is not in the local cache, first try to retrieve it from the database of registered mempools. Supported are direct and indirect mbufs, as well as externally-attached ones from MLX5 MPRQ feature. Lookup in the database of non-mempool memory is used as the last resort.
RX mempools are registered regardless of the devarg value. On RX data path only the local cache and the mempool database is used. If implicit mempool registration is disabled, these mempools are unregistered at port stop, releasing the MRs.
--- doc/guides/nics/mlx5.rst | 13 +++ doc/guides/rel_notes/release_21_11.rst | 6 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 +++++++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 10 ++ drivers/net/mlx5/mlx5_mr.c | 120 +++++-------------- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 ++-- drivers/net/mlx5/mlx5_rxq.c | 13 +++ drivers/net/mlx5/mlx5_trigger.c | 77 +++++++++++-- drivers/net/mlx5/windows/mlx5_os.c | 1 + 12 files changed, 347 insertions(+), 116 deletions(-)
doc/guides/nics/mlx5.rst +13 -0
@@ -1001,6 +1001,19 @@ Driver options Enabled by default. +- ``mr_mempool_reg_en`` parameter [int] + + A nonzero value enables implicit registration of DMA memory of all mempools + except those having ``MEMPOOL_F_NON_IO``. This flag is set automatically + for mempools populated with non-contiguous objects or those without IOVA. + The effect is that when a packet from a mempool is transmitted, + its memory is already registered for DMA in the PMD and no registration + will happen on the data path. The tradeoff is extra work on the creation + of each mempool and increased HW resource use if some mempools + are not used with MLX5 devices. + + Enabled by default. + - ``representor`` parameter [list] This parameter can be used to instantiate DPDK Ethernet devices from
doc/guides/rel_notes/release_21_11.rst +6 -0
@@ -159,6 +159,12 @@ New Features * Added tests to verify tunnel header verification in IPsec inbound. * Added tests to verify inner checksum. +* **Updated Mellanox mlx5 driver.** + + Updated the Mellanox mlx5 driver with new features and improvements, including: + + * Added implicit mempool registration to avoid data path hiccups (opt-out). + Removed Items -------------
drivers/net/mlx5/linux/mlx5_mp_os.c +44 -0
56 lines not on this page · raw message
drivers/net/mlx5/linux/mlx5_os.c +2 -2
@@ -1034,8 +1034,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, err =mlx5_proc_priv_init (eth_dev);if (err)return NULL ; - mp_id.port_id = eth_dev->data->port_id; -strlcpy (mp_id.name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +mlx5_mp_id_init (&mp_id, eth_dev->data->port_id);/* Receive command fd from primary process */ err =mlx5_mp_req_verbs_cmd_fd (&mp_id);if (err <0 )
@@ -2133,6 +2132,7 @@ mlx5_os_config_default(struct mlx5_dev_config *config) config->txqs_inline =MLX5_ARG_UNSET ; config->vf_nl_en =1 ; config->mr_ext_memseg_en =1 ; + config->mr_mempool_reg_en =1 ; config->mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; config->mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; config->dv_esw_en =1 ;
drivers/net/mlx5/mlx5.c +152 -0
188 lines not on this page · raw message
drivers/net/mlx5/mlx5.h +10 -0
@@ -155,6 +155,13 @@ struct mlx5_flow_dump_ack {/** Key string for IPC. */ #define MLX5_MP_NAME "net_mlx5_mp" +/** Initialize a multi-process ID. */ +static inline void +mlx5_mp_id_init (struct mlx5_mp_id *mp_id,uint16_t port_id) +{ + mp_id->port_id = port_id; +strlcpy (mp_id->name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +}LIST_HEAD (mlx5_dev_list, mlx5_dev_ctx_shared);
@@ -270,6 +277,8 @@ struct mlx5_dev_config { unsigned int dv_miss_info:1; /* restore packet after partial hw miss */ unsigned int allow_duplicate_pattern:1;/* Allow/Prevent the duplicate rules pattern. */ + unsigned int mr_mempool_reg_en:1; +/* Allow/prevent implicit mempool memory registration. */ struct {unsigned int enabled:1 ;/* Whether MPRQ is enabled. */ unsigned int stride_num_n;/* Number of strides. */
@@ -1498,6 +1507,7 @@ struct mlx5_dev_ctx_shared * mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, const struct mlx5_dev_config *config);void mlx5_free_shared_dev_ctx (struct mlx5_dev_ctx_shared *sh); +int mlx5_dev_ctx_shared_mempool_subscribe (struct rte_eth_dev *dev);void mlx5_free_table_hash_list (struct mlx5_priv *priv);int mlx5_alloc_table_hash_list (struct mlx5_priv *priv); void mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
drivers/net/mlx5/mlx5_mr.c +27 -93
138 lines not on this page · raw message
drivers/net/mlx5/mlx5_mr.h +0 -2
@@ -22,7 +22,5 @@void mlx5_mr_mem_event_cb (enum rte_mem_event event_type,const void *addr,size_t len,void *arg); -int mlx5_mr_update_mp (struct rte_eth_dev *dev,struct mlx5_mr_ctrl *mr_ctrl, -struct rte_mempool *mp);#endif /* RTE_PMD_MLX5_MR_H_ */
drivers/net/mlx5/mlx5_rx.h +14 -7
@@ -275,13 +275,11 @@ uint16_t mlx5_rx_burst_vec(void *dpdk_rxq, struct rte_mbuf **pkts,uint16_t mlx5_rx_burst_mprq_vec (void *dpdk_rxq,struct rte_mbuf **pkts,uint16_t pkts_n); -/* mlx5_mr.c */ - -uint32_t mlx5_rx_addr2mr_bh (struct mlx5_rxq_data *rxq,uintptr_t addr); +static int mlx5_rxq_mprq_enabled (struct mlx5_rxq_data *rxq);/** -* Query LKey from a packet buffer for Rx. No need to flush local caches for Rx -* as mempool is pre-configured and static. +* Query LKey from a packet buffer for Rx. No need to flush local caches +* as the Rx mempool database entries are valid for the lifetime of the queue. * * @param rxq * Pointer to Rx queue structure.
@@ -290,11 +288,14 @@ uint32_t mlx5_rx_addr2mr_bh(struct mlx5_rxq_data *rxq, uintptr_t addr);* * @return * Searched LKey on success, UINT32_MAX on no match. +* This function always succeeds on valid input. */ static __rte_always_inline uint32_tmlx5_rx_addr2mr (struct mlx5_rxq_data *rxq,uintptr_t addr) {struct mlx5_mr_ctrl *mr_ctrl = &rxq->mr_ctrl; +struct mlx5_rxq_ctrl *rxq_ctrl; +struct rte_mempool *mp;uint32_t lkey;/* Linear search on MR cache array. */
@@ -302,8 +303,14 @@ mlx5_rx_addr2mr(struct mlx5_rxq_data *rxq, uintptr_t addr) MLX5_MR_CACHE_N, addr);if (likely (lkey !=UINT32_MAX ))return lkey; -/* Take slower bottom-half (Binary Search) on miss. */ -return mlx5_rx_addr2mr_bh (rxq, addr); +/* +* Slower search in the mempool database on miss. +* During queue creation rxq->sh is not yet set, so we use rxq_ctrl. +*/ + rxq_ctrl = container_of(rxq, struct mlx5_rxq_ctrl, rxq); + mp =mlx5_rxq_mprq_enabled (rxq) ? rxq->mprq_mp : rxq->mp; +return mlx5_mr_mempool2mr_bh (&rxq_ctrl->priv->sh->share_cache, + mr_ctrl, mp, addr); }#define mlx5_rx_mb2mr (rxq, mb) mlx5_rx_addr2mr(rxq, (uintptr_t)((mb)->buf_addr))
drivers/net/mlx5/mlx5_rxq.c +13 -0
@@ -1162,6 +1162,7 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)unsigned int strd_sz_n =0 ;unsigned int i;unsigned int n_ibv =0 ; +int ret;if (!mlx5_mprq_enabled (dev))return 0 ;
@@ -1241,6 +1242,16 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev) rte_errno =ENOMEM ;return -rte_errno; } + ret =mlx5_mr_mempool_register (&priv->sh->share_cache, priv->sh->pd, + mp, &priv->mp_id); +if (ret <0 && rte_errno !=EEXIST ) { + ret = rte_errno; +DRV_LOG (ERR ,"port %u failed to register a mempool for Multi-Packet RQ" , + dev->data->port_id); +rte_mempool_free (mp); + rte_errno = ret; +return -rte_errno; + } priv->mprq_mp = mp; exit:/* Set mempool for each Rx queue. */
@@ -1443,6 +1454,8 @@ mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,/* rte_errno is already set. */ goto error; } +/* Rx queues don't use this pointer, but we want a valid structure. */ + tmpl->rxq.mr_ctrl.dev_gen_ptr = &priv->sh->share_cache.dev_gen; tmpl->socket = socket;if (dev->data->dev_conf.intr_conf.rxq) tmpl->irq =1 ;
drivers/net/mlx5/mlx5_trigger.c +65 -12
95 lines not on this page · raw message
drivers/net/mlx5/windows/mlx5_os.c +1 -0
@@ -1116,6 +1116,7 @@ mlx5_os_net_probe(struct rte_device *dev) dev_config.txqs_inline =MLX5_ARG_UNSET ; dev_config.vf_nl_en =0 ; dev_config.mr_ext_memseg_en =1 ; + dev_config.mr_mempool_reg_en =1 ; dev_config.mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; dev_config.mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; dev_config.dv_esw_en =0 ;
Signature · 1 line
2.25.1
v8 cover net/mlx5: implicit mempool registration
In reply to Dmitry KozlyukMLX5 hardware has its internal IOMMU where PMD registers the memory. On the data path, PMD translates VA into a key consumed by the device IOMMU. It is impractical for the PMD to register all allocated memory because of increased lookup cost both in HW and SW. Most often mbuf memory comes from mempools, so if PMD tracks them, it can almost always have mbuf memory registered before an mbuf hits the PMD. This patchset adds such tracking in the PMD and internal API to support it.
Please see [1] for the discussion of the patch 2/4 and how it can be useful outside of the MLX5 PMD.
v8:
Fix mempool_autotest failure on Ubuntu 18.04 (CI).
v7 (internal CI):
1. Fix unit test compilation issues with GCC.
2. Keep rte_mempool_event description non-internal: Doxygen treats it as not documented otherwise, "doc" target fails.
v6:
Fix compilation issue in proc-info (CI).
v5:
1. Change non-IO flag inference + various fixes (Andrew).
2. Fix callback unregistration from secondary processes (Olivier).
3. Support non-IO flag in proc-dump (David).
4. Fix the usage of locks (Olivier).
5. Avoid resource leaks in unit test (Olivier).
v4: (Andrew)
1. Improve mempool event callbacks unit tests and documentation.
2. Make MEMPOOL_F_NON_IO internal and automatically inferred. Add unit tests for the inference logic.
v3: Improve wording and naming; fix typos (Thomas).
v2 (internal review and testing):
1. Change tracked mempool event from being created (CREATE) to being fully populated (READY), which is the state PMD is interested in.
2. Unit test the new mempool callback API.
3. Remove bogus "error" messages in normal conditions.
4. Fixes in PMD.
Dmitry Kozlyuk (4):
mempool: add event callbacks
mempool: add non-IO flag
common/mlx5: add mempool registration facilities net/mlx5: support mempool registration
app/proc-info/main.c | 6 +- app/test/test_mempool.c | 362 +++++++++++++++ doc/guides/nics/mlx5.rst | 13 + doc/guides/rel_notes/release_21_11.rst | 9 + drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 ++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++ drivers/net/mlx5/mlx5.h | 10 + drivers/net/mlx5/mlx5_mr.c | 120 ++--- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 +- drivers/net/mlx5/mlx5_rxq.c | 13 + drivers/net/mlx5/mlx5_trigger.c | 77 +++- drivers/net/mlx5/windows/mlx5_os.c | 1 + lib/mempool/rte_mempool.c | 134 ++++++ lib/mempool/rte_mempool.h | 64 +++ lib/mempool/version.map | 8 + 22 files changed, 1588 insertions(+), 118 deletions(-)
Signature · 1 line
2.25.1
PATCH v8 1/4 mempool: add event callbacks
Data path performance can benefit if the PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track creation and destruction of mempools after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Add an API to register callback for mempool life cycle events:
* rte_mempool_event_callback_register()
* rte_mempool_event_callback_unregister()
Currently tracked events are:
* RTE_MEMPOOL_EVENT_READY (after populating a mempool)
* RTE_MEMPOOL_EVENT_DESTROY (before freeing a mempool) Provide a unit test for the new API.
The new API is internal, because it is primarily demanded by PMDs that may need to deal with any mempools and do not control their creation, while an application, on the other hand, knows which mempools it creates and doesn't care about internal mempools PMDs might create.
--- app/test/test_mempool.c | 248 ++++++++++++++++++++++++++++++++++++++ lib/mempool/rte_mempool.c | 124 +++++++++++++++++++ lib/mempool/rte_mempool.h | 62 ++++++++++ lib/mempool/version.map | 8 ++ 4 files changed, 442 insertions(+)
app/test/test_mempool.c +248 -0
@@ -14,6 +14,7 @@#include <rte_common.h> #include <rte_log.h> #include <rte_debug.h> +#include <rte_errno.h> #include <rte_memory.h> #include <rte_launch.h> #include <rte_cycles.h>
@@ -489,6 +490,245 @@ test_mp_mem_init(struct rte_mempool *mp, data->ret =0 ; } +struct test_mempool_events_data { +struct rte_mempool *mp; +enum rte_mempool_event event; +bool invoked; +}; + +static void +test_mempool_events_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *user_data) +{ +struct test_mempool_events_data *data = user_data; + + data->mp = mp; + data->event = event; + data->invoked = true; +} + +static int +test_mempool_events (int (*populate)(struct rte_mempool *mp)) +{ +#pragma push_macro("RTE_TEST_TRACE_FAILURE") +#undef RTE_TEST_TRACE_FAILURE +#define RTE_TEST_TRACE_FAILURE (...) do { goto fail; } while (0) + +static const size_t CB_NUM =3 ; +static const size_t MP_NUM =2 ; + +struct test_mempool_events_data data[CB_NUM ]; +struct rte_mempool *mp[MP_NUM ], *freed; +char name[RTE_MEMPOOL_NAMESIZE ]; +size_t i, j; +int ret; + +memset (mp,0 ,sizeof (mp)); +for (i =0 ; i <CB_NUM ; i++) { + ret =rte_mempool_event_callback_register + (test_mempool_events_cb, &data[i]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to register the callback %zu: %s" , + i,rte_strerror (rte_errno)); + } + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, mp); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Unregistered a non-registered callback" ); +/* NULL argument has no special meaning in this API. */ + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, +NULL ); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Unregistered a non-registered callback with NULL argument" ); + +/* Create mempool 0 that will be observed by all callbacks. */ +memset (&data,0 ,sizeof (data)); +strcpy (name,"empty0" ); + mp[0 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp[0 ],"Cannot create mempool %s: %s" , + name,rte_strerror (rte_errno)); +for (j =0 ; j <CB_NUM ; j++) +RTE_TEST_ASSERT_EQUAL (data[j].invoked, false, +"Callback %zu invoked on %s mempool creation" , + j, name); + +rte_mempool_set_ops_byname (mp[0 ],rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp[0 ]); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp[0 ]->size,"Failed to populate mempool %s: %s" , + name,rte_strerror (rte_errno)); +for (j =0 ; j <CB_NUM ; j++) { +RTE_TEST_ASSERT_EQUAL (data[j].invoked, true, +"Callback %zu not invoked on mempool %s population" , + j, name); +RTE_TEST_ASSERT_EQUAL (data[j].event, +RTE_MEMPOOL_EVENT_READY , +"Wrong callback invoked, expected READY" ); +RTE_TEST_ASSERT_EQUAL (data[j].mp, mp[0 ], +"Callback %zu invoked for a wrong mempool instead of %s" , + j, name); + } + +/* Check that unregistered callback 0 observes no events. */ + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, + &data[0 ]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister callback 0: %s" , +rte_strerror (rte_errno)); +memset (&data,0 ,sizeof (data)); +strcpy (name,"empty1" ); + mp[1 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp[1 ],"Cannot create mempool %s: %s" , + name,rte_strerror (rte_errno)); +rte_mempool_set_ops_byname (mp[1 ],rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp[1 ]); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp[1 ]->size,"Failed to populate mempool %s: %s" , + name,rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data[0 ].invoked, false, +"Unregistered callback 0 invoked on %s mempool populaton" , + name); + +for (i =0 ; i <MP_NUM ; i++) { +memset (&data,0 ,sizeof (data)); +sprintf (name,"empty%zu" , i); +rte_mempool_free (mp[i]); +/* +* Save pointer to check that it was passed to the callback, +* but put NULL into the array in case cleanup is called early. +*/ + freed = mp[i]; + mp[i] =NULL ; +for (j =1 ; j <CB_NUM ; j++) { +RTE_TEST_ASSERT_EQUAL (data[j].invoked, true, +"Callback %zu not invoked on mempool %s destruction" , + j, name); +RTE_TEST_ASSERT_EQUAL (data[j].event, +RTE_MEMPOOL_EVENT_DESTROY , +"Wrong callback invoked, expected DESTROY" ); +RTE_TEST_ASSERT_EQUAL (data[j].mp, freed, +"Callback %zu invoked for a wrong mempool instead of %s" , + j, name); + } +RTE_TEST_ASSERT_EQUAL (data[0 ].invoked, false, +"Unregistered callback 0 invoked on %s mempool destruction" , + name); + } + +for (j =1 ; j <CB_NUM ; j++) { + ret =rte_mempool_event_callback_unregister + (test_mempool_events_cb, &data[j]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister the callback %zu: %s" , + j,rte_strerror (rte_errno)); + } +return TEST_SUCCESS ; + +fail: +for (j =0 ; j <CB_NUM ; j++) +rte_mempool_event_callback_unregister + (test_mempool_events_cb, &data[j]); +for (i =0 ; i <MP_NUM ; i++) +rte_mempool_free (mp[i]); +return TEST_FAILED ; + +#pragma pop_macro("RTE_TEST_TRACE_FAILURE") +} + +struct test_mempool_events_safety_data { +bool invoked; +int (*api_func)(rte_mempool_event_callback *func,void *user_data); +rte_mempool_event_callback *cb_func; +void *cb_user_data; +int ret; +}; + +static void +test_mempool_events_safety_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *user_data) +{ +struct test_mempool_events_safety_data *data = user_data; + +RTE_SET_USED (event); +RTE_SET_USED (mp); + data->invoked = true; + data->ret = data->api_func (data->cb_func, data->cb_user_data); +} + +static int +test_mempool_events_safety (void ) +{ +#pragma push_macro("RTE_TEST_TRACE_FAILURE") +#undef RTE_TEST_TRACE_FAILURE +#define RTE_TEST_TRACE_FAILURE (...) do { \ + ret = TEST_FAILED; \ + goto exit; \ + } while (0) + +struct test_mempool_events_data data; +struct test_mempool_events_safety_data sdata[2 ]; +struct rte_mempool *mp; +size_t i; +int ret; + +/* removes itself */ + sdata[0 ].api_func = rte_mempool_event_callback_unregister; + sdata[0 ].cb_func = test_mempool_events_safety_cb; + sdata[0 ].cb_user_data = &sdata[0 ]; + sdata[0 ].ret =-1 ; +rte_mempool_event_callback_register (test_mempool_events_safety_cb, + &sdata[0 ]); +/* inserts a callback after itself */ + sdata[1 ].api_func = rte_mempool_event_callback_register; + sdata[1 ].cb_func = test_mempool_events_cb; + sdata[1 ].cb_user_data = &data; + sdata[1 ].ret =-1 ; +rte_mempool_event_callback_register (test_mempool_events_safety_cb, + &sdata[1 ]); + + mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create mempool: %s" , +rte_strerror (rte_errno)); +memset (&data,0 ,sizeof (data)); + ret =rte_mempool_populate_default (mp); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp->size,"Failed to populate mempool: %s" , +rte_strerror (rte_errno)); + +RTE_TEST_ASSERT_EQUAL (sdata[0 ].ret,0 ,"Callback failed to unregister itself: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (sdata[1 ].ret,0 ,"Failed to insert a new callback: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data.invoked, false, +"Inserted callback is invoked on mempool population" ); + +memset (&data,0 ,sizeof (data)); + sdata[0 ].invoked = false; +rte_mempool_free (mp); + mp =NULL ; +RTE_TEST_ASSERT_EQUAL (sdata[0 ].invoked, false, +"Callback that unregistered itself was called" ); +RTE_TEST_ASSERT_EQUAL (sdata[1 ].ret, -EEXIST , +"New callback inserted twice" ); +RTE_TEST_ASSERT_EQUAL (data.invoked, true, +"Inserted callback is not invoked on mempool destruction" ); + +rte_mempool_event_callback_unregister (test_mempool_events_cb, &data); +for (i =0 ; i <RTE_DIM (sdata); i++) +rte_mempool_event_callback_unregister + (test_mempool_events_safety_cb, &sdata[i]); + ret =TEST_SUCCESS ; + +exit: +/* cleanup, don't care which callbacks are already removed */ +rte_mempool_event_callback_unregister (test_mempool_events_cb, &data); +for (i =0 ; i <RTE_DIM (sdata); i++) +rte_mempool_event_callback_unregister + (test_mempool_events_safety_cb, &sdata[i]); +/* in case of failure before the planned destruction */ +rte_mempool_free (mp); +return ret; + +#pragma pop_macro("RTE_TEST_TRACE_FAILURE") +} +static int test_mempool (void ) {
@@ -666,6 +906,14 @@ test_mempool(void)if (test_mempool_basic (default_pool,1 ) <0 )GOTO_ERR (ret, err); +/* test mempool event callbacks */ +if (test_mempool_events (rte_mempool_populate_default) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events (rte_mempool_populate_anon) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events_safety () <0 ) +GOTO_ERR (ret, err); +rte_mempool_list_dump (stdout); ret =0 ;
lib/mempool/rte_mempool.c +124 -0
145 lines not on this page · raw message
lib/mempool/rte_mempool.h +62 -0
68 lines not on this page · raw message
lib/mempool/version.map +8 -0
@@ -64,3 +64,11 @@ EXPERIMENTAL { __rte_mempool_trace_ops_free; __rte_mempool_trace_set_ops_byname; }; + +INTERNAL { + global: + + # added in 21.11 + rte_mempool_event_callback_register; + rte_mempool_event_callback_unregister; +};
Signature · 1 line
2.25.1
PATCH v8 2/4 mempool: add non-IO flag
In reply to Dmitry KozlyukMempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add MEMPOOL_F_NON_IO flag to mark such mempools automatically
a) if their objects are not contiguous;
b) if IOVA is not available for any object.
Other components can inspect this flag
in order to optimize their memory management.
Discussion: https://mails.dpdk.org/archives/dev/2021-August/216654.html
--- app/proc-info/main.c | 6 +- app/test/test_mempool.c | 114 +++++++++++++++++++++++++ doc/guides/rel_notes/release_21_11.rst | 3 + lib/mempool/rte_mempool.c | 10 +++ lib/mempool/rte_mempool.h | 2 + 5 files changed, 133 insertions(+), 2 deletions(-)
app/proc-info/main.c +4 -2
@@ -1295,7 +1295,8 @@ show_mempool(char *name)"\t -- No cache align (%c)\n" "\t -- SP put (%c), SC get (%c)\n" "\t -- Pool created (%c)\n" -"\t -- No IOVA config (%c)\n" , +"\t -- No IOVA config (%c)\n" +"\t -- Not used for IO (%c)\n" , ptr->name, ptr->socket_id, (flags & MEMPOOL_F_NO_SPREAD) ? 'y' : 'n',
@@ -1303,7 +1304,8 @@ show_mempool(char *name) (flags &MEMPOOL_F_SP_PUT ) ?'y' :'n' , (flags &MEMPOOL_F_SC_GET ) ?'y' :'n' , (flags &MEMPOOL_F_POOL_CREATED ) ?'y' :'n' , - (flags & MEMPOOL_F_NO_IOVA_CONTIG) ? 'y' : 'n'); + (flags &MEMPOOL_F_NO_IOVA_CONTIG ) ?'y' :'n' , + (flags & MEMPOOL_F_NON_IO) ? 'y' : 'n'); printf(" - Size %u Cache %u element %u\n" " - header %u trailer %u\n" " - private data size %u\n",
app/test/test_mempool.c +114 -0
132 lines not on this page · raw message
doc/guides/rel_notes/release_21_11.rst +3 -0
@@ -237,6 +237,9 @@ API Changes the crypto/security operation. This field will be used to communicate events such as soft expiry with IPsec in lookaside mode. +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA). + ABI Changes -----------
lib/mempool/rte_mempool.c +10 -0
@@ -372,6 +372,10 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +/* At least some objects in the pool can now be used for IO. */ +if (iova !=RTE_BAD_IOVA ) + mp->flags &= ~MEMPOOL_F_NON_IO ; +/* Report the mempool as ready only when fully populated. */ if (mp->populated_size >= mp->size)mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_READY , mp);
@@ -851,6 +855,12 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,return NULL ; } +/* +* No objects in the pool can be used for IO until it's populated +* with at least some objects with valid IOVA. +*/ + flags |=MEMPOOL_F_NON_IO ; +/* "no cache align" imply "no spread" */ if (flags &MEMPOOL_F_NO_CACHE_ALIGN ) flags |=MEMPOOL_F_NO_SPREAD ;
lib/mempool/rte_mempool.h +2 -0
@@ -257,6 +257,8 @@ struct rte_mempool {#define MEMPOOL_F_SC_GET 0x0008/**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010/**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020/**< Don't need IOVA contiguous objs. */ +/** Internal: no object from the pool can be used for device IO (DMA). */ +#define MEMPOOL_F_NON_IO 0x0040/** * @internal When debug is enabled, store some statistics.
Signature · 1 line
2.25.1
Re: [dpdk-dev] [PATCH v8 2/4] mempool: add non-IO flag
Quoted 24 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of Dmitry Kozlyuk
Sent: Monday, October 18, 2021 10:41 PM
To: [email protected]
Cc: David Marchand <[email protected]>; Matan Azrad <[email protected]>; Andrew Rybchenko <[email protected]>; Tahhan, Maryam <[email protected]>; Pattan, Reshma <[email protected]>; Olivier Matz <[email protected]>
Subject: [dpdk-dev] [PATCH v8 2/4] mempool: add non-IO flagMempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA.
AddMEMPOOL_F_NON_IOflag to mark such mempools automatically
a) if their objects are not contiguous;
b) if IOVA is not available for any object.
Other components can inspect this flag
in order to optimize their memory management.Discussion: https://mails.dpdk.org/archives/dev/2021-August/216654.html
Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Matan Azrad <[email protected]>Reviewed-by Andrew Rybchenko <[email protected]>
Quoted 8 lines
--- app/proc-info/main.c | 6 +- app/test/test_mempool.c | 114 +++++++++++++++++++++++++ doc/guides/rel_notes/release_21_11.rst | 3 + lib/mempool/rte_mempool.c | 10 +++ lib/mempool/rte_mempool.h | 2 + 5 files changed, 133 insertions(+), 2 deletions(-)
Hi Dmitry,
We meet an issue based on this patch that mempool_autotest execute failed on FreeBSD13.0, bug id is https://bugs.dpdk.org/show_bug.cgi?id=863, could you pls have a look? Reproduce steps:
2.lanch app
# ./x86_64-native-bsdapp-gcc/app/test/dpdk-test -n 4 -c f 3. execute dpdk command # mempool_autotest common_pool_count=1598 no statistics available EAL: Test assert test_mempool_flag_non_io_unset_when_populated_with_valid_iova line 781 failed: Cannot get IOVA test failed at test_mempool():1030 Test Failed
PATCH v8 3/4 common/mlx5: add mempool registration facilities
In reply to Dmitry KozlyukAdd 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.
--- drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + 5 files changed, 666 insertions(+)
drivers/common/mlx5/mlx5_common_mp.c +50 -0
@@ -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. *
drivers/common/mlx5/mlx5_common_mp.h +14 -0
@@ -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 ,
@@ -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;
@@ -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;
@@ -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
drivers/common/mlx5/mlx5_common_mr.c +580 -0
596 lines not on this page · raw message
drivers/common/mlx5/mlx5_common_mr.h +17 -0
@@ -13,6 +13,7 @@#include <rte_rwlock.h> #include <rte_bitmap.h> +#include <rte_mbuf.h> #include <rte_memory.h> #include "mlx5_glue.h"
@@ -75,6 +76,7 @@ struct mlx5_mr_ctrl { } __rte_packed;LIST_HEAD (mlx5_mr_list, mlx5_mr); +LIST_HEAD (mlx5_mempool_reg_list, mlx5_mempool_reg);/* Global per-device MR cache. */ struct mlx5_mr_share_cache {
@@ -83,6 +85,7 @@ struct mlx5_mr_share_cache {struct mlx5_mr_btree cache;/* Global MR cache table. */ struct mlx5_mr_list mr_list;/* Registered MR list. */ struct mlx5_mr_list mr_free_list;/* Freed MR list. */ +struct mlx5_mempool_reg_list mempool_reg_list;/* Mempool database. */ mlx5_reg_mr_t reg_mr_cb;/* Callback to reg_mr func */ mlx5_dereg_mr_t dereg_mr_cb;/* Callback to dereg_mr func */ } __rte_packed;
@@ -136,6 +139,10 @@ uint32_t mlx5_mr_addr2mr_bh(void *pd, struct mlx5_mp_id *mp_id,struct mlx5_mr_ctrl *mr_ctrl, uintptr_t addr, unsigned int mr_ext_memseg_en);__rte_internal +uint32_t mlx5_mr_mempool2mr_bh(struct mlx5_mr_share_cache *share_cache, +struct mlx5_mr_ctrl *mr_ctrl, +struct rte_mempool *mp,uintptr_t addr); +__rte_internal void mlx5_mr_release_cache(struct mlx5_mr_share_cache *mr_cache);__rte_internal void mlx5_mr_dump_cache(struct mlx5_mr_share_cache *share_cache __rte_unused);
@@ -179,4 +186,14 @@ mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);__rte_internal voidmlx5_mr_free (struct mlx5_mr *mr,mlx5_dereg_mr_t dereg_mr_cb); + +__rte_internal +int +mlx5_mr_mempool_register (struct mlx5_mr_share_cache *share_cache,void *pd, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +__rte_internal +int +mlx5_mr_mempool_unregister (struct mlx5_mr_share_cache *share_cache, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +#endif /* RTE_PMD_MLX5_COMMON_MR_H_ */
drivers/common/mlx5/version.map +5 -0
@@ -152,4 +152,9 @@ INTERNAL { mlx5_realloc; mlx5_translate_port_name; # WINDOWS_NO_EXPORT + + mlx5_mr_mempool_register; + mlx5_mr_mempool_unregister; + mlx5_mp_req_mempool_reg; + mlx5_mr_mempool2mr_bh; };
Signature · 1 line
2.25.1
PATCH v8 4/4 net/mlx5: support mempool registration
In reply to Dmitry KozlyukWhen the first port in a given protection domain (PD) starts, install a mempool event callback for this PD and register all existing memory regions (MR) for it. When the last port in a PD closes, remove the callback and unregister all mempools for this PD. This behavior can be switched off with a new devarg: mr_mempool_reg_en.
On TX slow path, i.e. when an MR key for the address of the buffer to send is not in the local cache, first try to retrieve it from the database of registered mempools. Supported are direct and indirect mbufs, as well as externally-attached ones from MLX5 MPRQ feature. Lookup in the database of non-mempool memory is used as the last resort.
RX mempools are registered regardless of the devarg value. On RX data path only the local cache and the mempool database is used. If implicit mempool registration is disabled, these mempools are unregistered at port stop, releasing the MRs.
--- doc/guides/nics/mlx5.rst | 13 +++ doc/guides/rel_notes/release_21_11.rst | 6 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 +++++++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 10 ++ drivers/net/mlx5/mlx5_mr.c | 120 +++++-------------- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 ++-- drivers/net/mlx5/mlx5_rxq.c | 13 +++ drivers/net/mlx5/mlx5_trigger.c | 77 +++++++++++-- drivers/net/mlx5/windows/mlx5_os.c | 1 + 12 files changed, 347 insertions(+), 116 deletions(-)
doc/guides/nics/mlx5.rst +13 -0
@@ -1001,6 +1001,19 @@ Driver options Enabled by default. +- ``mr_mempool_reg_en`` parameter [int] + + A nonzero value enables implicit registration of DMA memory of all mempools + except those having ``MEMPOOL_F_NON_IO``. This flag is set automatically + for mempools populated with non-contiguous objects or those without IOVA. + The effect is that when a packet from a mempool is transmitted, + its memory is already registered for DMA in the PMD and no registration + will happen on the data path. The tradeoff is extra work on the creation + of each mempool and increased HW resource use if some mempools + are not used with MLX5 devices. + + Enabled by default. + - ``representor`` parameter [list] This parameter can be used to instantiate DPDK Ethernet devices from
doc/guides/rel_notes/release_21_11.rst +6 -0
@@ -167,6 +167,12 @@ New Features * Added tests to verify tunnel header verification in IPsec inbound. * Added tests to verify inner checksum. +* **Updated Mellanox mlx5 driver.** + + Updated the Mellanox mlx5 driver with new features and improvements, including: + + * Added implicit mempool registration to avoid data path hiccups (opt-out). + Removed Items -------------
drivers/net/mlx5/linux/mlx5_mp_os.c +44 -0
56 lines not on this page · raw message
drivers/net/mlx5/linux/mlx5_os.c +2 -2
@@ -1034,8 +1034,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, err =mlx5_proc_priv_init (eth_dev);if (err)return NULL ; - mp_id.port_id = eth_dev->data->port_id; -strlcpy (mp_id.name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +mlx5_mp_id_init (&mp_id, eth_dev->data->port_id);/* Receive command fd from primary process */ err =mlx5_mp_req_verbs_cmd_fd (&mp_id);if (err <0 )
@@ -2133,6 +2132,7 @@ mlx5_os_config_default(struct mlx5_dev_config *config) config->txqs_inline =MLX5_ARG_UNSET ; config->vf_nl_en =1 ; config->mr_ext_memseg_en =1 ; + config->mr_mempool_reg_en =1 ; config->mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; config->mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; config->dv_esw_en =1 ;
drivers/net/mlx5/mlx5.c +152 -0
188 lines not on this page · raw message
drivers/net/mlx5/mlx5.h +10 -0
@@ -155,6 +155,13 @@ struct mlx5_flow_dump_ack {/** Key string for IPC. */ #define MLX5_MP_NAME "net_mlx5_mp" +/** Initialize a multi-process ID. */ +static inline void +mlx5_mp_id_init (struct mlx5_mp_id *mp_id,uint16_t port_id) +{ + mp_id->port_id = port_id; +strlcpy (mp_id->name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +}LIST_HEAD (mlx5_dev_list, mlx5_dev_ctx_shared);
@@ -270,6 +277,8 @@ struct mlx5_dev_config { unsigned int dv_miss_info:1; /* restore packet after partial hw miss */ unsigned int allow_duplicate_pattern:1;/* Allow/Prevent the duplicate rules pattern. */ + unsigned int mr_mempool_reg_en:1; +/* Allow/prevent implicit mempool memory registration. */ struct {unsigned int enabled:1 ;/* Whether MPRQ is enabled. */ unsigned int stride_num_n;/* Number of strides. */
@@ -1498,6 +1507,7 @@ struct mlx5_dev_ctx_shared * mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, const struct mlx5_dev_config *config);void mlx5_free_shared_dev_ctx (struct mlx5_dev_ctx_shared *sh); +int mlx5_dev_ctx_shared_mempool_subscribe (struct rte_eth_dev *dev);void mlx5_free_table_hash_list (struct mlx5_priv *priv);int mlx5_alloc_table_hash_list (struct mlx5_priv *priv); void mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
drivers/net/mlx5/mlx5_mr.c +27 -93
138 lines not on this page · raw message
drivers/net/mlx5/mlx5_mr.h +0 -2
@@ -22,7 +22,5 @@void mlx5_mr_mem_event_cb (enum rte_mem_event event_type,const void *addr,size_t len,void *arg); -int mlx5_mr_update_mp (struct rte_eth_dev *dev,struct mlx5_mr_ctrl *mr_ctrl, -struct rte_mempool *mp);#endif /* RTE_PMD_MLX5_MR_H_ */
drivers/net/mlx5/mlx5_rx.h +14 -7
@@ -275,13 +275,11 @@ uint16_t mlx5_rx_burst_vec(void *dpdk_rxq, struct rte_mbuf **pkts,uint16_t mlx5_rx_burst_mprq_vec (void *dpdk_rxq,struct rte_mbuf **pkts,uint16_t pkts_n); -/* mlx5_mr.c */ - -uint32_t mlx5_rx_addr2mr_bh (struct mlx5_rxq_data *rxq,uintptr_t addr); +static int mlx5_rxq_mprq_enabled (struct mlx5_rxq_data *rxq);/** -* Query LKey from a packet buffer for Rx. No need to flush local caches for Rx -* as mempool is pre-configured and static. +* Query LKey from a packet buffer for Rx. No need to flush local caches +* as the Rx mempool database entries are valid for the lifetime of the queue. * * @param rxq * Pointer to Rx queue structure.
@@ -290,11 +288,14 @@ uint32_t mlx5_rx_addr2mr_bh(struct mlx5_rxq_data *rxq, uintptr_t addr);* * @return * Searched LKey on success, UINT32_MAX on no match. +* This function always succeeds on valid input. */ static __rte_always_inline uint32_tmlx5_rx_addr2mr (struct mlx5_rxq_data *rxq,uintptr_t addr) {struct mlx5_mr_ctrl *mr_ctrl = &rxq->mr_ctrl; +struct mlx5_rxq_ctrl *rxq_ctrl; +struct rte_mempool *mp;uint32_t lkey;/* Linear search on MR cache array. */
@@ -302,8 +303,14 @@ mlx5_rx_addr2mr(struct mlx5_rxq_data *rxq, uintptr_t addr) MLX5_MR_CACHE_N, addr);if (likely (lkey !=UINT32_MAX ))return lkey; -/* Take slower bottom-half (Binary Search) on miss. */ -return mlx5_rx_addr2mr_bh (rxq, addr); +/* +* Slower search in the mempool database on miss. +* During queue creation rxq->sh is not yet set, so we use rxq_ctrl. +*/ + rxq_ctrl = container_of(rxq, struct mlx5_rxq_ctrl, rxq); + mp =mlx5_rxq_mprq_enabled (rxq) ? rxq->mprq_mp : rxq->mp; +return mlx5_mr_mempool2mr_bh (&rxq_ctrl->priv->sh->share_cache, + mr_ctrl, mp, addr); }#define mlx5_rx_mb2mr (rxq, mb) mlx5_rx_addr2mr(rxq, (uintptr_t)((mb)->buf_addr))
drivers/net/mlx5/mlx5_rxq.c +13 -0
@@ -1162,6 +1162,7 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)unsigned int strd_sz_n =0 ;unsigned int i;unsigned int n_ibv =0 ; +int ret;if (!mlx5_mprq_enabled (dev))return 0 ;
@@ -1241,6 +1242,16 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev) rte_errno =ENOMEM ;return -rte_errno; } + ret =mlx5_mr_mempool_register (&priv->sh->share_cache, priv->sh->pd, + mp, &priv->mp_id); +if (ret <0 && rte_errno !=EEXIST ) { + ret = rte_errno; +DRV_LOG (ERR ,"port %u failed to register a mempool for Multi-Packet RQ" , + dev->data->port_id); +rte_mempool_free (mp); + rte_errno = ret; +return -rte_errno; + } priv->mprq_mp = mp; exit:/* Set mempool for each Rx queue. */
@@ -1443,6 +1454,8 @@ mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,/* rte_errno is already set. */ goto error; } +/* Rx queues don't use this pointer, but we want a valid structure. */ + tmpl->rxq.mr_ctrl.dev_gen_ptr = &priv->sh->share_cache.dev_gen; tmpl->socket = socket;if (dev->data->dev_conf.intr_conf.rxq) tmpl->irq =1 ;
drivers/net/mlx5/mlx5_trigger.c +65 -12
95 lines not on this page · raw message
drivers/net/mlx5/windows/mlx5_os.c +1 -0
@@ -1116,6 +1116,7 @@ mlx5_os_net_probe(struct rte_device *dev) dev_config.txqs_inline =MLX5_ARG_UNSET ; dev_config.vf_nl_en =0 ; dev_config.mr_ext_memseg_en =1 ; + dev_config.mr_mempool_reg_en =1 ; dev_config.mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; dev_config.mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; dev_config.dv_esw_en =0 ;
Signature · 1 line
2.25.1
v9 cover net/mlx5: implicit mempool registration
In reply to Dmitry KozlyukMLX5 hardware has its internal IOMMU where PMD registers the memory. On the data path, PMD translates VA into a key consumed by the device IOMMU. It is impractical for the PMD to register all allocated memory because of increased lookup cost both in HW and SW. Most often mbuf memory comes from mempools, so if PMD tracks them, it can almost always have mbuf memory registered before an mbuf hits the PMD. This patchset adds such tracking in the PMD and internal API to support it.
Please see [1] for the discussion of the patch 2/4 and how it can be useful outside of the MLX5 PMD.
v9 (CI):
Fix another failure of mempool_autotest.
Use negative result of rte_mempool_populate_iova()
to report errors in unit tests instead of rte_errno.
v8:
Fix mempool_autotest failure on Ubuntu 18.04 (CI).
v7 (internal CI):
1. Fix unit test compilation issues with GCC.
2. Keep rte_mempool_event description non-internal: Doxygen treats it as not documented otherwise, "doc" target fails.
v6:
Fix compilation issue in proc-info (CI).
v5:
1. Change non-IO flag inference + various fixes (Andrew).
2. Fix callback unregistration from secondary processes (Olivier).
3. Support non-IO flag in proc-dump (David).
4. Fix the usage of locks (Olivier).
5. Avoid resource leaks in unit test (Olivier).
v4: (Andrew)
1. Improve mempool event callbacks unit tests and documentation.
2. Make MEMPOOL_F_NON_IO internal and automatically inferred. Add unit tests for the inference logic.
v3: Improve wording and naming; fix typos (Thomas).
v2 (internal review and testing):
1. Change tracked mempool event from being created (CREATE) to being fully populated (READY), which is the state PMD is interested in.
2. Unit test the new mempool callback API.
3. Remove bogus "error" messages in normal conditions.
4. Fixes in PMD.
Dmitry Kozlyuk (4):
mempool: add event callbacks
mempool: add non-IO flag
common/mlx5: add mempool registration facilities net/mlx5: support mempool registration
app/proc-info/main.c | 6 +- app/test/test_mempool.c | 363 ++++++++++++++++ doc/guides/nics/mlx5.rst | 13 + doc/guides/rel_notes/release_21_11.rst | 9 + drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 ++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++ drivers/net/mlx5/mlx5.h | 10 + drivers/net/mlx5/mlx5_mr.c | 120 ++--- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 +- drivers/net/mlx5/mlx5_rxq.c | 13 + drivers/net/mlx5/mlx5_trigger.c | 77 +++- drivers/net/mlx5/windows/mlx5_os.c | 1 + lib/mempool/rte_mempool.c | 134 ++++++ lib/mempool/rte_mempool.h | 64 +++ lib/mempool/version.map | 8 + 22 files changed, 1589 insertions(+), 118 deletions(-)
Signature · 1 line
2.25.1
PATCH v9 1/4 mempool: add event callbacks
Data path performance can benefit if the PMD knows which memory it will need to handle in advance, before the first mbuf is sent to the PMD. It is impractical, however, to consider all allocated memory for this purpose. Most often mbuf memory comes from mempools that can come and go. PMD can enumerate existing mempools on device start, but it also needs to track creation and destruction of mempools after the forwarding starts but before an mbuf from the new mempool is sent to the device.
Add an API to register callback for mempool life cycle events:
* rte_mempool_event_callback_register()
* rte_mempool_event_callback_unregister()
Currently tracked events are:
* RTE_MEMPOOL_EVENT_READY (after populating a mempool)
* RTE_MEMPOOL_EVENT_DESTROY (before freeing a mempool) Provide a unit test for the new API.
The new API is internal, because it is primarily demanded by PMDs that may need to deal with any mempools and do not control their creation, while an application, on the other hand, knows which mempools it creates and doesn't care about internal mempools PMDs might create.
--- app/test/test_mempool.c | 248 ++++++++++++++++++++++++++++++++++++++ lib/mempool/rte_mempool.c | 124 +++++++++++++++++++ lib/mempool/rte_mempool.h | 62 ++++++++++ lib/mempool/version.map | 8 ++ 4 files changed, 442 insertions(+)
app/test/test_mempool.c +248 -0
@@ -14,6 +14,7 @@#include <rte_common.h> #include <rte_log.h> #include <rte_debug.h> +#include <rte_errno.h> #include <rte_memory.h> #include <rte_launch.h> #include <rte_cycles.h>
@@ -489,6 +490,245 @@ test_mp_mem_init(struct rte_mempool *mp, data->ret =0 ; } +struct test_mempool_events_data { +struct rte_mempool *mp; +enum rte_mempool_event event; +bool invoked; +}; + +static void +test_mempool_events_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *user_data) +{ +struct test_mempool_events_data *data = user_data; + + data->mp = mp; + data->event = event; + data->invoked = true; +} + +static int +test_mempool_events (int (*populate)(struct rte_mempool *mp)) +{ +#pragma push_macro("RTE_TEST_TRACE_FAILURE") +#undef RTE_TEST_TRACE_FAILURE +#define RTE_TEST_TRACE_FAILURE (...) do { goto fail; } while (0) + +static const size_t CB_NUM =3 ; +static const size_t MP_NUM =2 ; + +struct test_mempool_events_data data[CB_NUM ]; +struct rte_mempool *mp[MP_NUM ], *freed; +char name[RTE_MEMPOOL_NAMESIZE ]; +size_t i, j; +int ret; + +memset (mp,0 ,sizeof (mp)); +for (i =0 ; i <CB_NUM ; i++) { + ret =rte_mempool_event_callback_register + (test_mempool_events_cb, &data[i]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to register the callback %zu: %s" , + i,rte_strerror (rte_errno)); + } + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, mp); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Unregistered a non-registered callback" ); +/* NULL argument has no special meaning in this API. */ + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, +NULL ); +RTE_TEST_ASSERT_NOT_EQUAL (ret,0 ,"Unregistered a non-registered callback with NULL argument" ); + +/* Create mempool 0 that will be observed by all callbacks. */ +memset (&data,0 ,sizeof (data)); +strcpy (name,"empty0" ); + mp[0 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp[0 ],"Cannot create mempool %s: %s" , + name,rte_strerror (rte_errno)); +for (j =0 ; j <CB_NUM ; j++) +RTE_TEST_ASSERT_EQUAL (data[j].invoked, false, +"Callback %zu invoked on %s mempool creation" , + j, name); + +rte_mempool_set_ops_byname (mp[0 ],rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp[0 ]); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp[0 ]->size,"Failed to populate mempool %s: %s" , + name,rte_strerror (-ret)); +for (j =0 ; j <CB_NUM ; j++) { +RTE_TEST_ASSERT_EQUAL (data[j].invoked, true, +"Callback %zu not invoked on mempool %s population" , + j, name); +RTE_TEST_ASSERT_EQUAL (data[j].event, +RTE_MEMPOOL_EVENT_READY , +"Wrong callback invoked, expected READY" ); +RTE_TEST_ASSERT_EQUAL (data[j].mp, mp[0 ], +"Callback %zu invoked for a wrong mempool instead of %s" , + j, name); + } + +/* Check that unregistered callback 0 observes no events. */ + ret =rte_mempool_event_callback_unregister (test_mempool_events_cb, + &data[0 ]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister callback 0: %s" , +rte_strerror (rte_errno)); +memset (&data,0 ,sizeof (data)); +strcpy (name,"empty1" ); + mp[1 ] =rte_mempool_create_empty (name,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp[1 ],"Cannot create mempool %s: %s" , + name,rte_strerror (rte_errno)); +rte_mempool_set_ops_byname (mp[1 ],rte_mbuf_best_mempool_ops (),NULL ); + ret =populate (mp[1 ]); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp[1 ]->size,"Failed to populate mempool %s: %s" , + name,rte_strerror (-ret)); +RTE_TEST_ASSERT_EQUAL (data[0 ].invoked, false, +"Unregistered callback 0 invoked on %s mempool populaton" , + name); + +for (i =0 ; i <MP_NUM ; i++) { +memset (&data,0 ,sizeof (data)); +sprintf (name,"empty%zu" , i); +rte_mempool_free (mp[i]); +/* +* Save pointer to check that it was passed to the callback, +* but put NULL into the array in case cleanup is called early. +*/ + freed = mp[i]; + mp[i] =NULL ; +for (j =1 ; j <CB_NUM ; j++) { +RTE_TEST_ASSERT_EQUAL (data[j].invoked, true, +"Callback %zu not invoked on mempool %s destruction" , + j, name); +RTE_TEST_ASSERT_EQUAL (data[j].event, +RTE_MEMPOOL_EVENT_DESTROY , +"Wrong callback invoked, expected DESTROY" ); +RTE_TEST_ASSERT_EQUAL (data[j].mp, freed, +"Callback %zu invoked for a wrong mempool instead of %s" , + j, name); + } +RTE_TEST_ASSERT_EQUAL (data[0 ].invoked, false, +"Unregistered callback 0 invoked on %s mempool destruction" , + name); + } + +for (j =1 ; j <CB_NUM ; j++) { + ret =rte_mempool_event_callback_unregister + (test_mempool_events_cb, &data[j]); +RTE_TEST_ASSERT_EQUAL (ret,0 ,"Failed to unregister the callback %zu: %s" , + j,rte_strerror (rte_errno)); + } +return TEST_SUCCESS ; + +fail: +for (j =0 ; j <CB_NUM ; j++) +rte_mempool_event_callback_unregister + (test_mempool_events_cb, &data[j]); +for (i =0 ; i <MP_NUM ; i++) +rte_mempool_free (mp[i]); +return TEST_FAILED ; + +#pragma pop_macro("RTE_TEST_TRACE_FAILURE") +} + +struct test_mempool_events_safety_data { +bool invoked; +int (*api_func)(rte_mempool_event_callback *func,void *user_data); +rte_mempool_event_callback *cb_func; +void *cb_user_data; +int ret; +}; + +static void +test_mempool_events_safety_cb (enum rte_mempool_event event, +struct rte_mempool *mp,void *user_data) +{ +struct test_mempool_events_safety_data *data = user_data; + +RTE_SET_USED (event); +RTE_SET_USED (mp); + data->invoked = true; + data->ret = data->api_func (data->cb_func, data->cb_user_data); +} + +static int +test_mempool_events_safety (void ) +{ +#pragma push_macro("RTE_TEST_TRACE_FAILURE") +#undef RTE_TEST_TRACE_FAILURE +#define RTE_TEST_TRACE_FAILURE (...) do { \ + ret = TEST_FAILED; \ + goto exit; \ + } while (0) + +struct test_mempool_events_data data; +struct test_mempool_events_safety_data sdata[2 ]; +struct rte_mempool *mp; +size_t i; +int ret; + +/* removes itself */ + sdata[0 ].api_func = rte_mempool_event_callback_unregister; + sdata[0 ].cb_func = test_mempool_events_safety_cb; + sdata[0 ].cb_user_data = &sdata[0 ]; + sdata[0 ].ret =-1 ; +rte_mempool_event_callback_register (test_mempool_events_safety_cb, + &sdata[0 ]); +/* inserts a callback after itself */ + sdata[1 ].api_func = rte_mempool_event_callback_register; + sdata[1 ].cb_func = test_mempool_events_cb; + sdata[1 ].cb_user_data = &data; + sdata[1 ].ret =-1 ; +rte_mempool_event_callback_register (test_mempool_events_safety_cb, + &sdata[1 ]); + + mp =rte_mempool_create_empty ("empty" ,MEMPOOL_SIZE , +MEMPOOL_ELT_SIZE ,0 ,0 , +SOCKET_ID_ANY ,0 ); +RTE_TEST_ASSERT_NOT_NULL (mp,"Cannot create mempool: %s" , +rte_strerror (rte_errno)); +memset (&data,0 ,sizeof (data)); + ret =rte_mempool_populate_default (mp); +RTE_TEST_ASSERT_EQUAL (ret, (int )mp->size,"Failed to populate mempool: %s" , +rte_strerror (-ret)); + +RTE_TEST_ASSERT_EQUAL (sdata[0 ].ret,0 ,"Callback failed to unregister itself: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (sdata[1 ].ret,0 ,"Failed to insert a new callback: %s" , +rte_strerror (rte_errno)); +RTE_TEST_ASSERT_EQUAL (data.invoked, false, +"Inserted callback is invoked on mempool population" ); + +memset (&data,0 ,sizeof (data)); + sdata[0 ].invoked = false; +rte_mempool_free (mp); + mp =NULL ; +RTE_TEST_ASSERT_EQUAL (sdata[0 ].invoked, false, +"Callback that unregistered itself was called" ); +RTE_TEST_ASSERT_EQUAL (sdata[1 ].ret, -EEXIST , +"New callback inserted twice" ); +RTE_TEST_ASSERT_EQUAL (data.invoked, true, +"Inserted callback is not invoked on mempool destruction" ); + +rte_mempool_event_callback_unregister (test_mempool_events_cb, &data); +for (i =0 ; i <RTE_DIM (sdata); i++) +rte_mempool_event_callback_unregister + (test_mempool_events_safety_cb, &sdata[i]); + ret =TEST_SUCCESS ; + +exit: +/* cleanup, don't care which callbacks are already removed */ +rte_mempool_event_callback_unregister (test_mempool_events_cb, &data); +for (i =0 ; i <RTE_DIM (sdata); i++) +rte_mempool_event_callback_unregister + (test_mempool_events_safety_cb, &sdata[i]); +/* in case of failure before the planned destruction */ +rte_mempool_free (mp); +return ret; + +#pragma pop_macro("RTE_TEST_TRACE_FAILURE") +} +static int test_mempool (void ) {
@@ -666,6 +906,14 @@ test_mempool(void)if (test_mempool_basic (default_pool,1 ) <0 )GOTO_ERR (ret, err); +/* test mempool event callbacks */ +if (test_mempool_events (rte_mempool_populate_default) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events (rte_mempool_populate_anon) <0 ) +GOTO_ERR (ret, err); +if (test_mempool_events_safety () <0 ) +GOTO_ERR (ret, err); +rte_mempool_list_dump (stdout); ret =0 ;
lib/mempool/rte_mempool.c +124 -0
145 lines not on this page · raw message
lib/mempool/rte_mempool.h +62 -0
68 lines not on this page · raw message
lib/mempool/version.map +8 -0
@@ -64,3 +64,11 @@ EXPERIMENTAL { __rte_mempool_trace_ops_free; __rte_mempool_trace_set_ops_byname; }; + +INTERNAL { + global: + + # added in 21.11 + rte_mempool_event_callback_register; + rte_mempool_event_callback_unregister; +};
Signature · 1 line
2.25.1
PATCH v9 2/4 mempool: add non-IO flag
In reply to Dmitry KozlyukMempool is a generic allocator that is not necessarily used for device IO operations and its memory for DMA. Add MEMPOOL_F_NON_IO flag to mark such mempools automatically
a) if their objects are not contiguous;
b) if IOVA is not available for any object.
Other components can inspect this flag
in order to optimize their memory management.
Discussion: https://mails.dpdk.org/archives/dev/2021-August/216654.html
--- app/proc-info/main.c | 6 +- app/test/test_mempool.c | 115 +++++++++++++++++++++++++ doc/guides/rel_notes/release_21_11.rst | 3 + lib/mempool/rte_mempool.c | 10 +++ lib/mempool/rte_mempool.h | 2 + 5 files changed, 134 insertions(+), 2 deletions(-)
app/proc-info/main.c +4 -2
@@ -1295,7 +1295,8 @@ show_mempool(char *name)"\t -- No cache align (%c)\n" "\t -- SP put (%c), SC get (%c)\n" "\t -- Pool created (%c)\n" -"\t -- No IOVA config (%c)\n" , +"\t -- No IOVA config (%c)\n" +"\t -- Not used for IO (%c)\n" , ptr->name, ptr->socket_id, (flags & MEMPOOL_F_NO_SPREAD) ? 'y' : 'n',
@@ -1303,7 +1304,8 @@ show_mempool(char *name) (flags &MEMPOOL_F_SP_PUT ) ?'y' :'n' , (flags &MEMPOOL_F_SC_GET ) ?'y' :'n' , (flags &MEMPOOL_F_POOL_CREATED ) ?'y' :'n' , - (flags & MEMPOOL_F_NO_IOVA_CONTIG) ? 'y' : 'n'); + (flags &MEMPOOL_F_NO_IOVA_CONTIG ) ?'y' :'n' , + (flags & MEMPOOL_F_NON_IO) ? 'y' : 'n'); printf(" - Size %u Cache %u element %u\n" " - header %u trailer %u\n" " - private data size %u\n",
app/test/test_mempool.c +115 -0
133 lines not on this page · raw message
doc/guides/rel_notes/release_21_11.rst +3 -0
@@ -237,6 +237,9 @@ API Changes the crypto/security operation. This field will be used to communicate events such as soft expiry with IPsec in lookaside mode. +* mempool: Added ``MEMPOOL_F_NON_IO`` flag to give a hint to DPDK components + that objects from this pool will not be used for device IO (e.g. DMA). + ABI Changes -----------
lib/mempool/rte_mempool.c +10 -0
@@ -372,6 +372,10 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,STAILQ_INSERT_TAIL (&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; +/* At least some objects in the pool can now be used for IO. */ +if (iova !=RTE_BAD_IOVA ) + mp->flags &= ~MEMPOOL_F_NON_IO ; +/* Report the mempool as ready only when fully populated. */ if (mp->populated_size >= mp->size)mempool_event_callback_invoke (RTE_MEMPOOL_EVENT_READY , mp);
@@ -851,6 +855,12 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,return NULL ; } +/* +* No objects in the pool can be used for IO until it's populated +* with at least some objects with valid IOVA. +*/ + flags |=MEMPOOL_F_NON_IO ; +/* "no cache align" imply "no spread" */ if (flags &MEMPOOL_F_NO_CACHE_ALIGN ) flags |=MEMPOOL_F_NO_SPREAD ;
lib/mempool/rte_mempool.h +2 -0
@@ -257,6 +257,8 @@ struct rte_mempool {#define MEMPOOL_F_SC_GET 0x0008/**< Default get is "single-consumer".*/ #define MEMPOOL_F_POOL_CREATED 0x0010/**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020/**< Don't need IOVA contiguous objs. */ +/** Internal: no object from the pool can be used for device IO (DMA). */ +#define MEMPOOL_F_NON_IO 0x0040/** * @internal When debug is enabled, store some statistics.
Signature · 1 line
2.25.1
PATCH v9 3/4 common/mlx5: add mempool registration facilities
In reply to Dmitry KozlyukAdd 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.
--- drivers/common/mlx5/mlx5_common_mp.c | 50 +++ drivers/common/mlx5/mlx5_common_mp.h | 14 + drivers/common/mlx5/mlx5_common_mr.c | 580 +++++++++++++++++++++++++++ drivers/common/mlx5/mlx5_common_mr.h | 17 + drivers/common/mlx5/version.map | 5 + 5 files changed, 666 insertions(+)
drivers/common/mlx5/mlx5_common_mp.c +50 -0
@@ -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. *
drivers/common/mlx5/mlx5_common_mp.h +14 -0
@@ -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 ,
@@ -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;
@@ -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;
@@ -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
drivers/common/mlx5/mlx5_common_mr.c +580 -0
596 lines not on this page · raw message
drivers/common/mlx5/mlx5_common_mr.h +17 -0
@@ -13,6 +13,7 @@#include <rte_rwlock.h> #include <rte_bitmap.h> +#include <rte_mbuf.h> #include <rte_memory.h> #include "mlx5_glue.h"
@@ -75,6 +76,7 @@ struct mlx5_mr_ctrl { } __rte_packed;LIST_HEAD (mlx5_mr_list, mlx5_mr); +LIST_HEAD (mlx5_mempool_reg_list, mlx5_mempool_reg);/* Global per-device MR cache. */ struct mlx5_mr_share_cache {
@@ -83,6 +85,7 @@ struct mlx5_mr_share_cache {struct mlx5_mr_btree cache;/* Global MR cache table. */ struct mlx5_mr_list mr_list;/* Registered MR list. */ struct mlx5_mr_list mr_free_list;/* Freed MR list. */ +struct mlx5_mempool_reg_list mempool_reg_list;/* Mempool database. */ mlx5_reg_mr_t reg_mr_cb;/* Callback to reg_mr func */ mlx5_dereg_mr_t dereg_mr_cb;/* Callback to dereg_mr func */ } __rte_packed;
@@ -136,6 +139,10 @@ uint32_t mlx5_mr_addr2mr_bh(void *pd, struct mlx5_mp_id *mp_id,struct mlx5_mr_ctrl *mr_ctrl, uintptr_t addr, unsigned int mr_ext_memseg_en);__rte_internal +uint32_t mlx5_mr_mempool2mr_bh(struct mlx5_mr_share_cache *share_cache, +struct mlx5_mr_ctrl *mr_ctrl, +struct rte_mempool *mp,uintptr_t addr); +__rte_internal void mlx5_mr_release_cache(struct mlx5_mr_share_cache *mr_cache);__rte_internal void mlx5_mr_dump_cache(struct mlx5_mr_share_cache *share_cache __rte_unused);
@@ -179,4 +186,14 @@ mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);__rte_internal voidmlx5_mr_free (struct mlx5_mr *mr,mlx5_dereg_mr_t dereg_mr_cb); + +__rte_internal +int +mlx5_mr_mempool_register (struct mlx5_mr_share_cache *share_cache,void *pd, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +__rte_internal +int +mlx5_mr_mempool_unregister (struct mlx5_mr_share_cache *share_cache, +struct rte_mempool *mp,struct mlx5_mp_id *mp_id); +#endif /* RTE_PMD_MLX5_COMMON_MR_H_ */
drivers/common/mlx5/version.map +5 -0
@@ -152,4 +152,9 @@ INTERNAL { mlx5_realloc; mlx5_translate_port_name; # WINDOWS_NO_EXPORT + + mlx5_mr_mempool_register; + mlx5_mr_mempool_unregister; + mlx5_mp_req_mempool_reg; + mlx5_mr_mempool2mr_bh; };
Signature · 1 line
2.25.1
PATCH v9 4/4 net/mlx5: support mempool registration
In reply to Dmitry KozlyukWhen the first port in a given protection domain (PD) starts, install a mempool event callback for this PD and register all existing memory regions (MR) for it. When the last port in a PD closes, remove the callback and unregister all mempools for this PD. This behavior can be switched off with a new devarg: mr_mempool_reg_en.
On TX slow path, i.e. when an MR key for the address of the buffer to send is not in the local cache, first try to retrieve it from the database of registered mempools. Supported are direct and indirect mbufs, as well as externally-attached ones from MLX5 MPRQ feature. Lookup in the database of non-mempool memory is used as the last resort.
RX mempools are registered regardless of the devarg value. On RX data path only the local cache and the mempool database is used. If implicit mempool registration is disabled, these mempools are unregistered at port stop, releasing the MRs.
--- doc/guides/nics/mlx5.rst | 13 +++ doc/guides/rel_notes/release_21_11.rst | 6 + drivers/net/mlx5/linux/mlx5_mp_os.c | 44 +++++++ drivers/net/mlx5/linux/mlx5_os.c | 4 +- drivers/net/mlx5/mlx5.c | 152 +++++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 10 ++ drivers/net/mlx5/mlx5_mr.c | 120 +++++-------------- drivers/net/mlx5/mlx5_mr.h | 2 - drivers/net/mlx5/mlx5_rx.h | 21 ++-- drivers/net/mlx5/mlx5_rxq.c | 13 +++ drivers/net/mlx5/mlx5_trigger.c | 77 +++++++++++-- drivers/net/mlx5/windows/mlx5_os.c | 1 + 12 files changed, 347 insertions(+), 116 deletions(-)
doc/guides/nics/mlx5.rst +13 -0
@@ -1001,6 +1001,19 @@ Driver options Enabled by default. +- ``mr_mempool_reg_en`` parameter [int] + + A nonzero value enables implicit registration of DMA memory of all mempools + except those having ``MEMPOOL_F_NON_IO``. This flag is set automatically + for mempools populated with non-contiguous objects or those without IOVA. + The effect is that when a packet from a mempool is transmitted, + its memory is already registered for DMA in the PMD and no registration + will happen on the data path. The tradeoff is extra work on the creation + of each mempool and increased HW resource use if some mempools + are not used with MLX5 devices. + + Enabled by default. + - ``representor`` parameter [list] This parameter can be used to instantiate DPDK Ethernet devices from
doc/guides/rel_notes/release_21_11.rst +6 -0
@@ -167,6 +167,12 @@ New Features * Added tests to verify tunnel header verification in IPsec inbound. * Added tests to verify inner checksum. +* **Updated Mellanox mlx5 driver.** + + Updated the Mellanox mlx5 driver with new features and improvements, including: + + * Added implicit mempool registration to avoid data path hiccups (opt-out). + Removed Items -------------
drivers/net/mlx5/linux/mlx5_mp_os.c +44 -0
56 lines not on this page · raw message
drivers/net/mlx5/linux/mlx5_os.c +2 -2
@@ -1034,8 +1034,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, err =mlx5_proc_priv_init (eth_dev);if (err)return NULL ; - mp_id.port_id = eth_dev->data->port_id; -strlcpy (mp_id.name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +mlx5_mp_id_init (&mp_id, eth_dev->data->port_id);/* Receive command fd from primary process */ err =mlx5_mp_req_verbs_cmd_fd (&mp_id);if (err <0 )
@@ -2133,6 +2132,7 @@ mlx5_os_config_default(struct mlx5_dev_config *config) config->txqs_inline =MLX5_ARG_UNSET ; config->vf_nl_en =1 ; config->mr_ext_memseg_en =1 ; + config->mr_mempool_reg_en =1 ; config->mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; config->mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; config->dv_esw_en =1 ;
drivers/net/mlx5/mlx5.c +152 -0
188 lines not on this page · raw message
drivers/net/mlx5/mlx5.h +10 -0
@@ -155,6 +155,13 @@ struct mlx5_flow_dump_ack {/** Key string for IPC. */ #define MLX5_MP_NAME "net_mlx5_mp" +/** Initialize a multi-process ID. */ +static inline void +mlx5_mp_id_init (struct mlx5_mp_id *mp_id,uint16_t port_id) +{ + mp_id->port_id = port_id; +strlcpy (mp_id->name,MLX5_MP_NAME ,RTE_MP_MAX_NAME_LEN ); +}LIST_HEAD (mlx5_dev_list, mlx5_dev_ctx_shared);
@@ -270,6 +277,8 @@ struct mlx5_dev_config { unsigned int dv_miss_info:1; /* restore packet after partial hw miss */ unsigned int allow_duplicate_pattern:1;/* Allow/Prevent the duplicate rules pattern. */ + unsigned int mr_mempool_reg_en:1; +/* Allow/prevent implicit mempool memory registration. */ struct {unsigned int enabled:1 ;/* Whether MPRQ is enabled. */ unsigned int stride_num_n;/* Number of strides. */
@@ -1498,6 +1507,7 @@ struct mlx5_dev_ctx_shared * mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, const struct mlx5_dev_config *config);void mlx5_free_shared_dev_ctx (struct mlx5_dev_ctx_shared *sh); +int mlx5_dev_ctx_shared_mempool_subscribe (struct rte_eth_dev *dev);void mlx5_free_table_hash_list (struct mlx5_priv *priv);int mlx5_alloc_table_hash_list (struct mlx5_priv *priv); void mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
drivers/net/mlx5/mlx5_mr.c +27 -93
138 lines not on this page · raw message
drivers/net/mlx5/mlx5_mr.h +0 -2
@@ -22,7 +22,5 @@void mlx5_mr_mem_event_cb (enum rte_mem_event event_type,const void *addr,size_t len,void *arg); -int mlx5_mr_update_mp (struct rte_eth_dev *dev,struct mlx5_mr_ctrl *mr_ctrl, -struct rte_mempool *mp);#endif /* RTE_PMD_MLX5_MR_H_ */
drivers/net/mlx5/mlx5_rx.h +14 -7
@@ -275,13 +275,11 @@ uint16_t mlx5_rx_burst_vec(void *dpdk_rxq, struct rte_mbuf **pkts,uint16_t mlx5_rx_burst_mprq_vec (void *dpdk_rxq,struct rte_mbuf **pkts,uint16_t pkts_n); -/* mlx5_mr.c */ - -uint32_t mlx5_rx_addr2mr_bh (struct mlx5_rxq_data *rxq,uintptr_t addr); +static int mlx5_rxq_mprq_enabled (struct mlx5_rxq_data *rxq);/** -* Query LKey from a packet buffer for Rx. No need to flush local caches for Rx -* as mempool is pre-configured and static. +* Query LKey from a packet buffer for Rx. No need to flush local caches +* as the Rx mempool database entries are valid for the lifetime of the queue. * * @param rxq * Pointer to Rx queue structure.
@@ -290,11 +288,14 @@ uint32_t mlx5_rx_addr2mr_bh(struct mlx5_rxq_data *rxq, uintptr_t addr);* * @return * Searched LKey on success, UINT32_MAX on no match. +* This function always succeeds on valid input. */ static __rte_always_inline uint32_tmlx5_rx_addr2mr (struct mlx5_rxq_data *rxq,uintptr_t addr) {struct mlx5_mr_ctrl *mr_ctrl = &rxq->mr_ctrl; +struct mlx5_rxq_ctrl *rxq_ctrl; +struct rte_mempool *mp;uint32_t lkey;/* Linear search on MR cache array. */
@@ -302,8 +303,14 @@ mlx5_rx_addr2mr(struct mlx5_rxq_data *rxq, uintptr_t addr) MLX5_MR_CACHE_N, addr);if (likely (lkey !=UINT32_MAX ))return lkey; -/* Take slower bottom-half (Binary Search) on miss. */ -return mlx5_rx_addr2mr_bh (rxq, addr); +/* +* Slower search in the mempool database on miss. +* During queue creation rxq->sh is not yet set, so we use rxq_ctrl. +*/ + rxq_ctrl = container_of(rxq, struct mlx5_rxq_ctrl, rxq); + mp =mlx5_rxq_mprq_enabled (rxq) ? rxq->mprq_mp : rxq->mp; +return mlx5_mr_mempool2mr_bh (&rxq_ctrl->priv->sh->share_cache, + mr_ctrl, mp, addr); }#define mlx5_rx_mb2mr (rxq, mb) mlx5_rx_addr2mr(rxq, (uintptr_t)((mb)->buf_addr))
drivers/net/mlx5/mlx5_rxq.c +13 -0
@@ -1162,6 +1162,7 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev)unsigned int strd_sz_n =0 ;unsigned int i;unsigned int n_ibv =0 ; +int ret;if (!mlx5_mprq_enabled (dev))return 0 ;
@@ -1241,6 +1242,16 @@ mlx5_mprq_alloc_mp(struct rte_eth_dev *dev) rte_errno =ENOMEM ;return -rte_errno; } + ret =mlx5_mr_mempool_register (&priv->sh->share_cache, priv->sh->pd, + mp, &priv->mp_id); +if (ret <0 && rte_errno !=EEXIST ) { + ret = rte_errno; +DRV_LOG (ERR ,"port %u failed to register a mempool for Multi-Packet RQ" , + dev->data->port_id); +rte_mempool_free (mp); + rte_errno = ret; +return -rte_errno; + } priv->mprq_mp = mp; exit:/* Set mempool for each Rx queue. */
@@ -1443,6 +1454,8 @@ mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,/* rte_errno is already set. */ goto error; } +/* Rx queues don't use this pointer, but we want a valid structure. */ + tmpl->rxq.mr_ctrl.dev_gen_ptr = &priv->sh->share_cache.dev_gen; tmpl->socket = socket;if (dev->data->dev_conf.intr_conf.rxq) tmpl->irq =1 ;
drivers/net/mlx5/mlx5_trigger.c +65 -12
95 lines not on this page · raw message
drivers/net/mlx5/windows/mlx5_os.c +1 -0
@@ -1116,6 +1116,7 @@ mlx5_os_net_probe(struct rte_device *dev) dev_config.txqs_inline =MLX5_ARG_UNSET ; dev_config.vf_nl_en =0 ; dev_config.mr_ext_memseg_en =1 ; + dev_config.mr_mempool_reg_en =1 ; dev_config.mprq.max_memcpy_len =MLX5_MPRQ_MEMCPY_DEFAULT_LEN ; dev_config.mprq.min_rxqs_num =MLX5_MPRQ_MIN_RXQS ; dev_config.dv_esw_en =0 ;
Signature · 1 line
2.25.1
Thomas Monjalon
AppliedQuoted 5 lines
Dmitry Kozlyuk (4):
mempool: add event callbacks
mempool: add non-IO flag
common/mlx5: add mempool registration facilities net/mlx5: support mempool registration
Applied, thanks