From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6AABFA04BB; Tue, 6 Oct 2020 13:40:11 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F03034C93; Tue, 6 Oct 2020 13:39:11 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 8FF0F25B3 for ; Tue, 6 Oct 2020 13:39:05 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from suanmingm@nvidia.com) with SMTP; 6 Oct 2020 14:38:59 +0300 Received: from nvidia.com (mtbc-r640-04.mtbc.labs.mlnx [10.75.70.9]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 096BcuYM014182; Tue, 6 Oct 2020 14:38:58 +0300 From: Suanming Mou To: viacheslavo@nvidia.com, matan@nvidia.com Cc: rasland@nvidia.com, dev@dpdk.org Date: Tue, 6 Oct 2020 19:38:48 +0800 Message-Id: <1601984333-304464-2-git-send-email-suanmingm@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1601984333-304464-1-git-send-email-suanmingm@nvidia.com> References: <1601984333-304464-1-git-send-email-suanmingm@nvidia.com> Subject: [dpdk-dev] [PATCH 1/6] net/mlx5: locate aging pools in the general container X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Commit [1] introduced different container for the aging counter pools. In order to save container memory the aging counter pools can be located in the general pool container. This patch locates the aging counter pools in the general pool container. Remove the aging container management. [1] commit fd143711a6ea ("net/mlx5: separate aging counter pool range") Signed-off-by: Suanming Mou --- drivers/net/mlx5/mlx5.c | 7 ++-- drivers/net/mlx5/mlx5.h | 17 +++++---- drivers/net/mlx5/mlx5_flow.c | 19 +++------- drivers/net/mlx5/mlx5_flow_dv.c | 78 ++++++++++++++++++-------------------- drivers/net/mlx5/mlx5_flow_verbs.c | 4 +- 5 files changed, 57 insertions(+), 68 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 01ead6e..5e3569d 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -458,7 +458,7 @@ struct mlx5_flow_id_pool * static void mlx5_flow_counters_mng_init(struct mlx5_dev_ctx_shared *sh) { - int i; + int i, j; memset(&sh->cmng, 0, sizeof(sh->cmng)); TAILQ_INIT(&sh->cmng.flow_counters); @@ -468,7 +468,8 @@ struct mlx5_flow_id_pool * sh->cmng.ccont[i].last_pool_idx = POOL_IDX_INVALID; TAILQ_INIT(&sh->cmng.ccont[i].pool_list); rte_spinlock_init(&sh->cmng.ccont[i].resize_sl); - TAILQ_INIT(&sh->cmng.ccont[i].counters); + for (j = 0; j < MLX5_COUNTER_TYPE_MAX; j++) + TAILQ_INIT(&sh->cmng.ccont[i].counters[j]); rte_spinlock_init(&sh->cmng.ccont[i].csl); } } @@ -513,7 +514,7 @@ struct mlx5_flow_id_pool * } for (i = 0; i < MLX5_CCONT_TYPE_MAX; ++i) { struct mlx5_flow_counter_pool *pool; - uint32_t batch = !!(i > 1); + uint32_t batch = (i == MLX5_CCONT_TYPE_BATCH); if (!sh->cmng.ccont[i].pools) continue; diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index bd91e16..27c8f45 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -270,7 +270,6 @@ struct mlx5_drop { #define MLX5_COUNTERS_PER_POOL 512 #define MLX5_MAX_PENDING_QUERIES 4 #define MLX5_CNT_CONTAINER_RESIZE 64 -#define MLX5_CNT_AGE_OFFSET 0x80000000 #define CNT_SIZE (sizeof(struct mlx5_flow_counter)) #define CNTEXT_SIZE (sizeof(struct mlx5_flow_counter_ext)) #define AGE_SIZE (sizeof(struct mlx5_age_param)) @@ -279,7 +278,6 @@ struct mlx5_drop { #define CNT_POOL_TYPE_AGE (1 << 1) #define IS_EXT_POOL(pool) (((pool)->type) & CNT_POOL_TYPE_EXT) #define IS_AGE_POOL(pool) (((pool)->type) & CNT_POOL_TYPE_AGE) -#define MLX_CNT_IS_AGE(counter) ((counter) & MLX5_CNT_AGE_OFFSET ? 1 : 0) #define MLX5_CNT_LEN(pool) \ (CNT_SIZE + \ (IS_AGE_POOL(pool) ? AGE_SIZE : 0) + \ @@ -322,17 +320,20 @@ enum { AGE_TMOUT, /* Timeout, wait for rte_flow_get_aged_flows and destroy. */ }; -#define MLX5_CNT_CONTAINER(sh, batch, age) (&(sh)->cmng.ccont \ - [(batch) * 2 + (age)]) +#define MLX5_CNT_CONTAINER(sh, batch) (&(sh)->cmng.ccont[batch]) enum { MLX5_CCONT_TYPE_SINGLE, - MLX5_CCONT_TYPE_SINGLE_FOR_AGE, MLX5_CCONT_TYPE_BATCH, - MLX5_CCONT_TYPE_BATCH_FOR_AGE, MLX5_CCONT_TYPE_MAX, }; +enum mlx5_counter_type { + MLX5_COUNTER_TYPE_ORIGIN, + MLX5_COUNTER_TYPE_AGE, + MLX5_COUNTER_TYPE_MAX, +}; + /* Counter age parameter. */ struct mlx5_age_param { rte_atomic16_t state; /**< Age state. */ @@ -427,7 +428,8 @@ struct mlx5_pools_container { int max_id; /* The maximum counter ID in the pools. */ rte_spinlock_t resize_sl; /* The resize lock. */ rte_spinlock_t csl; /* The counter free list lock. */ - struct mlx5_counters counters; /* Free counter list. */ + struct mlx5_counters counters[MLX5_COUNTER_TYPE_MAX]; + /* Free counter list. */ struct mlx5_counter_pools pool_list; /* Counter pool list. */ struct mlx5_flow_counter_pool **pools; /* Counter pool array. */ struct mlx5_counter_stats_mem_mng *mem_mng; @@ -441,7 +443,6 @@ struct mlx5_flow_counter_mng { uint8_t pending_queries; uint8_t batch; uint16_t pool_index; - uint8_t age; uint8_t query_thread_on; LIST_HEAD(mem_mngs, mlx5_counter_stats_mem_mng) mem_mngs; LIST_HEAD(stat_raws, mlx5_counter_stats_raw) free_stat_raws; diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index ffa7646..db7fc8f 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -5940,7 +5940,6 @@ struct mlx5_meter_domains_infos * uint16_t offset; int ret; uint8_t batch = sh->cmng.batch; - uint8_t age = sh->cmng.age; uint16_t pool_index = sh->cmng.pool_index; struct mlx5_pools_container *cont; struct mlx5_flow_counter_pool *pool; @@ -5949,7 +5948,7 @@ struct mlx5_meter_domains_infos * if (sh->cmng.pending_queries >= MLX5_MAX_PENDING_QUERIES) goto set_alarm; next_container: - cont = MLX5_CNT_CONTAINER(sh, batch, age); + cont = MLX5_CNT_CONTAINER(sh, batch); rte_spinlock_lock(&cont->resize_sl); if (!cont->pools) { rte_spinlock_unlock(&cont->resize_sl); @@ -5958,11 +5957,6 @@ struct mlx5_meter_domains_infos * goto set_alarm; batch ^= 0x1; pool_index = 0; - if (batch == 0 && pool_index == 0) { - age ^= 0x1; - sh->cmng.batch = batch; - sh->cmng.age = age; - } goto next_container; } pool = cont->pools[pool_index]; @@ -6011,13 +6005,10 @@ struct mlx5_meter_domains_infos * if (pool_index >= rte_atomic16_read(&cont->n_valid)) { batch ^= 0x1; pool_index = 0; - if (batch == 0 && pool_index == 0) - age ^= 0x1; } set_alarm: sh->cmng.batch = batch; sh->cmng.pool_index = pool_index; - sh->cmng.age = age; mlx5_set_query_alarm(sh); } @@ -6103,10 +6094,12 @@ struct mlx5_meter_domains_infos * struct mlx5_flow_counter_pool *pool = (struct mlx5_flow_counter_pool *)(uintptr_t)async_id; struct mlx5_counter_stats_raw *raw_to_free; - uint8_t age = !!IS_AGE_POOL(pool); uint8_t query_gen = pool->query_gen ^ 1; struct mlx5_pools_container *cont = - MLX5_CNT_CONTAINER(sh, !IS_EXT_POOL(pool), age); + MLX5_CNT_CONTAINER(sh, !IS_EXT_POOL(pool)); + enum mlx5_counter_type cnt_type = + IS_AGE_POOL(pool) ? MLX5_COUNTER_TYPE_AGE : + MLX5_COUNTER_TYPE_ORIGIN; if (unlikely(status)) { raw_to_free = pool->raw_hw; @@ -6121,7 +6114,7 @@ struct mlx5_meter_domains_infos * rte_io_wmb(); if (!TAILQ_EMPTY(&pool->counters[query_gen])) { rte_spinlock_lock(&cont->csl); - TAILQ_CONCAT(&cont->counters, + TAILQ_CONCAT(&cont->counters[cnt_type], &pool->counters[query_gen], next); rte_spinlock_unlock(&cont->csl); } diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index 79fdf34..1bd3899 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -4170,16 +4170,14 @@ struct field_modify_info modify_tcp[] = { struct mlx5_priv *priv = dev->data->dev_private; struct mlx5_pools_container *cont; struct mlx5_flow_counter_pool *pool; - uint32_t batch = 0, age = 0; + uint32_t batch = 0; idx--; - age = MLX_CNT_IS_AGE(idx); - idx = age ? idx - MLX5_CNT_AGE_OFFSET : idx; if (idx >= MLX5_CNT_BATCH_OFFSET) { idx -= MLX5_CNT_BATCH_OFFSET; batch = 1; } - cont = MLX5_CNT_CONTAINER(priv->sh, batch, age); + cont = MLX5_CNT_CONTAINER(priv->sh, batch); MLX5_ASSERT(idx / MLX5_COUNTERS_PER_POOL < cont->n); pool = cont->pools[idx / MLX5_COUNTERS_PER_POOL]; MLX5_ASSERT(pool); @@ -4332,19 +4330,15 @@ struct field_modify_info modify_tcp[] = { * Pointer to the Ethernet device structure. * @param[in] batch * Whether the pool is for counter that was allocated by batch command. - * @param[in] age - * Whether the pool is for Aging counter. * * @return * 0 on success, otherwise negative errno value and rte_errno is set. */ static int -flow_dv_container_resize(struct rte_eth_dev *dev, - uint32_t batch, uint32_t age) +flow_dv_container_resize(struct rte_eth_dev *dev, uint32_t batch) { struct mlx5_priv *priv = dev->data->dev_private; - struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch, - age); + struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch); struct mlx5_counter_stats_mem_mng *mem_mng = NULL; void *old_pools = cont->pools; uint32_t resize = cont->n + MLX5_CNT_CONTAINER_RESIZE; @@ -4462,12 +4456,11 @@ struct field_modify_info modify_tcp[] = { { struct mlx5_priv *priv = dev->data->dev_private; struct mlx5_flow_counter_pool *pool; - struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch, - age); + struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch); int16_t n_valid = rte_atomic16_read(&cont->n_valid); uint32_t size = sizeof(*pool); - if (cont->n == n_valid && flow_dv_container_resize(dev, batch, age)) + if (cont->n == n_valid && flow_dv_container_resize(dev, batch)) return NULL; size += MLX5_COUNTERS_PER_POOL * CNT_SIZE; size += (batch ? 0 : MLX5_COUNTERS_PER_POOL * CNTEXT_SIZE); @@ -4595,10 +4588,12 @@ struct field_modify_info modify_tcp[] = { struct mlx5_devx_obj *last_min_dcs; struct mlx5_devx_obj *dcs = NULL; struct mlx5_flow_counter *cnt; + enum mlx5_counter_type cnt_type = + age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN; uint32_t add2other; uint32_t i; - cont = MLX5_CNT_CONTAINER(priv->sh, batch, age); + cont = MLX5_CNT_CONTAINER(priv->sh, batch); if (!batch) { retry: add2other = 0; @@ -4607,24 +4602,19 @@ struct field_modify_info modify_tcp[] = { if (!dcs) return NULL; pool = flow_dv_find_pool_by_id(cont, dcs->id); - /* Check if counter belongs to exist pool ID range. */ - if (!pool) { - pool = flow_dv_find_pool_by_id - (MLX5_CNT_CONTAINER - (priv->sh, batch, (age ^ 0x1)), dcs->id); - /* - * Pool eixsts, counter will be added to the other - * container, need to reallocate it later. - */ - if (pool) { - add2other = 1; - } else { - pool = flow_dv_pool_create(dev, dcs, batch, - age); - if (!pool) { - mlx5_devx_cmd_destroy(dcs); - return NULL; - } + /* + * If pool eixsts but with other type, counter will be added + * to the other pool, need to reallocate new counter in the + * ragne with same type later. + */ + if (pool && ((!!IS_AGE_POOL(pool)) != age)) { + add2other = 1; + } else if (!pool) { + pool = flow_dv_pool_create(dev, dcs, batch, + age); + if (!pool) { + mlx5_devx_cmd_destroy(dcs); + return NULL; } } if ((dcs->id < pool->min_dcs->id || @@ -4692,7 +4682,7 @@ struct field_modify_info modify_tcp[] = { TAILQ_INSERT_HEAD(&tmp_tq, cnt, next); } rte_spinlock_lock(&cont->csl); - TAILQ_CONCAT(&cont->counters, &tmp_tq, next); + TAILQ_CONCAT(&cont->counters[cnt_type], &tmp_tq, next); rte_spinlock_unlock(&cont->csl); *cnt_free = MLX5_POOL_GET_CNT(pool, 0); (*cnt_free)->pool = pool; @@ -4765,8 +4755,9 @@ struct field_modify_info modify_tcp[] = { * shared counters from the single container. */ uint32_t batch = (group && !shared && !priv->counter_fallback) ? 1 : 0; - struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch, - age); + struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, batch); + enum mlx5_counter_type cnt_type = + age ? MLX5_COUNTER_TYPE_AGE : MLX5_COUNTER_TYPE_ORIGIN; uint32_t cnt_idx; if (!priv->config.devx) { @@ -4789,9 +4780,9 @@ struct field_modify_info modify_tcp[] = { } /* Get free counters from container. */ rte_spinlock_lock(&cont->csl); - cnt_free = TAILQ_FIRST(&cont->counters); + cnt_free = TAILQ_FIRST(&cont->counters[cnt_type]); if (cnt_free) - TAILQ_REMOVE(&cont->counters, cnt_free, next); + TAILQ_REMOVE(&cont->counters[cnt_type], cnt_free, next); rte_spinlock_unlock(&cont->csl); if (!cnt_free && !flow_dv_counter_pool_prepare(dev, &cnt_free, batch, age)) @@ -4822,7 +4813,6 @@ struct field_modify_info modify_tcp[] = { cnt_idx = MLX5_MAKE_CNT_IDX(pool->index, MLX5_CNT_ARRAY_IDX(pool, cnt_free)); cnt_idx += batch * MLX5_CNT_BATCH_OFFSET; - cnt_idx += age * MLX5_CNT_AGE_OFFSET; /* Update the counter reset values. */ if (_flow_dv_query_count(dev, cnt_idx, &cnt_free->hits, &cnt_free->bytes)) @@ -4847,7 +4837,7 @@ struct field_modify_info modify_tcp[] = { if (cnt_free) { cnt_free->pool = pool; rte_spinlock_lock(&cont->csl); - TAILQ_INSERT_TAIL(&cont->counters, cnt_free, next); + TAILQ_INSERT_TAIL(&cont->counters[cnt_type], cnt_free, next); rte_spinlock_unlock(&cont->csl); } return 0; @@ -4926,6 +4916,7 @@ struct field_modify_info modify_tcp[] = { struct mlx5_flow_counter_pool *pool = NULL; struct mlx5_flow_counter *cnt; struct mlx5_flow_counter_ext *cnt_ext = NULL; + enum mlx5_counter_type cnt_type; if (!counter) return; @@ -4954,12 +4945,15 @@ struct field_modify_info modify_tcp[] = { * function both operate with the different list. * */ - if (!priv->counter_fallback) + if (!priv->counter_fallback) { TAILQ_INSERT_TAIL(&pool->counters[pool->query_gen], cnt, next); - else + } else { + cnt_type = IS_AGE_POOL(pool) ? MLX5_COUNTER_TYPE_AGE : + MLX5_COUNTER_TYPE_ORIGIN; TAILQ_INSERT_TAIL(&((MLX5_CNT_CONTAINER - (priv->sh, 0, 0))->counters), + (priv->sh, 0))->counters[cnt_type]), cnt, next); + } } /** diff --git a/drivers/net/mlx5/mlx5_flow_verbs.c b/drivers/net/mlx5/mlx5_flow_verbs.c index 62c18b8..2f3035a 100644 --- a/drivers/net/mlx5/mlx5_flow_verbs.c +++ b/drivers/net/mlx5/mlx5_flow_verbs.c @@ -159,7 +159,7 @@ struct mlx5_flow_counter_pool **ppool) { struct mlx5_priv *priv = dev->data->dev_private; - struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, 0, 0); + struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, 0); struct mlx5_flow_counter_pool *pool; idx--; @@ -254,7 +254,7 @@ flow_verbs_counter_new(struct rte_eth_dev *dev, uint32_t shared, uint32_t id) { struct mlx5_priv *priv = dev->data->dev_private; - struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, 0, 0); + struct mlx5_pools_container *cont = MLX5_CNT_CONTAINER(priv->sh, 0); struct mlx5_flow_counter_pool *pool = NULL; struct mlx5_flow_counter_ext *cnt_ext = NULL; struct mlx5_flow_counter *cnt = NULL; -- 1.8.3.1