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 AD841A04AB; Wed, 6 Nov 2019 16:14:50 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9D27C1D157; Wed, 6 Nov 2019 16:12:32 +0100 (CET) Received: from git-send-mailer.rdmz.labs.mlnx (unknown [37.142.13.130]) by dpdk.org (Postfix) with ESMTP id EB4351C1D9 for ; Wed, 6 Nov 2019 16:12:02 +0100 (CET) From: Suanming Mou To: Matan Azrad , Shahaf Shuler , Viacheslav Ovsiienko Cc: dev@dpdk.org Date: Wed, 6 Nov 2019 17:11:28 +0200 Message-Id: <1573053090-179521-20-git-send-email-suanmingm@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1573053090-179521-1-git-send-email-suanmingm@mellanox.com> References: <1573053090-179521-1-git-send-email-suanmingm@mellanox.com> Subject: [dpdk-dev] [PATCH 19/19] net/mlx5: clean meter resources 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" When the port is closed or program exits ungraceful, the meter rulers should be flushed after the flow destroyed. Signed-off-by: Suanming Mou --- drivers/net/mlx5/mlx5.c | 1 + drivers/net/mlx5/mlx5_flow.h | 2 ++ drivers/net/mlx5/mlx5_flow_meter.c | 61 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 1a2fef6..da79c14 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1016,6 +1016,7 @@ struct mlx5_flow_id_pool * mlx5_dev_interrupt_handler_devx_uninstall(dev); mlx5_traffic_disable(dev); mlx5_flow_flush(dev, NULL); + mlx5_flow_meter_flush(dev, NULL); /* Prevent crashes when queues are still in use. */ dev->rx_pkt_burst = removed_rx_burst; dev->tx_pkt_burst = removed_tx_burst; diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index e38d3c0..c37adfe 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -840,4 +840,6 @@ int mlx5_flow_create_policer_rules(struct rte_eth_dev *dev, int mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev, struct mlx5_flow_meter *fm, const struct rte_flow_attr *attr); +int mlx5_flow_meter_flush(struct rte_eth_dev *dev, + struct rte_mtr_error *error); #endif /* RTE_PMD_MLX5_FLOW_H_ */ diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c index bd2bf7c..f8e7e11 100644 --- a/drivers/net/mlx5/mlx5_flow_meter.c +++ b/drivers/net/mlx5/mlx5_flow_meter.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -1220,3 +1221,63 @@ struct mlx5_flow_meter * fm->mfts->meter_action = NULL; fm->attr = attr; } + +/** + * Flush meter configuration. + * + * @param[in] dev + * Pointer to Ethernet device. + * @param[out] error + * Pointer to rte meter error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_flow_meter_flush(struct rte_eth_dev *dev, struct rte_mtr_error *error) +{ + struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5_flow_meters *fms = &priv->flow_meters; + struct mlx5_mtr_profiles *fmps = &priv->flow_meter_profiles; + struct mlx5_flow_meter_profile *fmp; + struct mlx5_flow_meter *fm; + const struct rte_flow_attr attr = { + .ingress = 1, + .egress = 1, + .transfer = priv->config.dv_esw_en ? 1 : 0, + }; + void *tmp; + uint32_t i; + + TAILQ_FOREACH_SAFE(fm, fms, next, tmp) { + /* Meter object must not have any owner. */ + RTE_ASSERT(!fm->ref_cnt); + /* Get meter profile. */ + fmp = fm->profile; + if (fmp == NULL) + return -rte_mtr_error_set(error, EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, "MTR object meter profile invalid."); + /* Update dependencies. */ + fmp->ref_cnt--; + /* Remove from list. */ + TAILQ_REMOVE(fms, fm, next); + /* Free policer counters. */ + 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]); + /* Free meter flow table. */ + mlx5_flow_destroy_policer_rules(dev, fm, &attr); + mlx5_flow_destroy_mtr_tbls(dev, fm->mfts); + rte_free(fm); + } + TAILQ_FOREACH_SAFE(fmp, fmps, next, tmp) { + /* Check unused. */ + RTE_ASSERT(!fmp->ref_cnt); + /* Remove from list. */ + TAILQ_REMOVE(&priv->flow_meter_profiles, fmp, next); + rte_free(fmp); + } + return 0; +} -- 1.8.3.1