Skip to contentSkip to conversation

pipeline: add register array support to SWX pipeline

PATCH Superseded Cristian Dumitrescu 2 participants 8 messages Feb 26, 2021 – Mar 24, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 pipeline: add register array support to SWX pipeline

Register arrays are stateful objects that can be read & modified by both the data plane and the control plane, as opposed to tables, which are read-only for data plane. One key use-case is the implementation of stats counters.

---
 examples/pipeline/cli.c                     |  125 ++
 lib/librte_pipeline/rte_swx_ctl.h           |   79 +
 lib/librte_pipeline/rte_swx_pipeline.c      | 1712 +++++++++++++++++--
 lib/librte_pipeline/rte_swx_pipeline.h      |   21 +
 lib/librte_pipeline/rte_swx_pipeline_spec.c |   91 +
 lib/librte_pipeline/version.map             |    6 +
 6 files changed, 1855 insertions(+), 179 deletions(-)
examples/pipeline/cli.c +125 -0
index 30c2dd34d..cdf8f13f3 100644
@@ -1009,6 +1009,105 @@ cmd_pipeline_table_update(char **tokens,
 		fclose(file_default);
 }
 
+static const char cmd_pipeline_regrd_help[] =
+"pipeline <pipeline_name> regrd <register_array_name> <index>\n";
+
+static void
+cmd_pipeline_regrd(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name;
+	uint64_t value;
+	uint32_t idx;
+	int status;
+
+	if (n_tokens != 5) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "regrd")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regrd");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (parser_read_uint32(&idx, tokens[4])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+		return;
+	}
+
+	status = rte_swx_ctl_pipeline_regarray_read(p->p, name, idx, &value);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+
+	snprintf(out, out_size, "0x%" PRIx64 "\n", value);
+}
+
+static const char cmd_pipeline_regwr_help[] =
+"pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n";
+
+static void
+cmd_pipeline_regwr(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name;
+	uint64_t value;
+	uint32_t idx;
+	int status;
+
+	if (n_tokens != 6) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "regwr")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regwr");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (parser_read_uint32(&idx, tokens[4])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+		return;
+	}
+
+	if (parser_read_uint64(&value, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "value");
+		return;
+	}
+
+	status = rte_swx_ctl_pipeline_regarray_write(p->p, name, idx, value);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+}
+
 static const char cmd_pipeline_stats_help[] =
 "pipeline <pipeline_name> stats\n";
 
@@ -1202,6 +1301,8 @@ cmd_help(char **tokens,
 			"\tpipeline port out\n"
 			"\tpipeline build\n"
 			"\tpipeline table update\n"
+			"\tpipeline regrd\n"
+			"\tpipeline regwr\n"
 			"\tpipeline stats\n"
 			"\tthread pipeline enable\n"
 			"\tthread pipeline disable\n\n");
@@ -1254,6 +1355,18 @@ cmd_help(char **tokens,
 		return;
 	}
 
+	if ((strcmp(tokens[0], "pipeline") == 0) &&
+		(n_tokens == 2) && (strcmp(tokens[1], "regrd") == 0)) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_regrd_help);
+		return;
+	}
+
+	if ((strcmp(tokens[0], "pipeline") == 0) &&
+		(n_tokens == 2) && (strcmp(tokens[1], "regwr") == 0)) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_regwr_help);
+		return;
+	}
+
 	if ((strcmp(tokens[0], "pipeline") == 0) &&
 		(n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) {
 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help);
@@ -1356,6 +1469,18 @@ cli_process(char *in, char *out, size_t out_size, void *obj)
 			return;
 		}
 
+		if ((n_tokens >= 3) &&
+			(strcmp(tokens[2], "regrd") == 0)) {
+			cmd_pipeline_regrd(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 3) &&
+			(strcmp(tokens[2], "regwr") == 0)) {
+			cmd_pipeline_regwr(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
 		if ((n_tokens >= 3) &&
 			(strcmp(tokens[2], "stats") == 0)) {
 			cmd_pipeline_stats(tokens, n_tokens, out, out_size,
lib/librte_pipeline/rte_swx_ctl.h +79 -0

91 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.c +1533 -179

1,875 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.h +21 -0
index f0a2cef77..c6e4e50a8 100644
@@ -616,6 +616,27 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
 			      const char *args,
 			      uint32_t size);
 
+/**
+ * Pipeline register array configure
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] name
+ *   Register array name.
+ * @param[in] size
+ *   Number of registers in the array. Each register is 64-bit in size.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough space/cannot allocate memory;
+ *   -EEXIST: Register array with this name already exists.
+ */
+__rte_experimental
+int
+rte_swx_pipeline_regarray_config(struct rte_swx_pipeline *p,
+				 const char *name,
+				 uint32_t size);
+
 /**
  * Pipeline instructions configure
  *
lib/librte_pipeline/rte_swx_pipeline_spec.c +91 -0

115 lines not on this page · raw message

lib/librte_pipeline/version.map +6 -0
index 87c826f1b..26a9edf47 100644
@@ -102,4 +102,10 @@ EXPERIMENTAL {
 	rte_swx_pipeline_table_state_get;
 	rte_swx_pipeline_table_state_set;
 	rte_swx_pipeline_table_type_register;
+
+	#added in 21.05
+	rte_swx_ctl_pipeline_regarray_read;
+	rte_swx_ctl_pipeline_regarray_write;
+	rte_swx_ctl_regarray_info_get;
+	rte_swx_pipeline_regarray_config;
 };
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/2 pipeline: add register array support to SWX pipeline

Register arrays are stateful objects that can be read & modified by both the data plane and the control plane, as opposed to tables, which are read-only for data plane. One key use-case is the implementation of stats counters.

---
 examples/pipeline/cli.c                     |  125 ++
 examples/pipeline/examples/registers.cli    |   28 +
 examples/pipeline/examples/registers.spec   |   67 +
 lib/librte_pipeline/rte_swx_ctl.h           |   79 +
 lib/librte_pipeline/rte_swx_pipeline.c      | 1602 +++++++++++++++++--
 lib/librte_pipeline/rte_swx_pipeline.h      |   24 +
 lib/librte_pipeline/rte_swx_pipeline_spec.c |  105 ++
 lib/librte_pipeline/version.map             |    6 +
 8 files changed, 1882 insertions(+), 154 deletions(-)
 create mode 100644 examples/pipeline/examples/registers.cli
 create mode 100644 examples/pipeline/examples/registers.spec
examples/pipeline/cli.c +125 -0
index 30c2dd34d..cdf8f13f3 100644
@@ -1009,6 +1009,105 @@ cmd_pipeline_table_update(char **tokens,
 		fclose(file_default);
 }
 
+static const char cmd_pipeline_regrd_help[] =
+"pipeline <pipeline_name> regrd <register_array_name> <index>\n";
+
+static void
+cmd_pipeline_regrd(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name;
+	uint64_t value;
+	uint32_t idx;
+	int status;
+
+	if (n_tokens != 5) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "regrd")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regrd");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (parser_read_uint32(&idx, tokens[4])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+		return;
+	}
+
+	status = rte_swx_ctl_pipeline_regarray_read(p->p, name, idx, &value);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+
+	snprintf(out, out_size, "0x%" PRIx64 "\n", value);
+}
+
+static const char cmd_pipeline_regwr_help[] =
+"pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n";
+
+static void
+cmd_pipeline_regwr(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name;
+	uint64_t value;
+	uint32_t idx;
+	int status;
+
+	if (n_tokens != 6) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "regwr")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regwr");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (parser_read_uint32(&idx, tokens[4])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+		return;
+	}
+
+	if (parser_read_uint64(&value, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "value");
+		return;
+	}
+
+	status = rte_swx_ctl_pipeline_regarray_write(p->p, name, idx, value);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+}
+
 static const char cmd_pipeline_stats_help[] =
 "pipeline <pipeline_name> stats\n";
 
@@ -1202,6 +1301,8 @@ cmd_help(char **tokens,
 			"\tpipeline port out\n"
 			"\tpipeline build\n"
 			"\tpipeline table update\n"
+			"\tpipeline regrd\n"
+			"\tpipeline regwr\n"
 			"\tpipeline stats\n"
 			"\tthread pipeline enable\n"
 			"\tthread pipeline disable\n\n");
@@ -1254,6 +1355,18 @@ cmd_help(char **tokens,
 		return;
 	}
 
+	if ((strcmp(tokens[0], "pipeline") == 0) &&
+		(n_tokens == 2) && (strcmp(tokens[1], "regrd") == 0)) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_regrd_help);
+		return;
+	}
+
+	if ((strcmp(tokens[0], "pipeline") == 0) &&
+		(n_tokens == 2) && (strcmp(tokens[1], "regwr") == 0)) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_regwr_help);
+		return;
+	}
+
 	if ((strcmp(tokens[0], "pipeline") == 0) &&
 		(n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) {
 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help);
@@ -1356,6 +1469,18 @@ cli_process(char *in, char *out, size_t out_size, void *obj)
 			return;
 		}
 
+		if ((n_tokens >= 3) &&
+			(strcmp(tokens[2], "regrd") == 0)) {
+			cmd_pipeline_regrd(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 3) &&
+			(strcmp(tokens[2], "regwr") == 0)) {
+			cmd_pipeline_regwr(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
 		if ((n_tokens >= 3) &&
 			(strcmp(tokens[2], "stats") == 0)) {
 			cmd_pipeline_stats(tokens, n_tokens, out, out_size,
examples/pipeline/examples/registers.cli new file +28 -0
new file mode 100644
index 000000000..8d026294c
@@ -0,0 +1,28 @@
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright(c) 2020 Intel Corporation
+
+; Example command line:
+;	./build/examples/dpdk-pipeline -l0-1 -- -s ./examples/pipeline/examples/registers.cli
+
+mempool MEMPOOL0 buffer 2304 pool 32K cache 256 cpu 0
+
+link LINK0 dev 0000:18:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK1 dev 0000:18:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK2 dev 0000:3b:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK3 dev 0000:3b:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+
+pipeline PIPELINE0 create 0
+
+pipeline PIPELINE0 port in 0 link LINK0 rxq 0 bsz 32
+pipeline PIPELINE0 port in 1 link LINK1 rxq 0 bsz 32
+pipeline PIPELINE0 port in 2 link LINK2 rxq 0 bsz 32
+pipeline PIPELINE0 port in 3 link LINK3 rxq 0 bsz 32
+
+pipeline PIPELINE0 port out 0 link LINK0 txq 0 bsz 32
+pipeline PIPELINE0 port out 1 link LINK1 txq 0 bsz 32
+pipeline PIPELINE0 port out 2 link LINK2 txq 0 bsz 32
+pipeline PIPELINE0 port out 3 link LINK3 txq 0 bsz 32
+
+pipeline PIPELINE0 build ./examples/pipeline/examples/registers.spec
+
+thread 1 pipeline PIPELINE0 enable
examples/pipeline/examples/registers.spec new file +67 -0

67 lines not on this page · raw message

lib/librte_pipeline/rte_swx_ctl.h +79 -0

91 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.c +1448 -154

1,769 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.h +24 -0
index f0a2cef77..1c9b2eb12 100644
@@ -616,6 +616,30 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
 			      const char *args,
 			      uint32_t size);
 
+/**
+ * Pipeline register array configure
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] name
+ *   Register array name.
+ * @param[in] size
+ *   Number of registers in the array. Each register is 64-bit in size.
+ * @param[in] init_val
+ *   Initial value for every register in the array. The recommended value is 0.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough space/cannot allocate memory;
+ *   -EEXIST: Register array with this name already exists.
+ */
+__rte_experimental
+int
+rte_swx_pipeline_regarray_config(struct rte_swx_pipeline *p,
+				 const char *name,
+				 uint32_t size,
+				 uint64_t init_val);
+
 /**
  * Pipeline instructions configure
  *
lib/librte_pipeline/rte_swx_pipeline_spec.c +105 -0

129 lines not on this page · raw message

lib/librte_pipeline/version.map +6 -0
index 87c826f1b..26a9edf47 100644
@@ -102,4 +102,10 @@ EXPERIMENTAL {
 	rte_swx_pipeline_table_state_get;
 	rte_swx_pipeline_table_state_set;
 	rte_swx_pipeline_table_type_register;
+
+	#added in 21.05
+	rte_swx_ctl_pipeline_regarray_read;
+	rte_swx_ctl_pipeline_regarray_write;
+	rte_swx_ctl_regarray_info_get;
+	rte_swx_pipeline_regarray_config;
 };
Signature · 1 line
2.17.1
#2 lore raw

PATCH v3 2/2 pipeline: add meter support to the SWX pipeline

Meter arrays are stateful objects that are updated by the data plane and configured & monitored by the control plane. The meters implement the RFC 2698 Two Rate Three Color Marker (trTCM) algorithm.

---
 examples/pipeline/cli.c                     |  471 ++++++
 examples/pipeline/examples/meter.cli        |   31 +
 examples/pipeline/examples/meter.spec       |   63 +
 lib/librte_pipeline/rte_swx_ctl.h           |  154 ++
 lib/librte_pipeline/rte_swx_pipeline.c      | 1684 ++++++++++++++++---
 lib/librte_pipeline/rte_swx_pipeline.h      |   22 +
 lib/librte_pipeline/rte_swx_pipeline_spec.c |   91 +
 lib/librte_pipeline/version.map             |    7 +
 8 files changed, 2327 insertions(+), 196 deletions(-)
 create mode 100644 examples/pipeline/examples/meter.cli
 create mode 100644 examples/pipeline/examples/meter.spec
examples/pipeline/cli.c +471 -0
index cdf8f13f3..045525307 100644
@@ -1108,6 +1108,398 @@ cmd_pipeline_regwr(char **tokens,
 	}
 }
 
+static const char cmd_pipeline_meter_profile_add_help[] =
+"pipeline <pipeline_name> meter profile <profile_name> add "
+	"cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
+
+static void
+cmd_pipeline_meter_profile_add(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct rte_meter_trtcm_params params;
+	struct pipeline *p;
+	const char *profile_name;
+	int status;
+
+	if (n_tokens != 14) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	if (strcmp(tokens[3], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
+		return;
+	}
+
+	profile_name = tokens[4];
+
+	if (strcmp(tokens[5], "add")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
+		return;
+	}
+
+	if (strcmp(tokens[6], "cir")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
+		return;
+	}
+
+	if (parser_read_uint64(&params.cir, tokens[7])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "cir");
+		return;
+	}
+
+	if (strcmp(tokens[8], "pir")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
+		return;
+	}
+
+	if (parser_read_uint64(&params.pir, tokens[9])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pir");
+		return;
+	}
+
+	if (strcmp(tokens[10], "cbs")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
+		return;
+	}
+
+	if (parser_read_uint64(&params.cbs, tokens[11])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
+		return;
+	}
+
+	if (strcmp(tokens[12], "pbs")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
+		return;
+	}
+
+	if (parser_read_uint64(&params.pbs, tokens[13])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
+		return;
+	}
+
+	status = rte_swx_ctl_meter_profile_add(p->p, profile_name, &params);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+}
+
+static const char cmd_pipeline_meter_profile_delete_help[] =
+"pipeline <pipeline_name> meter profile <profile_name> delete\n";
+
+static void
+cmd_pipeline_meter_profile_delete(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *profile_name;
+	int status;
+
+	if (n_tokens != 6) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	if (strcmp(tokens[3], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
+		return;
+	}
+
+	profile_name = tokens[4];
+
+	if (strcmp(tokens[5], "delete")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
+		return;
+	}
+
+	status = rte_swx_ctl_meter_profile_delete(p->p, profile_name);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+}
+
+static const char cmd_pipeline_meter_reset_help[] =
+"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
+	"reset\n";
+
+static void
+cmd_pipeline_meter_reset(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name;
+	uint32_t idx0, idx1;
+
+	if (n_tokens != 9) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (strcmp(tokens[4], "from")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+		return;
+	}
+
+	if (parser_read_uint32(&idx0, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+		return;
+	}
+
+	if (strcmp(tokens[6], "to")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+		return;
+	}
+
+	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+		return;
+	}
+
+	if (strcmp(tokens[8], "reset")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
+		return;
+	}
+
+	for ( ; idx0 <= idx1; idx0++) {
+		int status;
+
+		status = rte_swx_ctl_meter_reset(p->p, name, idx0);
+		if (status) {
+			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			return;
+		}
+	}
+}
+
+static const char cmd_pipeline_meter_set_help[] =
+"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
+	"set profile <profile_name>\n";
+
+static void
+cmd_pipeline_meter_set(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name, *profile_name;
+	uint32_t idx0, idx1;
+
+	if (n_tokens != 11) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (strcmp(tokens[4], "from")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+		return;
+	}
+
+	if (parser_read_uint32(&idx0, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+		return;
+	}
+
+	if (strcmp(tokens[6], "to")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+		return;
+	}
+
+	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+		return;
+	}
+
+	if (strcmp(tokens[8], "set")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
+		return;
+	}
+
+	if (strcmp(tokens[9], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
+		return;
+	}
+
+	profile_name = tokens[10];
+
+	for ( ; idx0 <= idx1; idx0++) {
+		int status;
+
+		status = rte_swx_ctl_meter_set(p->p, name, idx0, profile_name);
+		if (status) {
+			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			return;
+		}
+	}
+}
+
+static const char cmd_pipeline_meter_stats_help[] =
+"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
+	"stats\n";
+
+static void
+cmd_pipeline_meter_stats(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct rte_swx_ctl_meter_stats stats;
+	struct pipeline *p;
+	const char *name;
+	uint32_t idx0, idx1;
+
+	if (n_tokens != 9) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (strcmp(tokens[4], "from")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+		return;
+	}
+
+	if (parser_read_uint32(&idx0, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+		return;
+	}
+
+	if (strcmp(tokens[6], "to")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+		return;
+	}
+
+	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+		return;
+	}
+
+	if (strcmp(tokens[8], "stats")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
+		return;
+	}
+
+	/* Table header. */
+	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
+		 "-------",
+		 "----------------", "----------------", "----------------",
+		 "----------------", "----------------", "----------------");
+	out_size -= strlen(out);
+	out += strlen(out);
+
+	snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n",
+		 "METER #",
+		 "GREEN (packets)", "YELLOW (packets)", "RED (packets)",
+		 "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)");
+	out_size -= strlen(out);
+	out += strlen(out);
+
+	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
+		 "-------",
+		 "----------------", "----------------", "----------------",
+		 "----------------", "----------------", "----------------");
+	out_size -= strlen(out);
+	out += strlen(out);
+
+	/* Table rows. */
+	for ( ; idx0 <= idx1; idx0++) {
+		int status;
+
+		status = rte_swx_ctl_meter_stats_read(p->p, name, idx0, &stats);
+		if (status) {
+			snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0);
+			out_size -= strlen(out);
+			out += strlen(out);
+			return;
+		}
+
+		snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64
+			 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n",
+			 idx0,
+			 stats.n_pkts[RTE_COLOR_GREEN],
+			 stats.n_pkts[RTE_COLOR_YELLOW],
+			 stats.n_pkts[RTE_COLOR_RED],
+			 stats.n_bytes[RTE_COLOR_GREEN],
+			 stats.n_bytes[RTE_COLOR_YELLOW],
+			 stats.n_bytes[RTE_COLOR_RED]);
+		out_size -= strlen(out);
+		out += strlen(out);
+	}
+}
+
 static const char cmd_pipeline_stats_help[] =
 "pipeline <pipeline_name> stats\n";
 
@@ -1303,6 +1695,11 @@ cmd_help(char **tokens,
 			"\tpipeline table update\n"
 			"\tpipeline regrd\n"
 			"\tpipeline regwr\n"
+			"\tpipeline meter profile add\n"
+			"\tpipeline meter profile delete\n"
+			"\tpipeline meter reset\n"
+			"\tpipeline meter set\n"
+			"\tpipeline meter stats\n"
 			"\tpipeline stats\n"
 			"\tthread pipeline enable\n"
 			"\tthread pipeline disable\n\n");
@@ -1373,6 +1770,43 @@ cmd_help(char **tokens,
 		return;
 	}
 
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 4) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[1], "profile")
+		&& !strcmp(tokens[1], "add")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_add_help);
+		return;
+	}
+
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 4) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[1], "profile")
+		&& !strcmp(tokens[1], "delete")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_delete_help);
+		return;
+	}
+
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 3) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[2], "reset")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_reset_help);
+		return;
+	}
+
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 3) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[2], "set")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_set_help);
+		return;
+	}
+
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 3) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[2], "stats")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_stats_help);
+		return;
+	}
+
 	if ((n_tokens == 3) &&
 		(strcmp(tokens[0], "thread") == 0) &&
 		(strcmp(tokens[1], "pipeline") == 0)) {
@@ -1481,6 +1915,43 @@ cli_process(char *in, char *out, size_t out_size, void *obj)
 			return;
 		}
 
+		if ((n_tokens >= 6) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[3], "profile") == 0) &&
+			(strcmp(tokens[5], "add") == 0)) {
+			cmd_pipeline_meter_profile_add(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 6) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[3], "profile") == 0) &&
+			(strcmp(tokens[5], "delete") == 0)) {
+			cmd_pipeline_meter_profile_delete(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 9) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[8], "reset") == 0)) {
+			cmd_pipeline_meter_reset(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 9) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[8], "set") == 0)) {
+			cmd_pipeline_meter_set(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 9) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[8], "stats") == 0)) {
+			cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
 		if ((n_tokens >= 3) &&
 			(strcmp(tokens[2], "stats") == 0)) {
 			cmd_pipeline_stats(tokens, n_tokens, out, out_size,
examples/pipeline/examples/meter.cli new file +31 -0
new file mode 100644
index 000000000..b29ed2402
@@ -0,0 +1,31 @@
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright(c) 2020 Intel Corporation
+
+; Example command line:
+;	./build/examples/dpdk-pipeline -l0-1 -- -s ./examples/pipeline/examples/meter.cli
+
+mempool MEMPOOL0 buffer 2304 pool 32K cache 256 cpu 0
+
+link LINK0 dev 0000:18:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK1 dev 0000:18:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK2 dev 0000:3b:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK3 dev 0000:3b:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+
+pipeline PIPELINE0 create 0
+
+pipeline PIPELINE0 port in 0 link LINK0 rxq 0 bsz 32
+pipeline PIPELINE0 port in 1 link LINK1 rxq 0 bsz 32
+pipeline PIPELINE0 port in 2 link LINK2 rxq 0 bsz 32
+pipeline PIPELINE0 port in 3 link LINK3 rxq 0 bsz 32
+
+pipeline PIPELINE0 port out 0 link LINK0 txq 0 bsz 32
+pipeline PIPELINE0 port out 1 link LINK1 txq 0 bsz 32
+pipeline PIPELINE0 port out 2 link LINK2 txq 0 bsz 32
+pipeline PIPELINE0 port out 3 link LINK3 txq 0 bsz 32
+
+pipeline PIPELINE0 build ./examples/pipeline/examples/meter.spec
+
+pipeline PIPELINE0 meter profile platinum add cir 46000000 pir 138000000 cbs 1000000 pbs 1000000
+pipeline PIPELINE0 meter meters from 0 to 15 set profile platinum
+
+thread 1 pipeline PIPELINE0 enable
examples/pipeline/examples/meter.spec new file +63 -0

63 lines not on this page · raw message

lib/librte_pipeline/rte_swx_ctl.h +154 -0

172 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.c +1488 -196

1,841 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.h +22 -0
index 1c9b2eb12..156b1fd67 100644
@@ -640,6 +640,28 @@ rte_swx_pipeline_regarray_config(struct rte_swx_pipeline *p,
 				 uint32_t size,
 				 uint64_t init_val);
 
+/**
+ * Pipeline meter array configure
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] name
+ *   Meter array name.
+ * @param[in] size
+ *   Number of meters in the array. Each meter in the array implements the Two
+ *   Rate Three Color Marker (trTCM) algorithm, as specified by RFC 2698.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough space/cannot allocate memory;
+ *   -EEXIST: Meter array with this name already exists.
+ */
+__rte_experimental
+int
+rte_swx_pipeline_metarray_config(struct rte_swx_pipeline *p,
+				 const char *name,
+				 uint32_t size);
+
 /**
  * Pipeline instructions configure
  *
lib/librte_pipeline/rte_swx_pipeline_spec.c +91 -0

115 lines not on this page · raw message

lib/librte_pipeline/version.map +7 -0
index 26a9edf47..2049d6d69 100644
@@ -104,8 +104,15 @@ EXPERIMENTAL {
 	rte_swx_pipeline_table_type_register;
 
 	#added in 21.05
+	rte_swx_ctl_metarray_info_get;
+	rte_swx_ctl_meter_profile_add;
+	rte_swx_ctl_meter_profile_delete;
+	rte_swx_ctl_meter_reset;
+	rte_swx_ctl_meter_set;
+	rte_swx_ctl_meter_stats_read;
 	rte_swx_ctl_pipeline_regarray_read;
 	rte_swx_ctl_pipeline_regarray_write;
 	rte_swx_ctl_regarray_info_get;
+	rte_swx_pipeline_metarray_config;
 	rte_swx_pipeline_regarray_config;
 };
Signature · 1 line
2.17.1
#3 lore raw

PATCH v4 1/2 pipeline: add register array support to SWX pipeline

In reply to Cristian Dumitrescu

Register arrays are stateful objects that can be read & modified by both the data plane and the control plane, as opposed to tables, which are read-only for data plane. One key use-case is the implementation of stats counters.

---
 examples/pipeline/cli.c                     |  125 ++
 examples/pipeline/examples/registers.cli    |   28 +
 examples/pipeline/examples/registers.spec   |   67 +
 lib/librte_pipeline/rte_swx_ctl.h           |   79 +
 lib/librte_pipeline/rte_swx_pipeline.c      | 1602 +++++++++++++++++--
 lib/librte_pipeline/rte_swx_pipeline.h      |   24 +
 lib/librte_pipeline/rte_swx_pipeline_spec.c |  105 ++
 lib/librte_pipeline/version.map             |    6 +
 8 files changed, 1882 insertions(+), 154 deletions(-)
 create mode 100644 examples/pipeline/examples/registers.cli
 create mode 100644 examples/pipeline/examples/registers.spec
examples/pipeline/cli.c +125 -0
index 30c2dd34d..cdf8f13f3 100644
@@ -1009,6 +1009,105 @@ cmd_pipeline_table_update(char **tokens,
 		fclose(file_default);
 }
 
+static const char cmd_pipeline_regrd_help[] =
+"pipeline <pipeline_name> regrd <register_array_name> <index>\n";
+
+static void
+cmd_pipeline_regrd(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name;
+	uint64_t value;
+	uint32_t idx;
+	int status;
+
+	if (n_tokens != 5) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "regrd")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regrd");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (parser_read_uint32(&idx, tokens[4])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+		return;
+	}
+
+	status = rte_swx_ctl_pipeline_regarray_read(p->p, name, idx, &value);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+
+	snprintf(out, out_size, "0x%" PRIx64 "\n", value);
+}
+
+static const char cmd_pipeline_regwr_help[] =
+"pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n";
+
+static void
+cmd_pipeline_regwr(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name;
+	uint64_t value;
+	uint32_t idx;
+	int status;
+
+	if (n_tokens != 6) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "regwr")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regwr");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (parser_read_uint32(&idx, tokens[4])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+		return;
+	}
+
+	if (parser_read_uint64(&value, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "value");
+		return;
+	}
+
+	status = rte_swx_ctl_pipeline_regarray_write(p->p, name, idx, value);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+}
+
 static const char cmd_pipeline_stats_help[] =
 "pipeline <pipeline_name> stats\n";
 
@@ -1202,6 +1301,8 @@ cmd_help(char **tokens,
 			"\tpipeline port out\n"
 			"\tpipeline build\n"
 			"\tpipeline table update\n"
+			"\tpipeline regrd\n"
+			"\tpipeline regwr\n"
 			"\tpipeline stats\n"
 			"\tthread pipeline enable\n"
 			"\tthread pipeline disable\n\n");
@@ -1254,6 +1355,18 @@ cmd_help(char **tokens,
 		return;
 	}
 
+	if ((strcmp(tokens[0], "pipeline") == 0) &&
+		(n_tokens == 2) && (strcmp(tokens[1], "regrd") == 0)) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_regrd_help);
+		return;
+	}
+
+	if ((strcmp(tokens[0], "pipeline") == 0) &&
+		(n_tokens == 2) && (strcmp(tokens[1], "regwr") == 0)) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_regwr_help);
+		return;
+	}
+
 	if ((strcmp(tokens[0], "pipeline") == 0) &&
 		(n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) {
 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help);
@@ -1356,6 +1469,18 @@ cli_process(char *in, char *out, size_t out_size, void *obj)
 			return;
 		}
 
+		if ((n_tokens >= 3) &&
+			(strcmp(tokens[2], "regrd") == 0)) {
+			cmd_pipeline_regrd(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 3) &&
+			(strcmp(tokens[2], "regwr") == 0)) {
+			cmd_pipeline_regwr(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
 		if ((n_tokens >= 3) &&
 			(strcmp(tokens[2], "stats") == 0)) {
 			cmd_pipeline_stats(tokens, n_tokens, out, out_size,
examples/pipeline/examples/registers.cli new file +28 -0
new file mode 100644
index 000000000..8d026294c
@@ -0,0 +1,28 @@
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright(c) 2020 Intel Corporation
+
+; Example command line:
+;	./build/examples/dpdk-pipeline -l0-1 -- -s ./examples/pipeline/examples/registers.cli
+
+mempool MEMPOOL0 buffer 2304 pool 32K cache 256 cpu 0
+
+link LINK0 dev 0000:18:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK1 dev 0000:18:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK2 dev 0000:3b:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK3 dev 0000:3b:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+
+pipeline PIPELINE0 create 0
+
+pipeline PIPELINE0 port in 0 link LINK0 rxq 0 bsz 32
+pipeline PIPELINE0 port in 1 link LINK1 rxq 0 bsz 32
+pipeline PIPELINE0 port in 2 link LINK2 rxq 0 bsz 32
+pipeline PIPELINE0 port in 3 link LINK3 rxq 0 bsz 32
+
+pipeline PIPELINE0 port out 0 link LINK0 txq 0 bsz 32
+pipeline PIPELINE0 port out 1 link LINK1 txq 0 bsz 32
+pipeline PIPELINE0 port out 2 link LINK2 txq 0 bsz 32
+pipeline PIPELINE0 port out 3 link LINK3 txq 0 bsz 32
+
+pipeline PIPELINE0 build ./examples/pipeline/examples/registers.spec
+
+thread 1 pipeline PIPELINE0 enable
examples/pipeline/examples/registers.spec new file +67 -0

67 lines not on this page · raw message

lib/librte_pipeline/rte_swx_ctl.h +79 -0

91 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.c +1448 -154

1,769 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.h +24 -0
index f0a2cef77..1c9b2eb12 100644
@@ -616,6 +616,30 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
 			      const char *args,
 			      uint32_t size);
 
+/**
+ * Pipeline register array configure
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] name
+ *   Register array name.
+ * @param[in] size
+ *   Number of registers in the array. Each register is 64-bit in size.
+ * @param[in] init_val
+ *   Initial value for every register in the array. The recommended value is 0.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough space/cannot allocate memory;
+ *   -EEXIST: Register array with this name already exists.
+ */
+__rte_experimental
+int
+rte_swx_pipeline_regarray_config(struct rte_swx_pipeline *p,
+				 const char *name,
+				 uint32_t size,
+				 uint64_t init_val);
+
 /**
  * Pipeline instructions configure
  *
lib/librte_pipeline/rte_swx_pipeline_spec.c +105 -0

129 lines not on this page · raw message

lib/librte_pipeline/version.map +6 -0
index 87c826f1b..26a9edf47 100644
@@ -102,4 +102,10 @@ EXPERIMENTAL {
 	rte_swx_pipeline_table_state_get;
 	rte_swx_pipeline_table_state_set;
 	rte_swx_pipeline_table_type_register;
+
+	#added in 21.05
+	rte_swx_ctl_pipeline_regarray_read;
+	rte_swx_ctl_pipeline_regarray_write;
+	rte_swx_ctl_regarray_info_get;
+	rte_swx_pipeline_regarray_config;
 };
Signature · 1 line
2.17.1
#4 lore raw

PATCH v4 2/2 pipeline: add meter support to the SWX pipeline

Meter arrays are stateful objects that are updated by the data plane and configured & monitored by the control plane. The meters implement the RFC 2698 Two Rate Three Color Marker (trTCM) algorithm.

---
 examples/pipeline/cli.c                     |  471 ++++++
 examples/pipeline/examples/meter.cli        |   31 +
 examples/pipeline/examples/meter.spec       |   63 +
 lib/librte_pipeline/rte_swx_ctl.h           |  155 ++
 lib/librte_pipeline/rte_swx_pipeline.c      | 1684 ++++++++++++++++---
 lib/librte_pipeline/rte_swx_pipeline.h      |   22 +
 lib/librte_pipeline/rte_swx_pipeline_spec.c |   91 +
 lib/librte_pipeline/version.map             |    7 +
 8 files changed, 2328 insertions(+), 196 deletions(-)
 create mode 100644 examples/pipeline/examples/meter.cli
 create mode 100644 examples/pipeline/examples/meter.spec
examples/pipeline/cli.c +471 -0
index cdf8f13f3..045525307 100644
@@ -1108,6 +1108,398 @@ cmd_pipeline_regwr(char **tokens,
 	}
 }
 
+static const char cmd_pipeline_meter_profile_add_help[] =
+"pipeline <pipeline_name> meter profile <profile_name> add "
+	"cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
+
+static void
+cmd_pipeline_meter_profile_add(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct rte_meter_trtcm_params params;
+	struct pipeline *p;
+	const char *profile_name;
+	int status;
+
+	if (n_tokens != 14) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	if (strcmp(tokens[3], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
+		return;
+	}
+
+	profile_name = tokens[4];
+
+	if (strcmp(tokens[5], "add")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
+		return;
+	}
+
+	if (strcmp(tokens[6], "cir")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
+		return;
+	}
+
+	if (parser_read_uint64(&params.cir, tokens[7])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "cir");
+		return;
+	}
+
+	if (strcmp(tokens[8], "pir")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
+		return;
+	}
+
+	if (parser_read_uint64(&params.pir, tokens[9])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pir");
+		return;
+	}
+
+	if (strcmp(tokens[10], "cbs")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
+		return;
+	}
+
+	if (parser_read_uint64(&params.cbs, tokens[11])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
+		return;
+	}
+
+	if (strcmp(tokens[12], "pbs")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
+		return;
+	}
+
+	if (parser_read_uint64(&params.pbs, tokens[13])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
+		return;
+	}
+
+	status = rte_swx_ctl_meter_profile_add(p->p, profile_name, &params);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+}
+
+static const char cmd_pipeline_meter_profile_delete_help[] =
+"pipeline <pipeline_name> meter profile <profile_name> delete\n";
+
+static void
+cmd_pipeline_meter_profile_delete(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *profile_name;
+	int status;
+
+	if (n_tokens != 6) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	if (strcmp(tokens[3], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
+		return;
+	}
+
+	profile_name = tokens[4];
+
+	if (strcmp(tokens[5], "delete")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
+		return;
+	}
+
+	status = rte_swx_ctl_meter_profile_delete(p->p, profile_name);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+}
+
+static const char cmd_pipeline_meter_reset_help[] =
+"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
+	"reset\n";
+
+static void
+cmd_pipeline_meter_reset(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name;
+	uint32_t idx0, idx1;
+
+	if (n_tokens != 9) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (strcmp(tokens[4], "from")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+		return;
+	}
+
+	if (parser_read_uint32(&idx0, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+		return;
+	}
+
+	if (strcmp(tokens[6], "to")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+		return;
+	}
+
+	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+		return;
+	}
+
+	if (strcmp(tokens[8], "reset")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
+		return;
+	}
+
+	for ( ; idx0 <= idx1; idx0++) {
+		int status;
+
+		status = rte_swx_ctl_meter_reset(p->p, name, idx0);
+		if (status) {
+			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			return;
+		}
+	}
+}
+
+static const char cmd_pipeline_meter_set_help[] =
+"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
+	"set profile <profile_name>\n";
+
+static void
+cmd_pipeline_meter_set(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name, *profile_name;
+	uint32_t idx0, idx1;
+
+	if (n_tokens != 11) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (strcmp(tokens[4], "from")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+		return;
+	}
+
+	if (parser_read_uint32(&idx0, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+		return;
+	}
+
+	if (strcmp(tokens[6], "to")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+		return;
+	}
+
+	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+		return;
+	}
+
+	if (strcmp(tokens[8], "set")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
+		return;
+	}
+
+	if (strcmp(tokens[9], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
+		return;
+	}
+
+	profile_name = tokens[10];
+
+	for ( ; idx0 <= idx1; idx0++) {
+		int status;
+
+		status = rte_swx_ctl_meter_set(p->p, name, idx0, profile_name);
+		if (status) {
+			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			return;
+		}
+	}
+}
+
+static const char cmd_pipeline_meter_stats_help[] =
+"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
+	"stats\n";
+
+static void
+cmd_pipeline_meter_stats(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct rte_swx_ctl_meter_stats stats;
+	struct pipeline *p;
+	const char *name;
+	uint32_t idx0, idx1;
+
+	if (n_tokens != 9) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (strcmp(tokens[4], "from")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+		return;
+	}
+
+	if (parser_read_uint32(&idx0, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+		return;
+	}
+
+	if (strcmp(tokens[6], "to")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+		return;
+	}
+
+	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+		return;
+	}
+
+	if (strcmp(tokens[8], "stats")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
+		return;
+	}
+
+	/* Table header. */
+	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
+		 "-------",
+		 "----------------", "----------------", "----------------",
+		 "----------------", "----------------", "----------------");
+	out_size -= strlen(out);
+	out += strlen(out);
+
+	snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n",
+		 "METER #",
+		 "GREEN (packets)", "YELLOW (packets)", "RED (packets)",
+		 "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)");
+	out_size -= strlen(out);
+	out += strlen(out);
+
+	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
+		 "-------",
+		 "----------------", "----------------", "----------------",
+		 "----------------", "----------------", "----------------");
+	out_size -= strlen(out);
+	out += strlen(out);
+
+	/* Table rows. */
+	for ( ; idx0 <= idx1; idx0++) {
+		int status;
+
+		status = rte_swx_ctl_meter_stats_read(p->p, name, idx0, &stats);
+		if (status) {
+			snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0);
+			out_size -= strlen(out);
+			out += strlen(out);
+			return;
+		}
+
+		snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64
+			 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n",
+			 idx0,
+			 stats.n_pkts[RTE_COLOR_GREEN],
+			 stats.n_pkts[RTE_COLOR_YELLOW],
+			 stats.n_pkts[RTE_COLOR_RED],
+			 stats.n_bytes[RTE_COLOR_GREEN],
+			 stats.n_bytes[RTE_COLOR_YELLOW],
+			 stats.n_bytes[RTE_COLOR_RED]);
+		out_size -= strlen(out);
+		out += strlen(out);
+	}
+}
+
 static const char cmd_pipeline_stats_help[] =
 "pipeline <pipeline_name> stats\n";
 
@@ -1303,6 +1695,11 @@ cmd_help(char **tokens,
 			"\tpipeline table update\n"
 			"\tpipeline regrd\n"
 			"\tpipeline regwr\n"
+			"\tpipeline meter profile add\n"
+			"\tpipeline meter profile delete\n"
+			"\tpipeline meter reset\n"
+			"\tpipeline meter set\n"
+			"\tpipeline meter stats\n"
 			"\tpipeline stats\n"
 			"\tthread pipeline enable\n"
 			"\tthread pipeline disable\n\n");
@@ -1373,6 +1770,43 @@ cmd_help(char **tokens,
 		return;
 	}
 
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 4) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[1], "profile")
+		&& !strcmp(tokens[1], "add")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_add_help);
+		return;
+	}
+
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 4) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[1], "profile")
+		&& !strcmp(tokens[1], "delete")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_delete_help);
+		return;
+	}
+
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 3) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[2], "reset")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_reset_help);
+		return;
+	}
+
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 3) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[2], "set")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_set_help);
+		return;
+	}
+
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 3) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[2], "stats")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_stats_help);
+		return;
+	}
+
 	if ((n_tokens == 3) &&
 		(strcmp(tokens[0], "thread") == 0) &&
 		(strcmp(tokens[1], "pipeline") == 0)) {
@@ -1481,6 +1915,43 @@ cli_process(char *in, char *out, size_t out_size, void *obj)
 			return;
 		}
 
+		if ((n_tokens >= 6) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[3], "profile") == 0) &&
+			(strcmp(tokens[5], "add") == 0)) {
+			cmd_pipeline_meter_profile_add(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 6) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[3], "profile") == 0) &&
+			(strcmp(tokens[5], "delete") == 0)) {
+			cmd_pipeline_meter_profile_delete(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 9) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[8], "reset") == 0)) {
+			cmd_pipeline_meter_reset(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 9) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[8], "set") == 0)) {
+			cmd_pipeline_meter_set(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 9) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[8], "stats") == 0)) {
+			cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
 		if ((n_tokens >= 3) &&
 			(strcmp(tokens[2], "stats") == 0)) {
 			cmd_pipeline_stats(tokens, n_tokens, out, out_size,
examples/pipeline/examples/meter.cli new file +31 -0
new file mode 100644
index 000000000..b29ed2402
@@ -0,0 +1,31 @@
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright(c) 2020 Intel Corporation
+
+; Example command line:
+;	./build/examples/dpdk-pipeline -l0-1 -- -s ./examples/pipeline/examples/meter.cli
+
+mempool MEMPOOL0 buffer 2304 pool 32K cache 256 cpu 0
+
+link LINK0 dev 0000:18:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK1 dev 0000:18:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK2 dev 0000:3b:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK3 dev 0000:3b:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+
+pipeline PIPELINE0 create 0
+
+pipeline PIPELINE0 port in 0 link LINK0 rxq 0 bsz 32
+pipeline PIPELINE0 port in 1 link LINK1 rxq 0 bsz 32
+pipeline PIPELINE0 port in 2 link LINK2 rxq 0 bsz 32
+pipeline PIPELINE0 port in 3 link LINK3 rxq 0 bsz 32
+
+pipeline PIPELINE0 port out 0 link LINK0 txq 0 bsz 32
+pipeline PIPELINE0 port out 1 link LINK1 txq 0 bsz 32
+pipeline PIPELINE0 port out 2 link LINK2 txq 0 bsz 32
+pipeline PIPELINE0 port out 3 link LINK3 txq 0 bsz 32
+
+pipeline PIPELINE0 build ./examples/pipeline/examples/meter.spec
+
+pipeline PIPELINE0 meter profile platinum add cir 46000000 pir 138000000 cbs 1000000 pbs 1000000
+pipeline PIPELINE0 meter meters from 0 to 15 set profile platinum
+
+thread 1 pipeline PIPELINE0 enable
examples/pipeline/examples/meter.spec new file +63 -0

63 lines not on this page · raw message

lib/librte_pipeline/rte_swx_ctl.h +155 -0

173 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.c +1488 -196

1,840 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.h +22 -0
index 1c9b2eb12..156b1fd67 100644
@@ -640,6 +640,28 @@ rte_swx_pipeline_regarray_config(struct rte_swx_pipeline *p,
 				 uint32_t size,
 				 uint64_t init_val);
 
+/**
+ * Pipeline meter array configure
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] name
+ *   Meter array name.
+ * @param[in] size
+ *   Number of meters in the array. Each meter in the array implements the Two
+ *   Rate Three Color Marker (trTCM) algorithm, as specified by RFC 2698.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough space/cannot allocate memory;
+ *   -EEXIST: Meter array with this name already exists.
+ */
+__rte_experimental
+int
+rte_swx_pipeline_metarray_config(struct rte_swx_pipeline *p,
+				 const char *name,
+				 uint32_t size);
+
 /**
  * Pipeline instructions configure
  *
lib/librte_pipeline/rte_swx_pipeline_spec.c +91 -0

115 lines not on this page · raw message

lib/librte_pipeline/version.map +7 -0
index 26a9edf47..2049d6d69 100644
@@ -104,8 +104,15 @@ EXPERIMENTAL {
 	rte_swx_pipeline_table_type_register;
 
 	#added in 21.05
+	rte_swx_ctl_metarray_info_get;
+	rte_swx_ctl_meter_profile_add;
+	rte_swx_ctl_meter_profile_delete;
+	rte_swx_ctl_meter_reset;
+	rte_swx_ctl_meter_set;
+	rte_swx_ctl_meter_stats_read;
 	rte_swx_ctl_pipeline_regarray_read;
 	rte_swx_ctl_pipeline_regarray_write;
 	rte_swx_ctl_regarray_info_get;
+	rte_swx_pipeline_metarray_config;
 	rte_swx_pipeline_regarray_config;
 };
Signature · 1 line
2.17.1
#5 lore raw

PATCH v5 1/2 pipeline: add register array support to SWX pipeline

In reply to Cristian Dumitrescu

Register arrays are stateful objects that can be read & modified by both the data plane and the control plane, as opposed to tables, which are read-only for data plane. One key use-case is the implementation of stats counters.

---
 examples/pipeline/cli.c                     |  125 ++
 examples/pipeline/examples/registers.cli    |   28 +
 examples/pipeline/examples/registers.spec   |   67 +
 lib/librte_pipeline/rte_swx_ctl.h           |   79 +
 lib/librte_pipeline/rte_swx_pipeline.c      | 1602 +++++++++++++++++--
 lib/librte_pipeline/rte_swx_pipeline.h      |   24 +
 lib/librte_pipeline/rte_swx_pipeline_spec.c |  105 ++
 lib/librte_pipeline/version.map             |    6 +
 8 files changed, 1882 insertions(+), 154 deletions(-)
 create mode 100644 examples/pipeline/examples/registers.cli
 create mode 100644 examples/pipeline/examples/registers.spec
examples/pipeline/cli.c +125 -0
index 30c2dd34d..cdf8f13f3 100644
@@ -1009,6 +1009,105 @@ cmd_pipeline_table_update(char **tokens,
 		fclose(file_default);
 }
 
+static const char cmd_pipeline_regrd_help[] =
+"pipeline <pipeline_name> regrd <register_array_name> <index>\n";
+
+static void
+cmd_pipeline_regrd(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name;
+	uint64_t value;
+	uint32_t idx;
+	int status;
+
+	if (n_tokens != 5) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "regrd")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regrd");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (parser_read_uint32(&idx, tokens[4])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+		return;
+	}
+
+	status = rte_swx_ctl_pipeline_regarray_read(p->p, name, idx, &value);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+
+	snprintf(out, out_size, "0x%" PRIx64 "\n", value);
+}
+
+static const char cmd_pipeline_regwr_help[] =
+"pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n";
+
+static void
+cmd_pipeline_regwr(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name;
+	uint64_t value;
+	uint32_t idx;
+	int status;
+
+	if (n_tokens != 6) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "regwr")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regwr");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (parser_read_uint32(&idx, tokens[4])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+		return;
+	}
+
+	if (parser_read_uint64(&value, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "value");
+		return;
+	}
+
+	status = rte_swx_ctl_pipeline_regarray_write(p->p, name, idx, value);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+}
+
 static const char cmd_pipeline_stats_help[] =
 "pipeline <pipeline_name> stats\n";
 
@@ -1202,6 +1301,8 @@ cmd_help(char **tokens,
 			"\tpipeline port out\n"
 			"\tpipeline build\n"
 			"\tpipeline table update\n"
+			"\tpipeline regrd\n"
+			"\tpipeline regwr\n"
 			"\tpipeline stats\n"
 			"\tthread pipeline enable\n"
 			"\tthread pipeline disable\n\n");
@@ -1254,6 +1355,18 @@ cmd_help(char **tokens,
 		return;
 	}
 
+	if ((strcmp(tokens[0], "pipeline") == 0) &&
+		(n_tokens == 2) && (strcmp(tokens[1], "regrd") == 0)) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_regrd_help);
+		return;
+	}
+
+	if ((strcmp(tokens[0], "pipeline") == 0) &&
+		(n_tokens == 2) && (strcmp(tokens[1], "regwr") == 0)) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_regwr_help);
+		return;
+	}
+
 	if ((strcmp(tokens[0], "pipeline") == 0) &&
 		(n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) {
 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help);
@@ -1356,6 +1469,18 @@ cli_process(char *in, char *out, size_t out_size, void *obj)
 			return;
 		}
 
+		if ((n_tokens >= 3) &&
+			(strcmp(tokens[2], "regrd") == 0)) {
+			cmd_pipeline_regrd(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 3) &&
+			(strcmp(tokens[2], "regwr") == 0)) {
+			cmd_pipeline_regwr(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
 		if ((n_tokens >= 3) &&
 			(strcmp(tokens[2], "stats") == 0)) {
 			cmd_pipeline_stats(tokens, n_tokens, out, out_size,
examples/pipeline/examples/registers.cli new file +28 -0
new file mode 100644
index 000000000..8d026294c
@@ -0,0 +1,28 @@
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright(c) 2020 Intel Corporation
+
+; Example command line:
+;	./build/examples/dpdk-pipeline -l0-1 -- -s ./examples/pipeline/examples/registers.cli
+
+mempool MEMPOOL0 buffer 2304 pool 32K cache 256 cpu 0
+
+link LINK0 dev 0000:18:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK1 dev 0000:18:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK2 dev 0000:3b:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK3 dev 0000:3b:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+
+pipeline PIPELINE0 create 0
+
+pipeline PIPELINE0 port in 0 link LINK0 rxq 0 bsz 32
+pipeline PIPELINE0 port in 1 link LINK1 rxq 0 bsz 32
+pipeline PIPELINE0 port in 2 link LINK2 rxq 0 bsz 32
+pipeline PIPELINE0 port in 3 link LINK3 rxq 0 bsz 32
+
+pipeline PIPELINE0 port out 0 link LINK0 txq 0 bsz 32
+pipeline PIPELINE0 port out 1 link LINK1 txq 0 bsz 32
+pipeline PIPELINE0 port out 2 link LINK2 txq 0 bsz 32
+pipeline PIPELINE0 port out 3 link LINK3 txq 0 bsz 32
+
+pipeline PIPELINE0 build ./examples/pipeline/examples/registers.spec
+
+thread 1 pipeline PIPELINE0 enable
examples/pipeline/examples/registers.spec new file +67 -0

67 lines not on this page · raw message

lib/librte_pipeline/rte_swx_ctl.h +79 -0

91 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.c +1448 -154

1,769 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.h +24 -0
index f0a2cef77..1c9b2eb12 100644
@@ -616,6 +616,30 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
 			      const char *args,
 			      uint32_t size);
 
+/**
+ * Pipeline register array configure
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] name
+ *   Register array name.
+ * @param[in] size
+ *   Number of registers in the array. Each register is 64-bit in size.
+ * @param[in] init_val
+ *   Initial value for every register in the array. The recommended value is 0.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough space/cannot allocate memory;
+ *   -EEXIST: Register array with this name already exists.
+ */
+__rte_experimental
+int
+rte_swx_pipeline_regarray_config(struct rte_swx_pipeline *p,
+				 const char *name,
+				 uint32_t size,
+				 uint64_t init_val);
+
 /**
  * Pipeline instructions configure
  *
lib/librte_pipeline/rte_swx_pipeline_spec.c +105 -0

129 lines not on this page · raw message

lib/librte_pipeline/version.map +6 -0
index 87c826f1b..26a9edf47 100644
@@ -102,4 +102,10 @@ EXPERIMENTAL {
 	rte_swx_pipeline_table_state_get;
 	rte_swx_pipeline_table_state_set;
 	rte_swx_pipeline_table_type_register;
+
+	#added in 21.05
+	rte_swx_ctl_pipeline_regarray_read;
+	rte_swx_ctl_pipeline_regarray_write;
+	rte_swx_ctl_regarray_info_get;
+	rte_swx_pipeline_regarray_config;
 };
Signature · 1 line
2.17.1
#6 lore raw

PATCH v5 2/2 pipeline: add meter support to the SWX pipeline

Meter arrays are stateful objects that are updated by the data plane and configured & monitored by the control plane. The meters implement the RFC 2698 Two Rate Three Color Marker (trTCM) algorithm.

---
 examples/pipeline/cli.c                     |  471 ++++++
 examples/pipeline/examples/meter.cli        |   31 +
 examples/pipeline/examples/meter.spec       |   63 +
 lib/librte_pipeline/rte_swx_ctl.h           |  155 ++
 lib/librte_pipeline/rte_swx_pipeline.c      | 1684 ++++++++++++++++---
 lib/librte_pipeline/rte_swx_pipeline.h      |   22 +
 lib/librte_pipeline/rte_swx_pipeline_spec.c |   91 +
 lib/librte_pipeline/version.map             |    7 +
 8 files changed, 2328 insertions(+), 196 deletions(-)
 create mode 100644 examples/pipeline/examples/meter.cli
 create mode 100644 examples/pipeline/examples/meter.spec
examples/pipeline/cli.c +471 -0
index cdf8f13f3..718dd07d4 100644
@@ -1108,6 +1108,398 @@ cmd_pipeline_regwr(char **tokens,
 	}
 }
 
+static const char cmd_pipeline_meter_profile_add_help[] =
+"pipeline <pipeline_name> meter profile <profile_name> add "
+	"cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
+
+static void
+cmd_pipeline_meter_profile_add(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct rte_meter_trtcm_params params;
+	struct pipeline *p;
+	const char *profile_name;
+	int status;
+
+	if (n_tokens != 14) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	if (strcmp(tokens[3], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
+		return;
+	}
+
+	profile_name = tokens[4];
+
+	if (strcmp(tokens[5], "add")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
+		return;
+	}
+
+	if (strcmp(tokens[6], "cir")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
+		return;
+	}
+
+	if (parser_read_uint64(&params.cir, tokens[7])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "cir");
+		return;
+	}
+
+	if (strcmp(tokens[8], "pir")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
+		return;
+	}
+
+	if (parser_read_uint64(&params.pir, tokens[9])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pir");
+		return;
+	}
+
+	if (strcmp(tokens[10], "cbs")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
+		return;
+	}
+
+	if (parser_read_uint64(&params.cbs, tokens[11])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
+		return;
+	}
+
+	if (strcmp(tokens[12], "pbs")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
+		return;
+	}
+
+	if (parser_read_uint64(&params.pbs, tokens[13])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
+		return;
+	}
+
+	status = rte_swx_ctl_meter_profile_add(p->p, profile_name, &params);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+}
+
+static const char cmd_pipeline_meter_profile_delete_help[] =
+"pipeline <pipeline_name> meter profile <profile_name> delete\n";
+
+static void
+cmd_pipeline_meter_profile_delete(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *profile_name;
+	int status;
+
+	if (n_tokens != 6) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	if (strcmp(tokens[3], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
+		return;
+	}
+
+	profile_name = tokens[4];
+
+	if (strcmp(tokens[5], "delete")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
+		return;
+	}
+
+	status = rte_swx_ctl_meter_profile_delete(p->p, profile_name);
+	if (status) {
+		snprintf(out, out_size, "Command failed.\n");
+		return;
+	}
+}
+
+static const char cmd_pipeline_meter_reset_help[] =
+"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
+	"reset\n";
+
+static void
+cmd_pipeline_meter_reset(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name;
+	uint32_t idx0, idx1;
+
+	if (n_tokens != 9) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (strcmp(tokens[4], "from")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+		return;
+	}
+
+	if (parser_read_uint32(&idx0, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+		return;
+	}
+
+	if (strcmp(tokens[6], "to")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+		return;
+	}
+
+	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+		return;
+	}
+
+	if (strcmp(tokens[8], "reset")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
+		return;
+	}
+
+	for ( ; idx0 <= idx1; idx0++) {
+		int status;
+
+		status = rte_swx_ctl_meter_reset(p->p, name, idx0);
+		if (status) {
+			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			return;
+		}
+	}
+}
+
+static const char cmd_pipeline_meter_set_help[] =
+"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
+	"set profile <profile_name>\n";
+
+static void
+cmd_pipeline_meter_set(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct pipeline *p;
+	const char *name, *profile_name;
+	uint32_t idx0, idx1;
+
+	if (n_tokens != 11) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (strcmp(tokens[4], "from")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+		return;
+	}
+
+	if (parser_read_uint32(&idx0, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+		return;
+	}
+
+	if (strcmp(tokens[6], "to")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+		return;
+	}
+
+	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+		return;
+	}
+
+	if (strcmp(tokens[8], "set")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
+		return;
+	}
+
+	if (strcmp(tokens[9], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
+		return;
+	}
+
+	profile_name = tokens[10];
+
+	for ( ; idx0 <= idx1; idx0++) {
+		int status;
+
+		status = rte_swx_ctl_meter_set(p->p, name, idx0, profile_name);
+		if (status) {
+			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			return;
+		}
+	}
+}
+
+static const char cmd_pipeline_meter_stats_help[] =
+"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
+	"stats\n";
+
+static void
+cmd_pipeline_meter_stats(char **tokens,
+	uint32_t n_tokens,
+	char *out,
+	size_t out_size,
+	void *obj)
+{
+	struct rte_swx_ctl_meter_stats stats;
+	struct pipeline *p;
+	const char *name;
+	uint32_t idx0, idx1;
+
+	if (n_tokens != 9) {
+		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+		return;
+	}
+
+	p = pipeline_find(obj, tokens[1]);
+	if (!p || !p->ctl) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
+		return;
+	}
+
+	if (strcmp(tokens[2], "meter")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
+		return;
+	}
+
+	name = tokens[3];
+
+	if (strcmp(tokens[4], "from")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+		return;
+	}
+
+	if (parser_read_uint32(&idx0, tokens[5])) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+		return;
+	}
+
+	if (strcmp(tokens[6], "to")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+		return;
+	}
+
+	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
+		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+		return;
+	}
+
+	if (strcmp(tokens[8], "stats")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
+		return;
+	}
+
+	/* Table header. */
+	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
+		 "-------",
+		 "----------------", "----------------", "----------------",
+		 "----------------", "----------------", "----------------");
+	out_size -= strlen(out);
+	out += strlen(out);
+
+	snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n",
+		 "METER #",
+		 "GREEN (packets)", "YELLOW (packets)", "RED (packets)",
+		 "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)");
+	out_size -= strlen(out);
+	out += strlen(out);
+
+	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
+		 "-------",
+		 "----------------", "----------------", "----------------",
+		 "----------------", "----------------", "----------------");
+	out_size -= strlen(out);
+	out += strlen(out);
+
+	/* Table rows. */
+	for ( ; idx0 <= idx1; idx0++) {
+		int status;
+
+		status = rte_swx_ctl_meter_stats_read(p->p, name, idx0, &stats);
+		if (status) {
+			snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0);
+			out_size -= strlen(out);
+			out += strlen(out);
+			return;
+		}
+
+		snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64
+			 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n",
+			 idx0,
+			 stats.n_pkts[RTE_COLOR_GREEN],
+			 stats.n_pkts[RTE_COLOR_YELLOW],
+			 stats.n_pkts[RTE_COLOR_RED],
+			 stats.n_bytes[RTE_COLOR_GREEN],
+			 stats.n_bytes[RTE_COLOR_YELLOW],
+			 stats.n_bytes[RTE_COLOR_RED]);
+		out_size -= strlen(out);
+		out += strlen(out);
+	}
+}
+
 static const char cmd_pipeline_stats_help[] =
 "pipeline <pipeline_name> stats\n";
 
@@ -1303,6 +1695,11 @@ cmd_help(char **tokens,
 			"\tpipeline table update\n"
 			"\tpipeline regrd\n"
 			"\tpipeline regwr\n"
+			"\tpipeline meter profile add\n"
+			"\tpipeline meter profile delete\n"
+			"\tpipeline meter reset\n"
+			"\tpipeline meter set\n"
+			"\tpipeline meter stats\n"
 			"\tpipeline stats\n"
 			"\tthread pipeline enable\n"
 			"\tthread pipeline disable\n\n");
@@ -1367,6 +1764,43 @@ cmd_help(char **tokens,
 		return;
 	}
 
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 4) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[2], "profile")
+		&& !strcmp(tokens[3], "add")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_add_help);
+		return;
+	}
+
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 4) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[2], "profile")
+		&& !strcmp(tokens[3], "delete")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_delete_help);
+		return;
+	}
+
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 3) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[2], "reset")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_reset_help);
+		return;
+	}
+
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 3) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[2], "set")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_set_help);
+		return;
+	}
+
+	if (!strcmp(tokens[0], "pipeline") &&
+		(n_tokens == 3) && !strcmp(tokens[1], "meter")
+		&& !strcmp(tokens[2], "stats")) {
+		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_stats_help);
+		return;
+	}
+
 	if ((strcmp(tokens[0], "pipeline") == 0) &&
 		(n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) {
 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help);
@@ -1481,6 +1915,43 @@ cli_process(char *in, char *out, size_t out_size, void *obj)
 			return;
 		}
 
+		if ((n_tokens >= 6) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[3], "profile") == 0) &&
+			(strcmp(tokens[5], "add") == 0)) {
+			cmd_pipeline_meter_profile_add(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 6) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[3], "profile") == 0) &&
+			(strcmp(tokens[5], "delete") == 0)) {
+			cmd_pipeline_meter_profile_delete(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 9) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[8], "reset") == 0)) {
+			cmd_pipeline_meter_reset(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 9) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[8], "set") == 0)) {
+			cmd_pipeline_meter_set(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
+		if ((n_tokens >= 9) &&
+			(strcmp(tokens[2], "meter") == 0) &&
+			(strcmp(tokens[8], "stats") == 0)) {
+			cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj);
+			return;
+		}
+
 		if ((n_tokens >= 3) &&
 			(strcmp(tokens[2], "stats") == 0)) {
 			cmd_pipeline_stats(tokens, n_tokens, out, out_size,
examples/pipeline/examples/meter.cli new file +31 -0
new file mode 100644
index 000000000..b29ed2402
@@ -0,0 +1,31 @@
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright(c) 2020 Intel Corporation
+
+; Example command line:
+;	./build/examples/dpdk-pipeline -l0-1 -- -s ./examples/pipeline/examples/meter.cli
+
+mempool MEMPOOL0 buffer 2304 pool 32K cache 256 cpu 0
+
+link LINK0 dev 0000:18:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK1 dev 0000:18:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK2 dev 0000:3b:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK3 dev 0000:3b:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+
+pipeline PIPELINE0 create 0
+
+pipeline PIPELINE0 port in 0 link LINK0 rxq 0 bsz 32
+pipeline PIPELINE0 port in 1 link LINK1 rxq 0 bsz 32
+pipeline PIPELINE0 port in 2 link LINK2 rxq 0 bsz 32
+pipeline PIPELINE0 port in 3 link LINK3 rxq 0 bsz 32
+
+pipeline PIPELINE0 port out 0 link LINK0 txq 0 bsz 32
+pipeline PIPELINE0 port out 1 link LINK1 txq 0 bsz 32
+pipeline PIPELINE0 port out 2 link LINK2 txq 0 bsz 32
+pipeline PIPELINE0 port out 3 link LINK3 txq 0 bsz 32
+
+pipeline PIPELINE0 build ./examples/pipeline/examples/meter.spec
+
+pipeline PIPELINE0 meter profile platinum add cir 46000000 pir 138000000 cbs 1000000 pbs 1000000
+pipeline PIPELINE0 meter meters from 0 to 15 set profile platinum
+
+thread 1 pipeline PIPELINE0 enable
examples/pipeline/examples/meter.spec new file +63 -0

63 lines not on this page · raw message

lib/librte_pipeline/rte_swx_ctl.h +155 -0

173 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.c +1488 -196

1,840 lines not on this page · raw message

lib/librte_pipeline/rte_swx_pipeline.h +22 -0
index 1c9b2eb12..156b1fd67 100644
@@ -640,6 +640,28 @@ rte_swx_pipeline_regarray_config(struct rte_swx_pipeline *p,
 				 uint32_t size,
 				 uint64_t init_val);
 
+/**
+ * Pipeline meter array configure
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] name
+ *   Meter array name.
+ * @param[in] size
+ *   Number of meters in the array. Each meter in the array implements the Two
+ *   Rate Three Color Marker (trTCM) algorithm, as specified by RFC 2698.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough space/cannot allocate memory;
+ *   -EEXIST: Meter array with this name already exists.
+ */
+__rte_experimental
+int
+rte_swx_pipeline_metarray_config(struct rte_swx_pipeline *p,
+				 const char *name,
+				 uint32_t size);
+
 /**
  * Pipeline instructions configure
  *
lib/librte_pipeline/rte_swx_pipeline_spec.c +91 -0

115 lines not on this page · raw message

lib/librte_pipeline/version.map +7 -0
index 26a9edf47..2049d6d69 100644
@@ -104,8 +104,15 @@ EXPERIMENTAL {
 	rte_swx_pipeline_table_type_register;
 
 	#added in 21.05
+	rte_swx_ctl_metarray_info_get;
+	rte_swx_ctl_meter_profile_add;
+	rte_swx_ctl_meter_profile_delete;
+	rte_swx_ctl_meter_reset;
+	rte_swx_ctl_meter_set;
+	rte_swx_ctl_meter_stats_read;
 	rte_swx_ctl_pipeline_regarray_read;
 	rte_swx_ctl_pipeline_regarray_write;
 	rte_swx_ctl_regarray_info_get;
+	rte_swx_pipeline_metarray_config;
 	rte_swx_pipeline_regarray_config;
 };
Signature · 1 line
2.17.1
#7 lore raw

Re: [dpdk-dev] [PATCH v5 2/2] pipeline: add meter support to the SWX pipeline

16/03/2021 12:40, Cristian Dumitrescu:

Quoted 5 lines

Meter arrays are stateful objects that are updated by the data plane and configured & monitored by the control plane. The meters implement the RFC 2698 Two Rate Three Color Marker (trTCM) algorithm.

Series applied, thanks