net/mlx5: allocate meter from indexed pool

This patch allocate the meter object memory from indexed memory pool
which will help to save the MALLOC_ELEM_OVERHEAD memory taken by
rte_malloc().

Signed-off-by: Suanming Mou <suanmingm@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
This commit is contained in:
Suanming Mou 2020-04-16 16:34:26 +08:00 committed by Ferruh Yigit
parent 8eb5485dc0
commit 8638e2b076
4 changed files with 19 additions and 5 deletions

View File

@ -256,6 +256,17 @@ static struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = {
.type = "mlx5_jump_ipool",
},
#endif
{
.size = sizeof(struct mlx5_flow_meter),
.trunk_size = 64,
.grow_trunk = 3,
.grow_shift = 2,
.need_lock = 0,
.release_mem_en = 1,
.malloc = rte_malloc_socket,
.free = rte_free,
.type = "mlx5_meter_ipool",
},
{
.size = (sizeof(struct mlx5_hrxq) + MLX5_RSS_HASH_KEY_LEN),
.trunk_size = 64,

View File

@ -52,6 +52,7 @@ enum mlx5_ipool_index {
MLX5_IPOOL_PORT_ID, /* Pool for port id resource. */
MLX5_IPOOL_JUMP, /* Pool for jump resource. */
#endif
MLX5_IPOOL_MTR, /* Pool for meter resource. */
MLX5_IPOOL_HRXQ, /* Pool for hrxq resource. */
MLX5_IPOOL_MLX5_FLOW, /* Pool for mlx5 flow handle. */
MLX5_IPOOL_MAX,

View File

@ -703,6 +703,7 @@ struct mlx5_meter_domains_infos {
struct mlx5_flow_meter {
TAILQ_ENTRY(mlx5_flow_meter) next;
/**< Pointer to the next flow meter structure. */
uint32_t idx; /* Index to meter object. */
uint32_t meter_id;
/**< Meter id. */
struct rte_mtr_params params;

View File

@ -631,6 +631,7 @@ mlx5_flow_meter_create(struct rte_eth_dev *dev, uint32_t meter_id,
};
int ret;
unsigned int i;
uint32_t idx = 0;
if (!priv->mtr_en)
return -rte_mtr_error_set(error, ENOTSUP,
@ -647,12 +648,12 @@ mlx5_flow_meter_create(struct rte_eth_dev *dev, uint32_t meter_id,
RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
NULL, "Meter profile id not valid.");
/* Allocate the flow meter memory. */
fm = rte_calloc(__func__, 1,
sizeof(struct mlx5_flow_meter), RTE_CACHE_LINE_SIZE);
fm = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MTR], &idx);
if (fm == NULL)
return -rte_mtr_error_set(error, ENOMEM,
RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
"Memory alloc failed for meter.");
fm->idx = idx;
/* Fill the flow meter parameters. */
fm->meter_id = meter_id;
fm->profile = fmp;
@ -683,7 +684,7 @@ mlx5_flow_meter_create(struct rte_eth_dev *dev, uint32_t meter_id,
for (i = 0; i < RTE_DIM(fm->policer_stats.cnt); i++)
if (fm->policer_stats.cnt[i])
mlx5_counter_free(dev, fm->policer_stats.cnt[i]);
rte_free(fm);
mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR], idx);
return -rte_mtr_error_set(error, -ret,
RTE_MTR_ERROR_TYPE_UNSPECIFIED,
NULL, "Failed to create devx meter.");
@ -746,7 +747,7 @@ mlx5_flow_meter_destroy(struct rte_eth_dev *dev, uint32_t meter_id,
/* Free meter flow table */
mlx5_flow_destroy_policer_rules(dev, fm, &attr);
mlx5_flow_destroy_mtr_tbls(dev, fm->mfts);
rte_free(fm);
mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR], fm->idx);
return 0;
}
@ -1274,7 +1275,7 @@ mlx5_flow_meter_flush(struct rte_eth_dev *dev, struct rte_mtr_error *error)
/* Free meter flow table. */
mlx5_flow_destroy_policer_rules(dev, fm, &attr);
mlx5_flow_destroy_mtr_tbls(dev, fm->mfts);
rte_free(fm);
mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MTR], fm->idx);
}
TAILQ_FOREACH_SAFE(fmp, fmps, next, tmp) {
/* Check unused. */