DPDK patches and discussions
 help / color / mirror / Atom feed
From: Rongwei Liu <rongweil@nvidia.com>
To: <matan@nvidia.com>, <viacheslavo@nvidia.com>, <orika@nvidia.com>,
	<thomas@monjalon.net>, Wisam Jaddo <wisamm@nvidia.com>
Cc: <dev@dpdk.org>, <rasland@nvidia.com>,
	Haifei Luo <haifeil@nvidia.com>, Jiawei Wang <jiaweiw@nvidia.com>
Subject: [dpdk-dev] [PATCH v2 1/3] app/flow-perf: support meter policy API
Date: Wed, 21 Jul 2021 10:05:40 +0300	[thread overview]
Message-ID: <20210721070542.1153843-2-rongweil@nvidia.com> (raw)
In-Reply-To: <20210721070542.1153843-1-rongweil@nvidia.com>

Add option "policy-mtr" to indicate if meter creation will include policy
or not. Meter creation will keep same without it.

With "policy-mtr", policy is introduced. API create_meter_policy
is to create a policy. API create_meter_rule will use it to create
meter.

Add option "policy-g_actions" to specify meter policy green color actions.
W/o this, policy creation will fail since there is no default one.

Signed-off-by: Haifei Luo <haifeil@nvidia.com>
Signed-off-by: Jiawei Wang <jiaweiw@nvidia.com>
Signed-off-by: Rongwei Liu <rongweil@nvidia.com>
---
 app/test-flow-perf/main.c      | 121 ++++++++++++++++++++++++++++++---
 doc/guides/tools/flow-perf.rst |   6 ++
 2 files changed, 119 insertions(+), 8 deletions(-)

diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 9be8edc31d..e0d94f943a 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -37,6 +37,7 @@
 #include <rte_mtr.h>
 
 #include "config.h"
+#include "actions_gen.h"
 #include "flow_gen.h"
 
 #define MAX_BATCHES_COUNT          100
@@ -49,10 +50,12 @@ static uint8_t flow_group;
 
 static uint64_t encap_data;
 static uint64_t decap_data;
+static uint64_t g_actions;
 
 static uint64_t flow_items[MAX_ITEMS_NUM];
 static uint64_t flow_actions[MAX_ACTIONS_NUM];
 static uint64_t flow_attrs[MAX_ATTRS_NUM];
+static uint32_t g_policy_id[MAX_PORTS];
 static uint8_t items_idx, actions_idx, attrs_idx;
 
 static uint64_t ports_mask;
@@ -62,6 +65,7 @@ static bool delete_flag;
 static bool dump_socket_mem_flag;
 static bool enable_fwd;
 static bool unique_data;
+static bool policy_mtr;
 
 static struct rte_mempool *mbuf_mp;
 static uint32_t nb_lcores;
@@ -69,6 +73,7 @@ static uint32_t rules_count;
 static uint32_t rules_batch;
 static uint32_t hairpin_queues_num; /* total hairpin q number - default: 0 */
 static uint32_t nb_lcores;
+static uint64_t meter_cir;
 
 #define MAX_PKT_BURST    32
 #define LCORE_MODE_PKT    1
@@ -134,6 +139,8 @@ usage(char *progname)
 	printf("  --portmask=N: hexadecimal bitmask of ports used\n");
 	printf("  --unique-data: flag to set using unique data for all"
 		" actions that support data, such as header modify and encap actions\n");
+	printf("  --policy-mtr: To create meter with policy\n");
+	printf("  --policy-g_actions: To set meter policy green color actions\n");
 
 	printf("To set flow attributes:\n");
 	printf("  --ingress: set ingress attribute in flows\n");
@@ -573,6 +580,9 @@ args_parse(int argc, char **argv)
 		{ "unique-data",                0, 0, 0 },
 		{ "portmask",                   1, 0, 0 },
 		{ "cores",                      1, 0, 0 },
+		{ "policy-mtr",                 0, 0, 0 },
+		{ "policy-g_actions",           1, 0, 0 },
+		{ "meter-profile-alg",          1, 0, 0 },
 		/* Attributes */
 		{ "ingress",                    0, 0, 0 },
 		{ "egress",                     0, 0, 0 },
@@ -802,6 +812,32 @@ args_parse(int argc, char **argv)
 						RTE_MAX_LCORE);
 				}
 			}
+			if (strcmp(lgopts[opt_idx].name, "policy-mtr") == 0)
+				policy_mtr = true;
+			if (strcmp(lgopts[opt_idx].name,
+					"policy-g_actions") == 0) {
+				token = strtok(optarg, ",");
+				while (token != NULL) {
+					for (i = 0;
+					     i < RTE_DIM(flow_options); i++) {
+						if (strcmp(optarg,
+						    flow_options[i].str) == 0) {
+							g_actions |=
+							flow_options[i].mask;
+							break;
+						}
+					}
+					/* Reached last item with no match */
+					if (i == (RTE_DIM(flow_options) - 1)) {
+						fprintf(stderr,
+							"Invalid g_actions "
+							"item: %s\n", token);
+						usage(argv[0]);
+						rte_exit(EXIT_SUCCESS, "Invalid g_actions item\n");
+					}
+					token = strtok(NULL, ",");
+				}
+			}
 			break;
 		default:
 			usage(argv[0]);
@@ -912,6 +948,62 @@ has_meter(void)
 	return 0;
 }
 
+static void
+create_meter_policy(void)
+{
+	struct rte_mtr_error error;
+	uint32_t policy_id;
+	int ret, i, port_id;
+	struct rte_mtr_meter_policy_params policy;
+	struct rte_flow_action r_actions[2];
+	uint16_t nr_ports;
+	struct rte_flow_action actions[MAX_ACTIONS_NUM];
+	uint64_t flow_actions[MAX_ACTIONS_NUM];
+	int lcore_counter = 0;
+	int lcore_id = rte_lcore_id();
+
+	memset(actions, 0, sizeof(actions));
+	memset(flow_actions, 0, sizeof(flow_actions));
+	memset(&policy, 0, sizeof(policy));
+	RTE_LCORE_FOREACH(i) {
+		/*  If core not needed return. */
+		if (lcore_id == i) {
+			if (lcore_counter >= (int) mc_pool.cores_count)
+				return;
+			break;
+		}
+		lcore_counter++;
+	}
+	lcore_id = lcore_counter;
+
+	if (lcore_id >= (int) mc_pool.cores_count)
+		return;
+
+	flow_actions[0] = g_actions;
+	fill_actions(actions, flow_actions, 0, 0, 0,
+		     0, 0, lcore_id, unique_data);
+
+	r_actions[0].type = RTE_FLOW_ACTION_TYPE_DROP;
+	r_actions[0].conf = NULL;
+	r_actions[1].type = RTE_FLOW_ACTION_TYPE_END;
+	r_actions[1].conf = NULL;
+
+	policy.actions[RTE_COLOR_GREEN] = &actions[0];
+	policy.actions[RTE_COLOR_YELLOW] = NULL;
+	policy.actions[RTE_COLOR_RED] = &r_actions[0];
+
+	nr_ports = rte_eth_dev_count_avail();
+	for (port_id = 0; port_id < nr_ports; port_id++) {
+		policy_id = port_id + 10;
+		ret = rte_mtr_meter_policy_add(port_id, policy_id,
+					       &policy, &error);
+		if (ret)
+			printf("meter policy add failed "
+			       "port_id %d\n", port_id);
+		g_policy_id[port_id] = policy_id;
+	}
+}
+
 static void
 create_meter_rule(int port_id, uint32_t counter)
 {
@@ -928,7 +1020,14 @@ create_meter_rule(int port_id, uint32_t counter)
 
 	/*create meter*/
 	params.meter_profile_id = default_prof_id;
-	ret = rte_mtr_create(port_id, counter, &params, 1, &error);
+
+	if (!policy_mtr) {
+		ret = rte_mtr_create(port_id, counter, &params, 1, &error);
+	} else {
+		params.meter_policy_id = g_policy_id[port_id];
+		ret = rte_mtr_create(port_id, counter, &params, 0, &error);
+	}
+
 	if (ret != 0) {
 		printf("Port %u create meter idx(%d) error(%d) message: %s\n",
 			port_id, counter, error.type,
@@ -942,11 +1041,16 @@ destroy_meter_rule(int port_id, uint32_t counter)
 {
 	struct rte_mtr_error error;
 
-	if (rte_mtr_destroy(port_id, counter, &error)) {
-		printf("Port %u destroy meter(%d) error(%d) message: %s\n",
+	if (policy_mtr) {
+		if (rte_mtr_meter_policy_delete(port_id, counter+1, &error))
+			printf("error delete policy %d\n", counter+1);
+	} else {
+		if (rte_mtr_destroy(port_id, counter, &error)) {
+			printf("Port %u destroy meter(%d) error(%d) message: %s\n",
 			port_id, counter, error.type,
 			error.message ? error.message : "(no stated reason)");
-		rte_exit(EXIT_FAILURE, "Error in deleting meter rule\n");
+			rte_exit(EXIT_FAILURE, "Error in deleting meter rule");
+		}
 	}
 }
 
@@ -1051,12 +1155,10 @@ create_meter_profile(void)
 		/* If port outside portmask */
 		if (!((ports_mask >> port_id) & 0x1))
 			continue;
-
 		mp.alg = RTE_MTR_SRTCM_RFC2697;
-		mp.srtcm_rfc2697.cir = METER_CIR;
-		mp.srtcm_rfc2697.cbs = METER_CIR / 8;
+		mp.srtcm_rfc2697.cir = meter_cir;
+		mp.srtcm_rfc2697.cbs = meter_cir / 8;
 		mp.srtcm_rfc2697.ebs = 0;
-
 		ret = rte_mtr_meter_profile_add
 			(port_id, DEFAULT_METER_PROF_ID, &mp, &error);
 		if (ret != 0) {
@@ -1875,6 +1977,7 @@ main(int argc, char **argv)
 	dump_socket_mem_flag = false;
 	flow_group = DEFAULT_GROUP;
 	unique_data = false;
+	meter_cir = METER_CIR;
 
 	signal(SIGINT, signal_handler);
 	signal(SIGTERM, signal_handler);
@@ -1894,6 +1997,8 @@ main(int argc, char **argv)
 
 	if (has_meter())
 		create_meter_profile();
+	if (policy_mtr)
+		create_meter_policy();
 	rte_eal_mp_remote_launch(run_rte_flow_handler_cores, NULL, CALL_MAIN);
 
 	if (enable_fwd) {
diff --git a/doc/guides/tools/flow-perf.rst b/doc/guides/tools/flow-perf.rst
index 280bf7e0e0..90b6934537 100644
--- a/doc/guides/tools/flow-perf.rst
+++ b/doc/guides/tools/flow-perf.rst
@@ -354,3 +354,9 @@ Actions:
 *       ``--meter``
         Add meter action to all flows actions.
         Currently, 1 meter profile -> N meter rules -> N rte flows.
+
+*       ``--policy-mtr``
+        Add policy-mtr to create meter with policy.
+
+*       ``--policy-g_actions``
+        Add policy-g_actions to specify policy green color actions.
-- 
2.27.0


  reply	other threads:[~2021-07-21  7:06 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06  6:50 [dpdk-dev] [PATCH] " Haifei Luo
2021-05-09 10:47 ` Wisam Monther
2021-07-21  7:05 ` [dpdk-dev] [PATCH v2 0/3] support new format meter Rongwei Liu
2021-07-21  7:05   ` Rongwei Liu [this message]
2021-09-26  9:45     ` [dpdk-dev] [PATCH v2 1/3] app/flow-perf: support meter policy API Wisam Monther
2021-10-28  3:25       ` [dpdk-dev] [PATCH v3 0/3] add meter policy support in flow-perf Rongwei Liu
2021-10-28  3:25         ` [dpdk-dev] [PATCH v3 1/3] app/flow-perf: support meter policy API Rongwei Liu
2021-11-05  9:57           ` Thomas Monjalon
2021-11-05 10:24             ` Rongwei Liu
2021-11-05 10:34               ` Thomas Monjalon
2021-11-08  8:53                 ` [dpdk-dev] [PATCH v4 0/3] add meter policy support in flow-perf Rongwei Liu
2021-11-08  8:53                   ` [dpdk-dev] [PATCH v4 1/3] app/flow-perf: support meter policy API Rongwei Liu
2021-11-08  9:05                     ` Thomas Monjalon
2021-11-08  9:23                       ` [dpdk-dev] [PATCH v5 0/3] add meter policy support in flow-perf Rongwei Liu
2021-11-08  9:23                         ` [dpdk-dev] [PATCH v5 1/3] app/flow-perf: support meter policy API Rongwei Liu
2021-11-08  9:23                         ` [dpdk-dev] [PATCH v5 2/3] app/flow-perf: add meter-profile to support cir cbs and ebs Rongwei Liu
2021-11-08  9:23                         ` [dpdk-dev] [PATCH v5 3/3] app/flow-perf: add packet mode metering mode Rongwei Liu
2021-11-08  9:35                         ` [dpdk-dev] [PATCH v5 0/3] add meter policy support in flow-perf Thomas Monjalon
2021-11-08  9:39                           ` Rongwei Liu
2021-11-08  9:40                             ` Thomas Monjalon
2021-11-08  9:58                       ` [dpdk-dev] [PATCH v6 " Rongwei Liu
2021-11-08  9:58                         ` [dpdk-dev] [PATCH v6 1/3] app/flow-perf: support meter policy API Rongwei Liu
2021-11-08 10:08                           ` Thomas Monjalon
2021-11-08  9:58                         ` [dpdk-dev] [PATCH v6 2/3] app/flow-perf: add meter-profile to support cir cbs and ebs Rongwei Liu
2021-11-08 10:10                           ` Thomas Monjalon
2021-11-08  9:58                         ` [dpdk-dev] [PATCH v6 3/3] app/flow-perf: add packet mode metering mode Rongwei Liu
2021-11-08 11:10                       ` [dpdk-dev] [PATCH v7 0/3] add meter policy support in flow-perf Rongwei Liu
2021-11-08 11:10                         ` [dpdk-dev] [PATCH v7 1/3] app/flow-perf: support meter policy API Rongwei Liu
2021-11-08 11:10                         ` [dpdk-dev] [PATCH v7 2/3] app/flow-perf: add meter-profile to support cir cbs and ebs Rongwei Liu
2021-11-08 11:10                         ` [dpdk-dev] [PATCH v7 3/3] app/flow-perf: add packet mode metering mode Rongwei Liu
2021-11-10 12:57                       ` [dpdk-dev] [PATCH v8 0/3] add meter policy support in flow-perf Rongwei Liu
2021-11-10 12:57                         ` [dpdk-dev] [PATCH v8 1/3] app/flow-perf: support meter policy API Rongwei Liu
2021-11-10 12:57                         ` [dpdk-dev] [PATCH v8 2/3] app/flow-perf: support dynamic values for meter profile Rongwei Liu
2021-11-10 12:57                         ` [dpdk-dev] [PATCH v8 3/3] app/flow-perf: add packet metering mode Rongwei Liu
2021-11-11 14:23                       ` [PATCH v9 0/5] add meter policy support in flow-perf Rongwei Liu
2021-11-11 14:23                         ` [PATCH v9 1/5] app/flow-perf: define flow-options as global Rongwei Liu
2021-11-16 10:05                           ` Wisam Monther
2021-11-11 14:23                         ` [PATCH v9 2/5] app/flow-perf: support meter policy API Rongwei Liu
2021-11-16 10:05                           ` Wisam Monther
2021-11-11 14:23                         ` [PATCH v9 3/5] app/flow-perf: support dynamic values for meter profile Rongwei Liu
2021-11-16 10:05                           ` Wisam Monther
2021-11-11 14:23                         ` [PATCH v9 4/5] app/flow-perf: add packet metering mode Rongwei Liu
2021-11-16 10:05                           ` Wisam Monther
2021-11-11 14:23                         ` [PATCH v9 5/5] app/flow-perf: fix previous wrong indentation Rongwei Liu
2021-11-16 10:05                           ` Wisam Monther
2021-11-16 10:07                             ` Rongwei Liu
2021-11-16 11:33                         ` [PATCH v9 0/5] add meter policy support in flow-perf Thomas Monjalon
2021-11-08  8:53                   ` [dpdk-dev] [PATCH v4 2/3] app/flow-perf: add meter-profile to support cir cbs and ebs Rongwei Liu
2021-11-08  8:53                   ` [dpdk-dev] [PATCH v4 3/3] app/flow-perf: add packet mode metering mode Rongwei Liu
2021-10-28  3:25         ` [dpdk-dev] [PATCH v3 2/3] app/flow-perf: add meter-profile to support cir cbs and ebs Rongwei Liu
2021-10-28  3:26         ` [dpdk-dev] [PATCH v3 3/3] app/flow-perf: add packet mode metering mode Rongwei Liu
2021-07-21  7:05   ` [dpdk-dev] [PATCH v2 2/3] app/flow-perf: add new meter CIR Configuration Rongwei Liu
2021-09-26  9:46     ` Wisam Monther
2021-07-21  7:05   ` [dpdk-dev] [PATCH v2 3/3] app/flow-perf: add the supports for meter PPS Rongwei Liu
2021-09-26  9:47     ` Wisam Monther

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=20210721070542.1153843-2-rongweil@nvidia.com \
    --to=rongweil@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=haifeil@nvidia.com \
    --cc=jiaweiw@nvidia.com \
    --cc=matan@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=thomas@monjalon.net \
    --cc=viacheslavo@nvidia.com \
    --cc=wisamm@nvidia.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).