DPDK patches and discussions
 help / color / mirror / Atom feed
From: Suanming Mou <suanmingm@mellanox.com>
To: viacheslavo@mellanox.com, matan@mellanox.com
Cc: orika@mellanox.com, rasland@mellanox.com, dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2 13/19] net/mlx5: add count action to meter
Date: Fri,  8 Nov 2019 05:49:19 +0200	[thread overview]
Message-ID: <1573184965-49691-14-git-send-email-suanmingm@mellanox.com> (raw)
In-Reply-To: <1573184965-49691-1-git-send-email-suanmingm@mellanox.com>

Add count action to meter for metering packet statistics. All the
packets be colored and dropped will be recorded.

Signed-off-by: Suanming Mou <suanmingm@mellanox.com>
---
 drivers/net/mlx5/mlx5_flow.c       |  7 +++++--
 drivers/net/mlx5/mlx5_flow.h       | 18 ++++++++++++++++--
 drivers/net/mlx5/mlx5_flow_dv.c    | 16 +++++++++++++++-
 drivers/net/mlx5/mlx5_flow_meter.c | 18 +++++++++++++++++-
 4 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 750e58e..ee964b0 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -4916,17 +4916,20 @@ struct rte_flow *
  *
  * @param[in] dev
  *   Pointer to Ethernet device.
+ * @param[in] fm
+ *   Pointer to the flow meter.
  *
  * @return
  *   Pointer to table set on success, NULL otherwise.
  */
 struct mlx5_meter_domains_infos *
-mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev)
+mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
+			  const struct mlx5_flow_meter *fm)
 {
 	const struct mlx5_flow_driver_ops *fops;
 
 	fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
-	return fops->create_mtr_tbls(dev);
+	return fops->create_mtr_tbls(dev, fm);
 }
 
 /**
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 0326330..cdcca7a 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -531,6 +531,14 @@ struct mlx5_flow {
 /* Modify this value if enum rte_mtr_color changes. */
 #define RTE_MTR_DROPPED RTE_COLORS
 
+/* Meter policer statistics */
+struct mlx5_flow_policer_stats {
+	struct mlx5_flow_counter *cnt[RTE_COLORS + 1];
+	/**< Color counter, extra for drop. */
+	uint64_t stats_mask;
+	/**< Statistics mask for the colors. */
+};
+
 /* Meter table structure. */
 struct mlx5_meter_domain_info {
 	struct mlx5_flow_tbl_resource *tbl;
@@ -557,6 +565,8 @@ struct mlx5_meter_domains_infos {
 	/**< FDB meter table. */
 	void *drop_actn;
 	/**< Drop action as not matched. */
+	void *count_actns[RTE_MTR_DROPPED + 1];
+	/**< Counters for match and unmatched statistics. */
 	uint32_t fmp[MLX5_ST_SZ_DW(flow_meter_parameters)];
 	/**< Flow meter parameter. */
 	size_t fmp_size;
@@ -577,6 +587,8 @@ struct mlx5_flow_meter {
 	/**< Meter profile parameters. */
 	struct mlx5_meter_domains_infos *mfts;
 	/**< Flow table created for this meter. */
+	struct mlx5_flow_policer_stats policer_stats;
+	/**< Meter policer statistics. */
 	uint32_t ref_cnt;
 	/**< Use count. */
 	uint32_t active_state:1;
@@ -653,7 +665,8 @@ typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev,
 				 void *data,
 				 struct rte_flow_error *error);
 typedef struct mlx5_meter_domains_infos *(*mlx5_flow_create_mtr_tbls_t)
-					    (struct rte_eth_dev *dev);
+					    (struct rte_eth_dev *dev,
+					     const struct mlx5_flow_meter *fm);
 typedef int (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
 					struct mlx5_meter_domains_infos *tbls);
 typedef int (*mlx5_flow_create_policer_rules_t)
@@ -814,7 +827,8 @@ int mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
 				   struct rte_eth_dev *dev,
 				   struct rte_flow_error *error);
 struct mlx5_meter_domains_infos *mlx5_flow_create_mtr_tbls
-					(struct rte_eth_dev *dev);
+					(struct rte_eth_dev *dev,
+					 const struct mlx5_flow_meter *fm);
 int mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
 			       struct mlx5_meter_domains_infos *tbl);
 int mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index b273b6c..c03950e 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -7756,6 +7756,8 @@ struct field_modify_info modify_tcp[] = {
 		DRV_LOG(ERR, "Failed to create meter policer color matcher.");
 		goto error_exit;
 	}
+	if (mtb->count_actns[RTE_MTR_DROPPED])
+		actions[i++] = mtb->count_actns[RTE_MTR_DROPPED];
 	actions[i++] = mtb->drop_actn;
 	/* Default rule: lowest priority, match any, actions: drop. */
 	dtb->policer_rules[RTE_MTR_DROPPED] =
@@ -7776,16 +7778,20 @@ struct field_modify_info modify_tcp[] = {
  *
  * @param[in] dev
  *   Pointer to Ethernet device.
+ * @param[in] fm
+ *   Pointer to the flow meter.
  *
  * @return
  *   Pointer to table set on success, NULL otherwise and rte_errno is set.
  */
 static struct mlx5_meter_domains_infos *
-flow_dv_create_mtr_tbl(struct rte_eth_dev *dev)
+flow_dv_create_mtr_tbl(struct rte_eth_dev *dev,
+		       const struct mlx5_flow_meter *fm)
 {
 	struct mlx5_priv *priv = dev->data->dev_private;
 	struct mlx5_meter_domains_infos *mtb;
 	int ret;
+	int i;
 
 	if (!priv->mtr_en) {
 		rte_errno = ENOTSUP;
@@ -7796,6 +7802,12 @@ struct field_modify_info modify_tcp[] = {
 		DRV_LOG(ERR, "Failed to allocate memory for meter.");
 		return NULL;
 	}
+	/* Create meter count actions */
+	for (i = 0; i <= RTE_MTR_DROPPED; i++) {
+		if (!fm->policer_stats.cnt[i])
+			continue;
+		mtb->count_actns[i] = fm->policer_stats.cnt[i]->action;
+	}
 	/* Create drop action. */
 	mtb->drop_actn = mlx5_glue->dr_create_flow_action_drop();
 	if (!mtb->drop_actn) {
@@ -7931,6 +7943,8 @@ struct field_modify_info modify_tcp[] = {
 
 		flow_dv_match_meta_reg(matcher.buf, value.buf, mtr_reg_c,
 				       rte_col_2_mlx5_col(i), UINT32_MAX);
+		if (mtb->count_actns[i])
+			actions[j++] = mtb->count_actns[i];
 		if (fm->params.action[i] == MTR_POLICER_ACTION_DROP)
 			actions[j++] = mtb->drop_actn;
 		else
diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c
index 7f64924..7645d92 100644
--- a/drivers/net/mlx5/mlx5_flow_meter.c
+++ b/drivers/net/mlx5/mlx5_flow_meter.c
@@ -571,6 +571,7 @@
 				.transfer = priv->config.dv_esw_en ? 1 : 0,
 			};
 	int ret;
+	unsigned int i;
 
 	if (!priv->mtr_en)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -597,7 +598,13 @@
 	fm->meter_id = meter_id;
 	fm->profile = fmp;
 	fm->params = *params;
-	fm->mfts = mlx5_flow_create_mtr_tbls(dev);
+	/* Alloc policer counters. */
+	for (i = 0; i < RTE_DIM(fm->policer_stats.cnt); i++) {
+		fm->policer_stats.cnt[i] = mlx5_counter_alloc(dev);
+		if (!fm->policer_stats.cnt[i])
+			goto error;
+	}
+	fm->mfts = mlx5_flow_create_mtr_tbls(dev, fm);
 	if (!fm->mfts)
 		goto error;
 	ret = mlx5_flow_create_policer_rules(dev, fm, &attr);
@@ -612,6 +619,10 @@
 error:
 	mlx5_flow_destroy_policer_rules(dev, fm, &attr);
 	mlx5_flow_destroy_mtr_tbls(dev, fm->mfts);
+	/* 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]);
 	rte_free(fm);
 	return -rte_mtr_error_set(error, -ret,
 				  RTE_MTR_ERROR_TYPE_UNSPECIFIED,
@@ -644,6 +655,7 @@
 				.egress = 1,
 				.transfer = priv->config.dv_esw_en ? 1 : 0,
 			};
+	unsigned int i;
 
 	if (!priv->mtr_en)
 		return -rte_mtr_error_set(error, ENOTSUP,
@@ -667,6 +679,10 @@
 	fmp->ref_cnt--;
 	/* Remove from the flow meter 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);
-- 
1.8.3.1


  parent reply	other threads:[~2019-11-08  3:51 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-06 15:11 [dpdk-dev] [PATCH 00/19] net/mlx5: support meter Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 01/19] net/mlx5: add meter operation callback Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 02/19] net/mlx5: fill meter capabilities using DevX Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 03/19] net/mlx5: allocate flow meter registers Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 04/19] net/mlx5: support meter profile operations Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 05/19] net/mlx5: validate meter profile Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 06/19] net/mlx5: prepare meter flow tables Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 07/19] net/mlx5: add policer rules operations Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 08/19] net/mlx5: support basic meter operations Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 09/19] net/mlx5: add meter action creation to the glue Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 10/19] net/mlx5: support meter modification operations Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 11/19] net/mlx5: support meter profile update Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 12/19] net/mlx5: expose flow counters management Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 13/19] net/mlx5: add count action to meter Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 14/19] net/mlx5: add meter statistics read and update Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 15/19] net/mlx5: add meter attach and detach Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 16/19] net/mlx5: support meter flow action Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 17/19] net/mlx5: split meter flow Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 18/19] net/mlx5: share tag between meter and metadata Suanming Mou
2019-11-06 15:11 ` [dpdk-dev] [PATCH 19/19] net/mlx5: clean meter resources Suanming Mou
2019-11-08  3:49 ` [dpdk-dev] [PATCH v2 00/19] net/mlx5: support meter Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 01/19] net/mlx5: add meter operation callback Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 02/19] net/mlx5: fill meter capabilities using DevX Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 03/19] net/mlx5: allocate flow meter registers Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 04/19] net/mlx5: support meter profile operations Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 05/19] net/mlx5: validate meter profile Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 06/19] net/mlx5: prepare meter flow tables Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 07/19] net/mlx5: add policer rules operations Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 08/19] net/mlx5: support basic meter operations Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 09/19] net/mlx5: add meter action creation to the glue Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 10/19] net/mlx5: support meter modification operations Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 11/19] net/mlx5: support meter profile update Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 12/19] net/mlx5: expose flow counters management Suanming Mou
2019-11-08  3:49   ` Suanming Mou [this message]
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 14/19] net/mlx5: add meter statistics read and update Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 15/19] net/mlx5: add meter attach and detach Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 16/19] net/mlx5: support meter flow action Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 17/19] net/mlx5: split meter flow Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 18/19] net/mlx5: share tag between meter and metadata Suanming Mou
2019-11-08  3:49   ` [dpdk-dev] [PATCH v2 19/19] net/mlx5: clean meter resources Suanming Mou
2019-11-08  6:20   ` [dpdk-dev] [PATCH v2 00/19] net/mlx5: support meter Matan Azrad
2019-11-08 14:22   ` Raslan Darawsheh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1573184965-49691-14-git-send-email-suanmingm@mellanox.com \
    --to=suanmingm@mellanox.com \
    --cc=dev@dpdk.org \
    --cc=matan@mellanox.com \
    --cc=orika@mellanox.com \
    --cc=rasland@mellanox.com \
    --cc=viacheslavo@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).