Skip to contentSkip to conversation

Support meter policy API

PATCH Superseded Li Zhang 2 participants 8 messages Apr 1, 2021 – Apr 8, 2021 Network drivers

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Li Zhang

author
#0 lore raw

cover Support meter policy API

Currently, the flow meter policy does not support multiple actions per color; also the allowed action types per color are very limited. In addition, the policy cannot be pre-defined.

Due to the growing in flow actions offload abilities there is a potential for the user to use variety of actions per color differently. This new meter policy API comes to allow this potential in the most ethdev common way using rte_flow action definition.
A list of rte_flow actions will be provided by the user per color in order to create a meter policy.
In addition, the API forces to pre-define the policy before the meters creation in order to allow sharing of single policy with multiple meters efficiently.

meter_policy_id is added into struct rte_mtr_params. So that it can get the policy during the meters creation.

RFC ("ethdev: add pre-defined meter policy API")
https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/

Haifei Luo (1):
app/testpmd: support policy actions per color

Li Zhang (1):
ethdev: add pre-defined meter policy API

 app/test-flow-perf/main.c                     |   7 -
 app/test-pmd/cmdline.c                        |   7 +-
 app/test-pmd/cmdline_flow.c                   | 118 ++++-
 app/test-pmd/cmdline_mtr.c                    | 257 +++-------
 app/test-pmd/cmdline_mtr.h                    |   4 +-
 app/test-pmd/config.c                         |  34 ++
 app/test-pmd/testpmd.h                        |   2 +
 doc/guides/rel_notes/release_20_11.rst        |   3 +
 drivers/net/mlx5/mlx5.h                       |  24 +-
 drivers/net/mlx5/mlx5_flow.c                  |  46 --
 drivers/net/mlx5/mlx5_flow.h                  |  18 +-
 drivers/net/mlx5/mlx5_flow_aso.c              |   8 +-
 drivers/net/mlx5/mlx5_flow_dv.c               | 461 +-----------------
 drivers/net/mlx5/mlx5_flow_meter.c            | 369 +-------------
 drivers/net/softnic/rte_eth_softnic_flow.c    |  19 +-
 .../net/softnic/rte_eth_softnic_internals.h   |  18 +-
 drivers/net/softnic/rte_eth_softnic_meter.c   | 303 +++++++++---
 lib/librte_ethdev/rte_flow.h                  |  18 +
 lib/librte_ethdev/rte_mtr.c                   |  55 ++-
 lib/librte_ethdev/rte_mtr.h                   | 166 +++++--
 lib/librte_ethdev/rte_mtr_driver.h            |  44 +-
 lib/librte_ethdev/version.map                 |   4 +
 22 files changed, 747 insertions(+), 1238 deletions(-)
Signature · 1 line
2.27.0
author
#1 lore raw

PATCH 1/2 ethdev: add pre-defined meter policy API

Currently, the flow meter policy does not support multiple actions per color; also the allowed action types per color are very limited. In addition, the policy cannot be pre-defined.

Due to the growing in flow actions offload abilities there is a potential for the user to use variety of actions per color differently. This new meter policy API comes to allow this potential in the most ethdev common way using rte_flow action definition.
A list of rte_flow actions will be provided by the user per color in order to create a meter policy.
In addition, the API forces to pre-define the policy before the meters creation in order to allow sharing of single policy with multiple meters efficiently.

meter_policy_id is added into struct rte_mtr_params. So that it can get the policy during the meters creation.

Policy id 0 is default policy. Action per color as below:
green - nothing, yellow - nothing, red - drop

Allow coloring the packet using a new rte_flow_action_color as could be done by the old policy API,

The next API function were added:
- rte_mtr_meter_policy_create
- rte_mtr_meter_policy_delete
- rte_mtr_meter_policy_update
- rte_mtr_meter_policy_validate
The next struct was changed:
- rte_mtr_params
- rte_mtr_capabilities
The next API was deleted:
- rte_mtr_policer_actions_update

To support this API the following app were changed:
app/test-flow-perf: clean meter policer app/testpmd: clean meter policer

To support this API the following drivers were changed:
net/softnic: support meter policy API
1. cleans meter rte_mtr_policer_action.
2. Support policy API to get color action as policer action did. The color action will be mapped into rte_table_action_policer.
3. Create default policy if policy id is RTE_MTR_DEFAULT_POLICY_ID. default policy actoins:
green - do nothing, yellow - do nothing, red - drop

net/mlx5: clean meter creation management Cleans and breaks part of the current meter management in order to allow better design with policy API.

---
 app/test-flow-perf/main.c                     |   7 -
 app/test-pmd/cmdline.c                        |   1 -
 app/test-pmd/cmdline_mtr.c                    | 172 -------
 app/test-pmd/cmdline_mtr.h                    |   1 -
 doc/guides/rel_notes/release_20_11.rst        |   3 +
 drivers/net/mlx5/mlx5.h                       |  24 +-
 drivers/net/mlx5/mlx5_flow.c                  |  46 --
 drivers/net/mlx5/mlx5_flow.h                  |  18 +-
 drivers/net/mlx5/mlx5_flow_aso.c              |   8 +-
 drivers/net/mlx5/mlx5_flow_dv.c               | 461 +-----------------
 drivers/net/mlx5/mlx5_flow_meter.c            | 369 +-------------
 drivers/net/softnic/rte_eth_softnic_flow.c    |  19 +-
 .../net/softnic/rte_eth_softnic_internals.h   |  18 +-
 drivers/net/softnic/rte_eth_softnic_meter.c   | 303 +++++++++---
 lib/librte_ethdev/rte_flow.h                  |  18 +
 lib/librte_ethdev/rte_mtr.c                   |  55 ++-
 lib/librte_ethdev/rte_mtr.h                   | 166 +++++--
 lib/librte_ethdev/rte_mtr_driver.h            |  44 +-
 lib/librte_ethdev/version.map                 |   4 +
 19 files changed, 507 insertions(+), 1230 deletions(-)
app/test-flow-perf/main.c +0 -7
index 99d0463456..66ec776017 100644
@@ -924,13 +924,6 @@ create_meter_rule(int port_id, uint32_t counter)
 
 	/*create meter*/
 	params.meter_profile_id = default_prof_id;
-	params.action[RTE_COLOR_GREEN] =
-		MTR_POLICER_ACTION_COLOR_GREEN;
-	params.action[RTE_COLOR_YELLOW] =
-		MTR_POLICER_ACTION_COLOR_YELLOW;
-	params.action[RTE_COLOR_RED] =
-		MTR_POLICER_ACTION_DROP;
-
 	ret = rte_mtr_create(port_id, counter, &params, 1, &error);
 	if (ret != 0) {
 		printf("Port %u create meter idx(%d) error(%d) message: %s\n",
app/test-pmd/cmdline.c +0 -1
index 14110eb2e4..dcb5f9c871 100644
@@ -17069,7 +17069,6 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_del_port_meter,
 	(cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
 	(cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
-	(cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
 	(cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
 	(cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
app/test-pmd/cmdline_mtr.c +0 -172

196 lines not on this page · raw message

app/test-pmd/cmdline_mtr.h +0 -1
index e69d6da023..7e2713cea3 100644
@@ -17,7 +17,6 @@ extern cmdline_parse_inst_t cmd_disable_port_meter;
 extern cmdline_parse_inst_t cmd_del_port_meter;
 extern cmdline_parse_inst_t cmd_set_port_meter_profile;
 extern cmdline_parse_inst_t cmd_set_port_meter_dscp_table;
-extern cmdline_parse_inst_t cmd_set_port_meter_policer_action;
 extern cmdline_parse_inst_t cmd_set_port_meter_stats_mask;
 extern cmdline_parse_inst_t cmd_show_port_meter_stats;
 
doc/guides/rel_notes/release_20_11.rst +3 -0
index 7405a9864f..5a6839758a 100644
@@ -663,6 +663,9 @@ API Changes
 * sched: Removed ``tb_rate``, ``tc_rate``, ``tc_period`` and ``tb_size``
   from ``struct rte_sched_subport_params``.
 
+* ethdev: Added meter API to support pre-defined policy, rte_flow action list per color.
+  ``rte_mtr_meter_policy_create()``, ``rte_mtr_meter_policy_delete()`` and
+  ``rte_mtr_create_with_policy()``
 
 ABI Changes
 -----------
drivers/net/mlx5/mlx5.h +2 -22
index 08efa5d15d..b182fb6c19 100644
@@ -593,14 +593,6 @@ struct mlx5_dev_shared_port {
 /* Modify this value if enum rte_mtr_color changes. */
 #define RTE_MTR_DROPPED RTE_COLORS
 
-/* Meter policer statistics */
-struct mlx5_flow_policer_stats {
-	uint32_t pass_cnt;
-	/**< Color counter for pass. */
-	uint32_t drop_cnt;
-	/**< Color counter for drop. */
-};
-
 /* Meter table structure. */
 struct mlx5_meter_domain_info {
 	struct mlx5_flow_tbl_resource *tbl;
@@ -639,24 +631,12 @@ struct mlx5_meter_domains_infos {
 
 /* Meter parameter structure. */
 struct mlx5_flow_meter_info {
-	uint32_t meter_id;
-	/**< Meter id. */
 	struct mlx5_flow_meter_profile *profile;
 	/**< Meter profile parameters. */
 	rte_spinlock_t sl; /**< Meter action spinlock. */
-	/** Policer actions (per meter output color). */
-	enum rte_mtr_policer_action action[RTE_COLORS];
 	/** Set of stats counters to be enabled.
 	 * @see enum rte_mtr_stats_type
 	 */
-	uint32_t green_bytes:1;
-	/** Set green bytes stats to be enabled. */
-	uint32_t green_pkts:1;
-	/** Set green packets stats to be enabled. */
-	uint32_t red_bytes:1;
-	/** Set red bytes stats to be enabled. */
-	uint32_t red_pkts:1;
-	/** Set red packets stats to be enabled. */
 	uint32_t bytes_dropped:1;
 	/** Set bytes dropped stats to be enabled. */
 	uint32_t pkts_dropped:1;
@@ -691,8 +671,8 @@ struct mlx5_flow_meter_info {
 	uint32_t transfer:1;
 	struct mlx5_meter_domains_infos *mfts;
 	/**< Flow table created for this meter. */
-	struct mlx5_flow_policer_stats policer_stats;
-	/**< Meter policer statistics. */
+	uint32_t drop_cnt;
+	/**< Color counter for drop. */
 	uint32_t ref_cnt;
 	/**< Use count. */
 	struct mlx5_indexed_pool *flow_ipool;
drivers/net/mlx5/mlx5_flow.c +0 -46

52 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +2 -16
index 59e9ce2c9e..8e4530f32c 100644
@@ -838,6 +838,8 @@ struct mlx5_legacy_flow_meter {
 	/* Must be the first in struct. */
 	TAILQ_ENTRY(mlx5_legacy_flow_meter) next;
 	/**< Pointer to the next flow meter structure. */
+	uint32_t meter_id;
+	/**< Meter id. */
 	uint32_t idx; /* Index to meter object. */
 };
 
@@ -1077,14 +1079,6 @@ typedef struct mlx5_meter_domains_infos *(*mlx5_flow_create_mtr_tbls_t)
 					    (struct rte_eth_dev *dev);
 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)
-					(struct rte_eth_dev *dev,
-					 struct mlx5_flow_meter_info *fm,
-					 const struct rte_flow_attr *attr);
-typedef int (*mlx5_flow_destroy_policer_rules_t)
-					(struct rte_eth_dev *dev,
-					 const struct mlx5_flow_meter_info *fm,
-					 const struct rte_flow_attr *attr);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev,
@@ -1141,8 +1135,6 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_query_t query;
 	mlx5_flow_create_mtr_tbls_t create_mtr_tbls;
 	mlx5_flow_destroy_mtr_tbls_t destroy_mtr_tbls;
-	mlx5_flow_create_policer_rules_t prepare_policer_rules;
-	mlx5_flow_destroy_policer_rules_t destroy_policer_rules;
 	mlx5_flow_mtr_alloc_t create_meter;
 	mlx5_flow_mtr_free_t free_meter;
 	mlx5_flow_counter_alloc_t counter_alloc;
@@ -1372,12 +1364,6 @@ struct mlx5_meter_domains_infos *mlx5_flow_create_mtr_tbls
 					(struct rte_eth_dev *dev);
 int mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
 			       struct mlx5_meter_domains_infos *tbl);
-int mlx5_flow_prepare_policer_rules(struct rte_eth_dev *dev,
-				   struct mlx5_flow_meter_info *fm,
-				   const struct rte_flow_attr *attr);
-int mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
-				    struct mlx5_flow_meter_info *fm,
-				    const struct rte_flow_attr *attr);
 int mlx5_flow_meter_flush(struct rte_eth_dev *dev,
 			  struct rte_mtr_error *error);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
drivers/net/mlx5/mlx5_flow_aso.c +4 -4
index 712f655761..4d13743ecc 100644
@@ -809,8 +809,8 @@ mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh,
 		/* Waiting for wqe resource. */
 		usleep(MLX5_ASO_WQE_CQE_RESPONSE_DELAY);
 	} while (--poll_wqe_times);
-	DRV_LOG(ERR, "Fail to send WQE for ASO meter %d",
-			mtr->fm.meter_id);
+	DRV_LOG(ERR, "Fail to send WQE for ASO meter offset %d",
+			mtr->offset);
 	return -1;
 }
 
@@ -845,7 +845,7 @@ mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,
 		/* Waiting for CQE ready. */
 		usleep(MLX5_ASO_WQE_CQE_RESPONSE_DELAY);
 	} while (--poll_cqe_times);
-	DRV_LOG(ERR, "Fail to poll CQE ready for ASO meter %d",
-			mtr->fm.meter_id);
+	DRV_LOG(ERR, "Fail to poll CQE ready for ASO meter offset %d",
+			mtr->offset);
 	return -1;
 }
drivers/net/mlx5/mlx5_flow_dv.c +2 -459

501 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +11 -358

491 lines not on this page · raw message

drivers/net/softnic/rte_eth_softnic_flow.c +15 -4
index 7925bad1c0..27eaf380cd 100644
@@ -1166,6 +1166,7 @@ flow_rule_action_get(struct pmd_internals *softnic,
 {
 	struct softnic_table_action_profile *profile;
 	struct softnic_table_action_profile_params *params;
+	struct softnic_mtr_meter_policy *policy;
 	int n_jump_queue_rss_drop = 0;
 	int n_count = 0;
 	int n_mark = 0;
@@ -1621,15 +1622,25 @@ flow_rule_action_get(struct pmd_internals *softnic,
 					return -1;
 				}
 			}
-
+			/* Meter policy must exist */
+			policy = softnic_mtr_meter_policy_find(softnic,
+					m->params.meter_policy_id);
+			if (policy == NULL) {
+				rte_flow_error_set(error,
+						EINVAL,
+						RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						NULL,
+						"METER: fail to find meter policy");
+				return -1;
+			}
 			/* RTE_TABLE_ACTION_METER */
 			rule_action->mtr.mtr[0].meter_profile_id = meter_profile_id;
 			rule_action->mtr.mtr[0].policer[RTE_COLOR_GREEN] =
-				softnic_table_action_policer(m->params.action[RTE_COLOR_GREEN]);
+				policy->policer[RTE_COLOR_GREEN];
 			rule_action->mtr.mtr[0].policer[RTE_COLOR_YELLOW] =
-				softnic_table_action_policer(m->params.action[RTE_COLOR_YELLOW]);
+				policy->policer[RTE_COLOR_YELLOW];
 			rule_action->mtr.mtr[0].policer[RTE_COLOR_RED] =
-				softnic_table_action_policer(m->params.action[RTE_COLOR_RED]);
+				policy->policer[RTE_COLOR_RED];
 			rule_action->mtr.tc_mask = 1;
 			rule_action->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
 			break;
drivers/net/softnic/rte_eth_softnic_internals.h +15 -3
index faf90a5a8c..1b3186ef0b 100644
@@ -83,6 +83,16 @@ struct softnic_mtr_meter_profile {
 
 TAILQ_HEAD(softnic_mtr_meter_profile_list, softnic_mtr_meter_profile);
 
+/* MTR meter policy */
+struct softnic_mtr_meter_policy {
+	TAILQ_ENTRY(softnic_mtr_meter_policy) node;
+	uint32_t meter_policy_id;
+	enum rte_table_action_policer policer[RTE_COLORS];
+	uint32_t n_users;
+};
+
+TAILQ_HEAD(softnic_mtr_meter_policy_list, softnic_mtr_meter_policy);
+
 /* MTR meter object */
 struct softnic_mtr {
 	TAILQ_ENTRY(softnic_mtr) node;
@@ -95,6 +105,7 @@ TAILQ_HEAD(softnic_mtr_list, softnic_mtr);
 
 struct mtr_internals {
 	struct softnic_mtr_meter_profile_list meter_profiles;
+	struct softnic_mtr_meter_policy_list meter_policies;
 	struct softnic_mtr_list mtrs;
 };
 
@@ -678,6 +689,10 @@ struct softnic_mtr_meter_profile *
 softnic_mtr_meter_profile_find(struct pmd_internals *p,
 	uint32_t meter_profile_id);
 
+struct softnic_mtr_meter_policy *
+softnic_mtr_meter_policy_find(struct pmd_internals *p,
+	uint32_t meter_policy_id);
+
 extern const struct rte_mtr_ops pmd_mtr_ops;
 
 /**
@@ -841,9 +856,6 @@ softnic_table_action_profile_create(struct pmd_internals *p,
 	const char *name,
 	struct softnic_table_action_profile_params *params);
 
-enum rte_table_action_policer
-softnic_table_action_policer(enum rte_mtr_policer_action action);
-
 /**
  * Pipeline
  */
drivers/net/softnic/rte_eth_softnic_meter.c +240 -63

437 lines not on this page · raw message

lib/librte_ethdev/rte_flow.h +18 -0
index 6cc57136ac..60fede4983 100644
@@ -32,6 +32,7 @@
 #include <rte_ecpri.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
+#include <rte_meter.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -2267,6 +2268,13 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_modify_field.
 	 */
 	RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
+
+	/**
+	 * Color the packet to reflect the meter color result.
+	 *
+	 * See struct rte_flow_action_color.
+	 */
+	RTE_FLOW_ACTION_TYPE_METER_COLOR,
 };
 
 /**
@@ -2859,6 +2867,16 @@ struct rte_flow_action_set_dscp {
  */
 struct rte_flow_shared_action;
 
+/**
+ * RTE_FLOW_ACTION_TYPE_COLOR
+ *
+ * The meter color should be set in the packet meta-data
+ * (i.e. struct rte_mbuf::sched::color).
+ */
+struct rte_flow_action_color {
+	enum rte_color color; /**< Green/Yellow/Red. */
+};
+
 /**
  * Field IDs for MODIFY_FIELD action.
  */
lib/librte_ethdev/rte_mtr.c +44 -11

79 lines not on this page · raw message

lib/librte_ethdev/rte_mtr.h +113 -53

245 lines not on this page · raw message

lib/librte_ethdev/rte_mtr_driver.h +34 -10

72 lines not on this page · raw message

lib/librte_ethdev/version.map +4 -0
index 93ad388e96..a45834b87f 100644
@@ -246,6 +246,10 @@ EXPERIMENTAL {
 
 	# added in 21.05
 	rte_eth_representor_info_get;
+	rte_mtr_meter_policy_create;
+	rte_mtr_meter_policy_delete;
+	rte_mtr_meter_policy_update;
+	rte_mtr_meter_policy_validate;
 };
 
 INTERNAL {
Signature · 1 line
2.27.0
author
#2 lore raw

PATCH 2/2 app/testpmd: support policy actions per color

In reply to Li Zhang

From: Haifei Luo <[email protected]>

add the new create meter with policy API to support it.

---
 app/test-pmd/cmdline.c      |   6 +-
 app/test-pmd/cmdline_flow.c | 118 +++++++++++++++++++++++++++++++++++-
 app/test-pmd/cmdline_mtr.c  |  85 ++++++++++++++++++++++++--
 app/test-pmd/cmdline_mtr.h  |   3 +
 app/test-pmd/config.c       |  34 +++++++++++
 app/test-pmd/testpmd.h      |   2 +
 6 files changed, 240 insertions(+), 8 deletions(-)
app/test-pmd/cmdline.c +5 -1
index dcb5f9c871..029cb38786 100644
@@ -705,7 +705,7 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"del port meter profile (port_id) (profile_id)\n"
 			"    meter profile delete\n\n"
 
-			"create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
+			"create port meter (port_id) [mtr_id] (profile_id) [policy (policy_id)] (meter_enable)\n"
 			"(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
 			"(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
 			"(dscp_tbl_entry63)]\n"
@@ -720,6 +720,9 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"del port meter (port_id) (mtr_id)\n"
 			"    meter delete\n\n"
 
+			"del port meter policy (port_id) (policy_id)\n"
+			"    meter policy delete\n\n"
+
 			"set port meter profile (port_id) (mtr_id) (profile_id)\n"
 			"    meter update meter profile\n\n"
 
@@ -17067,6 +17070,7 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_enable_port_meter,
 	(cmdline_parse_inst_t *)&cmd_disable_port_meter,
 	(cmdline_parse_inst_t *)&cmd_del_port_meter,
+	(cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
 	(cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
 	(cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
 	(cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
app/test-pmd/cmdline_flow.c +117 -1

178 lines not on this page · raw message

app/test-pmd/cmdline_mtr.c +79 -6

140 lines not on this page · raw message

app/test-pmd/cmdline_mtr.h +3 -0
index 7e2713cea3..2415fc16c3 100644
@@ -4,6 +4,7 @@
 
 #ifndef _CMDLINE_MTR_H_
 #define _CMDLINE_MTR_H_
+#include <rte_mtr.h>
 
 /* Traffic Metering and Policing */
 extern cmdline_parse_inst_t cmd_show_port_meter_cap;
@@ -15,9 +16,11 @@ extern cmdline_parse_inst_t cmd_create_port_meter;
 extern cmdline_parse_inst_t cmd_enable_port_meter;
 extern cmdline_parse_inst_t cmd_disable_port_meter;
 extern cmdline_parse_inst_t cmd_del_port_meter;
+extern cmdline_parse_inst_t cmd_del_port_meter_policy;
 extern cmdline_parse_inst_t cmd_set_port_meter_profile;
 extern cmdline_parse_inst_t cmd_set_port_meter_dscp_table;
 extern cmdline_parse_inst_t cmd_set_port_meter_stats_mask;
 extern cmdline_parse_inst_t cmd_show_port_meter_stats;
+void print_mtr_err_msg(struct rte_mtr_error *error);
 
 #endif /* _CMDLINE_MTR_H_ */
app/test-pmd/config.c +34 -0
index ef0b9784d0..336b9b500e 100644
@@ -38,6 +38,7 @@
 #include <rte_string_fns.h>
 #include <rte_cycles.h>
 #include <rte_flow.h>
+#include <rte_mtr.h>
 #include <rte_errno.h>
 #ifdef RTE_NET_IXGBE
 #include <rte_pmd_ixgbe.h>
@@ -52,6 +53,7 @@
 #include <rte_hexdump.h>
 
 #include "testpmd.h"
+#include "cmdline_mtr.h"
 
 #define ETHDEV_FWVERS_LEN 32
 
@@ -1464,6 +1466,38 @@ action_alloc(portid_t port_id, uint32_t id,
 	return 0;
 }
 
+/** Add port meter policy */
+int
+port_meter_policy_add(portid_t port_id, uint32_t policy_id,
+			const struct rte_flow_action *actions)
+{
+	struct rte_mtr_error error;
+	const struct rte_flow_action *acts[RTE_COLORS];
+	const struct rte_flow_action *act = actions;
+	const struct rte_flow_action *start;
+	uint32_t i = 0, act_n;
+	int ret;
+
+	for (i = 0; i < RTE_COLORS; i++) {
+		for (act_n = 0, start = act;
+			act->type != RTE_FLOW_ACTION_TYPE_END; act++)
+			act_n++;
+		if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
+			acts[i] = start;
+		else
+			acts[i] = NULL;
+		act++;
+	}
+	ret = rte_mtr_meter_policy_create(port_id,
+			policy_id,
+			acts, &error);
+	if (ret) {
+		print_mtr_err_msg(&error);
+		return -1;
+	}
+	return policy_id;
+}
+
 /** Create shared action */
 int
 port_shared_action_create(portid_t port_id, uint32_t id,
app/test-pmd/testpmd.h +2 -0
index a87ccb0f0f..bc7cb7e9b9 100644
@@ -837,6 +837,8 @@ void port_flow_tunnel_list(portid_t port_id);
 void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id);
 void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops);
 int port_flow_isolate(portid_t port_id, int set);
+int port_meter_policy_add(portid_t port_id, uint32_t policy_id,
+		const struct rte_flow_action *actions);
 
 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id);
 void tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id);
Signature · 1 line
2.27.0
author
#3 lore raw

v2 cover Support meter policy API

In reply to Li Zhang

Currently, the flow meter policy does not support multiple actions per color; also the allowed action types per color are very limited. In addition, the policy cannot be pre-defined.

Due to the growing in flow actions offload abilities there is a potential for the user to use variety of actions per color differently. This new meter policy API comes to allow this potential in the most ethdev common way using rte_flow action definition.
A list of rte_flow actions will be provided by the user per color in order to create a meter policy.
In addition, the API forces to pre-define the policy before the meters creation in order to allow sharing of single policy with multiple meters efficiently.

meter_policy_id is added into struct rte_mtr_params. So that it can get the policy during the meters creation.

RFC ("ethdev: add pre-defined meter policy API")
https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/

V2: Delete default policy and change relation doc files.

Haifei Luo (1):
app/testpmd: support policy actions per color

Li Zhang (1):
ethdev: add pre-defined meter policy API

 app/test-flow-perf/main.c                     |   7 -
 app/test-pmd/cmdline.c                        |   7 +-
 app/test-pmd/cmdline_flow.c                   | 118 ++++-
 app/test-pmd/cmdline_mtr.c                    | 257 +++-------
 app/test-pmd/cmdline_mtr.h                    |   4 +-
 app/test-pmd/config.c                         |  34 ++
 app/test-pmd/testpmd.h                        |   2 +
 doc/guides/nics/mlx5.rst                      |  12 +
 doc/guides/prog_guide/rte_flow.rst            |  20 +
 .../traffic_metering_and_policing.rst         |   9 +-
 doc/guides/rel_notes/release_21_05.rst        |  14 +-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst   |  18 -
 drivers/net/mlx5/mlx5.h                       |  24 +-
 drivers/net/mlx5/mlx5_flow.c                  |  46 --
 drivers/net/mlx5/mlx5_flow.h                  |  18 +-
 drivers/net/mlx5/mlx5_flow_aso.c              |  15 +-
 drivers/net/mlx5/mlx5_flow_dv.c               | 463 +-----------------
 drivers/net/mlx5/mlx5_flow_meter.c            | 369 +-------------
 drivers/net/softnic/rte_eth_softnic_flow.c    |  19 +-
 .../net/softnic/rte_eth_softnic_internals.h   |  18 +-
 drivers/net/softnic/rte_eth_softnic_meter.c   | 264 +++++++---
 lib/librte_ethdev/rte_flow.h                  |  18 +
 lib/librte_ethdev/rte_mtr.c                   |  55 ++-
 lib/librte_ethdev/rte_mtr.h                   | 157 ++++--
 lib/librte_ethdev/rte_mtr_driver.h            |  44 +-
 lib/librte_ethdev/version.map                 |   4 +
 26 files changed, 750 insertions(+), 1266 deletions(-)
Signature · 1 line
2.27.0
author
#4 lore raw

PATCH v2 1/2 ethdev: add pre-defined meter policy API

Currently, the flow meter policy does not support multiple actions per color; also the allowed action types per color are very limited. In addition, the policy cannot be pre-defined.

Due to the growing in flow actions offload abilities there is a potential for the user to use variety of actions per color differently. This new meter policy API comes to allow this potential in the most ethdev common way using rte_flow action definition.
A list of rte_flow actions will be provided by the user per color in order to create a meter policy.
In addition, the API forces to pre-define the policy before the meters creation in order to allow sharing of single policy with multiple meters efficiently.

meter_policy_id is added into struct rte_mtr_params. So that it can get the policy during the meters creation.

Policy id 0 is default policy. Action per color as below:
green - nothing, yellow - nothing, red - drop

Allow coloring the packet using a new rte_flow_action_color as could be done by the old policy API,

The next API function were added:
- rte_mtr_meter_policy_create
- rte_mtr_meter_policy_delete
- rte_mtr_meter_policy_update
- rte_mtr_meter_policy_validate
The next struct was changed:
- rte_mtr_params
- rte_mtr_capabilities
The next API was deleted:
- rte_mtr_policer_actions_update

To support this API the following app were changed:
app/test-flow-perf: clean meter policer app/testpmd: clean meter policer

To support this API the following drivers were changed:
net/softnic: support meter policy API
1. cleans meter rte_mtr_policer_action.
2. Support policy API to get color action as policer action did. The color action will be mapped into rte_table_action_policer.
3. Create default policy if policy id is RTE_MTR_DEFAULT_POLICY_ID. default policy actoins:
green - do nothing, yellow - do nothing, red - drop

net/mlx5: clean meter creation management Cleans and breaks part of the current meter management in order to allow better design with policy API.

---
 app/test-flow-perf/main.c                     |   7 -
 app/test-pmd/cmdline.c                        |   1 -
 app/test-pmd/cmdline_mtr.c                    | 172 -------
 app/test-pmd/cmdline_mtr.h                    |   1 -
 doc/guides/nics/mlx5.rst                      |  12 +
 doc/guides/prog_guide/rte_flow.rst            |  20 +
 .../traffic_metering_and_policing.rst         |   9 +-
 doc/guides/rel_notes/release_21_05.rst        |  14 +-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst   |  18 -
 drivers/net/mlx5/mlx5.h                       |  24 +-
 drivers/net/mlx5/mlx5_flow.c                  |  46 --
 drivers/net/mlx5/mlx5_flow.h                  |  18 +-
 drivers/net/mlx5/mlx5_flow_aso.c              |  15 +-
 drivers/net/mlx5/mlx5_flow_dv.c               | 463 +-----------------
 drivers/net/mlx5/mlx5_flow_meter.c            | 369 +-------------
 drivers/net/softnic/rte_eth_softnic_flow.c    |  19 +-
 .../net/softnic/rte_eth_softnic_internals.h   |  18 +-
 drivers/net/softnic/rte_eth_softnic_meter.c   | 264 +++++++---
 lib/librte_ethdev/rte_flow.h                  |  18 +
 lib/librte_ethdev/rte_mtr.c                   |  55 ++-
 lib/librte_ethdev/rte_mtr.h                   | 157 ++++--
 lib/librte_ethdev/rte_mtr_driver.h            |  44 +-
 lib/librte_ethdev/version.map                 |   4 +
 23 files changed, 510 insertions(+), 1258 deletions(-)
app/test-flow-perf/main.c +0 -7
index 99d0463456..66ec776017 100644
@@ -924,13 +924,6 @@ create_meter_rule(int port_id, uint32_t counter)
 
 	/*create meter*/
 	params.meter_profile_id = default_prof_id;
-	params.action[RTE_COLOR_GREEN] =
-		MTR_POLICER_ACTION_COLOR_GREEN;
-	params.action[RTE_COLOR_YELLOW] =
-		MTR_POLICER_ACTION_COLOR_YELLOW;
-	params.action[RTE_COLOR_RED] =
-		MTR_POLICER_ACTION_DROP;
-
 	ret = rte_mtr_create(port_id, counter, &params, 1, &error);
 	if (ret != 0) {
 		printf("Port %u create meter idx(%d) error(%d) message: %s\n",
app/test-pmd/cmdline.c +0 -1
index 14110eb2e4..dcb5f9c871 100644
@@ -17069,7 +17069,6 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_del_port_meter,
 	(cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
 	(cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
-	(cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
 	(cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
 	(cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
app/test-pmd/cmdline_mtr.c +0 -172

196 lines not on this page · raw message

app/test-pmd/cmdline_mtr.h +0 -1
index e69d6da023..7e2713cea3 100644
@@ -17,7 +17,6 @@ extern cmdline_parse_inst_t cmd_disable_port_meter;
 extern cmdline_parse_inst_t cmd_del_port_meter;
 extern cmdline_parse_inst_t cmd_set_port_meter_profile;
 extern cmdline_parse_inst_t cmd_set_port_meter_dscp_table;
-extern cmdline_parse_inst_t cmd_set_port_meter_policer_action;
 extern cmdline_parse_inst_t cmd_set_port_meter_stats_mask;
 extern cmdline_parse_inst_t cmd_show_port_meter_stats;
 
doc/guides/nics/mlx5.rst +12 -0
index fa63e62a5d..6e9a68baf5 100644
@@ -106,6 +106,7 @@ Features
 - E-Switch mirroring and modify.
 - 21844 flow priorities for ingress or egress flow groups greater than 0 and for any transfer
   flow group.
+- Flow metering, including meter policy API.
 
 Limitations
 -----------
@@ -403,6 +404,17 @@ Limitations
   - Green color is not supported with drop action.
   - Yellow detection is not supported.
   - Red color must be with drop action.
+  - Meter statistics are supported only for drop case.
+  - Meter yellow color detection is not supported.
+  - A meter action created with pre-defined policy must be the last action in the
+    flow except single case where the policy actions are
+    green: NULL or END,
+    yellow: NULL or END,
+    RED: DROP / END.
+  - The only supported meter policy actions:
+    green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG.
+    yellow: must be empty.
+    red: must be DROP.
 
 Statistics
 ----------
doc/guides/prog_guide/rte_flow.rst +20 -0
index aec2ba1ec0..63bc1ea075 100644
@@ -2834,6 +2834,26 @@ for ``RTE_FLOW_FIELD_VALUE`` and ``RTE_FLOW_FIELD_POINTER`` respectively.
    | ``value``     | immediate value or a pointer to this value               |
    +---------------+----------------------------------------------------------+
 
+Action: ``METER_COLOR``
+^^^^^^^^^^^^^^^^^
+
+Color the packet to reflect the meter color result.
+
+The meter action must be configured before meter color action.
+Meter color action is set to a color to reflect the meter color result.
+The meter color action output color is the output color of the packet,
+which is set in the packet meta-data (i.e. struct ``rte_mbuf::sched::color``)
+
+.. _table_rte_flow_action_meter_color:
+
+.. table:: METER_COLOR
+
+   +-----------------+--------------+
+   | Field           | Value        |
+   +=================+==============+
+   | ``meter_color`` | Packet color |
+   +-----------------+--------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
doc/guides/prog_guide/traffic_metering_and_policing.rst +6 -3
index 90c781eb1d..87b1ea6d2f 100644
@@ -56,10 +56,13 @@ The processing done for each input packet hitting an MTR object is:
   color blind mode, which is equivalent to considering all input packets
   initially colored as green.
 
-* Policing: There is a separate policer action configured for each meter
-  output color, which can:
+* Policing: There is the meter policy for the user to use variety of actions
+  per meter output color differently. A list of rte_flow actions will be
+  provided by the user per color in the policy. Action per color in policy
+  as one example: green - do nothing, yellow - do nothing, red - drop.
 
-  * Drop the packet.
+  There is a meter_color action configured by rte_flow_action_meter_color
+  for each meter output color, which can:
 
   * Keep the same packet color: the policer output color matches the meter
     output color (essentially a no-op action).
doc/guides/rel_notes/release_21_05.rst +13 -1
index 3c76148b11..ca600a8fea 100644
@@ -118,7 +118,19 @@ New Features
     ``dpdk-testpmd -- --eth-link-speed N``
   * Added command to display Rx queue used descriptor count.
     ``show port (port_id) rxq (queue_id) desc used count``
-
+  * deleted the port meter policer action command .
+    ``set port meter policer action (port_id) (mtr_id) (action_mask) ...``
+  * Added command to create meter policy.
+    ``add port meter policy (port_id) (policy_id) g_actions {action} end y_actions {action} end r_actions {action} end``
+  * Added command to delete meter policy.
+    ``del port meter policy (port_id) (policy_id)``
+
+* **Updated meter API. **
+  * ethdev: Deleted meter policer API to support policy API
+    ``rte_mtr_policer_actions_update()``
+  * ethdev: Added meter API to support pre-defined policy, rte_flow action list per color.
+    ``rte_mtr_meter_policy_create()``, ``rte_mtr_meter_policy_delete()`` and
+    ``rte_mtr_create_with_policy()``
 
 Removed Items
 -------------
doc/guides/testpmd_app_ug/testpmd_funcs.rst +0 -18
index f59eb8a27d..59d2931e82 100644
@@ -2812,24 +2812,6 @@ Set meter dscp table for the ethernet device::
    testpmd> set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0) \
    (dscp_tbl_entry1)...(dscp_tbl_entry63)]
 
-set port meter policer action
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Set meter policer action for the ethernet device::
-
-   testpmd> set port meter policer action (port_id) (mtr_id) (action_mask) \
-   (action0) [(action1) (action1)]
-
-where:
-
-* ``action_mask``: Bit mask indicating which policer actions need to be
-  updated. One or more policer actions can be updated in a single function
-  invocation. To update the policer action associated with color C, bit
-  (1 << C) needs to be set in *action_mask* and element at position C
-  in the *actions* array needs to be valid.
-* ``actionx``: Policer action for the color x,
-  RTE_MTR_GREEN <= x < RTE_MTR_COLORS
-
 set port meter stats mask
 ~~~~~~~~~~~~~~~~~~~~~~~~~
 
drivers/net/mlx5/mlx5.h +2 -22
index 08efa5d15d..b182fb6c19 100644
@@ -593,14 +593,6 @@ struct mlx5_dev_shared_port {
 /* Modify this value if enum rte_mtr_color changes. */
 #define RTE_MTR_DROPPED RTE_COLORS
 
-/* Meter policer statistics */
-struct mlx5_flow_policer_stats {
-	uint32_t pass_cnt;
-	/**< Color counter for pass. */
-	uint32_t drop_cnt;
-	/**< Color counter for drop. */
-};
-
 /* Meter table structure. */
 struct mlx5_meter_domain_info {
 	struct mlx5_flow_tbl_resource *tbl;
@@ -639,24 +631,12 @@ struct mlx5_meter_domains_infos {
 
 /* Meter parameter structure. */
 struct mlx5_flow_meter_info {
-	uint32_t meter_id;
-	/**< Meter id. */
 	struct mlx5_flow_meter_profile *profile;
 	/**< Meter profile parameters. */
 	rte_spinlock_t sl; /**< Meter action spinlock. */
-	/** Policer actions (per meter output color). */
-	enum rte_mtr_policer_action action[RTE_COLORS];
 	/** Set of stats counters to be enabled.
 	 * @see enum rte_mtr_stats_type
 	 */
-	uint32_t green_bytes:1;
-	/** Set green bytes stats to be enabled. */
-	uint32_t green_pkts:1;
-	/** Set green packets stats to be enabled. */
-	uint32_t red_bytes:1;
-	/** Set red bytes stats to be enabled. */
-	uint32_t red_pkts:1;
-	/** Set red packets stats to be enabled. */
 	uint32_t bytes_dropped:1;
 	/** Set bytes dropped stats to be enabled. */
 	uint32_t pkts_dropped:1;
@@ -691,8 +671,8 @@ struct mlx5_flow_meter_info {
 	uint32_t transfer:1;
 	struct mlx5_meter_domains_infos *mfts;
 	/**< Flow table created for this meter. */
-	struct mlx5_flow_policer_stats policer_stats;
-	/**< Meter policer statistics. */
+	uint32_t drop_cnt;
+	/**< Color counter for drop. */
 	uint32_t ref_cnt;
 	/**< Use count. */
 	struct mlx5_indexed_pool *flow_ipool;
drivers/net/mlx5/mlx5_flow.c +0 -46

52 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +2 -16
index 59e9ce2c9e..8e4530f32c 100644
@@ -838,6 +838,8 @@ struct mlx5_legacy_flow_meter {
 	/* Must be the first in struct. */
 	TAILQ_ENTRY(mlx5_legacy_flow_meter) next;
 	/**< Pointer to the next flow meter structure. */
+	uint32_t meter_id;
+	/**< Meter id. */
 	uint32_t idx; /* Index to meter object. */
 };
 
@@ -1077,14 +1079,6 @@ typedef struct mlx5_meter_domains_infos *(*mlx5_flow_create_mtr_tbls_t)
 					    (struct rte_eth_dev *dev);
 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)
-					(struct rte_eth_dev *dev,
-					 struct mlx5_flow_meter_info *fm,
-					 const struct rte_flow_attr *attr);
-typedef int (*mlx5_flow_destroy_policer_rules_t)
-					(struct rte_eth_dev *dev,
-					 const struct mlx5_flow_meter_info *fm,
-					 const struct rte_flow_attr *attr);
 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
 					    (struct rte_eth_dev *dev);
 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev,
@@ -1141,8 +1135,6 @@ struct mlx5_flow_driver_ops {
 	mlx5_flow_query_t query;
 	mlx5_flow_create_mtr_tbls_t create_mtr_tbls;
 	mlx5_flow_destroy_mtr_tbls_t destroy_mtr_tbls;
-	mlx5_flow_create_policer_rules_t prepare_policer_rules;
-	mlx5_flow_destroy_policer_rules_t destroy_policer_rules;
 	mlx5_flow_mtr_alloc_t create_meter;
 	mlx5_flow_mtr_free_t free_meter;
 	mlx5_flow_counter_alloc_t counter_alloc;
@@ -1372,12 +1364,6 @@ struct mlx5_meter_domains_infos *mlx5_flow_create_mtr_tbls
 					(struct rte_eth_dev *dev);
 int mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
 			       struct mlx5_meter_domains_infos *tbl);
-int mlx5_flow_prepare_policer_rules(struct rte_eth_dev *dev,
-				   struct mlx5_flow_meter_info *fm,
-				   const struct rte_flow_attr *attr);
-int mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
-				    struct mlx5_flow_meter_info *fm,
-				    const struct rte_flow_attr *attr);
 int mlx5_flow_meter_flush(struct rte_eth_dev *dev,
 			  struct rte_mtr_error *error);
 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
drivers/net/mlx5/mlx5_flow_aso.c +7 -8
index 8d08d940b6..4d13743ecc 100644
@@ -1,8 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright 2020 Mellanox Technologies, Ltd
  */
-#include <unistd.h>
-
 #include <mlx5_prm.h>
 #include <rte_malloc.h>
 #include <rte_cycles.h>
@@ -15,6 +13,7 @@
 #include "mlx5.h"
 #include "mlx5_flow.h"
 
+
 /**
  * Destroy Completion Queue used for ASO access.
  *
@@ -313,7 +312,7 @@ mlx5_aso_queue_init(struct mlx5_dev_ctx_shared *sh,
 		mlx5_aso_age_init_sq(&sh->aso_age_mng->aso_sq);
 		break;
 	case ASO_OPC_MOD_POLICER:
-		if (mlx5_aso_sq_create(sh->ctx, &sh->mtrmng->sq, 0,
+		if (mlx5_aso_sq_create(sh->ctx,&sh->mtrmng->sq, 0,
 				  sh->tx_uar, sh->pdn, MLX5_ASO_QUEUE_LOG_DESC,
 				  sh->sq_ts_format))
 			return -1;
@@ -729,7 +728,7 @@ mlx5_aso_mtrs_status_update(struct mlx5_aso_sq *sq, uint16_t aso_mtrs_nums)
 	for (i = 0; i < aso_mtrs_nums; ++i) {
 		aso_mtr = sq->elts[(sq->tail + i) & mask].mtr;
 		MLX5_ASSERT(aso_mtr);
-		(void)__atomic_compare_exchange_n(&aso_mtr->state,
+		__atomic_compare_exchange_n(&aso_mtr->state,
 				&exp_state, ASO_METER_READY,
 				false, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
 	}
@@ -810,8 +809,8 @@ mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh,
 		/* Waiting for wqe resource. */
 		usleep(MLX5_ASO_WQE_CQE_RESPONSE_DELAY);
 	} while (--poll_wqe_times);
-	DRV_LOG(ERR, "Fail to send WQE for ASO meter %d",
-			mtr->fm.meter_id);
+	DRV_LOG(ERR, "Fail to send WQE for ASO meter offset %d",
+			mtr->offset);
 	return -1;
 }
 
@@ -846,7 +845,7 @@ mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,
 		/* Waiting for CQE ready. */
 		usleep(MLX5_ASO_WQE_CQE_RESPONSE_DELAY);
 	} while (--poll_cqe_times);
-	DRV_LOG(ERR, "Fail to poll CQE ready for ASO meter %d",
-			mtr->fm.meter_id);
+	DRV_LOG(ERR, "Fail to poll CQE ready for ASO meter offset %d",
+			mtr->offset);
 	return -1;
 }
drivers/net/mlx5/mlx5_flow_dv.c +2 -461

511 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_meter.c +11 -358

491 lines not on this page · raw message

drivers/net/softnic/rte_eth_softnic_flow.c +15 -4
index 7925bad1c0..27eaf380cd 100644
@@ -1166,6 +1166,7 @@ flow_rule_action_get(struct pmd_internals *softnic,
 {
 	struct softnic_table_action_profile *profile;
 	struct softnic_table_action_profile_params *params;
+	struct softnic_mtr_meter_policy *policy;
 	int n_jump_queue_rss_drop = 0;
 	int n_count = 0;
 	int n_mark = 0;
@@ -1621,15 +1622,25 @@ flow_rule_action_get(struct pmd_internals *softnic,
 					return -1;
 				}
 			}
-
+			/* Meter policy must exist */
+			policy = softnic_mtr_meter_policy_find(softnic,
+					m->params.meter_policy_id);
+			if (policy == NULL) {
+				rte_flow_error_set(error,
+						EINVAL,
+						RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+						NULL,
+						"METER: fail to find meter policy");
+				return -1;
+			}
 			/* RTE_TABLE_ACTION_METER */
 			rule_action->mtr.mtr[0].meter_profile_id = meter_profile_id;
 			rule_action->mtr.mtr[0].policer[RTE_COLOR_GREEN] =
-				softnic_table_action_policer(m->params.action[RTE_COLOR_GREEN]);
+				policy->policer[RTE_COLOR_GREEN];
 			rule_action->mtr.mtr[0].policer[RTE_COLOR_YELLOW] =
-				softnic_table_action_policer(m->params.action[RTE_COLOR_YELLOW]);
+				policy->policer[RTE_COLOR_YELLOW];
 			rule_action->mtr.mtr[0].policer[RTE_COLOR_RED] =
-				softnic_table_action_policer(m->params.action[RTE_COLOR_RED]);
+				policy->policer[RTE_COLOR_RED];
 			rule_action->mtr.tc_mask = 1;
 			rule_action->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
 			break;
drivers/net/softnic/rte_eth_softnic_internals.h +15 -3
index faf90a5a8c..1b3186ef0b 100644
@@ -83,6 +83,16 @@ struct softnic_mtr_meter_profile {
 
 TAILQ_HEAD(softnic_mtr_meter_profile_list, softnic_mtr_meter_profile);
 
+/* MTR meter policy */
+struct softnic_mtr_meter_policy {
+	TAILQ_ENTRY(softnic_mtr_meter_policy) node;
+	uint32_t meter_policy_id;
+	enum rte_table_action_policer policer[RTE_COLORS];
+	uint32_t n_users;
+};
+
+TAILQ_HEAD(softnic_mtr_meter_policy_list, softnic_mtr_meter_policy);
+
 /* MTR meter object */
 struct softnic_mtr {
 	TAILQ_ENTRY(softnic_mtr) node;
@@ -95,6 +105,7 @@ TAILQ_HEAD(softnic_mtr_list, softnic_mtr);
 
 struct mtr_internals {
 	struct softnic_mtr_meter_profile_list meter_profiles;
+	struct softnic_mtr_meter_policy_list meter_policies;
 	struct softnic_mtr_list mtrs;
 };
 
@@ -678,6 +689,10 @@ struct softnic_mtr_meter_profile *
 softnic_mtr_meter_profile_find(struct pmd_internals *p,
 	uint32_t meter_profile_id);
 
+struct softnic_mtr_meter_policy *
+softnic_mtr_meter_policy_find(struct pmd_internals *p,
+	uint32_t meter_policy_id);
+
 extern const struct rte_mtr_ops pmd_mtr_ops;
 
 /**
@@ -841,9 +856,6 @@ softnic_table_action_profile_create(struct pmd_internals *p,
 	const char *name,
 	struct softnic_table_action_profile_params *params);
 
-enum rte_table_action_policer
-softnic_table_action_policer(enum rte_mtr_policer_action action);
-
 /**
  * Pipeline
  */
drivers/net/softnic/rte_eth_softnic_meter.c +201 -63

396 lines not on this page · raw message

lib/librte_ethdev/rte_flow.h +18 -0
index 6cc57136ac..0c5807deea 100644
@@ -32,6 +32,7 @@
 #include <rte_ecpri.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
+#include <rte_meter.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -2267,6 +2268,13 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_modify_field.
 	 */
 	RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
+
+	/**
+	 * Color the packet to reflect the meter color result.
+	 *
+	 * See struct rte_flow_action_meter_color.
+	 */
+	RTE_FLOW_ACTION_TYPE_METER_COLOR,
 };
 
 /**
@@ -2859,6 +2867,16 @@ struct rte_flow_action_set_dscp {
  */
 struct rte_flow_shared_action;
 
+/**
+ * RTE_FLOW_ACTION_TYPE_COLOR
+ *
+ * The meter color should be set in the packet meta-data
+ * (i.e. struct rte_mbuf::sched::color).
+ */
+struct rte_flow_action_meter_color {
+	enum rte_color color; /**< Packet color. */
+};
+
 /**
  * Field IDs for MODIFY_FIELD action.
  */
lib/librte_ethdev/rte_mtr.c +44 -11

79 lines not on this page · raw message

lib/librte_ethdev/rte_mtr.h +104 -53

236 lines not on this page · raw message

lib/librte_ethdev/rte_mtr_driver.h +34 -10

72 lines not on this page · raw message

lib/librte_ethdev/version.map +4 -0
index 93ad388e96..a45834b87f 100644
@@ -246,6 +246,10 @@ EXPERIMENTAL {
 
 	# added in 21.05
 	rte_eth_representor_info_get;
+	rte_mtr_meter_policy_create;
+	rte_mtr_meter_policy_delete;
+	rte_mtr_meter_policy_update;
+	rte_mtr_meter_policy_validate;
 };
 
 INTERNAL {
Signature · 1 line
2.27.0
#5 lore raw

Re: [dpdk-dev] [PATCH v2 1/2] ethdev: add pre-defined meter policy API

Hi Li,

Quoted 102 lines

-----Original Message-----
From: Li Zhang <[email protected]>
Sent: Friday, April 2, 2021 1:36 PM
Subject: [PATCH v2 1/2] ethdev: add pre-defined meter policy API

Currently, the flow meter policy does not support multiple actions per color; also the allowed action types per color are very limited. In addition, the policy cannot be pre-defined.

Due to the growing in flow actions offload abilities there is a potential for the user to use variety of actions per color differently. This new meter policy API comes to allow this potential in the most ethdev common way using rte_flow action definition.
A list of rte_flow actions will be provided by the user per color in order to create a meter policy.
In addition, the API forces to pre-define the policy before the meters creation in order to allow sharing of single policy with multiple meters efficiently.

meter_policy_id is added into struct rte_mtr_params. So that it can get the policy during the meters creation.

Policy id 0 is default policy. Action per color as below:
green - nothing, yellow - nothing, red - drop

Allow coloring the packet using a new rte_flow_action_color as could be done by the old policy API,

The next API function were added:
- rte_mtr_meter_policy_create
- rte_mtr_meter_policy_delete
- rte_mtr_meter_policy_update
- rte_mtr_meter_policy_validate
The next struct was changed:
- rte_mtr_params
- rte_mtr_capabilities
The next API was deleted:
- rte_mtr_policer_actions_update

To support this API the following app were changed:
app/test-flow-perf: clean meter policer app/testpmd: clean meter policer

To support this API the following drivers were changed:
net/softnic: support meter policy API
1. cleans meter rte_mtr_policer_action.
2. Support policy API to get color action as policer action did. The color action will be mapped into rte_table_action_policer.
3. Create default policy if policy id is RTE_MTR_DEFAULT_POLICY_ID. default policy actoins:
green - do nothing, yellow - do nothing, red - drop

net/mlx5: clean meter creation management Cleans and breaks part of the current meter management in order to allow better design with policy API.

---
 app/test-flow-perf/main.c                     |   7 -
 app/test-pmd/cmdline.c                        |   1 -
 app/test-pmd/cmdline_mtr.c                    | 172 -------
 app/test-pmd/cmdline_mtr.h                    |   1 -
 doc/guides/nics/mlx5.rst                      |  12 +
 doc/guides/prog_guide/rte_flow.rst            |  20 +
 .../traffic_metering_and_policing.rst         |   9 +-
 doc/guides/rel_notes/release_21_05.rst        |  14 +-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst   |  18 -
 drivers/net/mlx5/mlx5.h                       |  24 +-
 drivers/net/mlx5/mlx5_flow.c                  |  46 --
 drivers/net/mlx5/mlx5_flow.h                  |  18 +-
 drivers/net/mlx5/mlx5_flow_aso.c              |  15 +-
 drivers/net/mlx5/mlx5_flow_dv.c               | 463 +-----------------
 drivers/net/mlx5/mlx5_flow_meter.c            | 369 +-------------
 drivers/net/softnic/rte_eth_softnic_flow.c    |  19 +-
 .../net/softnic/rte_eth_softnic_internals.h   |  18 +-
 drivers/net/softnic/rte_eth_softnic_meter.c   | 264 +++++++---
 lib/librte_ethdev/rte_flow.h                  |  18 +
 lib/librte_ethdev/rte_mtr.c                   |  55 ++-
 lib/librte_ethdev/rte_mtr.h                   | 157 ++++--
 lib/librte_ethdev/rte_mtr_driver.h            |  44 +-
 lib/librte_ethdev/version.map                 |   4 +
 23 files changed, 510 insertions(+), 1258 deletions(-)
app/test-flow-perf/main.c +0 -7
index 99d0463456..66ec776017 100644
@@ -924,13 +924,6 @@ create_meter_rule(int port_id, uint32_t counter)
 
 	/*create meter*/
 	params.meter_profile_id = default_prof_id;
-	params.action[RTE_COLOR_GREEN] =
-		MTR_POLICER_ACTION_COLOR_GREEN;
-	params.action[RTE_COLOR_YELLOW] =
-		MTR_POLICER_ACTION_COLOR_YELLOW;
-	params.action[RTE_COLOR_RED] =
-		MTR_POLICER_ACTION_DROP;
-
 	ret = rte_mtr_create(port_id, counter, &params, 1, &error);
 	if (ret != 0) {
 		printf("Port %u create meter idx(%d) error(%d) message:
Quoted 1 line

%s\n",

,

[snip]

Quoted 15 lines
app/test-flow-perf/main.c +0 -0
 	.stats_read = pmd_mtr_stats_read,
lib/librte_ethdev/rte_flow.h +1 -0
index 6cc57136ac..0c5807deea 100644
@@ -32,6 +32,7 @@
 #include <rte_ecpri.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
+#include <rte_meter.h>
 
 #ifdef __cplusplus
 extern "C" {

lib/librte_ethdev/rte_flow.h enum rte_flow_action_type { · line 2277

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +7 -0
@@ -2267,6 +2268,13 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_modify_field.
 	 */
 	RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
+
+	/**
+	 * Color the packet to reflect the meter color result.
+	 *
+	 * See struct rte_flow_action_meter_color.
+	 */
+	RTE_FLOW_ACTION_TYPE_METER_COLOR,

Following previous discussion in the ML
I agree to this change with few comments:
1. This action will be experimental and we might change it later to adjust to other rte_flow actions.
2. please make sure in the doc and comment above that it is documented That this goes to mbuf field
Something like:
Set the meter color in the mbuf to the selected color. Since it doesn't color the packet for the rest of the rte_flow.

[snip]
Best
Ori

author
#6 lore raw

Re: [dpdk-dev] [PATCH v2 1/2] ethdev: add pre-defined meter policy API

Hi Ori,

Thank you for your comments.
I will add it into V3 patch.

Regards,
Li Zhang

Quoted 163 lines

-----Original Message-----
From: Ori Kam <[email protected]>
Sent: Thursday, April 8, 2021 9:55 PM
To: Li Zhang <[email protected]>; [email protected]; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; [email protected]; [email protected]; Wisam Monther <[email protected]>; Xiaoyun Li <[email protected]>; Jasvinder Singh <[email protected]>; NBU- Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>; Ray Kinsella <[email protected]>; Neil Horman <[email protected]>
Cc: [email protected]; Raslan Darawsheh <[email protected]>; Roni Bar Yanai <[email protected]>; Haifei Luo <[email protected]>
Subject: RE: [PATCH v2 1/2] ethdev: add pre-defined meter policy API

Hi Li,

Quoted 102 lines

-----Original Message-----
From: Li Zhang <[email protected]>
Sent: Friday, April 2, 2021 1:36 PM
Subject: [PATCH v2 1/2] ethdev: add pre-defined meter policy API

Currently, the flow meter policy does not support multiple actions per color; also the allowed action types per color are very limited. In addition, the policy cannot be pre-defined.

Due to the growing in flow actions offload abilities there is a potential for the user to use variety of actions per color differently. This new meter policy API comes to allow this potential in the most ethdev common way using rte_flow action definition.
A list of rte_flow actions will be provided by the user per color in order to create a meter policy.
In addition, the API forces to pre-define the policy before the meters creation in order to allow sharing of single policy with multiple meters efficiently.

meter_policy_id is added into struct rte_mtr_params. So that it can get the policy during the meters creation.

Policy id 0 is default policy. Action per color as below:
green - nothing, yellow - nothing, red - drop

Allow coloring the packet using a new rte_flow_action_color as could be done by the old policy API,

The next API function were added:
- rte_mtr_meter_policy_create
- rte_mtr_meter_policy_delete
- rte_mtr_meter_policy_update
- rte_mtr_meter_policy_validate
The next struct was changed:
- rte_mtr_params
- rte_mtr_capabilities
The next API was deleted:
- rte_mtr_policer_actions_update

To support this API the following app were changed:
app/test-flow-perf: clean meter policer app/testpmd: clean meter policer

To support this API the following drivers were changed:
net/softnic: support meter policy API
1. cleans meter rte_mtr_policer_action.
2. Support policy API to get color action as policer action did. The color action will be mapped into rte_table_action_policer.
3. Create default policy if policy id is RTE_MTR_DEFAULT_POLICY_ID. default policy actoins:
green - do nothing, yellow - do nothing, red - drop

net/mlx5: clean meter creation management Cleans and breaks part of the current meter management in order to allow better design with policy API.

---
 app/test-flow-perf/main.c                     |   7 -
 app/test-pmd/cmdline.c                        |   1 -
 app/test-pmd/cmdline_mtr.c                    | 172 -------
 app/test-pmd/cmdline_mtr.h                    |   1 -
 doc/guides/nics/mlx5.rst                      |  12 +
 doc/guides/prog_guide/rte_flow.rst            |  20 +
 .../traffic_metering_and_policing.rst         |   9 +-
 doc/guides/rel_notes/release_21_05.rst        |  14 +-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst   |  18 -
 drivers/net/mlx5/mlx5.h                       |  24 +-
 drivers/net/mlx5/mlx5_flow.c                  |  46 --
 drivers/net/mlx5/mlx5_flow.h                  |  18 +-
 drivers/net/mlx5/mlx5_flow_aso.c              |  15 +-
 drivers/net/mlx5/mlx5_flow_dv.c               | 463 +-----------------
 drivers/net/mlx5/mlx5_flow_meter.c            | 369 +-------------
 drivers/net/softnic/rte_eth_softnic_flow.c    |  19 +-
 .../net/softnic/rte_eth_softnic_internals.h   |  18 +-
 drivers/net/softnic/rte_eth_softnic_meter.c   | 264 +++++++---
 lib/librte_ethdev/rte_flow.h                  |  18 +
 lib/librte_ethdev/rte_mtr.c                   |  55 ++-
 lib/librte_ethdev/rte_mtr.h                   | 157 ++++--
 lib/librte_ethdev/rte_mtr_driver.h            |  44 +-
 lib/librte_ethdev/version.map                 |   4 +
 23 files changed, 510 insertions(+), 1258 deletions(-)
app/test-flow-perf/main.c +0 -7
index 99d0463456..66ec776017 100644
@@ -924,13 +924,6 @@ create_meter_rule(int port_id, uint32_t counter)
 
 	/*create meter*/
 	params.meter_profile_id = default_prof_id;
-	params.action[RTE_COLOR_GREEN] =
-		MTR_POLICER_ACTION_COLOR_GREEN;
-	params.action[RTE_COLOR_YELLOW] =
-		MTR_POLICER_ACTION_COLOR_YELLOW;
-	params.action[RTE_COLOR_RED] =
-		MTR_POLICER_ACTION_DROP;
-
 	ret = rte_mtr_create(port_id, counter, &params, 1, &error);
 	if (ret != 0) {
 		printf("Port %u create meter idx(%d) error(%d) message:
Quoted 1 line

%s\n",

,

[snip]

Quoted 15 lines
app/test-flow-perf/main.c +0 -0
 	.stats_read = pmd_mtr_stats_read,
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_flow.h index 6cc57136ac..0c5807deea 100644

lib/librte_ethdev/rte_flow.h +1 -0
@@ -32,6 +32,7 @@
 #include <rte_ecpri.h>
 #include <rte_mbuf.h>
 #include <rte_mbuf_dyn.h>
+#include <rte_meter.h>
 
 #ifdef __cplusplus
 extern "C" {

lib/librte_ethdev/rte_flow.h enum rte_flow_action_type { · line 2277

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +7 -0
@@ -2267,6 +2268,13 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_modify_field.
 	 */
 	RTE_FLOW_ACTION_TYPE_MODIFY_FIELD,
+
+	/**
+	 * Color the packet to reflect the meter color result.
+	 *
+	 * See struct rte_flow_action_meter_color.
+	 */
+	RTE_FLOW_ACTION_TYPE_METER_COLOR,

Following previous discussion in the ML
I agree to this change with few comments:
1. This action will be experimental and we might change it later to adjust to other rte_flow actions.
2. please make sure in the doc and comment above that it is documented That this goes to mbuf field Something like:
Set the meter color in the mbuf to the selected color.
Since it doesn't color the packet for the rest of the rte_flow.

[snip]
Best
Ori

author
#7 lore raw

PATCH v2 2/2 app/testpmd: support policy actions per color

In reply to Li Zhang

From: Haifei Luo <[email protected]>

add the new create meter with policy API to support it.

---
 app/test-pmd/cmdline.c      |   6 +-
 app/test-pmd/cmdline_flow.c | 118 +++++++++++++++++++++++++++++++++++-
 app/test-pmd/cmdline_mtr.c  |  85 ++++++++++++++++++++++++--
 app/test-pmd/cmdline_mtr.h  |   3 +
 app/test-pmd/config.c       |  34 +++++++++++
 app/test-pmd/testpmd.h      |   2 +
 6 files changed, 240 insertions(+), 8 deletions(-)
app/test-pmd/cmdline.c +5 -1
index dcb5f9c871..029cb38786 100644
@@ -705,7 +705,7 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"del port meter profile (port_id) (profile_id)\n"
 			"    meter profile delete\n\n"
 
-			"create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
+			"create port meter (port_id) [mtr_id] (profile_id) [policy (policy_id)] (meter_enable)\n"
 			"(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
 			"(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
 			"(dscp_tbl_entry63)]\n"
@@ -720,6 +720,9 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"del port meter (port_id) (mtr_id)\n"
 			"    meter delete\n\n"
 
+			"del port meter policy (port_id) (policy_id)\n"
+			"    meter policy delete\n\n"
+
 			"set port meter profile (port_id) (mtr_id) (profile_id)\n"
 			"    meter update meter profile\n\n"
 
@@ -17067,6 +17070,7 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_enable_port_meter,
 	(cmdline_parse_inst_t *)&cmd_disable_port_meter,
 	(cmdline_parse_inst_t *)&cmd_del_port_meter,
+	(cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
 	(cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
 	(cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
 	(cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
app/test-pmd/cmdline_flow.c +117 -1

178 lines not on this page · raw message

app/test-pmd/cmdline_mtr.c +79 -6

140 lines not on this page · raw message

app/test-pmd/cmdline_mtr.h +3 -0
index 7e2713cea3..2415fc16c3 100644
@@ -4,6 +4,7 @@
 
 #ifndef _CMDLINE_MTR_H_
 #define _CMDLINE_MTR_H_
+#include <rte_mtr.h>
 
 /* Traffic Metering and Policing */
 extern cmdline_parse_inst_t cmd_show_port_meter_cap;
@@ -15,9 +16,11 @@ extern cmdline_parse_inst_t cmd_create_port_meter;
 extern cmdline_parse_inst_t cmd_enable_port_meter;
 extern cmdline_parse_inst_t cmd_disable_port_meter;
 extern cmdline_parse_inst_t cmd_del_port_meter;
+extern cmdline_parse_inst_t cmd_del_port_meter_policy;
 extern cmdline_parse_inst_t cmd_set_port_meter_profile;
 extern cmdline_parse_inst_t cmd_set_port_meter_dscp_table;
 extern cmdline_parse_inst_t cmd_set_port_meter_stats_mask;
 extern cmdline_parse_inst_t cmd_show_port_meter_stats;
+void print_mtr_err_msg(struct rte_mtr_error *error);
 
 #endif /* _CMDLINE_MTR_H_ */
app/test-pmd/config.c +34 -0
index ef0b9784d0..336b9b500e 100644
@@ -38,6 +38,7 @@
 #include <rte_string_fns.h>
 #include <rte_cycles.h>
 #include <rte_flow.h>
+#include <rte_mtr.h>
 #include <rte_errno.h>
 #ifdef RTE_NET_IXGBE
 #include <rte_pmd_ixgbe.h>
@@ -52,6 +53,7 @@
 #include <rte_hexdump.h>
 
 #include "testpmd.h"
+#include "cmdline_mtr.h"
 
 #define ETHDEV_FWVERS_LEN 32
 
@@ -1464,6 +1466,38 @@ action_alloc(portid_t port_id, uint32_t id,
 	return 0;
 }
 
+/** Add port meter policy */
+int
+port_meter_policy_add(portid_t port_id, uint32_t policy_id,
+			const struct rte_flow_action *actions)
+{
+	struct rte_mtr_error error;
+	const struct rte_flow_action *acts[RTE_COLORS];
+	const struct rte_flow_action *act = actions;
+	const struct rte_flow_action *start;
+	uint32_t i = 0, act_n;
+	int ret;
+
+	for (i = 0; i < RTE_COLORS; i++) {
+		for (act_n = 0, start = act;
+			act->type != RTE_FLOW_ACTION_TYPE_END; act++)
+			act_n++;
+		if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
+			acts[i] = start;
+		else
+			acts[i] = NULL;
+		act++;
+	}
+	ret = rte_mtr_meter_policy_create(port_id,
+			policy_id,
+			acts, &error);
+	if (ret) {
+		print_mtr_err_msg(&error);
+		return -1;
+	}
+	return policy_id;
+}
+
 /** Create shared action */
 int
 port_shared_action_create(portid_t port_id, uint32_t id,
app/test-pmd/testpmd.h +2 -0
index a87ccb0f0f..bc7cb7e9b9 100644
@@ -837,6 +837,8 @@ void port_flow_tunnel_list(portid_t port_id);
 void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id);
 void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops);
 int port_flow_isolate(portid_t port_id, int set);
+int port_meter_policy_add(portid_t port_id, uint32_t policy_id,
+		const struct rte_flow_action *actions);
 
 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id);
 void tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id);
Signature · 1 line
2.27.0