DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 0/7] pipeline: support direct registers and meters
@ 2022-08-26 10:35 Cristian Dumitrescu
  2022-08-26 10:35 ` [PATCH 1/7] table: add entry ID for regular tables Cristian Dumitrescu
                   ` (8 more replies)
  0 siblings, 9 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 10:35 UTC (permalink / raw)
  To: dev

This patch introduces support for direct registers and meters. The
difference between indirect (indexed) and direct registers and meters
is explained below [1][2][3].

1. Indirect (indexed) registers and meters.

The index into an array of registers or meters used on the data path
is typically read from the action data identified by a table lookup
operation.

This means that the control plane manages the mapping of the mapping
of array entries to table entries and sets up this index explicitly
into the table entry action data.

These are called indirect or indexed registers and meters, and they
allow multiple table entries to share the same register/meter, as well
as a 1:1 mapping of table entries to register/meter array entries.

2. Direct registers and meters.
In the case of 1:1 mapping of table entries to register/meter array
elements, it is sometimes desired to avoid the explicit allocation of
register/meter array index to each table entry by the control plane.

One way this can be done is by implementing a mechanism to associate
a unique ID to each table entry, including the default table entry as
well; once the entry ID is retrieved as result of the table lookup
operation, it is saved by the pipeline and used later on as the
index into the register/meter array.

These are called direct registers and meters, and have the advantage
that the index is auto-generated, which simplifies the controller
implementation; the disadvantage is that they do not allow multiple
table entries to share the same register or meter.

References:

[1] Indirect and direct counters:
https://p4.org/p4-spec/docs/PSA.html#sec-counters

[2] Indirect and direct registers:
https://p4.org/p4-spec/docs/PSA.html#sec-registers

[3] Indirect and direct meters:
https://p4.org/p4-spec/docs/PSA.html#sec-meters

Cristian Dumitrescu (7):
  table: add entry ID for regular tables
  table: add entry ID for learner tables
  pipeline: add table entry ID read instruction
  pipeline: support direct registers on the control path
  pipeline: support direct meters on the control path
  examples/pipeline: add CLI commands for direct registers
  examples/pipeline: add CLI commands for direct meters

 examples/pipeline/cli.c                  | 642 ++++++++++++++++++-----
 examples/pipeline/examples/meter.cli     |   2 +-
 lib/pipeline/rte_swx_ctl.h               | 133 +++++
 lib/pipeline/rte_swx_pipeline.c          | 349 ++++++++++++
 lib/pipeline/rte_swx_pipeline_internal.h |  21 +
 lib/pipeline/version.map                 |   5 +
 lib/table/rte_swx_table.h                |  13 +
 lib/table/rte_swx_table_em.c             |   5 +
 lib/table/rte_swx_table_learner.c        |  13 +-
 lib/table/rte_swx_table_learner.h        |  12 +
 lib/table/rte_swx_table_wm.c             |   2 +
 11 files changed, 1053 insertions(+), 144 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 1/7] table: add entry ID for regular tables
  2022-08-26 10:35 [PATCH 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
@ 2022-08-26 10:35 ` Cristian Dumitrescu
  2022-08-26 10:36 ` [PATCH 2/7] table: add entry ID for learner tables Cristian Dumitrescu
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 10:35 UTC (permalink / raw)
  To: dev

Add support for unique ID for each table entry. The entry ID is
retrieved as part of the table lookup operation and is saved by the
pipeline for later use.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_pipeline.c          |  9 +++++++++
 lib/pipeline/rte_swx_pipeline_internal.h |  1 +
 lib/table/rte_swx_table.h                | 13 +++++++++++++
 lib/table/rte_swx_table_em.c             |  5 +++++
 lib/table/rte_swx_table_wm.c             |  2 ++
 5 files changed, 30 insertions(+)

diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index 1c49622be7..e271cc50eb 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -2401,6 +2401,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 	struct table_statistics *stats = &p->table_stats[table_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action;
 	uint8_t *action_data;
+	size_t entry_id;
 	int done, hit;
 
 	/* Table. */
@@ -2409,6 +2410,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 			   table->key,
 			   &action_id,
 			   &action_data,
+			   &entry_id,
 			   &hit);
 	if (!done) {
 		/* Thread. */
@@ -2422,6 +2424,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
 
@@ -2433,6 +2436,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	stats->n_pkts_hit[hit] = n_pkts_hit + 1;
 	stats->n_pkts_action[action_id] = n_pkts_action + 1;
@@ -2452,6 +2456,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 	struct table_statistics *stats = &p->table_stats[table_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action;
 	uint8_t *action_data;
+	size_t entry_id;
 	action_func_t action_func;
 	int done, hit;
 
@@ -2461,6 +2466,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 			   table->key,
 			   &action_id,
 			   &action_data,
+			   &entry_id,
 			   &hit);
 	if (!done) {
 		/* Thread. */
@@ -2474,6 +2480,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	action_func = p->action_funcs[action_id];
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
@@ -2486,6 +2493,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	stats->n_pkts_hit[hit] = n_pkts_hit + 1;
 	stats->n_pkts_action[action_id] = n_pkts_action + 1;
@@ -8283,6 +8291,7 @@ table_stub_lkp(void *table __rte_unused,
 	       uint8_t **key __rte_unused,
 	       uint64_t *action_id __rte_unused,
 	       uint8_t **action_data __rte_unused,
+	       size_t *entry_id __rte_unused,
 	       int *hit)
 {
 	*hit = 0;
diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h
index ef60288dca..8f96b67d76 100644
--- a/lib/pipeline/rte_swx_pipeline_internal.h
+++ b/lib/pipeline/rte_swx_pipeline_internal.h
@@ -1009,6 +1009,7 @@ struct thread {
 	struct learner_runtime *learners;
 	struct rte_swx_table_state *table_state;
 	uint64_t action_id;
+	size_t entry_id;
 	int hit; /* 0 = Miss, 1 = Hit. */
 	uint32_t learner_id;
 	uint64_t time;
diff --git a/lib/table/rte_swx_table.h b/lib/table/rte_swx_table.h
index 4b8dc06798..ac01e19781 100644
--- a/lib/table/rte_swx_table.h
+++ b/lib/table/rte_swx_table.h
@@ -233,6 +233,15 @@ typedef int
  * data likely to be read from the CPU cache with no CPU pipeline stall, which
  * significantly improves the table lookup performance.
  *
+ * The table entry consists of the action ID and the action data. Each table
+ * entry is unique, although different table entries can have identical content,
+ * i.e. same values for the action ID and the action data. The table entry ID is
+ * also returned by the table lookup operation. It can be used to index into an
+ * external array of resources such as counters, registers or meters to identify
+ * the resource directly associated with the current table entry with no need to
+ * store the corresponding index into the table entry. The index of the external
+ * resource is thus auto-generated instead of being stored in the table entry.
+ *
  * @param[in] table
  *   Table handle.
  * @param[in] mailbox
@@ -247,6 +256,9 @@ typedef int
  *   Action data for the *action_id* action. Must point to a valid array of
  *   table *action_data_size* bytes. Only valid when the function returns 1 and
  *   *hit* is set to true.
+ * @param[out] entry_id
+ *   Table entry unique ID. Must point to a valid 32-bit variable. Only valid
+ *   when the function returns 1 and *hit* is set to true.
  * @param[out] hit
  *   Only valid when the function returns 1. Set to non-zero (true) on table
  *   lookup hit and to zero (false) on table lookup miss.
@@ -260,6 +272,7 @@ typedef int
 			  uint8_t **key,
 			  uint64_t *action_id,
 			  uint8_t **action_data,
+			  size_t *entry_id,
 			  int *hit);
 
 /**
diff --git a/lib/table/rte_swx_table_em.c b/lib/table/rte_swx_table_em.c
index 568e76e249..2b5201e006 100644
--- a/lib/table/rte_swx_table_em.c
+++ b/lib/table/rte_swx_table_em.c
@@ -403,6 +403,7 @@ table_lookup_unoptimized(void *table,
 			 uint8_t **key,
 			 uint64_t *action_id,
 			 uint8_t **action_data,
+			 size_t *entry_id,
 			 int *hit)
 {
 	struct table *t = table;
@@ -431,6 +432,7 @@ table_lookup_unoptimized(void *table,
 				bkt_data = table_key_data(t, bkt_key_id);
 				*action_id = bkt_data[0];
 				*action_data = (uint8_t *)&bkt_data[1];
+				*entry_id = bkt_key_id;
 				*hit = 1;
 				return 1;
 			}
@@ -500,6 +502,7 @@ table_lookup(void *table,
 	     uint8_t **key,
 	     uint64_t *action_id,
 	     uint8_t **action_data,
+	     size_t *entry_id,
 	     int *hit)
 {
 	struct table *t = table;
@@ -576,6 +579,7 @@ table_lookup(void *table,
 		lkp_hit &= m->sig_match;
 		*action_id = bkt_data[0];
 		*action_data = (uint8_t *)&bkt_data[1];
+		*entry_id = bkt_key_id;
 		*hit = lkp_hit;
 
 		m->state = 0;
@@ -586,6 +590,7 @@ table_lookup(void *table,
 							key,
 							action_id,
 							action_data,
+							entry_id,
 							hit);
 
 		return 1;
diff --git a/lib/table/rte_swx_table_wm.c b/lib/table/rte_swx_table_wm.c
index ce2a78f94c..58afb35d46 100644
--- a/lib/table/rte_swx_table_wm.c
+++ b/lib/table/rte_swx_table_wm.c
@@ -436,6 +436,7 @@ table_lookup(void *table,
 	     const uint8_t **key,
 	     uint64_t *action_id,
 	     uint8_t **action_data,
+	     size_t *entry_id,
 	     int *hit)
 {
 	struct table *t = table;
@@ -451,6 +452,7 @@ table_lookup(void *table,
 	data = &t->data[(user_data - 1) * t->entry_data_size];
 	*action_id = ((uint64_t *)data)[0];
 	*action_data = &data[8];
+	*entry_id = user_data - 1;
 	*hit = 1;
 	return 1;
 }
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 2/7] table: add entry ID for learner tables
  2022-08-26 10:35 [PATCH 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
  2022-08-26 10:35 ` [PATCH 1/7] table: add entry ID for regular tables Cristian Dumitrescu
@ 2022-08-26 10:36 ` Cristian Dumitrescu
  2022-08-26 10:36 ` [PATCH 3/7] pipeline: add table entry ID read instruction Cristian Dumitrescu
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 10:36 UTC (permalink / raw)
  To: dev

Add support for unique ID for each learner table entry. The entry ID
is retrieved as part of the learner table lookup operation and is
saved by the pipeline for later use.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_pipeline.c   |  8 ++++++++
 lib/table/rte_swx_table_learner.c | 13 ++++++++++++-
 lib/table/rte_swx_table_learner.h | 12 ++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index e271cc50eb..80108b8916 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -2556,6 +2556,7 @@ instr_learner_exec(struct rte_swx_pipeline *p)
 	struct learner_statistics *stats = &p->learner_stats[learner_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action, time;
 	uint8_t *action_data;
+	size_t entry_id;
 	int done, hit;
 
 	/* Table. */
@@ -2567,6 +2568,7 @@ instr_learner_exec(struct rte_swx_pipeline *p)
 					    l->key,
 					    &action_id,
 					    &action_data,
+					    &entry_id,
 					    &hit);
 	if (!done) {
 		/* Thread. */
@@ -2580,6 +2582,7 @@ instr_learner_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
 
@@ -2591,6 +2594,7 @@ instr_learner_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	t->learner_id = learner_id;
 	t->time = time;
@@ -2613,6 +2617,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p)
 	struct learner_statistics *stats = &p->learner_stats[learner_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action, time;
 	uint8_t *action_data;
+	size_t entry_id;
 	action_func_t action_func;
 	int done, hit;
 
@@ -2625,6 +2630,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p)
 					    l->key,
 					    &action_id,
 					    &action_data,
+					    &entry_id,
 					    &hit);
 	if (!done) {
 		/* Thread. */
@@ -2638,6 +2644,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	action_func = p->action_funcs[action_id];
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
@@ -2650,6 +2657,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	t->learner_id = learner_id;
 	t->time = time;
diff --git a/lib/table/rte_swx_table_learner.c b/lib/table/rte_swx_table_learner.c
index c1045a1082..996fd3de5b 100644
--- a/lib/table/rte_swx_table_learner.c
+++ b/lib/table/rte_swx_table_learner.c
@@ -72,6 +72,7 @@ table_keycpy(void *dst, void *src, uint32_t n_bytes)
 }
 
 #define TABLE_KEYS_PER_BUCKET 4
+#define TABLE_KEYS_PER_BUCKET_LOG2 2
 
 #define TABLE_BUCKET_USEFUL_SIZE \
 	(TABLE_KEYS_PER_BUCKET * (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint8_t)))
@@ -263,6 +264,14 @@ table_bucket_data_get(struct table *t, struct table_bucket *b, size_t bucket_key
 				   (bucket_key_pos << t->params.data_size_log2)];
 }
 
+static inline size_t
+table_entry_id_get(struct table *t, struct table_bucket *b, size_t bucket_key_pos)
+{
+	size_t bucket_id = ((uint8_t *)b - t->buckets) >> t->params.bucket_size_log2;
+
+	return (bucket_id << TABLE_KEYS_PER_BUCKET_LOG2) + bucket_key_pos;
+}
+
 uint64_t
 rte_swx_table_learner_footprint_get(struct rte_swx_table_learner_params *params)
 {
@@ -332,7 +341,7 @@ struct mailbox {
 	/* Writer: lookup state 0. Reader(s): lookup state 1, add(). */
 	uint32_t input_sig;
 
-	/* Writer: lookup state 1. Reader(s): add(). */
+	/* Writer: lookup state 0. Reader(s): lookup state 1, add(). */
 	uint8_t *input_key;
 
 	/* Writer: lookup state 1. Reader(s): add(). Values: 0 = miss; 1 = hit. */
@@ -358,6 +367,7 @@ rte_swx_table_learner_lookup(void *table,
 			     uint8_t **key,
 			     uint64_t *action_id,
 			     uint8_t **action_data,
+			     size_t *entry_id,
 			     int *hit)
 {
 	struct table *t = table;
@@ -412,6 +422,7 @@ rte_swx_table_learner_lookup(void *table,
 
 				*action_id = data[0];
 				*action_data = (uint8_t *)&data[1];
+				*entry_id = table_entry_id_get(t, b, i);
 				*hit = 1;
 				return 1;
 			}
diff --git a/lib/table/rte_swx_table_learner.h b/lib/table/rte_swx_table_learner.h
index d72b6b88ff..62cac3f225 100644
--- a/lib/table/rte_swx_table_learner.h
+++ b/lib/table/rte_swx_table_learner.h
@@ -173,6 +173,14 @@ rte_swx_table_learner_timeout_update(void *table,
  * possibly an associated key add operation. The mailbox mechanism allows for multiple concurrent
  * table key lookup and add operations into the same table.
  *
+ * The table entry consists of the action ID and the action data. Each table entry is unique, even
+ * though different table entries can have identical content, i.e. same values for the action ID and
+ * the action data. The table entry ID is also returned by the table lookup operation. It can be
+ * used to index into an external array of resources such as counters, registers or meters to
+ * identify the resource directly associated with the current table entry with no need to store the
+ * corresponding index into the table entry. The index of the external resource is thus
+ * auto-generated instead of being stored in the table entry.
+ *
  * @param[in] table
  *   Table handle.
  * @param[in] mailbox
@@ -187,6 +195,9 @@ rte_swx_table_learner_timeout_update(void *table,
  * @param[out] action_data
  *   Action data for the *action_id* action. Must point to a valid array of table *action_data_size*
  *   bytes. Only valid when the function returns 1 and *hit* is set to true.
+ * @param[out] entry_id
+ *   Table entry unique ID. Must point to a valid 32-bit variable. Only valid when the function
+ *   returns 1 and *hit* is set to true.
  * @param[out] hit
  *   Only valid when the function returns 1. Set to non-zero (true) on table lookup hit and to zero
  *   (false) on table lookup miss.
@@ -202,6 +213,7 @@ rte_swx_table_learner_lookup(void *table,
 			     uint8_t **key,
 			     uint64_t *action_id,
 			     uint8_t **action_data,
+			     size_t *entry_id,
 			     int *hit);
 
 /**
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 3/7] pipeline: add table entry ID read instruction
  2022-08-26 10:35 [PATCH 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
  2022-08-26 10:35 ` [PATCH 1/7] table: add entry ID for regular tables Cristian Dumitrescu
  2022-08-26 10:36 ` [PATCH 2/7] table: add entry ID for learner tables Cristian Dumitrescu
@ 2022-08-26 10:36 ` Cristian Dumitrescu
  2022-08-26 10:36 ` [PATCH 4/7] pipeline: support direct registers on the control path Cristian Dumitrescu
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 10:36 UTC (permalink / raw)
  To: dev

Add the entry ID instruction that reads the entry ID of the latest
table lookup operation from the pipeline into the meta-data. The entry
ID is then used by the register and meter instructions as the index
into the register or meter array.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_pipeline.c          | 68 ++++++++++++++++++++++++
 lib/pipeline/rte_swx_pipeline_internal.h | 20 +++++++
 2 files changed, 88 insertions(+)

diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index 80108b8916..ec8268b7f8 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -2834,6 +2834,43 @@ instr_forget_exec(struct rte_swx_pipeline *p)
 	thread_ip_inc(p);
 }
 
+/*
+ * entryid.
+ */
+static int
+instr_entryid_translate(struct rte_swx_pipeline *p,
+			struct action *action __rte_unused,
+			char **tokens,
+			int n_tokens,
+			struct instruction *instr,
+			struct instruction_data *data __rte_unused)
+{
+	struct field *f;
+
+	CHECK(n_tokens == 2, EINVAL);
+
+	f = metadata_field_parse(p, tokens[1]);
+	CHECK(f, EINVAL);
+	CHECK(f->n_bits <= 64, EINVAL);
+
+	instr->type = INSTR_ENTRYID;
+	instr->mov.dst.n_bits = f->n_bits;
+	instr->mov.dst.offset = f->offset / 8;
+	return 0;
+}
+
+static inline void
+instr_entryid_exec(struct rte_swx_pipeline *p)
+{
+	struct thread *t = &p->threads[p->thread_id];
+	struct instruction *ip = t->ip;
+
+	__instr_entryid_exec(p, t, ip);
+
+	/* Thread. */
+	thread_ip_inc(p);
+}
+
 /*
  * extern.
  */
@@ -6336,6 +6373,14 @@ instr_translate(struct rte_swx_pipeline *p,
 					      instr,
 					      data);
 
+	if (!strcmp(tokens[tpos], "entryid"))
+		return instr_entryid_translate(p,
+					       action,
+					       &tokens[tpos],
+					       n_tokens - tpos,
+					       instr,
+					       data);
+
 	if (!strcmp(tokens[tpos], "extern"))
 		return instr_extern_translate(p,
 					      action,
@@ -7321,6 +7366,8 @@ static instr_exec_t instruction_table[] = {
 	[INSTR_LEARNER_REARM] = instr_rearm_exec,
 	[INSTR_LEARNER_REARM_NEW] = instr_rearm_new_exec,
 	[INSTR_LEARNER_FORGET] = instr_forget_exec,
+	[INSTR_ENTRYID] = instr_entryid_exec,
+
 	[INSTR_EXTERN_OBJ] = instr_extern_obj_exec,
 	[INSTR_EXTERN_FUNC] = instr_extern_func_exec,
 	[INSTR_HASH_FUNC] = instr_hash_func_exec,
@@ -11222,6 +11269,7 @@ instr_type_to_name(struct instruction *instr)
 	case INSTR_LEARNER_REARM: return "INSTR_LEARNER_REARM";
 	case INSTR_LEARNER_REARM_NEW: return "INSTR_LEARNER_REARM_NEW";
 	case INSTR_LEARNER_FORGET: return "INSTR_LEARNER_FORGET";
+	case INSTR_ENTRYID: return "INSTR_ENTRYID";
 
 	case INSTR_EXTERN_OBJ: return "INSTR_EXTERN_OBJ";
 	case INSTR_EXTERN_FUNC: return "INSTR_EXTERN_FUNC";
@@ -11922,6 +11970,24 @@ instr_forget_export(struct instruction *instr, FILE *f)
 		instr_type_to_name(instr));
 }
 
+static void
+instr_entryid_export(struct instruction *instr, FILE *f)
+{
+	fprintf(f,
+		"\t{\n"
+		"\t\t.type = %s,\n"
+		"\t\t.mov = {\n"
+		"\t\t\t.dst = {\n"
+		"\t\t\t\t.n_bits = %u,\n"
+		"\t\t\t\t.offset = %u,\n"
+		"\t\t\t},\n"
+		"\t\t},\n"
+		"\t},\n",
+		instr_type_to_name(instr),
+		instr->mov.dst.n_bits,
+		instr->mov.dst.offset);
+}
+
 static void
 instr_extern_export(struct instruction *instr, FILE *f)
 {
@@ -12212,6 +12278,7 @@ static instruction_export_t export_table[] = {
 	[INSTR_LEARNER_REARM] = instr_rearm_export,
 	[INSTR_LEARNER_REARM_NEW] = instr_rearm_export,
 	[INSTR_LEARNER_FORGET] = instr_forget_export,
+	[INSTR_ENTRYID] = instr_entryid_export,
 
 	[INSTR_EXTERN_OBJ] = instr_extern_export,
 	[INSTR_EXTERN_FUNC] = instr_extern_export,
@@ -12438,6 +12505,7 @@ instr_type_to_func(struct instruction *instr)
 	case INSTR_LEARNER_REARM: return "__instr_rearm_exec";
 	case INSTR_LEARNER_REARM_NEW: return "__instr_rearm_new_exec";
 	case INSTR_LEARNER_FORGET: return "__instr_forget_exec";
+	case INSTR_ENTRYID: return "__instr_entryid_exec";
 
 	case INSTR_EXTERN_OBJ: return NULL;
 	case INSTR_EXTERN_FUNC: return NULL;
diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h
index 8f96b67d76..335506039b 100644
--- a/lib/pipeline/rte_swx_pipeline_internal.h
+++ b/lib/pipeline/rte_swx_pipeline_internal.h
@@ -504,6 +504,11 @@ enum instruction_type {
 	/* forget */
 	INSTR_LEARNER_FORGET,
 
+	/* entryid m.table_entry_id
+	 * Read the internal table entry ID into the specified meta-data field.
+	 */
+	INSTR_ENTRYID,
+
 	/* extern e.obj.func */
 	INSTR_EXTERN_OBJ,
 
@@ -2377,6 +2382,21 @@ __instr_forget_exec(struct rte_swx_pipeline *p,
 	stats->n_pkts_forget += 1;
 }
 
+/*
+ * entryid.
+ */
+static inline void
+__instr_entryid_exec(struct rte_swx_pipeline *p __rte_unused,
+		       struct thread *t,
+		       const struct instruction *ip)
+{
+	TRACE("[Thread %2u]: entryid\n",
+	      p->thread_id);
+
+	/* Meta-data. */
+	METADATA_WRITE(t, ip->mov.dst.offset, ip->mov.dst.n_bits, t->entry_id);
+}
+
 /*
  * extern.
  */
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 4/7] pipeline: support direct registers on the control path
  2022-08-26 10:35 [PATCH 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                   ` (2 preceding siblings ...)
  2022-08-26 10:36 ` [PATCH 3/7] pipeline: add table entry ID read instruction Cristian Dumitrescu
@ 2022-08-26 10:36 ` Cristian Dumitrescu
  2022-08-26 10:36 ` [PATCH 5/7] pipeline: support direct meters " Cristian Dumitrescu
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 10:36 UTC (permalink / raw)
  To: dev

Add pipeline control path API to read/write direct registers. These
registers are identified by a table key, whose entry ID is used as the
index into the register array.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_ctl.h      |  52 ++++++++
 lib/pipeline/rte_swx_pipeline.c | 214 ++++++++++++++++++++++++++++++++
 lib/pipeline/version.map        |   2 +
 3 files changed, 268 insertions(+)

diff --git a/lib/pipeline/rte_swx_ctl.h b/lib/pipeline/rte_swx_ctl.h
index 0694df557a..1b47820441 100644
--- a/lib/pipeline/rte_swx_ctl.h
+++ b/lib/pipeline/rte_swx_ctl.h
@@ -1237,6 +1237,58 @@ rte_swx_ctl_pipeline_regarray_write(struct rte_swx_pipeline *p,
 				   uint32_t regarray_index,
 				   uint64_t value);
 
+/**
+ * Register read with table key lookup
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] regarray_name
+ *   Register array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @param[out] value
+ *   Current register value.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough memory.
+ */
+__rte_experimental
+int
+rte_swx_ctl_pipeline_regarray_read_with_key(struct rte_swx_pipeline *p,
+					    const char *regarray_name,
+					    const char *table_name,
+					    uint8_t *table_key,
+					    uint64_t *value);
+
+/**
+ * Register write with table key lookup
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] regarray_name
+ *   Register array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @param[in] value
+ *   Value to be written to the register.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough memory.
+ */
+__rte_experimental
+int
+rte_swx_ctl_pipeline_regarray_write_with_key(struct rte_swx_pipeline *p,
+					     const char *regarray_name,
+					     const char *table_name,
+					     uint8_t *table_key,
+					     uint64_t value);
+
 /*
  * Meter Array Query and Configuration API.
  */
diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index ec8268b7f8..e726bf1575 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -11101,6 +11101,220 @@ rte_swx_ctl_pipeline_mirroring_session_set(struct rte_swx_pipeline *p,
 	return 0;
 }
 
+static int
+rte_swx_ctl_pipeline_table_lookup(struct rte_swx_pipeline *p,
+				  const char *table_name,
+				  uint8_t *key,
+				  uint64_t *action_id,
+				  uint8_t **action_data,
+				  size_t *entry_id,
+				  int *hit)
+{
+	struct table *t;
+	void *mailbox = NULL;
+
+	/* Check input arguments. */
+	if (!p ||
+	    !p->build_done ||
+	    !table_name ||
+	    !table_name[0] ||
+	    !key ||
+	    !entry_id ||
+	    !hit)
+		return -EINVAL;
+
+	/* Find the table. */
+	t = table_find(p, table_name);
+	if (!t)
+		return -EINVAL;
+
+	if (!t->type) {
+		*hit = 0;
+		return 0;
+	}
+
+	/* Setup mailbox.  */
+	if (t->type->ops.mailbox_size_get) {
+		uint64_t mailbox_size;
+
+		mailbox_size = t->type->ops.mailbox_size_get();
+		if (mailbox_size) {
+			mailbox = calloc(1, mailbox_size);
+			if (!mailbox)
+				return -ENOMEM;
+		}
+	}
+
+	/* Table lookup operation. */
+	for ( ; ; ) {
+		struct rte_swx_table_state *ts = &p->table_state[t->id];
+		int done;
+
+		done = t->type->ops.lkp(ts->obj,
+					mailbox,
+					&key,
+					action_id,
+					action_data,
+					entry_id,
+					hit);
+		if (done)
+			break;
+	}
+
+	/* Free mailbox. */
+	free(mailbox);
+
+	return 0;
+}
+
+static int
+rte_swx_ctl_pipeline_learner_lookup(struct rte_swx_pipeline *p,
+				    const char *learner_name,
+				    uint8_t *key,
+				    uint64_t *action_id,
+				    uint8_t **action_data,
+				    size_t *entry_id,
+				    int *hit)
+{
+	struct learner *l;
+	void *mailbox = NULL;
+	uint64_t mailbox_size, time;
+
+	/* Check input arguments. */
+	if (!p ||
+	    !p->build_done ||
+	    !learner_name ||
+	    !learner_name[0] ||
+	    !key ||
+	    !entry_id ||
+	    !hit)
+		return -EINVAL;
+
+	/* Find the learner table. */
+	l = learner_find(p, learner_name);
+	if (!l)
+		return -EINVAL;
+
+	/* Setup mailbox.  */
+	mailbox_size = rte_swx_table_learner_mailbox_size_get();
+	if (mailbox_size) {
+		mailbox = calloc(1, mailbox_size);
+		if (!mailbox)
+			return -ENOMEM;
+	}
+
+	/* Learner table lookup operation. */
+	time = rte_get_tsc_cycles();
+	for ( ; ; ) {
+		uint32_t pos = p->n_tables + p->n_selectors + l->id;
+		struct rte_swx_table_state *ts = &p->table_state[pos];
+		int done;
+
+		done = rte_swx_table_learner_lookup(ts->obj,
+						    mailbox,
+						    time,
+						    &key,
+						    action_id,
+						    action_data,
+						    entry_id,
+						    hit);
+		if (done)
+			break;
+	}
+
+	/* Free mailbox. */
+	free(mailbox);
+
+	return 0;
+}
+
+static int
+rte_swx_ctl_pipeline_table_entry_id_get(struct rte_swx_pipeline *p,
+					const char *table_name,
+					uint8_t *table_key,
+					size_t *table_entry_id)
+{
+	struct table *t;
+	struct learner *l;
+	uint64_t action_id;
+	uint8_t *action_data;
+	size_t entry_id = 0;
+	int hit = 0, status;
+
+	/* Check input arguments. */
+	if (!p ||
+	    !p->build_done ||
+	    !table_name ||
+	    !table_name[0] ||
+	    !table_key ||
+	    !table_entry_id)
+		return -EINVAL;
+
+	t = table_find(p, table_name);
+	l = learner_find(p, table_name);
+	if (!t && !l)
+		return -EINVAL;
+
+	/* Table lookup operation. */
+	if (t)
+		status = rte_swx_ctl_pipeline_table_lookup(p,
+							   table_name,
+							   table_key,
+							   &action_id,
+							   &action_data,
+							   &entry_id,
+							   &hit);
+	else
+		status = rte_swx_ctl_pipeline_learner_lookup(p,
+							     table_name,
+							     table_key,
+							     &action_id,
+							     &action_data,
+							     &entry_id,
+							     &hit);
+	if (status)
+		return status;
+
+	/* Reserve entry ID 0 for the table default entry. */
+	*table_entry_id = hit ? (1 + entry_id) : 0;
+
+	return 0;
+}
+
+int
+rte_swx_ctl_pipeline_regarray_read_with_key(struct rte_swx_pipeline *p,
+					    const char *regarray_name,
+					    const char *table_name,
+					    uint8_t *table_key,
+					    uint64_t *value)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_pipeline_regarray_read(p, regarray_name, entry_id, value);
+}
+
+int
+rte_swx_ctl_pipeline_regarray_write_with_key(struct rte_swx_pipeline *p,
+					     const char *regarray_name,
+					     const char *table_name,
+					     uint8_t *table_key,
+					     uint64_t value)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_pipeline_regarray_write(p, regarray_name, entry_id, value);
+}
+
 /*
  * Pipeline compilation.
  */
diff --git a/lib/pipeline/version.map b/lib/pipeline/version.map
index 16806e6802..8ed92042d6 100644
--- a/lib/pipeline/version.map
+++ b/lib/pipeline/version.map
@@ -147,6 +147,8 @@ EXPERIMENTAL {
 
 	#added in 22.11
 	rte_swx_ctl_pipeline_find;
+	rte_swx_ctl_pipeline_regarray_read_with_key;
+	rte_swx_ctl_pipeline_regarray_write_with_key;
 	rte_swx_pipeline_build_from_lib;
 	rte_swx_pipeline_codegen;
 	rte_swx_pipeline_find;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 5/7] pipeline: support direct meters on the control path
  2022-08-26 10:35 [PATCH 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                   ` (3 preceding siblings ...)
  2022-08-26 10:36 ` [PATCH 4/7] pipeline: support direct registers on the control path Cristian Dumitrescu
@ 2022-08-26 10:36 ` Cristian Dumitrescu
  2022-08-26 10:36 ` [PATCH 6/7] examples/pipeline: add CLI commands for direct registers Cristian Dumitrescu
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 10:36 UTC (permalink / raw)
  To: dev

Add pipeline control path API to manage direct meters. These meters
are identified by a table key, whose entry ID is used as the index
into the meter array.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_ctl.h      | 81 +++++++++++++++++++++++++++++++++
 lib/pipeline/rte_swx_pipeline.c | 50 ++++++++++++++++++++
 lib/pipeline/version.map        |  3 ++
 3 files changed, 134 insertions(+)

diff --git a/lib/pipeline/rte_swx_ctl.h b/lib/pipeline/rte_swx_ctl.h
index 1b47820441..2eb51b2c76 100644
--- a/lib/pipeline/rte_swx_ctl.h
+++ b/lib/pipeline/rte_swx_ctl.h
@@ -1440,6 +1440,87 @@ rte_swx_ctl_meter_stats_read(struct rte_swx_pipeline *p,
 			     uint32_t metarray_index,
 			     struct rte_swx_ctl_meter_stats *stats);
 
+/**
+ * Meter reset with table key lookup
+ *
+ * Reset a meter within a given meter array to use the default profile that
+ * causes all the input packets to be colored as green. It is the responsibility
+ * of the control plane to make sure this meter is not used by the data plane
+ * pipeline before calling this function.
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] metarray_name
+ *   Meter array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument.
+ */
+__rte_experimental
+int
+rte_swx_ctl_meter_reset_with_key(struct rte_swx_pipeline *p,
+				 const char *metarray_name,
+				 const char *table_name,
+				 uint8_t *table_key);
+
+/**
+ * Meter set with table key lookup
+ *
+ * Set a meter within a given meter array to use a specific profile. It is the
+ * responsibility of the control plane to make sure this meter is not used by
+ * the data plane pipeline before calling this function.
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] metarray_name
+ *   Meter array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @param[in] profile_name
+ *   Existing meter profile name.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument.
+ */
+__rte_experimental
+int
+rte_swx_ctl_meter_set_with_key(struct rte_swx_pipeline *p,
+			       const char *metarray_name,
+			       const char *table_name,
+			       uint8_t *table_key,
+			       const char *profile_name);
+
+/**
+ * Meter statistics counters read with table key lookup
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] metarray_name
+ *   Meter array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @param[out] stats
+ *   Meter statistics counters.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument.
+ */
+__rte_experimental
+int
+rte_swx_ctl_meter_stats_read_with_key(struct rte_swx_pipeline *p,
+				      const char *metarray_name,
+				      const char *table_name,
+				      uint8_t *table_key,
+				      struct rte_swx_ctl_meter_stats *stats);
+
 /**
  * Pipeline control free
  *
diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index e726bf1575..4b1b311093 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -11315,6 +11315,56 @@ rte_swx_ctl_pipeline_regarray_write_with_key(struct rte_swx_pipeline *p,
 	return rte_swx_ctl_pipeline_regarray_write(p, regarray_name, entry_id, value);
 }
 
+int
+rte_swx_ctl_meter_reset_with_key(struct rte_swx_pipeline *p,
+				 const char *metarray_name,
+				 const char *table_name,
+				 uint8_t *table_key)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_meter_reset(p, metarray_name, entry_id);
+}
+
+int
+rte_swx_ctl_meter_set_with_key(struct rte_swx_pipeline *p,
+			       const char *metarray_name,
+			       const char *table_name,
+			       uint8_t *table_key,
+			       const char *profile_name)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_meter_set(p, metarray_name, entry_id, profile_name);
+}
+
+int
+rte_swx_ctl_meter_stats_read_with_key(struct rte_swx_pipeline *p,
+				      const char *metarray_name,
+				      const char *table_name,
+				      uint8_t *table_key,
+				      struct rte_swx_ctl_meter_stats *stats)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_meter_stats_read(p, metarray_name, entry_id, stats);
+}
+
 /*
  * Pipeline compilation.
  */
diff --git a/lib/pipeline/version.map b/lib/pipeline/version.map
index 8ed92042d6..f53a037edf 100644
--- a/lib/pipeline/version.map
+++ b/lib/pipeline/version.map
@@ -146,6 +146,9 @@ EXPERIMENTAL {
 	rte_swx_pipeline_hash_func_register;
 
 	#added in 22.11
+	rte_swx_ctl_meter_reset_with_key;
+	rte_swx_ctl_meter_set_with_key;
+	rte_swx_ctl_meter_stats_read_with_key;
 	rte_swx_ctl_pipeline_find;
 	rte_swx_ctl_pipeline_regarray_read_with_key;
 	rte_swx_ctl_pipeline_regarray_write_with_key;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 6/7] examples/pipeline: add CLI commands for direct registers
  2022-08-26 10:35 [PATCH 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                   ` (4 preceding siblings ...)
  2022-08-26 10:36 ` [PATCH 5/7] pipeline: support direct meters " Cristian Dumitrescu
@ 2022-08-26 10:36 ` Cristian Dumitrescu
  2022-08-26 10:36 ` [PATCH 7/7] examples/pipeline: add CLI commands for direct meters Cristian Dumitrescu
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 10:36 UTC (permalink / raw)
  To: dev

Add the CLI command support for reading/writing direct registers.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 examples/pipeline/cli.c | 228 +++++++++++++++++++++++++++++++++-------
 1 file changed, 192 insertions(+), 36 deletions(-)

diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c
index 2e69698031..72998f580b 100644
--- a/examples/pipeline/cli.c
+++ b/examples/pipeline/cli.c
@@ -142,6 +142,54 @@ is_comment(char *in)
 	return 0;
 }
 
+static void
+table_entry_free(struct rte_swx_table_entry *entry)
+{
+	if (!entry)
+		return;
+
+	free(entry->key);
+	free(entry->key_mask);
+	free(entry->action_data);
+	free(entry);
+}
+
+static struct rte_swx_table_entry *
+parse_table_entry(struct rte_swx_ctl_pipeline *p,
+		  char *table_name,
+		  char **tokens,
+		  uint32_t n_tokens)
+{
+	struct rte_swx_table_entry *entry;
+	char *line;
+	uint32_t i;
+
+	/* Buffer allocation. */
+	line = malloc(MAX_LINE_SIZE);
+	if (!line)
+		return NULL;
+
+	/* Copy tokens to buffer. Since the tokens were initially part of a buffer of size
+	 * MAX_LINE_LENGTH, it is guaranteed that putting back some of them into a buffer of the
+	 * same size separated by a single space will not result in buffer overrun.
+	 */
+	line[0] = 0;
+	for (i = 0; i < n_tokens; i++) {
+		if (i)
+			strcat(line, " ");
+
+		strcat(line, tokens[i]);
+	}
+
+	/* Read the table entry from the input buffer. */
+	entry = rte_swx_ctl_pipeline_table_entry_read(p, table_name, line, NULL);
+
+	/* Buffer free. */
+	free(line);
+
+	return entry;
+}
+
 static const char cmd_mempool_help[] =
 "mempool <mempool_name>\n"
 "   buffer <buffer_size>\n"
@@ -732,18 +780,6 @@ cmd_pipeline_build(char **tokens,
 		fclose(iospec_file);
 }
 
-static void
-table_entry_free(struct rte_swx_table_entry *entry)
-{
-	if (!entry)
-		return;
-
-	free(entry->key);
-	free(entry->key_mask);
-	free(entry->action_data);
-	free(entry);
-}
-
 static int
 pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p,
 			   const char *table_name,
@@ -1710,7 +1746,9 @@ cmd_pipeline_abort(char **tokens,
 }
 
 static const char cmd_pipeline_regrd_help[] =
-"pipeline <pipeline_name> regrd <register_array_name> <index>\n";
+"pipeline <pipeline_name> regrd <register_array_name>"
+	"index <index>"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_regrd(char **tokens,
@@ -1720,18 +1758,20 @@ cmd_pipeline_regrd(char **tokens,
 	void *obj __rte_unused)
 {
 	struct rte_swx_pipeline *p;
-	const char *name;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name;
 	uint64_t value;
-	uint32_t idx;
 	int status;
 
-	if (n_tokens != 5) {
+	if (n_tokens < 5) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -1743,22 +1783,77 @@ cmd_pipeline_regrd(char **tokens,
 
 	name = tokens[3];
 
-	if (parser_read_uint32(&idx, tokens[4])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+	/* index. */
+	if (!strcmp(tokens[4], "index")) {
+		uint32_t idx;
+
+		if (n_tokens != 6) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		if (parser_read_uint32(&idx, tokens[5])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index");
+			return;
+		}
+
+		status = rte_swx_ctl_pipeline_regarray_read(p, name, idx, &value);
+		if (status) {
+			snprintf(out, out_size, "Command failed.\n");
+			return;
+		}
+
+		snprintf(out, out_size, "0x%" PRIx64 "\n", value);
 		return;
 	}
 
-	status = rte_swx_ctl_pipeline_regarray_read(p, name, idx, &value);
-	if (status) {
-		snprintf(out, out_size, "Command failed.\n");
+	/* table. */
+	if (!strcmp(tokens[4], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
+
+		if (n_tokens < 8) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		table_name = tokens[5];
+
+		if (strcmp(tokens[6], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[6], n_tokens - 6);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
+
+		status = rte_swx_ctl_pipeline_regarray_read_with_key(p,
+								     name,
+								     table_name,
+								     entry->key,
+								     &value);
+		table_entry_free(entry);
+		if (status) {
+			snprintf(out, out_size, "Command failed.\n");
+			return;
+		}
+
+		snprintf(out, out_size, "0x%" PRIx64 "\n", value);
 		return;
 	}
 
-	snprintf(out, out_size, "0x%" PRIx64 "\n", value);
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[4]);
+	return;
 }
 
 static const char cmd_pipeline_regwr_help[] =
-"pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n";
+"pipeline <pipeline_name> regwr <register_array_name> value <value>"
+	"index <index>"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_regwr(char **tokens,
@@ -1768,18 +1863,20 @@ cmd_pipeline_regwr(char **tokens,
 	void *obj __rte_unused)
 {
 	struct rte_swx_pipeline *p;
-	const char *name;
-	uint64_t value;
-	uint32_t idx;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name;
+	uint64_t value = 0;
 	int status;
 
-	if (n_tokens != 6) {
+	if (n_tokens < 7) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -1791,8 +1888,8 @@ cmd_pipeline_regwr(char **tokens,
 
 	name = tokens[3];
 
-	if (parser_read_uint32(&idx, tokens[4])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+	if (strcmp(tokens[4], "value")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "value");
 		return;
 	}
 
@@ -1801,11 +1898,70 @@ cmd_pipeline_regwr(char **tokens,
 		return;
 	}
 
-	status = rte_swx_ctl_pipeline_regarray_write(p, name, idx, value);
-	if (status) {
-		snprintf(out, out_size, "Command failed.\n");
+	/* index. */
+	if (!strcmp(tokens[6], "index")) {
+		uint32_t idx;
+
+		if (n_tokens != 8) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		if (parser_read_uint32(&idx, tokens[7])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index");
+			return;
+		}
+
+		status = rte_swx_ctl_pipeline_regarray_write(p, name, idx, value);
+		if (status) {
+			snprintf(out, out_size, "Command failed.\n");
+			return;
+		}
+
+		snprintf(out, out_size, "0x%" PRIx64 "\n", value);
 		return;
 	}
+
+	/* table. */
+	if (!strcmp(tokens[6], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
+
+		if (n_tokens < 10) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		table_name = tokens[7];
+
+		if (strcmp(tokens[8], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[8], n_tokens - 8);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
+
+		status = rte_swx_ctl_pipeline_regarray_write_with_key(p,
+								      name,
+								      table_name,
+								      entry->key,
+								      value);
+		table_entry_free(entry);
+		if (status) {
+			snprintf(out, out_size, "Command failed.\n");
+			return;
+		}
+
+		return;
+	}
+
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[6]);
+	return;
 }
 
 static const char cmd_pipeline_meter_profile_add_help[] =
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 7/7] examples/pipeline: add CLI commands for direct meters
  2022-08-26 10:35 [PATCH 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                   ` (5 preceding siblings ...)
  2022-08-26 10:36 ` [PATCH 6/7] examples/pipeline: add CLI commands for direct registers Cristian Dumitrescu
@ 2022-08-26 10:36 ` Cristian Dumitrescu
  2022-08-26 11:21 ` [PATCH V2 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
  2022-08-30 18:58 ` [PATCH V3 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
  8 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 10:36 UTC (permalink / raw)
  To: dev

Add the CLI command support for managing direct meters.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 examples/pipeline/cli.c              | 414 ++++++++++++++++++++-------
 examples/pipeline/examples/meter.cli |   2 +-
 2 files changed, 309 insertions(+), 107 deletions(-)

diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c
index 72998f580b..4ddece3571 100644
--- a/examples/pipeline/cli.c
+++ b/examples/pipeline/cli.c
@@ -2105,8 +2105,9 @@ cmd_pipeline_meter_profile_delete(char **tokens,
 }
 
 static const char cmd_pipeline_meter_reset_help[] =
-"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
-	"reset\n";
+"pipeline <pipeline_name> meter <meter_array_name> reset"
+	"index from <index0> to <index1>"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_meter_reset(char **tokens,
@@ -2116,16 +2117,18 @@ cmd_pipeline_meter_reset(char **tokens,
 	void *obj __rte_unused)
 {
 	struct rte_swx_pipeline *p;
-	const char *name;
-	uint32_t idx0 = 0, idx1 = 0;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name;
 
-	if (n_tokens != 9) {
+	if (n_tokens < 6) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -2137,45 +2140,96 @@ cmd_pipeline_meter_reset(char **tokens,
 
 	name = tokens[3];
 
-	if (strcmp(tokens[4], "from")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+	if (strcmp(tokens[4], "reset")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
 		return;
 	}
 
-	if (parser_read_uint32(&idx0, tokens[5])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
-		return;
-	}
+	/* index. */
+	if (!strcmp(tokens[5], "index")) {
+		uint32_t idx0 = 0, idx1 = 0;
 
-	if (strcmp(tokens[6], "to")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
-		return;
-	}
+		if (n_tokens != 10) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
 
-	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
-		return;
-	}
+		if (strcmp(tokens[6], "from")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+			return;
+		}
+
+		if (parser_read_uint32(&idx0, tokens[7])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+			return;
+		}
+
+		if (strcmp(tokens[8], "to")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+			return;
+		}
+
+		if (parser_read_uint32(&idx1, tokens[9]) || (idx1 < idx0)) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+			return;
+		}
+
+		for ( ; idx0 <= idx1; idx0++) {
+			int status;
+
+			status = rte_swx_ctl_meter_reset(p, name, idx0);
+			if (status) {
+				snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+				return;
+			}
+		}
 
-	if (strcmp(tokens[8], "reset")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
 		return;
 	}
 
-	for ( ; idx0 <= idx1; idx0++) {
+	/* table. */
+	if (!strcmp(tokens[5], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
 		int status;
 
-		status = rte_swx_ctl_meter_reset(p, name, idx0);
+		if (n_tokens < 9) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		table_name = tokens[6];
+
+		if (strcmp(tokens[7], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[7], n_tokens - 7);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
+
+		status = rte_swx_ctl_meter_reset_with_key(p, name, table_name, entry->key);
+		table_entry_free(entry);
 		if (status) {
-			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			snprintf(out, out_size, "Command failed.\n");
 			return;
 		}
+
+		return;
 	}
+
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[5]);
+	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";
+"pipeline <pipeline_name> meter <meter_array_name> set profile <profile_name>"
+	"index from <index0> to <index1>"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_meter_set(char **tokens,
@@ -2185,16 +2239,18 @@ cmd_pipeline_meter_set(char **tokens,
 	void *obj __rte_unused)
 {
 	struct rte_swx_pipeline *p;
-	const char *name, *profile_name;
-	uint32_t idx0 = 0, idx1 = 0;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name, *profile_name;
 
-	if (n_tokens != 11) {
+	if (n_tokens < 8) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -2206,52 +2262,107 @@ cmd_pipeline_meter_set(char **tokens,
 
 	name = tokens[3];
 
-	if (strcmp(tokens[4], "from")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+	if (strcmp(tokens[4], "set")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
 		return;
 	}
 
-	if (parser_read_uint32(&idx0, tokens[5])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+	if (strcmp(tokens[5], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
 		return;
 	}
 
-	if (strcmp(tokens[6], "to")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
-		return;
-	}
+	profile_name = tokens[6];
 
-	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
-		return;
-	}
+	/* index. */
+	if (!strcmp(tokens[7], "index")) {
+		uint32_t idx0 = 0, idx1 = 0;
 
-	if (strcmp(tokens[8], "set")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
-		return;
-	}
+		if (n_tokens != 12) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		if (strcmp(tokens[8], "from")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+			return;
+		}
+
+		if (parser_read_uint32(&idx0, tokens[9])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+			return;
+		}
+
+		if (strcmp(tokens[10], "to")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+			return;
+		}
+
+		if (parser_read_uint32(&idx1, tokens[11]) || (idx1 < idx0)) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+			return;
+		}
+
+		for ( ; idx0 <= idx1; idx0++) {
+			int status;
+
+			status = rte_swx_ctl_meter_set(p, name, idx0, profile_name);
+			if (status) {
+				snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+				return;
+			}
+		}
 
-	if (strcmp(tokens[9], "profile")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
 		return;
 	}
 
-	profile_name = tokens[10];
-
-	for ( ; idx0 <= idx1; idx0++) {
+	/* table. */
+	if (!strcmp(tokens[7], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
 		int status;
 
-		status = rte_swx_ctl_meter_set(p, name, idx0, profile_name);
+		if (n_tokens < 11) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		table_name = tokens[8];
+
+		if (strcmp(tokens[9], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[9], n_tokens - 9);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
+
+		status = rte_swx_ctl_meter_set_with_key(p,
+							name,
+							table_name,
+							entry->key,
+							profile_name);
+		table_entry_free(entry);
 		if (status) {
-			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			snprintf(out, out_size, "Command failed.\n");
 			return;
 		}
+
+		return;
 	}
+
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[7]);
+	return;
 }
 
 static const char cmd_pipeline_meter_stats_help[] =
-"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
-	"stats\n";
+"pipeline <pipeline_name> meter <meter_array_name> stats"
+	"index from <index0> to <index1>"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_meter_stats(char **tokens,
@@ -2262,16 +2373,18 @@ cmd_pipeline_meter_stats(char **tokens,
 {
 	struct rte_swx_ctl_meter_stats stats;
 	struct rte_swx_pipeline *p;
-	const char *name;
-	uint32_t idx0 = 0, idx1 = 0;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name;
 
-	if (n_tokens != 9) {
+	if (n_tokens != 6) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -2283,68 +2396,151 @@ cmd_pipeline_meter_stats(char **tokens,
 
 	name = tokens[3];
 
-	if (strcmp(tokens[4], "from")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+	if (strcmp(tokens[4], "stats")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
 		return;
 	}
 
-	if (parser_read_uint32(&idx0, tokens[5])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
-		return;
-	}
+	/* index. */
+	if (!strcmp(tokens[5], "index")) {
+		uint32_t idx0 = 0, idx1 = 0;
 
-	if (strcmp(tokens[6], "to")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
-		return;
-	}
+		if (n_tokens != 10) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
 
-	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
-		return;
-	}
+		if (strcmp(tokens[6], "from")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+			return;
+		}
+
+		if (parser_read_uint32(&idx0, tokens[7])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+			return;
+		}
+
+		if (strcmp(tokens[8], "to")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+			return;
+		}
+
+		if (parser_read_uint32(&idx1, tokens[9]) || (idx1 < idx0)) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+			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, 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);
+		}
 
-	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);
+	/* table. */
+	if (!strcmp(tokens[5], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
+		int status;
 
-	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);
+		if (n_tokens < 9) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
 
-	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
-		 "-------",
-		 "----------------", "----------------", "----------------",
-		 "----------------", "----------------", "----------------");
-	out_size -= strlen(out);
-	out += strlen(out);
+		table_name = tokens[6];
 
-	/* Table rows. */
-	for ( ; idx0 <= idx1; idx0++) {
-		int status;
+		if (strcmp(tokens[7], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[7], n_tokens - 7);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
 
-		status = rte_swx_ctl_meter_stats_read(p, name, idx0, &stats);
+		status = rte_swx_ctl_meter_stats_read_with_key(p,
+							name,
+							table_name,
+							entry->key,
+							&stats);
+		table_entry_free(entry);
 		if (status) {
-			snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0);
-			out_size -= strlen(out);
-			out += strlen(out);
+			snprintf(out, out_size, "Command failed.\n");
 			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 row. */
 		snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64
 			 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n",
-			 idx0,
+			 0,
 			 stats.n_pkts[RTE_COLOR_GREEN],
 			 stats.n_pkts[RTE_COLOR_YELLOW],
 			 stats.n_pkts[RTE_COLOR_RED],
@@ -2353,7 +2549,13 @@ cmd_pipeline_meter_stats(char **tokens,
 			 stats.n_bytes[RTE_COLOR_RED]);
 		out_size -= strlen(out);
 		out += strlen(out);
+
+		return;
 	}
+
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[5]);
+	return;
 }
 
 static const char cmd_pipeline_stats_help[] =
diff --git a/examples/pipeline/examples/meter.cli b/examples/pipeline/examples/meter.cli
index c1b88c882a..21582554b9 100644
--- a/examples/pipeline/examples/meter.cli
+++ b/examples/pipeline/examples/meter.cli
@@ -35,7 +35,7 @@ pipeline PIPELINE0 build lib /tmp/meter.so io ./examples/pipeline/examples/ethde
 ; The table entries can later be updated at run-time through the CLI commands.
 ;
 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
+pipeline PIPELINE0 meter meters set profile platinum index from 0 to 15
 
 ;
 ; Pipelines-to-threads mapping.
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V2 0/7] pipeline: support direct registers and meters
  2022-08-26 10:35 [PATCH 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                   ` (6 preceding siblings ...)
  2022-08-26 10:36 ` [PATCH 7/7] examples/pipeline: add CLI commands for direct meters Cristian Dumitrescu
@ 2022-08-26 11:21 ` Cristian Dumitrescu
  2022-08-26 11:21   ` [PATCH V2 1/7] table: add entry ID for regular tables Cristian Dumitrescu
                     ` (6 more replies)
  2022-08-30 18:58 ` [PATCH V3 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
  8 siblings, 7 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 11:21 UTC (permalink / raw)
  To: dev

This patch introduces support for direct registers and meters. The
difference between indirect (indexed) and direct registers and meters
is explained below [1][2][3].

1. Indirect (indexed) registers and meters.

The index into an array of registers or meters used on the data path
is typically read from the action data identified by a table lookup
operation.

This means that the control plane manages the mapping of the mapping
of array entries to table entries and sets up this index explicitly
into the table entry action data.

These are called indirect or indexed registers and meters, and they
allow multiple table entries to share the same register/meter, as well
as a 1:1 mapping of table entries to register/meter array entries.

2. Direct registers and meters.
In the case of 1:1 mapping of table entries to register/meter array
elements, it is sometimes desired to avoid the explicit allocation of
register/meter array index to each table entry by the control plane.

One way this can be done is by implementing a mechanism to associate
a unique ID to each table entry, including the default table entry as
well; once the entry ID is retrieved as result of the table lookup
operation, it is saved by the pipeline and used later on as the
index into the register/meter array.

These are called direct registers and meters, and have the advantage
that the index is auto-generated, which simplifies the controller
implementation; the disadvantage is that they do not allow multiple
table entries to share the same register or meter.

References:

[1] Indirect and direct counters:
https://p4.org/p4-spec/docs/PSA.html#sec-counters

[2] Indirect and direct registers:
https://p4.org/p4-spec/docs/PSA.html#sec-registers

[3] Indirect and direct meters:
https://p4.org/p4-spec/docs/PSA.html#sec-meters

Depends-on: series-24366 ("pipeline: make the hash function configurable per table")

Change log:

V2:
-Fixed minor style issues flagged by CI/CD

Cristian Dumitrescu (7):
  table: add entry ID for regular tables
  table: add entry ID for learner tables
  pipeline: add table entry ID read instruction
  pipeline: support direct registers on the control path
  pipeline: support direct meters on the control path
  examples/pipeline: add CLI commands for direct registers
  examples/pipeline: add CLI commands for direct meters

 examples/pipeline/cli.c                  | 642 ++++++++++++++++++-----
 examples/pipeline/examples/meter.cli     |   2 +-
 lib/pipeline/rte_swx_ctl.h               | 133 +++++
 lib/pipeline/rte_swx_pipeline.c          | 349 ++++++++++++
 lib/pipeline/rte_swx_pipeline_internal.h |  21 +
 lib/pipeline/version.map                 |   5 +
 lib/table/rte_swx_table.h                |  13 +
 lib/table/rte_swx_table_em.c             |   5 +
 lib/table/rte_swx_table_learner.c        |  13 +-
 lib/table/rte_swx_table_learner.h        |  12 +
 lib/table/rte_swx_table_wm.c             |   2 +
 11 files changed, 1053 insertions(+), 144 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V2 1/7] table: add entry ID for regular tables
  2022-08-26 11:21 ` [PATCH V2 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
@ 2022-08-26 11:21   ` Cristian Dumitrescu
  2022-08-26 11:21   ` [PATCH V2 2/7] table: add entry ID for learner tables Cristian Dumitrescu
                     ` (5 subsequent siblings)
  6 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 11:21 UTC (permalink / raw)
  To: dev

Add support for unique ID for each table entry. The entry ID is
retrieved as part of the table lookup operation and is saved by the
pipeline for later use.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_pipeline.c          |  9 +++++++++
 lib/pipeline/rte_swx_pipeline_internal.h |  1 +
 lib/table/rte_swx_table.h                | 13 +++++++++++++
 lib/table/rte_swx_table_em.c             |  5 +++++
 lib/table/rte_swx_table_wm.c             |  2 ++
 5 files changed, 30 insertions(+)

diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index 1c49622be7..e271cc50eb 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -2401,6 +2401,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 	struct table_statistics *stats = &p->table_stats[table_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action;
 	uint8_t *action_data;
+	size_t entry_id;
 	int done, hit;
 
 	/* Table. */
@@ -2409,6 +2410,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 			   table->key,
 			   &action_id,
 			   &action_data,
+			   &entry_id,
 			   &hit);
 	if (!done) {
 		/* Thread. */
@@ -2422,6 +2424,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
 
@@ -2433,6 +2436,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	stats->n_pkts_hit[hit] = n_pkts_hit + 1;
 	stats->n_pkts_action[action_id] = n_pkts_action + 1;
@@ -2452,6 +2456,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 	struct table_statistics *stats = &p->table_stats[table_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action;
 	uint8_t *action_data;
+	size_t entry_id;
 	action_func_t action_func;
 	int done, hit;
 
@@ -2461,6 +2466,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 			   table->key,
 			   &action_id,
 			   &action_data,
+			   &entry_id,
 			   &hit);
 	if (!done) {
 		/* Thread. */
@@ -2474,6 +2480,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	action_func = p->action_funcs[action_id];
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
@@ -2486,6 +2493,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	stats->n_pkts_hit[hit] = n_pkts_hit + 1;
 	stats->n_pkts_action[action_id] = n_pkts_action + 1;
@@ -8283,6 +8291,7 @@ table_stub_lkp(void *table __rte_unused,
 	       uint8_t **key __rte_unused,
 	       uint64_t *action_id __rte_unused,
 	       uint8_t **action_data __rte_unused,
+	       size_t *entry_id __rte_unused,
 	       int *hit)
 {
 	*hit = 0;
diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h
index ef60288dca..8f96b67d76 100644
--- a/lib/pipeline/rte_swx_pipeline_internal.h
+++ b/lib/pipeline/rte_swx_pipeline_internal.h
@@ -1009,6 +1009,7 @@ struct thread {
 	struct learner_runtime *learners;
 	struct rte_swx_table_state *table_state;
 	uint64_t action_id;
+	size_t entry_id;
 	int hit; /* 0 = Miss, 1 = Hit. */
 	uint32_t learner_id;
 	uint64_t time;
diff --git a/lib/table/rte_swx_table.h b/lib/table/rte_swx_table.h
index 4b8dc06798..ac01e19781 100644
--- a/lib/table/rte_swx_table.h
+++ b/lib/table/rte_swx_table.h
@@ -233,6 +233,15 @@ typedef int
  * data likely to be read from the CPU cache with no CPU pipeline stall, which
  * significantly improves the table lookup performance.
  *
+ * The table entry consists of the action ID and the action data. Each table
+ * entry is unique, although different table entries can have identical content,
+ * i.e. same values for the action ID and the action data. The table entry ID is
+ * also returned by the table lookup operation. It can be used to index into an
+ * external array of resources such as counters, registers or meters to identify
+ * the resource directly associated with the current table entry with no need to
+ * store the corresponding index into the table entry. The index of the external
+ * resource is thus auto-generated instead of being stored in the table entry.
+ *
  * @param[in] table
  *   Table handle.
  * @param[in] mailbox
@@ -247,6 +256,9 @@ typedef int
  *   Action data for the *action_id* action. Must point to a valid array of
  *   table *action_data_size* bytes. Only valid when the function returns 1 and
  *   *hit* is set to true.
+ * @param[out] entry_id
+ *   Table entry unique ID. Must point to a valid 32-bit variable. Only valid
+ *   when the function returns 1 and *hit* is set to true.
  * @param[out] hit
  *   Only valid when the function returns 1. Set to non-zero (true) on table
  *   lookup hit and to zero (false) on table lookup miss.
@@ -260,6 +272,7 @@ typedef int
 			  uint8_t **key,
 			  uint64_t *action_id,
 			  uint8_t **action_data,
+			  size_t *entry_id,
 			  int *hit);
 
 /**
diff --git a/lib/table/rte_swx_table_em.c b/lib/table/rte_swx_table_em.c
index 568e76e249..2b5201e006 100644
--- a/lib/table/rte_swx_table_em.c
+++ b/lib/table/rte_swx_table_em.c
@@ -403,6 +403,7 @@ table_lookup_unoptimized(void *table,
 			 uint8_t **key,
 			 uint64_t *action_id,
 			 uint8_t **action_data,
+			 size_t *entry_id,
 			 int *hit)
 {
 	struct table *t = table;
@@ -431,6 +432,7 @@ table_lookup_unoptimized(void *table,
 				bkt_data = table_key_data(t, bkt_key_id);
 				*action_id = bkt_data[0];
 				*action_data = (uint8_t *)&bkt_data[1];
+				*entry_id = bkt_key_id;
 				*hit = 1;
 				return 1;
 			}
@@ -500,6 +502,7 @@ table_lookup(void *table,
 	     uint8_t **key,
 	     uint64_t *action_id,
 	     uint8_t **action_data,
+	     size_t *entry_id,
 	     int *hit)
 {
 	struct table *t = table;
@@ -576,6 +579,7 @@ table_lookup(void *table,
 		lkp_hit &= m->sig_match;
 		*action_id = bkt_data[0];
 		*action_data = (uint8_t *)&bkt_data[1];
+		*entry_id = bkt_key_id;
 		*hit = lkp_hit;
 
 		m->state = 0;
@@ -586,6 +590,7 @@ table_lookup(void *table,
 							key,
 							action_id,
 							action_data,
+							entry_id,
 							hit);
 
 		return 1;
diff --git a/lib/table/rte_swx_table_wm.c b/lib/table/rte_swx_table_wm.c
index ce2a78f94c..58afb35d46 100644
--- a/lib/table/rte_swx_table_wm.c
+++ b/lib/table/rte_swx_table_wm.c
@@ -436,6 +436,7 @@ table_lookup(void *table,
 	     const uint8_t **key,
 	     uint64_t *action_id,
 	     uint8_t **action_data,
+	     size_t *entry_id,
 	     int *hit)
 {
 	struct table *t = table;
@@ -451,6 +452,7 @@ table_lookup(void *table,
 	data = &t->data[(user_data - 1) * t->entry_data_size];
 	*action_id = ((uint64_t *)data)[0];
 	*action_data = &data[8];
+	*entry_id = user_data - 1;
 	*hit = 1;
 	return 1;
 }
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V2 2/7] table: add entry ID for learner tables
  2022-08-26 11:21 ` [PATCH V2 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
  2022-08-26 11:21   ` [PATCH V2 1/7] table: add entry ID for regular tables Cristian Dumitrescu
@ 2022-08-26 11:21   ` Cristian Dumitrescu
  2022-08-26 11:21   ` [PATCH V2 3/7] pipeline: add table entry ID read instruction Cristian Dumitrescu
                     ` (4 subsequent siblings)
  6 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 11:21 UTC (permalink / raw)
  To: dev

Add support for unique ID for each learner table entry. The entry ID
is retrieved as part of the learner table lookup operation and is
saved by the pipeline for later use.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_pipeline.c   |  8 ++++++++
 lib/table/rte_swx_table_learner.c | 13 ++++++++++++-
 lib/table/rte_swx_table_learner.h | 12 ++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index e271cc50eb..80108b8916 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -2556,6 +2556,7 @@ instr_learner_exec(struct rte_swx_pipeline *p)
 	struct learner_statistics *stats = &p->learner_stats[learner_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action, time;
 	uint8_t *action_data;
+	size_t entry_id;
 	int done, hit;
 
 	/* Table. */
@@ -2567,6 +2568,7 @@ instr_learner_exec(struct rte_swx_pipeline *p)
 					    l->key,
 					    &action_id,
 					    &action_data,
+					    &entry_id,
 					    &hit);
 	if (!done) {
 		/* Thread. */
@@ -2580,6 +2582,7 @@ instr_learner_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
 
@@ -2591,6 +2594,7 @@ instr_learner_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	t->learner_id = learner_id;
 	t->time = time;
@@ -2613,6 +2617,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p)
 	struct learner_statistics *stats = &p->learner_stats[learner_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action, time;
 	uint8_t *action_data;
+	size_t entry_id;
 	action_func_t action_func;
 	int done, hit;
 
@@ -2625,6 +2630,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p)
 					    l->key,
 					    &action_id,
 					    &action_data,
+					    &entry_id,
 					    &hit);
 	if (!done) {
 		/* Thread. */
@@ -2638,6 +2644,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	action_func = p->action_funcs[action_id];
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
@@ -2650,6 +2657,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	t->learner_id = learner_id;
 	t->time = time;
diff --git a/lib/table/rte_swx_table_learner.c b/lib/table/rte_swx_table_learner.c
index c1045a1082..996fd3de5b 100644
--- a/lib/table/rte_swx_table_learner.c
+++ b/lib/table/rte_swx_table_learner.c
@@ -72,6 +72,7 @@ table_keycpy(void *dst, void *src, uint32_t n_bytes)
 }
 
 #define TABLE_KEYS_PER_BUCKET 4
+#define TABLE_KEYS_PER_BUCKET_LOG2 2
 
 #define TABLE_BUCKET_USEFUL_SIZE \
 	(TABLE_KEYS_PER_BUCKET * (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint8_t)))
@@ -263,6 +264,14 @@ table_bucket_data_get(struct table *t, struct table_bucket *b, size_t bucket_key
 				   (bucket_key_pos << t->params.data_size_log2)];
 }
 
+static inline size_t
+table_entry_id_get(struct table *t, struct table_bucket *b, size_t bucket_key_pos)
+{
+	size_t bucket_id = ((uint8_t *)b - t->buckets) >> t->params.bucket_size_log2;
+
+	return (bucket_id << TABLE_KEYS_PER_BUCKET_LOG2) + bucket_key_pos;
+}
+
 uint64_t
 rte_swx_table_learner_footprint_get(struct rte_swx_table_learner_params *params)
 {
@@ -332,7 +341,7 @@ struct mailbox {
 	/* Writer: lookup state 0. Reader(s): lookup state 1, add(). */
 	uint32_t input_sig;
 
-	/* Writer: lookup state 1. Reader(s): add(). */
+	/* Writer: lookup state 0. Reader(s): lookup state 1, add(). */
 	uint8_t *input_key;
 
 	/* Writer: lookup state 1. Reader(s): add(). Values: 0 = miss; 1 = hit. */
@@ -358,6 +367,7 @@ rte_swx_table_learner_lookup(void *table,
 			     uint8_t **key,
 			     uint64_t *action_id,
 			     uint8_t **action_data,
+			     size_t *entry_id,
 			     int *hit)
 {
 	struct table *t = table;
@@ -412,6 +422,7 @@ rte_swx_table_learner_lookup(void *table,
 
 				*action_id = data[0];
 				*action_data = (uint8_t *)&data[1];
+				*entry_id = table_entry_id_get(t, b, i);
 				*hit = 1;
 				return 1;
 			}
diff --git a/lib/table/rte_swx_table_learner.h b/lib/table/rte_swx_table_learner.h
index d72b6b88ff..62cac3f225 100644
--- a/lib/table/rte_swx_table_learner.h
+++ b/lib/table/rte_swx_table_learner.h
@@ -173,6 +173,14 @@ rte_swx_table_learner_timeout_update(void *table,
  * possibly an associated key add operation. The mailbox mechanism allows for multiple concurrent
  * table key lookup and add operations into the same table.
  *
+ * The table entry consists of the action ID and the action data. Each table entry is unique, even
+ * though different table entries can have identical content, i.e. same values for the action ID and
+ * the action data. The table entry ID is also returned by the table lookup operation. It can be
+ * used to index into an external array of resources such as counters, registers or meters to
+ * identify the resource directly associated with the current table entry with no need to store the
+ * corresponding index into the table entry. The index of the external resource is thus
+ * auto-generated instead of being stored in the table entry.
+ *
  * @param[in] table
  *   Table handle.
  * @param[in] mailbox
@@ -187,6 +195,9 @@ rte_swx_table_learner_timeout_update(void *table,
  * @param[out] action_data
  *   Action data for the *action_id* action. Must point to a valid array of table *action_data_size*
  *   bytes. Only valid when the function returns 1 and *hit* is set to true.
+ * @param[out] entry_id
+ *   Table entry unique ID. Must point to a valid 32-bit variable. Only valid when the function
+ *   returns 1 and *hit* is set to true.
  * @param[out] hit
  *   Only valid when the function returns 1. Set to non-zero (true) on table lookup hit and to zero
  *   (false) on table lookup miss.
@@ -202,6 +213,7 @@ rte_swx_table_learner_lookup(void *table,
 			     uint8_t **key,
 			     uint64_t *action_id,
 			     uint8_t **action_data,
+			     size_t *entry_id,
 			     int *hit);
 
 /**
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V2 3/7] pipeline: add table entry ID read instruction
  2022-08-26 11:21 ` [PATCH V2 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
  2022-08-26 11:21   ` [PATCH V2 1/7] table: add entry ID for regular tables Cristian Dumitrescu
  2022-08-26 11:21   ` [PATCH V2 2/7] table: add entry ID for learner tables Cristian Dumitrescu
@ 2022-08-26 11:21   ` Cristian Dumitrescu
  2022-08-26 11:21   ` [PATCH V2 4/7] pipeline: support direct registers on the control path Cristian Dumitrescu
                     ` (3 subsequent siblings)
  6 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 11:21 UTC (permalink / raw)
  To: dev

Add the entry ID instruction that reads the entry ID of the latest
table lookup operation from the pipeline into the meta-data. The entry
ID is then used by the register and meter instructions as the index
into the register or meter array.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_pipeline.c          | 68 ++++++++++++++++++++++++
 lib/pipeline/rte_swx_pipeline_internal.h | 20 +++++++
 2 files changed, 88 insertions(+)

diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index 80108b8916..ec8268b7f8 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -2834,6 +2834,43 @@ instr_forget_exec(struct rte_swx_pipeline *p)
 	thread_ip_inc(p);
 }
 
+/*
+ * entryid.
+ */
+static int
+instr_entryid_translate(struct rte_swx_pipeline *p,
+			struct action *action __rte_unused,
+			char **tokens,
+			int n_tokens,
+			struct instruction *instr,
+			struct instruction_data *data __rte_unused)
+{
+	struct field *f;
+
+	CHECK(n_tokens == 2, EINVAL);
+
+	f = metadata_field_parse(p, tokens[1]);
+	CHECK(f, EINVAL);
+	CHECK(f->n_bits <= 64, EINVAL);
+
+	instr->type = INSTR_ENTRYID;
+	instr->mov.dst.n_bits = f->n_bits;
+	instr->mov.dst.offset = f->offset / 8;
+	return 0;
+}
+
+static inline void
+instr_entryid_exec(struct rte_swx_pipeline *p)
+{
+	struct thread *t = &p->threads[p->thread_id];
+	struct instruction *ip = t->ip;
+
+	__instr_entryid_exec(p, t, ip);
+
+	/* Thread. */
+	thread_ip_inc(p);
+}
+
 /*
  * extern.
  */
@@ -6336,6 +6373,14 @@ instr_translate(struct rte_swx_pipeline *p,
 					      instr,
 					      data);
 
+	if (!strcmp(tokens[tpos], "entryid"))
+		return instr_entryid_translate(p,
+					       action,
+					       &tokens[tpos],
+					       n_tokens - tpos,
+					       instr,
+					       data);
+
 	if (!strcmp(tokens[tpos], "extern"))
 		return instr_extern_translate(p,
 					      action,
@@ -7321,6 +7366,8 @@ static instr_exec_t instruction_table[] = {
 	[INSTR_LEARNER_REARM] = instr_rearm_exec,
 	[INSTR_LEARNER_REARM_NEW] = instr_rearm_new_exec,
 	[INSTR_LEARNER_FORGET] = instr_forget_exec,
+	[INSTR_ENTRYID] = instr_entryid_exec,
+
 	[INSTR_EXTERN_OBJ] = instr_extern_obj_exec,
 	[INSTR_EXTERN_FUNC] = instr_extern_func_exec,
 	[INSTR_HASH_FUNC] = instr_hash_func_exec,
@@ -11222,6 +11269,7 @@ instr_type_to_name(struct instruction *instr)
 	case INSTR_LEARNER_REARM: return "INSTR_LEARNER_REARM";
 	case INSTR_LEARNER_REARM_NEW: return "INSTR_LEARNER_REARM_NEW";
 	case INSTR_LEARNER_FORGET: return "INSTR_LEARNER_FORGET";
+	case INSTR_ENTRYID: return "INSTR_ENTRYID";
 
 	case INSTR_EXTERN_OBJ: return "INSTR_EXTERN_OBJ";
 	case INSTR_EXTERN_FUNC: return "INSTR_EXTERN_FUNC";
@@ -11922,6 +11970,24 @@ instr_forget_export(struct instruction *instr, FILE *f)
 		instr_type_to_name(instr));
 }
 
+static void
+instr_entryid_export(struct instruction *instr, FILE *f)
+{
+	fprintf(f,
+		"\t{\n"
+		"\t\t.type = %s,\n"
+		"\t\t.mov = {\n"
+		"\t\t\t.dst = {\n"
+		"\t\t\t\t.n_bits = %u,\n"
+		"\t\t\t\t.offset = %u,\n"
+		"\t\t\t},\n"
+		"\t\t},\n"
+		"\t},\n",
+		instr_type_to_name(instr),
+		instr->mov.dst.n_bits,
+		instr->mov.dst.offset);
+}
+
 static void
 instr_extern_export(struct instruction *instr, FILE *f)
 {
@@ -12212,6 +12278,7 @@ static instruction_export_t export_table[] = {
 	[INSTR_LEARNER_REARM] = instr_rearm_export,
 	[INSTR_LEARNER_REARM_NEW] = instr_rearm_export,
 	[INSTR_LEARNER_FORGET] = instr_forget_export,
+	[INSTR_ENTRYID] = instr_entryid_export,
 
 	[INSTR_EXTERN_OBJ] = instr_extern_export,
 	[INSTR_EXTERN_FUNC] = instr_extern_export,
@@ -12438,6 +12505,7 @@ instr_type_to_func(struct instruction *instr)
 	case INSTR_LEARNER_REARM: return "__instr_rearm_exec";
 	case INSTR_LEARNER_REARM_NEW: return "__instr_rearm_new_exec";
 	case INSTR_LEARNER_FORGET: return "__instr_forget_exec";
+	case INSTR_ENTRYID: return "__instr_entryid_exec";
 
 	case INSTR_EXTERN_OBJ: return NULL;
 	case INSTR_EXTERN_FUNC: return NULL;
diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h
index 8f96b67d76..335506039b 100644
--- a/lib/pipeline/rte_swx_pipeline_internal.h
+++ b/lib/pipeline/rte_swx_pipeline_internal.h
@@ -504,6 +504,11 @@ enum instruction_type {
 	/* forget */
 	INSTR_LEARNER_FORGET,
 
+	/* entryid m.table_entry_id
+	 * Read the internal table entry ID into the specified meta-data field.
+	 */
+	INSTR_ENTRYID,
+
 	/* extern e.obj.func */
 	INSTR_EXTERN_OBJ,
 
@@ -2377,6 +2382,21 @@ __instr_forget_exec(struct rte_swx_pipeline *p,
 	stats->n_pkts_forget += 1;
 }
 
+/*
+ * entryid.
+ */
+static inline void
+__instr_entryid_exec(struct rte_swx_pipeline *p __rte_unused,
+		       struct thread *t,
+		       const struct instruction *ip)
+{
+	TRACE("[Thread %2u]: entryid\n",
+	      p->thread_id);
+
+	/* Meta-data. */
+	METADATA_WRITE(t, ip->mov.dst.offset, ip->mov.dst.n_bits, t->entry_id);
+}
+
 /*
  * extern.
  */
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V2 4/7] pipeline: support direct registers on the control path
  2022-08-26 11:21 ` [PATCH V2 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                     ` (2 preceding siblings ...)
  2022-08-26 11:21   ` [PATCH V2 3/7] pipeline: add table entry ID read instruction Cristian Dumitrescu
@ 2022-08-26 11:21   ` Cristian Dumitrescu
  2022-08-26 11:21   ` [PATCH V2 5/7] pipeline: support direct meters " Cristian Dumitrescu
                     ` (2 subsequent siblings)
  6 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 11:21 UTC (permalink / raw)
  To: dev

Add pipeline control path API to read/write direct registers. These
registers are identified by a table key, whose entry ID is used as the
index into the register array.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_ctl.h      |  52 ++++++++
 lib/pipeline/rte_swx_pipeline.c | 214 ++++++++++++++++++++++++++++++++
 lib/pipeline/version.map        |   2 +
 3 files changed, 268 insertions(+)

diff --git a/lib/pipeline/rte_swx_ctl.h b/lib/pipeline/rte_swx_ctl.h
index 0694df557a..1b47820441 100644
--- a/lib/pipeline/rte_swx_ctl.h
+++ b/lib/pipeline/rte_swx_ctl.h
@@ -1237,6 +1237,58 @@ rte_swx_ctl_pipeline_regarray_write(struct rte_swx_pipeline *p,
 				   uint32_t regarray_index,
 				   uint64_t value);
 
+/**
+ * Register read with table key lookup
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] regarray_name
+ *   Register array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @param[out] value
+ *   Current register value.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough memory.
+ */
+__rte_experimental
+int
+rte_swx_ctl_pipeline_regarray_read_with_key(struct rte_swx_pipeline *p,
+					    const char *regarray_name,
+					    const char *table_name,
+					    uint8_t *table_key,
+					    uint64_t *value);
+
+/**
+ * Register write with table key lookup
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] regarray_name
+ *   Register array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @param[in] value
+ *   Value to be written to the register.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough memory.
+ */
+__rte_experimental
+int
+rte_swx_ctl_pipeline_regarray_write_with_key(struct rte_swx_pipeline *p,
+					     const char *regarray_name,
+					     const char *table_name,
+					     uint8_t *table_key,
+					     uint64_t value);
+
 /*
  * Meter Array Query and Configuration API.
  */
diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index ec8268b7f8..e726bf1575 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -11101,6 +11101,220 @@ rte_swx_ctl_pipeline_mirroring_session_set(struct rte_swx_pipeline *p,
 	return 0;
 }
 
+static int
+rte_swx_ctl_pipeline_table_lookup(struct rte_swx_pipeline *p,
+				  const char *table_name,
+				  uint8_t *key,
+				  uint64_t *action_id,
+				  uint8_t **action_data,
+				  size_t *entry_id,
+				  int *hit)
+{
+	struct table *t;
+	void *mailbox = NULL;
+
+	/* Check input arguments. */
+	if (!p ||
+	    !p->build_done ||
+	    !table_name ||
+	    !table_name[0] ||
+	    !key ||
+	    !entry_id ||
+	    !hit)
+		return -EINVAL;
+
+	/* Find the table. */
+	t = table_find(p, table_name);
+	if (!t)
+		return -EINVAL;
+
+	if (!t->type) {
+		*hit = 0;
+		return 0;
+	}
+
+	/* Setup mailbox.  */
+	if (t->type->ops.mailbox_size_get) {
+		uint64_t mailbox_size;
+
+		mailbox_size = t->type->ops.mailbox_size_get();
+		if (mailbox_size) {
+			mailbox = calloc(1, mailbox_size);
+			if (!mailbox)
+				return -ENOMEM;
+		}
+	}
+
+	/* Table lookup operation. */
+	for ( ; ; ) {
+		struct rte_swx_table_state *ts = &p->table_state[t->id];
+		int done;
+
+		done = t->type->ops.lkp(ts->obj,
+					mailbox,
+					&key,
+					action_id,
+					action_data,
+					entry_id,
+					hit);
+		if (done)
+			break;
+	}
+
+	/* Free mailbox. */
+	free(mailbox);
+
+	return 0;
+}
+
+static int
+rte_swx_ctl_pipeline_learner_lookup(struct rte_swx_pipeline *p,
+				    const char *learner_name,
+				    uint8_t *key,
+				    uint64_t *action_id,
+				    uint8_t **action_data,
+				    size_t *entry_id,
+				    int *hit)
+{
+	struct learner *l;
+	void *mailbox = NULL;
+	uint64_t mailbox_size, time;
+
+	/* Check input arguments. */
+	if (!p ||
+	    !p->build_done ||
+	    !learner_name ||
+	    !learner_name[0] ||
+	    !key ||
+	    !entry_id ||
+	    !hit)
+		return -EINVAL;
+
+	/* Find the learner table. */
+	l = learner_find(p, learner_name);
+	if (!l)
+		return -EINVAL;
+
+	/* Setup mailbox.  */
+	mailbox_size = rte_swx_table_learner_mailbox_size_get();
+	if (mailbox_size) {
+		mailbox = calloc(1, mailbox_size);
+		if (!mailbox)
+			return -ENOMEM;
+	}
+
+	/* Learner table lookup operation. */
+	time = rte_get_tsc_cycles();
+	for ( ; ; ) {
+		uint32_t pos = p->n_tables + p->n_selectors + l->id;
+		struct rte_swx_table_state *ts = &p->table_state[pos];
+		int done;
+
+		done = rte_swx_table_learner_lookup(ts->obj,
+						    mailbox,
+						    time,
+						    &key,
+						    action_id,
+						    action_data,
+						    entry_id,
+						    hit);
+		if (done)
+			break;
+	}
+
+	/* Free mailbox. */
+	free(mailbox);
+
+	return 0;
+}
+
+static int
+rte_swx_ctl_pipeline_table_entry_id_get(struct rte_swx_pipeline *p,
+					const char *table_name,
+					uint8_t *table_key,
+					size_t *table_entry_id)
+{
+	struct table *t;
+	struct learner *l;
+	uint64_t action_id;
+	uint8_t *action_data;
+	size_t entry_id = 0;
+	int hit = 0, status;
+
+	/* Check input arguments. */
+	if (!p ||
+	    !p->build_done ||
+	    !table_name ||
+	    !table_name[0] ||
+	    !table_key ||
+	    !table_entry_id)
+		return -EINVAL;
+
+	t = table_find(p, table_name);
+	l = learner_find(p, table_name);
+	if (!t && !l)
+		return -EINVAL;
+
+	/* Table lookup operation. */
+	if (t)
+		status = rte_swx_ctl_pipeline_table_lookup(p,
+							   table_name,
+							   table_key,
+							   &action_id,
+							   &action_data,
+							   &entry_id,
+							   &hit);
+	else
+		status = rte_swx_ctl_pipeline_learner_lookup(p,
+							     table_name,
+							     table_key,
+							     &action_id,
+							     &action_data,
+							     &entry_id,
+							     &hit);
+	if (status)
+		return status;
+
+	/* Reserve entry ID 0 for the table default entry. */
+	*table_entry_id = hit ? (1 + entry_id) : 0;
+
+	return 0;
+}
+
+int
+rte_swx_ctl_pipeline_regarray_read_with_key(struct rte_swx_pipeline *p,
+					    const char *regarray_name,
+					    const char *table_name,
+					    uint8_t *table_key,
+					    uint64_t *value)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_pipeline_regarray_read(p, regarray_name, entry_id, value);
+}
+
+int
+rte_swx_ctl_pipeline_regarray_write_with_key(struct rte_swx_pipeline *p,
+					     const char *regarray_name,
+					     const char *table_name,
+					     uint8_t *table_key,
+					     uint64_t value)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_pipeline_regarray_write(p, regarray_name, entry_id, value);
+}
+
 /*
  * Pipeline compilation.
  */
diff --git a/lib/pipeline/version.map b/lib/pipeline/version.map
index 16806e6802..8ed92042d6 100644
--- a/lib/pipeline/version.map
+++ b/lib/pipeline/version.map
@@ -147,6 +147,8 @@ EXPERIMENTAL {
 
 	#added in 22.11
 	rte_swx_ctl_pipeline_find;
+	rte_swx_ctl_pipeline_regarray_read_with_key;
+	rte_swx_ctl_pipeline_regarray_write_with_key;
 	rte_swx_pipeline_build_from_lib;
 	rte_swx_pipeline_codegen;
 	rte_swx_pipeline_find;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V2 5/7] pipeline: support direct meters on the control path
  2022-08-26 11:21 ` [PATCH V2 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                     ` (3 preceding siblings ...)
  2022-08-26 11:21   ` [PATCH V2 4/7] pipeline: support direct registers on the control path Cristian Dumitrescu
@ 2022-08-26 11:21   ` Cristian Dumitrescu
  2022-08-26 11:21   ` [PATCH V2 6/7] examples/pipeline: add CLI commands for direct registers Cristian Dumitrescu
  2022-08-26 11:21   ` [PATCH V2 7/7] examples/pipeline: add CLI commands for direct meters Cristian Dumitrescu
  6 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 11:21 UTC (permalink / raw)
  To: dev

Add pipeline control path API to manage direct meters. These meters
are identified by a table key, whose entry ID is used as the index
into the meter array.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_ctl.h      | 81 +++++++++++++++++++++++++++++++++
 lib/pipeline/rte_swx_pipeline.c | 50 ++++++++++++++++++++
 lib/pipeline/version.map        |  3 ++
 3 files changed, 134 insertions(+)

diff --git a/lib/pipeline/rte_swx_ctl.h b/lib/pipeline/rte_swx_ctl.h
index 1b47820441..2eb51b2c76 100644
--- a/lib/pipeline/rte_swx_ctl.h
+++ b/lib/pipeline/rte_swx_ctl.h
@@ -1440,6 +1440,87 @@ rte_swx_ctl_meter_stats_read(struct rte_swx_pipeline *p,
 			     uint32_t metarray_index,
 			     struct rte_swx_ctl_meter_stats *stats);
 
+/**
+ * Meter reset with table key lookup
+ *
+ * Reset a meter within a given meter array to use the default profile that
+ * causes all the input packets to be colored as green. It is the responsibility
+ * of the control plane to make sure this meter is not used by the data plane
+ * pipeline before calling this function.
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] metarray_name
+ *   Meter array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument.
+ */
+__rte_experimental
+int
+rte_swx_ctl_meter_reset_with_key(struct rte_swx_pipeline *p,
+				 const char *metarray_name,
+				 const char *table_name,
+				 uint8_t *table_key);
+
+/**
+ * Meter set with table key lookup
+ *
+ * Set a meter within a given meter array to use a specific profile. It is the
+ * responsibility of the control plane to make sure this meter is not used by
+ * the data plane pipeline before calling this function.
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] metarray_name
+ *   Meter array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @param[in] profile_name
+ *   Existing meter profile name.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument.
+ */
+__rte_experimental
+int
+rte_swx_ctl_meter_set_with_key(struct rte_swx_pipeline *p,
+			       const char *metarray_name,
+			       const char *table_name,
+			       uint8_t *table_key,
+			       const char *profile_name);
+
+/**
+ * Meter statistics counters read with table key lookup
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] metarray_name
+ *   Meter array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @param[out] stats
+ *   Meter statistics counters.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument.
+ */
+__rte_experimental
+int
+rte_swx_ctl_meter_stats_read_with_key(struct rte_swx_pipeline *p,
+				      const char *metarray_name,
+				      const char *table_name,
+				      uint8_t *table_key,
+				      struct rte_swx_ctl_meter_stats *stats);
+
 /**
  * Pipeline control free
  *
diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index e726bf1575..4b1b311093 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -11315,6 +11315,56 @@ rte_swx_ctl_pipeline_regarray_write_with_key(struct rte_swx_pipeline *p,
 	return rte_swx_ctl_pipeline_regarray_write(p, regarray_name, entry_id, value);
 }
 
+int
+rte_swx_ctl_meter_reset_with_key(struct rte_swx_pipeline *p,
+				 const char *metarray_name,
+				 const char *table_name,
+				 uint8_t *table_key)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_meter_reset(p, metarray_name, entry_id);
+}
+
+int
+rte_swx_ctl_meter_set_with_key(struct rte_swx_pipeline *p,
+			       const char *metarray_name,
+			       const char *table_name,
+			       uint8_t *table_key,
+			       const char *profile_name)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_meter_set(p, metarray_name, entry_id, profile_name);
+}
+
+int
+rte_swx_ctl_meter_stats_read_with_key(struct rte_swx_pipeline *p,
+				      const char *metarray_name,
+				      const char *table_name,
+				      uint8_t *table_key,
+				      struct rte_swx_ctl_meter_stats *stats)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_meter_stats_read(p, metarray_name, entry_id, stats);
+}
+
 /*
  * Pipeline compilation.
  */
diff --git a/lib/pipeline/version.map b/lib/pipeline/version.map
index 8ed92042d6..f53a037edf 100644
--- a/lib/pipeline/version.map
+++ b/lib/pipeline/version.map
@@ -146,6 +146,9 @@ EXPERIMENTAL {
 	rte_swx_pipeline_hash_func_register;
 
 	#added in 22.11
+	rte_swx_ctl_meter_reset_with_key;
+	rte_swx_ctl_meter_set_with_key;
+	rte_swx_ctl_meter_stats_read_with_key;
 	rte_swx_ctl_pipeline_find;
 	rte_swx_ctl_pipeline_regarray_read_with_key;
 	rte_swx_ctl_pipeline_regarray_write_with_key;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V2 6/7] examples/pipeline: add CLI commands for direct registers
  2022-08-26 11:21 ` [PATCH V2 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                     ` (4 preceding siblings ...)
  2022-08-26 11:21   ` [PATCH V2 5/7] pipeline: support direct meters " Cristian Dumitrescu
@ 2022-08-26 11:21   ` Cristian Dumitrescu
  2022-08-26 11:21   ` [PATCH V2 7/7] examples/pipeline: add CLI commands for direct meters Cristian Dumitrescu
  6 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 11:21 UTC (permalink / raw)
  To: dev

Add the CLI command support for reading/writing direct registers.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 examples/pipeline/cli.c | 228 +++++++++++++++++++++++++++++++++-------
 1 file changed, 192 insertions(+), 36 deletions(-)

diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c
index 2e69698031..115147adfc 100644
--- a/examples/pipeline/cli.c
+++ b/examples/pipeline/cli.c
@@ -142,6 +142,54 @@ is_comment(char *in)
 	return 0;
 }
 
+static void
+table_entry_free(struct rte_swx_table_entry *entry)
+{
+	if (!entry)
+		return;
+
+	free(entry->key);
+	free(entry->key_mask);
+	free(entry->action_data);
+	free(entry);
+}
+
+static struct rte_swx_table_entry *
+parse_table_entry(struct rte_swx_ctl_pipeline *p,
+		  char *table_name,
+		  char **tokens,
+		  uint32_t n_tokens)
+{
+	struct rte_swx_table_entry *entry;
+	char *line;
+	uint32_t i;
+
+	/* Buffer allocation. */
+	line = malloc(MAX_LINE_SIZE);
+	if (!line)
+		return NULL;
+
+	/* Copy tokens to buffer. Since the tokens were initially part of a buffer of size
+	 * MAX_LINE_LENGTH, it is guaranteed that putting back some of them into a buffer of the
+	 * same size separated by a single space will not result in buffer overrun.
+	 */
+	line[0] = 0;
+	for (i = 0; i < n_tokens; i++) {
+		if (i)
+			strcat(line, " ");
+
+		strcat(line, tokens[i]);
+	}
+
+	/* Read the table entry from the input buffer. */
+	entry = rte_swx_ctl_pipeline_table_entry_read(p, table_name, line, NULL);
+
+	/* Buffer free. */
+	free(line);
+
+	return entry;
+}
+
 static const char cmd_mempool_help[] =
 "mempool <mempool_name>\n"
 "   buffer <buffer_size>\n"
@@ -732,18 +780,6 @@ cmd_pipeline_build(char **tokens,
 		fclose(iospec_file);
 }
 
-static void
-table_entry_free(struct rte_swx_table_entry *entry)
-{
-	if (!entry)
-		return;
-
-	free(entry->key);
-	free(entry->key_mask);
-	free(entry->action_data);
-	free(entry);
-}
-
 static int
 pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p,
 			   const char *table_name,
@@ -1710,7 +1746,9 @@ cmd_pipeline_abort(char **tokens,
 }
 
 static const char cmd_pipeline_regrd_help[] =
-"pipeline <pipeline_name> regrd <register_array_name> <index>\n";
+"pipeline <pipeline_name> regrd <register_array_name>\n"
+	"index <index>\n"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_regrd(char **tokens,
@@ -1720,18 +1758,20 @@ cmd_pipeline_regrd(char **tokens,
 	void *obj __rte_unused)
 {
 	struct rte_swx_pipeline *p;
-	const char *name;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name;
 	uint64_t value;
-	uint32_t idx;
 	int status;
 
-	if (n_tokens != 5) {
+	if (n_tokens < 5) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -1743,22 +1783,77 @@ cmd_pipeline_regrd(char **tokens,
 
 	name = tokens[3];
 
-	if (parser_read_uint32(&idx, tokens[4])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+	/* index. */
+	if (!strcmp(tokens[4], "index")) {
+		uint32_t idx;
+
+		if (n_tokens != 6) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		if (parser_read_uint32(&idx, tokens[5])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index");
+			return;
+		}
+
+		status = rte_swx_ctl_pipeline_regarray_read(p, name, idx, &value);
+		if (status) {
+			snprintf(out, out_size, "Command failed.\n");
+			return;
+		}
+
+		snprintf(out, out_size, "0x%" PRIx64 "\n", value);
 		return;
 	}
 
-	status = rte_swx_ctl_pipeline_regarray_read(p, name, idx, &value);
-	if (status) {
-		snprintf(out, out_size, "Command failed.\n");
+	/* table. */
+	if (!strcmp(tokens[4], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
+
+		if (n_tokens < 8) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		table_name = tokens[5];
+
+		if (strcmp(tokens[6], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[6], n_tokens - 6);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
+
+		status = rte_swx_ctl_pipeline_regarray_read_with_key(p,
+								     name,
+								     table_name,
+								     entry->key,
+								     &value);
+		table_entry_free(entry);
+		if (status) {
+			snprintf(out, out_size, "Command failed.\n");
+			return;
+		}
+
+		snprintf(out, out_size, "0x%" PRIx64 "\n", value);
 		return;
 	}
 
-	snprintf(out, out_size, "0x%" PRIx64 "\n", value);
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[4]);
+	return;
 }
 
 static const char cmd_pipeline_regwr_help[] =
-"pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n";
+"pipeline <pipeline_name> regwr <register_array_name> value <value>\n"
+	"index <index>\n"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_regwr(char **tokens,
@@ -1768,18 +1863,20 @@ cmd_pipeline_regwr(char **tokens,
 	void *obj __rte_unused)
 {
 	struct rte_swx_pipeline *p;
-	const char *name;
-	uint64_t value;
-	uint32_t idx;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name;
+	uint64_t value = 0;
 	int status;
 
-	if (n_tokens != 6) {
+	if (n_tokens < 7) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -1791,8 +1888,8 @@ cmd_pipeline_regwr(char **tokens,
 
 	name = tokens[3];
 
-	if (parser_read_uint32(&idx, tokens[4])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+	if (strcmp(tokens[4], "value")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "value");
 		return;
 	}
 
@@ -1801,11 +1898,70 @@ cmd_pipeline_regwr(char **tokens,
 		return;
 	}
 
-	status = rte_swx_ctl_pipeline_regarray_write(p, name, idx, value);
-	if (status) {
-		snprintf(out, out_size, "Command failed.\n");
+	/* index. */
+	if (!strcmp(tokens[6], "index")) {
+		uint32_t idx;
+
+		if (n_tokens != 8) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		if (parser_read_uint32(&idx, tokens[7])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index");
+			return;
+		}
+
+		status = rte_swx_ctl_pipeline_regarray_write(p, name, idx, value);
+		if (status) {
+			snprintf(out, out_size, "Command failed.\n");
+			return;
+		}
+
+		snprintf(out, out_size, "0x%" PRIx64 "\n", value);
 		return;
 	}
+
+	/* table. */
+	if (!strcmp(tokens[6], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
+
+		if (n_tokens < 10) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		table_name = tokens[7];
+
+		if (strcmp(tokens[8], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[8], n_tokens - 8);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
+
+		status = rte_swx_ctl_pipeline_regarray_write_with_key(p,
+								      name,
+								      table_name,
+								      entry->key,
+								      value);
+		table_entry_free(entry);
+		if (status) {
+			snprintf(out, out_size, "Command failed.\n");
+			return;
+		}
+
+		return;
+	}
+
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[6]);
+	return;
 }
 
 static const char cmd_pipeline_meter_profile_add_help[] =
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V2 7/7] examples/pipeline: add CLI commands for direct meters
  2022-08-26 11:21 ` [PATCH V2 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                     ` (5 preceding siblings ...)
  2022-08-26 11:21   ` [PATCH V2 6/7] examples/pipeline: add CLI commands for direct registers Cristian Dumitrescu
@ 2022-08-26 11:21   ` Cristian Dumitrescu
  6 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-26 11:21 UTC (permalink / raw)
  To: dev

Add the CLI command support for managing direct meters.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 examples/pipeline/cli.c              | 414 ++++++++++++++++++++-------
 examples/pipeline/examples/meter.cli |   2 +-
 2 files changed, 309 insertions(+), 107 deletions(-)

diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c
index 115147adfc..829eb8fad3 100644
--- a/examples/pipeline/cli.c
+++ b/examples/pipeline/cli.c
@@ -2105,8 +2105,9 @@ cmd_pipeline_meter_profile_delete(char **tokens,
 }
 
 static const char cmd_pipeline_meter_reset_help[] =
-"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
-	"reset\n";
+"pipeline <pipeline_name> meter <meter_array_name> reset\n"
+	"index from <index0> to <index1>\n"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_meter_reset(char **tokens,
@@ -2116,16 +2117,18 @@ cmd_pipeline_meter_reset(char **tokens,
 	void *obj __rte_unused)
 {
 	struct rte_swx_pipeline *p;
-	const char *name;
-	uint32_t idx0 = 0, idx1 = 0;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name;
 
-	if (n_tokens != 9) {
+	if (n_tokens < 6) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -2137,45 +2140,96 @@ cmd_pipeline_meter_reset(char **tokens,
 
 	name = tokens[3];
 
-	if (strcmp(tokens[4], "from")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+	if (strcmp(tokens[4], "reset")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
 		return;
 	}
 
-	if (parser_read_uint32(&idx0, tokens[5])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
-		return;
-	}
+	/* index. */
+	if (!strcmp(tokens[5], "index")) {
+		uint32_t idx0 = 0, idx1 = 0;
 
-	if (strcmp(tokens[6], "to")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
-		return;
-	}
+		if (n_tokens != 10) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
 
-	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
-		return;
-	}
+		if (strcmp(tokens[6], "from")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+			return;
+		}
+
+		if (parser_read_uint32(&idx0, tokens[7])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+			return;
+		}
+
+		if (strcmp(tokens[8], "to")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+			return;
+		}
+
+		if (parser_read_uint32(&idx1, tokens[9]) || (idx1 < idx0)) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+			return;
+		}
+
+		for ( ; idx0 <= idx1; idx0++) {
+			int status;
+
+			status = rte_swx_ctl_meter_reset(p, name, idx0);
+			if (status) {
+				snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+				return;
+			}
+		}
 
-	if (strcmp(tokens[8], "reset")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
 		return;
 	}
 
-	for ( ; idx0 <= idx1; idx0++) {
+	/* table. */
+	if (!strcmp(tokens[5], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
 		int status;
 
-		status = rte_swx_ctl_meter_reset(p, name, idx0);
+		if (n_tokens < 9) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		table_name = tokens[6];
+
+		if (strcmp(tokens[7], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[7], n_tokens - 7);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
+
+		status = rte_swx_ctl_meter_reset_with_key(p, name, table_name, entry->key);
+		table_entry_free(entry);
 		if (status) {
-			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			snprintf(out, out_size, "Command failed.\n");
 			return;
 		}
+
+		return;
 	}
+
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[5]);
+	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";
+"pipeline <pipeline_name> meter <meter_array_name> set profile <profile_name>\n"
+	"index from <index0> to <index1>\n"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_meter_set(char **tokens,
@@ -2185,16 +2239,18 @@ cmd_pipeline_meter_set(char **tokens,
 	void *obj __rte_unused)
 {
 	struct rte_swx_pipeline *p;
-	const char *name, *profile_name;
-	uint32_t idx0 = 0, idx1 = 0;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name, *profile_name;
 
-	if (n_tokens != 11) {
+	if (n_tokens < 8) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -2206,52 +2262,107 @@ cmd_pipeline_meter_set(char **tokens,
 
 	name = tokens[3];
 
-	if (strcmp(tokens[4], "from")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+	if (strcmp(tokens[4], "set")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
 		return;
 	}
 
-	if (parser_read_uint32(&idx0, tokens[5])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+	if (strcmp(tokens[5], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
 		return;
 	}
 
-	if (strcmp(tokens[6], "to")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
-		return;
-	}
+	profile_name = tokens[6];
 
-	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
-		return;
-	}
+	/* index. */
+	if (!strcmp(tokens[7], "index")) {
+		uint32_t idx0 = 0, idx1 = 0;
 
-	if (strcmp(tokens[8], "set")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
-		return;
-	}
+		if (n_tokens != 12) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		if (strcmp(tokens[8], "from")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+			return;
+		}
+
+		if (parser_read_uint32(&idx0, tokens[9])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+			return;
+		}
+
+		if (strcmp(tokens[10], "to")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+			return;
+		}
+
+		if (parser_read_uint32(&idx1, tokens[11]) || (idx1 < idx0)) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+			return;
+		}
+
+		for ( ; idx0 <= idx1; idx0++) {
+			int status;
+
+			status = rte_swx_ctl_meter_set(p, name, idx0, profile_name);
+			if (status) {
+				snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+				return;
+			}
+		}
 
-	if (strcmp(tokens[9], "profile")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
 		return;
 	}
 
-	profile_name = tokens[10];
-
-	for ( ; idx0 <= idx1; idx0++) {
+	/* table. */
+	if (!strcmp(tokens[7], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
 		int status;
 
-		status = rte_swx_ctl_meter_set(p, name, idx0, profile_name);
+		if (n_tokens < 11) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		table_name = tokens[8];
+
+		if (strcmp(tokens[9], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[9], n_tokens - 9);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
+
+		status = rte_swx_ctl_meter_set_with_key(p,
+							name,
+							table_name,
+							entry->key,
+							profile_name);
+		table_entry_free(entry);
 		if (status) {
-			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			snprintf(out, out_size, "Command failed.\n");
 			return;
 		}
+
+		return;
 	}
+
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[7]);
+	return;
 }
 
 static const char cmd_pipeline_meter_stats_help[] =
-"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
-	"stats\n";
+"pipeline <pipeline_name> meter <meter_array_name> stats\n"
+	"index from <index0> to <index1>\n"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_meter_stats(char **tokens,
@@ -2262,16 +2373,18 @@ cmd_pipeline_meter_stats(char **tokens,
 {
 	struct rte_swx_ctl_meter_stats stats;
 	struct rte_swx_pipeline *p;
-	const char *name;
-	uint32_t idx0 = 0, idx1 = 0;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name;
 
-	if (n_tokens != 9) {
+	if (n_tokens != 6) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -2283,68 +2396,151 @@ cmd_pipeline_meter_stats(char **tokens,
 
 	name = tokens[3];
 
-	if (strcmp(tokens[4], "from")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+	if (strcmp(tokens[4], "stats")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
 		return;
 	}
 
-	if (parser_read_uint32(&idx0, tokens[5])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
-		return;
-	}
+	/* index. */
+	if (!strcmp(tokens[5], "index")) {
+		uint32_t idx0 = 0, idx1 = 0;
 
-	if (strcmp(tokens[6], "to")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
-		return;
-	}
+		if (n_tokens != 10) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
 
-	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
-		return;
-	}
+		if (strcmp(tokens[6], "from")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+			return;
+		}
+
+		if (parser_read_uint32(&idx0, tokens[7])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+			return;
+		}
+
+		if (strcmp(tokens[8], "to")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+			return;
+		}
+
+		if (parser_read_uint32(&idx1, tokens[9]) || (idx1 < idx0)) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+			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, name, idx0, &stats);
+			if (status) {
+				snprintf(out, out_size, "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);
+		}
 
-	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);
+	/* table. */
+	if (!strcmp(tokens[5], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
+		int status;
 
-	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);
+		if (n_tokens < 9) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
 
-	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
-		 "-------",
-		 "----------------", "----------------", "----------------",
-		 "----------------", "----------------", "----------------");
-	out_size -= strlen(out);
-	out += strlen(out);
+		table_name = tokens[6];
 
-	/* Table rows. */
-	for ( ; idx0 <= idx1; idx0++) {
-		int status;
+		if (strcmp(tokens[7], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[7], n_tokens - 7);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
 
-		status = rte_swx_ctl_meter_stats_read(p, name, idx0, &stats);
+		status = rte_swx_ctl_meter_stats_read_with_key(p,
+							name,
+							table_name,
+							entry->key,
+							&stats);
+		table_entry_free(entry);
 		if (status) {
-			snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0);
-			out_size -= strlen(out);
-			out += strlen(out);
+			snprintf(out, out_size, "Command failed.\n");
 			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 row. */
 		snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64
 			 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n",
-			 idx0,
+			 0,
 			 stats.n_pkts[RTE_COLOR_GREEN],
 			 stats.n_pkts[RTE_COLOR_YELLOW],
 			 stats.n_pkts[RTE_COLOR_RED],
@@ -2353,7 +2549,13 @@ cmd_pipeline_meter_stats(char **tokens,
 			 stats.n_bytes[RTE_COLOR_RED]);
 		out_size -= strlen(out);
 		out += strlen(out);
+
+		return;
 	}
+
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[5]);
+	return;
 }
 
 static const char cmd_pipeline_stats_help[] =
diff --git a/examples/pipeline/examples/meter.cli b/examples/pipeline/examples/meter.cli
index c1b88c882a..21582554b9 100644
--- a/examples/pipeline/examples/meter.cli
+++ b/examples/pipeline/examples/meter.cli
@@ -35,7 +35,7 @@ pipeline PIPELINE0 build lib /tmp/meter.so io ./examples/pipeline/examples/ethde
 ; The table entries can later be updated at run-time through the CLI commands.
 ;
 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
+pipeline PIPELINE0 meter meters set profile platinum index from 0 to 15
 
 ;
 ; Pipelines-to-threads mapping.
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V3 0/7] pipeline: support direct registers and meters
  2022-08-26 10:35 [PATCH 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                   ` (7 preceding siblings ...)
  2022-08-26 11:21 ` [PATCH V2 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
@ 2022-08-30 18:58 ` Cristian Dumitrescu
  2022-08-30 18:58   ` [PATCH V3 1/7] table: add entry ID for regular tables Cristian Dumitrescu
                     ` (7 more replies)
  8 siblings, 8 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-30 18:58 UTC (permalink / raw)
  To: dev

This patch introduces support for direct registers and meters. The
difference between indirect (indexed) and direct registers and meters
is explained below [1][2][3].

1. Indirect (indexed) registers and meters.

The index into an array of registers or meters used on the data path
is typically read from the action data identified by a table lookup
operation.

This means that the control plane manages the mapping of the mapping
of array entries to table entries and sets up this index explicitly
into the table entry action data.

These are called indirect or indexed registers and meters, and they
allow multiple table entries to share the same register/meter, as well
as a 1:1 mapping of table entries to register/meter array entries.

2. Direct registers and meters.
In the case of 1:1 mapping of table entries to register/meter array
elements, it is sometimes desired to avoid the explicit allocation of
register/meter array index to each table entry by the control plane.

One way this can be done is by implementing a mechanism to associate
a unique ID to each table entry, including the default table entry as
well; once the entry ID is retrieved as result of the table lookup
operation, it is saved by the pipeline and used later on as the
index into the register/meter array.

These are called direct registers and meters, and have the advantage
that the index is auto-generated, which simplifies the controller
implementation; the disadvantage is that they do not allow multiple
table entries to share the same register or meter.

References:

[1] Indirect and direct counters:
https://p4.org/p4-spec/docs/PSA.html#sec-counters

[2] Indirect and direct registers:
https://p4.org/p4-spec/docs/PSA.html#sec-registers

[3] Indirect and direct meters:
https://p4.org/p4-spec/docs/PSA.html#sec-meters

Depends-on: series-24366 ("pipeline: make the hash function configurable per table")

Change log:

V3:
-Fixed issues related to CLI parsing
-Fixed issue related to the key offset

V2:
-Fixed minor style issues flagged by CI/CD

Cristian Dumitrescu (7):
  table: add entry ID for regular tables
  table: add entry ID for learner tables
  pipeline: add table entry ID read instruction
  pipeline: support direct registers on the control path
  pipeline: support direct meters on the control path
  examples/pipeline: add CLI commands for direct registers
  examples/pipeline: add CLI commands for direct meters

 examples/pipeline/cli.c                  | 654 +++++++++++++++++------
 examples/pipeline/examples/meter.cli     |   2 +-
 lib/pipeline/rte_swx_ctl.h               | 133 +++++
 lib/pipeline/rte_swx_pipeline.c          | 390 ++++++++++++++
 lib/pipeline/rte_swx_pipeline_internal.h |  21 +
 lib/pipeline/version.map                 |   5 +
 lib/table/rte_swx_table.h                |  13 +
 lib/table/rte_swx_table_em.c             |   5 +
 lib/table/rte_swx_table_learner.c        |  13 +-
 lib/table/rte_swx_table_learner.h        |  12 +
 lib/table/rte_swx_table_wm.c             |   2 +
 11 files changed, 1097 insertions(+), 153 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V3 1/7] table: add entry ID for regular tables
  2022-08-30 18:58 ` [PATCH V3 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
@ 2022-08-30 18:58   ` Cristian Dumitrescu
  2022-08-30 18:58   ` [PATCH V3 2/7] table: add entry ID for learner tables Cristian Dumitrescu
                     ` (6 subsequent siblings)
  7 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-30 18:58 UTC (permalink / raw)
  To: dev

Add support for unique ID for each table entry. The entry ID is
retrieved as part of the table lookup operation and is saved by the
pipeline for later use.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_pipeline.c          |  9 +++++++++
 lib/pipeline/rte_swx_pipeline_internal.h |  1 +
 lib/table/rte_swx_table.h                | 13 +++++++++++++
 lib/table/rte_swx_table_em.c             |  5 +++++
 lib/table/rte_swx_table_wm.c             |  2 ++
 5 files changed, 30 insertions(+)

diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index 1c49622be7..e271cc50eb 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -2401,6 +2401,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 	struct table_statistics *stats = &p->table_stats[table_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action;
 	uint8_t *action_data;
+	size_t entry_id;
 	int done, hit;
 
 	/* Table. */
@@ -2409,6 +2410,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 			   table->key,
 			   &action_id,
 			   &action_data,
+			   &entry_id,
 			   &hit);
 	if (!done) {
 		/* Thread. */
@@ -2422,6 +2424,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
 
@@ -2433,6 +2436,7 @@ instr_table_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	stats->n_pkts_hit[hit] = n_pkts_hit + 1;
 	stats->n_pkts_action[action_id] = n_pkts_action + 1;
@@ -2452,6 +2456,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 	struct table_statistics *stats = &p->table_stats[table_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action;
 	uint8_t *action_data;
+	size_t entry_id;
 	action_func_t action_func;
 	int done, hit;
 
@@ -2461,6 +2466,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 			   table->key,
 			   &action_id,
 			   &action_data,
+			   &entry_id,
 			   &hit);
 	if (!done) {
 		/* Thread. */
@@ -2474,6 +2480,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	action_func = p->action_funcs[action_id];
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
@@ -2486,6 +2493,7 @@ instr_table_af_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	stats->n_pkts_hit[hit] = n_pkts_hit + 1;
 	stats->n_pkts_action[action_id] = n_pkts_action + 1;
@@ -8283,6 +8291,7 @@ table_stub_lkp(void *table __rte_unused,
 	       uint8_t **key __rte_unused,
 	       uint64_t *action_id __rte_unused,
 	       uint8_t **action_data __rte_unused,
+	       size_t *entry_id __rte_unused,
 	       int *hit)
 {
 	*hit = 0;
diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h
index ef60288dca..8f96b67d76 100644
--- a/lib/pipeline/rte_swx_pipeline_internal.h
+++ b/lib/pipeline/rte_swx_pipeline_internal.h
@@ -1009,6 +1009,7 @@ struct thread {
 	struct learner_runtime *learners;
 	struct rte_swx_table_state *table_state;
 	uint64_t action_id;
+	size_t entry_id;
 	int hit; /* 0 = Miss, 1 = Hit. */
 	uint32_t learner_id;
 	uint64_t time;
diff --git a/lib/table/rte_swx_table.h b/lib/table/rte_swx_table.h
index 4b8dc06798..ac01e19781 100644
--- a/lib/table/rte_swx_table.h
+++ b/lib/table/rte_swx_table.h
@@ -233,6 +233,15 @@ typedef int
  * data likely to be read from the CPU cache with no CPU pipeline stall, which
  * significantly improves the table lookup performance.
  *
+ * The table entry consists of the action ID and the action data. Each table
+ * entry is unique, although different table entries can have identical content,
+ * i.e. same values for the action ID and the action data. The table entry ID is
+ * also returned by the table lookup operation. It can be used to index into an
+ * external array of resources such as counters, registers or meters to identify
+ * the resource directly associated with the current table entry with no need to
+ * store the corresponding index into the table entry. The index of the external
+ * resource is thus auto-generated instead of being stored in the table entry.
+ *
  * @param[in] table
  *   Table handle.
  * @param[in] mailbox
@@ -247,6 +256,9 @@ typedef int
  *   Action data for the *action_id* action. Must point to a valid array of
  *   table *action_data_size* bytes. Only valid when the function returns 1 and
  *   *hit* is set to true.
+ * @param[out] entry_id
+ *   Table entry unique ID. Must point to a valid 32-bit variable. Only valid
+ *   when the function returns 1 and *hit* is set to true.
  * @param[out] hit
  *   Only valid when the function returns 1. Set to non-zero (true) on table
  *   lookup hit and to zero (false) on table lookup miss.
@@ -260,6 +272,7 @@ typedef int
 			  uint8_t **key,
 			  uint64_t *action_id,
 			  uint8_t **action_data,
+			  size_t *entry_id,
 			  int *hit);
 
 /**
diff --git a/lib/table/rte_swx_table_em.c b/lib/table/rte_swx_table_em.c
index 568e76e249..2b5201e006 100644
--- a/lib/table/rte_swx_table_em.c
+++ b/lib/table/rte_swx_table_em.c
@@ -403,6 +403,7 @@ table_lookup_unoptimized(void *table,
 			 uint8_t **key,
 			 uint64_t *action_id,
 			 uint8_t **action_data,
+			 size_t *entry_id,
 			 int *hit)
 {
 	struct table *t = table;
@@ -431,6 +432,7 @@ table_lookup_unoptimized(void *table,
 				bkt_data = table_key_data(t, bkt_key_id);
 				*action_id = bkt_data[0];
 				*action_data = (uint8_t *)&bkt_data[1];
+				*entry_id = bkt_key_id;
 				*hit = 1;
 				return 1;
 			}
@@ -500,6 +502,7 @@ table_lookup(void *table,
 	     uint8_t **key,
 	     uint64_t *action_id,
 	     uint8_t **action_data,
+	     size_t *entry_id,
 	     int *hit)
 {
 	struct table *t = table;
@@ -576,6 +579,7 @@ table_lookup(void *table,
 		lkp_hit &= m->sig_match;
 		*action_id = bkt_data[0];
 		*action_data = (uint8_t *)&bkt_data[1];
+		*entry_id = bkt_key_id;
 		*hit = lkp_hit;
 
 		m->state = 0;
@@ -586,6 +590,7 @@ table_lookup(void *table,
 							key,
 							action_id,
 							action_data,
+							entry_id,
 							hit);
 
 		return 1;
diff --git a/lib/table/rte_swx_table_wm.c b/lib/table/rte_swx_table_wm.c
index ce2a78f94c..58afb35d46 100644
--- a/lib/table/rte_swx_table_wm.c
+++ b/lib/table/rte_swx_table_wm.c
@@ -436,6 +436,7 @@ table_lookup(void *table,
 	     const uint8_t **key,
 	     uint64_t *action_id,
 	     uint8_t **action_data,
+	     size_t *entry_id,
 	     int *hit)
 {
 	struct table *t = table;
@@ -451,6 +452,7 @@ table_lookup(void *table,
 	data = &t->data[(user_data - 1) * t->entry_data_size];
 	*action_id = ((uint64_t *)data)[0];
 	*action_data = &data[8];
+	*entry_id = user_data - 1;
 	*hit = 1;
 	return 1;
 }
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V3 2/7] table: add entry ID for learner tables
  2022-08-30 18:58 ` [PATCH V3 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
  2022-08-30 18:58   ` [PATCH V3 1/7] table: add entry ID for regular tables Cristian Dumitrescu
@ 2022-08-30 18:58   ` Cristian Dumitrescu
  2022-09-24  8:25     ` Thomas Monjalon
  2022-08-30 18:58   ` [PATCH V3 3/7] pipeline: add table entry ID read instruction Cristian Dumitrescu
                     ` (5 subsequent siblings)
  7 siblings, 1 reply; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-30 18:58 UTC (permalink / raw)
  To: dev

Add support for unique ID for each learner table entry. The entry ID
is retrieved as part of the learner table lookup operation and is
saved by the pipeline for later use.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_pipeline.c   |  8 ++++++++
 lib/table/rte_swx_table_learner.c | 13 ++++++++++++-
 lib/table/rte_swx_table_learner.h | 12 ++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index e271cc50eb..80108b8916 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -2556,6 +2556,7 @@ instr_learner_exec(struct rte_swx_pipeline *p)
 	struct learner_statistics *stats = &p->learner_stats[learner_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action, time;
 	uint8_t *action_data;
+	size_t entry_id;
 	int done, hit;
 
 	/* Table. */
@@ -2567,6 +2568,7 @@ instr_learner_exec(struct rte_swx_pipeline *p)
 					    l->key,
 					    &action_id,
 					    &action_data,
+					    &entry_id,
 					    &hit);
 	if (!done) {
 		/* Thread. */
@@ -2580,6 +2582,7 @@ instr_learner_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
 
@@ -2591,6 +2594,7 @@ instr_learner_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	t->learner_id = learner_id;
 	t->time = time;
@@ -2613,6 +2617,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p)
 	struct learner_statistics *stats = &p->learner_stats[learner_id];
 	uint64_t action_id, n_pkts_hit, n_pkts_action, time;
 	uint8_t *action_data;
+	size_t entry_id;
 	action_func_t action_func;
 	int done, hit;
 
@@ -2625,6 +2630,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p)
 					    l->key,
 					    &action_id,
 					    &action_data,
+					    &entry_id,
 					    &hit);
 	if (!done) {
 		/* Thread. */
@@ -2638,6 +2644,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p)
 
 	action_id = hit ? action_id : ts->default_action_id;
 	action_data = hit ? action_data : ts->default_action_data;
+	entry_id = hit ? (1 + entry_id) : 0;
 	action_func = p->action_funcs[action_id];
 	n_pkts_hit = stats->n_pkts_hit[hit];
 	n_pkts_action = stats->n_pkts_action[action_id];
@@ -2650,6 +2657,7 @@ instr_learner_af_exec(struct rte_swx_pipeline *p)
 
 	t->action_id = action_id;
 	t->structs[0] = action_data;
+	t->entry_id = entry_id;
 	t->hit = hit;
 	t->learner_id = learner_id;
 	t->time = time;
diff --git a/lib/table/rte_swx_table_learner.c b/lib/table/rte_swx_table_learner.c
index c1045a1082..996fd3de5b 100644
--- a/lib/table/rte_swx_table_learner.c
+++ b/lib/table/rte_swx_table_learner.c
@@ -72,6 +72,7 @@ table_keycpy(void *dst, void *src, uint32_t n_bytes)
 }
 
 #define TABLE_KEYS_PER_BUCKET 4
+#define TABLE_KEYS_PER_BUCKET_LOG2 2
 
 #define TABLE_BUCKET_USEFUL_SIZE \
 	(TABLE_KEYS_PER_BUCKET * (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint8_t)))
@@ -263,6 +264,14 @@ table_bucket_data_get(struct table *t, struct table_bucket *b, size_t bucket_key
 				   (bucket_key_pos << t->params.data_size_log2)];
 }
 
+static inline size_t
+table_entry_id_get(struct table *t, struct table_bucket *b, size_t bucket_key_pos)
+{
+	size_t bucket_id = ((uint8_t *)b - t->buckets) >> t->params.bucket_size_log2;
+
+	return (bucket_id << TABLE_KEYS_PER_BUCKET_LOG2) + bucket_key_pos;
+}
+
 uint64_t
 rte_swx_table_learner_footprint_get(struct rte_swx_table_learner_params *params)
 {
@@ -332,7 +341,7 @@ struct mailbox {
 	/* Writer: lookup state 0. Reader(s): lookup state 1, add(). */
 	uint32_t input_sig;
 
-	/* Writer: lookup state 1. Reader(s): add(). */
+	/* Writer: lookup state 0. Reader(s): lookup state 1, add(). */
 	uint8_t *input_key;
 
 	/* Writer: lookup state 1. Reader(s): add(). Values: 0 = miss; 1 = hit. */
@@ -358,6 +367,7 @@ rte_swx_table_learner_lookup(void *table,
 			     uint8_t **key,
 			     uint64_t *action_id,
 			     uint8_t **action_data,
+			     size_t *entry_id,
 			     int *hit)
 {
 	struct table *t = table;
@@ -412,6 +422,7 @@ rte_swx_table_learner_lookup(void *table,
 
 				*action_id = data[0];
 				*action_data = (uint8_t *)&data[1];
+				*entry_id = table_entry_id_get(t, b, i);
 				*hit = 1;
 				return 1;
 			}
diff --git a/lib/table/rte_swx_table_learner.h b/lib/table/rte_swx_table_learner.h
index d72b6b88ff..62cac3f225 100644
--- a/lib/table/rte_swx_table_learner.h
+++ b/lib/table/rte_swx_table_learner.h
@@ -173,6 +173,14 @@ rte_swx_table_learner_timeout_update(void *table,
  * possibly an associated key add operation. The mailbox mechanism allows for multiple concurrent
  * table key lookup and add operations into the same table.
  *
+ * The table entry consists of the action ID and the action data. Each table entry is unique, even
+ * though different table entries can have identical content, i.e. same values for the action ID and
+ * the action data. The table entry ID is also returned by the table lookup operation. It can be
+ * used to index into an external array of resources such as counters, registers or meters to
+ * identify the resource directly associated with the current table entry with no need to store the
+ * corresponding index into the table entry. The index of the external resource is thus
+ * auto-generated instead of being stored in the table entry.
+ *
  * @param[in] table
  *   Table handle.
  * @param[in] mailbox
@@ -187,6 +195,9 @@ rte_swx_table_learner_timeout_update(void *table,
  * @param[out] action_data
  *   Action data for the *action_id* action. Must point to a valid array of table *action_data_size*
  *   bytes. Only valid when the function returns 1 and *hit* is set to true.
+ * @param[out] entry_id
+ *   Table entry unique ID. Must point to a valid 32-bit variable. Only valid when the function
+ *   returns 1 and *hit* is set to true.
  * @param[out] hit
  *   Only valid when the function returns 1. Set to non-zero (true) on table lookup hit and to zero
  *   (false) on table lookup miss.
@@ -202,6 +213,7 @@ rte_swx_table_learner_lookup(void *table,
 			     uint8_t **key,
 			     uint64_t *action_id,
 			     uint8_t **action_data,
+			     size_t *entry_id,
 			     int *hit);
 
 /**
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V3 3/7] pipeline: add table entry ID read instruction
  2022-08-30 18:58 ` [PATCH V3 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
  2022-08-30 18:58   ` [PATCH V3 1/7] table: add entry ID for regular tables Cristian Dumitrescu
  2022-08-30 18:58   ` [PATCH V3 2/7] table: add entry ID for learner tables Cristian Dumitrescu
@ 2022-08-30 18:58   ` Cristian Dumitrescu
  2022-08-30 18:58   ` [PATCH V3 4/7] pipeline: support direct registers on the control path Cristian Dumitrescu
                     ` (4 subsequent siblings)
  7 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-30 18:58 UTC (permalink / raw)
  To: dev

Add the entry ID instruction that reads the entry ID of the latest
table lookup operation from the pipeline into the meta-data. The entry
ID is then used by the register and meter instructions as the index
into the register or meter array.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_pipeline.c          | 68 ++++++++++++++++++++++++
 lib/pipeline/rte_swx_pipeline_internal.h | 20 +++++++
 2 files changed, 88 insertions(+)

diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index 80108b8916..ec8268b7f8 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -2834,6 +2834,43 @@ instr_forget_exec(struct rte_swx_pipeline *p)
 	thread_ip_inc(p);
 }
 
+/*
+ * entryid.
+ */
+static int
+instr_entryid_translate(struct rte_swx_pipeline *p,
+			struct action *action __rte_unused,
+			char **tokens,
+			int n_tokens,
+			struct instruction *instr,
+			struct instruction_data *data __rte_unused)
+{
+	struct field *f;
+
+	CHECK(n_tokens == 2, EINVAL);
+
+	f = metadata_field_parse(p, tokens[1]);
+	CHECK(f, EINVAL);
+	CHECK(f->n_bits <= 64, EINVAL);
+
+	instr->type = INSTR_ENTRYID;
+	instr->mov.dst.n_bits = f->n_bits;
+	instr->mov.dst.offset = f->offset / 8;
+	return 0;
+}
+
+static inline void
+instr_entryid_exec(struct rte_swx_pipeline *p)
+{
+	struct thread *t = &p->threads[p->thread_id];
+	struct instruction *ip = t->ip;
+
+	__instr_entryid_exec(p, t, ip);
+
+	/* Thread. */
+	thread_ip_inc(p);
+}
+
 /*
  * extern.
  */
@@ -6336,6 +6373,14 @@ instr_translate(struct rte_swx_pipeline *p,
 					      instr,
 					      data);
 
+	if (!strcmp(tokens[tpos], "entryid"))
+		return instr_entryid_translate(p,
+					       action,
+					       &tokens[tpos],
+					       n_tokens - tpos,
+					       instr,
+					       data);
+
 	if (!strcmp(tokens[tpos], "extern"))
 		return instr_extern_translate(p,
 					      action,
@@ -7321,6 +7366,8 @@ static instr_exec_t instruction_table[] = {
 	[INSTR_LEARNER_REARM] = instr_rearm_exec,
 	[INSTR_LEARNER_REARM_NEW] = instr_rearm_new_exec,
 	[INSTR_LEARNER_FORGET] = instr_forget_exec,
+	[INSTR_ENTRYID] = instr_entryid_exec,
+
 	[INSTR_EXTERN_OBJ] = instr_extern_obj_exec,
 	[INSTR_EXTERN_FUNC] = instr_extern_func_exec,
 	[INSTR_HASH_FUNC] = instr_hash_func_exec,
@@ -11222,6 +11269,7 @@ instr_type_to_name(struct instruction *instr)
 	case INSTR_LEARNER_REARM: return "INSTR_LEARNER_REARM";
 	case INSTR_LEARNER_REARM_NEW: return "INSTR_LEARNER_REARM_NEW";
 	case INSTR_LEARNER_FORGET: return "INSTR_LEARNER_FORGET";
+	case INSTR_ENTRYID: return "INSTR_ENTRYID";
 
 	case INSTR_EXTERN_OBJ: return "INSTR_EXTERN_OBJ";
 	case INSTR_EXTERN_FUNC: return "INSTR_EXTERN_FUNC";
@@ -11922,6 +11970,24 @@ instr_forget_export(struct instruction *instr, FILE *f)
 		instr_type_to_name(instr));
 }
 
+static void
+instr_entryid_export(struct instruction *instr, FILE *f)
+{
+	fprintf(f,
+		"\t{\n"
+		"\t\t.type = %s,\n"
+		"\t\t.mov = {\n"
+		"\t\t\t.dst = {\n"
+		"\t\t\t\t.n_bits = %u,\n"
+		"\t\t\t\t.offset = %u,\n"
+		"\t\t\t},\n"
+		"\t\t},\n"
+		"\t},\n",
+		instr_type_to_name(instr),
+		instr->mov.dst.n_bits,
+		instr->mov.dst.offset);
+}
+
 static void
 instr_extern_export(struct instruction *instr, FILE *f)
 {
@@ -12212,6 +12278,7 @@ static instruction_export_t export_table[] = {
 	[INSTR_LEARNER_REARM] = instr_rearm_export,
 	[INSTR_LEARNER_REARM_NEW] = instr_rearm_export,
 	[INSTR_LEARNER_FORGET] = instr_forget_export,
+	[INSTR_ENTRYID] = instr_entryid_export,
 
 	[INSTR_EXTERN_OBJ] = instr_extern_export,
 	[INSTR_EXTERN_FUNC] = instr_extern_export,
@@ -12438,6 +12505,7 @@ instr_type_to_func(struct instruction *instr)
 	case INSTR_LEARNER_REARM: return "__instr_rearm_exec";
 	case INSTR_LEARNER_REARM_NEW: return "__instr_rearm_new_exec";
 	case INSTR_LEARNER_FORGET: return "__instr_forget_exec";
+	case INSTR_ENTRYID: return "__instr_entryid_exec";
 
 	case INSTR_EXTERN_OBJ: return NULL;
 	case INSTR_EXTERN_FUNC: return NULL;
diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h
index 8f96b67d76..335506039b 100644
--- a/lib/pipeline/rte_swx_pipeline_internal.h
+++ b/lib/pipeline/rte_swx_pipeline_internal.h
@@ -504,6 +504,11 @@ enum instruction_type {
 	/* forget */
 	INSTR_LEARNER_FORGET,
 
+	/* entryid m.table_entry_id
+	 * Read the internal table entry ID into the specified meta-data field.
+	 */
+	INSTR_ENTRYID,
+
 	/* extern e.obj.func */
 	INSTR_EXTERN_OBJ,
 
@@ -2377,6 +2382,21 @@ __instr_forget_exec(struct rte_swx_pipeline *p,
 	stats->n_pkts_forget += 1;
 }
 
+/*
+ * entryid.
+ */
+static inline void
+__instr_entryid_exec(struct rte_swx_pipeline *p __rte_unused,
+		       struct thread *t,
+		       const struct instruction *ip)
+{
+	TRACE("[Thread %2u]: entryid\n",
+	      p->thread_id);
+
+	/* Meta-data. */
+	METADATA_WRITE(t, ip->mov.dst.offset, ip->mov.dst.n_bits, t->entry_id);
+}
+
 /*
  * extern.
  */
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V3 4/7] pipeline: support direct registers on the control path
  2022-08-30 18:58 ` [PATCH V3 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                     ` (2 preceding siblings ...)
  2022-08-30 18:58   ` [PATCH V3 3/7] pipeline: add table entry ID read instruction Cristian Dumitrescu
@ 2022-08-30 18:58   ` Cristian Dumitrescu
  2022-08-30 18:58   ` [PATCH V3 5/7] pipeline: support direct meters " Cristian Dumitrescu
                     ` (3 subsequent siblings)
  7 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-30 18:58 UTC (permalink / raw)
  To: dev

Add pipeline control path API to read/write direct registers. These
registers are identified by a table key, whose entry ID is used as the
index into the register array.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_ctl.h      |  52 +++++++
 lib/pipeline/rte_swx_pipeline.c | 255 ++++++++++++++++++++++++++++++++
 lib/pipeline/version.map        |   2 +
 3 files changed, 309 insertions(+)

diff --git a/lib/pipeline/rte_swx_ctl.h b/lib/pipeline/rte_swx_ctl.h
index 0694df557a..1b47820441 100644
--- a/lib/pipeline/rte_swx_ctl.h
+++ b/lib/pipeline/rte_swx_ctl.h
@@ -1237,6 +1237,58 @@ rte_swx_ctl_pipeline_regarray_write(struct rte_swx_pipeline *p,
 				   uint32_t regarray_index,
 				   uint64_t value);
 
+/**
+ * Register read with table key lookup
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] regarray_name
+ *   Register array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @param[out] value
+ *   Current register value.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough memory.
+ */
+__rte_experimental
+int
+rte_swx_ctl_pipeline_regarray_read_with_key(struct rte_swx_pipeline *p,
+					    const char *regarray_name,
+					    const char *table_name,
+					    uint8_t *table_key,
+					    uint64_t *value);
+
+/**
+ * Register write with table key lookup
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] regarray_name
+ *   Register array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @param[in] value
+ *   Value to be written to the register.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough memory.
+ */
+__rte_experimental
+int
+rte_swx_ctl_pipeline_regarray_write_with_key(struct rte_swx_pipeline *p,
+					     const char *regarray_name,
+					     const char *table_name,
+					     uint8_t *table_key,
+					     uint64_t value);
+
 /*
  * Meter Array Query and Configuration API.
  */
diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index ec8268b7f8..ab59e7ad79 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -8261,6 +8261,24 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
 	return status;
 }
 
+static uint32_t
+table_params_offset_get(struct table *table)
+{
+	struct field *first;
+	uint32_t i;
+
+	first = table->fields[0].field;
+
+	for (i = 1; i < table->n_fields; i++) {
+		struct field *f = table->fields[i].field;
+
+		if (f->offset < first->offset)
+			first = f;
+	}
+
+	return first->offset / 8;
+}
+
 static struct rte_swx_table_params *
 table_params_get(struct table *table)
 {
@@ -9217,6 +9235,24 @@ rte_swx_pipeline_learner_config(struct rte_swx_pipeline *p,
 	return status;
 }
 
+static uint32_t
+learner_params_offset_get(struct learner *l)
+{
+	struct field *first;
+	uint32_t i;
+
+	first = l->fields[0];
+
+	for (i = 1; i < l->n_fields; i++) {
+		struct field *f = l->fields[i];
+
+		if (f->offset < first->offset)
+			first = f;
+	}
+
+	return first->offset / 8;
+}
+
 static void
 learner_params_free(struct rte_swx_table_learner_params *params)
 {
@@ -11101,6 +11137,225 @@ rte_swx_ctl_pipeline_mirroring_session_set(struct rte_swx_pipeline *p,
 	return 0;
 }
 
+static int
+rte_swx_ctl_pipeline_table_lookup(struct rte_swx_pipeline *p,
+				  const char *table_name,
+				  uint8_t *key,
+				  uint64_t *action_id,
+				  uint8_t **action_data,
+				  size_t *entry_id,
+				  int *hit)
+{
+	struct table *t;
+	void *mailbox = NULL;
+
+	/* Check input arguments. */
+	if (!p ||
+	    !p->build_done ||
+	    !table_name ||
+	    !table_name[0] ||
+	    !key ||
+	    !entry_id ||
+	    !hit)
+		return -EINVAL;
+
+	/* Find the table. */
+	t = table_find(p, table_name);
+	if (!t)
+		return -EINVAL;
+
+	if (!t->type) {
+		*hit = 0;
+		return 0;
+	}
+
+	/* Setup mailbox.  */
+	if (t->type->ops.mailbox_size_get) {
+		uint64_t mailbox_size;
+
+		mailbox_size = t->type->ops.mailbox_size_get();
+		if (mailbox_size) {
+			mailbox = calloc(1, mailbox_size);
+			if (!mailbox)
+				return -ENOMEM;
+		}
+	}
+
+	/* Table lookup operation. */
+	key -= table_params_offset_get(t);
+
+	for ( ; ; ) {
+		struct rte_swx_table_state *ts = &p->table_state[t->id];
+		int done;
+
+		done = t->type->ops.lkp(ts->obj,
+					mailbox,
+					&key,
+					action_id,
+					action_data,
+					entry_id,
+					hit);
+		if (done)
+			break;
+	}
+
+	/* Free mailbox. */
+	free(mailbox);
+
+	return 0;
+}
+
+static int
+rte_swx_ctl_pipeline_learner_lookup(struct rte_swx_pipeline *p,
+				    const char *learner_name,
+				    uint8_t *key,
+				    uint64_t *action_id,
+				    uint8_t **action_data,
+				    size_t *entry_id,
+				    int *hit)
+{
+	struct learner *l;
+	void *mailbox = NULL;
+	uint64_t mailbox_size, time;
+
+	/* Check input arguments. */
+	if (!p ||
+	    !p->build_done ||
+	    !learner_name ||
+	    !learner_name[0] ||
+	    !key ||
+	    !entry_id ||
+	    !hit)
+		return -EINVAL;
+
+	/* Find the learner table. */
+	l = learner_find(p, learner_name);
+	if (!l)
+		return -EINVAL;
+
+	/* Setup mailbox.  */
+	mailbox_size = rte_swx_table_learner_mailbox_size_get();
+	if (mailbox_size) {
+		mailbox = calloc(1, mailbox_size);
+		if (!mailbox)
+			return -ENOMEM;
+	}
+
+	/* Learner table lookup operation. */
+	key -= learner_params_offset_get(l);
+
+	time = rte_get_tsc_cycles();
+
+	for ( ; ; ) {
+		uint32_t pos = p->n_tables + p->n_selectors + l->id;
+		struct rte_swx_table_state *ts = &p->table_state[pos];
+		int done;
+
+		done = rte_swx_table_learner_lookup(ts->obj,
+						    mailbox,
+						    time,
+						    &key,
+						    action_id,
+						    action_data,
+						    entry_id,
+						    hit);
+		if (done)
+			break;
+	}
+
+	/* Free mailbox. */
+	free(mailbox);
+
+	return 0;
+}
+
+static int
+rte_swx_ctl_pipeline_table_entry_id_get(struct rte_swx_pipeline *p,
+					const char *table_name,
+					uint8_t *table_key,
+					size_t *table_entry_id)
+{
+	struct table *t;
+	struct learner *l;
+	uint64_t action_id;
+	uint8_t *action_data;
+	size_t entry_id = 0;
+	int hit = 0, status;
+
+	/* Check input arguments. */
+	if (!p ||
+	    !p->build_done ||
+	    !table_name ||
+	    !table_name[0] ||
+	    !table_key ||
+	    !table_entry_id)
+		return -EINVAL;
+
+	t = table_find(p, table_name);
+	l = learner_find(p, table_name);
+	if (!t && !l)
+		return -EINVAL;
+
+	/* Table lookup operation. */
+	if (t)
+		status = rte_swx_ctl_pipeline_table_lookup(p,
+							   table_name,
+							   table_key,
+							   &action_id,
+							   &action_data,
+							   &entry_id,
+							   &hit);
+	else
+		status = rte_swx_ctl_pipeline_learner_lookup(p,
+							     table_name,
+							     table_key,
+							     &action_id,
+							     &action_data,
+							     &entry_id,
+							     &hit);
+	if (status)
+		return status;
+
+	/* Reserve entry ID 0 for the table default entry. */
+	*table_entry_id = hit ? (1 + entry_id) : 0;
+
+	return 0;
+}
+
+int
+rte_swx_ctl_pipeline_regarray_read_with_key(struct rte_swx_pipeline *p,
+					    const char *regarray_name,
+					    const char *table_name,
+					    uint8_t *table_key,
+					    uint64_t *value)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_pipeline_regarray_read(p, regarray_name, entry_id, value);
+}
+
+int
+rte_swx_ctl_pipeline_regarray_write_with_key(struct rte_swx_pipeline *p,
+					     const char *regarray_name,
+					     const char *table_name,
+					     uint8_t *table_key,
+					     uint64_t value)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_pipeline_regarray_write(p, regarray_name, entry_id, value);
+}
+
 /*
  * Pipeline compilation.
  */
diff --git a/lib/pipeline/version.map b/lib/pipeline/version.map
index 16806e6802..8ed92042d6 100644
--- a/lib/pipeline/version.map
+++ b/lib/pipeline/version.map
@@ -147,6 +147,8 @@ EXPERIMENTAL {
 
 	#added in 22.11
 	rte_swx_ctl_pipeline_find;
+	rte_swx_ctl_pipeline_regarray_read_with_key;
+	rte_swx_ctl_pipeline_regarray_write_with_key;
 	rte_swx_pipeline_build_from_lib;
 	rte_swx_pipeline_codegen;
 	rte_swx_pipeline_find;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V3 5/7] pipeline: support direct meters on the control path
  2022-08-30 18:58 ` [PATCH V3 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                     ` (3 preceding siblings ...)
  2022-08-30 18:58   ` [PATCH V3 4/7] pipeline: support direct registers on the control path Cristian Dumitrescu
@ 2022-08-30 18:58   ` Cristian Dumitrescu
  2022-08-30 18:58   ` [PATCH V3 6/7] examples/pipeline: add CLI commands for direct registers Cristian Dumitrescu
                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-30 18:58 UTC (permalink / raw)
  To: dev

Add pipeline control path API to manage direct meters. These meters
are identified by a table key, whose entry ID is used as the index
into the meter array.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/pipeline/rte_swx_ctl.h      | 81 +++++++++++++++++++++++++++++++++
 lib/pipeline/rte_swx_pipeline.c | 50 ++++++++++++++++++++
 lib/pipeline/version.map        |  3 ++
 3 files changed, 134 insertions(+)

diff --git a/lib/pipeline/rte_swx_ctl.h b/lib/pipeline/rte_swx_ctl.h
index 1b47820441..2eb51b2c76 100644
--- a/lib/pipeline/rte_swx_ctl.h
+++ b/lib/pipeline/rte_swx_ctl.h
@@ -1440,6 +1440,87 @@ rte_swx_ctl_meter_stats_read(struct rte_swx_pipeline *p,
 			     uint32_t metarray_index,
 			     struct rte_swx_ctl_meter_stats *stats);
 
+/**
+ * Meter reset with table key lookup
+ *
+ * Reset a meter within a given meter array to use the default profile that
+ * causes all the input packets to be colored as green. It is the responsibility
+ * of the control plane to make sure this meter is not used by the data plane
+ * pipeline before calling this function.
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] metarray_name
+ *   Meter array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument.
+ */
+__rte_experimental
+int
+rte_swx_ctl_meter_reset_with_key(struct rte_swx_pipeline *p,
+				 const char *metarray_name,
+				 const char *table_name,
+				 uint8_t *table_key);
+
+/**
+ * Meter set with table key lookup
+ *
+ * Set a meter within a given meter array to use a specific profile. It is the
+ * responsibility of the control plane to make sure this meter is not used by
+ * the data plane pipeline before calling this function.
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] metarray_name
+ *   Meter array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @param[in] profile_name
+ *   Existing meter profile name.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument.
+ */
+__rte_experimental
+int
+rte_swx_ctl_meter_set_with_key(struct rte_swx_pipeline *p,
+			       const char *metarray_name,
+			       const char *table_name,
+			       uint8_t *table_key,
+			       const char *profile_name);
+
+/**
+ * Meter statistics counters read with table key lookup
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] metarray_name
+ *   Meter array name.
+ * @param[in] table_name
+ *   Regular or learner table name.
+ * @param[in] table_key
+ *   Table key.
+ * @param[out] stats
+ *   Meter statistics counters.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument.
+ */
+__rte_experimental
+int
+rte_swx_ctl_meter_stats_read_with_key(struct rte_swx_pipeline *p,
+				      const char *metarray_name,
+				      const char *table_name,
+				      uint8_t *table_key,
+				      struct rte_swx_ctl_meter_stats *stats);
+
 /**
  * Pipeline control free
  *
diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index ab59e7ad79..232dafb95e 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -11356,6 +11356,56 @@ rte_swx_ctl_pipeline_regarray_write_with_key(struct rte_swx_pipeline *p,
 	return rte_swx_ctl_pipeline_regarray_write(p, regarray_name, entry_id, value);
 }
 
+int
+rte_swx_ctl_meter_reset_with_key(struct rte_swx_pipeline *p,
+				 const char *metarray_name,
+				 const char *table_name,
+				 uint8_t *table_key)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_meter_reset(p, metarray_name, entry_id);
+}
+
+int
+rte_swx_ctl_meter_set_with_key(struct rte_swx_pipeline *p,
+			       const char *metarray_name,
+			       const char *table_name,
+			       uint8_t *table_key,
+			       const char *profile_name)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_meter_set(p, metarray_name, entry_id, profile_name);
+}
+
+int
+rte_swx_ctl_meter_stats_read_with_key(struct rte_swx_pipeline *p,
+				      const char *metarray_name,
+				      const char *table_name,
+				      uint8_t *table_key,
+				      struct rte_swx_ctl_meter_stats *stats)
+{
+	size_t entry_id = 0;
+	int status;
+
+	status = rte_swx_ctl_pipeline_table_entry_id_get(p, table_name, table_key, &entry_id);
+	if (status)
+		return status;
+
+	return rte_swx_ctl_meter_stats_read(p, metarray_name, entry_id, stats);
+}
+
 /*
  * Pipeline compilation.
  */
diff --git a/lib/pipeline/version.map b/lib/pipeline/version.map
index 8ed92042d6..f53a037edf 100644
--- a/lib/pipeline/version.map
+++ b/lib/pipeline/version.map
@@ -146,6 +146,9 @@ EXPERIMENTAL {
 	rte_swx_pipeline_hash_func_register;
 
 	#added in 22.11
+	rte_swx_ctl_meter_reset_with_key;
+	rte_swx_ctl_meter_set_with_key;
+	rte_swx_ctl_meter_stats_read_with_key;
 	rte_swx_ctl_pipeline_find;
 	rte_swx_ctl_pipeline_regarray_read_with_key;
 	rte_swx_ctl_pipeline_regarray_write_with_key;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V3 6/7] examples/pipeline: add CLI commands for direct registers
  2022-08-30 18:58 ` [PATCH V3 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                     ` (4 preceding siblings ...)
  2022-08-30 18:58   ` [PATCH V3 5/7] pipeline: support direct meters " Cristian Dumitrescu
@ 2022-08-30 18:58   ` Cristian Dumitrescu
  2022-08-30 18:58   ` [PATCH V3 7/7] examples/pipeline: add CLI commands for direct meters Cristian Dumitrescu
  2022-09-24  9:34   ` [PATCH V3 0/7] pipeline: support direct registers and meters Thomas Monjalon
  7 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-30 18:58 UTC (permalink / raw)
  To: dev

Add the CLI command support for reading/writing direct registers.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 examples/pipeline/cli.c | 228 +++++++++++++++++++++++++++++++++-------
 1 file changed, 192 insertions(+), 36 deletions(-)

diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c
index 2e69698031..115147adfc 100644
--- a/examples/pipeline/cli.c
+++ b/examples/pipeline/cli.c
@@ -142,6 +142,54 @@ is_comment(char *in)
 	return 0;
 }
 
+static void
+table_entry_free(struct rte_swx_table_entry *entry)
+{
+	if (!entry)
+		return;
+
+	free(entry->key);
+	free(entry->key_mask);
+	free(entry->action_data);
+	free(entry);
+}
+
+static struct rte_swx_table_entry *
+parse_table_entry(struct rte_swx_ctl_pipeline *p,
+		  char *table_name,
+		  char **tokens,
+		  uint32_t n_tokens)
+{
+	struct rte_swx_table_entry *entry;
+	char *line;
+	uint32_t i;
+
+	/* Buffer allocation. */
+	line = malloc(MAX_LINE_SIZE);
+	if (!line)
+		return NULL;
+
+	/* Copy tokens to buffer. Since the tokens were initially part of a buffer of size
+	 * MAX_LINE_LENGTH, it is guaranteed that putting back some of them into a buffer of the
+	 * same size separated by a single space will not result in buffer overrun.
+	 */
+	line[0] = 0;
+	for (i = 0; i < n_tokens; i++) {
+		if (i)
+			strcat(line, " ");
+
+		strcat(line, tokens[i]);
+	}
+
+	/* Read the table entry from the input buffer. */
+	entry = rte_swx_ctl_pipeline_table_entry_read(p, table_name, line, NULL);
+
+	/* Buffer free. */
+	free(line);
+
+	return entry;
+}
+
 static const char cmd_mempool_help[] =
 "mempool <mempool_name>\n"
 "   buffer <buffer_size>\n"
@@ -732,18 +780,6 @@ cmd_pipeline_build(char **tokens,
 		fclose(iospec_file);
 }
 
-static void
-table_entry_free(struct rte_swx_table_entry *entry)
-{
-	if (!entry)
-		return;
-
-	free(entry->key);
-	free(entry->key_mask);
-	free(entry->action_data);
-	free(entry);
-}
-
 static int
 pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p,
 			   const char *table_name,
@@ -1710,7 +1746,9 @@ cmd_pipeline_abort(char **tokens,
 }
 
 static const char cmd_pipeline_regrd_help[] =
-"pipeline <pipeline_name> regrd <register_array_name> <index>\n";
+"pipeline <pipeline_name> regrd <register_array_name>\n"
+	"index <index>\n"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_regrd(char **tokens,
@@ -1720,18 +1758,20 @@ cmd_pipeline_regrd(char **tokens,
 	void *obj __rte_unused)
 {
 	struct rte_swx_pipeline *p;
-	const char *name;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name;
 	uint64_t value;
-	uint32_t idx;
 	int status;
 
-	if (n_tokens != 5) {
+	if (n_tokens < 5) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -1743,22 +1783,77 @@ cmd_pipeline_regrd(char **tokens,
 
 	name = tokens[3];
 
-	if (parser_read_uint32(&idx, tokens[4])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+	/* index. */
+	if (!strcmp(tokens[4], "index")) {
+		uint32_t idx;
+
+		if (n_tokens != 6) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		if (parser_read_uint32(&idx, tokens[5])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index");
+			return;
+		}
+
+		status = rte_swx_ctl_pipeline_regarray_read(p, name, idx, &value);
+		if (status) {
+			snprintf(out, out_size, "Command failed.\n");
+			return;
+		}
+
+		snprintf(out, out_size, "0x%" PRIx64 "\n", value);
 		return;
 	}
 
-	status = rte_swx_ctl_pipeline_regarray_read(p, name, idx, &value);
-	if (status) {
-		snprintf(out, out_size, "Command failed.\n");
+	/* table. */
+	if (!strcmp(tokens[4], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
+
+		if (n_tokens < 8) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		table_name = tokens[5];
+
+		if (strcmp(tokens[6], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[6], n_tokens - 6);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
+
+		status = rte_swx_ctl_pipeline_regarray_read_with_key(p,
+								     name,
+								     table_name,
+								     entry->key,
+								     &value);
+		table_entry_free(entry);
+		if (status) {
+			snprintf(out, out_size, "Command failed.\n");
+			return;
+		}
+
+		snprintf(out, out_size, "0x%" PRIx64 "\n", value);
 		return;
 	}
 
-	snprintf(out, out_size, "0x%" PRIx64 "\n", value);
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[4]);
+	return;
 }
 
 static const char cmd_pipeline_regwr_help[] =
-"pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n";
+"pipeline <pipeline_name> regwr <register_array_name> value <value>\n"
+	"index <index>\n"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_regwr(char **tokens,
@@ -1768,18 +1863,20 @@ cmd_pipeline_regwr(char **tokens,
 	void *obj __rte_unused)
 {
 	struct rte_swx_pipeline *p;
-	const char *name;
-	uint64_t value;
-	uint32_t idx;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name;
+	uint64_t value = 0;
 	int status;
 
-	if (n_tokens != 6) {
+	if (n_tokens < 7) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -1791,8 +1888,8 @@ cmd_pipeline_regwr(char **tokens,
 
 	name = tokens[3];
 
-	if (parser_read_uint32(&idx, tokens[4])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index");
+	if (strcmp(tokens[4], "value")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "value");
 		return;
 	}
 
@@ -1801,11 +1898,70 @@ cmd_pipeline_regwr(char **tokens,
 		return;
 	}
 
-	status = rte_swx_ctl_pipeline_regarray_write(p, name, idx, value);
-	if (status) {
-		snprintf(out, out_size, "Command failed.\n");
+	/* index. */
+	if (!strcmp(tokens[6], "index")) {
+		uint32_t idx;
+
+		if (n_tokens != 8) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		if (parser_read_uint32(&idx, tokens[7])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index");
+			return;
+		}
+
+		status = rte_swx_ctl_pipeline_regarray_write(p, name, idx, value);
+		if (status) {
+			snprintf(out, out_size, "Command failed.\n");
+			return;
+		}
+
+		snprintf(out, out_size, "0x%" PRIx64 "\n", value);
 		return;
 	}
+
+	/* table. */
+	if (!strcmp(tokens[6], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
+
+		if (n_tokens < 10) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		table_name = tokens[7];
+
+		if (strcmp(tokens[8], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[8], n_tokens - 8);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
+
+		status = rte_swx_ctl_pipeline_regarray_write_with_key(p,
+								      name,
+								      table_name,
+								      entry->key,
+								      value);
+		table_entry_free(entry);
+		if (status) {
+			snprintf(out, out_size, "Command failed.\n");
+			return;
+		}
+
+		return;
+	}
+
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[6]);
+	return;
 }
 
 static const char cmd_pipeline_meter_profile_add_help[] =
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH V3 7/7] examples/pipeline: add CLI commands for direct meters
  2022-08-30 18:58 ` [PATCH V3 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                     ` (5 preceding siblings ...)
  2022-08-30 18:58   ` [PATCH V3 6/7] examples/pipeline: add CLI commands for direct registers Cristian Dumitrescu
@ 2022-08-30 18:58   ` Cristian Dumitrescu
  2022-09-24  9:34   ` [PATCH V3 0/7] pipeline: support direct registers and meters Thomas Monjalon
  7 siblings, 0 replies; 28+ messages in thread
From: Cristian Dumitrescu @ 2022-08-30 18:58 UTC (permalink / raw)
  To: dev

Add the CLI command support for managing direct meters.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 examples/pipeline/cli.c              | 426 +++++++++++++++++++--------
 examples/pipeline/examples/meter.cli |   2 +-
 2 files changed, 312 insertions(+), 116 deletions(-)

diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c
index 115147adfc..1426faf1f9 100644
--- a/examples/pipeline/cli.c
+++ b/examples/pipeline/cli.c
@@ -2105,8 +2105,9 @@ cmd_pipeline_meter_profile_delete(char **tokens,
 }
 
 static const char cmd_pipeline_meter_reset_help[] =
-"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
-	"reset\n";
+"pipeline <pipeline_name> meter <meter_array_name> reset\n"
+	"index from <index0> to <index1>\n"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_meter_reset(char **tokens,
@@ -2116,16 +2117,18 @@ cmd_pipeline_meter_reset(char **tokens,
 	void *obj __rte_unused)
 {
 	struct rte_swx_pipeline *p;
-	const char *name;
-	uint32_t idx0 = 0, idx1 = 0;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name;
 
-	if (n_tokens != 9) {
+	if (n_tokens < 6) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -2137,45 +2140,96 @@ cmd_pipeline_meter_reset(char **tokens,
 
 	name = tokens[3];
 
-	if (strcmp(tokens[4], "from")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+	if (strcmp(tokens[4], "reset")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
 		return;
 	}
 
-	if (parser_read_uint32(&idx0, tokens[5])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
-		return;
-	}
+	/* index. */
+	if (!strcmp(tokens[5], "index")) {
+		uint32_t idx0 = 0, idx1 = 0;
 
-	if (strcmp(tokens[6], "to")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
-		return;
-	}
+		if (n_tokens != 10) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
 
-	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
-		return;
-	}
+		if (strcmp(tokens[6], "from")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+			return;
+		}
+
+		if (parser_read_uint32(&idx0, tokens[7])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+			return;
+		}
+
+		if (strcmp(tokens[8], "to")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+			return;
+		}
+
+		if (parser_read_uint32(&idx1, tokens[9]) || (idx1 < idx0)) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+			return;
+		}
+
+		for ( ; idx0 <= idx1; idx0++) {
+			int status;
+
+			status = rte_swx_ctl_meter_reset(p, name, idx0);
+			if (status) {
+				snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+				return;
+			}
+		}
 
-	if (strcmp(tokens[8], "reset")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
 		return;
 	}
 
-	for ( ; idx0 <= idx1; idx0++) {
+	/* table. */
+	if (!strcmp(tokens[5], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
 		int status;
 
-		status = rte_swx_ctl_meter_reset(p, name, idx0);
+		if (n_tokens < 9) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		table_name = tokens[6];
+
+		if (strcmp(tokens[7], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[7], n_tokens - 7);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
+
+		status = rte_swx_ctl_meter_reset_with_key(p, name, table_name, entry->key);
+		table_entry_free(entry);
 		if (status) {
-			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			snprintf(out, out_size, "Command failed.\n");
 			return;
 		}
+
+		return;
 	}
+
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[5]);
+	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";
+"pipeline <pipeline_name> meter <meter_array_name> set profile <profile_name>\n"
+	"index from <index0> to <index1>\n"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_meter_set(char **tokens,
@@ -2185,16 +2239,18 @@ cmd_pipeline_meter_set(char **tokens,
 	void *obj __rte_unused)
 {
 	struct rte_swx_pipeline *p;
-	const char *name, *profile_name;
-	uint32_t idx0 = 0, idx1 = 0;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name, *profile_name;
 
-	if (n_tokens != 11) {
+	if (n_tokens < 8) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -2206,52 +2262,107 @@ cmd_pipeline_meter_set(char **tokens,
 
 	name = tokens[3];
 
-	if (strcmp(tokens[4], "from")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+	if (strcmp(tokens[4], "set")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
 		return;
 	}
 
-	if (parser_read_uint32(&idx0, tokens[5])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+	if (strcmp(tokens[5], "profile")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
 		return;
 	}
 
-	if (strcmp(tokens[6], "to")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
-		return;
-	}
+	profile_name = tokens[6];
 
-	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
-		return;
-	}
+	/* index. */
+	if (!strcmp(tokens[7], "index")) {
+		uint32_t idx0 = 0, idx1 = 0;
 
-	if (strcmp(tokens[8], "set")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
-		return;
-	}
+		if (n_tokens != 12) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		if (strcmp(tokens[8], "from")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+			return;
+		}
+
+		if (parser_read_uint32(&idx0, tokens[9])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+			return;
+		}
+
+		if (strcmp(tokens[10], "to")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+			return;
+		}
+
+		if (parser_read_uint32(&idx1, tokens[11]) || (idx1 < idx0)) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+			return;
+		}
+
+		for ( ; idx0 <= idx1; idx0++) {
+			int status;
+
+			status = rte_swx_ctl_meter_set(p, name, idx0, profile_name);
+			if (status) {
+				snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+				return;
+			}
+		}
 
-	if (strcmp(tokens[9], "profile")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
 		return;
 	}
 
-	profile_name = tokens[10];
-
-	for ( ; idx0 <= idx1; idx0++) {
+	/* table. */
+	if (!strcmp(tokens[7], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
 		int status;
 
-		status = rte_swx_ctl_meter_set(p, name, idx0, profile_name);
+		if (n_tokens < 11) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
+
+		table_name = tokens[8];
+
+		if (strcmp(tokens[9], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
+
+		entry = parse_table_entry(ctl, table_name, &tokens[9], n_tokens - 9);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
+
+		status = rte_swx_ctl_meter_set_with_key(p,
+							name,
+							table_name,
+							entry->key,
+							profile_name);
+		table_entry_free(entry);
 		if (status) {
-			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
+			snprintf(out, out_size, "Command failed.\n");
 			return;
 		}
+
+		return;
 	}
+
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[7]);
+	return;
 }
 
 static const char cmd_pipeline_meter_stats_help[] =
-"pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
-	"stats\n";
+"pipeline <pipeline_name> meter <meter_array_name> stats\n"
+	"index from <index0> to <index1>\n"
+	" | table <table_name> match <field0> ...\n";
 
 static void
 cmd_pipeline_meter_stats(char **tokens,
@@ -2262,16 +2373,18 @@ cmd_pipeline_meter_stats(char **tokens,
 {
 	struct rte_swx_ctl_meter_stats stats;
 	struct rte_swx_pipeline *p;
-	const char *name;
-	uint32_t idx0 = 0, idx1 = 0;
+	struct rte_swx_ctl_pipeline *ctl;
+	const char *pipeline_name, *name;
 
-	if (n_tokens != 9) {
+	if (n_tokens < 6) {
 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
 		return;
 	}
 
-	p = rte_swx_pipeline_find(tokens[1]);
-	if (!p) {
+	pipeline_name = tokens[1];
+	p = rte_swx_pipeline_find(pipeline_name);
+	ctl = rte_swx_ctl_pipeline_find(pipeline_name);
+	if (!p || !ctl) {
 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
 		return;
 	}
@@ -2283,68 +2396,151 @@ cmd_pipeline_meter_stats(char **tokens,
 
 	name = tokens[3];
 
-	if (strcmp(tokens[4], "from")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+	if (strcmp(tokens[4], "stats")) {
+		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
 		return;
 	}
 
-	if (parser_read_uint32(&idx0, tokens[5])) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
-		return;
-	}
+	/* index. */
+	if (!strcmp(tokens[5], "index")) {
+		uint32_t idx0 = 0, idx1 = 0;
 
-	if (strcmp(tokens[6], "to")) {
-		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
-		return;
-	}
+		if (n_tokens != 10) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
 
-	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
-		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
-		return;
-	}
+		if (strcmp(tokens[6], "from")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
+			return;
+		}
+
+		if (parser_read_uint32(&idx0, tokens[7])) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index0");
+			return;
+		}
+
+		if (strcmp(tokens[8], "to")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
+			return;
+		}
+
+		if (parser_read_uint32(&idx1, tokens[9]) || (idx1 < idx0)) {
+			snprintf(out, out_size, MSG_ARG_INVALID, "index1");
+			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, name, idx0, &stats);
+			if (status) {
+				snprintf(out, out_size, "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);
+		}
 
-	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);
+	/* table. */
+	if (!strcmp(tokens[5], "table")) {
+		struct rte_swx_table_entry *entry;
+		char *table_name;
+		int status;
 
-	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);
+		if (n_tokens < 9) {
+			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+			return;
+		}
 
-	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
-		 "-------",
-		 "----------------", "----------------", "----------------",
-		 "----------------", "----------------", "----------------");
-	out_size -= strlen(out);
-	out += strlen(out);
+		table_name = tokens[6];
 
-	/* Table rows. */
-	for ( ; idx0 <= idx1; idx0++) {
-		int status;
+		if (strcmp(tokens[7], "match")) {
+			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
+			return;
+		}
 
-		status = rte_swx_ctl_meter_stats_read(p, name, idx0, &stats);
+		entry = parse_table_entry(ctl, table_name, &tokens[7], n_tokens - 7);
+		if (!entry) {
+			snprintf(out, out_size, "Invalid match tokens.\n");
+			return;
+		}
+
+		status = rte_swx_ctl_meter_stats_read_with_key(p,
+							name,
+							table_name,
+							entry->key,
+							&stats);
+		table_entry_free(entry);
 		if (status) {
-			snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0);
-			out_size -= strlen(out);
-			out += strlen(out);
+			snprintf(out, out_size, "Command failed.\n");
 			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 row. */
 		snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64
 			 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n",
-			 idx0,
+			 0,
 			 stats.n_pkts[RTE_COLOR_GREEN],
 			 stats.n_pkts[RTE_COLOR_YELLOW],
 			 stats.n_pkts[RTE_COLOR_RED],
@@ -2353,7 +2549,13 @@ cmd_pipeline_meter_stats(char **tokens,
 			 stats.n_bytes[RTE_COLOR_RED]);
 		out_size -= strlen(out);
 		out += strlen(out);
+
+		return;
 	}
+
+	/* anything else. */
+	snprintf(out, out_size, "Invalid token %s\n.", tokens[5]);
+	return;
 }
 
 static const char cmd_pipeline_stats_help[] =
@@ -3228,23 +3430,17 @@ cli_process(char *in, char *out, size_t out_size, void *obj)
 			return;
 		}
 
-		if ((n_tokens >= 9) &&
-			(strcmp(tokens[2], "meter") == 0) &&
-			(strcmp(tokens[8], "reset") == 0)) {
+		if (n_tokens >= 9 && !strcmp(tokens[2], "meter") && !strcmp(tokens[4], "reset")) {
 			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)) {
+		if (n_tokens >= 9 && !strcmp(tokens[2], "meter") && !strcmp(tokens[4], "set")) {
 			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)) {
+		if (n_tokens >= 9 && !strcmp(tokens[2], "meter") && !strcmp(tokens[4], "stats")) {
 			cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj);
 			return;
 		}
diff --git a/examples/pipeline/examples/meter.cli b/examples/pipeline/examples/meter.cli
index c1b88c882a..21582554b9 100644
--- a/examples/pipeline/examples/meter.cli
+++ b/examples/pipeline/examples/meter.cli
@@ -35,7 +35,7 @@ pipeline PIPELINE0 build lib /tmp/meter.so io ./examples/pipeline/examples/ethde
 ; The table entries can later be updated at run-time through the CLI commands.
 ;
 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
+pipeline PIPELINE0 meter meters set profile platinum index from 0 to 15
 
 ;
 ; Pipelines-to-threads mapping.
-- 
2.34.1


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH V3 2/7] table: add entry ID for learner tables
  2022-08-30 18:58   ` [PATCH V3 2/7] table: add entry ID for learner tables Cristian Dumitrescu
@ 2022-09-24  8:25     ` Thomas Monjalon
  2022-09-26  9:19       ` Dumitrescu, Cristian
  0 siblings, 1 reply; 28+ messages in thread
From: Thomas Monjalon @ 2022-09-24  8:25 UTC (permalink / raw)
  To: Cristian Dumitrescu; +Cc: dev

30/08/2022 20:58, Cristian Dumitrescu:
> @@ -202,6 +213,7 @@ rte_swx_table_learner_lookup(void *table,
>  			     uint8_t **key,
>  			     uint64_t *action_id,
>  			     uint8_t **action_data,
> +			     size_t *entry_id,

size_t is not automatically included (I think since a recent commit),
so I have to add this:

--- a/lib/table/rte_swx_table_learner.h
+++ b/lib/table/rte_swx_table_learner.h
@@ -47,6 +47,7 @@ extern "C" {
  */
 
 #include <stdint.h>
+#include <sys/types.h>
 
 #include <rte_compat.h>




^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH V3 0/7] pipeline: support direct registers and meters
  2022-08-30 18:58 ` [PATCH V3 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
                     ` (6 preceding siblings ...)
  2022-08-30 18:58   ` [PATCH V3 7/7] examples/pipeline: add CLI commands for direct meters Cristian Dumitrescu
@ 2022-09-24  9:34   ` Thomas Monjalon
  7 siblings, 0 replies; 28+ messages in thread
From: Thomas Monjalon @ 2022-09-24  9:34 UTC (permalink / raw)
  To: Cristian Dumitrescu; +Cc: dev

30/08/2022 20:58, Cristian Dumitrescu:
> This patch introduces support for direct registers and meters. The
> difference between indirect (indexed) and direct registers and meters
> is explained below [1][2][3].
> 
> 1. Indirect (indexed) registers and meters.
> 
> The index into an array of registers or meters used on the data path
> is typically read from the action data identified by a table lookup
> operation.
> 
> This means that the control plane manages the mapping of the mapping
> of array entries to table entries and sets up this index explicitly
> into the table entry action data.
> 
> These are called indirect or indexed registers and meters, and they
> allow multiple table entries to share the same register/meter, as well
> as a 1:1 mapping of table entries to register/meter array entries.
> 
> 2. Direct registers and meters.
> In the case of 1:1 mapping of table entries to register/meter array
> elements, it is sometimes desired to avoid the explicit allocation of
> register/meter array index to each table entry by the control plane.
> 
> One way this can be done is by implementing a mechanism to associate
> a unique ID to each table entry, including the default table entry as
> well; once the entry ID is retrieved as result of the table lookup
> operation, it is saved by the pipeline and used later on as the
> index into the register/meter array.
> 
> These are called direct registers and meters, and have the advantage
> that the index is auto-generated, which simplifies the controller
> implementation; the disadvantage is that they do not allow multiple
> table entries to share the same register or meter.
> 
> References:
> 
> [1] Indirect and direct counters:
> https://p4.org/p4-spec/docs/PSA.html#sec-counters
> 
> [2] Indirect and direct registers:
> https://p4.org/p4-spec/docs/PSA.html#sec-registers
> 
> [3] Indirect and direct meters:
> https://p4.org/p4-spec/docs/PSA.html#sec-meters
> 
> Depends-on: series-24366 ("pipeline: make the hash function configurable per table")
> 
> Change log:
> 
> V3:
> -Fixed issues related to CLI parsing
> -Fixed issue related to the key offset
> 
> V2:
> -Fixed minor style issues flagged by CI/CD
> 
> Cristian Dumitrescu (7):
>   table: add entry ID for regular tables
>   table: add entry ID for learner tables
>   pipeline: add table entry ID read instruction
>   pipeline: support direct registers on the control path
>   pipeline: support direct meters on the control path
>   examples/pipeline: add CLI commands for direct registers
>   examples/pipeline: add CLI commands for direct meters

Applied, thanks.




^ permalink raw reply	[flat|nested] 28+ messages in thread

* RE: [PATCH V3 2/7] table: add entry ID for learner tables
  2022-09-24  8:25     ` Thomas Monjalon
@ 2022-09-26  9:19       ` Dumitrescu, Cristian
  2022-09-26 13:45         ` Thomas Monjalon
  0 siblings, 1 reply; 28+ messages in thread
From: Dumitrescu, Cristian @ 2022-09-26  9:19 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev



> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Saturday, September 24, 2022 9:25 AM
> To: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>
> Cc: dev@dpdk.org
> Subject: Re: [PATCH V3 2/7] table: add entry ID for learner tables
> 
> 30/08/2022 20:58, Cristian Dumitrescu:
> > @@ -202,6 +213,7 @@ rte_swx_table_learner_lookup(void *table,
> >  			     uint8_t **key,
> >  			     uint64_t *action_id,
> >  			     uint8_t **action_data,
> > +			     size_t *entry_id,
> 
> size_t is not automatically included (I think since a recent commit),
> so I have to add this:
> 
> --- a/lib/table/rte_swx_table_learner.h
> +++ b/lib/table/rte_swx_table_learner.h
> @@ -47,6 +47,7 @@ extern "C" {
>   */
> 
>  #include <stdint.h>
> +#include <sys/types.h>
> 
>  #include <rte_compat.h>
> 
> 

Thanks, Thomas!

Is there a package that I need to update? I am mostly using gcc 11.2.0.

Regards,
Cristian

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH V3 2/7] table: add entry ID for learner tables
  2022-09-26  9:19       ` Dumitrescu, Cristian
@ 2022-09-26 13:45         ` Thomas Monjalon
  0 siblings, 0 replies; 28+ messages in thread
From: Thomas Monjalon @ 2022-09-26 13:45 UTC (permalink / raw)
  To: Dumitrescu, Cristian; +Cc: dev

26/09/2022 11:19, Dumitrescu, Cristian:
> 
> > -----Original Message-----
> > From: Thomas Monjalon <thomas@monjalon.net>
> > Sent: Saturday, September 24, 2022 9:25 AM
> > To: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>
> > Cc: dev@dpdk.org
> > Subject: Re: [PATCH V3 2/7] table: add entry ID for learner tables
> > 
> > 30/08/2022 20:58, Cristian Dumitrescu:
> > > @@ -202,6 +213,7 @@ rte_swx_table_learner_lookup(void *table,
> > >  			     uint8_t **key,
> > >  			     uint64_t *action_id,
> > >  			     uint8_t **action_data,
> > > +			     size_t *entry_id,
> > 
> > size_t is not automatically included (I think since a recent commit),
> > so I have to add this:
> > 
> > --- a/lib/table/rte_swx_table_learner.h
> > +++ b/lib/table/rte_swx_table_learner.h
> > @@ -47,6 +47,7 @@ extern "C" {
> >   */
> > 
> >  #include <stdint.h>
> > +#include <sys/types.h>
> > 
> >  #include <rte_compat.h>
> > 
> > 
> 
> Thanks, Thomas!
> 
> Is there a package that I need to update? I am mostly using gcc 11.2.0.

No update required, that's just required by a recent commit merged after you sent your patches. Business as usual :)





^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2022-09-26 13:45 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26 10:35 [PATCH 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
2022-08-26 10:35 ` [PATCH 1/7] table: add entry ID for regular tables Cristian Dumitrescu
2022-08-26 10:36 ` [PATCH 2/7] table: add entry ID for learner tables Cristian Dumitrescu
2022-08-26 10:36 ` [PATCH 3/7] pipeline: add table entry ID read instruction Cristian Dumitrescu
2022-08-26 10:36 ` [PATCH 4/7] pipeline: support direct registers on the control path Cristian Dumitrescu
2022-08-26 10:36 ` [PATCH 5/7] pipeline: support direct meters " Cristian Dumitrescu
2022-08-26 10:36 ` [PATCH 6/7] examples/pipeline: add CLI commands for direct registers Cristian Dumitrescu
2022-08-26 10:36 ` [PATCH 7/7] examples/pipeline: add CLI commands for direct meters Cristian Dumitrescu
2022-08-26 11:21 ` [PATCH V2 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
2022-08-26 11:21   ` [PATCH V2 1/7] table: add entry ID for regular tables Cristian Dumitrescu
2022-08-26 11:21   ` [PATCH V2 2/7] table: add entry ID for learner tables Cristian Dumitrescu
2022-08-26 11:21   ` [PATCH V2 3/7] pipeline: add table entry ID read instruction Cristian Dumitrescu
2022-08-26 11:21   ` [PATCH V2 4/7] pipeline: support direct registers on the control path Cristian Dumitrescu
2022-08-26 11:21   ` [PATCH V2 5/7] pipeline: support direct meters " Cristian Dumitrescu
2022-08-26 11:21   ` [PATCH V2 6/7] examples/pipeline: add CLI commands for direct registers Cristian Dumitrescu
2022-08-26 11:21   ` [PATCH V2 7/7] examples/pipeline: add CLI commands for direct meters Cristian Dumitrescu
2022-08-30 18:58 ` [PATCH V3 0/7] pipeline: support direct registers and meters Cristian Dumitrescu
2022-08-30 18:58   ` [PATCH V3 1/7] table: add entry ID for regular tables Cristian Dumitrescu
2022-08-30 18:58   ` [PATCH V3 2/7] table: add entry ID for learner tables Cristian Dumitrescu
2022-09-24  8:25     ` Thomas Monjalon
2022-09-26  9:19       ` Dumitrescu, Cristian
2022-09-26 13:45         ` Thomas Monjalon
2022-08-30 18:58   ` [PATCH V3 3/7] pipeline: add table entry ID read instruction Cristian Dumitrescu
2022-08-30 18:58   ` [PATCH V3 4/7] pipeline: support direct registers on the control path Cristian Dumitrescu
2022-08-30 18:58   ` [PATCH V3 5/7] pipeline: support direct meters " Cristian Dumitrescu
2022-08-30 18:58   ` [PATCH V3 6/7] examples/pipeline: add CLI commands for direct registers Cristian Dumitrescu
2022-08-30 18:58   ` [PATCH V3 7/7] examples/pipeline: add CLI commands for direct meters Cristian Dumitrescu
2022-09-24  9:34   ` [PATCH V3 0/7] pipeline: support direct registers and meters Thomas Monjalon

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).