Use consecutive Tx queues' memory
A message that is not in the archive (sent off-list or not yet received): [email protected]
v5 cover Use consecutive Tx queues' memory
This patchset will move all the mlx5 Tx queues memory to a consecutive memory area. All the WQEBBs will be allocated based on the offset of this memory area.
---
v2:
1. add a new fix for legacy code of WQE calculation
2. fix the style
v3:
1. change the devarg and add description.
2. reorganize the code with different commits order.
v4:
1. fix building failure on Windows and OSes with different compilers
2. update the rst
3. addressing comments and fix bugs
v5:
1. solve one size_t coverity warning
---
Bing Zhao (5):
net/mlx5: add new devarg for Tx queue consecutive memory net/mlx5: calculate the memory length for all Tx queues net/mlx5: allocate and release unique resources for Tx queues net/mlx5: pass the information in Tx queue start net/mlx5: use consecutive memory for Tx queue creation
doc/guides/nics/mlx5.rst | 25 ++++ drivers/common/mlx5/mlx5_common_devx.c | 160 +++++++++++++++-------- drivers/common/mlx5/mlx5_common_devx.h | 2 + drivers/common/mlx5/mlx5_devx_cmds.h | 10 ++ drivers/net/mlx5/mlx5.c | 36 +++++ drivers/net/mlx5/mlx5.h | 15 ++- drivers/net/mlx5/mlx5_devx.c | 26 +++- drivers/net/mlx5/mlx5_trigger.c | 173 +++++++++++++++++++------ drivers/net/mlx5/mlx5_tx.h | 2 + drivers/net/mlx5/mlx5_txq.c | 67 +++++++++- 10 files changed, 418 insertions(+), 98 deletions(-)
Signature · 1 line
2.34.1
PATCH v5 1/5 net/mlx5: add new devarg for Tx queue consecutive memory
With this commit, a new device argument is introduced to control the memory allocation for Tx queues.
By default, without specifying any value. A default alignment with system page size will be used. All SQ / CQ memory of Tx queues will be allocated once and a single umem & MR will be used.
When setting to 0, the legacy way of per queue umem allocation will be selected in the following commit.
If the value is smaller than the system page size, the starting address alignment will be rounded up to the page size.
The value is a logarithm value based to 2. Refer to the rst file change for more details.
--- doc/guides/nics/mlx5.rst | 25 +++++++++++++++++++++++++ drivers/net/mlx5/mlx5.c | 36 ++++++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 7 ++++--- 3 files changed, 65 insertions(+), 3 deletions(-)
doc/guides/nics/mlx5.rst +25 -0
@@ -1682,6 +1682,31 @@ for an additional list of options shared with other mlx5 drivers. By default, the PMD will set this value to 1. +- ``txq_mem_algn`` parameter [int] + + A logarithm base 2 value for the memory starting address alignment + for Tx queues' WQ and associated CQ. + + Different CPU architectures and generations may have different cache systems. + The memory accessing order may impact the cache misses rate on different CPUs. + This devarg gives the ability to control the umem alignment for all TxQs without + rebuilding the application binary. + + The performance can be tuned by specifying this devarg after benchmark testing + on a specific system and hardware. + + By default, ``txq_mem_algn`` is set to log2(4K), or log2(64K) on some specific OS + distributions - based on the system page size configuration. + All Tx queues will use a unique memory region and umem area. Each TxQ will start at + an address right after the previous one except the 1st queue that will be aligned at + the given size of address boundary controlled by this devarg. + + If the value is less then the page size, it will be rounded up. + If it is bigger than the maximal queue size, a warning message will appear, there will + be some waste of memory at the beginning. + + 0 indicates legacy per queue memory allocation and separate Memory Regions (MR). + Multiport E-Switch ------------------
drivers/net/mlx5/mlx5.c +36 -0
@@ -185,6 +185,14 @@/* Device parameter to control representor matching in ingress/egress flows with HWS. */ #define MLX5_REPR_MATCHING_EN "repr_matching_en" +/* +* Alignment of the Tx queue starting address, +* If not set, using separate umem and MR for each TxQ. +* If set, using consecutive memory address and single MR for all Tx queues, each TxQ will start at +* the alignment specified. +*/ +#define MLX5_TXQ_MEM_ALGN "txq_mem_algn" +/* Shared memory between primary and secondary processes. */ struct mlx5_shared_data *mlx5_shared_data;
@@ -1447,6 +1455,8 @@ mlx5_dev_args_check_handler(const char *key, const char *val, void *opaque) config->cnt_svc.cycle_time = tmp; }else if (strcmp (MLX5_REPR_MATCHING_EN , key) ==0 ) { config->repr_matching = !!tmp; + }else if (strcmp (MLX5_TXQ_MEM_ALGN , key) ==0 ) { + config->txq_mem_algn = (uint32_t )tmp; }return 0 ; }
@@ -1486,9 +1496,17 @@ mlx5_shared_dev_ctx_args_config(struct mlx5_dev_ctx_shared *sh,MLX5_HWS_CNT_SERVICE_CORE ,MLX5_HWS_CNT_CYCLE_TIME ,MLX5_REPR_MATCHING_EN , +MLX5_TXQ_MEM_ALGN , NULL, };int ret =0 ; +size_t alignment =rte_mem_page_size (); +uint32_t max_queue_umem_size =MLX5_WQE_SIZE *mlx5_dev_get_max_wq_size (sh); + +if (alignment == (size_t )-1 ) { + alignment = (1 <<MLX5_LOG_PAGE_SIZE ); +DRV_LOG (WARNING ,"Failed to get page_size, using default %zu size." , alignment); + }/* Default configuration. */ memset (config,0 ,sizeof (*config));
@@ -1501,6 +1519,7 @@ mlx5_shared_dev_ctx_args_config(struct mlx5_dev_ctx_shared *sh, config->cnt_svc.cycle_time =MLX5_CNT_SVC_CYCLE_TIME_DEFAULT ; config->cnt_svc.service_core =rte_get_main_lcore (); config->repr_matching =1 ; + config->txq_mem_algn =log2above (alignment);if (mkvlist !=NULL ) {/* Process parameters. */ ret = mlx5_kvargs_process(mkvlist, params,
@@ -1567,6 +1586,16 @@ mlx5_shared_dev_ctx_args_config(struct mlx5_dev_ctx_shared *sh, config->hw_fcs_strip =0 ; else config->hw_fcs_strip = sh->dev_cap.hw_fcs_strip; +if (config->txq_mem_algn !=0 && config->txq_mem_algn <log2above (alignment)) { +DRV_LOG (WARNING , +"\"txq_mem_algn\" too small %u, round up to %u." , + config->txq_mem_algn,log2above (alignment)); + config->txq_mem_algn =log2above (alignment); + }else if (config->txq_mem_algn >log2above (max_queue_umem_size)) { +DRV_LOG (WARNING , +"\"txq_mem_algn\" with value %u bigger than %u." , + config->txq_mem_algn,log2above (max_queue_umem_size)); + }DRV_LOG (DEBUG ,"FCS stripping configuration is %ssupported" , (config->hw_fcs_strip ?"" :"not " ));DRV_LOG (DEBUG ,"\"tx_pp\" is %d." , config->tx_pp);
@@ -1584,6 +1613,7 @@ mlx5_shared_dev_ctx_args_config(struct mlx5_dev_ctx_shared *sh, config->allow_duplicate_pattern);DRV_LOG (DEBUG ,"\"fdb_def_rule_en\" is %u." , config->fdb_def_rule);DRV_LOG (DEBUG ,"\"repr_matching_en\" is %u." , config->repr_matching); +DRV_LOG (DEBUG ,"\"txq_mem_algn\" is %u." , config->txq_mem_algn);return 0 ; }
@@ -3151,6 +3181,12 @@ mlx5_probe_again_args_validate(struct mlx5_common_device *cdev, sh->ibdev_name); goto error; } +if (sh->config.txq_mem_algn != config->txq_mem_algn) { +DRV_LOG (ERR ,"\"TxQ memory alignment\" " +"configuration mismatch for shared %s context. %u - %u" , + sh->ibdev_name, sh->config.txq_mem_algn, config->txq_mem_algn); + goto error; + }mlx5_free (config);return 0 ; error:
drivers/net/mlx5/mlx5.h +4 -3
@@ -386,13 +386,14 @@ struct mlx5_sh_config { uint32_t hw_fcs_strip:1; /* FCS stripping is supported. */ uint32_t allow_duplicate_pattern:1; uint32_t lro_allowed:1; /* Whether LRO is allowed. */ +/* Allow/Prevent the duplicate rules pattern. */ + uint32_t fdb_def_rule:1; /* Create FDB default jump rule */ + uint32_t repr_matching:1; /* Enable implicit vport matching in HWS FDB. */ +uint32_t txq_mem_algn;/* logarithm value of the TxQ address alignment. */ struct {uint16_t service_core;uint32_t cycle_time;/* query cycle time in milli-second. */ } cnt_svc;/* configure for HW steering's counter's service. */ -/* Allow/Prevent the duplicate rules pattern. */ - uint32_t fdb_def_rule:1; /* Create FDB default jump rule */ - uint32_t repr_matching:1; /* Enable implicit vport matching in HWS FDB. */ };/* Structure for VF VLAN workaround. */
Signature · 1 line
2.34.1
PATCH v5 2/5 net/mlx5: calculate the memory length for all Tx queues
In reply to Bing ZhaoWhen the alignment is non-zero, it means that the single umem and MR allocation for all Tx queues will be used.
In this commit, the total length of SQs and associated CQs will be calculated and saved.
--- drivers/net/mlx5/mlx5.h | 4 +++ drivers/net/mlx5/mlx5_tx.h | 2 ++ drivers/net/mlx5/mlx5_txq.c | 67 +++++++++++++++++++++++++++++++++++-- 3 files changed, 71 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.h +4 -0
@@ -2138,6 +2138,10 @@ struct mlx5_priv {struct mlx5_nta_sample_ctx *nta_sample_ctx;#endif struct rte_eth_dev *shared_host;/* Host device for HW steering. */ +struct { +uint32_t sq_total_size; +uint32_t cq_total_size; + } consec_tx_mem;RTE_ATOMIC (uint16_t ) shared_refcnt;/* HW steering host reference counter. */ };
drivers/net/mlx5/mlx5_tx.h +2 -0
@@ -149,6 +149,7 @@ struct __rte_cache_aligned mlx5_txq_data {uint16_t inlen_mode;/* Minimal data length to inline. */ uint8_t tx_aggr_affinity;/* TxQ affinity configuration. */ uint32_t qp_num_8s;/* QP number shifted by 8. */ +uint32_t sq_mem_len;/* Length of TxQ for WQEs */ uint64_t offloads;/* Offloads for Tx Queue. */ struct mlx5_mr_ctrl mr_ctrl;/* MR control descriptor. */ struct mlx5_wqe *wqes;/* Work queue. */
@@ -167,6 +168,7 @@ struct __rte_cache_aligned mlx5_txq_data {uint64_t ts_mask;/* Timestamp flag dynamic mask. */ uint64_t ts_last;/* Last scheduled timestamp. */ int32_t ts_offset;/* Timestamp field dynamic offset. */ +uint32_t cq_mem_len;/* Length of TxQ for CQEs */ struct mlx5_dev_ctx_shared *sh;/* Shared context. */ struct mlx5_txq_stats stats;/* TX queue counters. */ struct mlx5_txq_stats stats_reset;/* stats on last reset. */
drivers/net/mlx5/mlx5_txq.c +65 -2
98 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v5 3/5 net/mlx5: allocate and release unique resources for Tx queues
In reply to Bing ZhaoIf the unique umem and MR method is enabled, before starting Tx queues in device start stage, the memory will be pre-allocated and the MR will be registered for the Tx queues' usage later.
--- drivers/net/mlx5/mlx5.h | 4 ++ drivers/net/mlx5/mlx5_trigger.c | 91 +++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+)
drivers/net/mlx5/mlx5.h +4 -0
@@ -2141,6 +2141,10 @@ struct mlx5_priv {struct {uint32_t sq_total_size;uint32_t cq_total_size; +void *umem; +void *umem_obj; +uint32_t sq_cur_off; +uint32_t cq_cur_off; } consec_tx_mem;RTE_ATOMIC (uint16_t ) shared_refcnt;/* HW steering host reference counter. */ };
drivers/net/mlx5/mlx5_trigger.c +91 -0
115 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v5 4/5 net/mlx5: pass the information in Tx queue start
In reply to Bing ZhaoThe actual Devx object of SQs and CQs are only created in the function mlx5_txq_start() in the device stage.
By changing the 1-level iteration to 2-level iterations, the Tx queue with a big number of queue depth will be set up firstly. This will help to split the memory from big trunks to small trunks.
In the testing, such assignment will help to improve the performance a little bit. All the doorbells will be grouped and padded at the end of the umem area.
The umem object and offsets information are passed to the Devx creation function for the further usage.
--- drivers/common/mlx5/mlx5_devx_cmds.h | 10 ++++ drivers/net/mlx5/mlx5_devx.c | 26 ++++++++- drivers/net/mlx5/mlx5_trigger.c | 82 +++++++++++++++------------- 3 files changed, 77 insertions(+), 41 deletions(-)
drivers/common/mlx5/mlx5_devx_cmds.h +10 -0
@@ -483,6 +483,11 @@ struct mlx5_devx_create_sq_attr { uint32_t packet_pacing_rate_limit_index:16; uint32_t tis_lst_sz:16; uint32_t tis_num:24; +uint32_t q_off; +void *umem; +void *umem_obj; +uint32_t q_len; +uint32_t db_off;struct mlx5_devx_wq_attr wq_attr; };
@@ -514,6 +519,11 @@ struct mlx5_devx_cq_attr {uint64_t db_umem_offset;uint32_t eqn;uint64_t db_addr; +void *umem; +void *umem_obj; +uint32_t q_off; +uint32_t q_len; +uint32_t db_off; };/* Virtq attributes structure, used by VIRTQ operations. */
drivers/net/mlx5/mlx5_devx.c +24 -2
@@ -1493,10 +1493,22 @@ mlx5_txq_create_devx_sq_resources(struct rte_eth_dev *dev, uint16_t idx, mlx5_ts_format_conv(cdev->config.hca_attr.sq_ts_format), .tis_num = mlx5_get_txq_tis_num(dev, idx), }; +uint32_t db_start = priv->consec_tx_mem.sq_total_size + priv->consec_tx_mem.cq_total_size; +int ret;/* Create Send Queue object with DevX. */ -return mlx5_devx_sq_create (cdev->ctx, &txq_obj->sq_obj, - log_desc_n, &sq_attr, priv->sh->numa_node); +if (priv->sh->config.txq_mem_algn) { + sq_attr.umem = priv->consec_tx_mem.umem; + sq_attr.umem_obj = priv->consec_tx_mem.umem_obj; + sq_attr.q_off = priv->consec_tx_mem.sq_cur_off; + sq_attr.db_off = db_start + (2 * idx) *MLX5_DBR_SIZE ; + sq_attr.q_len = txq_data->sq_mem_len; + } + ret =mlx5_devx_sq_create (cdev->ctx, &txq_obj->sq_obj, + log_desc_n, &sq_attr, priv->sh->numa_node); +if (!ret && priv->sh->config.txq_mem_algn) + priv->consec_tx_mem.sq_cur_off += txq_data->sq_mem_len; +return ret; }#endif
@@ -1536,6 +1548,7 @@ mlx5_txq_devx_obj_new(struct rte_eth_dev *dev, uint16_t idx)uint32_t cqe_n, log_desc_n;uint32_t wqe_n, wqe_size;int ret =0 ; +uint32_t db_start = priv->consec_tx_mem.sq_total_size + priv->consec_tx_mem.cq_total_size;MLX5_ASSERT (txq_data);MLX5_ASSERT (txq_obj);
@@ -1557,6 +1570,13 @@ mlx5_txq_devx_obj_new(struct rte_eth_dev *dev, uint16_t idx) rte_errno =EINVAL ;return 0 ; } +if (priv->sh->config.txq_mem_algn) { + cq_attr.umem = priv->consec_tx_mem.umem; + cq_attr.umem_obj = priv->consec_tx_mem.umem_obj; + cq_attr.q_off = priv->consec_tx_mem.cq_cur_off; + cq_attr.db_off = db_start + (2 * idx +1 ) *MLX5_DBR_SIZE ; + cq_attr.q_len = txq_data->cq_mem_len; + }/* Create completion queue object with DevX. */ ret =mlx5_devx_cq_create (sh->cdev->ctx, &txq_obj->cq_obj, log_desc_n, &cq_attr, priv->sh->numa_node);
@@ -1641,6 +1661,8 @@ mlx5_txq_devx_obj_new(struct rte_eth_dev *dev, uint16_t idx)#endif txq_ctrl->uar_mmap_offset =mlx5_os_get_devx_uar_mmap_offset (sh->tx_uar.obj); +if (priv->sh->config.txq_mem_algn) + priv->consec_tx_mem.cq_cur_off += txq_data->cq_mem_len; ppriv->uar_table[txq_data->idx] = sh->tx_uar.bf_db; dev->data->tx_queue_state[idx] =RTE_ETH_QUEUE_STATE_STARTED ;return 0 ;
drivers/net/mlx5/mlx5_trigger.c +43 -39
95 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v5 5/5 net/mlx5: use consecutive memory for Tx queue creation
In reply to Bing ZhaoThe queue starting addresses offsets of a umem and doorbell offsets are already passed to the Devx object creation function.
When the queue length is not zero, it means that the memory was pre-allocated and the new object creation with consecutive memory should be enabled.
When destroying the SQ / CQ objects, if it is in consecutive mode, the umem and MR should not be released and the global resources should only be released when stopping the device.
--- drivers/common/mlx5/mlx5_common_devx.c | 160 +++++++++++++++++-------- drivers/common/mlx5/mlx5_common_devx.h | 2 + 2 files changed, 110 insertions(+), 52 deletions(-)
drivers/common/mlx5/mlx5_common_devx.c +108 -52
@@ -30,6 +30,8 @@ mlx5_devx_cq_destroy(struct mlx5_devx_cq *cq) {if (cq->cq)claim_zero (mlx5_devx_cmd_destroy (cq->cq)); +if (cq->consec) +return ;if (cq->umem_obj)claim_zero (mlx5_os_umem_dereg (cq->umem_obj));if (cq->umem_buf)
@@ -93,6 +95,7 @@ mlx5_devx_cq_create(void *ctx, struct mlx5_devx_cq *cq_obj, uint16_t log_desc_n,uint32_t eqn;uint32_t num_of_cqes =RTE_BIT32 (log_desc_n);int ret; +uint32_t umem_offset, umem_id;if (page_size == (size_t )-1 || alignment == (size_t )-1 ) {DRV_LOG (ERR ,"Failed to get page_size." );
@@ -108,29 +111,44 @@ mlx5_devx_cq_create(void *ctx, struct mlx5_devx_cq *cq_obj, uint16_t log_desc_n, }/* Allocate memory buffer for CQEs and doorbell record. */ umem_size =sizeof (struct mlx5_cqe ) * num_of_cqes; - umem_dbrec =RTE_ALIGN (umem_size,MLX5_DBR_SIZE ); - umem_size +=MLX5_DBR_SIZE ; - umem_buf =mlx5_malloc_numa_tolerant (MLX5_MEM_RTE |MLX5_MEM_ZERO , umem_size, - alignment, socket); -if (!umem_buf) { -DRV_LOG (ERR ,"Failed to allocate memory for CQ." ); - rte_errno =ENOMEM ; -return -rte_errno; - } -/* Register allocated buffer in user space with DevX. */ - umem_obj =mlx5_os_umem_reg (ctx, (void *)(uintptr_t )umem_buf, umem_size, -IBV_ACCESS_LOCAL_WRITE ); -if (!umem_obj) { -DRV_LOG (ERR ,"Failed to register umem for CQ." ); - rte_errno = errno; - goto error; +if (!attr->q_len) { + umem_dbrec =RTE_ALIGN (umem_size,MLX5_DBR_SIZE ); + umem_size +=MLX5_DBR_SIZE ; + umem_buf =mlx5_malloc_numa_tolerant (MLX5_MEM_RTE |MLX5_MEM_ZERO , umem_size, + alignment, socket); +if (!umem_buf) { +DRV_LOG (ERR ,"Failed to allocate memory for CQ." ); + rte_errno =ENOMEM ; +return -rte_errno; + } +/* Register allocated buffer in user space with DevX. */ + umem_obj =mlx5_os_umem_reg (ctx, (void *)(uintptr_t )umem_buf, umem_size, +IBV_ACCESS_LOCAL_WRITE ); +if (!umem_obj) { +DRV_LOG (ERR ,"Failed to register umem for CQ." ); + rte_errno = errno; + goto error; + } + umem_offset =0 ; + umem_id =mlx5_os_get_umem_id (umem_obj); + }else { +if (umem_size != attr->q_len) { +DRV_LOG (ERR ,"Mismatch between saved length and calc length of CQ %u-%u" , + umem_size, attr->q_len); + rte_errno =EINVAL ; +return -rte_errno; + } + umem_buf = attr->umem; + umem_offset = attr->q_off; + umem_dbrec = attr->db_off; + umem_id =mlx5_os_get_umem_id (attr->umem_obj); }/* Fill attributes for CQ object creation. */ attr->q_umem_valid =1 ; - attr->q_umem_id =mlx5_os_get_umem_id (umem_obj); - attr->q_umem_offset =0 ; + attr->q_umem_id = umem_id; + attr->q_umem_offset = umem_offset; attr->db_umem_valid =1 ; - attr->db_umem_id = attr->q_umem_id; + attr->db_umem_id = umem_id; attr->db_umem_offset = umem_dbrec; attr->eqn = eqn; attr->log_cq_size = log_desc_n;
@@ -142,19 +160,29 @@ mlx5_devx_cq_create(void *ctx, struct mlx5_devx_cq *cq_obj, uint16_t log_desc_n, rte_errno =ENOMEM ; goto error; } - cq_obj->umem_buf = umem_buf; - cq_obj->umem_obj = umem_obj; +if (!attr->q_len) { + cq_obj->umem_buf = umem_buf; + cq_obj->umem_obj = umem_obj; + cq_obj->db_rec =RTE_PTR_ADD (cq_obj->umem_buf, umem_dbrec); + cq_obj->consec = false; + }else { + cq_obj->umem_buf =RTE_PTR_ADD (umem_buf, umem_offset); + cq_obj->umem_obj = attr->umem_obj; + cq_obj->db_rec =RTE_PTR_ADD (umem_buf, umem_dbrec); + cq_obj->consec = true; + } cq_obj->cq = cq; - cq_obj->db_rec =RTE_PTR_ADD (cq_obj->umem_buf, umem_dbrec);/* Mark all CQEs initially as invalid. */ mlx5_cq_init (cq_obj, num_of_cqes);return 0 ; error: ret = rte_errno; -if (umem_obj) -claim_zero (mlx5_os_umem_dereg (umem_obj)); -if (umem_buf) -mlx5_free ((void *)(uintptr_t )umem_buf); +if (!attr->q_len) { +if (umem_obj) +claim_zero (mlx5_os_umem_dereg (umem_obj)); +if (umem_buf) +mlx5_free ((void *)(uintptr_t )umem_buf); + } rte_errno = ret;return -rte_errno; }
@@ -171,6 +199,8 @@ mlx5_devx_sq_destroy(struct mlx5_devx_sq *sq) {if (sq->sq)claim_zero (mlx5_devx_cmd_destroy (sq->sq)); +if (sq->consec) +return ;if (sq->umem_obj)claim_zero (mlx5_os_umem_dereg (sq->umem_obj));if (sq->umem_buf)
@@ -220,6 +250,7 @@ mlx5_devx_sq_create(void *ctx, struct mlx5_devx_sq *sq_obj, uint16_t log_wqbb_n,uint32_t umem_size, umem_dbrec;uint32_t num_of_wqbbs =RTE_BIT32 (log_wqbb_n);int ret; +uint32_t umem_offset, umem_id;if (alignment == (size_t )-1 ) {DRV_LOG (ERR ,"Failed to get WQE buf alignment." );
@@ -228,30 +259,45 @@ mlx5_devx_sq_create(void *ctx, struct mlx5_devx_sq *sq_obj, uint16_t log_wqbb_n, }/* Allocate memory buffer for WQEs and doorbell record. */ umem_size =MLX5_WQE_SIZE * num_of_wqbbs; - umem_dbrec =RTE_ALIGN (umem_size,MLX5_DBR_SIZE ); - umem_size +=MLX5_DBR_SIZE ; - umem_buf =mlx5_malloc (MLX5_MEM_RTE |MLX5_MEM_ZERO , umem_size, - alignment, socket); -if (!umem_buf) { -DRV_LOG (ERR ,"Failed to allocate memory for SQ." ); - rte_errno =ENOMEM ; -return -rte_errno; - } -/* Register allocated buffer in user space with DevX. */ - umem_obj =mlx5_os_umem_reg (ctx, (void *)(uintptr_t )umem_buf, umem_size, -IBV_ACCESS_LOCAL_WRITE ); -if (!umem_obj) { -DRV_LOG (ERR ,"Failed to register umem for SQ." ); - rte_errno = errno; - goto error; +if (!attr->q_len) { + umem_dbrec =RTE_ALIGN (umem_size,MLX5_DBR_SIZE ); + umem_size +=MLX5_DBR_SIZE ; + umem_buf =mlx5_malloc (MLX5_MEM_RTE |MLX5_MEM_ZERO , umem_size, + alignment, socket); +if (!umem_buf) { +DRV_LOG (ERR ,"Failed to allocate memory for SQ." ); + rte_errno =ENOMEM ; +return -rte_errno; + } +/* Register allocated buffer in user space with DevX. */ + umem_obj =mlx5_os_umem_reg (ctx, (void *)(uintptr_t )umem_buf, umem_size, +IBV_ACCESS_LOCAL_WRITE ); +if (!umem_obj) { +DRV_LOG (ERR ,"Failed to register umem for SQ." ); + rte_errno = errno; + goto error; + } + umem_offset =0 ; + umem_id =mlx5_os_get_umem_id (umem_obj); + }else { +if (umem_size != attr->q_len) { +DRV_LOG (ERR ,"Mismatch between saved length and calc length of WQ %u-%u" , + umem_size, attr->q_len); + rte_errno =EINVAL ; +return -rte_errno; + } + umem_buf = attr->umem; + umem_offset = attr->q_off; + umem_dbrec = attr->db_off; + umem_id =mlx5_os_get_umem_id (attr->umem_obj); }/* Fill attributes for SQ object creation. */ attr->wq_attr.wq_type =MLX5_WQ_TYPE_CYCLIC ; attr->wq_attr.wq_umem_valid =1 ; - attr->wq_attr.wq_umem_id =mlx5_os_get_umem_id (umem_obj); - attr->wq_attr.wq_umem_offset =0 ; + attr->wq_attr.wq_umem_id = umem_id; + attr->wq_attr.wq_umem_offset = umem_offset; attr->wq_attr.dbr_umem_valid =1 ; - attr->wq_attr.dbr_umem_id = attr->wq_attr.wq_umem_id; + attr->wq_attr.dbr_umem_id = umem_id; attr->wq_attr.dbr_addr = umem_dbrec; attr->wq_attr.log_wq_stride =rte_log2_u32 (MLX5_WQE_SIZE ); attr->wq_attr.log_wq_sz = log_wqbb_n;
@@ -263,17 +309,27 @@ mlx5_devx_sq_create(void *ctx, struct mlx5_devx_sq *sq_obj, uint16_t log_wqbb_n, rte_errno =ENOMEM ; goto error; } - sq_obj->umem_buf = umem_buf; - sq_obj->umem_obj = umem_obj; +if (!attr->q_len) { + sq_obj->umem_buf = umem_buf; + sq_obj->umem_obj = umem_obj; + sq_obj->db_rec =RTE_PTR_ADD (sq_obj->umem_buf, umem_dbrec); + sq_obj->consec = false; + }else { + sq_obj->umem_buf =RTE_PTR_ADD (umem_buf, attr->q_off); + sq_obj->umem_obj = attr->umem_obj; + sq_obj->db_rec =RTE_PTR_ADD (umem_buf, attr->db_off); + sq_obj->consec = true; + } sq_obj->sq = sq; - sq_obj->db_rec =RTE_PTR_ADD (sq_obj->umem_buf, umem_dbrec);return 0 ; error: ret = rte_errno; -if (umem_obj) -claim_zero (mlx5_os_umem_dereg (umem_obj)); -if (umem_buf) -mlx5_free ((void *)(uintptr_t )umem_buf); +if (!attr->q_len) { +if (umem_obj) +claim_zero (mlx5_os_umem_dereg (umem_obj)); +if (umem_buf) +mlx5_free ((void *)(uintptr_t )umem_buf); + } rte_errno = ret;return -rte_errno; }
drivers/common/mlx5/mlx5_common_devx.h +2 -0
@@ -21,6 +21,7 @@ struct mlx5_devx_cq {volatile struct mlx5_cqe *cqes;/* The CQ ring buffer. */ };volatile uint32_t *db_rec;/* The CQ doorbell record. */ +bool consec;/* Using consecutive memory. */ };/* DevX Send Queue structure. */
@@ -33,6 +34,7 @@ struct mlx5_devx_sq {volatile struct mlx5_aso_wqe *aso_wqes; };volatile uint32_t *db_rec;/* The SQ doorbell record. */ +bool consec;/* Using consecutive memory. */ };/* DevX Queue Pair structure. */
Signature · 1 line
2.34.1
Thomas Monjalon
AppliedQuoted 6 lines
Bing Zhao (5):
net/mlx5: add new devarg for Tx queue consecutive memory net/mlx5: calculate the memory length for all Tx queues net/mlx5: allocate and release unique resources for Tx queues net/mlx5: pass the information in Tx queue start net/mlx5: use consecutive memory for Tx queue creation
Applied, thanks.