net/mlx5: use C11 atomic builtins
cover net/mlx5: use C11 atomic builtins
The rte_atomic API is deprecated and needs to be
replaced with C11 atomic builtins in MLX5 driver.
Alexander Kozyrev (4):
common/mlx5: use C11 atomics for memory allocation common/mlx5: use C11 atomics for netlink sequence net/mlx5: use C11 atomics for RxQ/TxQ refcounts net/mlx5: use C11 atomics for RTE flow tables
drivers/common/mlx5/linux/mlx5_nl.c | 5 +- drivers/common/mlx5/mlx5_malloc.c | 91 ++++++++--------- drivers/net/mlx5/linux/mlx5_ethdev_os.c | 1 - drivers/net/mlx5/mlx5.c | 9 +- drivers/net/mlx5/mlx5.h | 15 ++- drivers/net/mlx5/mlx5_ethdev.c | 1 - drivers/net/mlx5/mlx5_flow.h | 15 ++- drivers/net/mlx5/mlx5_flow_dv.c | 126 +++++++++++++----------- drivers/net/mlx5/mlx5_rxq.c | 28 +++--- drivers/net/mlx5/mlx5_txq.c | 8 +- 10 files changed, 153 insertions(+), 146 deletions(-)
Signature · 1 line
2.24.1
PATCH 1/4 common/mlx5: use C11 atomics for memory allocation
The rte_atomic API is deprecated and needs to be replaced with C11 atomic builtins. Use the relaxed ordering for mlx5 mallocs.
--- drivers/common/mlx5/mlx5_malloc.c | 91 ++++++++++++++++--------------- 1 file changed, 47 insertions(+), 44 deletions(-)
drivers/common/mlx5/mlx5_malloc.c +47 -44
@@ -8,8 +8,6 @@#include <stdbool.h> #include <string.h> -#include <rte_atomic.h> -#include "mlx5_common_utils.h" #include "mlx5_malloc.h"
@@ -17,27 +15,24 @@ struct mlx5_sys_mem { uint32_t init:1; /* Memory allocator initialized. */ uint32_t enable:1; /* System memory select. */ uint32_t reserve:30; /* Reserve. */ -union { -struct rte_memseg_list *last_msl; -rte_atomic64_t a64_last_msl; - }; +struct rte_memseg_list *last_msl;/* last allocated rte memory memseg list. */ #ifdef RTE_LIBRTE_MLX5_DEBUG -rte_atomic64_t malloc_sys; +uint64_t malloc_sys;/* Memory allocated from system count. */ -rte_atomic64_t malloc_rte; +uint64_t malloc_rte;/* Memory allocated from hugepage count. */ -rte_atomic64_t realloc_sys; +uint64_t realloc_sys;/* Memory reallocate from system count. */ -rte_atomic64_t realloc_rte; +uint64_t realloc_rte;/* Memory reallocate from hugepage count. */ -rte_atomic64_t free_sys; +uint64_t free_sys;/* Memory free to system count. */ -rte_atomic64_t free_rte; +uint64_t free_rte;/* Memory free to hugepage count. */ -rte_atomic64_t msl_miss; +uint64_t msl_miss;/* MSL miss count. */ -rte_atomic64_t msl_update; +uint64_t msl_update;/* MSL update count. */ #endif };
@@ -47,14 +42,14 @@ static struct mlx5_sys_mem mlx5_sys_mem = { .init = 0, .enable =0 , #ifdef RTE_LIBRTE_MLX5_DEBUG - .malloc_sys =RTE_ATOMIC64_INIT (0 ), - .malloc_rte = RTE_ATOMIC64_INIT(0), - .realloc_sys = RTE_ATOMIC64_INIT(0), - .realloc_rte = RTE_ATOMIC64_INIT(0), - .free_sys = RTE_ATOMIC64_INIT(0), - .free_rte = RTE_ATOMIC64_INIT(0), - .msl_miss = RTE_ATOMIC64_INIT(0), - .msl_update = RTE_ATOMIC64_INIT(0), + .malloc_sys =0 , + .malloc_rte = 0, + .realloc_sys = 0, + .realloc_rte = 0, + .free_sys = 0, + .free_rte = 0, + .msl_miss = 0, + .msl_update = 0, #endif };
@@ -97,12 +92,14 @@ mlx5_mem_update_msl(void *addr)* different with the cached msl. */ if (addr && !mlx5_mem_check_msl (addr, - (struct rte_memseg_list *)(uintptr_t )rte_atomic64_read - (&mlx5_sys_mem.a64_last_msl))) { -rte_atomic64_set (&mlx5_sys_mem.a64_last_msl, - (int64_t )(uintptr_t )rte_mem_virt2memseg_list (addr)); + (struct rte_memseg_list *)__atomic_load_n + (&mlx5_sys_mem.last_msl, __ATOMIC_RELAXED))) { +__atomic_store_n (&mlx5_sys_mem.last_msl, +rte_mem_virt2memseg_list (addr), + __ATOMIC_RELAXED);#ifdef RTE_LIBRTE_MLX5_DEBUG -rte_atomic64_inc (&mlx5_sys_mem.msl_update); +__atomic_add_fetch (&mlx5_sys_mem.msl_update,1 , + __ATOMIC_RELAXED);#endif } }
@@ -123,12 +120,12 @@ mlx5_mem_is_rte(void *addr)* Check if the last cache msl matches. Drop to slow path * to check if the memory belongs to rte memory. */ -if (!mlx5_mem_check_msl (addr, (struct rte_memseg_list *)(uintptr_t ) -rte_atomic64_read (&mlx5_sys_mem.a64_last_msl))) { +if (!mlx5_mem_check_msl (addr, (struct rte_memseg_list *) +__atomic_load_n (&mlx5_sys_mem.last_msl, __ATOMIC_RELAXED))) {if (!rte_mem_virt2memseg_list (addr))return false;#ifdef RTE_LIBRTE_MLX5_DEBUG -rte_atomic64_inc (&mlx5_sys_mem.msl_miss); +__atomic_add_fetch (&mlx5_sys_mem.msl_miss,1 , __ATOMIC_RELAXED);#endif }return true;
@@ -190,7 +187,8 @@ mlx5_malloc(uint32_t flags, size_t size, unsigned int align, int socket)mlx5_mem_update_msl (addr);#ifdef RTE_LIBRTE_MLX5_DEBUG if (addr) -rte_atomic64_inc (&mlx5_sys_mem.malloc_rte); +__atomic_add_fetch (&mlx5_sys_mem->malloc_rte,1 , + __ATOMIC_RELAXED);#endif return addr; }
@@ -203,7 +201,8 @@ mlx5_malloc(uint32_t flags, size_t size, unsigned int align, int socket) addr =malloc (size);#ifdef RTE_LIBRTE_MLX5_DEBUG if (addr) -rte_atomic64_inc (&mlx5_sys_mem.malloc_sys); +__atomic_add_fetch (&mlx5_sys_mem->malloc_sys,1 , + __ATOMIC_RELAXED);#endif return addr; }
@@ -236,7 +235,8 @@ mlx5_realloc(void *addr, uint32_t flags, size_t size, unsigned int align,mlx5_mem_update_msl (new_addr);#ifdef RTE_LIBRTE_MLX5_DEBUG if (new_addr) -rte_atomic64_inc (&mlx5_sys_mem.realloc_rte); +__atomic_add_fetch (&mlx5_sys_mem->realloc_rte,1 , + __ATOMIC_RELAXED);#endif return new_addr; }
@@ -248,7 +248,8 @@ mlx5_realloc(void *addr, uint32_t flags, size_t size, unsigned int align, new_addr =realloc (addr, size);#ifdef RTE_LIBRTE_MLX5_DEBUG if (new_addr) -rte_atomic64_inc (&mlx5_sys_mem.realloc_sys); +__atomic_add_fetch (&mlx5_sys_mem->realloc_sys,1 , + __ATOMIC_RELAXED);#endif return new_addr; }
@@ -260,12 +261,14 @@ mlx5_free(void *addr)return ;if (!mlx5_mem_is_rte (addr)) {#ifdef RTE_LIBRTE_MLX5_DEBUG -rte_atomic64_inc (&mlx5_sys_mem.free_sys); +__atomic_add_fetch (&mlx5_sys_mem->free_sys,1 , + __ATOMIC_RELAXED);#endif free (addr); }else {#ifdef RTE_LIBRTE_MLX5_DEBUG -rte_atomic64_inc (&mlx5_sys_mem.free_rte); +__atomic_add_fetch (&mlx5_sys_mem->free_rte,1 , + __ATOMIC_RELAXED);#endif rte_free (addr); }
@@ -279,14 +282,14 @@ mlx5_memory_stat_dump(void)" free:%" PRIi64"\nRTE memory malloc:%" PRIi64"," " realloc:%" PRIi64", free:%" PRIi64"\nMSL miss:%" PRIi64"," " update:%" PRIi64"" , -rte_atomic64_read (&mlx5_sys_mem.malloc_sys), -rte_atomic64_read (&mlx5_sys_mem.realloc_sys), -rte_atomic64_read (&mlx5_sys_mem.free_sys), -rte_atomic64_read (&mlx5_sys_mem.malloc_rte), -rte_atomic64_read (&mlx5_sys_mem.realloc_rte), -rte_atomic64_read (&mlx5_sys_mem.free_rte), -rte_atomic64_read (&mlx5_sys_mem.msl_miss), - rte_atomic64_read(&mlx5_sys_mem.msl_update)); +__atomic_load_n (&mlx5_sys_mem.malloc_sys, __ATOMIC_RELAXED), +__atomic_load_n (&mlx5_sys_mem.realloc_sys, __ATOMIC_RELAXED), +__atomic_load_n (&mlx5_sys_mem.free_sys, __ATOMIC_RELAXED), +__atomic_load_n (&mlx5_sys_mem.malloc_rte, __ATOMIC_RELAXED), +__atomic_load_n (&mlx5_sys_mem.realloc_rte, __ATOMIC_RELAXED), +__atomic_load_n (&mlx5_sys_mem.free_rte, __ATOMIC_RELAXED), +__atomic_load_n (&mlx5_sys_mem.msl_miss, __ATOMIC_RELAXED), + __atomic_load_n(&mlx5_sys_mem.msl_update, __ATOMIC_RELAXED));#endif }
Signature · 1 line
2.24.1
PATCH 2/4 common/mlx5: use C11 atomics for netlink sequence
In reply to Alexander KozyrevThe rte_atomic API is deprecated and needs to be replaced with C11 atomic builtins. Use __atomic_add_fetch instead of rte_atomic32_add_return to generate a Netlink sequence number.
--- drivers/common/mlx5/linux/mlx5_nl.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/common/mlx5/linux/mlx5_nl.c +2 -3
@@ -18,7 +18,6 @@#include <unistd.h> #include <rte_errno.h> -#include <rte_atomic.h> #include "mlx5_nl.h" #include "mlx5_common_utils.h"
@@ -169,10 +168,10 @@ struct mlx5_nl_ifindex_data {uint32_t portnum;/**< IB device max port number (out). */ }; -rte_atomic32_t atomic_sn =RTE_ATOMIC32_INIT (0 ); +uint32_t atomic_sn;/* Generate Netlink sequence number. */ -#define MLX5_NL_SN_GENERATE ((uint32_t)rte_atomic32_add_return(&atomic_sn, 1)) +#define MLX5_NL_SN_GENERATE __atomic_add_fetch(&atomic_sn, 1, __ATOMIC_RELAXED)/** * Opens a Netlink socket.
Signature · 1 line
2.24.1
PATCH 3/4 net/mlx5: use C11 atomics for RxQ/TxQ refcounts
In reply to Alexander KozyrevThe rte_atomic API is deprecated and needs to be replaced with C11 atomic builtins. Use the relaxed ordering for RxQ/TxQ refcounts.
--- drivers/net/mlx5/linux/mlx5_ethdev_os.c | 1 - drivers/net/mlx5/mlx5.c | 9 +++----- drivers/net/mlx5/mlx5.h | 6 +++--- drivers/net/mlx5/mlx5_ethdev.c | 1 - drivers/net/mlx5/mlx5_flow_dv.c | 3 ++- drivers/net/mlx5/mlx5_rxq.c | 28 ++++++++++++------------- drivers/net/mlx5/mlx5_txq.c | 8 +++---- 7 files changed, 26 insertions(+), 30 deletions(-)
drivers/net/mlx5/linux/mlx5_ethdev_os.c +0 -1
@@ -24,7 +24,6 @@#include <sys/un.h> #include <time.h> -#include <rte_atomic.h> #include <rte_ethdev_driver.h> #include <rte_bus_pci.h> #include <rte_mbuf.h>
drivers/net/mlx5/mlx5.c +3 -6
@@ -1232,8 +1232,7 @@ mlx5_alloc_table_hash_list(struct mlx5_priv *priv) err =mlx5_hlist_insert (sh->flow_tbls, &tbl_data->entry);if (err) goto error; -rte_atomic32_init (&tbl_data->tbl.refcnt); -rte_atomic32_inc (&tbl_data->tbl.refcnt); +__atomic_store_n (&tbl_data->tbl.refcnt,1 , __ATOMIC_RELAXED); table_key.direction =1 ; tbl_data =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*tbl_data),0 ,SOCKET_ID_ANY );
@@ -1245,8 +1244,7 @@ mlx5_alloc_table_hash_list(struct mlx5_priv *priv) err =mlx5_hlist_insert (sh->flow_tbls, &tbl_data->entry);if (err) goto error; -rte_atomic32_init (&tbl_data->tbl.refcnt); -rte_atomic32_inc (&tbl_data->tbl.refcnt); +__atomic_store_n (&tbl_data->tbl.refcnt,1 , __ATOMIC_RELAXED); table_key.direction =0 ; table_key.domain =1 ; tbl_data = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*tbl_data), 0,
@@ -1259,8 +1257,7 @@ mlx5_alloc_table_hash_list(struct mlx5_priv *priv) err =mlx5_hlist_insert (sh->flow_tbls, &tbl_data->entry);if (err) goto error; -rte_atomic32_init (&tbl_data->tbl.refcnt); -rte_atomic32_inc (&tbl_data->tbl.refcnt); +__atomic_store_n (&tbl_data->tbl.refcnt,1 , __ATOMIC_RELAXED);return err; error:mlx5_free_table_hash_list (priv);
drivers/net/mlx5/mlx5.h +3 -3
@@ -719,7 +719,7 @@ struct mlx5_rxq_obj {/* Indirection table. */ struct mlx5_ind_table_obj { LIST_ENTRY(mlx5_ind_table_obj) next; /* Pointer to the next element. */ - rte_atomic32_t refcnt; /* Reference counter. */ + uint32_t refcnt; /* Reference counter. */ RTE_STD_C11 union { void *ind_table; /**< Indirection table. */
@@ -733,7 +733,7 @@ struct mlx5_ind_table_obj { __extension__ struct mlx5_hrxq { ILIST_ENTRY(uint32_t)next; /* Index to the next element. */ - rte_atomic32_t refcnt; /* Reference counter. */ + uint32_t refcnt; /* Reference counter. */ uint32_t shared:1; /* This object used in shared action. */ struct mlx5_ind_table_obj *ind_table; /* Indirection table. */ RTE_STD_C11
@@ -872,7 +872,7 @@ struct mlx5_priv {/* Indirection tables. */ LIST_HEAD(ind_tables, mlx5_ind_table_obj) ind_tbls;/* Pointer to next element. */ -rte_atomic32_t refcnt;/**< Reference counter. */ +uint32_t refcnt;/**< Reference counter. */ /**< Verbs modify header action object. */ uint8_t ft_type;/**< Flow table type, Rx or Tx. */ uint8_t max_lro_msg_size;
drivers/net/mlx5/mlx5_ethdev.c +0 -1
@@ -10,7 +10,6 @@#include <stdlib.h> #include <errno.h> -#include <rte_atomic.h> #include <rte_ethdev_driver.h> #include <rte_bus_pci.h> #include <rte_mbuf.h>
drivers/net/mlx5/mlx5_flow_dv.c +2 -1
@@ -10283,7 +10283,8 @@ __flow_dv_rss_get_hrxq(struct rte_eth_dev *dev, struct rte_flow *flow,if (hrxq_idx) { *hrxq =mlx5_ipool_get (priv->sh->ipool[MLX5_IPOOL_HRXQ ], hrxq_idx); -rte_atomic32_inc (&(*hrxq)->refcnt); +__atomic_fetch_add (&(*hrxq)->refcnt,1 , + __ATOMIC_RELAXED); } }else { struct mlx5_flow_rss_desc *rss_desc =
drivers/net/mlx5/mlx5_rxq.c +14 -14
@@ -461,7 +461,6 @@ mlx5_rxq_releasable(struct rte_eth_dev *dev, uint16_t idx) } rxq_ctrl = container_of((*priv->rxqs)[idx], struct mlx5_rxq_ctrl, rxq);return (__atomic_load_n (&rxq_ctrl->refcnt, __ATOMIC_RELAXED) ==1 ); - }/* Fetches and drops all SW-owned and error CQEs to synchronize CQ. */
@@ -1669,7 +1668,7 @@ mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, tmpl->rxq.uar_lock_cq = &priv->sh->uar_lock_cq;#endif tmpl->rxq.idx = idx; -__atomic_add_fetch (&tmpl->refcnt,1 , __ATOMIC_RELAXED); +__atomic_fetch_add (&tmpl->refcnt,1 , __ATOMIC_RELAXED);LIST_INSERT_HEAD (&priv->rxqsctrl, tmpl, next);return tmpl; error:
@@ -1716,7 +1715,7 @@ mlx5_rxq_hairpin_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, tmpl->rxq.mr_ctrl.cache_bh = (struct mlx5_mr_btree ) {0 }; tmpl->hairpin_conf = *hairpin_conf; tmpl->rxq.idx = idx; -__atomic_add_fetch (&tmpl->refcnt,1 , __ATOMIC_RELAXED); +__atomic_fetch_add (&tmpl->refcnt,1 , __ATOMIC_RELAXED);LIST_INSERT_HEAD (&priv->rxqsctrl, tmpl, next);return tmpl; }
@@ -1741,7 +1740,7 @@ mlx5_rxq_get(struct rte_eth_dev *dev, uint16_t idx)if (rxq_data) { rxq_ctrl = container_of(rxq_data, struct mlx5_rxq_ctrl, rxq); -__atomic_add_fetch (&rxq_ctrl->refcnt,1 , __ATOMIC_RELAXED); +__atomic_fetch_add (&rxq_ctrl->refcnt,1 , __ATOMIC_RELAXED); }return rxq_ctrl; }
@@ -1916,7 +1915,7 @@ mlx5_ind_table_obj_get(struct rte_eth_dev *dev, const uint16_t *queues,if (ind_tbl) {unsigned int i; -rte_atomic32_inc (&ind_tbl->refcnt); +__atomic_fetch_add (&ind_tbl->refcnt,1 , __ATOMIC_RELAXED);for (i =0 ; i != ind_tbl->queues_n; ++i)mlx5_rxq_get (dev, ind_tbl->queues[i]); }
@@ -1941,11 +1940,11 @@ mlx5_ind_table_obj_release(struct rte_eth_dev *dev,struct mlx5_priv *priv = dev->data->dev_private;unsigned int i; -if (rte_atomic32_dec_and_test (&ind_tbl->refcnt)) +if (__atomic_sub_fetch (&ind_tbl->refcnt,1 , __ATOMIC_RELAXED) ==0 ) priv->obj_ops.ind_table_destroy (ind_tbl);for (i =0 ; i != ind_tbl->queues_n; ++i)claim_nonzero (mlx5_rxq_release (dev, ind_tbl->queues[i])); -if (!rte_atomic32_read (&ind_tbl->refcnt)) { +if (__atomic_load_n (&ind_tbl->refcnt, __ATOMIC_RELAXED) ==0 ) {LIST_REMOVE (ind_tbl, next);mlx5_free (ind_tbl);return 0 ;
@@ -2019,7 +2018,7 @@ mlx5_ind_table_obj_new(struct rte_eth_dev *dev, const uint16_t *queues, ret = priv->obj_ops.ind_table_new (dev, n, ind_tbl);if (ret <0 ) goto error; -rte_atomic32_inc (&ind_tbl->refcnt); +__atomic_fetch_add (&ind_tbl->refcnt,1 , __ATOMIC_RELAXED);LIST_INSERT_HEAD (&priv->ind_tbls, ind_tbl, next);return ind_tbl; error:
@@ -2078,7 +2077,7 @@ mlx5_hrxq_get(struct rte_eth_dev *dev,mlx5_ind_table_obj_release (dev, ind_tbl);continue ; } -rte_atomic32_inc (&hrxq->refcnt); +__atomic_fetch_add (&hrxq->refcnt,1 , __ATOMIC_RELAXED);return idx; }return 0 ;
@@ -2184,7 +2183,7 @@ mlx5_hrxq_release(struct rte_eth_dev *dev, uint32_t hrxq_idx) hrxq =mlx5_ipool_get (priv->sh->ipool[MLX5_IPOOL_HRXQ ], hrxq_idx);if (!hrxq)return 0 ; -if (rte_atomic32_dec_and_test (&hrxq->refcnt)) { +if (__atomic_sub_fetch (&hrxq->refcnt,1 , __ATOMIC_RELAXED) ==0 ) {#ifdef HAVE_IBV_FLOW_DV_SUPPORT mlx5_glue->destroy_flow_action (hrxq->action);#endif
@@ -2257,7 +2256,7 @@ mlx5_hrxq_new(struct rte_eth_dev *dev, rte_errno = errno; goto error; } -rte_atomic32_inc (&hrxq->refcnt); +__atomic_fetch_add (&hrxq->refcnt,1 , __ATOMIC_RELAXED);ILIST_INSERT (priv->sh->ipool[MLX5_IPOOL_HRXQ ], &priv->hrxqs, hrxq_idx, hrxq, next);return hrxq_idx;
@@ -2287,7 +2286,8 @@ mlx5_drop_action_create(struct rte_eth_dev *dev)int ret;if (priv->drop_queue.hrxq) { -rte_atomic32_inc (&priv->drop_queue.hrxq->refcnt); +__atomic_fetch_add (&priv->drop_queue.hrxq->refcnt,1 , + __ATOMIC_RELAXED);return priv->drop_queue.hrxq; } hrxq =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (*hrxq),0 ,SOCKET_ID_ANY );
@@ -2308,7 +2308,7 @@ mlx5_drop_action_create(struct rte_eth_dev *dev) ret = priv->obj_ops.drop_action_create (dev);if (ret <0 ) goto error; -rte_atomic32_set (&hrxq->refcnt,1 ); +__atomic_store_n (&hrxq->refcnt,1 , __ATOMIC_RELAXED);return hrxq; error:if (hrxq) {
@@ -2332,7 +2332,7 @@ mlx5_drop_action_destroy(struct rte_eth_dev *dev)struct mlx5_priv *priv = dev->data->dev_private;struct mlx5_hrxq *hrxq = priv->drop_queue.hrxq; -if (rte_atomic32_dec_and_test (&hrxq->refcnt)) { +if (__atomic_sub_fetch (&hrxq->refcnt,1 , __ATOMIC_RELAXED) ==0 ) { priv->obj_ops.drop_action_destroy (dev);mlx5_free (priv->drop_queue.rxq);mlx5_free (hrxq->ind_table);
drivers/net/mlx5/mlx5_txq.c +4 -4
@@ -1141,7 +1141,7 @@ mlx5_txq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, rte_errno =ENOMEM ; goto error; } -__atomic_add_fetch (&tmpl->refcnt,1 , __ATOMIC_RELAXED); +__atomic_fetch_add (&tmpl->refcnt,1 , __ATOMIC_RELAXED); tmpl->type =MLX5_TXQ_TYPE_STANDARD ;LIST_INSERT_HEAD (&priv->txqsctrl, tmpl, next);return tmpl;
@@ -1185,7 +1185,7 @@ mlx5_txq_hairpin_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, tmpl->txq.idx = idx; tmpl->hairpin_conf = *hairpin_conf; tmpl->type =MLX5_TXQ_TYPE_HAIRPIN ; -__atomic_add_fetch (&tmpl->refcnt,1 , __ATOMIC_RELAXED); +__atomic_fetch_add (&tmpl->refcnt,1 , __ATOMIC_RELAXED);LIST_INSERT_HEAD (&priv->txqsctrl, tmpl, next);return tmpl; }
@@ -1210,7 +1210,7 @@ mlx5_txq_get(struct rte_eth_dev *dev, uint16_t idx)if (txq_data) { ctrl = container_of(txq_data, struct mlx5_txq_ctrl, txq); -__atomic_add_fetch (&ctrl->refcnt,1 , __ATOMIC_RELAXED); +__atomic_fetch_add (&ctrl->refcnt,1 , __ATOMIC_RELAXED); }return ctrl; }
@@ -1235,7 +1235,7 @@ mlx5_txq_release(struct rte_eth_dev *dev, uint16_t idx)if (!(*priv->txqs)[idx])return 0 ; txq_ctrl = container_of((*priv->txqs)[idx], struct mlx5_txq_ctrl, txq); -if (__atomic_sub_fetch (&txq_ctrl->refcnt,1 , __ATOMIC_RELAXED) >1 ) +if (__atomic_sub_fetch (&txq_ctrl->refcnt,1 , __ATOMIC_RELAXED) !=0 )return 1 ;if (txq_ctrl->obj) { priv->obj_ops.txq_obj_release (txq_ctrl->obj);
Signature · 1 line
2.24.1
PATCH 4/4 net/mlx5: use C11 atomics for RTE flow tables
In reply to Alexander KozyrevThe rte_atomic API is deprecated and needs to be replaced with C11 atomic builtins. Use the relaxed ordering for RTE flow tables. Enforce Acquire/Release model for managing DevX pools.
--- drivers/net/mlx5/mlx5.h | 9 +-- drivers/net/mlx5/mlx5_flow.h | 15 ++-- drivers/net/mlx5/mlx5_flow_dv.c | 123 ++++++++++++++++++-------------- 3 files changed, 78 insertions(+), 69 deletions(-)
drivers/net/mlx5/mlx5.h +3 -6
@@ -402,10 +402,7 @@ TAILQ_HEAD(mlx5_counters, mlx5_flow_counter);struct mlx5_flow_counter_pool {TAILQ_ENTRY (mlx5_flow_counter_pool) next;struct mlx5_counters counters[2 ];/* Free counter list. */ -union { -struct mlx5_devx_obj *min_dcs; -rte_atomic64_t a64_dcs; - }; +struct mlx5_devx_obj *min_dcs;/* The devx object of the minimum counter ID. */ uint64_t time_of_last_age_check;/* System time (from rte_rdtsc()) read in the last aging check. */
@@ -464,7 +461,7 @@ struct mlx5_flow_counter_mng {/* Default miss action resource structure. */ struct mlx5_flow_default_miss_resource {void *action;/* Pointer to the rdma-core action. */ -rte_atomic32_t refcnt;/* Default miss action reference counter. */ +uint32_t refcnt;/* Default miss action reference counter. */ };#define MLX5_AGE_EVENT_NEW 1
@@ -515,7 +512,7 @@ union mlx5_flow_tbl_key {/* Table structure. */ struct mlx5_flow_tbl_resource {void *obj;/**< Pointer to DR table object. */ -rte_atomic32_t refcnt;/**< Reference counter. */ +uint32_t refcnt;/**< Reference counter. */ };#define MLX5_MAX_TABLES UINT16_MAX
drivers/net/mlx5/mlx5_flow.h +7 -8
@@ -11,7 +11,6 @@#include <stdint.h> #include <string.h> -#include <rte_atomic.h> #include <rte_alarm.h> #include <rte_mtr.h>
@@ -396,7 +395,7 @@ struct mlx5_flow_dv_matcher {/**< Pointer to the next element. */ struct mlx5_flow_tbl_resource *tbl;/**< Pointer to the table(group) the matcher associated with. */ -rte_atomic32_t refcnt;/**< Reference counter. */ +uint32_t refcnt;/**< Reference counter. */ void *matcher_object;/**< Pointer to DV matcher */ uint16_t crc;/**< CRC of key. */ uint16_t priority;/**< Priority of matcher. */
@@ -421,7 +420,7 @@ union mlx5_flow_encap_decap_key {struct mlx5_flow_dv_encap_decap_resource {struct mlx5_hlist_entry entry;/* Pointer to next element. */ -rte_atomic32_t refcnt;/**< Reference counter. */ +uint32_t refcnt;/**< Reference counter. */ void *action;/**< Encap/decap action object. */ uint8_t buf[MLX5_ENCAP_MAX_LEN ];
@@ -438,7 +437,7 @@ struct mlx5_flow_dv_tag_resource {/**< hash list entry for tag resource, tag value as the key. */ void *action;/**< Tag action object. */ -rte_atomic32_t refcnt;/**< Reference counter. */ +uint32_t refcnt;/**< Reference counter. */ uint32_t idx;/**< Index for the index memory pool. */ };
@@ -459,7 +458,7 @@ struct mlx5_flow_dv_tag_resource {struct mlx5_flow_dv_modify_hdr_resource {struct mlx5_hlist_entry entry;/* Pointer to next element. */ -rte_atomic32_t refcnt;/**< Reference counter. */ +uint32_t refcnt;/**< Reference counter. */ void *action;/**< Modify header action object. */ uint8_t ft_type;/**< Flow table type, Rx or Tx. */
@@ -482,7 +481,7 @@ union mlx5_flow_modify_hdr_key {/* Jump action resource structure. */ struct mlx5_flow_dv_jump_tbl_resource { -rte_atomic32_t refcnt;/**< Reference counter. */ +uint32_t refcnt;/**< Reference counter. */ uint8_t ft_type;/**< Flow table type, Rx or Tx. */ void *action;/**< Pointer to the rdma core action. */ };
@@ -491,7 +490,7 @@ struct mlx5_flow_dv_jump_tbl_resource {struct mlx5_flow_dv_port_id_action_resource {ILIST_ENTRY (uint32_t )next;/* Pointer to next element. */ -rte_atomic32_t refcnt;/**< Reference counter. */ +uint32_t refcnt;/**< Reference counter. */ void *action;/**< Action object. */ uint32_t port_id;/**< Port ID value. */
@@ -501,7 +500,7 @@ struct mlx5_flow_dv_port_id_action_resource {struct mlx5_flow_dv_push_vlan_action_resource {ILIST_ENTRY (uint32_t )next;/* Pointer to next element. */ -rte_atomic32_t refcnt;/**< Reference counter. */ +uint32_t refcnt;/**< Reference counter. */ void *action;/**< Action object. */ uint8_t ft_type;/**< Flow table type, Rx, Tx or FDB. */ rte_be32_t vlan_tag;/**< VLAN tag value. */
drivers/net/mlx5/mlx5_flow_dv.c +68 -55
333 lines not on this page · raw message
Signature · 1 line
2.24.1
Hi,
Quoted 29 lines
-----Original Message-----
From: Alexander Kozyrev <[email protected]>
Sent: Tuesday, October 27, 2020 5:28 PM
To: [email protected]
Cc: Raslan Darawsheh <[email protected]>; Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>
Subject: [PATCH 0/4] net/mlx5: use C11 atomic builtinsThe
rte_atomicAPI is deprecated and needs to be
replaced with C11 atomic builtins in MLX5 driver.Alexander Kozyrev (4):
common/mlx5: use C11 atomics for memory allocation common/mlx5: use C11 atomics for netlink sequence net/mlx5: use C11 atomics for RxQ/TxQ refcounts net/mlx5: use C11 atomics for RTE flow tablesdrivers/common/mlx5/linux/mlx5_nl.c | 5 +- drivers/common/mlx5/mlx5_malloc.c | 91 ++++++++--------- drivers/net/mlx5/linux/mlx5_ethdev_os.c | 1 - drivers/net/mlx5/mlx5.c | 9 +- drivers/net/mlx5/mlx5.h | 15 ++- drivers/net/mlx5/mlx5_ethdev.c | 1 - drivers/net/mlx5/mlx5_flow.h | 15 ++- drivers/net/mlx5/mlx5_flow_dv.c | 126 +++++++++++++----------- drivers/net/mlx5/mlx5_rxq.c | 28 +++--- drivers/net/mlx5/mlx5_txq.c | 8 +- 10 files changed, 153 insertions(+), 146 deletions(-)
Quoted 2 lines
--
2.24.1
Series applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh