Skip to contentSkip to conversation

ethdev: datapath-focused flow rules management

RFC In review Alexander Kozyrev 12 participants 218 messages Oct 6, 2021 – Feb 24, 2022 Page 2 of 4

lore
Share & tools
lore
Acked-by on v3 9/10
#76 lore raw

RE: [PATCH v3 09/10] app/testpmd: implement rte flow pull operations

In reply to Alexander Kozyrev

Hi Alexander,

Quoted 11 lines

-----Original Message-----
From: Alexander Kozyrev <[email protected]>
Sent: Sunday, February 6, 2022 5:25 AM
Subject: [PATCH v3 09/10] app/testpmd: implement rte flow pull operations

Add testpmd support for the rte_flow_q_pull API. Provide the command line interface for pulling operations results. Usage example: flow pull 0 queue 0

---

Best,
Ori

#77 lore raw

PATCH v3 10/10 app/testpmd: implement rte flow queue indirect actions

In reply to Alexander Kozyrev

Add testpmd support for the rte_flow_q_action_handle API. Provide the command line interface for operations dequeue. Usage example:
flow queue 0 indirect_action 0 create action_id 9
ingress postpone yes action rss / end
flow queue 0 indirect_action 0 update action_id 9
action queue index 0 / end
flow queue 0 indirect_action 0 destroy action_id 9

---
 app/test-pmd/cmdline_flow.c                 | 276 ++++++++++++++++++++
 app/test-pmd/config.c                       | 131 ++++++++++
 app/test-pmd/testpmd.h                      |  10 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  65 +++++
 4 files changed, 482 insertions(+)
app/test-pmd/cmdline_flow.c +276 -0
index 35eb2a0997..1eea36d8d0 100644
@@ -121,6 +121,7 @@ enum index {
 	/* Queue arguments. */
 	QUEUE_CREATE,
 	QUEUE_DESTROY,
+	QUEUE_INDIRECT_ACTION,
 
 	/* Queue create arguments. */
 	QUEUE_CREATE_ID,
@@ -134,6 +135,26 @@ enum index {
 	QUEUE_DESTROY_ID,
 	QUEUE_DESTROY_POSTPONE,
 
+	/* Queue indirect action arguments */
+	QUEUE_INDIRECT_ACTION_CREATE,
+	QUEUE_INDIRECT_ACTION_UPDATE,
+	QUEUE_INDIRECT_ACTION_DESTROY,
+
+	/* Queue indirect action create arguments */
+	QUEUE_INDIRECT_ACTION_CREATE_ID,
+	QUEUE_INDIRECT_ACTION_INGRESS,
+	QUEUE_INDIRECT_ACTION_EGRESS,
+	QUEUE_INDIRECT_ACTION_TRANSFER,
+	QUEUE_INDIRECT_ACTION_CREATE_POSTPONE,
+	QUEUE_INDIRECT_ACTION_SPEC,
+
+	/* Queue indirect action update arguments */
+	QUEUE_INDIRECT_ACTION_UPDATE_POSTPONE,
+
+	/* Queue indirect action destroy arguments */
+	QUEUE_INDIRECT_ACTION_DESTROY_ID,
+	QUEUE_INDIRECT_ACTION_DESTROY_POSTPONE,
+
 	/* Push arguments. */
 	PUSH_QUEUE,
 
@@ -1101,6 +1122,7 @@ static const enum index next_table_destroy_attr[] = {
 static const enum index next_queue_subcmd[] = {
 	QUEUE_CREATE,
 	QUEUE_DESTROY,
+	QUEUE_INDIRECT_ACTION,
 	ZERO,
 };
 
@@ -1110,6 +1132,36 @@ static const enum index next_queue_destroy_attr[] = {
 	ZERO,
 };
 
+static const enum index next_qia_subcmd[] = {
+	QUEUE_INDIRECT_ACTION_CREATE,
+	QUEUE_INDIRECT_ACTION_UPDATE,
+	QUEUE_INDIRECT_ACTION_DESTROY,
+	ZERO,
+};
+
+static const enum index next_qia_create_attr[] = {
+	QUEUE_INDIRECT_ACTION_CREATE_ID,
+	QUEUE_INDIRECT_ACTION_INGRESS,
+	QUEUE_INDIRECT_ACTION_EGRESS,
+	QUEUE_INDIRECT_ACTION_TRANSFER,
+	QUEUE_INDIRECT_ACTION_CREATE_POSTPONE,
+	QUEUE_INDIRECT_ACTION_SPEC,
+	ZERO,
+};
+
+static const enum index next_qia_update_attr[] = {
+	QUEUE_INDIRECT_ACTION_UPDATE_POSTPONE,
+	QUEUE_INDIRECT_ACTION_SPEC,
+	ZERO,
+};
+
+static const enum index next_qia_destroy_attr[] = {
+	QUEUE_INDIRECT_ACTION_DESTROY_POSTPONE,
+	QUEUE_INDIRECT_ACTION_DESTROY_ID,
+	END,
+	ZERO,
+};
+
 static const enum index next_ia_create_attr[] = {
 	INDIRECT_ACTION_CREATE_ID,
 	INDIRECT_ACTION_INGRESS,
@@ -2165,6 +2217,12 @@ static int parse_qo(struct context *, const struct token *,
 static int parse_qo_destroy(struct context *, const struct token *,
 			    const char *, unsigned int,
 			    void *, unsigned int);
+static int parse_qia(struct context *, const struct token *,
+		     const char *, unsigned int,
+		     void *, unsigned int);
+static int parse_qia_destroy(struct context *, const struct token *,
+			     const char *, unsigned int,
+			     void *, unsigned int);
 static int parse_push(struct context *, const struct token *,
 		      const char *, unsigned int,
 		      void *, unsigned int);
@@ -2741,6 +2799,13 @@ static const struct token token_list[] = {
 		.args = ARGS(ARGS_ENTRY(struct buffer, queue)),
 		.call = parse_qo_destroy,
 	},
+	[QUEUE_INDIRECT_ACTION] = {
+		.name = "indirect_action",
+		.help = "queue indirect actions",
+		.next = NEXT(next_qia_subcmd, NEXT_ENTRY(COMMON_QUEUE_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, queue)),
+		.call = parse_qia,
+	},
 	/* Queue  arguments. */
 	[QUEUE_TABLE] = {
 		.name = "table",
@@ -2794,6 +2859,90 @@ static const struct token token_list[] = {
 					    args.destroy.rule)),
 		.call = parse_qo_destroy,
 	},
+	/* Queue indirect action arguments */
+	[QUEUE_INDIRECT_ACTION_CREATE] = {
+		.name = "create",
+		.help = "create indirect action",
+		.next = NEXT(next_qia_create_attr),
+		.call = parse_qia,
+	},
+	[QUEUE_INDIRECT_ACTION_UPDATE] = {
+		.name = "update",
+		.help = "update indirect action",
+		.next = NEXT(next_qia_update_attr,
+			     NEXT_ENTRY(COMMON_INDIRECT_ACTION_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, args.vc.attr.group)),
+		.call = parse_qia,
+	},
+	[QUEUE_INDIRECT_ACTION_DESTROY] = {
+		.name = "destroy",
+		.help = "destroy indirect action",
+		.next = NEXT(next_qia_destroy_attr),
+		.call = parse_qia_destroy,
+	},
+	/* Indirect action destroy arguments. */
+	[QUEUE_INDIRECT_ACTION_DESTROY_POSTPONE] = {
+		.name = "postpone",
+		.help = "postpone destroy operation",
+		.next = NEXT(next_qia_destroy_attr,
+			     NEXT_ENTRY(COMMON_BOOLEAN)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, postpone)),
+	},
+	[QUEUE_INDIRECT_ACTION_DESTROY_ID] = {
+		.name = "action_id",
+		.help = "specify a indirect action id to destroy",
+		.next = NEXT(next_qia_destroy_attr,
+			     NEXT_ENTRY(COMMON_INDIRECT_ACTION_ID)),
+		.args = ARGS(ARGS_ENTRY_PTR(struct buffer,
+					    args.ia_destroy.action_id)),
+		.call = parse_qia_destroy,
+	},
+	/* Indirect action update arguments. */
+	[QUEUE_INDIRECT_ACTION_UPDATE_POSTPONE] = {
+		.name = "postpone",
+		.help = "postpone update operation",
+		.next = NEXT(next_qia_update_attr,
+			     NEXT_ENTRY(COMMON_BOOLEAN)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, postpone)),
+	},
+	/* Indirect action create arguments. */
+	[QUEUE_INDIRECT_ACTION_CREATE_ID] = {
+		.name = "action_id",
+		.help = "specify a indirect action id to create",
+		.next = NEXT(next_qia_create_attr,
+			     NEXT_ENTRY(COMMON_INDIRECT_ACTION_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, args.vc.attr.group)),
+	},
+	[QUEUE_INDIRECT_ACTION_INGRESS] = {
+		.name = "ingress",
+		.help = "affect rule to ingress",
+		.next = NEXT(next_qia_create_attr),
+		.call = parse_qia,
+	},
+	[QUEUE_INDIRECT_ACTION_EGRESS] = {
+		.name = "egress",
+		.help = "affect rule to egress",
+		.next = NEXT(next_qia_create_attr),
+		.call = parse_qia,
+	},
+	[QUEUE_INDIRECT_ACTION_TRANSFER] = {
+		.name = "transfer",
+		.help = "affect rule to transfer",
+		.next = NEXT(next_qia_create_attr),
+		.call = parse_qia,
+	},
+	[QUEUE_INDIRECT_ACTION_CREATE_POSTPONE] = {
+		.name = "postpone",
+		.help = "postpone create operation",
+		.next = NEXT(next_qia_create_attr,
+			     NEXT_ENTRY(COMMON_BOOLEAN)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, postpone)),
+	},
+	[QUEUE_INDIRECT_ACTION_SPEC] = {
+		.name = "action",
+		.help = "specify action to create indirect handle",
+		.next = NEXT(next_action),
+	},
 	/* Top-level command. */
 	[PUSH] = {
 		.name = "push",
@@ -6193,6 +6342,110 @@ parse_ia_destroy(struct context *ctx, const struct token *token,
 	return len;
 }
 
+/** Parse tokens for indirect action commands. */
+static int
+parse_qia(struct context *ctx, const struct token *token,
+	  const char *str, unsigned int len,
+	  void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != QUEUE)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->args.vc.data = (uint8_t *)out + size;
+		return len;
+	}
+	switch (ctx->curr) {
+	case QUEUE_INDIRECT_ACTION:
+		return len;
+	case QUEUE_INDIRECT_ACTION_CREATE:
+	case QUEUE_INDIRECT_ACTION_UPDATE:
+		out->args.vc.actions =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		out->args.vc.attr.group = UINT32_MAX;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		return len;
+	case QUEUE_INDIRECT_ACTION_EGRESS:
+		out->args.vc.attr.egress = 1;
+		return len;
+	case QUEUE_INDIRECT_ACTION_INGRESS:
+		out->args.vc.attr.ingress = 1;
+		return len;
+	case QUEUE_INDIRECT_ACTION_TRANSFER:
+		out->args.vc.attr.transfer = 1;
+		return len;
+	case QUEUE_INDIRECT_ACTION_CREATE_POSTPONE:
+		return len;
+	default:
+		return -1;
+	}
+}
+
+/** Parse tokens for indirect action destroy command. */
+static int
+parse_qia_destroy(struct context *ctx, const struct token *token,
+		  const char *str, unsigned int len,
+		  void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+	uint32_t *action_id;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command || out->command == QUEUE) {
+		if (ctx->curr != QUEUE_INDIRECT_ACTION_DESTROY)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.ia_destroy.action_id =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		return len;
+	}
+	switch (ctx->curr) {
+	case QUEUE_INDIRECT_ACTION:
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		return len;
+	case QUEUE_INDIRECT_ACTION_DESTROY_ID:
+		action_id = out->args.ia_destroy.action_id
+				+ out->args.ia_destroy.action_id_n++;
+		if ((uint8_t *)action_id > (uint8_t *)out + size)
+			return -1;
+		ctx->objdata = 0;
+		ctx->object = action_id;
+		ctx->objmask = NULL;
+		return len;
+	case QUEUE_INDIRECT_ACTION_DESTROY_POSTPONE:
+		return len;
+	default:
+		return -1;
+	}
+}
+
 /** Parse tokens for meter policy action commands. */
 static int
 parse_mp(struct context *ctx, const struct token *token,
@@ -9876,6 +10129,29 @@ cmd_flow_parsed(const struct buffer *in)
 	case PULL:
 		port_queue_flow_pull(in->port, in->queue);
 		break;
+	case QUEUE_INDIRECT_ACTION_CREATE:
+		port_queue_action_handle_create(
+				in->port, in->queue, in->postpone,
+				in->args.vc.attr.group,
+				&((const struct rte_flow_indir_action_conf) {
+					.ingress = in->args.vc.attr.ingress,
+					.egress = in->args.vc.attr.egress,
+					.transfer = in->args.vc.attr.transfer,
+				}),
+				in->args.vc.actions);
+		break;
+	case QUEUE_INDIRECT_ACTION_DESTROY:
+		port_queue_action_handle_destroy(in->port,
+					   in->queue, in->postpone,
+					   in->args.ia_destroy.action_id_n,
+					   in->args.ia_destroy.action_id);
+		break;
+	case QUEUE_INDIRECT_ACTION_UPDATE:
+		port_queue_action_handle_update(in->port,
+						in->queue, in->postpone,
+						in->args.vc.attr.group,
+						in->args.vc.actions);
+		break;
 	case INDIRECT_ACTION_CREATE:
 		port_action_handle_create(
 				in->port, in->args.vc.attr.group,
app/test-pmd/config.c +131 -0

137 lines not on this page · raw message

app/test-pmd/testpmd.h +10 -0
index 8526db6766..3da5201014 100644
@@ -939,6 +939,16 @@ int port_queue_flow_create(portid_t port_id, queueid_t queue_id,
 			   const struct rte_flow_action *actions);
 int port_queue_flow_destroy(portid_t port_id, queueid_t queue_id,
 			    bool postpone, uint32_t n, const uint32_t *rule);
+int port_queue_action_handle_create(portid_t port_id, uint32_t queue_id,
+			bool postpone, uint32_t id,
+			const struct rte_flow_indir_action_conf *conf,
+			const struct rte_flow_action *action);
+int port_queue_action_handle_destroy(portid_t port_id,
+				     uint32_t queue_id, bool postpone,
+				     uint32_t n, const uint32_t *action);
+int port_queue_action_handle_update(portid_t port_id, uint32_t queue_id,
+				    bool postpone, uint32_t id,
+				    const struct rte_flow_action *action);
 int port_queue_flow_push(portid_t port_id, queueid_t queue_id);
 int port_queue_flow_pull(portid_t port_id, queueid_t queue_id);
 int port_flow_validate(portid_t port_id,
doc/guides/testpmd_app_ug/testpmd_funcs.rst +65 -0

83 lines not on this page · raw message

Signature · 1 line
2.18.2
Acked-by on v3 10/10
#78 lore raw

RE: [PATCH v3 10/10] app/testpmd: implement rte flow queue indirect actions

Hi Alex,

Quoted 14 lines

-----Original Message-----
From: Alexander Kozyrev <[email protected]>
Sent: Sunday, February 6, 2022 5:25 AM
Subject: [PATCH v3 10/10] app/testpmd: implement rte flow queue indirect actions

Add testpmd support for the rte_flow_q_action_handle API. Provide the command line interface for operations dequeue. Usage example:
flow queue 0 indirect_action 0 create action_id 9
ingress postpone yes action rss / end
flow queue 0 indirect_action 0 update action_id 9
action queue index 0 / end
flow queue 0 indirect_action 0 destroy action_id 9

Quoted 2 lines

---

Best,
Ori

#79 lore raw

v4 cover ethdev: datapath-focused flow rules management

In reply to Alexander Kozyrev

Three major changes to a generic RTE Flow API were implemented in order to speed up flow rule insertion/destruction and adapt the API to the needs of a datapath-focused flow rules management applications:

1. Pre-configuration hints.
Application may give us some hints on what type of resources are needed. Introduce the configuration routine to prepare all the needed resources inside a PMD/HW before any flow rules are created at the init stage.

2. Flow grouping using templates.
Use the knowledge about which flow rules are to be used in an application and prepare item and action templates for them in advance. Group flow rules with common patterns and actions together for better resource management.

3. Queue-based flow management.
Perform flow rule insertion/destruction asynchronously to spare the datapath from blocking on RTE Flow API and allow it to continue with packet processing. Enqueue flow rules operations and poll for the results later.

testpmd examples are part of the patch series. PMD changes will follow.

RFC: https://patchwork.dpdk.org/project/dpdk/cover/[email protected]/

---
v4:
- removed structures versioning
- introduced new rte_flow_port_info structure for rte_flow_info_get API
- renamed rte_flow_table_create to rte_flow_template_table_create

v3: addressed review comments and updated documentation
- added API to get info about pre-configurable resources
- renamed rte_flow_item_template to rte_flow_pattern_template
- renamed drain operation attribute to postpone
- renamed rte_flow_q_drain to rte_flow_q_push
- renamed rte_flow_q_dequeue to rte_flow_q_pull

v2: fixed patch series thread

Alexander Kozyrev (10):
ethdev: introduce flow pre-configuration hints
ethdev: add flow item/action templates
ethdev: bring in async queue-based flow rules operations app/testpmd: implement rte flow configuration app/testpmd: implement rte flow template management app/testpmd: implement rte flow table management app/testpmd: implement rte flow queue flow operations app/testpmd: implement rte flow push operations app/testpmd: implement rte flow pull operations app/testpmd: implement rte flow queue indirect actions

 app/test-pmd/cmdline_flow.c                   | 1496 ++++++++++++++++-
 app/test-pmd/config.c                         |  771 +++++++++
 app/test-pmd/testpmd.h                        |   66 +
 doc/guides/prog_guide/img/rte_flow_q_init.svg |  205 +++
 .../prog_guide/img/rte_flow_q_usage.svg       |  351 ++++
 doc/guides/prog_guide/rte_flow.rst            |  326 ++++
 doc/guides/rel_notes/release_22_03.rst        |   22 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst   |  378 ++++-
 lib/ethdev/rte_flow.c                         |  359 ++++
 lib/ethdev/rte_flow.h                         |  702 ++++++++
 lib/ethdev/rte_flow_driver.h                  |  102 ++
 lib/ethdev/version.map                        |   15 +
 12 files changed, 4773 insertions(+), 20 deletions(-)
 create mode 100644 doc/guides/prog_guide/img/rte_flow_q_init.svg
 create mode 100644 doc/guides/prog_guide/img/rte_flow_q_usage.svg
Signature · 1 line
2.18.2
#80 lore raw

PATCH v4 1/10 ethdev: introduce flow pre-configuration hints

The flow rules creation/destruction at a large scale incurs a performance penalty and may negatively impact the packet processing when used as part of the datapath logic. This is mainly because software/hardware resources are allocated and prepared during the flow rule creation.

In order to optimize the insertion rate, PMD may use some hints provided by the application at the initialization phase. The rte_flow_configure() function allows to pre-allocate all the needed resources beforehand. These resources can be used at a later stage without costly allocations. Every PMD may use only the subset of hints and ignore unused ones or fail in case the requested configuration is not supported.

The rte_flow_info_get() is available to retrieve the information about supported pre-configurable resources. Both these functions must be called before any other usage of the flow API engine.

---
 doc/guides/prog_guide/rte_flow.rst     |  37 +++++++++
 doc/guides/rel_notes/release_22_03.rst |   6 ++
 lib/ethdev/rte_flow.c                  |  40 +++++++++
 lib/ethdev/rte_flow.h                  | 108 +++++++++++++++++++++++++
 lib/ethdev/rte_flow_driver.h           |  10 +++
 lib/ethdev/version.map                 |   2 +
 6 files changed, 203 insertions(+)
doc/guides/prog_guide/rte_flow.rst +37 -0
index b4aa9c47c2..72fb1132ac 100644
@@ -3589,6 +3589,43 @@ Return values:
 
 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
 
+Flow engine configuration
+-------------------------
+
+Configure flow API management.
+
+An application may provide some parameters at the initialization phase about
+rules engine configuration and/or expected flow rules characteristics.
+These parameters may be used by PMD to preallocate resources and configure NIC.
+
+Configuration
+~~~~~~~~~~~~~
+
+This function performs the flow API management configuration and
+pre-allocates needed resources beforehand to avoid costly allocations later.
+Expected number of counters or meters in an application, for example,
+allow PMD to prepare and optimize NIC memory layout in advance.
+``rte_flow_configure()`` must be called before any flow rule is created,
+but after an Ethernet device is configured.
+
+.. code-block:: c
+
+   int
+   rte_flow_configure(uint16_t port_id,
+                     const struct rte_flow_port_attr *port_attr,
+                     struct rte_flow_error *error);
+
+Information about resources that can benefit from pre-allocation can be
+retrieved via ``rte_flow_info_get()`` API. It returns the maximum number
+of pre-configurable resources for a given port on a system.
+
+.. code-block:: c
+
+   int
+   rte_flow_info_get(uint16_t port_id,
+                     struct rte_flow_port_info *port_info,
+                     struct rte_flow_error *error);
+
 .. _flow_isolated_mode:
 
 Flow isolated mode
doc/guides/rel_notes/release_22_03.rst +6 -0
index f03183ee86..2a47a37f0a 100644
@@ -69,6 +69,12 @@ New Features
   New APIs, ``rte_eth_dev_priority_flow_ctrl_queue_info_get()`` and
   ``rte_eth_dev_priority_flow_ctrl_queue_configure()``, was added.
 
+* ** Added functions to configure Flow API engine
+
+  * ethdev: Added ``rte_flow_configure`` API to configure Flow Management
+    engine, allowing to pre-allocate some resources for better performance.
+    Added ``rte_flow_info_get`` API to retrieve pre-configurable resources.
+
 * **Updated AF_XDP PMD**
 
   * Added support for libxdp >=v1.2.2.
lib/ethdev/rte_flow.c +40 -0
index a93f68abbc..66614ae29b 100644
@@ -1391,3 +1391,43 @@ rte_flow_flex_item_release(uint16_t port_id,
 	ret = ops->flex_item_release(dev, handle, error);
 	return flow_err(port_id, ret, error);
 }
+
+int
+rte_flow_info_get(uint16_t port_id,
+		  struct rte_flow_port_info *port_info,
+		  struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->info_get)) {
+		return flow_err(port_id,
+				ops->info_get(dev, port_info, error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_configure(uint16_t port_id,
+		   const struct rte_flow_port_attr *port_attr,
+		   struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->configure)) {
+		return flow_err(port_id,
+				ops->configure(dev, port_attr, error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +108 -0

114 lines not on this page · raw message

lib/ethdev/rte_flow_driver.h +10 -0
index f691b04af4..7c29930d0f 100644
@@ -152,6 +152,16 @@ struct rte_flow_ops {
 		(struct rte_eth_dev *dev,
 		 const struct rte_flow_item_flex_handle *handle,
 		 struct rte_flow_error *error);
+	/** See rte_flow_info_get() */
+	int (*info_get)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_port_info *port_info,
+		 struct rte_flow_error *err);
+	/** See rte_flow_configure() */
+	int (*configure)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_port_attr *port_attr,
+		 struct rte_flow_error *err);
 };
 
 /**
lib/ethdev/version.map +2 -0
index cd0c4c428d..f1235aa913 100644
@@ -260,6 +260,8 @@ EXPERIMENTAL {
 	# added in 22.03
 	rte_eth_dev_priority_flow_ctrl_queue_configure;
 	rte_eth_dev_priority_flow_ctrl_queue_info_get;
+	rte_flow_info_get;
+	rte_flow_configure;
 };
 
 INTERNAL {
Signature · 1 line
2.18.2
#81 lore raw

PATCH v4 2/10 ethdev: add flow item/action templates

In reply to Alexander Kozyrev

Treating every single flow rule as a completely independent and separate entity negatively impacts the flow rules insertion rate. Oftentimes in an application, many flow rules share a common structure (the same item mask and/or action list) so they can be grouped and classified together. This knowledge may be used as a source of optimization by a PMD/HW.

The pattern template defines common matching fields (the item mask) without values. The actions template holds a list of action types that will be used together in the same rule. The specific values for items and actions will be given only during the rule creation.

A table combines pattern and actions templates along with shared flow rule attributes (group ID, priority and traffic direction). This way a PMD/HW can prepare all the resources needed for efficient flow rules creation in the datapath. To avoid any hiccups due to memory reallocation, the maximum number of flow rules is defined at the table creation time.

The flow rule creation is done by selecting a table, a pattern template and an actions template (which are bound to the table), and setting unique values for the items and actions.

---
 doc/guides/prog_guide/rte_flow.rst     | 124 ++++++++++++
 doc/guides/rel_notes/release_22_03.rst |   8 +
 lib/ethdev/rte_flow.c                  | 147 ++++++++++++++
 lib/ethdev/rte_flow.h                  | 260 +++++++++++++++++++++++++
 lib/ethdev/rte_flow_driver.h           |  37 ++++
 lib/ethdev/version.map                 |   6 +
 6 files changed, 582 insertions(+)
doc/guides/prog_guide/rte_flow.rst +124 -0
index 72fb1132ac..5391648833 100644
@@ -3626,6 +3626,130 @@ of pre-configurable resources for a given port on a system.
                      struct rte_flow_port_info *port_info,
                      struct rte_flow_error *error);
 
+Flow templates
+~~~~~~~~~~~~~~
+
+Oftentimes in an application, many flow rules share a common structure
+(the same pattern and/or action list) so they can be grouped and classified
+together. This knowledge may be used as a source of optimization by a PMD/HW.
+The flow rule creation is done by selecting a table, a pattern template
+and an actions template (which are bound to the table), and setting unique
+values for the items and actions. This API is not thread-safe.
+
+Pattern templates
+^^^^^^^^^^^^^^^^^
+
+The pattern template defines a common pattern (the item mask) without values.
+The mask value is used to select a field to match on, spec/last are ignored.
+The pattern template may be used by multiple tables and must not be destroyed
+until all these tables are destroyed first.
+
+.. code-block:: c
+
+	struct rte_flow_pattern_template *
+	rte_flow_pattern_template_create(uint16_t port_id,
+				const struct rte_flow_pattern_template_attr *template_attr,
+				const struct rte_flow_item pattern[],
+				struct rte_flow_error *error);
+
+For example, to create a pattern template to match on the destination MAC:
+
+.. code-block:: c
+
+	struct rte_flow_item pattern[2] = {{0}};
+	struct rte_flow_item_eth eth_m = {0};
+	pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
+	eth_m.dst.addr_bytes = "\xff\xff\xff\xff\xff\xff";
+	pattern[0].mask = &eth_m;
+	pattern[1].type = RTE_FLOW_ITEM_TYPE_END;
+
+	struct rte_flow_pattern_template *pattern_template =
+		rte_flow_pattern_template_create(port, &itr, &pattern, &error);
+
+The concrete value to match on will be provided at the rule creation.
+
+Actions templates
+^^^^^^^^^^^^^^^^^
+
+The actions template holds a list of action types to be used in flow rules.
+The mask parameter allows specifying a shared constant value for every rule.
+The actions template may be used by multiple tables and must not be destroyed
+until all these tables are destroyed first.
+
+.. code-block:: c
+
+	struct rte_flow_actions_template *
+	rte_flow_actions_template_create(uint16_t port_id,
+				const struct rte_flow_actions_template_attr *template_attr,
+				const struct rte_flow_action actions[],
+				const struct rte_flow_action masks[],
+				struct rte_flow_error *error);
+
+For example, to create an actions template with the same Mark ID
+but different Queue Index for every rule:
+
+.. code-block:: c
+
+	struct rte_flow_action actions[] = {
+		/* Mark ID is constant (4) for every rule, Queue Index is unique */
+		[0] = {.type = RTE_FLOW_ACTION_TYPE_MARK,
+			   .conf = &(struct rte_flow_action_mark){.id = 4}},
+		[1] = {.type = RTE_FLOW_ACTION_TYPE_QUEUE},
+		[2] = {.type = RTE_FLOW_ACTION_TYPE_END,},
+	};
+	struct rte_flow_action masks[] = {
+		/* Assign to MARK mask any non-zero value to make it constant */
+		[0] = {.type = RTE_FLOW_ACTION_TYPE_MARK,
+			   .conf = &(struct rte_flow_action_mark){.id = 1}},
+		[1] = {.type = RTE_FLOW_ACTION_TYPE_QUEUE},
+		[2] = {.type = RTE_FLOW_ACTION_TYPE_END,},
+	};
+
+	struct rte_flow_actions_template *at =
+		rte_flow_actions_template_create(port, &atr, &actions, &masks, &error);
+
+The concrete value for Queue Index will be provided at the rule creation.
+
+Template table
+^^^^^^^^^^^^^^
+
+A template table combines a number of pattern and actions templates along with
+shared flow rule attributes (group ID, priority and traffic direction).
+This way a PMD/HW can prepare all the resources needed for efficient flow rules
+creation in the datapath. To avoid any hiccups due to memory reallocation,
+the maximum number of flow rules is defined at table creation time.
+Any flow rule creation beyond the maximum table size is rejected.
+Application may create another table to accommodate more rules in this case.
+
+.. code-block:: c
+
+	struct rte_flow_template_table *
+	rte_flow_template_table_create(uint16_t port_id,
+				const struct rte_flow_template_table_attr *table_attr,
+				struct rte_flow_pattern_template *pattern_templates[],
+				uint8_t nb_pattern_templates,
+				struct rte_flow_actions_template *actions_templates[],
+				uint8_t nb_actions_templates,
+				struct rte_flow_error *error);
+
+A table can be created only after the Flow Rules management is configured
+and pattern and actions templates are created.
+
+.. code-block:: c
+
+	rte_flow_configure(port, *port_attr, *error);
+
+	struct rte_flow_pattern_template *pattern_templates[0] =
+		rte_flow_pattern_template_create(port, &itr, &pattern, &error);
+	struct rte_flow_actions_template *actions_templates[0] =
+		rte_flow_actions_template_create(port, &atr, &actions, &masks, &error);
+
+	struct rte_flow_template_table *table =
+		rte_flow_template_table_create(port, *table_attr,
+				*pattern_templates, nb_pattern_templates,
+				*actions_templates, nb_actions_templates,
+				*error);
+
 .. _flow_isolated_mode:
 
 Flow isolated mode
doc/guides/rel_notes/release_22_03.rst +8 -0
index 2a47a37f0a..6656b35295 100644
@@ -75,6 +75,14 @@ New Features
     engine, allowing to pre-allocate some resources for better performance.
     Added ``rte_flow_info_get`` API to retrieve pre-configurable resources.
 
+  * ethdev: Added ``rte_flow_template_table_create`` API to group flow rules
+    with the same flow attributes and common matching patterns and actions
+    defined by ``rte_flow_pattern_template_create`` and
+    ``rte_flow_actions_template_create`` respectively.
+    Corresponding functions to destroy these entities are:
+    ``rte_flow_template_table_destroy``, ``rte_flow_pattern_template_destroy``
+    and ``rte_flow_actions_template_destroy``.
+
 * **Updated AF_XDP PMD**
 
   * Added support for libxdp >=v1.2.2.
lib/ethdev/rte_flow.c +147 -0

150 lines not on this page · raw message

lib/ethdev/rte_flow.h +260 -0

266 lines not on this page · raw message

lib/ethdev/rte_flow_driver.h +37 -0
index 7c29930d0f..2d96db1dc7 100644
@@ -162,6 +162,43 @@ struct rte_flow_ops {
 		(struct rte_eth_dev *dev,
 		 const struct rte_flow_port_attr *port_attr,
 		 struct rte_flow_error *err);
+	/** See rte_flow_pattern_template_create() */
+	struct rte_flow_pattern_template *(*pattern_template_create)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_pattern_template_attr *template_attr,
+		 const struct rte_flow_item pattern[],
+		 struct rte_flow_error *err);
+	/** See rte_flow_pattern_template_destroy() */
+	int (*pattern_template_destroy)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_pattern_template *pattern_template,
+		 struct rte_flow_error *err);
+	/** See rte_flow_actions_template_create() */
+	struct rte_flow_actions_template *(*actions_template_create)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_actions_template_attr *template_attr,
+		 const struct rte_flow_action actions[],
+		 const struct rte_flow_action masks[],
+		 struct rte_flow_error *err);
+	/** See rte_flow_actions_template_destroy() */
+	int (*actions_template_destroy)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_actions_template *actions_template,
+		 struct rte_flow_error *err);
+	/** See rte_flow_template_table_create() */
+	struct rte_flow_template_table *(*template_table_create)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_template_table_attr *table_attr,
+		 struct rte_flow_pattern_template *pattern_templates[],
+		 uint8_t nb_pattern_templates,
+		 struct rte_flow_actions_template *actions_templates[],
+		 uint8_t nb_actions_templates,
+		 struct rte_flow_error *err);
+	/** See rte_flow_template_table_destroy() */
+	int (*template_table_destroy)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_template_table *template_table,
+		 struct rte_flow_error *err);
 };
 
 /**
lib/ethdev/version.map +6 -0
index f1235aa913..5fd2108895 100644
@@ -262,6 +262,12 @@ EXPERIMENTAL {
 	rte_eth_dev_priority_flow_ctrl_queue_info_get;
 	rte_flow_info_get;
 	rte_flow_configure;
+	rte_flow_pattern_template_create;
+	rte_flow_pattern_template_destroy;
+	rte_flow_actions_template_create;
+	rte_flow_actions_template_destroy;
+	rte_flow_template_table_create;
+	rte_flow_template_table_destroy;
 };
 
 INTERNAL {
Signature · 1 line
2.18.2
#82 lore raw

PATCH v4 3/10 ethdev: bring in async queue-based flow rules operations

In reply to Alexander Kozyrev

A new, faster, queue-based flow rules management mechanism is needed for applications offloading rules inside the datapath. This asynchronous and lockless mechanism frees the CPU for further packet processing and reduces the performance impact of the flow rules creation/destruction on the datapath. Note that queues are not thread-safe and the queue should be accessed from the same thread for all queue operations. It is the responsibility of the app to sync the queue functions in case of multi-threaded access to the same queue.

The rte_flow_q_flow_create() function enqueues a flow creation to the requested queue. It benefits from already configured resources and sets unique values on top of item and action templates. A flow rule is enqueued on the specified flow queue and offloaded asynchronously to the hardware. The function returns immediately to spare CPU for further packet processing. The application must invoke the rte_flow_q_pull() function to complete the flow rule operation offloading, to clear the queue, and to receive the operation status. The rte_flow_q_flow_destroy() function enqueues a flow destruction to the requested queue.

---
 doc/guides/prog_guide/img/rte_flow_q_init.svg | 205 ++++++++++
 .../prog_guide/img/rte_flow_q_usage.svg       | 351 ++++++++++++++++++
 doc/guides/prog_guide/rte_flow.rst            | 167 ++++++++-
 doc/guides/rel_notes/release_22_03.rst        |   8 +
 lib/ethdev/rte_flow.c                         | 174 ++++++++-
 lib/ethdev/rte_flow.h                         | 334 +++++++++++++++++
 lib/ethdev/rte_flow_driver.h                  |  55 +++
 lib/ethdev/version.map                        |   7 +
 8 files changed, 1299 insertions(+), 2 deletions(-)
 create mode 100644 doc/guides/prog_guide/img/rte_flow_q_init.svg
 create mode 100644 doc/guides/prog_guide/img/rte_flow_q_usage.svg
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +205 -0
new file mode 100644
index 0000000000..96160bde42
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- SPDX-License-Identifier: BSD-3-Clause -->
+
+<!-- Copyright(c) 2022 NVIDIA Corporation & Affiliates -->
+
+<svg
+   width="485"
+   height="535"
+   overflow="hidden"
+   version="1.1"
+   id="svg61"
+   sodipodi:docname="rte_flow_q_init.svg"
+   inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:svg="http://www.w3.org/2000/svg">
+  <sodipodi:namedview
+     id="namedview63"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageshadow="2"
+     inkscape:pageopacity="0.0"
+     inkscape:pagecheckerboard="0"
+     showgrid="false"
+     inkscape:zoom="1.517757"
+     inkscape:cx="242.79249"
+     inkscape:cy="267.17057"
+     inkscape:window-width="2400"
+     inkscape:window-height="1271"
+     inkscape:window-x="2391"
+     inkscape:window-y="-9"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="g59" />
+  <defs
+     id="defs5">
+    <clipPath
+       id="clip0">
+      <rect
+         x="0"
+         y="0"
+         width="485"
+         height="535"
+         id="rect2" />
+    </clipPath>
+  </defs>
+  <g
+     clip-path="url(#clip0)"
+     id="g59">
+    <rect
+       x="0"
+       y="0"
+       width="485"
+       height="535"
+       fill="#FFFFFF"
+       id="rect7" />
+    <rect
+       x="0.500053"
+       y="79.5001"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#A6A6A6"
+       id="rect9" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="24"
+       transform="translate(121.6 116)"
+       id="text13">
+         rte_eth_dev_configure
+         <tspan
+   font-size="24"
+   x="224.007"
+   y="0"
+   id="tspan11">()</tspan></text>
+    <rect
+       x="0.500053"
+       y="158.5"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect15" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="24"
+       transform="translate(140.273 195)"
+       id="text17">
+         rte_flow_configure()
+      </text>
+    <rect
+       x="0.500053"
+       y="236.5"
+       width="482"
+       height="60"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect19" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text21"
+       x="63.425903"
+       y="274">rte_flow_pattern_template_create()</text>
+    <rect
+       x="0.500053"
+       y="316.5"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect23" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text27"
+       x="69.379204"
+       y="353">rte_flow_actions_template_create()</text>
+    <rect
+       x="0.500053"
+       y="0.500053"
+       width="482"
+       height="60"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#A6A6A6"
+       id="rect29" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       transform="translate(177.233,37)"
+       id="text33">rte_eal_init()</text>
+    <path
+       d="M2-1.09108e-05 2.00005 9.2445-1.99995 9.24452-2 1.09108e-05ZM6.00004 7.24448 0.000104987 19.2445-5.99996 7.24455Z"
+       transform="matrix(-1 0 0 1 241 60)"
+       id="path35" />
+    <path
+       d="M2-1.08133e-05 2.00005 9.41805-1.99995 9.41807-2 1.08133e-05ZM6.00004 7.41802 0.000104987 19.4181-5.99996 7.41809Z"
+       transform="matrix(-1 0 0 1 241 138)"
+       id="path37" />
+    <path
+       d="M2-1.09108e-05 2.00005 9.2445-1.99995 9.24452-2 1.09108e-05ZM6.00004 7.24448 0.000104987 19.2445-5.99996 7.24455Z"
+       transform="matrix(-1 0 0 1 241 217)"
+       id="path39" />
+    <rect
+       x="0.500053"
+       y="395.5"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect41" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text47"
+       x="76.988998"
+       y="432">rte_flow_template_table_create()</text>
+    <path
+       d="M2-1.05859e-05 2.00005 9.83526-1.99995 9.83529-2 1.05859e-05ZM6.00004 7.83524 0.000104987 19.8353-5.99996 7.83531Z"
+       transform="matrix(-1 0 0 1 241 296)"
+       id="path49" />
+    <path
+       d="M243 375 243 384.191 239 384.191 239 375ZM247 382.191 241 394.191 235 382.191Z"
+       id="path51" />
+    <rect
+       x="0.500053"
+       y="473.5"
+       width="482"
+       height="60"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#A6A6A6"
+       id="rect53" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text55"
+       x="149.30299"
+       y="511">rte_eth_dev_start()</text>
+    <path
+       d="M245 454 245 463.191 241 463.191 241 454ZM249 461.191 243 473.191 237 461.191Z"
+       id="path57" />
+  </g>
+</svg>
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +351 -0

351 lines not on this page · raw message

doc/guides/prog_guide/rte_flow.rst +166 -1

191 lines not on this page · raw message

doc/guides/rel_notes/release_22_03.rst +8 -0
index 6656b35295..b4e18836ea 100644
@@ -83,6 +83,14 @@ New Features
     ``rte_flow_template_table_destroy``, ``rte_flow_pattern_template_destroy``
     and ``rte_flow_actions_template_destroy``.
 
+  * ethdev: Added ``rte_flow_q_flow_create`` and ``rte_flow_q_flow_destroy``
+    API to enqueue flow creaion/destruction operations asynchronously as well
+	as ``rte_flow_q_pull`` to poll and retrieve results of these operations
+	and ``rte_flow_q_push`` to push all the in-flight operations to the NIC.
+    Introduced asynchronous API for indirect actions management as well:
+    ``rte_flow_q_action_handle_create``, ``rte_flow_q_action_handle_destroy``
+	and ``rte_flow_q_action_handle_update``.
+
 * **Updated AF_XDP PMD**
 
   * Added support for libxdp >=v1.2.2.
lib/ethdev/rte_flow.c +173 -1

189 lines not on this page · raw message

lib/ethdev/rte_flow.h +334 -0

364 lines not on this page · raw message

lib/ethdev/rte_flow_driver.h +55 -0

67 lines not on this page · raw message

lib/ethdev/version.map +7 -0
index 5fd2108895..46a4151053 100644
@@ -268,6 +268,13 @@ EXPERIMENTAL {
 	rte_flow_actions_template_destroy;
 	rte_flow_template_table_create;
 	rte_flow_template_table_destroy;
+	rte_flow_q_flow_create;
+	rte_flow_q_flow_destroy;
+	rte_flow_q_action_handle_create;
+	rte_flow_q_action_handle_destroy;
+	rte_flow_q_action_handle_update;
+	rte_flow_q_push;
+	rte_flow_q_pull;
 };
 
 INTERNAL {
Signature · 1 line
2.18.2
#83 lore raw

PATCH v4 4/10 app/testpmd: implement rte flow configuration

In reply to Alexander Kozyrev

Add testpmd support for the rte_flow_configure API. Provide the command line interface for the Flow management. Usage example: flow configure 0 queues_number 8 queues_size 256

Implement rte_flow_info_get API to get available resources:
Usage example: flow info 0

---
 app/test-pmd/cmdline_flow.c                 | 126 +++++++++++++++++++-
 app/test-pmd/config.c                       |  54 +++++++++
 app/test-pmd/testpmd.h                      |   7 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  60 +++++++++-
 4 files changed, 244 insertions(+), 3 deletions(-)
app/test-pmd/cmdline_flow.c +125 -1
index 7b56b1b0ff..cc3003e6eb 100644
@@ -72,6 +72,8 @@ enum index {
 	/* Top-level command. */
 	FLOW,
 	/* Sub-level commands. */
+	INFO,
+	CONFIGURE,
 	INDIRECT_ACTION,
 	VALIDATE,
 	CREATE,
@@ -122,6 +124,13 @@ enum index {
 	DUMP_ALL,
 	DUMP_ONE,
 
+	/* Configure arguments */
+	CONFIG_QUEUES_NUMBER,
+	CONFIG_QUEUES_SIZE,
+	CONFIG_COUNTERS_NUMBER,
+	CONFIG_AGING_COUNTERS_NUMBER,
+	CONFIG_METERS_NUMBER,
+
 	/* Indirect action arguments */
 	INDIRECT_ACTION_CREATE,
 	INDIRECT_ACTION_UPDATE,
@@ -847,6 +856,11 @@ struct buffer {
 	enum index command; /**< Flow command. */
 	portid_t port; /**< Affected port ID. */
 	union {
+		struct {
+			struct rte_flow_port_attr port_attr;
+			uint32_t nb_queue;
+			struct rte_flow_queue_attr queue_attr;
+		} configure; /**< Configuration arguments. */
 		struct {
 			uint32_t *action_id;
 			uint32_t action_id_n;
@@ -928,6 +942,16 @@ static const enum index next_flex_item[] = {
 	ZERO,
 };
 
+static const enum index next_config_attr[] = {
+	CONFIG_QUEUES_NUMBER,
+	CONFIG_QUEUES_SIZE,
+	CONFIG_COUNTERS_NUMBER,
+	CONFIG_AGING_COUNTERS_NUMBER,
+	CONFIG_METERS_NUMBER,
+	END,
+	ZERO,
+};
+
 static const enum index next_ia_create_attr[] = {
 	INDIRECT_ACTION_CREATE_ID,
 	INDIRECT_ACTION_INGRESS,
@@ -1964,6 +1988,9 @@ static int parse_aged(struct context *, const struct token *,
 static int parse_isolate(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
+static int parse_configure(struct context *, const struct token *,
+			   const char *, unsigned int,
+			   void *, unsigned int);
 static int parse_tunnel(struct context *, const struct token *,
 			const char *, unsigned int,
 			void *, unsigned int);
@@ -2189,7 +2216,9 @@ static const struct token token_list[] = {
 		.type = "{command} {port_id} [{arg} [...]]",
 		.help = "manage ingress/egress flow rules",
 		.next = NEXT(NEXT_ENTRY
-			     (INDIRECT_ACTION,
+			     (INFO,
+			      CONFIGURE,
+			      INDIRECT_ACTION,
 			      VALIDATE,
 			      CREATE,
 			      DESTROY,
@@ -2204,6 +2233,65 @@ static const struct token token_list[] = {
 		.call = parse_init,
 	},
 	/* Top-level command. */
+	[INFO] = {
+		.name = "info",
+		.help = "get information about flow engine",
+		.next = NEXT(NEXT_ENTRY(END),
+			     NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_configure,
+	},
+	/* Top-level command. */
+	[CONFIGURE] = {
+		.name = "configure",
+		.help = "configure flow engine",
+		.next = NEXT(next_config_attr,
+			     NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_configure,
+	},
+	/* Configure arguments. */
+	[CONFIG_QUEUES_NUMBER] = {
+		.name = "queues_number",
+		.help = "number of queues",
+		.next = NEXT(next_config_attr,
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.configure.nb_queue)),
+	},
+	[CONFIG_QUEUES_SIZE] = {
+		.name = "queues_size",
+		.help = "number of elements in queues",
+		.next = NEXT(next_config_attr,
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.configure.queue_attr.size)),
+	},
+	[CONFIG_COUNTERS_NUMBER] = {
+		.name = "counters_number",
+		.help = "number of counters",
+		.next = NEXT(next_config_attr,
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.configure.port_attr.nb_counters)),
+	},
+	[CONFIG_AGING_COUNTERS_NUMBER] = {
+		.name = "aging_counters_number",
+		.help = "number of aging flows",
+		.next = NEXT(next_config_attr,
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.configure.port_attr.nb_aging_flows)),
+	},
+	[CONFIG_METERS_NUMBER] = {
+		.name = "meters_number",
+		.help = "number of meters",
+		.next = NEXT(next_config_attr,
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.configure.port_attr.nb_meters)),
+	},
+	/* Top-level command. */
 	[INDIRECT_ACTION] = {
 		.name = "indirect_action",
 		.type = "{command} {port_id} [{arg} [...]]",
@@ -7480,6 +7568,33 @@ parse_isolate(struct context *ctx, const struct token *token,
 	return len;
 }
 
+/** Parse tokens for info/configure command. */
+static int
+parse_configure(struct context *ctx, const struct token *token,
+		const char *str, unsigned int len,
+		void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != INFO && ctx->curr != CONFIGURE)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+	}
+	return len;
+}
+
 static int
 parse_flex(struct context *ctx, const struct token *token,
 	     const char *str, unsigned int len,
@@ -8708,6 +8823,15 @@ static void
 cmd_flow_parsed(const struct buffer *in)
 {
 	switch (in->command) {
+	case INFO:
+		port_flow_get_info(in->port);
+		break;
+	case CONFIGURE:
+		port_flow_configure(in->port,
+				    &in->args.configure.port_attr,
+				    in->args.configure.nb_queue,
+				    &in->args.configure.queue_attr);
+		break;
 	case INDIRECT_ACTION_CREATE:
 		port_action_handle_create(
 				in->port, in->args.vc.attr.group,
app/test-pmd/config.c +54 -0

60 lines not on this page · raw message

app/test-pmd/testpmd.h +7 -0
index 9967825044..096b6825eb 100644
@@ -243,6 +243,8 @@ struct rte_port {
 	struct rte_eth_txconf   tx_conf[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue tx configuration */
 	struct rte_ether_addr   *mc_addr_pool; /**< pool of multicast addrs */
 	uint32_t                mc_addr_nb; /**< nb. of addr. in mc_addr_pool */
+	queueid_t               queue_nb; /**< nb. of queues for flow rules */
+	uint32_t                queue_sz; /**< size of a queue for flow rules */
 	uint8_t                 slave_flag; /**< bonding slave port */
 	struct port_flow        *flow_list; /**< Associated flows. */
 	struct port_indirect_action *actions_list;
@@ -885,6 +887,11 @@ struct rte_flow_action_handle *port_action_handle_get_by_id(portid_t port_id,
 							    uint32_t id);
 int port_action_handle_update(portid_t port_id, uint32_t id,
 			      const struct rte_flow_action *action);
+int port_flow_get_info(portid_t port_id);
+int port_flow_configure(portid_t port_id,
+			const struct rte_flow_port_attr *port_attr,
+			uint16_t nb_queue,
+			const struct rte_flow_queue_attr *queue_attr);
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
doc/guides/testpmd_app_ug/testpmd_funcs.rst +58 -2

78 lines not on this page · raw message

Signature · 1 line
2.18.2
#84 lore raw

Re: [PATCH v4 04/10] app/testpmd: implement rte flow configuration

09/02/2022 22:38, Alexander Kozyrev:

Quoted 1 line

Add testpmd support for the rte_flow_configure API.

A note about the titles for testpmd patches in this series:
You don't "implement" because it was implemented in rte_flow.c. Instead, better to say "add" in the testpmd app context.

Also you should not mention "rte flow" with a space.
It's better to keep rte_flow with underscore (even if discouraged), or in a more verbal English manner, just "flow" if it is enough to understand. Here I think it could be:
app/testpmd: add flow engine configuration

#85 lore raw

PATCH v4 5/10 app/testpmd: implement rte flow template management

In reply to Alexander Kozyrev

Add testpmd support for the rte_flow_pattern_template and rte_flow_actions_template APIs. Provide the command line interface for the template creation/destruction. Usage example:
testpmd> flow pattern_template 0 create pattern_template_id 2

           template eth dst is 00:16:3e:31:15:c3 / end

testpmd> flow actions_template 0 create actions_template_id 4
template drop / end mask drop / end
testpmd> flow actions_template 0 destroy actions_template 4 testpmd> flow pattern_template 0 destroy pattern_template 2

---
 app/test-pmd/cmdline_flow.c                 | 376 +++++++++++++++++++-
 app/test-pmd/config.c                       | 203 +++++++++++
 app/test-pmd/testpmd.h                      |  23 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  97 +++++
 4 files changed, 697 insertions(+), 2 deletions(-)
app/test-pmd/cmdline_flow.c +374 -2
index cc3003e6eb..34bc73eea3 100644
@@ -56,6 +56,8 @@ enum index {
 	COMMON_POLICY_ID,
 	COMMON_FLEX_HANDLE,
 	COMMON_FLEX_TOKEN,
+	COMMON_PATTERN_TEMPLATE_ID,
+	COMMON_ACTIONS_TEMPLATE_ID,
 
 	/* TOP-level command. */
 	ADD,
@@ -74,6 +76,8 @@ enum index {
 	/* Sub-level commands. */
 	INFO,
 	CONFIGURE,
+	PATTERN_TEMPLATE,
+	ACTIONS_TEMPLATE,
 	INDIRECT_ACTION,
 	VALIDATE,
 	CREATE,
@@ -92,6 +96,22 @@ enum index {
 	FLEX_ITEM_CREATE,
 	FLEX_ITEM_DESTROY,
 
+	/* Pattern template arguments. */
+	PATTERN_TEMPLATE_CREATE,
+	PATTERN_TEMPLATE_DESTROY,
+	PATTERN_TEMPLATE_CREATE_ID,
+	PATTERN_TEMPLATE_DESTROY_ID,
+	PATTERN_TEMPLATE_RELAXED_MATCHING,
+	PATTERN_TEMPLATE_SPEC,
+
+	/* Actions template arguments. */
+	ACTIONS_TEMPLATE_CREATE,
+	ACTIONS_TEMPLATE_DESTROY,
+	ACTIONS_TEMPLATE_CREATE_ID,
+	ACTIONS_TEMPLATE_DESTROY_ID,
+	ACTIONS_TEMPLATE_SPEC,
+	ACTIONS_TEMPLATE_MASK,
+
 	/* Tunnel arguments. */
 	TUNNEL_CREATE,
 	TUNNEL_CREATE_TYPE,
@@ -861,6 +881,10 @@ struct buffer {
 			uint32_t nb_queue;
 			struct rte_flow_queue_attr queue_attr;
 		} configure; /**< Configuration arguments. */
+		struct {
+			uint32_t *template_id;
+			uint32_t template_id_n;
+		} templ_destroy; /**< Template destroy arguments. */
 		struct {
 			uint32_t *action_id;
 			uint32_t action_id_n;
@@ -869,10 +893,13 @@ struct buffer {
 			uint32_t action_id;
 		} ia; /* Indirect action query arguments */
 		struct {
+			uint32_t pat_templ_id;
+			uint32_t act_templ_id;
 			struct rte_flow_attr attr;
 			struct tunnel_ops tunnel_ops;
 			struct rte_flow_item *pattern;
 			struct rte_flow_action *actions;
+			struct rte_flow_action *masks;
 			uint32_t pattern_n;
 			uint32_t actions_n;
 			uint8_t *data;
@@ -952,6 +979,43 @@ static const enum index next_config_attr[] = {
 	ZERO,
 };
 
+static const enum index next_pt_subcmd[] = {
+	PATTERN_TEMPLATE_CREATE,
+	PATTERN_TEMPLATE_DESTROY,
+	ZERO,
+};
+
+static const enum index next_pt_attr[] = {
+	PATTERN_TEMPLATE_CREATE_ID,
+	PATTERN_TEMPLATE_RELAXED_MATCHING,
+	PATTERN_TEMPLATE_SPEC,
+	ZERO,
+};
+
+static const enum index next_pt_destroy_attr[] = {
+	PATTERN_TEMPLATE_DESTROY_ID,
+	END,
+	ZERO,
+};
+
+static const enum index next_at_subcmd[] = {
+	ACTIONS_TEMPLATE_CREATE,
+	ACTIONS_TEMPLATE_DESTROY,
+	ZERO,
+};
+
+static const enum index next_at_attr[] = {
+	ACTIONS_TEMPLATE_CREATE_ID,
+	ACTIONS_TEMPLATE_SPEC,
+	ZERO,
+};
+
+static const enum index next_at_destroy_attr[] = {
+	ACTIONS_TEMPLATE_DESTROY_ID,
+	END,
+	ZERO,
+};
+
 static const enum index next_ia_create_attr[] = {
 	INDIRECT_ACTION_CREATE_ID,
 	INDIRECT_ACTION_INGRESS,
@@ -1991,6 +2055,12 @@ static int parse_isolate(struct context *, const struct token *,
 static int parse_configure(struct context *, const struct token *,
 			   const char *, unsigned int,
 			   void *, unsigned int);
+static int parse_template(struct context *, const struct token *,
+			  const char *, unsigned int,
+			  void *, unsigned int);
+static int parse_template_destroy(struct context *, const struct token *,
+				  const char *, unsigned int,
+				  void *, unsigned int);
 static int parse_tunnel(struct context *, const struct token *,
 			const char *, unsigned int,
 			void *, unsigned int);
@@ -2060,6 +2130,10 @@ static int comp_set_modify_field_op(struct context *, const struct token *,
 			      unsigned int, char *, unsigned int);
 static int comp_set_modify_field_id(struct context *, const struct token *,
 			      unsigned int, char *, unsigned int);
+static int comp_pattern_template_id(struct context *, const struct token *,
+				    unsigned int, char *, unsigned int);
+static int comp_actions_template_id(struct context *, const struct token *,
+				    unsigned int, char *, unsigned int);
 
 /** Token definitions. */
 static const struct token token_list[] = {
@@ -2210,6 +2284,20 @@ static const struct token token_list[] = {
 		.call = parse_flex_handle,
 		.comp = comp_none,
 	},
+	[COMMON_PATTERN_TEMPLATE_ID] = {
+		.name = "{pattern_template_id}",
+		.type = "PATTERN_TEMPLATE_ID",
+		.help = "pattern template id",
+		.call = parse_int,
+		.comp = comp_pattern_template_id,
+	},
+	[COMMON_ACTIONS_TEMPLATE_ID] = {
+		.name = "{actions_template_id}",
+		.type = "ACTIONS_TEMPLATE_ID",
+		.help = "actions template id",
+		.call = parse_int,
+		.comp = comp_actions_template_id,
+	},
 	/* Top-level command. */
 	[FLOW] = {
 		.name = "flow",
@@ -2218,6 +2306,8 @@ static const struct token token_list[] = {
 		.next = NEXT(NEXT_ENTRY
 			     (INFO,
 			      CONFIGURE,
+			      PATTERN_TEMPLATE,
+			      ACTIONS_TEMPLATE,
 			      INDIRECT_ACTION,
 			      VALIDATE,
 			      CREATE,
@@ -2292,6 +2382,112 @@ static const struct token token_list[] = {
 					args.configure.port_attr.nb_meters)),
 	},
 	/* Top-level command. */
+	[PATTERN_TEMPLATE] = {
+		.name = "pattern_template",
+		.type = "{command} {port_id} [{arg} [...]]",
+		.help = "manage pattern templates",
+		.next = NEXT(next_pt_subcmd, NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_template,
+	},
+	/* Sub-level commands. */
+	[PATTERN_TEMPLATE_CREATE] = {
+		.name = "create",
+		.help = "create pattern template",
+		.next = NEXT(next_pt_attr),
+		.call = parse_template,
+	},
+	[PATTERN_TEMPLATE_DESTROY] = {
+		.name = "destroy",
+		.help = "destroy pattern template",
+		.next = NEXT(NEXT_ENTRY(PATTERN_TEMPLATE_DESTROY_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_template_destroy,
+	},
+	/* Pattern template arguments. */
+	[PATTERN_TEMPLATE_CREATE_ID] = {
+		.name = "pattern_template_id",
+		.help = "specify a pattern template id to create",
+		.next = NEXT(next_pt_attr,
+			     NEXT_ENTRY(COMMON_PATTERN_TEMPLATE_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, args.vc.pat_templ_id)),
+	},
+	[PATTERN_TEMPLATE_DESTROY_ID] = {
+		.name = "pattern_template",
+		.help = "specify a pattern template id to destroy",
+		.next = NEXT(next_pt_destroy_attr,
+			     NEXT_ENTRY(COMMON_PATTERN_TEMPLATE_ID)),
+		.args = ARGS(ARGS_ENTRY_PTR(struct buffer,
+					    args.templ_destroy.template_id)),
+		.call = parse_template_destroy,
+	},
+	[PATTERN_TEMPLATE_RELAXED_MATCHING] = {
+		.name = "relaxed",
+		.help = "is matching relaxed",
+		.next = NEXT(next_pt_attr,
+			     NEXT_ENTRY(COMMON_BOOLEAN)),
+		.args = ARGS(ARGS_ENTRY_BF(struct buffer,
+			     args.vc.attr.reserved, 1)),
+	},
+	[PATTERN_TEMPLATE_SPEC] = {
+		.name = "template",
+		.help = "specify item to create pattern template",
+		.next = NEXT(next_item),
+	},
+	/* Top-level command. */
+	[ACTIONS_TEMPLATE] = {
+		.name = "actions_template",
+		.type = "{command} {port_id} [{arg} [...]]",
+		.help = "manage actions templates",
+		.next = NEXT(next_at_subcmd, NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_template,
+	},
+	/* Sub-level commands. */
+	[ACTIONS_TEMPLATE_CREATE] = {
+		.name = "create",
+		.help = "create actions template",
+		.next = NEXT(next_at_attr),
+		.call = parse_template,
+	},
+	[ACTIONS_TEMPLATE_DESTROY] = {
+		.name = "destroy",
+		.help = "destroy actions template",
+		.next = NEXT(NEXT_ENTRY(ACTIONS_TEMPLATE_DESTROY_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_template_destroy,
+	},
+	/* Actions template arguments. */
+	[ACTIONS_TEMPLATE_CREATE_ID] = {
+		.name = "actions_template_id",
+		.help = "specify an actions template id to create",
+		.next = NEXT(NEXT_ENTRY(ACTIONS_TEMPLATE_MASK),
+			     NEXT_ENTRY(ACTIONS_TEMPLATE_SPEC),
+			     NEXT_ENTRY(COMMON_ACTIONS_TEMPLATE_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, args.vc.act_templ_id)),
+	},
+	[ACTIONS_TEMPLATE_DESTROY_ID] = {
+		.name = "actions_template",
+		.help = "specify an actions template id to destroy",
+		.next = NEXT(next_at_destroy_attr,
+			     NEXT_ENTRY(COMMON_ACTIONS_TEMPLATE_ID)),
+		.args = ARGS(ARGS_ENTRY_PTR(struct buffer,
+					    args.templ_destroy.template_id)),
+		.call = parse_template_destroy,
+	},
+	[ACTIONS_TEMPLATE_SPEC] = {
+		.name = "template",
+		.help = "specify action to create actions template",
+		.next = NEXT(next_action),
+		.call = parse_template,
+	},
+	[ACTIONS_TEMPLATE_MASK] = {
+		.name = "mask",
+		.help = "specify action mask to create actions template",
+		.next = NEXT(next_action),
+		.call = parse_template,
+	},
+	/* Top-level command. */
 	[INDIRECT_ACTION] = {
 		.name = "indirect_action",
 		.type = "{command} {port_id} [{arg} [...]]",
@@ -2614,7 +2810,7 @@ static const struct token token_list[] = {
 		.name = "end",
 		.help = "end list of pattern items",
 		.priv = PRIV_ITEM(END, 0),
-		.next = NEXT(NEXT_ENTRY(ACTIONS)),
+		.next = NEXT(NEXT_ENTRY(ACTIONS, END)),
 		.call = parse_vc,
 	},
 	[ITEM_VOID] = {
@@ -5731,7 +5927,9 @@ parse_vc(struct context *ctx, const struct token *token,
 	if (!out)
 		return len;
 	if (!out->command) {
-		if (ctx->curr != VALIDATE && ctx->curr != CREATE)
+		if (ctx->curr != VALIDATE && ctx->curr != CREATE &&
+		    ctx->curr != PATTERN_TEMPLATE_CREATE &&
+		    ctx->curr != ACTIONS_TEMPLATE_CREATE)
 			return -1;
 		if (sizeof(*out) > size)
 			return -1;
@@ -7595,6 +7793,114 @@ parse_configure(struct context *ctx, const struct token *token,
 	return len;
 }
 
+/** Parse tokens for template create command. */
+static int
+parse_template(struct context *ctx, const struct token *token,
+	       const char *str, unsigned int len,
+	       void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != PATTERN_TEMPLATE &&
+		    ctx->curr != ACTIONS_TEMPLATE)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.vc.data = (uint8_t *)out + size;
+		return len;
+	}
+	switch (ctx->curr) {
+	case PATTERN_TEMPLATE_CREATE:
+		out->args.vc.pattern =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		out->args.vc.pat_templ_id = UINT32_MAX;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		return len;
+	case ACTIONS_TEMPLATE_CREATE:
+		out->args.vc.act_templ_id = UINT32_MAX;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		return len;
+	case ACTIONS_TEMPLATE_SPEC:
+		out->args.vc.actions =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		ctx->object = out->args.vc.actions;
+		ctx->objmask = NULL;
+		return len;
+	case ACTIONS_TEMPLATE_MASK:
+		out->args.vc.masks =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)
+					       (out->args.vc.actions +
+						out->args.vc.actions_n),
+					       sizeof(double));
+		ctx->object = out->args.vc.masks;
+		ctx->objmask = NULL;
+		return len;
+	default:
+		return -1;
+	}
+}
+
+/** Parse tokens for template destroy command. */
+static int
+parse_template_destroy(struct context *ctx, const struct token *token,
+		       const char *str, unsigned int len,
+		       void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+	uint32_t *template_id;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command ||
+		out->command == PATTERN_TEMPLATE ||
+		out->command == ACTIONS_TEMPLATE) {
+		if (ctx->curr != PATTERN_TEMPLATE_DESTROY &&
+			ctx->curr != ACTIONS_TEMPLATE_DESTROY)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.templ_destroy.template_id =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		return len;
+	}
+	template_id = out->args.templ_destroy.template_id
+		    + out->args.templ_destroy.template_id_n++;
+	if ((uint8_t *)template_id > (uint8_t *)out + size)
+		return -1;
+	ctx->objdata = 0;
+	ctx->object = template_id;
+	ctx->objmask = NULL;
+	return len;
+}
+
 static int
 parse_flex(struct context *ctx, const struct token *token,
 	     const char *str, unsigned int len,
@@ -8564,6 +8870,54 @@ comp_set_modify_field_id(struct context *ctx, const struct token *token,
 	return -1;
 }
 
+/** Complete available pattern template IDs. */
+static int
+comp_pattern_template_id(struct context *ctx, const struct token *token,
+			 unsigned int ent, char *buf, unsigned int size)
+{
+	unsigned int i = 0;
+	struct rte_port *port;
+	struct port_template *pt;
+
+	(void)token;
+	if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
+	    ctx->port == (portid_t)RTE_PORT_ALL)
+		return -1;
+	port = &ports[ctx->port];
+	for (pt = port->pattern_templ_list; pt != NULL; pt = pt->next) {
+		if (buf && i == ent)
+			return snprintf(buf, size, "%u", pt->id);
+		++i;
+	}
+	if (buf)
+		return -1;
+	return i;
+}
+
+/** Complete available actions template IDs. */
+static int
+comp_actions_template_id(struct context *ctx, const struct token *token,
+			 unsigned int ent, char *buf, unsigned int size)
+{
+	unsigned int i = 0;
+	struct rte_port *port;
+	struct port_template *pt;
+
+	(void)token;
+	if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
+	    ctx->port == (portid_t)RTE_PORT_ALL)
+		return -1;
+	port = &ports[ctx->port];
+	for (pt = port->actions_templ_list; pt != NULL; pt = pt->next) {
+		if (buf && i == ent)
+			return snprintf(buf, size, "%u", pt->id);
+		++i;
+	}
+	if (buf)
+		return -1;
+	return i;
+}
+
 /** Internal context. */
 static struct context cmd_flow_context;
 
@@ -8832,6 +9186,24 @@ cmd_flow_parsed(const struct buffer *in)
 				    in->args.configure.nb_queue,
 				    &in->args.configure.queue_attr);
 		break;
+	case PATTERN_TEMPLATE_CREATE:
+		port_flow_pattern_template_create(in->port, in->args.vc.pat_templ_id,
+				in->args.vc.attr.reserved, in->args.vc.pattern);
+		break;
+	case PATTERN_TEMPLATE_DESTROY:
+		port_flow_pattern_template_destroy(in->port,
+				in->args.templ_destroy.template_id_n,
+				in->args.templ_destroy.template_id);
+		break;
+	case ACTIONS_TEMPLATE_CREATE:
+		port_flow_actions_template_create(in->port, in->args.vc.act_templ_id,
+				in->args.vc.actions, in->args.vc.masks);
+		break;
+	case ACTIONS_TEMPLATE_DESTROY:
+		port_flow_actions_template_destroy(in->port,
+				in->args.templ_destroy.template_id_n,
+				in->args.templ_destroy.template_id);
+		break;
 	case INDIRECT_ACTION_CREATE:
 		port_action_handle_create(
 				in->port, in->args.vc.attr.group,
app/test-pmd/config.c +203 -0

215 lines not on this page · raw message

app/test-pmd/testpmd.h +23 -0
index 096b6825eb..c70b1fa4e8 100644
@@ -166,6 +166,17 @@ enum age_action_context_type {
 	ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION,
 };
 
+/** Descriptor for a template. */
+struct port_template {
+	struct port_template *next; /**< Next template in list. */
+	struct port_template *tmp; /**< Temporary linking. */
+	uint32_t id; /**< Template ID. */
+	union {
+		struct rte_flow_pattern_template *pattern_template;
+		struct rte_flow_actions_template *actions_template;
+	} template; /**< PMD opaque template object */
+};
+
 /** Descriptor for a single flow. */
 struct port_flow {
 	struct port_flow *next; /**< Next flow in list. */
@@ -246,6 +257,8 @@ struct rte_port {
 	queueid_t               queue_nb; /**< nb. of queues for flow rules */
 	uint32_t                queue_sz; /**< size of a queue for flow rules */
 	uint8_t                 slave_flag; /**< bonding slave port */
+	struct port_template    *pattern_templ_list; /**< Pattern templates. */
+	struct port_template    *actions_templ_list; /**< Actions templates. */
 	struct port_flow        *flow_list; /**< Associated flows. */
 	struct port_indirect_action *actions_list;
 	/**< Associated indirect actions. */
@@ -892,6 +905,16 @@ int port_flow_configure(portid_t port_id,
 			const struct rte_flow_port_attr *port_attr,
 			uint16_t nb_queue,
 			const struct rte_flow_queue_attr *queue_attr);
+int port_flow_pattern_template_create(portid_t port_id, uint32_t id,
+				      bool relaxed,
+				      const struct rte_flow_item *pattern);
+int port_flow_pattern_template_destroy(portid_t port_id, uint32_t n,
+				       const uint32_t *template);
+int port_flow_actions_template_create(portid_t port_id, uint32_t id,
+				      const struct rte_flow_action *actions,
+				      const struct rte_flow_action *masks);
+int port_flow_actions_template_destroy(portid_t port_id, uint32_t n,
+				       const uint32_t *template);
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
doc/guides/testpmd_app_ug/testpmd_funcs.rst +97 -0

109 lines not on this page · raw message

Signature · 1 line
2.18.2
#86 lore raw

PATCH v4 6/10 app/testpmd: implement rte flow table management

In reply to Alexander Kozyrev

Add testpmd support for the rte_flow_table API. Provide the command line interface for the flow table creation/destruction. Usage example:
testpmd> flow template_table 0 create table_id 6
group 9 priority 4 ingress mode 1 rules_number 64 pattern_template 2 actions_template 4
testpmd> flow template_table 0 destroy table 6

---
 app/test-pmd/cmdline_flow.c                 | 315 ++++++++++++++++++++
 app/test-pmd/config.c                       | 171 +++++++++++
 app/test-pmd/testpmd.h                      |  17 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  53 ++++
 4 files changed, 556 insertions(+)
app/test-pmd/cmdline_flow.c +315 -0
index 34bc73eea3..3e89525445 100644
@@ -58,6 +58,7 @@ enum index {
 	COMMON_FLEX_TOKEN,
 	COMMON_PATTERN_TEMPLATE_ID,
 	COMMON_ACTIONS_TEMPLATE_ID,
+	COMMON_TABLE_ID,
 
 	/* TOP-level command. */
 	ADD,
@@ -78,6 +79,7 @@ enum index {
 	CONFIGURE,
 	PATTERN_TEMPLATE,
 	ACTIONS_TEMPLATE,
+	TABLE,
 	INDIRECT_ACTION,
 	VALIDATE,
 	CREATE,
@@ -112,6 +114,20 @@ enum index {
 	ACTIONS_TEMPLATE_SPEC,
 	ACTIONS_TEMPLATE_MASK,
 
+	/* Table arguments. */
+	TABLE_CREATE,
+	TABLE_DESTROY,
+	TABLE_CREATE_ID,
+	TABLE_DESTROY_ID,
+	TABLE_GROUP,
+	TABLE_PRIORITY,
+	TABLE_INGRESS,
+	TABLE_EGRESS,
+	TABLE_TRANSFER,
+	TABLE_RULES_NUMBER,
+	TABLE_PATTERN_TEMPLATE,
+	TABLE_ACTIONS_TEMPLATE,
+
 	/* Tunnel arguments. */
 	TUNNEL_CREATE,
 	TUNNEL_CREATE_TYPE,
@@ -885,6 +901,18 @@ struct buffer {
 			uint32_t *template_id;
 			uint32_t template_id_n;
 		} templ_destroy; /**< Template destroy arguments. */
+		struct {
+			uint32_t id;
+			struct rte_flow_template_table_attr attr;
+			uint32_t *pat_templ_id;
+			uint32_t pat_templ_id_n;
+			uint32_t *act_templ_id;
+			uint32_t act_templ_id_n;
+		} table; /**< Table arguments. */
+		struct {
+			uint32_t *table_id;
+			uint32_t table_id_n;
+		} table_destroy; /**< Template destroy arguments. */
 		struct {
 			uint32_t *action_id;
 			uint32_t action_id_n;
@@ -1016,6 +1044,32 @@ static const enum index next_at_destroy_attr[] = {
 	ZERO,
 };
 
+static const enum index next_table_subcmd[] = {
+	TABLE_CREATE,
+	TABLE_DESTROY,
+	ZERO,
+};
+
+static const enum index next_table_attr[] = {
+	TABLE_CREATE_ID,
+	TABLE_GROUP,
+	TABLE_PRIORITY,
+	TABLE_INGRESS,
+	TABLE_EGRESS,
+	TABLE_TRANSFER,
+	TABLE_RULES_NUMBER,
+	TABLE_PATTERN_TEMPLATE,
+	TABLE_ACTIONS_TEMPLATE,
+	END,
+	ZERO,
+};
+
+static const enum index next_table_destroy_attr[] = {
+	TABLE_DESTROY_ID,
+	END,
+	ZERO,
+};
+
 static const enum index next_ia_create_attr[] = {
 	INDIRECT_ACTION_CREATE_ID,
 	INDIRECT_ACTION_INGRESS,
@@ -2061,6 +2115,11 @@ static int parse_template(struct context *, const struct token *,
 static int parse_template_destroy(struct context *, const struct token *,
 				  const char *, unsigned int,
 				  void *, unsigned int);
+static int parse_table(struct context *, const struct token *,
+		       const char *, unsigned int, void *, unsigned int);
+static int parse_table_destroy(struct context *, const struct token *,
+			       const char *, unsigned int,
+			       void *, unsigned int);
 static int parse_tunnel(struct context *, const struct token *,
 			const char *, unsigned int,
 			void *, unsigned int);
@@ -2134,6 +2193,8 @@ static int comp_pattern_template_id(struct context *, const struct token *,
 				    unsigned int, char *, unsigned int);
 static int comp_actions_template_id(struct context *, const struct token *,
 				    unsigned int, char *, unsigned int);
+static int comp_table_id(struct context *, const struct token *,
+			 unsigned int, char *, unsigned int);
 
 /** Token definitions. */
 static const struct token token_list[] = {
@@ -2298,6 +2359,13 @@ static const struct token token_list[] = {
 		.call = parse_int,
 		.comp = comp_actions_template_id,
 	},
+	[COMMON_TABLE_ID] = {
+		.name = "{table_id}",
+		.type = "TABLE_ID",
+		.help = "table id",
+		.call = parse_int,
+		.comp = comp_table_id,
+	},
 	/* Top-level command. */
 	[FLOW] = {
 		.name = "flow",
@@ -2308,6 +2376,7 @@ static const struct token token_list[] = {
 			      CONFIGURE,
 			      PATTERN_TEMPLATE,
 			      ACTIONS_TEMPLATE,
+			      TABLE,
 			      INDIRECT_ACTION,
 			      VALIDATE,
 			      CREATE,
@@ -2488,6 +2557,104 @@ static const struct token token_list[] = {
 		.call = parse_template,
 	},
 	/* Top-level command. */
+	[TABLE] = {
+		.name = "template_table",
+		.type = "{command} {port_id} [{arg} [...]]",
+		.help = "manage template tables",
+		.next = NEXT(next_table_subcmd, NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_table,
+	},
+	/* Sub-level commands. */
+	[TABLE_CREATE] = {
+		.name = "create",
+		.help = "create template table",
+		.next = NEXT(next_table_attr),
+		.call = parse_table,
+	},
+	[TABLE_DESTROY] = {
+		.name = "destroy",
+		.help = "destroy template table",
+		.next = NEXT(NEXT_ENTRY(TABLE_DESTROY_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_table_destroy,
+	},
+	/* Table  arguments. */
+	[TABLE_CREATE_ID] = {
+		.name = "table_id",
+		.help = "specify table id to create",
+		.next = NEXT(next_table_attr,
+			     NEXT_ENTRY(COMMON_TABLE_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, args.table.id)),
+	},
+	[TABLE_DESTROY_ID] = {
+		.name = "table",
+		.help = "specify table id to destroy",
+		.next = NEXT(next_table_destroy_attr,
+			     NEXT_ENTRY(COMMON_TABLE_ID)),
+		.args = ARGS(ARGS_ENTRY_PTR(struct buffer,
+					    args.table_destroy.table_id)),
+		.call = parse_table_destroy,
+	},
+	[TABLE_GROUP] = {
+		.name = "group",
+		.help = "specify a group",
+		.next = NEXT(next_table_attr, NEXT_ENTRY(COMMON_GROUP_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.table.attr.flow_attr.group)),
+	},
+	[TABLE_PRIORITY] = {
+		.name = "priority",
+		.help = "specify a priority level",
+		.next = NEXT(next_table_attr, NEXT_ENTRY(COMMON_PRIORITY_LEVEL)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.table.attr.flow_attr.priority)),
+	},
+	[TABLE_EGRESS] = {
+		.name = "egress",
+		.help = "affect rule to egress",
+		.next = NEXT(next_table_attr),
+		.call = parse_table,
+	},
+	[TABLE_INGRESS] = {
+		.name = "ingress",
+		.help = "affect rule to ingress",
+		.next = NEXT(next_table_attr),
+		.call = parse_table,
+	},
+	[TABLE_TRANSFER] = {
+		.name = "transfer",
+		.help = "affect rule to transfer",
+		.next = NEXT(next_table_attr),
+		.call = parse_table,
+	},
+	[TABLE_RULES_NUMBER] = {
+		.name = "rules_number",
+		.help = "number of rules in table",
+		.next = NEXT(next_table_attr,
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.table.attr.nb_flows)),
+	},
+	[TABLE_PATTERN_TEMPLATE] = {
+		.name = "pattern_template",
+		.help = "specify pattern template id",
+		.next = NEXT(next_table_attr,
+			     NEXT_ENTRY(COMMON_PATTERN_TEMPLATE_ID)),
+		.args = ARGS(ARGS_ENTRY_PTR(struct buffer,
+					    args.table.pat_templ_id)),
+		.call = parse_table,
+	},
+	[TABLE_ACTIONS_TEMPLATE] = {
+		.name = "actions_template",
+		.help = "specify actions template id",
+		.next = NEXT(next_table_attr,
+			     NEXT_ENTRY(COMMON_ACTIONS_TEMPLATE_ID)),
+		.args = ARGS(ARGS_ENTRY_PTR(struct buffer,
+					    args.table.act_templ_id)),
+		.call = parse_table,
+	},
+	/* Top-level command. */
 	[INDIRECT_ACTION] = {
 		.name = "indirect_action",
 		.type = "{command} {port_id} [{arg} [...]]",
@@ -7901,6 +8068,119 @@ parse_template_destroy(struct context *ctx, const struct token *token,
 	return len;
 }
 
+/** Parse tokens for table create command. */
+static int
+parse_table(struct context *ctx, const struct token *token,
+	    const char *str, unsigned int len,
+	    void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+	uint32_t *template_id;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != TABLE)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		return len;
+	}
+	switch (ctx->curr) {
+	case TABLE_CREATE:
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.table.id = UINT32_MAX;
+		return len;
+	case TABLE_PATTERN_TEMPLATE:
+		out->args.table.pat_templ_id =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		template_id = out->args.table.pat_templ_id
+				+ out->args.table.pat_templ_id_n++;
+		if ((uint8_t *)template_id > (uint8_t *)out + size)
+			return -1;
+		ctx->objdata = 0;
+		ctx->object = template_id;
+		ctx->objmask = NULL;
+		return len;
+	case TABLE_ACTIONS_TEMPLATE:
+		out->args.table.act_templ_id =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)
+					       (out->args.table.pat_templ_id +
+						out->args.table.pat_templ_id_n),
+					       sizeof(double));
+		template_id = out->args.table.act_templ_id
+				+ out->args.table.act_templ_id_n++;
+		if ((uint8_t *)template_id > (uint8_t *)out + size)
+			return -1;
+		ctx->objdata = 0;
+		ctx->object = template_id;
+		ctx->objmask = NULL;
+		return len;
+	case TABLE_INGRESS:
+		out->args.table.attr.flow_attr.ingress = 1;
+		return len;
+	case TABLE_EGRESS:
+		out->args.table.attr.flow_attr.egress = 1;
+		return len;
+	case TABLE_TRANSFER:
+		out->args.table.attr.flow_attr.transfer = 1;
+		return len;
+	default:
+		return -1;
+	}
+}
+
+/** Parse tokens for table destroy command. */
+static int
+parse_table_destroy(struct context *ctx, const struct token *token,
+		    const char *str, unsigned int len,
+		    void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+	uint32_t *table_id;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command || out->command == TABLE) {
+		if (ctx->curr != TABLE_DESTROY)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.table_destroy.table_id =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		return len;
+	}
+	table_id = out->args.table_destroy.table_id
+		    + out->args.table_destroy.table_id_n++;
+	if ((uint8_t *)table_id > (uint8_t *)out + size)
+		return -1;
+	ctx->objdata = 0;
+	ctx->object = table_id;
+	ctx->objmask = NULL;
+	return len;
+}
+
 static int
 parse_flex(struct context *ctx, const struct token *token,
 	     const char *str, unsigned int len,
@@ -8918,6 +9198,30 @@ comp_actions_template_id(struct context *ctx, const struct token *token,
 	return i;
 }
 
+/** Complete available table IDs. */
+static int
+comp_table_id(struct context *ctx, const struct token *token,
+	      unsigned int ent, char *buf, unsigned int size)
+{
+	unsigned int i = 0;
+	struct rte_port *port;
+	struct port_table *pt;
+
+	(void)token;
+	if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
+	    ctx->port == (portid_t)RTE_PORT_ALL)
+		return -1;
+	port = &ports[ctx->port];
+	for (pt = port->table_list; pt != NULL; pt = pt->next) {
+		if (buf && i == ent)
+			return snprintf(buf, size, "%u", pt->id);
+		++i;
+	}
+	if (buf)
+		return -1;
+	return i;
+}
+
 /** Internal context. */
 static struct context cmd_flow_context;
 
@@ -9204,6 +9508,17 @@ cmd_flow_parsed(const struct buffer *in)
 				in->args.templ_destroy.template_id_n,
 				in->args.templ_destroy.template_id);
 		break;
+	case TABLE_CREATE:
+		port_flow_template_table_create(in->port, in->args.table.id,
+			&in->args.table.attr, in->args.table.pat_templ_id_n,
+			in->args.table.pat_templ_id, in->args.table.act_templ_id_n,
+			in->args.table.act_templ_id);
+		break;
+	case TABLE_DESTROY:
+		port_flow_template_table_destroy(in->port,
+					in->args.table_destroy.table_id_n,
+					in->args.table_destroy.table_id);
+		break;
 	case INDIRECT_ACTION_CREATE:
 		port_action_handle_create(
 				in->port, in->args.vc.attr.group,
app/test-pmd/config.c +171 -0

183 lines not on this page · raw message

app/test-pmd/testpmd.h +17 -0
index c70b1fa4e8..4c6e775bad 100644
@@ -177,6 +177,16 @@ struct port_template {
 	} template; /**< PMD opaque template object */
 };
 
+/** Descriptor for a flow table. */
+struct port_table {
+	struct port_table *next; /**< Next table in list. */
+	struct port_table *tmp; /**< Temporary linking. */
+	uint32_t id; /**< Table ID. */
+	uint32_t nb_pattern_templates; /**< Number of pattern templates. */
+	uint32_t nb_actions_templates; /**< Number of actions templates. */
+	struct rte_flow_template_table *table; /**< PMD opaque template object */
+};
+
 /** Descriptor for a single flow. */
 struct port_flow {
 	struct port_flow *next; /**< Next flow in list. */
@@ -259,6 +269,7 @@ struct rte_port {
 	uint8_t                 slave_flag; /**< bonding slave port */
 	struct port_template    *pattern_templ_list; /**< Pattern templates. */
 	struct port_template    *actions_templ_list; /**< Actions templates. */
+	struct port_table       *table_list; /**< Flow tables. */
 	struct port_flow        *flow_list; /**< Associated flows. */
 	struct port_indirect_action *actions_list;
 	/**< Associated indirect actions. */
@@ -915,6 +926,12 @@ int port_flow_actions_template_create(portid_t port_id, uint32_t id,
 				      const struct rte_flow_action *masks);
 int port_flow_actions_template_destroy(portid_t port_id, uint32_t n,
 				       const uint32_t *template);
+int port_flow_template_table_create(portid_t port_id, uint32_t id,
+		   const struct rte_flow_template_table_attr *table_attr,
+		   uint32_t nb_pattern_templates, uint32_t *pattern_templates,
+		   uint32_t nb_actions_templates, uint32_t *actions_templates);
+int port_flow_template_table_destroy(portid_t port_id,
+			    uint32_t n, const uint32_t *table);
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
doc/guides/testpmd_app_ug/testpmd_funcs.rst +53 -0

65 lines not on this page · raw message

Signature · 1 line
2.18.2
#87 lore raw

PATCH v4 7/10 app/testpmd: implement rte flow queue flow operations

In reply to Alexander Kozyrev

Add testpmd support for the rte_flow_q_create/rte_flow_q_destroy API. Provide the command line interface for enqueueing flow creation/destruction operations. Usage example:
testpmd> flow queue 0 create 0 postpone no
template_table 6 pattern_template 0 actions_template 0 pattern eth dst is 00:16:3e:31:15:c3 / end actions drop / end
testpmd> flow queue 0 destroy 0 postpone yes rule 0

---
 app/test-pmd/cmdline_flow.c                 | 267 +++++++++++++++++++-
 app/test-pmd/config.c                       | 166 ++++++++++++
 app/test-pmd/testpmd.h                      |   7 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  57 +++++
 4 files changed, 496 insertions(+), 1 deletion(-)
app/test-pmd/cmdline_flow.c +266 -1
index 3e89525445..f794a83a07 100644
@@ -59,6 +59,7 @@ enum index {
 	COMMON_PATTERN_TEMPLATE_ID,
 	COMMON_ACTIONS_TEMPLATE_ID,
 	COMMON_TABLE_ID,
+	COMMON_QUEUE_ID,
 
 	/* TOP-level command. */
 	ADD,
@@ -92,6 +93,7 @@ enum index {
 	ISOLATE,
 	TUNNEL,
 	FLEX,
+	QUEUE,
 
 	/* Flex arguments */
 	FLEX_ITEM_INIT,
@@ -114,6 +116,22 @@ enum index {
 	ACTIONS_TEMPLATE_SPEC,
 	ACTIONS_TEMPLATE_MASK,
 
+	/* Queue arguments. */
+	QUEUE_CREATE,
+	QUEUE_DESTROY,
+
+	/* Queue create arguments. */
+	QUEUE_CREATE_ID,
+	QUEUE_CREATE_POSTPONE,
+	QUEUE_TEMPLATE_TABLE,
+	QUEUE_PATTERN_TEMPLATE,
+	QUEUE_ACTIONS_TEMPLATE,
+	QUEUE_SPEC,
+
+	/* Queue destroy arguments. */
+	QUEUE_DESTROY_ID,
+	QUEUE_DESTROY_POSTPONE,
+
 	/* Table arguments. */
 	TABLE_CREATE,
 	TABLE_DESTROY,
@@ -891,6 +909,8 @@ struct token {
 struct buffer {
 	enum index command; /**< Flow command. */
 	portid_t port; /**< Affected port ID. */
+	queueid_t queue; /** Async queue ID. */
+	bool postpone; /** Postpone async operation */
 	union {
 		struct {
 			struct rte_flow_port_attr port_attr;
@@ -921,6 +941,7 @@ struct buffer {
 			uint32_t action_id;
 		} ia; /* Indirect action query arguments */
 		struct {
+			uint32_t table_id;
 			uint32_t pat_templ_id;
 			uint32_t act_templ_id;
 			struct rte_flow_attr attr;
@@ -1070,6 +1091,18 @@ static const enum index next_table_destroy_attr[] = {
 	ZERO,
 };
 
+static const enum index next_queue_subcmd[] = {
+	QUEUE_CREATE,
+	QUEUE_DESTROY,
+	ZERO,
+};
+
+static const enum index next_queue_destroy_attr[] = {
+	QUEUE_DESTROY_ID,
+	END,
+	ZERO,
+};
+
 static const enum index next_ia_create_attr[] = {
 	INDIRECT_ACTION_CREATE_ID,
 	INDIRECT_ACTION_INGRESS,
@@ -2120,6 +2153,12 @@ static int parse_table(struct context *, const struct token *,
 static int parse_table_destroy(struct context *, const struct token *,
 			       const char *, unsigned int,
 			       void *, unsigned int);
+static int parse_qo(struct context *, const struct token *,
+		    const char *, unsigned int,
+		    void *, unsigned int);
+static int parse_qo_destroy(struct context *, const struct token *,
+			    const char *, unsigned int,
+			    void *, unsigned int);
 static int parse_tunnel(struct context *, const struct token *,
 			const char *, unsigned int,
 			void *, unsigned int);
@@ -2195,6 +2234,8 @@ static int comp_actions_template_id(struct context *, const struct token *,
 				    unsigned int, char *, unsigned int);
 static int comp_table_id(struct context *, const struct token *,
 			 unsigned int, char *, unsigned int);
+static int comp_queue_id(struct context *, const struct token *,
+			 unsigned int, char *, unsigned int);
 
 /** Token definitions. */
 static const struct token token_list[] = {
@@ -2366,6 +2407,13 @@ static const struct token token_list[] = {
 		.call = parse_int,
 		.comp = comp_table_id,
 	},
+	[COMMON_QUEUE_ID] = {
+		.name = "{queue_id}",
+		.type = "QUEUE_ID",
+		.help = "queue id",
+		.call = parse_int,
+		.comp = comp_queue_id,
+	},
 	/* Top-level command. */
 	[FLOW] = {
 		.name = "flow",
@@ -2388,7 +2436,8 @@ static const struct token token_list[] = {
 			      QUERY,
 			      ISOLATE,
 			      TUNNEL,
-			      FLEX)),
+			      FLEX,
+			      QUEUE)),
 		.call = parse_init,
 	},
 	/* Top-level command. */
@@ -2655,6 +2704,84 @@ static const struct token token_list[] = {
 		.call = parse_table,
 	},
 	/* Top-level command. */
+	[QUEUE] = {
+		.name = "queue",
+		.help = "queue a flow rule operation",
+		.next = NEXT(next_queue_subcmd, NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_qo,
+	},
+	/* Sub-level commands. */
+	[QUEUE_CREATE] = {
+		.name = "create",
+		.help = "create a flow rule",
+		.next = NEXT(NEXT_ENTRY(QUEUE_TEMPLATE_TABLE),
+			     NEXT_ENTRY(COMMON_QUEUE_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, queue)),
+		.call = parse_qo,
+	},
+	[QUEUE_DESTROY] = {
+		.name = "destroy",
+		.help = "destroy a flow rule",
+		.next = NEXT(NEXT_ENTRY(QUEUE_DESTROY_ID),
+			     NEXT_ENTRY(COMMON_QUEUE_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, queue)),
+		.call = parse_qo_destroy,
+	},
+	/* Queue  arguments. */
+	[QUEUE_TEMPLATE_TABLE] = {
+		.name = "template table",
+		.help = "specify table id",
+		.next = NEXT(NEXT_ENTRY(QUEUE_PATTERN_TEMPLATE),
+			     NEXT_ENTRY(COMMON_TABLE_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.vc.table_id)),
+		.call = parse_qo,
+	},
+	[QUEUE_PATTERN_TEMPLATE] = {
+		.name = "pattern_template",
+		.help = "specify pattern template index",
+		.next = NEXT(NEXT_ENTRY(QUEUE_ACTIONS_TEMPLATE),
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.vc.pat_templ_id)),
+		.call = parse_qo,
+	},
+	[QUEUE_ACTIONS_TEMPLATE] = {
+		.name = "actions_template",
+		.help = "specify actions template index",
+		.next = NEXT(NEXT_ENTRY(QUEUE_CREATE_POSTPONE),
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.vc.act_templ_id)),
+		.call = parse_qo,
+	},
+	[QUEUE_CREATE_POSTPONE] = {
+		.name = "postpone",
+		.help = "postpone create operation",
+		.next = NEXT(NEXT_ENTRY(ITEM_PATTERN),
+			     NEXT_ENTRY(COMMON_BOOLEAN)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, postpone)),
+		.call = parse_qo,
+	},
+	[QUEUE_DESTROY_POSTPONE] = {
+		.name = "postpone",
+		.help = "postpone destroy operation",
+		.next = NEXT(NEXT_ENTRY(QUEUE_DESTROY_ID),
+			     NEXT_ENTRY(COMMON_BOOLEAN)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, postpone)),
+		.call = parse_qo_destroy,
+	},
+	[QUEUE_DESTROY_ID] = {
+		.name = "rule",
+		.help = "specify rule id to destroy",
+		.next = NEXT(next_queue_destroy_attr,
+			NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_PTR(struct buffer,
+					    args.destroy.rule)),
+		.call = parse_qo_destroy,
+	},
+	/* Top-level command. */
 	[INDIRECT_ACTION] = {
 		.name = "indirect_action",
 		.type = "{command} {port_id} [{arg} [...]]",
@@ -8181,6 +8308,111 @@ parse_table_destroy(struct context *ctx, const struct token *token,
 	return len;
 }
 
+/** Parse tokens for queue create commands. */
+static int
+parse_qo(struct context *ctx, const struct token *token,
+	 const char *str, unsigned int len,
+	 void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != QUEUE)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.vc.data = (uint8_t *)out + size;
+		return len;
+	}
+	switch (ctx->curr) {
+	case QUEUE_CREATE:
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		return len;
+	case QUEUE_TEMPLATE_TABLE:
+	case QUEUE_PATTERN_TEMPLATE:
+	case QUEUE_ACTIONS_TEMPLATE:
+	case QUEUE_CREATE_POSTPONE:
+		return len;
+	case ITEM_PATTERN:
+		out->args.vc.pattern =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		ctx->object = out->args.vc.pattern;
+		ctx->objmask = NULL;
+		return len;
+	case ACTIONS:
+		out->args.vc.actions =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)
+					       (out->args.vc.pattern +
+						out->args.vc.pattern_n),
+					       sizeof(double));
+		ctx->object = out->args.vc.actions;
+		ctx->objmask = NULL;
+		return len;
+	default:
+		return -1;
+	}
+}
+
+/** Parse tokens for queue destroy command. */
+static int
+parse_qo_destroy(struct context *ctx, const struct token *token,
+		 const char *str, unsigned int len,
+		 void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+	uint32_t *flow_id;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command || out->command == QUEUE) {
+		if (ctx->curr != QUEUE_DESTROY)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.destroy.rule =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		return len;
+	}
+	switch (ctx->curr) {
+	case QUEUE_DESTROY_ID:
+		flow_id = out->args.destroy.rule
+				+ out->args.destroy.rule_n++;
+		if ((uint8_t *)flow_id > (uint8_t *)out + size)
+			return -1;
+		ctx->objdata = 0;
+		ctx->object = flow_id;
+		ctx->objmask = NULL;
+		return len;
+	case QUEUE_DESTROY_POSTPONE:
+		return len;
+	default:
+		return -1;
+	}
+}
+
 static int
 parse_flex(struct context *ctx, const struct token *token,
 	     const char *str, unsigned int len,
@@ -9222,6 +9454,28 @@ comp_table_id(struct context *ctx, const struct token *token,
 	return i;
 }
 
+/** Complete available queue IDs. */
+static int
+comp_queue_id(struct context *ctx, const struct token *token,
+	      unsigned int ent, char *buf, unsigned int size)
+{
+	unsigned int i = 0;
+	struct rte_port *port;
+
+	(void)token;
+	if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
+	    ctx->port == (portid_t)RTE_PORT_ALL)
+		return -1;
+	port = &ports[ctx->port];
+	for (i = 0; i < port->queue_nb; i++) {
+		if (buf && i == ent)
+			return snprintf(buf, size, "%u", i);
+	}
+	if (buf)
+		return -1;
+	return i;
+}
+
 /** Internal context. */
 static struct context cmd_flow_context;
 
@@ -9519,6 +9773,17 @@ cmd_flow_parsed(const struct buffer *in)
 					in->args.table_destroy.table_id_n,
 					in->args.table_destroy.table_id);
 		break;
+	case QUEUE_CREATE:
+		port_queue_flow_create(in->port, in->queue, in->postpone,
+				       in->args.vc.table_id, in->args.vc.pat_templ_id,
+				       in->args.vc.act_templ_id, in->args.vc.pattern,
+				       in->args.vc.actions);
+		break;
+	case QUEUE_DESTROY:
+		port_queue_flow_destroy(in->port, in->queue, in->postpone,
+					in->args.destroy.rule_n,
+					in->args.destroy.rule);
+		break;
 	case INDIRECT_ACTION_CREATE:
 		port_action_handle_create(
 				in->port, in->args.vc.attr.group,
app/test-pmd/config.c +166 -0

172 lines not on this page · raw message

app/test-pmd/testpmd.h +7 -0
index 4c6e775bad..d0e1e3eeec 100644
@@ -932,6 +932,13 @@ int port_flow_template_table_create(portid_t port_id, uint32_t id,
 		   uint32_t nb_actions_templates, uint32_t *actions_templates);
 int port_flow_template_table_destroy(portid_t port_id,
 			    uint32_t n, const uint32_t *table);
+int port_queue_flow_create(portid_t port_id, queueid_t queue_id,
+			   bool postpone, uint32_t table_id,
+			   uint32_t pattern_idx, uint32_t actions_idx,
+			   const struct rte_flow_item *pattern,
+			   const struct rte_flow_action *actions);
+int port_queue_flow_destroy(portid_t port_id, queueid_t queue_id,
+			    bool postpone, uint32_t n, const uint32_t *rule);
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
doc/guides/testpmd_app_ug/testpmd_funcs.rst +57 -0

75 lines not on this page · raw message

Signature · 1 line
2.18.2
Acked-by on v4 7/10
#88 lore raw

RE: [PATCH v4 07/10] app/testpmd: implement rte flow queue flow operations

Hi Alexander,

Quoted 13 lines

-----Original Message-----
From: Alexander Kozyrev <[email protected]>
Sent: Wednesday, February 9, 2022 11:38 PM
Subject: [PATCH v4 07/10] app/testpmd: implement rte flow queue flow operations

Add testpmd support for the rte_flow_q_create/rte_flow_q_destroy API. Provide the command line interface for enqueueing flow creation/destruction operations. Usage example:
testpmd> flow queue 0 create 0 postpone no
template_table 6 pattern_template 0 actions_template 0 pattern eth dst is 00:16:3e:31:15:c3 / end actions drop / end
testpmd> flow queue 0 destroy 0 postpone yes rule 0

Quoted 2 lines

---

Best,
Ori

#89 lore raw

PATCH v4 8/10 app/testpmd: implement rte flow push operations

In reply to Alexander Kozyrev

Add testpmd support for the rte_flow_q_push API. Provide the command line interface for pushing operations. Usage example: flow queue 0 push 0

---
 app/test-pmd/cmdline_flow.c                 | 56 ++++++++++++++++++++-
 app/test-pmd/config.c                       | 28 +++++++++++
 app/test-pmd/testpmd.h                      |  1 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst | 21 ++++++++
 4 files changed, 105 insertions(+), 1 deletion(-)
app/test-pmd/cmdline_flow.c +55 -1
index f794a83a07..11240d6f04 100644
@@ -94,6 +94,7 @@ enum index {
 	TUNNEL,
 	FLEX,
 	QUEUE,
+	PUSH,
 
 	/* Flex arguments */
 	FLEX_ITEM_INIT,
@@ -132,6 +133,9 @@ enum index {
 	QUEUE_DESTROY_ID,
 	QUEUE_DESTROY_POSTPONE,
 
+	/* Push arguments. */
+	PUSH_QUEUE,
+
 	/* Table arguments. */
 	TABLE_CREATE,
 	TABLE_DESTROY,
@@ -2159,6 +2163,9 @@ static int parse_qo(struct context *, const struct token *,
 static int parse_qo_destroy(struct context *, const struct token *,
 			    const char *, unsigned int,
 			    void *, unsigned int);
+static int parse_push(struct context *, const struct token *,
+		      const char *, unsigned int,
+		      void *, unsigned int);
 static int parse_tunnel(struct context *, const struct token *,
 			const char *, unsigned int,
 			void *, unsigned int);
@@ -2437,7 +2444,8 @@ static const struct token token_list[] = {
 			      ISOLATE,
 			      TUNNEL,
 			      FLEX,
-			      QUEUE)),
+			      QUEUE,
+			      PUSH)),
 		.call = parse_init,
 	},
 	/* Top-level command. */
@@ -2782,6 +2790,21 @@ static const struct token token_list[] = {
 		.call = parse_qo_destroy,
 	},
 	/* Top-level command. */
+	[PUSH] = {
+		.name = "push",
+		.help = "push enqueued operations",
+		.next = NEXT(NEXT_ENTRY(PUSH_QUEUE), NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_push,
+	},
+	/* Sub-level commands. */
+	[PUSH_QUEUE] = {
+		.name = "queue",
+		.help = "specify queue id",
+		.next = NEXT(NEXT_ENTRY(END), NEXT_ENTRY(COMMON_QUEUE_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, queue)),
+	},
+	/* Top-level command. */
 	[INDIRECT_ACTION] = {
 		.name = "indirect_action",
 		.type = "{command} {port_id} [{arg} [...]]",
@@ -8413,6 +8436,34 @@ parse_qo_destroy(struct context *ctx, const struct token *token,
 	}
 }
 
+/** Parse tokens for push queue command. */
+static int
+parse_push(struct context *ctx, const struct token *token,
+	   const char *str, unsigned int len,
+	   void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != PUSH)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.vc.data = (uint8_t *)out + size;
+	}
+	return len;
+}
+
 static int
 parse_flex(struct context *ctx, const struct token *token,
 	     const char *str, unsigned int len,
@@ -9784,6 +9835,9 @@ cmd_flow_parsed(const struct buffer *in)
 					in->args.destroy.rule_n,
 					in->args.destroy.rule);
 		break;
+	case PUSH:
+		port_queue_flow_push(in->port, in->queue);
+		break;
 	case INDIRECT_ACTION_CREATE:
 		port_action_handle_create(
 				in->port, in->args.vc.attr.group,
app/test-pmd/config.c +28 -0
index e8ae16a044..24660c01dd 100644
@@ -2618,6 +2618,34 @@ port_queue_flow_destroy(portid_t port_id, queueid_t queue_id,
 	return ret;
 }
 
+/** Push all the queue operations in the queue to the NIC. */
+int
+port_queue_flow_push(portid_t port_id, queueid_t queue_id)
+{
+	struct rte_port *port;
+	struct rte_flow_error error;
+	int ret = 0;
+
+	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+	    port_id == (portid_t)RTE_PORT_ALL)
+		return -EINVAL;
+	port = &ports[port_id];
+
+	if (queue_id >= port->queue_nb) {
+		printf("Queue #%u is invalid\n", queue_id);
+		return -EINVAL;
+	}
+
+	memset(&error, 0x55, sizeof(error));
+	ret = rte_flow_q_push(port_id, queue_id, &error);
+	if (ret < 0) {
+		printf("Failed to push operations in the queue\n");
+		return -EINVAL;
+	}
+	printf("Queue #%u operations pushed\n", queue_id);
+	return ret;
+}
+
 /** Create flow rule. */
 int
 port_flow_create(portid_t port_id,
app/test-pmd/testpmd.h +1 -0
index d0e1e3eeec..03f135ff46 100644
@@ -939,6 +939,7 @@ int port_queue_flow_create(portid_t port_id, queueid_t queue_id,
 			   const struct rte_flow_action *actions);
 int port_queue_flow_destroy(portid_t port_id, queueid_t queue_id,
 			    bool postpone, uint32_t n, const uint32_t *rule);
+int port_queue_flow_push(portid_t port_id, queueid_t queue_id);
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
doc/guides/testpmd_app_ug/testpmd_funcs.rst +21 -0
index b802288c66..01e5e3c19f 100644
@@ -3396,6 +3396,10 @@ following sections.
    flow queue {port_id} destroy {queue_id}
        [postpone {boolean}] rule {rule_id} [...]
 
+- Push enqueued operations::
+
+   flow push {port_id} queue {queue_id}
+
 - Create a flow rule::
 
    flow create {port_id}
@@ -3611,6 +3615,23 @@ The usual error message is shown when a table cannot be destroyed::
 
    Caught error type [...] ([...]): [...]
 
+Pushing enqueued operations
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``flow push`` pushes all the outstanding enqueued operations
+to the underlying device immediately.
+It is bound to ``rte_flow_q_push()``::
+
+   flow push {port_id} queue {queue_id}
+
+If successful, it will show::
+
+   Queue #[...] operations pushed
+
+The usual error message is shown when operations cannot be pushed::
+
+   Caught error type [...] ([...]): [...]
+
 Creating a tunnel stub for offload
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.18.2
#90 lore raw

PATCH v4 9/10 app/testpmd: implement rte flow pull operations

In reply to Alexander Kozyrev

Add testpmd support for the rte_flow_q_pull API. Provide the command line interface for pulling operations results. Usage example: flow pull 0 queue 0

---
 app/test-pmd/cmdline_flow.c                 | 56 +++++++++++++++-
 app/test-pmd/config.c                       | 74 +++++++++++++--------
 app/test-pmd/testpmd.h                      |  1 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst | 25 +++++++
 4 files changed, 127 insertions(+), 29 deletions(-)
app/test-pmd/cmdline_flow.c +55 -1
index 11240d6f04..26ef2ccfd4 100644
@@ -95,6 +95,7 @@ enum index {
 	FLEX,
 	QUEUE,
 	PUSH,
+	PULL,
 
 	/* Flex arguments */
 	FLEX_ITEM_INIT,
@@ -136,6 +137,9 @@ enum index {
 	/* Push arguments. */
 	PUSH_QUEUE,
 
+	/* Pull arguments. */
+	PULL_QUEUE,
+
 	/* Table arguments. */
 	TABLE_CREATE,
 	TABLE_DESTROY,
@@ -2166,6 +2170,9 @@ static int parse_qo_destroy(struct context *, const struct token *,
 static int parse_push(struct context *, const struct token *,
 		      const char *, unsigned int,
 		      void *, unsigned int);
+static int parse_pull(struct context *, const struct token *,
+		      const char *, unsigned int,
+		      void *, unsigned int);
 static int parse_tunnel(struct context *, const struct token *,
 			const char *, unsigned int,
 			void *, unsigned int);
@@ -2445,7 +2452,8 @@ static const struct token token_list[] = {
 			      TUNNEL,
 			      FLEX,
 			      QUEUE,
-			      PUSH)),
+			      PUSH,
+			      PULL)),
 		.call = parse_init,
 	},
 	/* Top-level command. */
@@ -2805,6 +2813,21 @@ static const struct token token_list[] = {
 		.args = ARGS(ARGS_ENTRY(struct buffer, queue)),
 	},
 	/* Top-level command. */
+	[PULL] = {
+		.name = "pull",
+		.help = "pull flow operations results",
+		.next = NEXT(NEXT_ENTRY(PULL_QUEUE), NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_pull,
+	},
+	/* Sub-level commands. */
+	[PULL_QUEUE] = {
+		.name = "queue",
+		.help = "specify queue id",
+		.next = NEXT(NEXT_ENTRY(END), NEXT_ENTRY(COMMON_QUEUE_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, queue)),
+	},
+	/* Top-level command. */
 	[INDIRECT_ACTION] = {
 		.name = "indirect_action",
 		.type = "{command} {port_id} [{arg} [...]]",
@@ -8464,6 +8487,34 @@ parse_push(struct context *ctx, const struct token *token,
 	return len;
 }
 
+/** Parse tokens for pull command. */
+static int
+parse_pull(struct context *ctx, const struct token *token,
+	   const char *str, unsigned int len,
+	   void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != PULL)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.vc.data = (uint8_t *)out + size;
+	}
+	return len;
+}
+
 static int
 parse_flex(struct context *ctx, const struct token *token,
 	     const char *str, unsigned int len,
@@ -9838,6 +9889,9 @@ cmd_flow_parsed(const struct buffer *in)
 	case PUSH:
 		port_queue_flow_push(in->port, in->queue);
 		break;
+	case PULL:
+		port_queue_flow_pull(in->port, in->queue);
+		break;
 	case INDIRECT_ACTION_CREATE:
 		port_action_handle_create(
 				in->port, in->args.vc.attr.group,
app/test-pmd/config.c +46 -28

110 lines not on this page · raw message

app/test-pmd/testpmd.h +1 -0
index 03f135ff46..6fe829edab 100644
@@ -940,6 +940,7 @@ int port_queue_flow_create(portid_t port_id, queueid_t queue_id,
 int port_queue_flow_destroy(portid_t port_id, queueid_t queue_id,
 			    bool postpone, uint32_t n, const uint32_t *rule);
 int port_queue_flow_push(portid_t port_id, queueid_t queue_id);
+int port_queue_flow_pull(portid_t port_id, queueid_t queue_id);
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
doc/guides/testpmd_app_ug/testpmd_funcs.rst +25 -0
index 01e5e3c19f..d5d9125d50 100644
@@ -3400,6 +3400,10 @@ following sections.
 
    flow push {port_id} queue {queue_id}
 
+- Pull all operations results from a queue::
+
+   flow pull {port_id} queue {queue_id}
+
 - Create a flow rule::
 
    flow create {port_id}
@@ -3632,6 +3636,23 @@ The usual error message is shown when operations cannot be pushed::
 
    Caught error type [...] ([...]): [...]
 
+Pulling flow operations results
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``flow pull`` asks the underlying device about flow queue operations
+results and return all the processed (successfully or not) operations.
+It is bound to ``rte_flow_q_pull()``::
+
+   flow pull {port_id} queue {queue_id}
+
+If successful, it will show::
+
+   Queue #[...] pulled #[...] operations (#[...] failed, #[...] succeeded)
+
+The usual error message is shown when operations results cannot be pulled::
+
+   Caught error type [...] ([...]): [...]
+
 Creating a tunnel stub for offload
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -3762,6 +3783,8 @@ Otherwise it will show an error message of the form::
 This command uses the same pattern items and actions as ``flow create``,
 their format is described in `Creating flow rules`_.
 
+``flow queue pull`` must be called to retrieve the operation status.
+
 Attributes
 ^^^^^^^^^^
 
@@ -4496,6 +4519,8 @@ message is shown when a rule cannot be destroyed::
 
    Caught error type [...] ([...]): [...]
 
+``flow queue pull`` must be called to retrieve the operation status.
+
 Querying flow rules
 ~~~~~~~~~~~~~~~~~~~
 
Signature · 1 line
2.18.2
#91 lore raw

PATCH v4 10/10 app/testpmd: implement rte flow queue indirect actions

In reply to Alexander Kozyrev

Add testpmd support for the rte_flow_q_action_handle API. Provide the command line interface for operations dequeue. Usage example:
flow queue 0 indirect_action 0 create action_id 9
ingress postpone yes action rss / end
flow queue 0 indirect_action 0 update action_id 9
action queue index 0 / end
flow queue 0 indirect_action 0 destroy action_id 9

---
 app/test-pmd/cmdline_flow.c                 | 276 ++++++++++++++++++++
 app/test-pmd/config.c                       | 131 ++++++++++
 app/test-pmd/testpmd.h                      |  10 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  65 +++++
 4 files changed, 482 insertions(+)
app/test-pmd/cmdline_flow.c +276 -0
index 26ef2ccfd4..b9edb1d482 100644
@@ -121,6 +121,7 @@ enum index {
 	/* Queue arguments. */
 	QUEUE_CREATE,
 	QUEUE_DESTROY,
+	QUEUE_INDIRECT_ACTION,
 
 	/* Queue create arguments. */
 	QUEUE_CREATE_ID,
@@ -134,6 +135,26 @@ enum index {
 	QUEUE_DESTROY_ID,
 	QUEUE_DESTROY_POSTPONE,
 
+	/* Queue indirect action arguments */
+	QUEUE_INDIRECT_ACTION_CREATE,
+	QUEUE_INDIRECT_ACTION_UPDATE,
+	QUEUE_INDIRECT_ACTION_DESTROY,
+
+	/* Queue indirect action create arguments */
+	QUEUE_INDIRECT_ACTION_CREATE_ID,
+	QUEUE_INDIRECT_ACTION_INGRESS,
+	QUEUE_INDIRECT_ACTION_EGRESS,
+	QUEUE_INDIRECT_ACTION_TRANSFER,
+	QUEUE_INDIRECT_ACTION_CREATE_POSTPONE,
+	QUEUE_INDIRECT_ACTION_SPEC,
+
+	/* Queue indirect action update arguments */
+	QUEUE_INDIRECT_ACTION_UPDATE_POSTPONE,
+
+	/* Queue indirect action destroy arguments */
+	QUEUE_INDIRECT_ACTION_DESTROY_ID,
+	QUEUE_INDIRECT_ACTION_DESTROY_POSTPONE,
+
 	/* Push arguments. */
 	PUSH_QUEUE,
 
@@ -1102,6 +1123,7 @@ static const enum index next_table_destroy_attr[] = {
 static const enum index next_queue_subcmd[] = {
 	QUEUE_CREATE,
 	QUEUE_DESTROY,
+	QUEUE_INDIRECT_ACTION,
 	ZERO,
 };
 
@@ -1111,6 +1133,36 @@ static const enum index next_queue_destroy_attr[] = {
 	ZERO,
 };
 
+static const enum index next_qia_subcmd[] = {
+	QUEUE_INDIRECT_ACTION_CREATE,
+	QUEUE_INDIRECT_ACTION_UPDATE,
+	QUEUE_INDIRECT_ACTION_DESTROY,
+	ZERO,
+};
+
+static const enum index next_qia_create_attr[] = {
+	QUEUE_INDIRECT_ACTION_CREATE_ID,
+	QUEUE_INDIRECT_ACTION_INGRESS,
+	QUEUE_INDIRECT_ACTION_EGRESS,
+	QUEUE_INDIRECT_ACTION_TRANSFER,
+	QUEUE_INDIRECT_ACTION_CREATE_POSTPONE,
+	QUEUE_INDIRECT_ACTION_SPEC,
+	ZERO,
+};
+
+static const enum index next_qia_update_attr[] = {
+	QUEUE_INDIRECT_ACTION_UPDATE_POSTPONE,
+	QUEUE_INDIRECT_ACTION_SPEC,
+	ZERO,
+};
+
+static const enum index next_qia_destroy_attr[] = {
+	QUEUE_INDIRECT_ACTION_DESTROY_POSTPONE,
+	QUEUE_INDIRECT_ACTION_DESTROY_ID,
+	END,
+	ZERO,
+};
+
 static const enum index next_ia_create_attr[] = {
 	INDIRECT_ACTION_CREATE_ID,
 	INDIRECT_ACTION_INGRESS,
@@ -2167,6 +2219,12 @@ static int parse_qo(struct context *, const struct token *,
 static int parse_qo_destroy(struct context *, const struct token *,
 			    const char *, unsigned int,
 			    void *, unsigned int);
+static int parse_qia(struct context *, const struct token *,
+		     const char *, unsigned int,
+		     void *, unsigned int);
+static int parse_qia_destroy(struct context *, const struct token *,
+			     const char *, unsigned int,
+			     void *, unsigned int);
 static int parse_push(struct context *, const struct token *,
 		      const char *, unsigned int,
 		      void *, unsigned int);
@@ -2744,6 +2802,13 @@ static const struct token token_list[] = {
 		.args = ARGS(ARGS_ENTRY(struct buffer, queue)),
 		.call = parse_qo_destroy,
 	},
+	[QUEUE_INDIRECT_ACTION] = {
+		.name = "indirect_action",
+		.help = "queue indirect actions",
+		.next = NEXT(next_qia_subcmd, NEXT_ENTRY(COMMON_QUEUE_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, queue)),
+		.call = parse_qia,
+	},
 	/* Queue  arguments. */
 	[QUEUE_TEMPLATE_TABLE] = {
 		.name = "template table",
@@ -2797,6 +2862,90 @@ static const struct token token_list[] = {
 					    args.destroy.rule)),
 		.call = parse_qo_destroy,
 	},
+	/* Queue indirect action arguments */
+	[QUEUE_INDIRECT_ACTION_CREATE] = {
+		.name = "create",
+		.help = "create indirect action",
+		.next = NEXT(next_qia_create_attr),
+		.call = parse_qia,
+	},
+	[QUEUE_INDIRECT_ACTION_UPDATE] = {
+		.name = "update",
+		.help = "update indirect action",
+		.next = NEXT(next_qia_update_attr,
+			     NEXT_ENTRY(COMMON_INDIRECT_ACTION_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, args.vc.attr.group)),
+		.call = parse_qia,
+	},
+	[QUEUE_INDIRECT_ACTION_DESTROY] = {
+		.name = "destroy",
+		.help = "destroy indirect action",
+		.next = NEXT(next_qia_destroy_attr),
+		.call = parse_qia_destroy,
+	},
+	/* Indirect action destroy arguments. */
+	[QUEUE_INDIRECT_ACTION_DESTROY_POSTPONE] = {
+		.name = "postpone",
+		.help = "postpone destroy operation",
+		.next = NEXT(next_qia_destroy_attr,
+			     NEXT_ENTRY(COMMON_BOOLEAN)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, postpone)),
+	},
+	[QUEUE_INDIRECT_ACTION_DESTROY_ID] = {
+		.name = "action_id",
+		.help = "specify a indirect action id to destroy",
+		.next = NEXT(next_qia_destroy_attr,
+			     NEXT_ENTRY(COMMON_INDIRECT_ACTION_ID)),
+		.args = ARGS(ARGS_ENTRY_PTR(struct buffer,
+					    args.ia_destroy.action_id)),
+		.call = parse_qia_destroy,
+	},
+	/* Indirect action update arguments. */
+	[QUEUE_INDIRECT_ACTION_UPDATE_POSTPONE] = {
+		.name = "postpone",
+		.help = "postpone update operation",
+		.next = NEXT(next_qia_update_attr,
+			     NEXT_ENTRY(COMMON_BOOLEAN)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, postpone)),
+	},
+	/* Indirect action create arguments. */
+	[QUEUE_INDIRECT_ACTION_CREATE_ID] = {
+		.name = "action_id",
+		.help = "specify a indirect action id to create",
+		.next = NEXT(next_qia_create_attr,
+			     NEXT_ENTRY(COMMON_INDIRECT_ACTION_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, args.vc.attr.group)),
+	},
+	[QUEUE_INDIRECT_ACTION_INGRESS] = {
+		.name = "ingress",
+		.help = "affect rule to ingress",
+		.next = NEXT(next_qia_create_attr),
+		.call = parse_qia,
+	},
+	[QUEUE_INDIRECT_ACTION_EGRESS] = {
+		.name = "egress",
+		.help = "affect rule to egress",
+		.next = NEXT(next_qia_create_attr),
+		.call = parse_qia,
+	},
+	[QUEUE_INDIRECT_ACTION_TRANSFER] = {
+		.name = "transfer",
+		.help = "affect rule to transfer",
+		.next = NEXT(next_qia_create_attr),
+		.call = parse_qia,
+	},
+	[QUEUE_INDIRECT_ACTION_CREATE_POSTPONE] = {
+		.name = "postpone",
+		.help = "postpone create operation",
+		.next = NEXT(next_qia_create_attr,
+			     NEXT_ENTRY(COMMON_BOOLEAN)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, postpone)),
+	},
+	[QUEUE_INDIRECT_ACTION_SPEC] = {
+		.name = "action",
+		.help = "specify action to create indirect handle",
+		.next = NEXT(next_action),
+	},
 	/* Top-level command. */
 	[PUSH] = {
 		.name = "push",
@@ -6209,6 +6358,110 @@ parse_ia_destroy(struct context *ctx, const struct token *token,
 	return len;
 }
 
+/** Parse tokens for indirect action commands. */
+static int
+parse_qia(struct context *ctx, const struct token *token,
+	  const char *str, unsigned int len,
+	  void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != QUEUE)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->args.vc.data = (uint8_t *)out + size;
+		return len;
+	}
+	switch (ctx->curr) {
+	case QUEUE_INDIRECT_ACTION:
+		return len;
+	case QUEUE_INDIRECT_ACTION_CREATE:
+	case QUEUE_INDIRECT_ACTION_UPDATE:
+		out->args.vc.actions =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		out->args.vc.attr.group = UINT32_MAX;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		return len;
+	case QUEUE_INDIRECT_ACTION_EGRESS:
+		out->args.vc.attr.egress = 1;
+		return len;
+	case QUEUE_INDIRECT_ACTION_INGRESS:
+		out->args.vc.attr.ingress = 1;
+		return len;
+	case QUEUE_INDIRECT_ACTION_TRANSFER:
+		out->args.vc.attr.transfer = 1;
+		return len;
+	case QUEUE_INDIRECT_ACTION_CREATE_POSTPONE:
+		return len;
+	default:
+		return -1;
+	}
+}
+
+/** Parse tokens for indirect action destroy command. */
+static int
+parse_qia_destroy(struct context *ctx, const struct token *token,
+		  const char *str, unsigned int len,
+		  void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+	uint32_t *action_id;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command || out->command == QUEUE) {
+		if (ctx->curr != QUEUE_INDIRECT_ACTION_DESTROY)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.ia_destroy.action_id =
+			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+					       sizeof(double));
+		return len;
+	}
+	switch (ctx->curr) {
+	case QUEUE_INDIRECT_ACTION:
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		return len;
+	case QUEUE_INDIRECT_ACTION_DESTROY_ID:
+		action_id = out->args.ia_destroy.action_id
+				+ out->args.ia_destroy.action_id_n++;
+		if ((uint8_t *)action_id > (uint8_t *)out + size)
+			return -1;
+		ctx->objdata = 0;
+		ctx->object = action_id;
+		ctx->objmask = NULL;
+		return len;
+	case QUEUE_INDIRECT_ACTION_DESTROY_POSTPONE:
+		return len;
+	default:
+		return -1;
+	}
+}
+
 /** Parse tokens for meter policy action commands. */
 static int
 parse_mp(struct context *ctx, const struct token *token,
@@ -9892,6 +10145,29 @@ cmd_flow_parsed(const struct buffer *in)
 	case PULL:
 		port_queue_flow_pull(in->port, in->queue);
 		break;
+	case QUEUE_INDIRECT_ACTION_CREATE:
+		port_queue_action_handle_create(
+				in->port, in->queue, in->postpone,
+				in->args.vc.attr.group,
+				&((const struct rte_flow_indir_action_conf) {
+					.ingress = in->args.vc.attr.ingress,
+					.egress = in->args.vc.attr.egress,
+					.transfer = in->args.vc.attr.transfer,
+				}),
+				in->args.vc.actions);
+		break;
+	case QUEUE_INDIRECT_ACTION_DESTROY:
+		port_queue_action_handle_destroy(in->port,
+					   in->queue, in->postpone,
+					   in->args.ia_destroy.action_id_n,
+					   in->args.ia_destroy.action_id);
+		break;
+	case QUEUE_INDIRECT_ACTION_UPDATE:
+		port_queue_action_handle_update(in->port,
+						in->queue, in->postpone,
+						in->args.vc.attr.group,
+						in->args.vc.actions);
+		break;
 	case INDIRECT_ACTION_CREATE:
 		port_action_handle_create(
 				in->port, in->args.vc.attr.group,
app/test-pmd/config.c +131 -0

137 lines not on this page · raw message

app/test-pmd/testpmd.h +10 -0
index 6fe829edab..167f1741dc 100644
@@ -939,6 +939,16 @@ int port_queue_flow_create(portid_t port_id, queueid_t queue_id,
 			   const struct rte_flow_action *actions);
 int port_queue_flow_destroy(portid_t port_id, queueid_t queue_id,
 			    bool postpone, uint32_t n, const uint32_t *rule);
+int port_queue_action_handle_create(portid_t port_id, uint32_t queue_id,
+			bool postpone, uint32_t id,
+			const struct rte_flow_indir_action_conf *conf,
+			const struct rte_flow_action *action);
+int port_queue_action_handle_destroy(portid_t port_id,
+				     uint32_t queue_id, bool postpone,
+				     uint32_t n, const uint32_t *action);
+int port_queue_action_handle_update(portid_t port_id, uint32_t queue_id,
+				    bool postpone, uint32_t id,
+				    const struct rte_flow_action *action);
 int port_queue_flow_push(portid_t port_id, queueid_t queue_id);
 int port_queue_flow_pull(portid_t port_id, queueid_t queue_id);
 int port_flow_validate(portid_t port_id,
doc/guides/testpmd_app_ug/testpmd_funcs.rst +65 -0

83 lines not on this page · raw message

Signature · 1 line
2.18.2
#92 lore raw
In reply to Alexander Kozyrev
Quoted 41 lines · Alexander Kozyrev

Three major changes to a generic RTE Flow API were implemented in order to speed up flow rule insertion/destruction and adapt the API to the needs of a datapath-focused flow rules management applications:

1. Pre-configuration hints.
Application may give us some hints on what type of resources are needed. Introduce the configuration routine to prepare all the needed resources inside a PMD/HW before any flow rules are created at the init stage.

2. Flow grouping using templates.
Use the knowledge about which flow rules are to be used in an application and prepare item and action templates for them in advance. Group flow rules with common patterns and actions together for better resource management.

3. Queue-based flow management.
Perform flow rule insertion/destruction asynchronously to spare the datapath from blocking on RTE Flow API and allow it to continue with packet processing. Enqueue flow rules operations and poll for the results later.

testpmd examples are part of the patch series. PMD changes will follow.

RFC: https://patchwork.dpdk.org/project/dpdk/cover/[email protected]/

---
v4:
- removed structures versioning
- introduced new rte_flow_port_info structure for rte_flow_info_get API
- renamed rte_flow_table_create to rte_flow_template_table_create

v3: addressed review comments and updated documentation
- added API to get info about pre-configurable resources
- renamed rte_flow_item_template to rte_flow_pattern_template
- renamed drain operation attribute to postpone
- renamed rte_flow_q_drain to rte_flow_q_push
- renamed rte_flow_q_dequeue to rte_flow_q_pull

v2: fixed patch series thread

Quoted 12 lines

Alexander Kozyrev (10):
ethdev: introduce flow pre-configuration hints
ethdev: add flow item/action templates
ethdev: bring in async queue-based flow rules operations app/testpmd: implement rte flow configuration app/testpmd: implement rte flow template management app/testpmd: implement rte flow table management app/testpmd: implement rte flow queue flow operations app/testpmd: implement rte flow push operations app/testpmd: implement rte flow pull operations app/testpmd: implement rte flow queue indirect actions

Hi Jerin, Ajit, Ivan,

As far as I can see you did some reviews in the previous versions, but not ack the patch.
Is there any objection to last version of the patch, if not I will proceed with it.

Hi Alex,

As process we require at least one PMD implementation (it can be draft) to justify the API design.

If there is no objection from above reviewers and PMD implementation exists before end of the week, I think we can get the set for -rc1.

Thanks,
ferruh

#93 lore raw

Thanks, Ferruh.
The pmd part is being updated according to the previous API comments. @Suanming Mou is working on it and will send it once ready, before the weekend.

Regards,
Asaf Penso

Quoted 91 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Thursday, February 10, 2022 6:00 PM
To: Alexander Kozyrev <[email protected]>; [email protected]
Cc: Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon (EXTERNAL) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 00/10] ethdev: datapath-focused flow rules management

Quoted 8 lines · Alexander Kozyrev

Three major changes to a generic RTE Flow API were implemented in order to speed up flow rule insertion/destruction and adapt the API to the needs of a datapath-focused flow rules management applications:

1. Pre-configuration hints.
Application may give us some hints on what type of resources are needed. Introduce the configuration routine to prepare all the needed resources inside a PMD/HW before any flow rules are created at the init

stage.

Quoted 5 lines

2. Flow grouping using templates.
Use the knowledge about which flow rules are to be used in an application and prepare item and action templates for them in advance. Group flow rules with common patterns and actions together for better

resource management.

Quoted 4 lines

3. Queue-based flow management.
Perform flow rule insertion/destruction asynchronously to spare the datapath from blocking on RTE Flow API and allow it to continue with packet

processing.

Quoted 6 lines

Enqueue flow rules operations and poll for the results later.

testpmd examples are part of the patch series. PMD changes will follow.

RFC:
https://patchwork.dpdk.org/project/dpdk/cover/20211006044835.3936226-

1

Quoted 21 lines

[email protected]/

---
v4:
- removed structures versioning
- introduced new rte_flow_port_info structure for rte_flow_info_get API
- renamed rte_flow_table_create to rte_flow_template_table_create

v3: addressed review comments and updated documentation
- added API to get info about pre-configurable resources
- renamed rte_flow_item_template to rte_flow_pattern_template
- renamed drain operation attribute to postpone
- renamed rte_flow_q_drain to rte_flow_q_push
- renamed rte_flow_q_dequeue to rte_flow_q_pull

v2: fixed patch series thread

Quoted 12 lines

Alexander Kozyrev (10):
ethdev: introduce flow pre-configuration hints
ethdev: add flow item/action templates
ethdev: bring in async queue-based flow rules operations app/testpmd: implement rte flow configuration app/testpmd: implement rte flow template management app/testpmd: implement rte flow table management app/testpmd: implement rte flow queue flow operations app/testpmd: implement rte flow push operations app/testpmd: implement rte flow pull operations app/testpmd: implement rte flow queue indirect actions

Hi Jerin, Ajit, Ivan,

As far as I can see you did some reviews in the previous versions, but not ack the patch.
Is there any objection to last version of the patch, if not I will proceed with it.

Hi Alex,

As process we require at least one PMD implementation (it can be draft) to justify the API design.

If there is no objection from above reviewers and PMD implementation exists before end of the week, I think we can get the set for -rc1.

Thanks,
ferruh

#94 lore raw

Hi,

I wish the PMD part is not too late. You can find the series here:
https://patches.dpdk.org/project/dpdk/cover/[email protected]/

Thanks,
Suanming Mou

Quoted 115 lines

-----Original Message-----
From: Asaf Penso <[email protected]>
Sent: Friday, February 11, 2022 12:12 AM
To: Ferruh Yigit <[email protected]>; Alexander Kozyrev <[email protected]>; [email protected]; Suanming Mou <[email protected]>
Cc: Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon (EXTERNAL) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v4 00/10] ethdev: datapath-focused flow rules management

Thanks, Ferruh.
The pmd part is being updated according to the previous API comments. @Suanming Mou is working on it and will send it once ready, before the weekend.

Regards,
Asaf Penso

Quoted 93 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Thursday, February 10, 2022 6:00 PM
To: Alexander Kozyrev <[email protected]>; [email protected]
Cc: Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon (EXTERNAL) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 00/10] ethdev: datapath-focused flow rules management

Quoted 9 lines · Alexander Kozyrev

Three major changes to a generic RTE Flow API were implemented in order to speed up flow rule insertion/destruction and adapt the API to the needs of a datapath-focused flow rules management applications:

1. Pre-configuration hints.
Application may give us some hints on what type of resources are needed. Introduce the configuration routine to prepare all the needed resources inside a PMD/HW before any flow rules are created at the init

stage.

Quoted 5 lines

2. Flow grouping using templates.
Use the knowledge about which flow rules are to be used in an application and prepare item and action templates for them in advance. Group flow rules with common patterns and actions together for better

resource management.

Quoted 5 lines

3. Queue-based flow management.
Perform flow rule insertion/destruction asynchronously to spare the datapath from blocking on RTE Flow API and allow it to continue with packet

processing.

Quoted 6 lines

Enqueue flow rules operations and poll for the results later.

testpmd examples are part of the patch series. PMD changes will follow.

RFC:
https://patchwork.dpdk.org/project/dpdk/cover/20211006044835.3936226-

1

Quoted 21 lines

[email protected]/

---
v4:
- removed structures versioning
- introduced new rte_flow_port_info structure for rte_flow_info_get API
- renamed rte_flow_table_create to rte_flow_template_table_create

v3: addressed review comments and updated documentation
- added API to get info about pre-configurable resources
- renamed rte_flow_item_template to rte_flow_pattern_template
- renamed drain operation attribute to postpone
- renamed rte_flow_q_drain to rte_flow_q_push
- renamed rte_flow_q_dequeue to rte_flow_q_pull

v2: fixed patch series thread

Quoted 12 lines

Alexander Kozyrev (10):
ethdev: introduce flow pre-configuration hints
ethdev: add flow item/action templates
ethdev: bring in async queue-based flow rules operations app/testpmd: implement rte flow configuration app/testpmd: implement rte flow template management app/testpmd: implement rte flow table management app/testpmd: implement rte flow queue flow operations app/testpmd: implement rte flow push operations app/testpmd: implement rte flow pull operations app/testpmd: implement rte flow queue indirect actions

Hi Jerin, Ajit, Ivan,

As far as I can see you did some reviews in the previous versions, but not ack the patch.
Is there any objection to last version of the patch, if not I will proceed with it.

Hi Alex,

As process we require at least one PMD implementation (it can be draft) to justify the API design.

If there is no objection from above reviewers and PMD implementation exists before end of the week, I think we can get the set for -rc1.

Thanks,
ferruh

Acked-by
#95 lore raw
In reply to Ferruh Yigit
Quoted 56 lines · Ferruh Yigit
Quoted 41 lines · Alexander Kozyrev

Three major changes to a generic RTE Flow API were implemented in order to speed up flow rule insertion/destruction and adapt the API to the needs of a datapath-focused flow rules management applications:

1. Pre-configuration hints.
Application may give us some hints on what type of resources are needed. Introduce the configuration routine to prepare all the needed resources inside a PMD/HW before any flow rules are created at the init stage.

2. Flow grouping using templates.
Use the knowledge about which flow rules are to be used in an application and prepare item and action templates for them in advance. Group flow rules with common patterns and actions together for better resource management.

3. Queue-based flow management.
Perform flow rule insertion/destruction asynchronously to spare the datapath from blocking on RTE Flow API and allow it to continue with packet processing. Enqueue flow rules operations and poll for the results later.

testpmd examples are part of the patch series. PMD changes will follow.

RFC: https://patchwork.dpdk.org/project/dpdk/cover/[email protected]/

---
v4:
- removed structures versioning
- introduced new rte_flow_port_info structure for rte_flow_info_get API
- renamed rte_flow_table_create to rte_flow_template_table_create

v3: addressed review comments and updated documentation
- added API to get info about pre-configurable resources
- renamed rte_flow_item_template to rte_flow_pattern_template
- renamed drain operation attribute to postpone
- renamed rte_flow_q_drain to rte_flow_q_push
- renamed rte_flow_q_dequeue to rte_flow_q_pull

v2: fixed patch series thread

Quoted 12 lines

Alexander Kozyrev (10):
ethdev: introduce flow pre-configuration hints
ethdev: add flow item/action templates
ethdev: bring in async queue-based flow rules operations app/testpmd: implement rte flow configuration app/testpmd: implement rte flow template management app/testpmd: implement rte flow table management app/testpmd: implement rte flow queue flow operations app/testpmd: implement rte flow push operations app/testpmd: implement rte flow pull operations app/testpmd: implement rte flow queue indirect actions

Quoted 6 lines

Hi Jerin, Ajit, Ivan,

As far as I can see you did some reviews in the previous versions, but not ack the patch.
Is there any objection to last version of the patch, if not I will proceed with it.

The latest set is looking good. There are some places where we could cleanup or rephrase the text. But that need not block the series. So for the series

Thanks for checking.

Quoted 12 lines

Hi Alex,

As process we require at least one PMD implementation (it can be draft) to justify the API design.

If there is no objection from above reviewers and PMD implementation exists before end of the week, I think we can get the set for -rc1.

Thanks,
ferruh

#96 lore raw
In reply to Ferruh Yigit

Hi Ferruh,

Quoted 55 lines · Ferruh Yigit
Quoted 41 lines · Alexander Kozyrev

Three major changes to a generic RTE Flow API were implemented in order to speed up flow rule insertion/destruction and adapt the API to the needs of a datapath-focused flow rules management applications:

1. Pre-configuration hints.
Application may give us some hints on what type of resources are needed. Introduce the configuration routine to prepare all the needed resources inside a PMD/HW before any flow rules are created at the init stage.

2. Flow grouping using templates.
Use the knowledge about which flow rules are to be used in an application and prepare item and action templates for them in advance. Group flow rules with common patterns and actions together for better resource management.

3. Queue-based flow management.
Perform flow rule insertion/destruction asynchronously to spare the datapath from blocking on RTE Flow API and allow it to continue with packet processing. Enqueue flow rules operations and poll for the results later.

testpmd examples are part of the patch series. PMD changes will follow.

RFC: https://patchwork.dpdk.org/project/dpdk/cover/[email protected]/

---
v4:
- removed structures versioning
- introduced new rte_flow_port_info structure for rte_flow_info_get API
- renamed rte_flow_table_create to rte_flow_template_table_create

v3: addressed review comments and updated documentation
- added API to get info about pre-configurable resources
- renamed rte_flow_item_template to rte_flow_pattern_template
- renamed drain operation attribute to postpone
- renamed rte_flow_q_drain to rte_flow_q_push
- renamed rte_flow_q_dequeue to rte_flow_q_pull

v2: fixed patch series thread

Quoted 12 lines

Alexander Kozyrev (10):
ethdev: introduce flow pre-configuration hints
ethdev: add flow item/action templates
ethdev: bring in async queue-based flow rules operations app/testpmd: implement rte flow configuration app/testpmd: implement rte flow template management app/testpmd: implement rte flow table management app/testpmd: implement rte flow queue flow operations app/testpmd: implement rte flow push operations app/testpmd: implement rte flow pull operations app/testpmd: implement rte flow queue indirect actions

Quoted 4 lines

Hi Jerin, Ajit, Ivan,

As far as I can see you did some reviews in the previous versions, but not ack the patch.

Thanks for sending the reminder. Yes, I did review the series. During the review, we did not find a common ground with regard to possibly having a universal "task enqueue" method. However, I was assured that such design would affect performance.

Quoted 2 lines

Is there any objection to last version of the patch, if not I will proceed with it.

Personally, I have no strong objections. The v5 series seems a lot clearer in a number of ways, yet, it is going to be experimental, so I believe that if we run into some issues with this deisgn, we will still have a chance to improve it to some extent. In general, the author did a very good job applying that many review notes. Thanks to Alexander for perseverance.

Please feel free to proceed with the series as you see fit.

Quoted 4 lines

Hi Alex,

Quoted 9 lines

As process we require at least one PMD implementation (it can be draft) to justify the API design.

If there is no objection from above reviewers and PMD implementation exists before end of the week, I think we can get the set for -rc1.

Thanks,
ferruh

--
Ivan M

#97 lore raw
In reply to Ferruh Yigit
Quoted 56 lines · Ferruh Yigit
Quoted 41 lines · Alexander Kozyrev

Three major changes to a generic RTE Flow API were implemented in order to speed up flow rule insertion/destruction and adapt the API to the needs of a datapath-focused flow rules management applications:

1. Pre-configuration hints.
Application may give us some hints on what type of resources are needed. Introduce the configuration routine to prepare all the needed resources inside a PMD/HW before any flow rules are created at the init stage.

2. Flow grouping using templates.
Use the knowledge about which flow rules are to be used in an application and prepare item and action templates for them in advance. Group flow rules with common patterns and actions together for better resource management.

3. Queue-based flow management.
Perform flow rule insertion/destruction asynchronously to spare the datapath from blocking on RTE Flow API and allow it to continue with packet processing. Enqueue flow rules operations and poll for the results later.

testpmd examples are part of the patch series. PMD changes will follow.

RFC: https://patchwork.dpdk.org/project/dpdk/cover/[email protected]/

---
v4:
- removed structures versioning
- introduced new rte_flow_port_info structure for rte_flow_info_get API
- renamed rte_flow_table_create to rte_flow_template_table_create

v3: addressed review comments and updated documentation
- added API to get info about pre-configurable resources
- renamed rte_flow_item_template to rte_flow_pattern_template
- renamed drain operation attribute to postpone
- renamed rte_flow_q_drain to rte_flow_q_push
- renamed rte_flow_q_dequeue to rte_flow_q_pull

v2: fixed patch series thread

Quoted 12 lines

Alexander Kozyrev (10):
ethdev: introduce flow pre-configuration hints
ethdev: add flow item/action templates
ethdev: bring in async queue-based flow rules operations app/testpmd: implement rte flow configuration app/testpmd: implement rte flow template management app/testpmd: implement rte flow table management app/testpmd: implement rte flow queue flow operations app/testpmd: implement rte flow push operations app/testpmd: implement rte flow pull operations app/testpmd: implement rte flow queue indirect actions

Quoted 6 lines

Hi Jerin, Ajit, Ivan,

As far as I can see you did some reviews in the previous versions, but not ack the patch.
Is there any objection to last version of the patch, if not I will proceed with it.

Personally, I have no strong objections. Based on the top level review, It looks good to me on the application API side.
Please feel free to proceed with the series as you see fit.

Quoted 11 lines

Hi Alex,

As process we require at least one PMD implementation (it can be draft) to justify the API design.

If there is no objection from above reviewers and PMD implementation exists before end of the week, I think we can get the set for -rc1.

Thanks,
ferruh

#98 lore raw

v5 cover ethdev: datapath-focused flow rules management

In reply to Alexander Kozyrev

Three major changes to a generic RTE Flow API were implemented in order to speed up flow rule insertion/destruction and adapt the API to the needs of a datapath-focused flow rules management applications:

1. Pre-configuration hints.
Application may give us some hints on what type of resources are needed. Introduce the configuration routine to prepare all the needed resources inside a PMD/HW before any flow rules are created at the init stage.

2. Flow grouping using templates.
Use the knowledge about which flow rules are to be used in an application and prepare item and action templates for them in advance. Group flow rules with common patterns and actions together for better resource management.

3. Queue-based flow management.
Perform flow rule insertion/destruction asynchronously to spare the datapath from blocking on RTE Flow API and allow it to continue with packet processing. Enqueue flow rules operations and poll for the results later.

testpmd examples are part of the patch series. PMD changes will follow.

RFC: https://patchwork.dpdk.org/project/dpdk/cover/[email protected]/

---
v5: cahnged titles for testpmd commits

v4:
- removed structures versioning
- introduced new rte_flow_port_info structure for rte_flow_info_get API
- renamed rte_flow_table_create to rte_flow_template_table_create

v3: addressed review comments and updated documentation
- added API to get info about pre-configurable resources
- renamed rte_flow_item_template to rte_flow_pattern_template
- renamed drain operation attribute to postpone
- renamed rte_flow_q_drain to rte_flow_q_push
- renamed rte_flow_q_dequeue to rte_flow_q_pull

v2: fixed patch series thread

Alexander Kozyrev (10):
ethdev: introduce flow pre-configuration hints
ethdev: add flow item/action templates
ethdev: bring in async queue-based flow rules operations app/testpmd: add flow engine configuration app/testpmd: add flow template management app/testpmd: add flow table management app/testpmd: add async flow create/destroy operations app/testpmd: add flow queue push operation app/testpmd: add flow queue pull operation app/testpmd: add async indirect actions creation/destruction

 app/test-pmd/cmdline_flow.c                   | 1496 ++++++++++++++++-
 app/test-pmd/config.c                         |  772 +++++++++
 app/test-pmd/testpmd.h                        |   66 +
 doc/guides/prog_guide/img/rte_flow_q_init.svg |  205 +++
 .../prog_guide/img/rte_flow_q_usage.svg       |  351 ++++
 doc/guides/prog_guide/rte_flow.rst            |  326 ++++
 doc/guides/rel_notes/release_22_03.rst        |   22 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst   |  378 ++++-
 lib/ethdev/rte_flow.c                         |  360 ++++
 lib/ethdev/rte_flow.h                         |  702 ++++++++
 lib/ethdev/rte_flow_driver.h                  |  102 ++
 lib/ethdev/version.map                        |   15 +
 12 files changed, 4775 insertions(+), 20 deletions(-)
 create mode 100644 doc/guides/prog_guide/img/rte_flow_q_init.svg
 create mode 100644 doc/guides/prog_guide/img/rte_flow_q_usage.svg
Signature · 1 line
2.18.2
#99 lore raw

PATCH v5 1/10 ethdev: introduce flow pre-configuration hints

The flow rules creation/destruction at a large scale incurs a performance penalty and may negatively impact the packet processing when used as part of the datapath logic. This is mainly because software/hardware resources are allocated and prepared during the flow rule creation.

In order to optimize the insertion rate, PMD may use some hints provided by the application at the initialization phase. The rte_flow_configure() function allows to pre-allocate all the needed resources beforehand. These resources can be used at a later stage without costly allocations. Every PMD may use only the subset of hints and ignore unused ones or fail in case the requested configuration is not supported.

The rte_flow_info_get() is available to retrieve the information about supported pre-configurable resources. Both these functions must be called before any other usage of the flow API engine.

---
 doc/guides/prog_guide/rte_flow.rst     |  37 +++++++++
 doc/guides/rel_notes/release_22_03.rst |   6 ++
 lib/ethdev/rte_flow.c                  |  40 +++++++++
 lib/ethdev/rte_flow.h                  | 108 +++++++++++++++++++++++++
 lib/ethdev/rte_flow_driver.h           |  10 +++
 lib/ethdev/version.map                 |   2 +
 6 files changed, 203 insertions(+)
doc/guides/prog_guide/rte_flow.rst +37 -0
index b4aa9c47c2..72fb1132ac 100644
@@ -3589,6 +3589,43 @@ Return values:
 
 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
 
+Flow engine configuration
+-------------------------
+
+Configure flow API management.
+
+An application may provide some parameters at the initialization phase about
+rules engine configuration and/or expected flow rules characteristics.
+These parameters may be used by PMD to preallocate resources and configure NIC.
+
+Configuration
+~~~~~~~~~~~~~
+
+This function performs the flow API management configuration and
+pre-allocates needed resources beforehand to avoid costly allocations later.
+Expected number of counters or meters in an application, for example,
+allow PMD to prepare and optimize NIC memory layout in advance.
+``rte_flow_configure()`` must be called before any flow rule is created,
+but after an Ethernet device is configured.
+
+.. code-block:: c
+
+   int
+   rte_flow_configure(uint16_t port_id,
+                     const struct rte_flow_port_attr *port_attr,
+                     struct rte_flow_error *error);
+
+Information about resources that can benefit from pre-allocation can be
+retrieved via ``rte_flow_info_get()`` API. It returns the maximum number
+of pre-configurable resources for a given port on a system.
+
+.. code-block:: c
+
+   int
+   rte_flow_info_get(uint16_t port_id,
+                     struct rte_flow_port_info *port_info,
+                     struct rte_flow_error *error);
+
 .. _flow_isolated_mode:
 
 Flow isolated mode
doc/guides/rel_notes/release_22_03.rst +6 -0
index f03183ee86..2a47a37f0a 100644
@@ -69,6 +69,12 @@ New Features
   New APIs, ``rte_eth_dev_priority_flow_ctrl_queue_info_get()`` and
   ``rte_eth_dev_priority_flow_ctrl_queue_configure()``, was added.
 
+* ** Added functions to configure Flow API engine
+
+  * ethdev: Added ``rte_flow_configure`` API to configure Flow Management
+    engine, allowing to pre-allocate some resources for better performance.
+    Added ``rte_flow_info_get`` API to retrieve pre-configurable resources.
+
 * **Updated AF_XDP PMD**
 
   * Added support for libxdp >=v1.2.2.
lib/ethdev/rte_flow.c +40 -0
index a93f68abbc..66614ae29b 100644
@@ -1391,3 +1391,43 @@ rte_flow_flex_item_release(uint16_t port_id,
 	ret = ops->flex_item_release(dev, handle, error);
 	return flow_err(port_id, ret, error);
 }
+
+int
+rte_flow_info_get(uint16_t port_id,
+		  struct rte_flow_port_info *port_info,
+		  struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->info_get)) {
+		return flow_err(port_id,
+				ops->info_get(dev, port_info, error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_configure(uint16_t port_id,
+		   const struct rte_flow_port_attr *port_attr,
+		   struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->configure)) {
+		return flow_err(port_id,
+				ops->configure(dev, port_attr, error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +108 -0

114 lines not on this page · raw message

lib/ethdev/rte_flow_driver.h +10 -0
index f691b04af4..7c29930d0f 100644
@@ -152,6 +152,16 @@ struct rte_flow_ops {
 		(struct rte_eth_dev *dev,
 		 const struct rte_flow_item_flex_handle *handle,
 		 struct rte_flow_error *error);
+	/** See rte_flow_info_get() */
+	int (*info_get)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_port_info *port_info,
+		 struct rte_flow_error *err);
+	/** See rte_flow_configure() */
+	int (*configure)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_port_attr *port_attr,
+		 struct rte_flow_error *err);
 };
 
 /**
lib/ethdev/version.map +2 -0
index cd0c4c428d..f1235aa913 100644
@@ -260,6 +260,8 @@ EXPERIMENTAL {
 	# added in 22.03
 	rte_eth_dev_priority_flow_ctrl_queue_configure;
 	rte_eth_dev_priority_flow_ctrl_queue_info_get;
+	rte_flow_info_get;
+	rte_flow_configure;
 };
 
 INTERNAL {
Signature · 1 line
2.18.2
#100 lore raw

Re: [PATCH v5 01/10] ethdev: introduce flow pre-configuration hints

Quoted 102 lines · Alexander Kozyrev

The flow rules creation/destruction at a large scale incurs a performance penalty and may negatively impact the packet processing when used as part of the datapath logic. This is mainly because software/hardware resources are allocated and prepared during the flow rule creation.

In order to optimize the insertion rate, PMD may use some hints provided by the application at the initialization phase. The rte_flow_configure() function allows to pre-allocate all the needed resources beforehand. These resources can be used at a later stage without costly allocations. Every PMD may use only the subset of hints and ignore unused ones or fail in case the requested configuration is not supported.

The rte_flow_info_get() is available to retrieve the information about supported pre-configurable resources. Both these functions must be called before any other usage of the flow API engine.

---
  doc/guides/prog_guide/rte_flow.rst     |  37 +++++++++
  doc/guides/rel_notes/release_22_03.rst |   6 ++
  lib/ethdev/rte_flow.c                  |  40 +++++++++
  lib/ethdev/rte_flow.h                  | 108 +++++++++++++++++++++++++
  lib/ethdev/rte_flow_driver.h           |  10 +++
  lib/ethdev/version.map                 |   2 +
  6 files changed, 203 insertions(+)
doc/guides/prog_guide/rte_flow.rst +37 -0
index b4aa9c47c2..72fb1132ac 100644
@@ -3589,6 +3589,43 @@ Return values:
 
  - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
 
+Flow engine configuration
+-------------------------
+
+Configure flow API management.
+
+An application may provide some parameters at the initialization phase about
+rules engine configuration and/or expected flow rules characteristics.
+These parameters may be used by PMD to preallocate resources and configure NIC.
+
+Configuration
+~~~~~~~~~~~~~
+
+This function performs the flow API management configuration and
+pre-allocates needed resources beforehand to avoid costly allocations later.
+Expected number of counters or meters in an application, for example,
+allow PMD to prepare and optimize NIC memory layout in advance.
+``rte_flow_configure()`` must be called before any flow rule is created,
+but after an Ethernet device is configured.
+
+.. code-block:: c
+
+   int
+   rte_flow_configure(uint16_t port_id,
+                     const struct rte_flow_port_attr *port_attr,
+                     struct rte_flow_error *error);
+
+Information about resources that can benefit from pre-allocation can be
+retrieved via ``rte_flow_info_get()`` API. It returns the maximum number
+of pre-configurable resources for a given port on a system.
+
+.. code-block:: c
+
+   int
+   rte_flow_info_get(uint16_t port_id,
+                     struct rte_flow_port_info *port_info,
+                     struct rte_flow_error *error);
+
  .. _flow_isolated_mode:
 
  Flow isolated mode
doc/guides/rel_notes/release_22_03.rst +6 -0
index f03183ee86..2a47a37f0a 100644
@@ -69,6 +69,12 @@ New Features
    New APIs, ``rte_eth_dev_priority_flow_ctrl_queue_info_get()`` and
    ``rte_eth_dev_priority_flow_ctrl_queue_configure()``, was added.
 
+* ** Added functions to configure Flow API engine
+
+  * ethdev: Added ``rte_flow_configure`` API to configure Flow Management
+    engine, allowing to pre-allocate some resources for better performance.
+    Added ``rte_flow_info_get`` API to retrieve pre-configurable resources.
+
  * **Updated AF_XDP PMD**
 
    * Added support for libxdp >=v1.2.2.
lib/ethdev/rte_flow.c +2 -0
index a93f68abbc..66614ae29b 100644
@@ -1391,3 +1391,43 @@ rte_flow_flex_item_release(uint16_t port_id,
  	ret = ops->flex_item_release(dev, handle, error);
  	return flow_err(port_id, ret, error);
  }
+
+int

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1405

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_info_get(uint16_t port_id,
+		  struct rte_flow_port_info *port_info,
+		  struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->info_get)) {

expected ethdev state must be validated. Just configured?

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1407

Quoted 2 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->info_get(dev, port_info, error),

port_info must be checked vs NULL

Quoted 8 lines
lib/ethdev/rte_flow.c +8 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1425

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_configure(uint16_t port_id,
+		   const struct rte_flow_port_attr *port_attr,
+		   struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->configure)) {

The API must validate ethdev state. configured and not started?

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1427

Quoted 2 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->configure(dev, port_attr, error),

port_attr must be checked vs NULL

Quoted 18 lines
lib/ethdev/rte_flow.c +6 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +4 -0
index 1031fb246b..92be2a9a89 100644
@@ -4853,6 +4853,114 @@ rte_flow_flex_item_release(uint16_t port_id,
  			   const struct rte_flow_item_flex_handle *handle,
  			   struct rte_flow_error *error);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4869

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * Information about available pre-configurable resources.
+ * The zero value means a resource cannot be pre-allocated.
+ *
+ */
+struct rte_flow_port_info {
+	/**
+	 * Number of pre-configurable counter actions.
+	 * @see RTE_FLOW_ACTION_TYPE_COUNT
+	 */
+	uint32_t nb_counters;

Name says that it is a number of counters, but description says that it is about actions.
Also I don't understand what does "pre-configurable" mean. Isn't it a maximum number of available counters? If no, how can I find a maximum?

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4874

Quoted 5 lines
lib/ethdev/rte_flow.h +5 -0
+	/**
+	 * Number of pre-configurable aging flows actions.
+	 * @see RTE_FLOW_ACTION_TYPE_AGE
+	 */
+	uint32_t nb_aging_flows;

Same

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4879

Quoted 5 lines
lib/ethdev/rte_flow.h +5 -0
+	/**
+	 * Number of pre-configurable traffic metering actions.
+	 * @see RTE_FLOW_ACTION_TYPE_METER
+	 */
+	uint32_t nb_meters;

Same

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4886

Quoted 7 lines
lib/ethdev/rte_flow.h +7 -0
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Retrieve configuration attributes supported by the port.

Description should be a bit more flow API aware.
Right now it sounds too generic.

Quoted 14 lines
lib/ethdev/rte_flow.h +14 -0
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[out] port_info
+ *   A pointer to a structure of type *rte_flow_port_info*
+ *   to be filled with the contextual information of the port.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4910

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+int
+rte_flow_info_get(uint16_t port_id,
+		  struct rte_flow_port_info *port_info,
+		  struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Resource pre-allocation and pre-configuration settings.

What is the difference between pre-allocation and pre-configuration? Why are both mentioned above, but just pre-configured actions are mentioned below?

Quoted 90 lines
lib/ethdev/rte_flow.h +53 -0
+ * The zero value means on demand resource allocations only.
+ *
+ */
+struct rte_flow_port_attr {
+	/**
+	 * Number of counter actions pre-configured.
+	 * @see RTE_FLOW_ACTION_TYPE_COUNT
+	 */
+	uint32_t nb_counters;
+	/**
+	 * Number of aging flows actions pre-configured.
+	 * @see RTE_FLOW_ACTION_TYPE_AGE
+	 */
+	uint32_t nb_aging_flows;
+	/**
+	 * Number of traffic metering actions pre-configured.
+	 * @see RTE_FLOW_ACTION_TYPE_METER
+	 */
+	uint32_t nb_meters;
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Configure the port's flow API engine.
+ *
+ * This API can only be invoked before the application
+ * starts using the rest of the flow library functions.
+ *
+ * The API can be invoked multiple times to change the
+ * settings. The port, however, may reject the changes.
+ *
+ * Parameters in configuration attributes must not exceed
+ * numbers of resources returned by the rte_flow_info_get API.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] port_attr
+ *   Port configuration attributes.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_configure(uint16_t port_id,
+		   const struct rte_flow_port_attr *port_attr,
+		   struct rte_flow_error *error);
+
  #ifdef __cplusplus
  }
  #endif
lib/ethdev/rte_flow_driver.h +10 -0
index f691b04af4..7c29930d0f 100644
@@ -152,6 +152,16 @@ struct rte_flow_ops {
  		(struct rte_eth_dev *dev,
  		 const struct rte_flow_item_flex_handle *handle,
  		 struct rte_flow_error *error);
+	/** See rte_flow_info_get() */
+	int (*info_get)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_port_info *port_info,
+		 struct rte_flow_error *err);
+	/** See rte_flow_configure() */
+	int (*configure)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_port_attr *port_attr,
+		 struct rte_flow_error *err);
  };
 
  /**
lib/ethdev/version.map +2 -0
index cd0c4c428d..f1235aa913 100644
@@ -260,6 +260,8 @@ EXPERIMENTAL {
  	# added in 22.03
  	rte_eth_dev_priority_flow_ctrl_queue_configure;
  	rte_eth_dev_priority_flow_ctrl_queue_info_get;
+	rte_flow_info_get;
+	rte_flow_configure;
  };
 
  INTERNAL {
#101 lore raw

RE: [PATCH v5 01/10] ethdev: introduce flow pre-configuration hints

Quoted 127 lines · On Friday, February 11, 2022 5:17 Andrew Rybchenko…

Sent: Friday, February 11, 2022 5:17
To: Alexander Kozyrev <[email protected]>; [email protected]
Cc: Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon (EXTERNAL) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 01/10] ethdev: introduce flow pre-configuration hints

Quoted 27 lines · Alexander Kozyrev

The flow rules creation/destruction at a large scale incurs a performance penalty and may negatively impact the packet processing when used as part of the datapath logic. This is mainly because software/hardware resources are allocated and prepared during the flow rule creation.

In order to optimize the insertion rate, PMD may use some hints provided by the application at the initialization phase. The rte_flow_configure() function allows to pre-allocate all the needed resources beforehand. These resources can be used at a later stage without costly allocations. Every PMD may use only the subset of hints and ignore unused ones or fail in case the requested configuration is not supported.

The rte_flow_info_get() is available to retrieve the information about supported pre-configurable resources. Both these functions must be called before any other usage of the flow API engine.

---
  doc/guides/prog_guide/rte_flow.rst     |  37 +++++++++
  doc/guides/rel_notes/release_22_03.rst |   6 ++
  lib/ethdev/rte_flow.c                  |  40 +++++++++
  lib/ethdev/rte_flow.h                  | 108 +++++++++++++++++++++++++
  lib/ethdev/rte_flow_driver.h           |  10 +++
  lib/ethdev/version.map                 |   2 +
  6 files changed, 203 insertions(+)

Review

Quoted 1 line
(quoted diff) +0 -0

b/doc/guides/prog_guide/rte_flow.rst

Quoted 5 lines

index b4aa9c47c2..72fb1132ac 100644

doc/guides/prog_guide/rte_flow.rst +0 -0
@@ -3589,6 +3589,43 @@ Return values:
 

doc/guides/prog_guide/rte_flow.rst Return values: · line 3599

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +8 -0
  - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
 
+Flow engine configuration
+-------------------------
+
+Configure flow API management.
+
+An application may provide some parameters at the initialization phase about
+rules engine configuration and/or expected flow rules characteristics.
+These parameters may be used by PMD to preallocate resources and

configure NIC.

Review

Quoted 33 lines
doc/guides/prog_guide/rte_flow.rst +29 -0
+
+Configuration
+~~~~~~~~~~~~~
+
+This function performs the flow API management configuration and
+pre-allocates needed resources beforehand to avoid costly allocations later.
+Expected number of counters or meters in an application, for example,
+allow PMD to prepare and optimize NIC memory layout in advance.
+``rte_flow_configure()`` must be called before any flow rule is created,
+but after an Ethernet device is configured.
+
+.. code-block:: c
+
+   int
+   rte_flow_configure(uint16_t port_id,
+                     const struct rte_flow_port_attr *port_attr,
+                     struct rte_flow_error *error);
+
+Information about resources that can benefit from pre-allocation can be
+retrieved via ``rte_flow_info_get()`` API. It returns the maximum number
+of pre-configurable resources for a given port on a system.
+
+.. code-block:: c
+
+   int
+   rte_flow_info_get(uint16_t port_id,
+                     struct rte_flow_port_info *port_info,
+                     struct rte_flow_error *error);
+
  .. _flow_isolated_mode:
 
  Flow isolated mode
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_22_03.rst

Quoted 26 lines

index f03183ee86..2a47a37f0a 100644

doc/guides/rel_notes/release_22_03.rst +6 -0
@@ -69,6 +69,12 @@ New Features
    New APIs, ``rte_eth_dev_priority_flow_ctrl_queue_info_get()`` and
    ``rte_eth_dev_priority_flow_ctrl_queue_configure()``, was added.
 
+* ** Added functions to configure Flow API engine
+
+  * ethdev: Added ``rte_flow_configure`` API to configure Flow Management
+    engine, allowing to pre-allocate some resources for better performance.
+    Added ``rte_flow_info_get`` API to retrieve pre-configurable resources.
+
  * **Updated AF_XDP PMD**
 
    * Added support for libxdp >=v1.2.2.
lib/ethdev/rte_flow.c +2 -0
index a93f68abbc..66614ae29b 100644
@@ -1391,3 +1391,43 @@ rte_flow_flex_item_release(uint16_t port_id,
  	ret = ops->flex_item_release(dev, handle, error);
  	return flow_err(port_id, ret, error);
  }
+
+int

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1405

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_info_get(uint16_t port_id,
+		  struct rte_flow_port_info *port_info,
+		  struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->info_get)) {

expected ethdev state must be validated. Just configured?

Quoted 4 lines

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1407

Quoted 2 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->info_get(dev, port_info, error),

port_info must be checked vs NULL

We don’t have any NULL checks for parameters in the whole ret flow API library. See rte_flow_create() for example. attributes, pattern and actions are passed to PMD unchecked.

Quoted 12 lines
Quoted 12 lines
lib/ethdev/rte_flow.c +12 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_configure(uint16_t port_id,
+		   const struct rte_flow_port_attr *port_attr,
+		   struct rte_flow_error *error)
+{
Quoted 8 lines

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1425

Quoted 6 lines
lib/ethdev/rte_flow.c +6 -0
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->configure)) {

The API must validate ethdev state. configured and not started?

Again, we have no such validation for any rte flow API today.

Quoted 5 lines

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1427

Quoted 3 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->configure(dev, port_attr, error),

port_attr must be checked vs NULL

Same.

Quoted 26 lines
Quoted 26 lines
lib/ethdev/rte_flow.c +6 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +12 -0
index 1031fb246b..92be2a9a89 100644
@@ -4853,6 +4853,114 @@ rte_flow_flex_item_release(uint16_t port_id,
  			   const struct rte_flow_item_flex_handle *handle,
  			   struct rte_flow_error *error);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Information about available pre-configurable resources.
+ * The zero value means a resource cannot be pre-allocated.
+ *
+ */
+struct rte_flow_port_info {
+	/**
+	 * Number of pre-configurable counter actions.
+	 * @see RTE_FLOW_ACTION_TYPE_COUNT
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4869

Quoted 2 lines
lib/ethdev/rte_flow.h +2 -0
+	 */
+	uint32_t nb_counters;

Name says that it is a number of counters, but description says that it is about actions.
Also I don't understand what does "pre-configurable" mean. Isn't it a maximum number of available counters? If no, how can I find a maximum?

It is number of pre-allocated and pre-configured actions. How are they pr-configured is up to PDM driver. But let's change to "pre-configured" everywhere. Configuration includes some memory allocation anyway.

Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4874

Quoted 6 lines
lib/ethdev/rte_flow.h +5 -0
+	/**
+	 * Number of pre-configurable aging flows actions.
+	 * @see RTE_FLOW_ACTION_TYPE_AGE
+	 */
+	uint32_t nb_aging_flows;

Same

Ditto.

Quoted 7 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4879

Quoted 5 lines
lib/ethdev/rte_flow.h +5 -0
+	/**
+	 * Number of pre-configurable traffic metering actions.
+	 * @see RTE_FLOW_ACTION_TYPE_METER
+	 */
+	uint32_t nb_meters;

Same

Ditto.

Quoted 10 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4886

Quoted 7 lines
lib/ethdev/rte_flow.h +7 -0
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Retrieve configuration attributes supported by the port.

Description should be a bit more flow API aware.
Right now it sounds too generic.

Ok, how about
"Get information about flow engine pre-configurable resources."

Quoted 20 lines
Quoted 20 lines
lib/ethdev/rte_flow.h +20 -0
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[out] port_info
+ *   A pointer to a structure of type *rte_flow_port_info*
+ *   to be filled with the contextual information of the port.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_info_get(uint16_t port_id,
+		  struct rte_flow_port_info *port_info,
+		  struct rte_flow_error *error);
+
+/**
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4910

Quoted 4 lines
lib/ethdev/rte_flow.h +4 -0
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Resource pre-allocation and pre-configuration settings.

What is the difference between pre-allocation and pre-configuration? Why are both mentioned above, but just pre-configured actions are mentioned below?

Please see answer to this question above.

Quoted 90 lines
Quoted 90 lines
lib/ethdev/rte_flow.h +53 -0
+ * The zero value means on demand resource allocations only.
+ *
+ */
+struct rte_flow_port_attr {
+	/**
+	 * Number of counter actions pre-configured.
+	 * @see RTE_FLOW_ACTION_TYPE_COUNT
+	 */
+	uint32_t nb_counters;
+	/**
+	 * Number of aging flows actions pre-configured.
+	 * @see RTE_FLOW_ACTION_TYPE_AGE
+	 */
+	uint32_t nb_aging_flows;
+	/**
+	 * Number of traffic metering actions pre-configured.
+	 * @see RTE_FLOW_ACTION_TYPE_METER
+	 */
+	uint32_t nb_meters;
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Configure the port's flow API engine.
+ *
+ * This API can only be invoked before the application
+ * starts using the rest of the flow library functions.
+ *
+ * The API can be invoked multiple times to change the
+ * settings. The port, however, may reject the changes.
+ *
+ * Parameters in configuration attributes must not exceed
+ * numbers of resources returned by the rte_flow_info_get API.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] port_attr
+ *   Port configuration attributes.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_configure(uint16_t port_id,
+		   const struct rte_flow_port_attr *port_attr,
+		   struct rte_flow_error *error);
+
  #ifdef __cplusplus
  }
  #endif
lib/ethdev/rte_flow_driver.h +10 -0
index f691b04af4..7c29930d0f 100644
@@ -152,6 +152,16 @@ struct rte_flow_ops {
  		(struct rte_eth_dev *dev,
  		 const struct rte_flow_item_flex_handle *handle,
  		 struct rte_flow_error *error);
+	/** See rte_flow_info_get() */
+	int (*info_get)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_port_info *port_info,
+		 struct rte_flow_error *err);
+	/** See rte_flow_configure() */
+	int (*configure)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_port_attr *port_attr,
+		 struct rte_flow_error *err);
  };
 
  /**
lib/ethdev/version.map +2 -0
index cd0c4c428d..f1235aa913 100644
@@ -260,6 +260,8 @@ EXPERIMENTAL {
  	# added in 22.03
  	rte_eth_dev_priority_flow_ctrl_queue_configure;
  	rte_eth_dev_priority_flow_ctrl_queue_info_get;
+	rte_flow_info_get;
+	rte_flow_configure;
  };
 
  INTERNAL {
#102 lore raw

Re: [PATCH v5 01/10] ethdev: introduce flow pre-configuration hints

Quoted 28 lines · Alexander Kozyrev
Quoted 27 lines · On Friday, February 11, 2022 5:17 Andrew Rybchenko…

Sent: Friday, February 11, 2022 5:17
To: Alexander Kozyrev <[email protected]>; [email protected]
Cc: Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon (EXTERNAL) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 01/10] ethdev: introduce flow pre-configuration hints

Quoted 18 lines · Alexander Kozyrev

The flow rules creation/destruction at a large scale incurs a performance penalty and may negatively impact the packet processing when used as part of the datapath logic. This is mainly because software/hardware resources are allocated and prepared during the flow rule creation.

In order to optimize the insertion rate, PMD may use some hints provided by the application at the initialization phase. The rte_flow_configure() function allows to pre-allocate all the needed resources beforehand. These resources can be used at a later stage without costly allocations. Every PMD may use only the subset of hints and ignore unused ones or fail in case the requested configuration is not supported.

The rte_flow_info_get() is available to retrieve the information about supported pre-configurable resources. Both these functions must be called before any other usage of the flow API engine.

[snip]

Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
lib/ethdev/rte_flow.c +2 -0
index a93f68abbc..66614ae29b 100644
@@ -1391,3 +1391,43 @@ rte_flow_flex_item_release(uint16_t port_id,
   	ret = ops->flex_item_release(dev, handle, error);
   	return flow_err(port_id, ret, error);
   }
+
+int

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1405

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_info_get(uint16_t port_id,
+		  struct rte_flow_port_info *port_info,
+		  struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->info_get)) {

expected ethdev state must be validated. Just configured?

Quoted 7 lines
Quoted 4 lines

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1407

Quoted 2 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->info_get(dev, port_info, error),

port_info must be checked vs NULL

We don’t have any NULL checks for parameters in the whole ret flow API library. See rte_flow_create() for example. attributes, pattern and actions are passed to PMD unchecked.

IMHO it is hardly a good reason to have no such check here. The API is pure control path. So, it must validate all input arguments and it is better to do it in a generic place.

Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
lib/ethdev/rte_flow.c +12 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_configure(uint16_t port_id,
+		   const struct rte_flow_port_attr *port_attr,
+		   struct rte_flow_error *error)
+{
Quoted 8 lines

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1425

Quoted 6 lines
lib/ethdev/rte_flow.c +6 -0
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->configure)) {

The API must validate ethdev state. configured and not started?

Quoted 1 line

Again, we have no such validation for any rte flow API today.

Same here. If documentation defines in which state the API should be called, generic code must guarantee it.

Quoted 41 lines
Quoted 5 lines

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1427

Quoted 3 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->configure(dev, port_attr, error),

port_attr must be checked vs NULL

Same.

Quoted 26 lines
Quoted 26 lines
lib/ethdev/rte_flow.c +6 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +12 -0
index 1031fb246b..92be2a9a89 100644
@@ -4853,6 +4853,114 @@ rte_flow_flex_item_release(uint16_t port_id,
   			   const struct rte_flow_item_flex_handle *handle,
   			   struct rte_flow_error *error);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Information about available pre-configurable resources.
+ * The zero value means a resource cannot be pre-allocated.
+ *
+ */
+struct rte_flow_port_info {
+	/**
+	 * Number of pre-configurable counter actions.
+	 * @see RTE_FLOW_ACTION_TYPE_COUNT
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4869

Quoted 2 lines
lib/ethdev/rte_flow.h +2 -0
+	 */
+	uint32_t nb_counters;

Name says that it is a number of counters, but description says that it is about actions.
Also I don't understand what does "pre-configurable" mean. Isn't it a maximum number of available counters? If no, how can I find a maximum?

Quoted 4 lines

It is number of pre-allocated and pre-configured actions. How are they pr-configured is up to PDM driver. But let's change to "pre-configured" everywhere. Configuration includes some memory allocation anyway.

Sorry, but I still don't understand. I guess HW has a hard limit on a number of counters. How can I get the information?

Quoted 118 lines
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4874

Quoted 6 lines
lib/ethdev/rte_flow.h +5 -0
+	/**
+	 * Number of pre-configurable aging flows actions.
+	 * @see RTE_FLOW_ACTION_TYPE_AGE
+	 */
+	uint32_t nb_aging_flows;

Same

Ditto.

Quoted 7 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4879

Quoted 5 lines
lib/ethdev/rte_flow.h +5 -0
+	/**
+	 * Number of pre-configurable traffic metering actions.
+	 * @see RTE_FLOW_ACTION_TYPE_METER
+	 */
+	uint32_t nb_meters;

Same

Ditto.

Quoted 10 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4886

Quoted 7 lines
lib/ethdev/rte_flow.h +7 -0
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Retrieve configuration attributes supported by the port.

Description should be a bit more flow API aware.
Right now it sounds too generic.

Ok, how about
"Get information about flow engine pre-configurable resources."

Quoted 20 lines
Quoted 20 lines
lib/ethdev/rte_flow.h +20 -0
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[out] port_info
+ *   A pointer to a structure of type *rte_flow_port_info*
+ *   to be filled with the contextual information of the port.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_info_get(uint16_t port_id,
+		  struct rte_flow_port_info *port_info,
+		  struct rte_flow_error *error);
+
+/**
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4910

Quoted 4 lines
lib/ethdev/rte_flow.h +4 -0
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Resource pre-allocation and pre-configuration settings.

What is the difference between pre-allocation and pre-configuration? Why are both mentioned above, but just pre-configured actions are mentioned below?

Please see answer to this question above.

Quoted 56 lines
Quoted 56 lines
lib/ethdev/rte_flow.h +53 -0
+ * The zero value means on demand resource allocations only.
+ *
+ */
+struct rte_flow_port_attr {
+	/**
+	 * Number of counter actions pre-configured.
+	 * @see RTE_FLOW_ACTION_TYPE_COUNT
+	 */
+	uint32_t nb_counters;
+	/**
+	 * Number of aging flows actions pre-configured.
+	 * @see RTE_FLOW_ACTION_TYPE_AGE
+	 */
+	uint32_t nb_aging_flows;
+	/**
+	 * Number of traffic metering actions pre-configured.
+	 * @see RTE_FLOW_ACTION_TYPE_METER
+	 */
+	uint32_t nb_meters;
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Configure the port's flow API engine.
+ *
+ * This API can only be invoked before the application
+ * starts using the rest of the flow library functions.
+ *
+ * The API can be invoked multiple times to change the
+ * settings. The port, however, may reject the changes.
+ *
+ * Parameters in configuration attributes must not exceed
+ * numbers of resources returned by the rte_flow_info_get API.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] port_attr
+ *   Port configuration attributes.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_configure(uint16_t port_id,
+		   const struct rte_flow_port_attr *port_attr,
+		   struct rte_flow_error *error);
+
   #ifdef __cplusplus
   }
   #endif

[snip]

#103 lore raw

RE: [PATCH v5 01/10] ethdev: introduce flow pre-configuration hints

On Wed, Feb 16, 2022 8:03 Andrew Rybchenko <[email protected]>:

Quoted 67 lines · Alexander Kozyrev
Quoted 1 line

On Friday, February 11, 2022 5:17 Andrew Rybchenko

Quoted 3 lines · <[email protected]> wrote:
Quoted 3 lines

Sent: Friday, February 11, 2022 5:17
To: Alexander Kozyrev <[email protected]>; [email protected]
Cc: Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon

(EXTERNAL)

Quoted 1 line
Quoted 1 line

<[email protected]>; [email protected];

[email protected];

Quoted 1 line
Quoted 1 line

[email protected]; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

[email protected]; [email protected]
Subject: Re: [PATCH v5 01/10] ethdev: introduce flow pre-configuration

hints

Quoted 8 lines
Quoted 8 lines · Alexander Kozyrev
Quoted 6 lines

The flow rules creation/destruction at a large scale incurs a performance penalty and may negatively impact the packet processing when used as part of the datapath logic. This is mainly because software/hardware resources are allocated and prepared during the flow rule creation.

In order to optimize the insertion rate, PMD may use some hints

provided

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

by the application at the initialization phase. The rte_flow_configure() function allows to pre-allocate all the needed resources beforehand. These resources can be used at a later stage without costly allocations. Every PMD may use only the subset of hints and ignore unused ones or fail in case the requested configuration is not supported.

The rte_flow_info_get() is available to retrieve the information about supported pre-configurable resources. Both these functions must be

called

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

before any other usage of the flow API engine.

[snip]

Quoted 28 lines
Quoted 27 lines
Quoted 10 lines
lib/ethdev/rte_flow.c +2 -0
index a93f68abbc..66614ae29b 100644
@@ -1391,3 +1391,43 @@ rte_flow_flex_item_release(uint16_t port_id,
   	ret = ops->flex_item_release(dev, handle, error);
   	return flow_err(port_id, ret, error);
   }
+
+int

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1405

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_info_get(uint16_t port_id,
+		  struct rte_flow_port_info *port_info,
+		  struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->info_get)) {

expected ethdev state must be validated. Just configured?

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1407

Quoted 2 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->info_get(dev, port_info, error),

port_info must be checked vs NULL

Quoted 8 lines
Quoted 1 line

We don’t have any NULL checks for parameters in the whole ret flow API

library.

Quoted 1 line

See rte_flow_create() for example. attributes, pattern and actions are

passed to PMD unchecked.

IMHO it is hardly a good reason to have no such check here. The API is pure control path. So, it must validate all input arguments and it is better to do it in a generic place.

Agree, I have no objections to introduce these validation checks on control path. My only concern is the data-path performance, so I'm reluctant to add them to rte_flow_q_create/destroy functions. But let's add NULL checks to configuration routines, ok?

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 8 lines
lib/ethdev/rte_flow.c +8 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1425

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_configure(uint16_t port_id,
+		   const struct rte_flow_port_attr *port_attr,
+		   struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->configure)) {

The API must validate ethdev state. configured and not started?

Quoted 4 lines
Quoted 1 line

Again, we have no such validation for any rte flow API today.

Same here. If documentation defines in which state the API should be called, generic code must guarantee it.

Ok, as long as it stays in the configuration phase only.

Quoted 42 lines
Quoted 7 lines
Quoted 5 lines

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1427

Quoted 3 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->configure(dev, port_attr, error),

port_attr must be checked vs NULL

Same.

Quoted 11 lines
Quoted 11 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t

Quoted 11 lines
lib/ethdev/rte_flow.c +6 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +0 -0
index 1031fb246b..92be2a9a89 100644
@@ -4853,6 +4853,114 @@ rte_flow_flex_item_release(uint16_t

port_id,

Quoted 23 lines
Quoted 23 lines
Quoted 7 lines
lib/ethdev/rte_flow.h +4 -0
   			   const struct rte_flow_item_flex_handle *handle,
   			   struct rte_flow_error *error);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4869

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * Information about available pre-configurable resources.
+ * The zero value means a resource cannot be pre-allocated.
+ *
+ */
+struct rte_flow_port_info {
+	/**
+	 * Number of pre-configurable counter actions.
+	 * @see RTE_FLOW_ACTION_TYPE_COUNT
+	 */
+	uint32_t nb_counters;

Name says that it is a number of counters, but description says that it is about actions.
Also I don't understand what does "pre-configurable" mean. Isn't it a maximum number of available counters? If no, how can I find a maximum?

Quoted 8 lines
Quoted 4 lines

It is number of pre-allocated and pre-configured actions. How are they pr-configured is up to PDM driver. But let's change to "pre-configured" everywhere. Configuration includes some memory allocation anyway.

Sorry, but I still don't understand. I guess HW has a hard limit on a number of counters. How can I get the information?

Sorry for not being clear. These are resources/objects limitation. It may be the hard HW limit on number of counter objects, for example. Or the system has a little of memory and NIC is constrained in memory in its attempt to create these counter objects as another example. In any case, the info_get() API should return the limit to a user.

Quoted 120 lines
Quoted 118 lines
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4874

Quoted 6 lines
lib/ethdev/rte_flow.h +5 -0
+	/**
+	 * Number of pre-configurable aging flows actions.
+	 * @see RTE_FLOW_ACTION_TYPE_AGE
+	 */
+	uint32_t nb_aging_flows;

Same

Ditto.

Quoted 7 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4879

Quoted 5 lines
lib/ethdev/rte_flow.h +5 -0
+	/**
+	 * Number of pre-configurable traffic metering actions.
+	 * @see RTE_FLOW_ACTION_TYPE_METER
+	 */
+	uint32_t nb_meters;

Same

Ditto.

Quoted 10 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4886

Quoted 7 lines
lib/ethdev/rte_flow.h +7 -0
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Retrieve configuration attributes supported by the port.

Description should be a bit more flow API aware.
Right now it sounds too generic.

Ok, how about
"Get information about flow engine pre-configurable resources."

Quoted 20 lines
Quoted 20 lines
lib/ethdev/rte_flow.h +20 -0
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[out] port_info
+ *   A pointer to a structure of type *rte_flow_port_info*
+ *   to be filled with the contextual information of the port.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_info_get(uint16_t port_id,
+		  struct rte_flow_port_info *port_info,
+		  struct rte_flow_error *error);
+
+/**
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4910

Quoted 4 lines
lib/ethdev/rte_flow.h +4 -0
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Resource pre-allocation and pre-configuration settings.

What is the difference between pre-allocation and pre-configuration? Why are both mentioned above, but just pre-configured actions are mentioned below?

Please see answer to this question above.

Quoted 56 lines
Quoted 56 lines
lib/ethdev/rte_flow.h +53 -0
+ * The zero value means on demand resource allocations only.
+ *
+ */
+struct rte_flow_port_attr {
+	/**
+	 * Number of counter actions pre-configured.
+	 * @see RTE_FLOW_ACTION_TYPE_COUNT
+	 */
+	uint32_t nb_counters;
+	/**
+	 * Number of aging flows actions pre-configured.
+	 * @see RTE_FLOW_ACTION_TYPE_AGE
+	 */
+	uint32_t nb_aging_flows;
+	/**
+	 * Number of traffic metering actions pre-configured.
+	 * @see RTE_FLOW_ACTION_TYPE_METER
+	 */
+	uint32_t nb_meters;
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Configure the port's flow API engine.
+ *
+ * This API can only be invoked before the application
+ * starts using the rest of the flow library functions.
+ *
+ * The API can be invoked multiple times to change the
+ * settings. The port, however, may reject the changes.
+ *
+ * Parameters in configuration attributes must not exceed
+ * numbers of resources returned by the rte_flow_info_get API.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] port_attr
+ *   Port configuration attributes.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_configure(uint16_t port_id,
+		   const struct rte_flow_port_attr *port_attr,
+		   struct rte_flow_error *error);
+
   #ifdef __cplusplus
   }
   #endif

[snip]

#104 lore raw

Re: [PATCH v5 01/10] ethdev: introduce flow pre-configuration hints

Quoted 70 lines · Alexander Kozyrev

On Wed, Feb 16, 2022 8:03 Andrew Rybchenko <[email protected]>:

Quoted 69 lines · Alexander Kozyrev
Quoted 1 line

On Friday, February 11, 2022 5:17 Andrew Rybchenko

Quoted 3 lines · <[email protected]> wrote:
Quoted 3 lines

Sent: Friday, February 11, 2022 5:17
To: Alexander Kozyrev <[email protected]>; [email protected]
Cc: Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon

(EXTERNAL)

Quoted 1 line
Quoted 1 line

<[email protected]>; [email protected];

[email protected];

Quoted 1 line
Quoted 1 line

[email protected]; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

[email protected]; [email protected]
Subject: Re: [PATCH v5 01/10] ethdev: introduce flow pre-configuration

hints

Quoted 8 lines
Quoted 8 lines · Alexander Kozyrev
Quoted 6 lines

The flow rules creation/destruction at a large scale incurs a performance penalty and may negatively impact the packet processing when used as part of the datapath logic. This is mainly because software/hardware resources are allocated and prepared during the flow rule creation.

In order to optimize the insertion rate, PMD may use some hints

provided

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

by the application at the initialization phase. The rte_flow_configure() function allows to pre-allocate all the needed resources beforehand. These resources can be used at a later stage without costly allocations. Every PMD may use only the subset of hints and ignore unused ones or fail in case the requested configuration is not supported.

The rte_flow_info_get() is available to retrieve the information about supported pre-configurable resources. Both these functions must be

called

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

before any other usage of the flow API engine.

[snip]

Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
lib/ethdev/rte_flow.c +2 -0
index a93f68abbc..66614ae29b 100644
@@ -1391,3 +1391,43 @@ rte_flow_flex_item_release(uint16_t port_id,
    	ret = ops->flex_item_release(dev, handle, error);
    	return flow_err(port_id, ret, error);
    }
+
+int

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1405

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_info_get(uint16_t port_id,
+		  struct rte_flow_port_info *port_info,
+		  struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->info_get)) {

expected ethdev state must be validated. Just configured?

Quoted 6 lines
Quoted 4 lines

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1407

Quoted 2 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->info_get(dev, port_info, error),

port_info must be checked vs NULL

We don’t have any NULL checks for parameters in the whole ret flow API

library.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

See rte_flow_create() for example. attributes, pattern and actions are

passed to PMD unchecked.

IMHO it is hardly a good reason to have no such check here. The API is pure control path. So, it must validate all input arguments and it is better to do it in a generic place.

Agree, I have no objections to introduce these validation checks on control path.

Good, we have a progress.

Quoted 3 lines

My only concern is the data-path performance, so I'm reluctant to add them to rte_flow_q_create/destroy functions. But let's add NULL checks to configuration routines, ok?

My opinion is not that strong on the aspect, but, personally, I'd have sanity checks in the case of flow create/destroy as well. First of all it is not a true datapath. Second, these checks are very lightweight.

Anyway, if nobody supports me, I'm OK to go without these checks in generic functions, but it would be very useful to highlight it in the parameters description.

Quoted 78 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 8 lines
lib/ethdev/rte_flow.c +8 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1425

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_configure(uint16_t port_id,
+		   const struct rte_flow_port_attr *port_attr,
+		   struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->configure)) {

The API must validate ethdev state. configured and not started?

Quoted 4 lines
Quoted 1 line

Again, we have no such validation for any rte flow API today.

Same here. If documentation defines in which state the API should be called, generic code must guarantee it.

Ok, as long as it stays in the configuration phase only.

Quoted 42 lines
Quoted 7 lines
Quoted 5 lines

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1427

Quoted 3 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->configure(dev, port_attr, error),

port_attr must be checked vs NULL

Same.

Quoted 11 lines
Quoted 11 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t

Quoted 11 lines
lib/ethdev/rte_flow.c +6 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +0 -0
index 1031fb246b..92be2a9a89 100644
@@ -4853,6 +4853,114 @@ rte_flow_flex_item_release(uint16_t

port_id,

Quoted 23 lines
Quoted 23 lines
Quoted 7 lines
lib/ethdev/rte_flow.h +4 -0
    			   const struct rte_flow_item_flex_handle *handle,
    			   struct rte_flow_error *error);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4869

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * Information about available pre-configurable resources.
+ * The zero value means a resource cannot be pre-allocated.
+ *
+ */
+struct rte_flow_port_info {
+	/**
+	 * Number of pre-configurable counter actions.
+	 * @see RTE_FLOW_ACTION_TYPE_COUNT
+	 */
+	uint32_t nb_counters;

Name says that it is a number of counters, but description says that it is about actions.
Also I don't understand what does "pre-configurable" mean. Isn't it a maximum number of available counters? If no, how can I find a maximum?

Quoted 8 lines
Quoted 4 lines

It is number of pre-allocated and pre-configured actions. How are they pr-configured is up to PDM driver. But let's change to "pre-configured" everywhere. Configuration includes some memory allocation anyway.

Sorry, but I still don't understand. I guess HW has a hard limit on a number of counters. How can I get the information?

Quoted 5 lines

Sorry for not being clear. These are resources/objects limitation. It may be the hard HW limit on number of counter objects, for example. Or the system has a little of memory and NIC is constrained in memory in its attempt to create these counter objects as another example. In any case, the info_get() API should return the limit to a user.

Look. First of all it is confusing that description says "counter actions". I remember that we have no shared counters now (just shared actions), but it does not matter a lot. IMHO it is a bit more clear to say that it is a limit on a number of flow counters. I guess it better express the nature of the limitation. May be I'm missing something. If so, I'd like to understand what.

Second, "per-configurable" is confusing. May be it is better just to drop it? I.e. "Information about available resources." Otherwise it is necessary to explain who and when pre-configures these resources. Is it really pre-configured?

"The zero value means a resource cannot be pre-allocated." Does it mean that the action cannot be used at all? I think it must be explicitly clarified in the case of any answer.

#105 lore raw

RE: [PATCH v5 01/10] ethdev: introduce flow pre-configuration hints

Hi Andrew,

Quoted 91 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Thursday, February 17, 2022 12:35 PM
Subject: Re: [PATCH v5 01/10] ethdev: introduce flow pre-configuration hints

Quoted 70 lines · Alexander Kozyrev

On Wed, Feb 16, 2022 8:03 Andrew Rybchenko <[email protected]>:

Quoted 69 lines · Alexander Kozyrev
Quoted 1 line

On Friday, February 11, 2022 5:17 Andrew Rybchenko

Quoted 3 lines · <[email protected]> wrote:
Quoted 3 lines

Sent: Friday, February 11, 2022 5:17
To: Alexander Kozyrev <[email protected]>; [email protected]
Cc: Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon

(EXTERNAL)

Quoted 1 line
Quoted 1 line

<[email protected]>; [email protected];

[email protected];

Quoted 1 line
Quoted 1 line

[email protected]; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

[email protected]; [email protected]
Subject: Re: [PATCH v5 01/10] ethdev: introduce flow pre-configuration

hints

Quoted 8 lines
Quoted 8 lines · Alexander Kozyrev
Quoted 6 lines

The flow rules creation/destruction at a large scale incurs a performance penalty and may negatively impact the packet processing when used as part of the datapath logic. This is mainly because software/hardware resources are allocated and prepared during the flow rule creation.

In order to optimize the insertion rate, PMD may use some hints

provided

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

by the application at the initialization phase. The rte_flow_configure() function allows to pre-allocate all the needed resources beforehand. These resources can be used at a later stage without costly allocations. Every PMD may use only the subset of hints and ignore unused ones or fail in case the requested configuration is not supported.

The rte_flow_info_get() is available to retrieve the information about supported pre-configurable resources. Both these functions must be

called

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

before any other usage of the flow API engine.

[snip]

Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
lib/ethdev/rte_flow.c +2 -0
index a93f68abbc..66614ae29b 100644
@@ -1391,3 +1391,43 @@ rte_flow_flex_item_release(uint16_t port_id,
    	ret = ops->flex_item_release(dev, handle, error);
    	return flow_err(port_id, ret, error);
    }
+
+int

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1405

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_info_get(uint16_t port_id,
+		  struct rte_flow_port_info *port_info,
+		  struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->info_get)) {

expected ethdev state must be validated. Just configured?

Quoted 6 lines
Quoted 4 lines

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1407

Quoted 2 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->info_get(dev, port_info, error),

port_info must be checked vs NULL

We don’t have any NULL checks for parameters in the whole ret flow API

library.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

See rte_flow_create() for example. attributes, pattern and actions are

passed to PMD unchecked.

IMHO it is hardly a good reason to have no such check here. The API is pure control path. So, it must validate all input arguments and it is better to do it in a generic place.

Agree, I have no objections to introduce these validation checks on control path.

Good, we have a progress.

Quoted 3 lines

My only concern is the data-path performance, so I'm reluctant to add them to rte_flow_q_create/destroy functions. But let's add NULL checks to configuration routines, ok?

Quoted 9 lines

My opinion is not that strong on the aspect, but, personally, I'd have sanity checks in the case of flow create/destroy as well. First of all it is not a true datapath. Second, these checks are very lightweight.

Anyway, if nobody supports me, I'm OK to go without these checks in generic functions, but it would be very useful to highlight it in the parameters description.

I vote for adding the checks only on configuration function. From my point of view the rule functions are part of the data path and should be treated this way.

Quoted 84 lines
Quoted 78 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 8 lines
lib/ethdev/rte_flow.c +8 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1425

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_configure(uint16_t port_id,
+		   const struct rte_flow_port_attr *port_attr,
+		   struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->configure)) {

The API must validate ethdev state. configured and not started?

Quoted 4 lines
Quoted 1 line

Again, we have no such validation for any rte flow API today.

Same here. If documentation defines in which state the API should be called, generic code must guarantee it.

Ok, as long as it stays in the configuration phase only.

Quoted 42 lines
Quoted 7 lines
Quoted 5 lines

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1427

Quoted 3 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->configure(dev, port_attr, error),

port_attr must be checked vs NULL

Same.

Quoted 11 lines
Quoted 11 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t

Quoted 11 lines
lib/ethdev/rte_flow.c +6 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +0 -0
index 1031fb246b..92be2a9a89 100644
@@ -4853,6 +4853,114 @@ rte_flow_flex_item_release(uint16_t

port_id,

Quoted 23 lines
Quoted 23 lines
Quoted 7 lines
lib/ethdev/rte_flow.h +4 -0
    			   const struct rte_flow_item_flex_handle *handle,
    			   struct rte_flow_error *error);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4869

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * Information about available pre-configurable resources.
+ * The zero value means a resource cannot be pre-allocated.
+ *
+ */
+struct rte_flow_port_info {
+	/**
+	 * Number of pre-configurable counter actions.
+	 * @see RTE_FLOW_ACTION_TYPE_COUNT
+	 */
+	uint32_t nb_counters;

Name says that it is a number of counters, but description says that it is about actions.
Also I don't understand what does "pre-configurable" mean. Isn't it a maximum number of available counters? If no, how can I find a maximum?

Quoted 8 lines
Quoted 4 lines

It is number of pre-allocated and pre-configured actions. How are they pr-configured is up to PDM driver. But let's change to "pre-configured" everywhere. Configuration includes some memory allocation anyway.

Sorry, but I still don't understand. I guess HW has a hard limit on a number of counters. How can I get the information?

Quoted 5 lines

Sorry for not being clear. These are resources/objects limitation. It may be the hard HW limit on number of counter objects, for example. Or the system has a little of memory and NIC is constrained in memory in its attempt to create these counter objects as another example. In any case, the info_get() API should return the limit to a user.

Quoted 8 lines

Look. First of all it is confusing that description says "counter actions". I remember that we have no shared counters now (just shared actions), but it does not matter a lot. IMHO it is a bit more clear to say that it is a limit on a number of flow counters. I guess it better express the nature of the limitation. May be I'm missing something. If so, I'd like to understand what.

From my view point, this should be the number of resource/objects that the HW can allocate (in an ideal system).
For example if the HW can allocate 1M counters but due to limited memory on the system the actual number can be less.

Like you said we also have the handle action, this means that
the same object can be shared between any number of rules.
as a result the limitation is not on the number of rules but on the number of resources allocated.

In addition and even more importantly during this stage there is no knowlge on the number of rules that will be inserted.

So can we agree to say resources?

Quoted 5 lines

Second, "per-configurable" is confusing. May be it is better just to drop it? I.e. "Information about available resources." Otherwise it is necessary to explain who and when pre-configures these resources. Is it really pre-configured?

I'm O.K with dropping the configuration part
It should just say number of counter objects

Quoted 4 lines

"The zero value means a resource cannot be pre-allocated." Does it mean that the action cannot be used at all? I think it must be explicitly clarified in the case of any answer.

Agree, it should state that if the PMD report 0 in means that it doesn’t support such an object.

Best,
Ori

#106 lore raw

Re: [PATCH v5 01/10] ethdev: introduce flow pre-configuration hints

Quoted 208 lines · Ori Kam

Hi Andrew,

Quoted 91 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Thursday, February 17, 2022 12:35 PM
Subject: Re: [PATCH v5 01/10] ethdev: introduce flow pre-configuration hints

Quoted 70 lines · Alexander Kozyrev

On Wed, Feb 16, 2022 8:03 Andrew Rybchenko <[email protected]>:

Quoted 69 lines · Alexander Kozyrev
Quoted 1 line

On Friday, February 11, 2022 5:17 Andrew Rybchenko

Quoted 3 lines · <[email protected]> wrote:
Quoted 3 lines

Sent: Friday, February 11, 2022 5:17
To: Alexander Kozyrev <[email protected]>; [email protected]
Cc: Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon

(EXTERNAL)

Quoted 1 line
Quoted 1 line

<[email protected]>; [email protected];

[email protected];

Quoted 1 line
Quoted 1 line

[email protected]; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines

[email protected]; [email protected]
Subject: Re: [PATCH v5 01/10] ethdev: introduce flow pre-configuration

hints

Quoted 8 lines
Quoted 8 lines · Alexander Kozyrev
Quoted 6 lines

The flow rules creation/destruction at a large scale incurs a performance penalty and may negatively impact the packet processing when used as part of the datapath logic. This is mainly because software/hardware resources are allocated and prepared during the flow rule creation.

In order to optimize the insertion rate, PMD may use some hints

provided

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

by the application at the initialization phase. The rte_flow_configure() function allows to pre-allocate all the needed resources beforehand. These resources can be used at a later stage without costly allocations. Every PMD may use only the subset of hints and ignore unused ones or fail in case the requested configuration is not supported.

The rte_flow_info_get() is available to retrieve the information about supported pre-configurable resources. Both these functions must be

called

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

before any other usage of the flow API engine.

[snip]

Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
lib/ethdev/rte_flow.c +2 -0
index a93f68abbc..66614ae29b 100644
@@ -1391,3 +1391,43 @@ rte_flow_flex_item_release(uint16_t port_id,
     	ret = ops->flex_item_release(dev, handle, error);
     	return flow_err(port_id, ret, error);
     }
+
+int

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1405

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_info_get(uint16_t port_id,
+		  struct rte_flow_port_info *port_info,
+		  struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->info_get)) {

expected ethdev state must be validated. Just configured?

Quoted 6 lines
Quoted 4 lines

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1407

Quoted 2 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->info_get(dev, port_info, error),

port_info must be checked vs NULL

We don’t have any NULL checks for parameters in the whole ret flow API

library.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

See rte_flow_create() for example. attributes, pattern and actions are

passed to PMD unchecked.

IMHO it is hardly a good reason to have no such check here. The API is pure control path. So, it must validate all input arguments and it is better to do it in a generic place.

Agree, I have no objections to introduce these validation checks on control path.

Good, we have a progress.

Quoted 3 lines

My only concern is the data-path performance, so I'm reluctant to add them to rte_flow_q_create/destroy functions. But let's add NULL checks to configuration routines, ok?

Quoted 9 lines

My opinion is not that strong on the aspect, but, personally, I'd have sanity checks in the case of flow create/destroy as well. First of all it is not a true datapath. Second, these checks are very lightweight.

Anyway, if nobody supports me, I'm OK to go without these checks in generic functions, but it would be very useful to highlight it in the parameters description.

I vote for adding the checks only on configuration function.
From my point of view the rule functions are part of the data path
and should be treated this way.

Quoted 84 lines
Quoted 78 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 8 lines
lib/ethdev/rte_flow.c +8 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1425

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_configure(uint16_t port_id,
+		   const struct rte_flow_port_attr *port_attr,
+		   struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->configure)) {

The API must validate ethdev state. configured and not started?

Quoted 4 lines
Quoted 1 line

Again, we have no such validation for any rte flow API today.

Same here. If documentation defines in which state the API should be called, generic code must guarantee it.

Ok, as long as it stays in the configuration phase only.

Quoted 42 lines
Quoted 7 lines
Quoted 5 lines

lib/ethdev/rte_flow.c rte_flow_flex_item_release(uint16_t port_id, · line 1427

Quoted 3 lines
lib/ethdev/rte_flow.c +2 -0
+		return flow_err(port_id,
+				ops->configure(dev, port_attr, error),

port_attr must be checked vs NULL

Same.

Quoted 11 lines
Quoted 11 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t

Quoted 11 lines
lib/ethdev/rte_flow.c +6 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +0 -0
index 1031fb246b..92be2a9a89 100644
@@ -4853,6 +4853,114 @@ rte_flow_flex_item_release(uint16_t

port_id,

Quoted 23 lines
Quoted 23 lines
Quoted 7 lines
lib/ethdev/rte_flow.h +4 -0
     			   const struct rte_flow_item_flex_handle *handle,
     			   struct rte_flow_error *error);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t · line 4869

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * Information about available pre-configurable resources.
+ * The zero value means a resource cannot be pre-allocated.
+ *
+ */
+struct rte_flow_port_info {
+	/**
+	 * Number of pre-configurable counter actions.
+	 * @see RTE_FLOW_ACTION_TYPE_COUNT
+	 */
+	uint32_t nb_counters;

Name says that it is a number of counters, but description says that it is about actions.
Also I don't understand what does "pre-configurable" mean. Isn't it a maximum number of available counters? If no, how can I find a maximum?

Quoted 8 lines
Quoted 4 lines

It is number of pre-allocated and pre-configured actions. How are they pr-configured is up to PDM driver. But let's change to "pre-configured" everywhere. Configuration includes some memory allocation anyway.

Sorry, but I still don't understand. I guess HW has a hard limit on a number of counters. How can I get the information?

Quoted 5 lines

Sorry for not being clear. These are resources/objects limitation. It may be the hard HW limit on number of counter objects, for example. Or the system has a little of memory and NIC is constrained in memory in its attempt to create these counter objects as another example. In any case, the info_get() API should return the limit to a user.

Quoted 8 lines

Look. First of all it is confusing that description says "counter actions". I remember that we have no shared counters now (just shared actions), but it does not matter a lot. IMHO it is a bit more clear to say that it is a limit on a number of flow counters. I guess it better express the nature of the limitation. May be I'm missing something. If so, I'd like to understand what.

From my view point, this should be the number of resource/objects that
the HW can allocate (in an ideal system).
For example if the HW can allocate 1M counters but due to limited memory on the system the actual number can be less.

Like you said we also have the handle action, this means that
the same object can be shared between any number of rules.
as a result the limitation is not on the number of rules but on the number of resources allocated.

Quoted 4 lines

In addition and even more importantly during this stage there is no knowlge on the number of rules that will be inserted.

So can we agree to say resources?

Yes

Quoted 8 lines
Quoted 5 lines

Second, "per-configurable" is confusing. May be it is better just to drop it? I.e. "Information about available resources." Otherwise it is necessary to explain who and when pre-configures these resources. Is it really pre-configured?

I'm O.K with dropping the configuration part
It should just say number of counter objects

Quoted 7 lines
Quoted 4 lines

"The zero value means a resource cannot be pre-allocated." Does it mean that the action cannot be used at all? I think it must be explicitly clarified in the case of any answer.

Agree, it should state that if the PMD report 0 in means that it doesn’t support such an object.

Good.

#107 lore raw

PATCH v5 2/10 ethdev: add flow item/action templates

In reply to Alexander Kozyrev

Treating every single flow rule as a completely independent and separate entity negatively impacts the flow rules insertion rate. Oftentimes in an application, many flow rules share a common structure (the same item mask and/or action list) so they can be grouped and classified together. This knowledge may be used as a source of optimization by a PMD/HW.

The pattern template defines common matching fields (the item mask) without values. The actions template holds a list of action types that will be used together in the same rule. The specific values for items and actions will be given only during the rule creation.

A table combines pattern and actions templates along with shared flow rule attributes (group ID, priority and traffic direction). This way a PMD/HW can prepare all the resources needed for efficient flow rules creation in the datapath. To avoid any hiccups due to memory reallocation, the maximum number of flow rules is defined at the table creation time.

The flow rule creation is done by selecting a table, a pattern template and an actions template (which are bound to the table), and setting unique values for the items and actions.

---
 doc/guides/prog_guide/rte_flow.rst     | 124 ++++++++++++
 doc/guides/rel_notes/release_22_03.rst |   8 +
 lib/ethdev/rte_flow.c                  | 147 ++++++++++++++
 lib/ethdev/rte_flow.h                  | 260 +++++++++++++++++++++++++
 lib/ethdev/rte_flow_driver.h           |  37 ++++
 lib/ethdev/version.map                 |   6 +
 6 files changed, 582 insertions(+)
doc/guides/prog_guide/rte_flow.rst +124 -0
index 72fb1132ac..5391648833 100644
@@ -3626,6 +3626,130 @@ of pre-configurable resources for a given port on a system.
                      struct rte_flow_port_info *port_info,
                      struct rte_flow_error *error);
 
+Flow templates
+~~~~~~~~~~~~~~
+
+Oftentimes in an application, many flow rules share a common structure
+(the same pattern and/or action list) so they can be grouped and classified
+together. This knowledge may be used as a source of optimization by a PMD/HW.
+The flow rule creation is done by selecting a table, a pattern template
+and an actions template (which are bound to the table), and setting unique
+values for the items and actions. This API is not thread-safe.
+
+Pattern templates
+^^^^^^^^^^^^^^^^^
+
+The pattern template defines a common pattern (the item mask) without values.
+The mask value is used to select a field to match on, spec/last are ignored.
+The pattern template may be used by multiple tables and must not be destroyed
+until all these tables are destroyed first.
+
+.. code-block:: c
+
+	struct rte_flow_pattern_template *
+	rte_flow_pattern_template_create(uint16_t port_id,
+				const struct rte_flow_pattern_template_attr *template_attr,
+				const struct rte_flow_item pattern[],
+				struct rte_flow_error *error);
+
+For example, to create a pattern template to match on the destination MAC:
+
+.. code-block:: c
+
+	struct rte_flow_item pattern[2] = {{0}};
+	struct rte_flow_item_eth eth_m = {0};
+	pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
+	eth_m.dst.addr_bytes = "\xff\xff\xff\xff\xff\xff";
+	pattern[0].mask = &eth_m;
+	pattern[1].type = RTE_FLOW_ITEM_TYPE_END;
+
+	struct rte_flow_pattern_template *pattern_template =
+		rte_flow_pattern_template_create(port, &itr, &pattern, &error);
+
+The concrete value to match on will be provided at the rule creation.
+
+Actions templates
+^^^^^^^^^^^^^^^^^
+
+The actions template holds a list of action types to be used in flow rules.
+The mask parameter allows specifying a shared constant value for every rule.
+The actions template may be used by multiple tables and must not be destroyed
+until all these tables are destroyed first.
+
+.. code-block:: c
+
+	struct rte_flow_actions_template *
+	rte_flow_actions_template_create(uint16_t port_id,
+				const struct rte_flow_actions_template_attr *template_attr,
+				const struct rte_flow_action actions[],
+				const struct rte_flow_action masks[],
+				struct rte_flow_error *error);
+
+For example, to create an actions template with the same Mark ID
+but different Queue Index for every rule:
+
+.. code-block:: c
+
+	struct rte_flow_action actions[] = {
+		/* Mark ID is constant (4) for every rule, Queue Index is unique */
+		[0] = {.type = RTE_FLOW_ACTION_TYPE_MARK,
+			   .conf = &(struct rte_flow_action_mark){.id = 4}},
+		[1] = {.type = RTE_FLOW_ACTION_TYPE_QUEUE},
+		[2] = {.type = RTE_FLOW_ACTION_TYPE_END,},
+	};
+	struct rte_flow_action masks[] = {
+		/* Assign to MARK mask any non-zero value to make it constant */
+		[0] = {.type = RTE_FLOW_ACTION_TYPE_MARK,
+			   .conf = &(struct rte_flow_action_mark){.id = 1}},
+		[1] = {.type = RTE_FLOW_ACTION_TYPE_QUEUE},
+		[2] = {.type = RTE_FLOW_ACTION_TYPE_END,},
+	};
+
+	struct rte_flow_actions_template *at =
+		rte_flow_actions_template_create(port, &atr, &actions, &masks, &error);
+
+The concrete value for Queue Index will be provided at the rule creation.
+
+Template table
+^^^^^^^^^^^^^^
+
+A template table combines a number of pattern and actions templates along with
+shared flow rule attributes (group ID, priority and traffic direction).
+This way a PMD/HW can prepare all the resources needed for efficient flow rules
+creation in the datapath. To avoid any hiccups due to memory reallocation,
+the maximum number of flow rules is defined at table creation time.
+Any flow rule creation beyond the maximum table size is rejected.
+Application may create another table to accommodate more rules in this case.
+
+.. code-block:: c
+
+	struct rte_flow_template_table *
+	rte_flow_template_table_create(uint16_t port_id,
+				const struct rte_flow_template_table_attr *table_attr,
+				struct rte_flow_pattern_template *pattern_templates[],
+				uint8_t nb_pattern_templates,
+				struct rte_flow_actions_template *actions_templates[],
+				uint8_t nb_actions_templates,
+				struct rte_flow_error *error);
+
+A table can be created only after the Flow Rules management is configured
+and pattern and actions templates are created.
+
+.. code-block:: c
+
+	rte_flow_configure(port, *port_attr, *error);
+
+	struct rte_flow_pattern_template *pattern_templates[0] =
+		rte_flow_pattern_template_create(port, &itr, &pattern, &error);
+	struct rte_flow_actions_template *actions_templates[0] =
+		rte_flow_actions_template_create(port, &atr, &actions, &masks, &error);
+
+	struct rte_flow_template_table *table =
+		rte_flow_template_table_create(port, *table_attr,
+				*pattern_templates, nb_pattern_templates,
+				*actions_templates, nb_actions_templates,
+				*error);
+
 .. _flow_isolated_mode:
 
 Flow isolated mode
doc/guides/rel_notes/release_22_03.rst +8 -0
index 2a47a37f0a..6656b35295 100644
@@ -75,6 +75,14 @@ New Features
     engine, allowing to pre-allocate some resources for better performance.
     Added ``rte_flow_info_get`` API to retrieve pre-configurable resources.
 
+  * ethdev: Added ``rte_flow_template_table_create`` API to group flow rules
+    with the same flow attributes and common matching patterns and actions
+    defined by ``rte_flow_pattern_template_create`` and
+    ``rte_flow_actions_template_create`` respectively.
+    Corresponding functions to destroy these entities are:
+    ``rte_flow_template_table_destroy``, ``rte_flow_pattern_template_destroy``
+    and ``rte_flow_actions_template_destroy``.
+
 * **Updated AF_XDP PMD**
 
   * Added support for libxdp >=v1.2.2.
lib/ethdev/rte_flow.c +147 -0

150 lines not on this page · raw message

lib/ethdev/rte_flow.h +260 -0

266 lines not on this page · raw message

lib/ethdev/rte_flow_driver.h +37 -0
index 7c29930d0f..2d96db1dc7 100644
@@ -162,6 +162,43 @@ struct rte_flow_ops {
 		(struct rte_eth_dev *dev,
 		 const struct rte_flow_port_attr *port_attr,
 		 struct rte_flow_error *err);
+	/** See rte_flow_pattern_template_create() */
+	struct rte_flow_pattern_template *(*pattern_template_create)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_pattern_template_attr *template_attr,
+		 const struct rte_flow_item pattern[],
+		 struct rte_flow_error *err);
+	/** See rte_flow_pattern_template_destroy() */
+	int (*pattern_template_destroy)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_pattern_template *pattern_template,
+		 struct rte_flow_error *err);
+	/** See rte_flow_actions_template_create() */
+	struct rte_flow_actions_template *(*actions_template_create)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_actions_template_attr *template_attr,
+		 const struct rte_flow_action actions[],
+		 const struct rte_flow_action masks[],
+		 struct rte_flow_error *err);
+	/** See rte_flow_actions_template_destroy() */
+	int (*actions_template_destroy)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_actions_template *actions_template,
+		 struct rte_flow_error *err);
+	/** See rte_flow_template_table_create() */
+	struct rte_flow_template_table *(*template_table_create)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_template_table_attr *table_attr,
+		 struct rte_flow_pattern_template *pattern_templates[],
+		 uint8_t nb_pattern_templates,
+		 struct rte_flow_actions_template *actions_templates[],
+		 uint8_t nb_actions_templates,
+		 struct rte_flow_error *err);
+	/** See rte_flow_template_table_destroy() */
+	int (*template_table_destroy)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_template_table *template_table,
+		 struct rte_flow_error *err);
 };
 
 /**
lib/ethdev/version.map +6 -0
index f1235aa913..5fd2108895 100644
@@ -262,6 +262,12 @@ EXPERIMENTAL {
 	rte_eth_dev_priority_flow_ctrl_queue_info_get;
 	rte_flow_info_get;
 	rte_flow_configure;
+	rte_flow_pattern_template_create;
+	rte_flow_pattern_template_destroy;
+	rte_flow_actions_template_create;
+	rte_flow_actions_template_destroy;
+	rte_flow_template_table_create;
+	rte_flow_template_table_destroy;
 };
 
 INTERNAL {
Signature · 1 line
2.18.2
#108 lore raw

Re: [PATCH v5 02/10] ethdev: add flow item/action templates

Quoted 69 lines · Alexander Kozyrev

Treating every single flow rule as a completely independent and separate entity negatively impacts the flow rules insertion rate. Oftentimes in an application, many flow rules share a common structure (the same item mask and/or action list) so they can be grouped and classified together. This knowledge may be used as a source of optimization by a PMD/HW.

The pattern template defines common matching fields (the item mask) without values. The actions template holds a list of action types that will be used together in the same rule. The specific values for items and actions will be given only during the rule creation.

A table combines pattern and actions templates along with shared flow rule attributes (group ID, priority and traffic direction). This way a PMD/HW can prepare all the resources needed for efficient flow rules creation in the datapath. To avoid any hiccups due to memory reallocation, the maximum number of flow rules is defined at the table creation time.

The flow rule creation is done by selecting a table, a pattern template and an actions template (which are bound to the table), and setting unique values for the items and actions.

---
  doc/guides/prog_guide/rte_flow.rst     | 124 ++++++++++++
  doc/guides/rel_notes/release_22_03.rst |   8 +
  lib/ethdev/rte_flow.c                  | 147 ++++++++++++++
  lib/ethdev/rte_flow.h                  | 260 +++++++++++++++++++++++++
  lib/ethdev/rte_flow_driver.h           |  37 ++++
  lib/ethdev/version.map                 |   6 +
  6 files changed, 582 insertions(+)
doc/guides/prog_guide/rte_flow.rst +29 -0
index 72fb1132ac..5391648833 100644
@@ -3626,6 +3626,130 @@ of pre-configurable resources for a given port on a system.
                       struct rte_flow_port_info *port_info,
                       struct rte_flow_error *error);
 
+Flow templates
+~~~~~~~~~~~~~~
+
+Oftentimes in an application, many flow rules share a common structure
+(the same pattern and/or action list) so they can be grouped and classified
+together. This knowledge may be used as a source of optimization by a PMD/HW.
+The flow rule creation is done by selecting a table, a pattern template
+and an actions template (which are bound to the table), and setting unique
+values for the items and actions. This API is not thread-safe.
+
+Pattern templates
+^^^^^^^^^^^^^^^^^
+
+The pattern template defines a common pattern (the item mask) without values.
+The mask value is used to select a field to match on, spec/last are ignored.
+The pattern template may be used by multiple tables and must not be destroyed
+until all these tables are destroyed first.
+
+.. code-block:: c
+
+	struct rte_flow_pattern_template *
+	rte_flow_pattern_template_create(uint16_t port_id,
+				const struct rte_flow_pattern_template_attr *template_attr,
+				const struct rte_flow_item pattern[],
+				struct rte_flow_error *error);
+
+For example, to create a pattern template to match on the destination MAC:
+
+.. code-block:: c

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system. · line 3667

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+
+	struct rte_flow_item pattern[2] = {{0}};
+	struct rte_flow_item_eth eth_m = {0};
+	pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
+	eth_m.dst.addr_bytes = "\xff\xff\xff\xff\xff\xff";
+	pattern[0].mask = &eth_m;
+	pattern[1].type = RTE_FLOW_ITEM_TYPE_END;
+
+	struct rte_flow_pattern_template *pattern_template =
+		rte_flow_pattern_template_create(port, &itr, &pattern, &error);

itr?

Quoted 32 lines
doc/guides/prog_guide/rte_flow.rst +32 -0
+
+The concrete value to match on will be provided at the rule creation.
+
+Actions templates
+^^^^^^^^^^^^^^^^^
+
+The actions template holds a list of action types to be used in flow rules.
+The mask parameter allows specifying a shared constant value for every rule.
+The actions template may be used by multiple tables and must not be destroyed
+until all these tables are destroyed first.
+
+.. code-block:: c
+
+	struct rte_flow_actions_template *
+	rte_flow_actions_template_create(uint16_t port_id,
+				const struct rte_flow_actions_template_attr *template_attr,
+				const struct rte_flow_action actions[],
+				const struct rte_flow_action masks[],
+				struct rte_flow_error *error);
+
+For example, to create an actions template with the same Mark ID
+but different Queue Index for every rule:
+
+.. code-block:: c
+
+	struct rte_flow_action actions[] = {
+		/* Mark ID is constant (4) for every rule, Queue Index is unique */
+		[0] = {.type = RTE_FLOW_ACTION_TYPE_MARK,
+			   .conf = &(struct rte_flow_action_mark){.id = 4}},
+		[1] = {.type = RTE_FLOW_ACTION_TYPE_QUEUE},
+		[2] = {.type = RTE_FLOW_ACTION_TYPE_END,},
+	};

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system. · line 3709

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+	struct rte_flow_action masks[] = {
+		/* Assign to MARK mask any non-zero value to make it constant */
+		[0] = {.type = RTE_FLOW_ACTION_TYPE_MARK,
+			   .conf = &(struct rte_flow_action_mark){.id = 1}},
+		[1] = {.type = RTE_FLOW_ACTION_TYPE_QUEUE},
+		[2] = {.type = RTE_FLOW_ACTION_TYPE_END,},
+	};
+
+	struct rte_flow_actions_template *at =
+		rte_flow_actions_template_create(port, &atr, &actions, &masks, &error);

atr?

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+
+The concrete value for Queue Index will be provided at the rule creation.
+
+Template table
+^^^^^^^^^^^^^^
+
+A template table combines a number of pattern and actions templates along with
+shared flow rule attributes (group ID, priority and traffic direction).
+This way a PMD/HW can prepare all the resources needed for efficient flow rules
+creation in the datapath. To avoid any hiccups due to memory reallocation,

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system. · line 3729

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+the maximum number of flow rules is defined at table creation time.
+Any flow rule creation beyond the maximum table size is rejected.
+Application may create another table to accommodate more rules in this case.
+
+.. code-block:: c
+
+	struct rte_flow_template_table *
+	rte_flow_template_table_create(uint16_t port_id,
+				const struct rte_flow_template_table_attr *table_attr,
+				struct rte_flow_pattern_template *pattern_templates[],

const?

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system. · line 3731

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+				uint8_t nb_pattern_templates,
+				struct rte_flow_actions_template *actions_templates[],

const?

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system. · line 3740

Quoted 9 lines
doc/guides/prog_guide/rte_flow.rst +9 -0
+				uint8_t nb_actions_templates,
+				struct rte_flow_error *error);
+
+A table can be created only after the Flow Rules management is configured
+and pattern and actions templates are created.
+
+.. code-block:: c
+
+	rte_flow_configure(port, *port_attr, *error);

Why do you have '*' before port_attr and error above?

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system. · line 3742

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+
+	struct rte_flow_pattern_template *pattern_templates[0] =

Definition of zero size array looks wrong.

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system. · line 3743

Quoted 1 line
doc/guides/prog_guide/rte_flow.rst +1 -0
+		rte_flow_pattern_template_create(port, &itr, &pattern, &error);

itr?

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system. · line 3744

Quoted 1 line
doc/guides/prog_guide/rte_flow.rst +1 -0
+	struct rte_flow_actions_template *actions_templates[0] =

Zero size array?

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system. · line 3745

Quoted 1 line
doc/guides/prog_guide/rte_flow.rst +1 -0
+		rte_flow_actions_template_create(port, &atr, &actions, &masks, &error);

atr?

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system. · line 3751

Quoted 6 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
+
+	struct rte_flow_template_table *table =
+		rte_flow_template_table_create(port, *table_attr,
+				*pattern_templates, nb_pattern_templates,
+				*actions_templates, nb_actions_templates,
+				*error);

Similar question here.

Quoted 35 lines
doc/guides/prog_guide/rte_flow.rst +1 -0
+
  .. _flow_isolated_mode:
 
  Flow isolated mode
doc/guides/rel_notes/release_22_03.rst +8 -0
index 2a47a37f0a..6656b35295 100644
@@ -75,6 +75,14 @@ New Features
      engine, allowing to pre-allocate some resources for better performance.
      Added ``rte_flow_info_get`` API to retrieve pre-configurable resources.
 
+  * ethdev: Added ``rte_flow_template_table_create`` API to group flow rules
+    with the same flow attributes and common matching patterns and actions
+    defined by ``rte_flow_pattern_template_create`` and
+    ``rte_flow_actions_template_create`` respectively.
+    Corresponding functions to destroy these entities are:
+    ``rte_flow_template_table_destroy``, ``rte_flow_pattern_template_destroy``
+    and ``rte_flow_actions_template_destroy``.
+
  * **Updated AF_XDP PMD**
 
    * Added support for libxdp >=v1.2.2.
lib/ethdev/rte_flow.c +4 -0
index 66614ae29b..b53f8c9b89 100644
@@ -1431,3 +1431,150 @@ rte_flow_configure(uint16_t port_id,
  				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
  				  NULL, rte_strerror(ENOTSUP));
  }
+
+struct rte_flow_pattern_template *
+rte_flow_pattern_template_create(uint16_t port_id,
+		const struct rte_flow_pattern_template_attr *template_attr,

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1447

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+		const struct rte_flow_item pattern[],
+		struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	struct rte_flow_pattern_template *template;
+
+	if (unlikely(!ops))
+		return NULL;
+	if (likely(!!ops->pattern_template_create)) {

Don't we need any state checks?

Check pattern vs NULL?

Quoted 13 lines
lib/ethdev/rte_flow.c +13 -0
+		template = ops->pattern_template_create(dev, template_attr,
+						     pattern, error);
+		if (template == NULL)
+			flow_err(port_id, -rte_errno, error);
+		return template;
+	}
+	rte_flow_error_set(error, ENOTSUP,
+			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+			   NULL, rte_strerror(ENOTSUP));
+	return NULL;
+}
+
+int

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1470

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_pattern_template_destroy(uint16_t port_id,
+		struct rte_flow_pattern_template *pattern_template,
+		struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->pattern_template_destroy)) {

IMHO we should return success here if pattern_template is NULL

Quoted 15 lines
lib/ethdev/rte_flow.c +15 -0
+		return flow_err(port_id,
+				ops->pattern_template_destroy(dev,
+							      pattern_template,
+							      error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+struct rte_flow_actions_template *
+rte_flow_actions_template_create(uint16_t port_id,
+			const struct rte_flow_actions_template_attr *template_attr,
+			const struct rte_flow_action actions[],

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1495

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+			const struct rte_flow_action masks[],
+			struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	struct rte_flow_actions_template *template;
+
+	if (unlikely(!ops))
+		return NULL;
+	if (likely(!!ops->actions_template_create)) {

State checks?

Check actions and masks vs NULL?

Quoted 13 lines
lib/ethdev/rte_flow.c +13 -0
+		template = ops->actions_template_create(dev, template_attr,
+							actions, masks, error);
+		if (template == NULL)
+			flow_err(port_id, -rte_errno, error);
+		return template;
+	}
+	rte_flow_error_set(error, ENOTSUP,
+			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+			   NULL, rte_strerror(ENOTSUP));
+	return NULL;
+}
+
+int

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1518

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_actions_template_destroy(uint16_t port_id,
+			struct rte_flow_actions_template *actions_template,
+			struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->actions_template_destroy)) {

IMHO we should return success here if actions_template is NULL

Quoted 17 lines
lib/ethdev/rte_flow.c +17 -0
+		return flow_err(port_id,
+				ops->actions_template_destroy(dev,
+							      actions_template,
+							      error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+struct rte_flow_template_table *
+rte_flow_template_table_create(uint16_t port_id,
+			const struct rte_flow_template_table_attr *table_attr,
+			struct rte_flow_pattern_template *pattern_templates[],
+			uint8_t nb_pattern_templates,
+			struct rte_flow_actions_template *actions_templates[],

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1545

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+			uint8_t nb_actions_templates,
+			struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	struct rte_flow_template_table *table;
+
+	if (unlikely(!ops))
+		return NULL;
+	if (likely(!!ops->template_table_create)) {

Argument sanity checks here. array NULL when size is not 0.

Quoted 15 lines
lib/ethdev/rte_flow.c +15 -0
+		table = ops->template_table_create(dev, table_attr,
+					pattern_templates, nb_pattern_templates,
+					actions_templates, nb_actions_templates,
+					error);
+		if (table == NULL)
+			flow_err(port_id, -rte_errno, error);
+		return table;
+	}
+	rte_flow_error_set(error, ENOTSUP,
+			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+			   NULL, rte_strerror(ENOTSUP));
+	return NULL;
+}
+
+int

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1570

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+rte_flow_template_table_destroy(uint16_t port_id,
+				struct rte_flow_template_table *template_table,
+				struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->template_table_destroy)) {

Return success if template_table is NULL

Quoted 39 lines
lib/ethdev/rte_flow.c +10 -0
+		return flow_err(port_id,
+				ops->template_table_destroy(dev,
+							    template_table,
+							    error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +21 -0
index 92be2a9a89..e87db5a540 100644
@@ -4961,6 +4961,266 @@ rte_flow_configure(uint16_t port_id,
  		   const struct rte_flow_port_attr *port_attr,
  		   struct rte_flow_error *error);
 
+/**
+ * Opaque type returned after successful creation of pattern template.
+ * This handle can be used to manage the created pattern template.
+ */
+struct rte_flow_pattern_template;
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Flow pattern template attributes.
+ */
+__extension__
+struct rte_flow_pattern_template_attr {
+	/**
+	 * Relaxed matching policy.
+	 * - PMD may match only on items with mask member set and skip
+	 * matching on protocol layers specified without any masks.
+	 * - If not set, PMD will match on protocol layers
+	 * specified without any masks as well.
+	 * - Packet data must be stacked in the same order as the

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 4994

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+	 * protocol layers to match inside packets, starting from the lowest.
+	 */
+	uint32_t relaxed_matching:1;
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Create pattern template.

Create flow pattern template.

Quoted 5 lines
lib/ethdev/rte_flow.h +5 -0
+ *
+ * The pattern template defines common matching fields without values.
+ * For example, matching on 5 tuple TCP flow, the template will be
+ * eth(null) + IPv4(source + dest) + TCP(s_port + d_port),
+ * while values for each rule will be set during the flow rule creation.

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5009

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * The number and order of items in the template must be the same
+ * at the rule creation.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] template_attr
+ *   Pattern template attributes.
+ * @param[in] pattern
+ *   Pattern specification (list terminated by the END pattern item).
+ *   The spec member of an item is not used unless the end member is used.

Interpretation of the pattern may depend on transfer vs non-transfer rule to be used. It is essential information and we should provide it when pattern template is created.

The information is provided on table stage, but it is too late.

Quoted 9 lines
lib/ethdev/rte_flow.h +9 -0
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   Handle on success, NULL otherwise and rte_errno is set.
+ */
+__rte_experimental
+struct rte_flow_pattern_template *

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5028

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+rte_flow_pattern_template_create(uint16_t port_id,
+		const struct rte_flow_pattern_template_attr *template_attr,
+		const struct rte_flow_item pattern[],
+		struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Destroy pattern template.

Destroy flow pattern template.

Quoted 30 lines
lib/ethdev/rte_flow.h +30 -0
+ *
+ * This function may be called only when
+ * there are no more tables referencing this template.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] pattern_template
+ *   Handle of the template to be destroyed.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_pattern_template_destroy(uint16_t port_id,
+		struct rte_flow_pattern_template *pattern_template,
+		struct rte_flow_error *error);
+
+/**
+ * Opaque type returned after successful creation of actions template.
+ * This handle can be used to manage the created actions template.
+ */
+struct rte_flow_actions_template;
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5068

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ *
+ * Flow actions template attributes.
+ */
+struct rte_flow_actions_template_attr;
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Create actions template.

Create flow rule actions template.

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5074

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+ *
+ * The actions template holds a list of action types without values.
+ * For example, the template to change TCP ports is TCP(s_port + d_port),
+ * while values for each rule will be set during the flow rule creation.
+ * The number and order of actions in the template must be the same
+ * at the rule creation.

Again, it highly depends on transfer vs non-transfer. Moreover, application definitely know it. So, it should say if the action is intended for transfer or non-transfer flow rule.

Quoted 27 lines
lib/ethdev/rte_flow.h +27 -0
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] template_attr
+ *   Template attributes.
+ * @param[in] actions
+ *   Associated actions (list terminated by the END action).
+ *   The spec member is only used if @p masks spec is non-zero.
+ * @param[in] masks
+ *   List of actions that marks which of the action's member is constant.
+ *   A mask has the same format as the corresponding action.
+ *   If the action field in @p masks is not 0,
+ *   the corresponding value in an action from @p actions will be the part
+ *   of the template and used in all flow rules.
+ *   The order of actions in @p masks is the same as in @p actions.
+ *   In case of indirect actions present in @p actions,
+ *   the actual action type should be present in @p mask.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   Handle on success, NULL otherwise and rte_errno is set.
+ */
+__rte_experimental
+struct rte_flow_actions_template *
+rte_flow_actions_template_create(uint16_t port_id,

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5111

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+		const struct rte_flow_actions_template_attr *template_attr,
+		const struct rte_flow_action actions[],
+		const struct rte_flow_action masks[],
+		struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Destroy actions template.

Destroy flow rule actions template.

Quoted 180 lines
lib/ethdev/rte_flow.h +112 -0
+ *
+ * This function may be called only when
+ * there are no more tables referencing this template.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] actions_template
+ *   Handle to the template to be destroyed.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_actions_template_destroy(uint16_t port_id,
+		struct rte_flow_actions_template *actions_template,
+		struct rte_flow_error *error);
+
+/**
+ * Opaque type returned after successful creation of a template table.
+ * This handle can be used to manage the created template table.
+ */
+struct rte_flow_template_table;
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Table attributes.
+ */
+struct rte_flow_template_table_attr {
+	/**
+	 * Flow attributes to be used in each rule generated from this table.
+	 */
+	struct rte_flow_attr flow_attr;
+	/**
+	 * Maximum number of flow rules that this table holds.
+	 */
+	uint32_t nb_flows;
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Create template table.
+ *
+ * A template table consists of multiple pattern templates and actions
+ * templates associated with a single set of rule attributes (group ID,
+ * priority and traffic direction).
+ *
+ * Each rule is free to use any combination of pattern and actions templates
+ * and specify particular values for items and actions it would like to change.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] table_attr
+ *   Template table attributes.
+ * @param[in] pattern_templates
+ *   Array of pattern templates to be used in this table.
+ * @param[in] nb_pattern_templates
+ *   The number of pattern templates in the pattern_templates array.
+ * @param[in] actions_templates
+ *   Array of actions templates to be used in this table.
+ * @param[in] nb_actions_templates
+ *   The number of actions templates in the actions_templates array.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   Handle on success, NULL otherwise and rte_errno is set.
+ */
+__rte_experimental
+struct rte_flow_template_table *
+rte_flow_template_table_create(uint16_t port_id,
+		const struct rte_flow_template_table_attr *table_attr,
+		struct rte_flow_pattern_template *pattern_templates[],
+		uint8_t nb_pattern_templates,
+		struct rte_flow_actions_template *actions_templates[],
+		uint8_t nb_actions_templates,
+		struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Destroy template table.
+ *
+ * This function may be called only when
+ * there are no more flow rules referencing this table.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] template_table
+ *   Handle to the table to be destroyed.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_template_table_destroy(uint16_t port_id,
+		struct rte_flow_template_table *template_table,
+		struct rte_flow_error *error);
+
  #ifdef __cplusplus
  }
  #endif
lib/ethdev/rte_flow_driver.h +37 -0
index 7c29930d0f..2d96db1dc7 100644
@@ -162,6 +162,43 @@ struct rte_flow_ops {
  		(struct rte_eth_dev *dev,
  		 const struct rte_flow_port_attr *port_attr,
  		 struct rte_flow_error *err);
+	/** See rte_flow_pattern_template_create() */
+	struct rte_flow_pattern_template *(*pattern_template_create)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_pattern_template_attr *template_attr,
+		 const struct rte_flow_item pattern[],
+		 struct rte_flow_error *err);
+	/** See rte_flow_pattern_template_destroy() */
+	int (*pattern_template_destroy)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_pattern_template *pattern_template,
+		 struct rte_flow_error *err);
+	/** See rte_flow_actions_template_create() */
+	struct rte_flow_actions_template *(*actions_template_create)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_actions_template_attr *template_attr,
+		 const struct rte_flow_action actions[],
+		 const struct rte_flow_action masks[],
+		 struct rte_flow_error *err);
+	/** See rte_flow_actions_template_destroy() */
+	int (*actions_template_destroy)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_actions_template *actions_template,
+		 struct rte_flow_error *err);
+	/** See rte_flow_template_table_create() */
+	struct rte_flow_template_table *(*template_table_create)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_template_table_attr *table_attr,
+		 struct rte_flow_pattern_template *pattern_templates[],
+		 uint8_t nb_pattern_templates,
+		 struct rte_flow_actions_template *actions_templates[],
+		 uint8_t nb_actions_templates,
+		 struct rte_flow_error *err);
+	/** See rte_flow_template_table_destroy() */
+	int (*template_table_destroy)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_template_table *template_table,
+		 struct rte_flow_error *err);
  };
 
  /**
lib/ethdev/version.map +6 -0
index f1235aa913..5fd2108895 100644
@@ -262,6 +262,12 @@ EXPERIMENTAL {
  	rte_eth_dev_priority_flow_ctrl_queue_info_get;
  	rte_flow_info_get;
  	rte_flow_configure;
+	rte_flow_pattern_template_create;
+	rte_flow_pattern_template_destroy;
+	rte_flow_actions_template_create;
+	rte_flow_actions_template_destroy;
+	rte_flow_template_table_create;
+	rte_flow_template_table_destroy;
  };
 
  INTERNAL {
#109 lore raw

RE: [PATCH v5 02/10] ethdev: add flow item/action templates

Quoted 88 lines · On Fri, Feb 11, 2022 6:27 Andrew Rybchenko <[email protected]>…
Quoted 32 lines · Alexander Kozyrev

Treating every single flow rule as a completely independent and separate entity negatively impacts the flow rules insertion rate. Oftentimes in an application, many flow rules share a common structure (the same item mask and/or action list) so they can be grouped and classified together. This knowledge may be used as a source of optimization by a PMD/HW.

The pattern template defines common matching fields (the item mask) without values. The actions template holds a list of action types that will be used together in the same rule. The specific values for items and actions will be given only during the rule creation.

A table combines pattern and actions templates along with shared flow rule attributes (group ID, priority and traffic direction). This way a PMD/HW can prepare all the resources needed for efficient flow rules creation in the datapath. To avoid any hiccups due to memory reallocation, the maximum number of flow rules is defined at the table creation time.

The flow rule creation is done by selecting a table, a pattern template and an actions template (which are bound to the table), and setting unique values for the items and actions.

---
  doc/guides/prog_guide/rte_flow.rst     | 124 ++++++++++++
  doc/guides/rel_notes/release_22_03.rst |   8 +
  lib/ethdev/rte_flow.c                  | 147 ++++++++++++++
  lib/ethdev/rte_flow.h                  | 260 +++++++++++++++++++++++++
  lib/ethdev/rte_flow_driver.h           |  37 ++++
  lib/ethdev/version.map                 |   6 +
  6 files changed, 582 insertions(+)

Review

Quoted 1 line
(quoted diff) +0 -0

b/doc/guides/prog_guide/rte_flow.rst

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on

Quoted 4 lines

index 72fb1132ac..5391648833 100644

doc/guides/prog_guide/rte_flow.rst +0 -0
@@ -3626,6 +3626,130 @@ of pre-configurable resources for a given port on

a system.

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system.

Quoted 9 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
                       struct rte_flow_port_info *port_info,
                       struct rte_flow_error *error);
 
+Flow templates
+~~~~~~~~~~~~~~
+
+Oftentimes in an application, many flow rules share a common structure
+(the same pattern and/or action list) so they can be grouped and classified
+together. This knowledge may be used as a source of optimization by a

PMD/HW.

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system.

Quoted 8 lines
doc/guides/prog_guide/rte_flow.rst +8 -0
+The flow rule creation is done by selecting a table, a pattern template
+and an actions template (which are bound to the table), and setting unique
+values for the items and actions. This API is not thread-safe.
+
+Pattern templates
+^^^^^^^^^^^^^^^^^
+
+The pattern template defines a common pattern (the item mask) without

values.

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on · line 3644

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+The mask value is used to select a field to match on, spec/last are ignored.
+The pattern template may be used by multiple tables and must not be

destroyed

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system.

Quoted 7 lines
doc/guides/prog_guide/rte_flow.rst +7 -0
+until all these tables are destroyed first.
+
+.. code-block:: c
+
+	struct rte_flow_pattern_template *
+	rte_flow_pattern_template_create(uint16_t port_id,
+				const struct rte_flow_pattern_template_attr

*template_attr,

Quoted 6 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
+				const struct rte_flow_item pattern[],
+				struct rte_flow_error *error);
+
+For example, to create a pattern template to match on the destination MAC:
+
+.. code-block:: c

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system.

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+
+	struct rte_flow_item pattern[2] = {{0}};
+	struct rte_flow_item_eth eth_m = {0};
+	pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
+	eth_m.dst.addr_bytes = "\xff\xff\xff\xff\xff\xff";
+	pattern[0].mask = &eth_m;
+	pattern[1].type = RTE_FLOW_ITEM_TYPE_END;
+
+	struct rte_flow_pattern_template *pattern_template =
+		rte_flow_pattern_template_create(port, &itr, &pattern,

&error);

Quoted 1 line

itr?

Will add it's declaration for clarity.

Quoted 48 lines

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system.

Quoted 9 lines
doc/guides/prog_guide/rte_flow.rst +9 -0
+
+The concrete value to match on will be provided at the rule creation.
+
+Actions templates
+^^^^^^^^^^^^^^^^^
+
+The actions template holds a list of action types to be used in flow rules.
+The mask parameter allows specifying a shared constant value for every rule.
+The actions template may be used by multiple tables and must not be

destroyed

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system.

Quoted 7 lines
doc/guides/prog_guide/rte_flow.rst +7 -0
+until all these tables are destroyed first.
+
+.. code-block:: c
+
+	struct rte_flow_actions_template *
+	rte_flow_actions_template_create(uint16_t port_id,
+				const struct rte_flow_actions_template_attr

*template_attr,

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system.

Quoted 11 lines
doc/guides/prog_guide/rte_flow.rst +11 -0
+				const struct rte_flow_action actions[],
+				const struct rte_flow_action masks[],
+				struct rte_flow_error *error);
+
+For example, to create an actions template with the same Mark ID
+but different Queue Index for every rule:
+
+.. code-block:: c
+
+	struct rte_flow_action actions[] = {
+		/* Mark ID is constant (4) for every rule, Queue Index is unique

*/

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system.

Quoted 7 lines
doc/guides/prog_guide/rte_flow.rst +7 -0
+		[0] = {.type = RTE_FLOW_ACTION_TYPE_MARK,
+			   .conf = &(struct rte_flow_action_mark){.id = 4}},
+		[1] = {.type = RTE_FLOW_ACTION_TYPE_QUEUE},
+		[2] = {.type = RTE_FLOW_ACTION_TYPE_END,},
+	};
+	struct rte_flow_action masks[] = {
+		/* Assign to MARK mask any non-zero value to make it constant

*/

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system.

Quoted 8 lines
doc/guides/prog_guide/rte_flow.rst +8 -0
+		[0] = {.type = RTE_FLOW_ACTION_TYPE_MARK,
+			   .conf = &(struct rte_flow_action_mark){.id = 1}},
+		[1] = {.type = RTE_FLOW_ACTION_TYPE_QUEUE},
+		[2] = {.type = RTE_FLOW_ACTION_TYPE_END,},
+	};
+
+	struct rte_flow_actions_template *at =
+		rte_flow_actions_template_create(port, &atr, &actions,

&masks, &error);

Quoted 1 line

atr?

Same

Quoted 23 lines

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system.

Quoted 7 lines
doc/guides/prog_guide/rte_flow.rst +7 -0
+
+The concrete value for Queue Index will be provided at the rule creation.
+
+Template table
+^^^^^^^^^^^^^^
+
+A template table combines a number of pattern and actions templates along

with

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on · line 3718

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+shared flow rule attributes (group ID, priority and traffic direction).
+This way a PMD/HW can prepare all the resources needed for efficient flow

rules

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system.

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+creation in the datapath. To avoid any hiccups due to memory reallocation,
+the maximum number of flow rules is defined at table creation time.
+Any flow rule creation beyond the maximum table size is rejected.
+Application may create another table to accommodate more rules in this

case.

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system.

Quoted 6 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
+
+.. code-block:: c
+
+	struct rte_flow_template_table *
+	rte_flow_template_table_create(uint16_t port_id,
+				const struct rte_flow_template_table_attr

*table_attr,

Quoted 4 lines

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on · line 3729

Quoted 1 line
doc/guides/prog_guide/rte_flow.rst +1 -0
+				struct rte_flow_pattern_template

*pattern_templates[],

const?

No, pattern templates refcount is updated by the table API.

Quoted 5 lines

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on · line 3731

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+				uint8_t nb_pattern_templates,
+				struct rte_flow_actions_template

*actions_templates[],

const?

Again, refcount is updated inside.

Quoted 13 lines

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system. · line 3740

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +9 -0
+				uint8_t nb_actions_templates,
+				struct rte_flow_error *error);
+
+A table can be created only after the Flow Rules management is configured
+and pattern and actions templates are created.
+
+.. code-block:: c
+
+	rte_flow_configure(port, *port_attr, *error);

Why do you have '*' before port_attr and error above?

Typo, thanks for noticing.

Quoted 20 lines

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on · line 3742

Quoted 3 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+
+	struct rte_flow_pattern_template *pattern_templates[0] =

Definition of zero size array looks wrong.

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on · line 3743

Quoted 1 line
doc/guides/prog_guide/rte_flow.rst +1 -0
+		rte_flow_pattern_template_create(port, &itr, &pattern,

&error);

itr?

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system. · line 3744

Quoted 1 line
doc/guides/prog_guide/rte_flow.rst +1 -0
+	struct rte_flow_actions_template *actions_templates[0] =

Zero size array?

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on · line 3745

Quoted 1 line
doc/guides/prog_guide/rte_flow.rst +1 -0
+		rte_flow_actions_template_create(port, &atr, &actions,

&masks, &error);

atr?

Quoted 8 lines

doc/guides/prog_guide/rte_flow.rst of pre-configurable resources for a given port on a system. · line 3751

Quoted 6 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
+
+	struct rte_flow_template_table *table =
+		rte_flow_template_table_create(port, *table_attr,
+				*pattern_templates, nb_pattern_templates,
+				*actions_templates, nb_actions_templates,
+				*error);

Similar question here.

Rewriting this snippet to fix everything.

Quoted 51 lines

Review

Quoted 6 lines
doc/guides/prog_guide/rte_flow.rst +1 -0
+
  .. _flow_isolated_mode:
 
  Flow isolated mode
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_22_03.rst

doc/guides/rel_notes/release_22_03.rst New Features · line 83

Quoted 13 lines

index 2a47a37f0a..6656b35295 100644

doc/guides/rel_notes/release_22_03.rst +6 -0
@@ -75,6 +75,14 @@ New Features
      engine, allowing to pre-allocate some resources for better performance.
      Added ``rte_flow_info_get`` API to retrieve pre-configurable resources.
 
+  * ethdev: Added ``rte_flow_template_table_create`` API to group flow rules
+    with the same flow attributes and common matching patterns and actions
+    defined by ``rte_flow_pattern_template_create`` and
+    ``rte_flow_actions_template_create`` respectively.
+    Corresponding functions to destroy these entities are:
+    ``rte_flow_template_table_destroy``,

``rte_flow_pattern_template_destroy``

Quoted 17 lines
doc/guides/rel_notes/release_22_03.rst +2 -0
+    and ``rte_flow_actions_template_destroy``.
+
  * **Updated AF_XDP PMD**
 
    * Added support for libxdp >=v1.2.2.
lib/ethdev/rte_flow.c +4 -0
index 66614ae29b..b53f8c9b89 100644
@@ -1431,3 +1431,150 @@ rte_flow_configure(uint16_t port_id,
  				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
  				  NULL, rte_strerror(ENOTSUP));
  }
+
+struct rte_flow_pattern_template *
+rte_flow_pattern_template_create(uint16_t port_id,
+		const struct rte_flow_pattern_template_attr *template_attr,

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1447

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+		const struct rte_flow_item pattern[],
+		struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	struct rte_flow_pattern_template *template;
+
+	if (unlikely(!ops))
+		return NULL;
+	if (likely(!!ops->pattern_template_create)) {

Don't we need any state checks?

Quoted 1 line

Check pattern vs NULL?

Still the same situation, no NULL checks elsewhere in rte flow API.

Quoted 18 lines
Quoted 18 lines
lib/ethdev/rte_flow.c +17 -0
+		template = ops->pattern_template_create(dev, template_attr,
+						     pattern, error);
+		if (template == NULL)
+			flow_err(port_id, -rte_errno, error);
+		return template;
+	}
+	rte_flow_error_set(error, ENOTSUP,
+			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+			   NULL, rte_strerror(ENOTSUP));
+	return NULL;
+}
+
+int
+rte_flow_pattern_template_destroy(uint16_t port_id,
+		struct rte_flow_pattern_template *pattern_template,
+		struct rte_flow_error *error)
+{
Quoted 8 lines

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1470

Quoted 6 lines
lib/ethdev/rte_flow.c +6 -0
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->pattern_template_destroy)) {

IMHO we should return success here if pattern_template is NULL

Just like in rte_flow_destroy() it is up to PMD driver to decide.

Quoted 29 lines
Quoted 4 lines
lib/ethdev/rte_flow.c +4 -0
+		return flow_err(port_id,
+				ops->pattern_template_destroy(dev,
+							      pattern_template,
+							      error),

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id,

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+struct rte_flow_actions_template *
+rte_flow_actions_template_create(uint16_t port_id,
+			const struct rte_flow_actions_template_attr

*template_attr,

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1495

Quoted 11 lines
lib/ethdev/rte_flow.c +11 -0
+			const struct rte_flow_action actions[],
+			const struct rte_flow_action masks[],
+			struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	struct rte_flow_actions_template *template;
+
+	if (unlikely(!ops))
+		return NULL;
+	if (likely(!!ops->actions_template_create)) {

State checks?

Quoted 1 line

Check actions and masks vs NULL?

No, sorry.

Quoted 18 lines
Quoted 18 lines
lib/ethdev/rte_flow.c +17 -0
+		template = ops->actions_template_create(dev, template_attr,
+							actions, masks, error);
+		if (template == NULL)
+			flow_err(port_id, -rte_errno, error);
+		return template;
+	}
+	rte_flow_error_set(error, ENOTSUP,
+			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+			   NULL, rte_strerror(ENOTSUP));
+	return NULL;
+}
+
+int
+rte_flow_actions_template_destroy(uint16_t port_id,
+			struct rte_flow_actions_template *actions_template,
+			struct rte_flow_error *error)
+{
Quoted 8 lines

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1518

Quoted 6 lines
lib/ethdev/rte_flow.c +6 -0
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->actions_template_destroy)) {

IMHO we should return success here if actions_template is NULL

Just like in rte_flow_destroy() it is up to PMD driver to decide.

Quoted 20 lines
Quoted 6 lines
lib/ethdev/rte_flow.c +5 -0
+		return flow_err(port_id,
+				ops->actions_template_destroy(dev,
+							      actions_template,
+							      error),
+				error);

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id,

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+struct rte_flow_template_table *
+rte_flow_template_table_create(uint16_t port_id,
+			const struct rte_flow_template_table_attr *table_attr,
+			struct rte_flow_pattern_template

*pattern_templates[],

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1535

Quoted 2 lines
lib/ethdev/rte_flow.c +2 -0
+			uint8_t nb_pattern_templates,
+			struct rte_flow_actions_template

*actions_templates[],

Quoted 12 lines

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1545

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+			uint8_t nb_actions_templates,
+			struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	struct rte_flow_template_table *table;
+
+	if (unlikely(!ops))
+		return NULL;
+	if (likely(!!ops->template_table_create)) {

Argument sanity checks here. array NULL when size is not 0.

Hate to say no so many times, but I cannot help it.

Quoted 21 lines

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1547

Quoted 3 lines
lib/ethdev/rte_flow.c +2 -0
+		table = ops->template_table_create(dev, table_attr,
+					pattern_templates,

nb_pattern_templates,

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1548

Quoted 1 line
lib/ethdev/rte_flow.c +1 -0
+					actions_templates,

nb_actions_templates,

Quoted 4 lines
lib/ethdev/rte_flow.c +4 -0
+					error);
+		if (table == NULL)
+			flow_err(port_id, -rte_errno, error);
+		return table;

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id,

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+	}
+	rte_flow_error_set(error, ENOTSUP,
+			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+			   NULL, rte_strerror(ENOTSUP));
+	return NULL;
+}
+
+int
+rte_flow_template_table_destroy(uint16_t port_id,
+				struct rte_flow_template_table

*template_table,

Quoted 10 lines

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1570

Quoted 8 lines
lib/ethdev/rte_flow.c +8 -0
+				struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->template_table_destroy)) {

Return success if template_table is NULL

Just like in rte_flow_destroy() it is up to PMD driver to decide.

Quoted 43 lines
Quoted 43 lines
lib/ethdev/rte_flow.c +10 -0
+		return flow_err(port_id,
+				ops->template_table_destroy(dev,
+							    template_table,
+							    error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +25 -0
index 92be2a9a89..e87db5a540 100644
@@ -4961,6 +4961,266 @@ rte_flow_configure(uint16_t port_id,
  		   const struct rte_flow_port_attr *port_attr,
  		   struct rte_flow_error *error);
 
+/**
+ * Opaque type returned after successful creation of pattern template.
+ * This handle can be used to manage the created pattern template.
+ */
+struct rte_flow_pattern_template;
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Flow pattern template attributes.
+ */
+__extension__
+struct rte_flow_pattern_template_attr {
+	/**
+	 * Relaxed matching policy.
+	 * - PMD may match only on items with mask member set and skip
+	 * matching on protocol layers specified without any masks.
+	 * - If not set, PMD will match on protocol layers
+	 * specified without any masks as well.
+	 * - Packet data must be stacked in the same order as the
+	 * protocol layers to match inside packets, starting from the lowest.
+	 */
+	uint32_t relaxed_matching:1;
+};
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 4994

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Create pattern template.

Create flow pattern template.

Ok.

Quoted 16 lines
Quoted 5 lines
lib/ethdev/rte_flow.h +5 -0
+ *
+ * The pattern template defines common matching fields without values.
+ * For example, matching on 5 tuple TCP flow, the template will be
+ * eth(null) + IPv4(source + dest) + TCP(s_port + d_port),
+ * while values for each rule will be set during the flow rule creation.

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5009

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * The number and order of items in the template must be the same
+ * at the rule creation.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] template_attr
+ *   Pattern template attributes.
+ * @param[in] pattern
+ *   Pattern specification (list terminated by the END pattern item).
+ *   The spec member of an item is not used unless the end member is used.
Quoted 5 lines

Interpretation of the pattern may depend on transfer vs non-transfer rule to be used. It is essential information and we should provide it when pattern template is created.

The information is provided on table stage, but it is too late.

Why is it too late? Application knows which template goes to which table. And the pattern is generic to accommodate anything, user just need to put it into the right table.

Quoted 14 lines
Quoted 14 lines
lib/ethdev/rte_flow.h +13 -0
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   Handle on success, NULL otherwise and rte_errno is set.
+ */
+__rte_experimental
+struct rte_flow_pattern_template *
+rte_flow_pattern_template_create(uint16_t port_id,
+		const struct rte_flow_pattern_template_attr *template_attr,
+		const struct rte_flow_item pattern[],
+		struct rte_flow_error *error);
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5028

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Destroy pattern template.

Destroy flow pattern template.

Ok.

Quoted 34 lines
Quoted 34 lines
lib/ethdev/rte_flow.h +34 -0
+ *
+ * This function may be called only when
+ * there are no more tables referencing this template.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] pattern_template
+ *   Handle of the template to be destroyed.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_pattern_template_destroy(uint16_t port_id,
+		struct rte_flow_pattern_template *pattern_template,
+		struct rte_flow_error *error);
+
+/**
+ * Opaque type returned after successful creation of actions template.
+ * This handle can be used to manage the created actions template.
+ */
+struct rte_flow_actions_template;
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Flow actions template attributes.
+ */
+struct rte_flow_actions_template_attr;
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5068

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Create actions template.

Create flow rule actions template.

Yes, finally compensating for multiple no's.

Quoted 10 lines

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5074

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+ *
+ * The actions template holds a list of action types without values.
+ * For example, the template to change TCP ports is TCP(s_port + d_port),
+ * while values for each rule will be set during the flow rule creation.
+ * The number and order of actions in the template must be the same
+ * at the rule creation.

Again, it highly depends on transfer vs non-transfer. Moreover, application definitely know it. So, it should say if the action is intended for transfer or non-transfer flow rule.

It is up to application to define which pattern it is going to use in different tables.

Quoted 31 lines
Quoted 31 lines
lib/ethdev/rte_flow.h +31 -0
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] template_attr
+ *   Template attributes.
+ * @param[in] actions
+ *   Associated actions (list terminated by the END action).
+ *   The spec member is only used if @p masks spec is non-zero.
+ * @param[in] masks
+ *   List of actions that marks which of the action's member is constant.
+ *   A mask has the same format as the corresponding action.
+ *   If the action field in @p masks is not 0,
+ *   the corresponding value in an action from @p actions will be the part
+ *   of the template and used in all flow rules.
+ *   The order of actions in @p masks is the same as in @p actions.
+ *   In case of indirect actions present in @p actions,
+ *   the actual action type should be present in @p mask.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   Handle on success, NULL otherwise and rte_errno is set.
+ */
+__rte_experimental
+struct rte_flow_actions_template *
+rte_flow_actions_template_create(uint16_t port_id,
+		const struct rte_flow_actions_template_attr *template_attr,
+		const struct rte_flow_action actions[],
+		const struct rte_flow_action masks[],
+		struct rte_flow_error *error);
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5111

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Destroy actions template.

Destroy flow rule actions template.

Yes, again.

Quoted 181 lines
Quoted 181 lines
lib/ethdev/rte_flow.h +112 -0
+ *
+ * This function may be called only when
+ * there are no more tables referencing this template.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] actions_template
+ *   Handle to the template to be destroyed.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_actions_template_destroy(uint16_t port_id,
+		struct rte_flow_actions_template *actions_template,
+		struct rte_flow_error *error);
+
+/**
+ * Opaque type returned after successful creation of a template table.
+ * This handle can be used to manage the created template table.
+ */
+struct rte_flow_template_table;
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Table attributes.
+ */
+struct rte_flow_template_table_attr {
+	/**
+	 * Flow attributes to be used in each rule generated from this table.
+	 */
+	struct rte_flow_attr flow_attr;
+	/**
+	 * Maximum number of flow rules that this table holds.
+	 */
+	uint32_t nb_flows;
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Create template table.
+ *
+ * A template table consists of multiple pattern templates and actions
+ * templates associated with a single set of rule attributes (group ID,
+ * priority and traffic direction).
+ *
+ * Each rule is free to use any combination of pattern and actions templates
+ * and specify particular values for items and actions it would like to change.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] table_attr
+ *   Template table attributes.
+ * @param[in] pattern_templates
+ *   Array of pattern templates to be used in this table.
+ * @param[in] nb_pattern_templates
+ *   The number of pattern templates in the pattern_templates array.
+ * @param[in] actions_templates
+ *   Array of actions templates to be used in this table.
+ * @param[in] nb_actions_templates
+ *   The number of actions templates in the actions_templates array.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   Handle on success, NULL otherwise and rte_errno is set.
+ */
+__rte_experimental
+struct rte_flow_template_table *
+rte_flow_template_table_create(uint16_t port_id,
+		const struct rte_flow_template_table_attr *table_attr,
+		struct rte_flow_pattern_template *pattern_templates[],
+		uint8_t nb_pattern_templates,
+		struct rte_flow_actions_template *actions_templates[],
+		uint8_t nb_actions_templates,
+		struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Destroy template table.
+ *
+ * This function may be called only when
+ * there are no more flow rules referencing this table.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] template_table
+ *   Handle to the table to be destroyed.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_template_table_destroy(uint16_t port_id,
+		struct rte_flow_template_table *template_table,
+		struct rte_flow_error *error);
+
  #ifdef __cplusplus
  }
  #endif
lib/ethdev/rte_flow_driver.h +37 -0
index 7c29930d0f..2d96db1dc7 100644
@@ -162,6 +162,43 @@ struct rte_flow_ops {
  		(struct rte_eth_dev *dev,
  		 const struct rte_flow_port_attr *port_attr,
  		 struct rte_flow_error *err);
+	/** See rte_flow_pattern_template_create() */
+	struct rte_flow_pattern_template *(*pattern_template_create)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_pattern_template_attr *template_attr,
+		 const struct rte_flow_item pattern[],
+		 struct rte_flow_error *err);
+	/** See rte_flow_pattern_template_destroy() */
+	int (*pattern_template_destroy)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_pattern_template *pattern_template,
+		 struct rte_flow_error *err);
+	/** See rte_flow_actions_template_create() */
+	struct rte_flow_actions_template *(*actions_template_create)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_actions_template_attr *template_attr,
+		 const struct rte_flow_action actions[],
+		 const struct rte_flow_action masks[],
+		 struct rte_flow_error *err);
+	/** See rte_flow_actions_template_destroy() */
+	int (*actions_template_destroy)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_actions_template *actions_template,
+		 struct rte_flow_error *err);
+	/** See rte_flow_template_table_create() */
+	struct rte_flow_template_table *(*template_table_create)
+		(struct rte_eth_dev *dev,
+		 const struct rte_flow_template_table_attr *table_attr,
+		 struct rte_flow_pattern_template *pattern_templates[],
+		 uint8_t nb_pattern_templates,
+		 struct rte_flow_actions_template *actions_templates[],
+		 uint8_t nb_actions_templates,
+		 struct rte_flow_error *err);
+	/** See rte_flow_template_table_destroy() */
+	int (*template_table_destroy)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_template_table *template_table,
+		 struct rte_flow_error *err);
  };
 
  /**
lib/ethdev/version.map +6 -0
index f1235aa913..5fd2108895 100644
@@ -262,6 +262,12 @@ EXPERIMENTAL {
  	rte_eth_dev_priority_flow_ctrl_queue_info_get;
  	rte_flow_info_get;
  	rte_flow_configure;
+	rte_flow_pattern_template_create;
+	rte_flow_pattern_template_destroy;
+	rte_flow_actions_template_create;
+	rte_flow_actions_template_destroy;
+	rte_flow_template_table_create;
+	rte_flow_template_table_destroy;
  };
 
  INTERNAL {
#110 lore raw

Re: [PATCH v5 02/10] ethdev: add flow item/action templates

Quoted 25 lines · Alexander Kozyrev
Quoted 24 lines · On Fri, Feb 11, 2022 6:27 Andrew Rybchenko <[email protected]>…
Quoted 23 lines · Alexander Kozyrev

Treating every single flow rule as a completely independent and separate entity negatively impacts the flow rules insertion rate. Oftentimes in an application, many flow rules share a common structure (the same item mask and/or action list) so they can be grouped and classified together. This knowledge may be used as a source of optimization by a PMD/HW.

The pattern template defines common matching fields (the item mask) without values. The actions template holds a list of action types that will be used together in the same rule. The specific values for items and actions will be given only during the rule creation.

A table combines pattern and actions templates along with shared flow rule attributes (group ID, priority and traffic direction). This way a PMD/HW can prepare all the resources needed for efficient flow rules creation in the datapath. To avoid any hiccups due to memory reallocation, the maximum number of flow rules is defined at the table creation time.

The flow rule creation is done by selecting a table, a pattern template and an actions template (which are bound to the table), and setting unique values for the items and actions.

[snip]

Quoted 25 lines
Quoted 25 lines
Quoted 12 lines
lib/ethdev/rte_flow.c +4 -0
index 66614ae29b..b53f8c9b89 100644
@@ -1431,3 +1431,150 @@ rte_flow_configure(uint16_t port_id,
   				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
   				  NULL, rte_strerror(ENOTSUP));
   }
+
+struct rte_flow_pattern_template *
+rte_flow_pattern_template_create(uint16_t port_id,
+		const struct rte_flow_pattern_template_attr *template_attr,

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1447

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+		const struct rte_flow_item pattern[],
+		struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	struct rte_flow_pattern_template *template;
+
+	if (unlikely(!ops))
+		return NULL;
+	if (likely(!!ops->pattern_template_create)) {

Don't we need any state checks?

Quoted 3 lines
Quoted 1 line

Check pattern vs NULL?

Still the same situation, no NULL checks elsewhere in rte flow API.

I still think that it is wrong as explained.
Same is applicable to many review notes below.

Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
lib/ethdev/rte_flow.c +17 -0
+		template = ops->pattern_template_create(dev, template_attr,
+						     pattern, error);
+		if (template == NULL)
+			flow_err(port_id, -rte_errno, error);
+		return template;
+	}
+	rte_flow_error_set(error, ENOTSUP,
+			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+			   NULL, rte_strerror(ENOTSUP));
+	return NULL;
+}
+
+int
+rte_flow_pattern_template_destroy(uint16_t port_id,
+		struct rte_flow_pattern_template *pattern_template,
+		struct rte_flow_error *error)
+{
Quoted 8 lines

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1470

Quoted 6 lines
lib/ethdev/rte_flow.c +6 -0
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->pattern_template_destroy)) {

IMHO we should return success here if pattern_template is NULL

Quoted 1 line

Just like in rte_flow_destroy() it is up to PMD driver to decide.

Why? We must define behaviour in the case of NULL and guarantee it.

Quoted 60 lines
Quoted 29 lines
Quoted 4 lines
lib/ethdev/rte_flow.c +4 -0
+		return flow_err(port_id,
+				ops->pattern_template_destroy(dev,
+							      pattern_template,
+							      error),

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id,

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+struct rte_flow_actions_template *
+rte_flow_actions_template_create(uint16_t port_id,
+			const struct rte_flow_actions_template_attr

*template_attr,

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1495

Quoted 11 lines
lib/ethdev/rte_flow.c +11 -0
+			const struct rte_flow_action actions[],
+			const struct rte_flow_action masks[],
+			struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	struct rte_flow_actions_template *template;
+
+	if (unlikely(!ops))
+		return NULL;
+	if (likely(!!ops->actions_template_create)) {

State checks?

Quoted 1 line

Check actions and masks vs NULL?

No, sorry.

Quoted 18 lines
Quoted 18 lines
lib/ethdev/rte_flow.c +17 -0
+		template = ops->actions_template_create(dev, template_attr,
+							actions, masks, error);
+		if (template == NULL)
+			flow_err(port_id, -rte_errno, error);
+		return template;
+	}
+	rte_flow_error_set(error, ENOTSUP,
+			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+			   NULL, rte_strerror(ENOTSUP));
+	return NULL;
+}
+
+int
+rte_flow_actions_template_destroy(uint16_t port_id,
+			struct rte_flow_actions_template *actions_template,
+			struct rte_flow_error *error)
+{
Quoted 8 lines

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1518

Quoted 6 lines
lib/ethdev/rte_flow.c +6 -0
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->actions_template_destroy)) {

IMHO we should return success here if actions_template is NULL

Quoted 1 line

Just like in rte_flow_destroy() it is up to PMD driver to decide.

Same

Quoted 67 lines
Quoted 20 lines
Quoted 6 lines
lib/ethdev/rte_flow.c +5 -0
+		return flow_err(port_id,
+				ops->actions_template_destroy(dev,
+							      actions_template,
+							      error),
+				error);

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id,

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+struct rte_flow_template_table *
+rte_flow_template_table_create(uint16_t port_id,
+			const struct rte_flow_template_table_attr *table_attr,
+			struct rte_flow_pattern_template

*pattern_templates[],

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1535

Quoted 2 lines
lib/ethdev/rte_flow.c +2 -0
+			uint8_t nb_pattern_templates,
+			struct rte_flow_actions_template

*actions_templates[],

Quoted 12 lines

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1545

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+			uint8_t nb_actions_templates,
+			struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	struct rte_flow_template_table *table;
+
+	if (unlikely(!ops))
+		return NULL;
+	if (likely(!!ops->template_table_create)) {

Argument sanity checks here. array NULL when size is not 0.

Hate to say no so many times, but I cannot help it.

Quoted 21 lines

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1547

Quoted 3 lines
lib/ethdev/rte_flow.c +2 -0
+		table = ops->template_table_create(dev, table_attr,
+					pattern_templates,

nb_pattern_templates,

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1548

Quoted 1 line
lib/ethdev/rte_flow.c +1 -0
+					actions_templates,

nb_actions_templates,

Quoted 4 lines
lib/ethdev/rte_flow.c +4 -0
+					error);
+		if (table == NULL)
+			flow_err(port_id, -rte_errno, error);
+		return table;

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id,

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+	}
+	rte_flow_error_set(error, ENOTSUP,
+			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+			   NULL, rte_strerror(ENOTSUP));
+	return NULL;
+}
+
+int
+rte_flow_template_table_destroy(uint16_t port_id,
+				struct rte_flow_template_table

*template_table,

Quoted 10 lines

lib/ethdev/rte_flow.c rte_flow_configure(uint16_t port_id, · line 1570

Quoted 8 lines
lib/ethdev/rte_flow.c +8 -0
+				struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->template_table_destroy)) {

Return success if template_table is NULL

Quoted 1 line

Just like in rte_flow_destroy() it is up to PMD driver to decide.

Same

Quoted 75 lines
Quoted 44 lines
Quoted 44 lines
lib/ethdev/rte_flow.c +10 -0
+		return flow_err(port_id,
+				ops->template_table_destroy(dev,
+							    template_table,
+							    error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +25 -0
index 92be2a9a89..e87db5a540 100644
@@ -4961,6 +4961,266 @@ rte_flow_configure(uint16_t port_id,
   		   const struct rte_flow_port_attr *port_attr,
   		   struct rte_flow_error *error);
 
+/**
+ * Opaque type returned after successful creation of pattern template.
+ * This handle can be used to manage the created pattern template.
+ */
+struct rte_flow_pattern_template;
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Flow pattern template attributes.
+ */
+__extension__
+struct rte_flow_pattern_template_attr {
+	/**
+	 * Relaxed matching policy.
+	 * - PMD may match only on items with mask member set and skip
+	 * matching on protocol layers specified without any masks.
+	 * - If not set, PMD will match on protocol layers
+	 * specified without any masks as well.
+	 * - Packet data must be stacked in the same order as the
+	 * protocol layers to match inside packets, starting from the lowest.
+	 */
+	uint32_t relaxed_matching:1;
+};
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 4994

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Create pattern template.

Create flow pattern template.

Ok.

Quoted 20 lines
Quoted 5 lines
lib/ethdev/rte_flow.h +5 -0
+ *
+ * The pattern template defines common matching fields without values.
+ * For example, matching on 5 tuple TCP flow, the template will be
+ * eth(null) + IPv4(source + dest) + TCP(s_port + d_port),
+ * while values for each rule will be set during the flow rule creation.

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5009

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * The number and order of items in the template must be the same
+ * at the rule creation.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] template_attr
+ *   Pattern template attributes.
+ * @param[in] pattern
+ *   Pattern specification (list terminated by the END pattern item).
+ *   The spec member of an item is not used unless the end member is used.

Interpretation of the pattern may depend on transfer vs non-transfer rule to be used. It is essential information and we should provide it when pattern template is created.

Quoted 5 lines
Quoted 1 line

The information is provided on table stage, but it is too late.

Why is it too late? Application knows which template goes to which table. And the pattern is generic to accommodate anything, user just need to put it into the right table.

Because it is more convenient to handle it when individual template is processed. Otherwise error reporting will be complicated since it could be just one template which is wrong.

Otherwise, I see no point to have driver callbacks template creation API. I can do nothing here since I have no enough context. What's the problem to add the context?

Quoted 78 lines
Quoted 15 lines
Quoted 15 lines
lib/ethdev/rte_flow.h +13 -0
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   Handle on success, NULL otherwise and rte_errno is set.
+ */
+__rte_experimental
+struct rte_flow_pattern_template *
+rte_flow_pattern_template_create(uint16_t port_id,
+		const struct rte_flow_pattern_template_attr *template_attr,
+		const struct rte_flow_item pattern[],
+		struct rte_flow_error *error);
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5028

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Destroy pattern template.

Destroy flow pattern template.

Ok.

Quoted 34 lines
Quoted 34 lines
lib/ethdev/rte_flow.h +34 -0
+ *
+ * This function may be called only when
+ * there are no more tables referencing this template.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] pattern_template
+ *   Handle of the template to be destroyed.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_pattern_template_destroy(uint16_t port_id,
+		struct rte_flow_pattern_template *pattern_template,
+		struct rte_flow_error *error);
+
+/**
+ * Opaque type returned after successful creation of actions template.
+ * This handle can be used to manage the created actions template.
+ */
+struct rte_flow_actions_template;
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Flow actions template attributes.
+ */
+struct rte_flow_actions_template_attr;
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5068

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Create actions template.

Create flow rule actions template.

Yes, finally compensating for multiple no's.

Quoted 7 lines
Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+ *
+ * The actions template holds a list of action types without values.
+ * For example, the template to change TCP ports is TCP(s_port + d_port),
+ * while values for each rule will be set during the flow rule creation.
+ * The number and order of actions in the template must be the same
+ * at the rule creation.
Quoted 5 lines
Quoted 3 lines

Again, it highly depends on transfer vs non-transfer. Moreover, application definitely know it. So, it should say if the action is intended for transfer or non-transfer flow rule.

It is up to application to define which pattern it is going to use in different tables.

Same as above.

Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
lib/ethdev/rte_flow.h +31 -0
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] template_attr
+ *   Template attributes.
+ * @param[in] actions
+ *   Associated actions (list terminated by the END action).
+ *   The spec member is only used if @p masks spec is non-zero.
+ * @param[in] masks
+ *   List of actions that marks which of the action's member is constant.
+ *   A mask has the same format as the corresponding action.
+ *   If the action field in @p masks is not 0,
+ *   the corresponding value in an action from @p actions will be the part
+ *   of the template and used in all flow rules.
+ *   The order of actions in @p masks is the same as in @p actions.
+ *   In case of indirect actions present in @p actions,
+ *   the actual action type should be present in @p mask.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   Handle on success, NULL otherwise and rte_errno is set.
+ */
+__rte_experimental
+struct rte_flow_actions_template *
+rte_flow_actions_template_create(uint16_t port_id,
+		const struct rte_flow_actions_template_attr *template_attr,
+		const struct rte_flow_action actions[],
+		const struct rte_flow_action masks[],
+		struct rte_flow_error *error);

[snip]

#111 lore raw

RE: [PATCH v5 02/10] ethdev: add flow item/action templates

Hi Andrew,

Quoted 33 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Subject: Re: [PATCH v5 02/10] ethdev: add flow item/action templates

Quoted 25 lines · Alexander Kozyrev
Quoted 24 lines · On Fri, Feb 11, 2022 6:27 Andrew Rybchenko <[email protected]>…
Quoted 23 lines · Alexander Kozyrev

Treating every single flow rule as a completely independent and separate entity negatively impacts the flow rules insertion rate. Oftentimes in an application, many flow rules share a common structure (the same item mask and/or action list) so they can be grouped and classified together. This knowledge may be used as a source of optimization by a PMD/HW.

The pattern template defines common matching fields (the item mask) without values. The actions template holds a list of action types that will be used together in the same rule. The specific values for items and actions will be given only during the rule creation.

A table combines pattern and actions templates along with shared flow rule attributes (group ID, priority and traffic direction). This way a PMD/HW can prepare all the resources needed for efficient flow rules creation in the datapath. To avoid any hiccups due to memory reallocation, the maximum number of flow rules is defined at the table creation time.

The flow rule creation is done by selecting a table, a pattern template and an actions template (which are bound to the table), and setting unique values for the items and actions.

[snip]

[Snip]

Quoted 31 lines
Quoted 20 lines
Quoted 20 lines
Quoted 7 lines

+ *
+ * The pattern template defines common matching fields without values.
+ * For example, matching on 5 tuple TCP flow, the template will be
+ * eth(null) + IPv4(source + dest) + TCP(s_port + d_port),
+ * while values for each rule will be set during the flow rule creation.
+ * The number and order of items in the template must be the same
+ * at the rule creation.

Quoted 8 lines

+ *
+ * @param port_id
+ * Port identifier of Ethernet device.
+ * @param[in] template_attr
+ * Pattern template attributes.
+ * @param[in] pattern
+ * Pattern specification (list terminated by the END pattern item).
+ * The spec member of an item is not used unless the end member is used.

Interpretation of the pattern may depend on transfer vs non-transfer rule to be used. It is essential information and we should provide it when pattern template is created.

Quoted 5 lines
Quoted 1 line

The information is provided on table stage, but it is too late.

Why is it too late? Application knows which template goes to which table. And the pattern is generic to accommodate anything, user just need to put it into the right table.

Because it is more convenient to handle it when individual template is processed. Otherwise error reporting will be complicated since it could be just one template which is wrong.

Quoted 5 lines

Otherwise, I see no point to have driver callbacks template creation API. I can do nothing here since I have no enough context. What's the problem to add the context?

The idea is that the same template can be used in different domains (ingress/egress and transfer)
May be we can add on which domains this template is expected to be used. What do you think?

Quoted 78 lines
Quoted 78 lines
Quoted 15 lines
Quoted 15 lines

+ * @param[out] error
+ * Perform verbose error reporting if not NULL.
+ * PMDs initialize this structure in case of error only.
+ *
+ * @return
+ * Handle on success, NULL otherwise and rte_errno is set.
+ */

lib/ethdev/rte_flow.h +6 -0
+__rte_experimental
+struct rte_flow_pattern_template *
+rte_flow_pattern_template_create(uint16_t port_id,
+		const struct rte_flow_pattern_template_attr *template_attr,
+		const struct rte_flow_item pattern[],
+		struct rte_flow_error *error);
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5028

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Destroy pattern template.

Destroy flow pattern template.

Ok.

Quoted 34 lines
Quoted 34 lines

+ *
+ * This function may be called only when
+ * there are no more tables referencing this template.
+ *
+ * @param port_id
+ * Port identifier of Ethernet device.
+ * @param[in] pattern_template
+ * Handle of the template to be destroyed.
+ * @param[out] error
+ * Perform verbose error reporting if not NULL.
+ * PMDs initialize this structure in case of error only.
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise and rte_errno is set.
+ */

lib/ethdev/rte_flow.h +19 -0
+__rte_experimental
+int
+rte_flow_pattern_template_destroy(uint16_t port_id,
+		struct rte_flow_pattern_template *pattern_template,
+		struct rte_flow_error *error);
+
+/**
+ * Opaque type returned after successful creation of actions template.
+ * This handle can be used to manage the created actions template.
+ */
+struct rte_flow_actions_template;
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Flow actions template attributes.
+ */
+struct rte_flow_actions_template_attr;
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_configure(uint16_t port_id, · line 5068

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Create actions template.

Create flow rule actions template.

Yes, finally compensating for multiple no's.

Quoted 7 lines
Quoted 6 lines

+ *
+ * The actions template holds a list of action types without values.
+ * For example, the template to change TCP ports is TCP(s_port + d_port),
+ * while values for each rule will be set during the flow rule creation.
+ * The number and order of actions in the template must be the same
+ * at the rule creation.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Again, it highly depends on transfer vs non-transfer. Moreover, application definitely know it. So, it should say if the action is intended for transfer or non-transfer flow rule.

It is up to application to define which pattern it is going to use in different tables.

Same as above.

Same comment as above, what do you think?

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines

+ *
+ * @param port_id
+ * Port identifier of Ethernet device.
+ * @param[in] template_attr
+ * Template attributes.
+ * @param[in] actions
+ * Associated actions (list terminated by the END action).
+ * The spec member is only used if @p masks spec is non-zero.
+ * @param[in] masks

+ *   List of actions that marks which of the action's member is constant.
+ *   A mask has the same format as the corresponding action.
+ *   If the action field in @p masks is not 0,
+ *   the corresponding value in an action from @p actions will be the part
+ *   of the template and used in all flow rules.
+ *   The order of actions in @p masks is the same as in @p actions.
+ *   In case of indirect actions present in @p actions,
+ *   the actual action type should be present in @p mask.

+ * @param[out] error
+ * Perform verbose error reporting if not NULL.
+ * PMDs initialize this structure in case of error only.
+ *
+ * @return
+ * Handle on success, NULL otherwise and rte_errno is set.
+ */
+__rte_experimental

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
+struct rte_flow_actions_template *
+rte_flow_actions_template_create(uint16_t port_id,
+		const struct rte_flow_actions_template_attr *template_attr,
+		const struct rte_flow_action actions[],
+		const struct rte_flow_action masks[],
+		struct rte_flow_error *error);

[snip]

Best,
Ori

#112 lore raw

Re: [PATCH v5 02/10] ethdev: add flow item/action templates

Hi Ori,

Quoted 75 lines · Ori Kam

Hi Andrew,

Quoted 33 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Subject: Re: [PATCH v5 02/10] ethdev: add flow item/action templates

Quoted 25 lines · Alexander Kozyrev
Quoted 24 lines · On Fri, Feb 11, 2022 6:27 Andrew Rybchenko <[email protected]>…
Quoted 23 lines · Alexander Kozyrev

Treating every single flow rule as a completely independent and separate entity negatively impacts the flow rules insertion rate. Oftentimes in an application, many flow rules share a common structure (the same item mask and/or action list) so they can be grouped and classified together. This knowledge may be used as a source of optimization by a PMD/HW.

The pattern template defines common matching fields (the item mask) without values. The actions template holds a list of action types that will be used together in the same rule. The specific values for items and actions will be given only during the rule creation.

A table combines pattern and actions templates along with shared flow rule attributes (group ID, priority and traffic direction). This way a PMD/HW can prepare all the resources needed for efficient flow rules creation in the datapath. To avoid any hiccups due to memory reallocation, the maximum number of flow rules is defined at the table creation time.

The flow rule creation is done by selecting a table, a pattern template and an actions template (which are bound to the table), and setting unique values for the items and actions.

[snip]

[Snip]

Quoted 31 lines
Quoted 20 lines
Quoted 20 lines
Quoted 7 lines

+ *
+ * The pattern template defines common matching fields without values.
+ * For example, matching on 5 tuple TCP flow, the template will be
+ * eth(null) + IPv4(source + dest) + TCP(s_port + d_port),
+ * while values for each rule will be set during the flow rule creation.
+ * The number and order of items in the template must be the same
+ * at the rule creation.

Quoted 8 lines

+ *
+ * @param port_id
+ * Port identifier of Ethernet device.
+ * @param[in] template_attr
+ * Pattern template attributes.
+ * @param[in] pattern
+ * Pattern specification (list terminated by the END pattern item).
+ * The spec member of an item is not used unless the end member is used.

Interpretation of the pattern may depend on transfer vs non-transfer rule to be used. It is essential information and we should provide it when pattern template is created.

Quoted 5 lines
Quoted 1 line

The information is provided on table stage, but it is too late.

Why is it too late? Application knows which template goes to which table. And the pattern is generic to accommodate anything, user just need to put it into the right table.

Because it is more convenient to handle it when individual template is processed. Otherwise error reporting will be complicated since it could be just one template which is wrong.

Quoted 5 lines

Otherwise, I see no point to have driver callbacks template creation API. I can do nothing here since I have no enough context. What's the problem to add the context?

Quoted 4 lines

The idea is that the same template can be used in different domains (ingress/egress and transfer)
May be we can add on which domains this template is expected to be used. What do you think?

I see. IMHO if application is going to use the same template in transfer and non-transfer rules, it is not a problem to register it twice. Otherwise, if PMD needs the information and template handling differs a lot in transfer and non-transfer case, handling should be postponed and should be done on table definition. In this case, we cannot provide feedback to application which template it cannot handle. Even if the information is somehow encoded in flow error, encoding must be defined and it still could be inconvenient for the application to handle it.

Yes, I agree that it is better to fully specify domain including ingress and egress, not just transfer/non-transfer.

Andrew.

#113 lore raw

RE: [PATCH v5 02/10] ethdev: add flow item/action templates

Hi Andrew,

Quoted 99 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Thursday, February 17, 2022 12:45 PM
Subject: Re: [PATCH v5 02/10] ethdev: add flow item/action templates

Hi Ori,

Quoted 75 lines · Ori Kam

Hi Andrew,

Quoted 33 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Subject: Re: [PATCH v5 02/10] ethdev: add flow item/action templates

Quoted 25 lines · Alexander Kozyrev
Quoted 24 lines · On Fri, Feb 11, 2022 6:27 Andrew Rybchenko <[email protected]>…
Quoted 23 lines · Alexander Kozyrev

Treating every single flow rule as a completely independent and separate entity negatively impacts the flow rules insertion rate. Oftentimes in an application, many flow rules share a common structure (the same item mask and/or action list) so they can be grouped and classified together. This knowledge may be used as a source of optimization by a PMD/HW.

The pattern template defines common matching fields (the item mask) without values. The actions template holds a list of action types that will be used together in the same rule. The specific values for items and actions will be given only during the rule creation.

A table combines pattern and actions templates along with shared flow rule attributes (group ID, priority and traffic direction). This way a PMD/HW can prepare all the resources needed for efficient flow rules creation in the datapath. To avoid any hiccups due to memory reallocation, the maximum number of flow rules is defined at the table creation time.

The flow rule creation is done by selecting a table, a pattern template and an actions template (which are bound to the table), and setting unique values for the items and actions.

[snip]

[Snip]

Quoted 31 lines
Quoted 20 lines
Quoted 20 lines
Quoted 7 lines

+ *
+ * The pattern template defines common matching fields without values.
+ * For example, matching on 5 tuple TCP flow, the template will be
+ * eth(null) + IPv4(source + dest) + TCP(s_port + d_port),
+ * while values for each rule will be set during the flow rule creation.
+ * The number and order of items in the template must be the same
+ * at the rule creation.

Quoted 8 lines

+ *
+ * @param port_id
+ * Port identifier of Ethernet device.
+ * @param[in] template_attr
+ * Pattern template attributes.
+ * @param[in] pattern
+ * Pattern specification (list terminated by the END pattern item).
+ * The spec member of an item is not used unless the end member is used.

Interpretation of the pattern may depend on transfer vs non-transfer rule to be used. It is essential information and we should provide it when pattern template is created.

Quoted 5 lines
Quoted 1 line

The information is provided on table stage, but it is too late.

Why is it too late? Application knows which template goes to which table. And the pattern is generic to accommodate anything, user just need to put it into the right table.

Because it is more convenient to handle it when individual template is processed. Otherwise error reporting will be complicated since it could be just one template which is wrong.

Quoted 5 lines

Otherwise, I see no point to have driver callbacks template creation API. I can do nothing here since I have no enough context. What's the problem to add the context?

Quoted 4 lines

The idea is that the same template can be used in different domains (ingress/egress and transfer)
May be we can add on which domains this template is expected to be used. What do you think?

I see. IMHO if application is going to use the same template in transfer and non-transfer rules, it is not a problem to register it twice. Otherwise, if PMD needs the information and template handling differs a lot in transfer and non-transfer case, handling should be postponed and should be done on table definition. In this case, we cannot provide feedback to application which template it cannot handle. Even if the information is somehow encoded in flow error, encoding must be defined and it still could be inconvenient for the application to handle it.

Quoted 3 lines

Yes, I agree that it is better to fully specify domain including ingress and egress, not just transfer/non-transfer.

So lets add the 3 domains.

Quoted 1 line

Andrew.

Thanks,
Ori

#114 lore raw

PATCH v5 3/10 ethdev: bring in async queue-based flow rules operations

In reply to Alexander Kozyrev

A new, faster, queue-based flow rules management mechanism is needed for applications offloading rules inside the datapath. This asynchronous and lockless mechanism frees the CPU for further packet processing and reduces the performance impact of the flow rules creation/destruction on the datapath. Note that queues are not thread-safe and the queue should be accessed from the same thread for all queue operations. It is the responsibility of the app to sync the queue functions in case of multi-threaded access to the same queue.

The rte_flow_q_flow_create() function enqueues a flow creation to the requested queue. It benefits from already configured resources and sets unique values on top of item and action templates. A flow rule is enqueued on the specified flow queue and offloaded asynchronously to the hardware. The function returns immediately to spare CPU for further packet processing. The application must invoke the rte_flow_q_pull() function to complete the flow rule operation offloading, to clear the queue, and to receive the operation status. The rte_flow_q_flow_destroy() function enqueues a flow destruction to the requested queue.

---
 doc/guides/prog_guide/img/rte_flow_q_init.svg | 205 ++++++++++
 .../prog_guide/img/rte_flow_q_usage.svg       | 351 ++++++++++++++++++
 doc/guides/prog_guide/rte_flow.rst            | 167 ++++++++-
 doc/guides/rel_notes/release_22_03.rst        |   8 +
 lib/ethdev/rte_flow.c                         | 175 ++++++++-
 lib/ethdev/rte_flow.h                         | 334 +++++++++++++++++
 lib/ethdev/rte_flow_driver.h                  |  55 +++
 lib/ethdev/version.map                        |   7 +
 8 files changed, 1300 insertions(+), 2 deletions(-)
 create mode 100644 doc/guides/prog_guide/img/rte_flow_q_init.svg
 create mode 100644 doc/guides/prog_guide/img/rte_flow_q_usage.svg
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +205 -0
new file mode 100644
index 0000000000..96160bde42
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- SPDX-License-Identifier: BSD-3-Clause -->
+
+<!-- Copyright(c) 2022 NVIDIA Corporation & Affiliates -->
+
+<svg
+   width="485"
+   height="535"
+   overflow="hidden"
+   version="1.1"
+   id="svg61"
+   sodipodi:docname="rte_flow_q_init.svg"
+   inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:svg="http://www.w3.org/2000/svg">
+  <sodipodi:namedview
+     id="namedview63"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageshadow="2"
+     inkscape:pageopacity="0.0"
+     inkscape:pagecheckerboard="0"
+     showgrid="false"
+     inkscape:zoom="1.517757"
+     inkscape:cx="242.79249"
+     inkscape:cy="267.17057"
+     inkscape:window-width="2400"
+     inkscape:window-height="1271"
+     inkscape:window-x="2391"
+     inkscape:window-y="-9"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="g59" />
+  <defs
+     id="defs5">
+    <clipPath
+       id="clip0">
+      <rect
+         x="0"
+         y="0"
+         width="485"
+         height="535"
+         id="rect2" />
+    </clipPath>
+  </defs>
+  <g
+     clip-path="url(#clip0)"
+     id="g59">
+    <rect
+       x="0"
+       y="0"
+       width="485"
+       height="535"
+       fill="#FFFFFF"
+       id="rect7" />
+    <rect
+       x="0.500053"
+       y="79.5001"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#A6A6A6"
+       id="rect9" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="24"
+       transform="translate(121.6 116)"
+       id="text13">
+         rte_eth_dev_configure
+         <tspan
+   font-size="24"
+   x="224.007"
+   y="0"
+   id="tspan11">()</tspan></text>
+    <rect
+       x="0.500053"
+       y="158.5"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect15" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="24"
+       transform="translate(140.273 195)"
+       id="text17">
+         rte_flow_configure()
+      </text>
+    <rect
+       x="0.500053"
+       y="236.5"
+       width="482"
+       height="60"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect19" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text21"
+       x="63.425903"
+       y="274">rte_flow_pattern_template_create()</text>
+    <rect
+       x="0.500053"
+       y="316.5"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect23" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text27"
+       x="69.379204"
+       y="353">rte_flow_actions_template_create()</text>
+    <rect
+       x="0.500053"
+       y="0.500053"
+       width="482"
+       height="60"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#A6A6A6"
+       id="rect29" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       transform="translate(177.233,37)"
+       id="text33">rte_eal_init()</text>
+    <path
+       d="M2-1.09108e-05 2.00005 9.2445-1.99995 9.24452-2 1.09108e-05ZM6.00004 7.24448 0.000104987 19.2445-5.99996 7.24455Z"
+       transform="matrix(-1 0 0 1 241 60)"
+       id="path35" />
+    <path
+       d="M2-1.08133e-05 2.00005 9.41805-1.99995 9.41807-2 1.08133e-05ZM6.00004 7.41802 0.000104987 19.4181-5.99996 7.41809Z"
+       transform="matrix(-1 0 0 1 241 138)"
+       id="path37" />
+    <path
+       d="M2-1.09108e-05 2.00005 9.2445-1.99995 9.24452-2 1.09108e-05ZM6.00004 7.24448 0.000104987 19.2445-5.99996 7.24455Z"
+       transform="matrix(-1 0 0 1 241 217)"
+       id="path39" />
+    <rect
+       x="0.500053"
+       y="395.5"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect41" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text47"
+       x="76.988998"
+       y="432">rte_flow_template_table_create()</text>
+    <path
+       d="M2-1.05859e-05 2.00005 9.83526-1.99995 9.83529-2 1.05859e-05ZM6.00004 7.83524 0.000104987 19.8353-5.99996 7.83531Z"
+       transform="matrix(-1 0 0 1 241 296)"
+       id="path49" />
+    <path
+       d="M243 375 243 384.191 239 384.191 239 375ZM247 382.191 241 394.191 235 382.191Z"
+       id="path51" />
+    <rect
+       x="0.500053"
+       y="473.5"
+       width="482"
+       height="60"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#A6A6A6"
+       id="rect53" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text55"
+       x="149.30299"
+       y="511">rte_eth_dev_start()</text>
+    <path
+       d="M245 454 245 463.191 241 463.191 241 454ZM249 461.191 243 473.191 237 461.191Z"
+       id="path57" />
+  </g>
+</svg>
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +351 -0

351 lines not on this page · raw message

doc/guides/prog_guide/rte_flow.rst +166 -1

191 lines not on this page · raw message

doc/guides/rel_notes/release_22_03.rst +8 -0
index 6656b35295..87cea8a966 100644
@@ -83,6 +83,14 @@ New Features
     ``rte_flow_template_table_destroy``, ``rte_flow_pattern_template_destroy``
     and ``rte_flow_actions_template_destroy``.
 
+  * ethdev: Added ``rte_flow_q_flow_create`` and ``rte_flow_q_flow_destroy``
+    API to enqueue flow creaion/destruction operations asynchronously as well
+    as ``rte_flow_q_pull`` to poll and retrieve results of these operations
+    and ``rte_flow_q_push`` to push all the in-flight operations to the NIC.
+    Introduced asynchronous API for indirect actions management as well:
+    ``rte_flow_q_action_handle_create``, ``rte_flow_q_action_handle_destroy``
+    and ``rte_flow_q_action_handle_update``.
+
 * **Updated AF_XDP PMD**
 
   * Added support for libxdp >=v1.2.2.
lib/ethdev/rte_flow.c +174 -1

190 lines not on this page · raw message

lib/ethdev/rte_flow.h +334 -0

364 lines not on this page · raw message

lib/ethdev/rte_flow_driver.h +55 -0

67 lines not on this page · raw message

lib/ethdev/version.map +7 -0
index 5fd2108895..46a4151053 100644
@@ -268,6 +268,13 @@ EXPERIMENTAL {
 	rte_flow_actions_template_destroy;
 	rte_flow_template_table_create;
 	rte_flow_template_table_destroy;
+	rte_flow_q_flow_create;
+	rte_flow_q_flow_destroy;
+	rte_flow_q_action_handle_create;
+	rte_flow_q_action_handle_destroy;
+	rte_flow_q_action_handle_update;
+	rte_flow_q_push;
+	rte_flow_q_pull;
 };
 
 INTERNAL {
Signature · 1 line
2.18.2
#115 lore raw

Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Quoted 624 lines · Alexander Kozyrev

A new, faster, queue-based flow rules management mechanism is needed for applications offloading rules inside the datapath. This asynchronous and lockless mechanism frees the CPU for further packet processing and reduces the performance impact of the flow rules creation/destruction on the datapath. Note that queues are not thread-safe and the queue should be accessed from the same thread for all queue operations. It is the responsibility of the app to sync the queue functions in case of multi-threaded access to the same queue.

The rte_flow_q_flow_create() function enqueues a flow creation to the requested queue. It benefits from already configured resources and sets unique values on top of item and action templates. A flow rule is enqueued on the specified flow queue and offloaded asynchronously to the hardware. The function returns immediately to spare CPU for further packet processing. The application must invoke the rte_flow_q_pull() function to complete the flow rule operation offloading, to clear the queue, and to receive the operation status. The rte_flow_q_flow_destroy() function enqueues a flow destruction to the requested queue.

---
  doc/guides/prog_guide/img/rte_flow_q_init.svg | 205 ++++++++++
  .../prog_guide/img/rte_flow_q_usage.svg       | 351 ++++++++++++++++++
  doc/guides/prog_guide/rte_flow.rst            | 167 ++++++++-
  doc/guides/rel_notes/release_22_03.rst        |   8 +
  lib/ethdev/rte_flow.c                         | 175 ++++++++-
  lib/ethdev/rte_flow.h                         | 334 +++++++++++++++++
  lib/ethdev/rte_flow_driver.h                  |  55 +++
  lib/ethdev/version.map                        |   7 +
  8 files changed, 1300 insertions(+), 2 deletions(-)

create mode 100644 doc/guides/prog_guide/img/rte_flow_q_init.svg create mode 100644 doc/guides/prog_guide/img/rte_flow_q_usage.svg

doc/guides/prog_guide/img/rte_flow_q_init.svg new file +205 -0
new file mode 100644
index 0000000000..96160bde42
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- SPDX-License-Identifier: BSD-3-Clause -->
+
+<!-- Copyright(c) 2022 NVIDIA Corporation & Affiliates -->
+
+<svg
+   width="485"
+   height="535"
+   overflow="hidden"
+   version="1.1"
+   id="svg61"
+   sodipodi:docname="rte_flow_q_init.svg"
+   inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:svg="http://www.w3.org/2000/svg">
+  <sodipodi:namedview
+     id="namedview63"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageshadow="2"
+     inkscape:pageopacity="0.0"
+     inkscape:pagecheckerboard="0"
+     showgrid="false"
+     inkscape:zoom="1.517757"
+     inkscape:cx="242.79249"
+     inkscape:cy="267.17057"
+     inkscape:window-width="2400"
+     inkscape:window-height="1271"
+     inkscape:window-x="2391"
+     inkscape:window-y="-9"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="g59" />
+  <defs
+     id="defs5">
+    <clipPath
+       id="clip0">
+      <rect
+         x="0"
+         y="0"
+         width="485"
+         height="535"
+         id="rect2" />
+    </clipPath>
+  </defs>
+  <g
+     clip-path="url(#clip0)"
+     id="g59">
+    <rect
+       x="0"
+       y="0"
+       width="485"
+       height="535"
+       fill="#FFFFFF"
+       id="rect7" />
+    <rect
+       x="0.500053"
+       y="79.5001"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#A6A6A6"
+       id="rect9" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="24"
+       transform="translate(121.6 116)"
+       id="text13">
+         rte_eth_dev_configure
+         <tspan
+   font-size="24"
+   x="224.007"
+   y="0"
+   id="tspan11">()</tspan></text>
+    <rect
+       x="0.500053"
+       y="158.5"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect15" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="24"
+       transform="translate(140.273 195)"
+       id="text17">
+         rte_flow_configure()
+      </text>
+    <rect
+       x="0.500053"
+       y="236.5"
+       width="482"
+       height="60"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect19" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text21"
+       x="63.425903"
+       y="274">rte_flow_pattern_template_create()</text>
+    <rect
+       x="0.500053"
+       y="316.5"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect23" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text27"
+       x="69.379204"
+       y="353">rte_flow_actions_template_create()</text>
+    <rect
+       x="0.500053"
+       y="0.500053"
+       width="482"
+       height="60"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#A6A6A6"
+       id="rect29" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       transform="translate(177.233,37)"
+       id="text33">rte_eal_init()</text>
+    <path
+       d="M2-1.09108e-05 2.00005 9.2445-1.99995 9.24452-2 1.09108e-05ZM6.00004 7.24448 0.000104987 19.2445-5.99996 7.24455Z"
+       transform="matrix(-1 0 0 1 241 60)"
+       id="path35" />
+    <path
+       d="M2-1.08133e-05 2.00005 9.41805-1.99995 9.41807-2 1.08133e-05ZM6.00004 7.41802 0.000104987 19.4181-5.99996 7.41809Z"
+       transform="matrix(-1 0 0 1 241 138)"
+       id="path37" />
+    <path
+       d="M2-1.09108e-05 2.00005 9.2445-1.99995 9.24452-2 1.09108e-05ZM6.00004 7.24448 0.000104987 19.2445-5.99996 7.24455Z"
+       transform="matrix(-1 0 0 1 241 217)"
+       id="path39" />
+    <rect
+       x="0.500053"
+       y="395.5"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect41" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text47"
+       x="76.988998"
+       y="432">rte_flow_template_table_create()</text>
+    <path
+       d="M2-1.05859e-05 2.00005 9.83526-1.99995 9.83529-2 1.05859e-05ZM6.00004 7.83524 0.000104987 19.8353-5.99996 7.83531Z"
+       transform="matrix(-1 0 0 1 241 296)"
+       id="path49" />
+    <path
+       d="M243 375 243 384.191 239 384.191 239 375ZM247 382.191 241 394.191 235 382.191Z"
+       id="path51" />
+    <rect
+       x="0.500053"
+       y="473.5"
+       width="482"
+       height="60"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#A6A6A6"
+       id="rect53" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text55"
+       x="149.30299"
+       y="511">rte_eth_dev_start()</text>
+    <path
+       d="M245 454 245 463.191 241 463.191 241 454ZM249 461.191 243 473.191 237 461.191Z"
+       id="path57" />
+  </g>
+</svg>
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +351 -0
new file mode 100644
index 0000000000..a1f6c0a0a8
@@ -0,0 +1,351 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- SPDX-License-Identifier: BSD-3-Clause -->
+
+<!-- Copyright(c) 2022 NVIDIA Corporation & Affiliates -->
+
+<svg
+   width="880"
+   height="610"
+   overflow="hidden"
+   version="1.1"
+   id="svg103"
+   sodipodi:docname="rte_flow_q_usage.svg"
+   inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:svg="http://www.w3.org/2000/svg">
+  <sodipodi:namedview
+     id="namedview105"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageshadow="2"
+     inkscape:pageopacity="0.0"
+     inkscape:pagecheckerboard="0"
+     showgrid="false"
+     inkscape:zoom="1.3311475"
+     inkscape:cx="439.84606"
+     inkscape:cy="305.37562"
+     inkscape:window-width="2400"
+     inkscape:window-height="1271"
+     inkscape:window-x="2391"
+     inkscape:window-y="-9"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="g101" />
+  <defs
+     id="defs5">
+    <clipPath
+       id="clip0">
+      <rect
+         x="0"
+         y="0"
+         width="880"
+         height="610"
+         id="rect2" />
+    </clipPath>
+  </defs>
+  <g
+     clip-path="url(#clip0)"
+     id="g101">
+    <rect
+       x="0"
+       y="0"
+       width="880"
+       height="610"
+       fill="#FFFFFF"
+       id="rect7" />
+    <rect
+       x="333.5"
+       y="0.500053"
+       width="234"
+       height="45"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#A6A6A6"
+       id="rect9" />
+    <text
+       font-family="Consolas, Consolas_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="19px"
+       transform="translate(357.196,29)"
+       id="text11">rte_eth_rx_burst()</text>
+    <rect
+       x="333.5"
+       y="63.5001"
+       width="234"
+       height="45"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       id="rect13" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(394.666 91)"
+       id="text17">analyze <tspan
+   font-size="19"
+   x="60.9267"
+   y="0"
+   id="tspan15">packet </tspan></text>
+    <rect
+       x="572.5"
+       y="279.5"
+       width="234"
+       height="46"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect19" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(591.429 308)"
+       id="text21">rte_flow_q_flow_create()</text>
+    <path
+       d="M333.5 384 450.5 350.5 567.5 384 450.5 417.5Z"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       fill-rule="evenodd"
+       id="path23" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(430.069 378)"
+       id="text27">more <tspan
+   font-size="19"
+   x="-12.94"
+   y="23"
+   id="tspan25">packets?</tspan></text>
+    <path
+       d="M689.249 325.5 689.249 338.402 450.5 338.402 450.833 338.069 450.833 343.971 450.167 343.971 450.167 337.735 688.916 337.735 688.582 338.069 688.582 325.5ZM454.5 342.638 450.5 350.638 446.5 342.638Z"
+       id="path29" />
+    <path
+       d="M450.833 45.5 450.833 56.8197 450.167 56.8197 450.167 45.5001ZM454.5 55.4864 450.5 63.4864 446.5 55.4864Z"
+       id="path31" />
+    <path
+       d="M450.833 108.5 450.833 120.375 450.167 120.375 450.167 108.5ZM454.5 119.041 450.5 127.041 446.5 119.041Z"
+       id="path33" />
+    <path
+       d="M451.833 507.5 451.833 533.61 451.167 533.61 451.167 507.5ZM455.5 532.277 451.5 540.277 447.5 532.277Z"
+       id="path35" />
+    <path
+       d="M0 0.333333-23.9993 0.333333-23.666 0-23.666 141.649-23.9993 141.316 562.966 141.316 562.633 141.649 562.633 124.315 563.299 124.315 563.299 141.983-24.3327 141.983-24.3327-0.333333 0-0.333333ZM558.966 125.649 562.966 117.649 566.966 125.649Z"
+       transform="matrix(-6.12323e-17 -1 -1 6.12323e-17 451.149 585.466)"
+       id="path37" />
+    <path
+       d="M333.5 160.5 450.5 126.5 567.5 160.5 450.5 194.5Z"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       fill-rule="evenodd"
+       id="path39" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(417.576 155)"
+       id="text43">add new <tspan
+   font-size="19"
+   x="13.2867"
+   y="23"
+   id="tspan41">rule?</tspan></text>
+    <path
+       d="M567.5 160.167 689.267 160.167 689.267 273.228 688.6 273.228 688.6 160.5 688.933 160.833 567.5 160.833ZM692.933 271.894 688.933 279.894 684.933 271.894Z"
+       id="path45" />
+    <rect
+       x="602.5"
+       y="127.5"
+       width="46"
+       height="30"
+       stroke="#000000"
+       stroke-width="0.666667"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       id="rect47" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(611.34 148)"
+       id="text49">yes</text>
+    <rect
+       x="254.5"
+       y="126.5"
+       width="46"
+       height="31"
+       stroke="#000000"
+       stroke-width="0.666667"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       id="rect51" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(267.182 147)"
+       id="text53">no</text>
+    <path
+       d="M0-0.333333 251.563-0.333333 251.563 298.328 8.00002 298.328 8.00002 297.662 251.229 297.662 250.896 297.995 250.896 0 251.229 0.333333 0 0.333333ZM9.33333 301.995 1.33333 297.995 9.33333 293.995Z"
+       transform="matrix(1 0 0 -1 567.5 383.495)"
+       id="path55" />
+    <path
+       d="M86.5001 213.5 203.5 180.5 320.5 213.5 203.5 246.5Z"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       fill-rule="evenodd"
+       id="path57" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(159.155 208)"
+       id="text61">destroy the <tspan
+   font-size="19"
+   x="24.0333"
+   y="23"
+   id="tspan59">rule?</tspan></text>
+    <path
+       d="M0-0.333333 131.029-0.333333 131.029 12.9778 130.363 12.9778 130.363 0 130.696 0.333333 0 0.333333ZM134.696 11.6445 130.696 19.6445 126.696 11.6445Z"
+       transform="matrix(-1 1.22465e-16 1.22465e-16 1 334.196 160.5)"
+       id="path63" />
+    <rect
+       x="81.5001"
+       y="280.5"
+       width="234"
+       height="45"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect65" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(96.2282 308)"
+       id="text67">rte_flow_q_flow_destroy()</text>
+    <path
+       d="M0 0.333333-24.0001 0.333333-23.6667 0-23.6667 49.9498-24.0001 49.6165 121.748 49.6165 121.748 59.958 121.082 59.958 121.082 49.9498 121.415 50.2832-24.3334 50.2832-24.3334-0.333333 0-0.333333ZM125.415 58.6247 121.415 66.6247 117.415 58.6247Z"
+       transform="matrix(-1 0 0 1 319.915 213.5)"
+       id="path69" />
+    <path
+       d="M86.5001 213.833 62.5002 213.833 62.8335 213.5 62.8335 383.95 62.5002 383.617 327.511 383.617 327.511 384.283 62.1668 384.283 62.1668 213.167 86.5001 213.167ZM326.178 379.95 334.178 383.95 326.178 387.95Z"
+       id="path71" />
+    <path
+       d="M0-0.333333 12.8273-0.333333 12.8273 252.111 12.494 251.778 18.321 251.778 18.321 252.445 12.1607 252.445 12.1607 0 12.494 0.333333 0 0.333333ZM16.9877 248.111 24.9877 252.111 16.9877 256.111Z"
+       transform="matrix(1.83697e-16 1 1 -1.83697e-16 198.5 325.5)"
+       id="path73" />
+    <rect
+       x="334.5"
+       y="540.5"
+       width="234"
+       height="45"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect75" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="19px"
+       id="text77"
+       x="385.08301"
+       y="569">rte_flow_q_pull()</text>
+    <rect
+       x="334.5"
+       y="462.5"
+       width="234"
+       height="45"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect79" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(379.19 491)"
+       id="text81">rte_flow_q_push()</text>
+    <path
+       d="M450.833 417.495 451.402 455.999 450.735 456.008 450.167 417.505ZM455.048 454.611 451.167 462.669 447.049 454.729Z"
+       id="path83" />
+    <rect
+       x="0.500053"
+       y="287.5"
+       width="46"
+       height="30"
+       stroke="#000000"
+       stroke-width="0.666667"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       id="rect85" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(12.8617 308)"
+       id="text87">no</text>
+    <rect
+       x="357.5"
+       y="223.5"
+       width="47"
+       height="31"
+       stroke="#000000"
+       stroke-width="0.666667"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       id="rect89" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(367.001 244)"
+       id="text91">yes</text>
+    <rect
+       x="469.5"
+       y="421.5"
+       width="46"
+       height="30"
+       stroke="#000000"
+       stroke-width="0.666667"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       id="rect93" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(481.872 442)"
+       id="text95">no</text>
+    <rect
+       x="832.5"
+       y="223.5"
+       width="46"
+       height="31"
+       stroke="#000000"
+       stroke-width="0.666667"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       id="rect97" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(841.777 244)"
+       id="text99">yes</text>
+  </g>
+</svg>
doc/guides/prog_guide/rte_flow.rst +4 -0
index 5391648833..5d47f3bd21 100644
@@ -3607,12 +3607,16 @@ Expected number of counters or meters in an application, for example,
  allow PMD to prepare and optimize NIC memory layout in advance.
  ``rte_flow_configure()`` must be called before any flow rule is created,
  but after an Ethernet device is configured.
+It also creates flow queues for asynchronous flow rules operations via
+queue-based API, see `Asynchronous operations`_ section.
 
  .. code-block:: c
 
     int
     rte_flow_configure(uint16_t port_id,
                       const struct rte_flow_port_attr *port_attr,
+                     uint16_t nb_queue,
+                     const struct rte_flow_queue_attr *queue_attr[],
                       struct rte_flow_error *error);
 
  Information about resources that can benefit from pre-allocation can be

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3744

Quoted 5 lines
doc/guides/prog_guide/rte_flow.rst +1 -1
@@ -3737,7 +3741,7 @@ and pattern and actions templates are created.
 
  .. code-block:: c
 
-	rte_flow_configure(port, *port_attr, *error);
+	rte_flow_configure(port, *port_attr, nb_queue, *queue_attr, *error);

* before queue_attr looks strange

Quoted 7 lines
doc/guides/prog_guide/rte_flow.rst +0 -0
  	struct rte_flow_pattern_template *pattern_templates[0] =
  		rte_flow_pattern_template_create(port, &itr, &pattern, &error);
@@ -3750,6 +3754,167 @@ and pattern and actions templates are created.
  				*actions_templates, nb_actions_templates,
  				*error);
 

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3766

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+Asynchronous operations
+-----------------------
+
+Flow rules management can be done via special lockless flow management queues.
+- Queue operations are asynchronous and not thread-safe.
+
+- Operations can thus be invoked by the app's datapath,
+  packet processing can continue while queue operations are processed by NIC.
+
+- The queue number is configured at initialization stage.

I read "the queue number" as some number for a specific queue. May be "Number of queues is configured..."

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3771

Quoted 5 lines
doc/guides/prog_guide/rte_flow.rst +5 -0
+
+- Available operation types: rule creation, rule destruction,
+  indirect rule creation, indirect rule destruction, indirect rule update.
+
+- Operations may be reordered within a queue.

Do we want to have barriers?
E.g. create rule, destroy the same rule -> reoder -> destroy fails, rule lives forever.

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3775

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+- Operations can be postponed and pushed to NIC in batches.
+
+- Results pulling must be done on time to avoid queue overflows.

polling? (as libc poll() which checks status of file descriptors) it is not pulling the door to open it :)

Quoted 366 lines
doc/guides/prog_guide/rte_flow.rst +142 -0
+
+- User data is returned as part of the result to identify an operation.
+
+- Flow handle is valid once the creation operation is enqueued and must be
+  destroyed even if the operation is not successful and the rule is not inserted.
+
+The asynchronous flow rule insertion logic can be broken into two phases.
+
+1. Initialization stage as shown here:
+
+.. _figure_rte_flow_q_init:
+
+.. figure:: img/rte_flow_q_init.*
+
+2. Main loop as presented on a datapath application example:
+
+.. _figure_rte_flow_q_usage:
+
+.. figure:: img/rte_flow_q_usage.*
+
+Enqueue creation operation
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Enqueueing a flow rule creation operation is similar to simple creation.
+
+.. code-block:: c
+
+	struct rte_flow *
+	rte_flow_q_flow_create(uint16_t port_id,
+				uint32_t queue_id,
+				const struct rte_flow_q_ops_attr *q_ops_attr,
+				struct rte_flow_template_table *template_table,
+				const struct rte_flow_item pattern[],
+				uint8_t pattern_template_index,
+				const struct rte_flow_action actions[],
+				uint8_t actions_template_index,
+				struct rte_flow_error *error);
+
+A valid handle in case of success is returned. It must be destroyed later
+by calling ``rte_flow_q_flow_destroy()`` even if the rule is rejected by HW.
+
+Enqueue destruction operation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Enqueueing a flow rule destruction operation is similar to simple destruction.
+
+.. code-block:: c
+
+	int
+	rte_flow_q_flow_destroy(uint16_t port_id,
+				uint32_t queue_id,
+				const struct rte_flow_q_ops_attr *q_ops_attr,
+				struct rte_flow *flow,
+				struct rte_flow_error *error);
+
+Push enqueued operations
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Pushing all internally stored rules from a queue to the NIC.
+
+.. code-block:: c
+
+	int
+	rte_flow_q_push(uint16_t port_id,
+			uint32_t queue_id,
+			struct rte_flow_error *error);
+
+There is the postpone attribute in the queue operation attributes.
+When it is set, multiple operations can be bulked together and not sent to HW
+right away to save SW/HW interactions and prioritize throughput over latency.
+The application must invoke this function to actually push all outstanding
+operations to HW in this case.
+
+Pull enqueued operations
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Pulling asynchronous operations results.
+
+The application must invoke this function in order to complete asynchronous
+flow rule operations and to receive flow rule operations statuses.
+
+.. code-block:: c
+
+	int
+	rte_flow_q_pull(uint16_t port_id,
+			uint32_t queue_id,
+			struct rte_flow_q_op_res res[],
+			uint16_t n_res,
+			struct rte_flow_error *error);
+
+Multiple outstanding operation results can be pulled simultaneously.
+User data may be provided during a flow creation/destruction in order
+to distinguish between multiple operations. User data is returned as part
+of the result to provide a method to detect which operation is completed.
+
+Enqueue indirect action creation operation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Asynchronous version of indirect action creation API.
+
+.. code-block:: c
+
+	struct rte_flow_action_handle *
+	rte_flow_q_action_handle_create(uint16_t port_id,
+			uint32_t queue_id,
+			const struct rte_flow_q_ops_attr *q_ops_attr,
+			const struct rte_flow_indir_action_conf *indir_action_conf,
+			const struct rte_flow_action *action,
+			struct rte_flow_error *error);
+
+A valid handle in case of success is returned. It must be destroyed later by
+calling ``rte_flow_q_action_handle_destroy()`` even if the rule is rejected.
+
+Enqueue indirect action destruction operation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Asynchronous version of indirect action destruction API.
+
+.. code-block:: c
+
+	int
+	rte_flow_q_action_handle_destroy(uint16_t port_id,
+			uint32_t queue_id,
+			const struct rte_flow_q_ops_attr *q_ops_attr,
+			struct rte_flow_action_handle *action_handle,
+			struct rte_flow_error *error);
+
+Enqueue indirect action update operation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Asynchronous version of indirect action update API.
+
+.. code-block:: c
+
+	int
+	rte_flow_q_action_handle_update(uint16_t port_id,
+			uint32_t queue_id,
+			const struct rte_flow_q_ops_attr *q_ops_attr,
+			struct rte_flow_action_handle *action_handle,
+			const void *update,
+			struct rte_flow_error *error);
+
  .. _flow_isolated_mode:
 
  Flow isolated mode
doc/guides/rel_notes/release_22_03.rst +8 -0
index 6656b35295..87cea8a966 100644
@@ -83,6 +83,14 @@ New Features
      ``rte_flow_template_table_destroy``, ``rte_flow_pattern_template_destroy``
      and ``rte_flow_actions_template_destroy``.
 
+  * ethdev: Added ``rte_flow_q_flow_create`` and ``rte_flow_q_flow_destroy``
+    API to enqueue flow creaion/destruction operations asynchronously as well
+    as ``rte_flow_q_pull`` to poll and retrieve results of these operations
+    and ``rte_flow_q_push`` to push all the in-flight operations to the NIC.
+    Introduced asynchronous API for indirect actions management as well:
+    ``rte_flow_q_action_handle_create``, ``rte_flow_q_action_handle_destroy``
+    and ``rte_flow_q_action_handle_update``.
+
  * **Updated AF_XDP PMD**
 
    * Added support for libxdp >=v1.2.2.
lib/ethdev/rte_flow.c +174 -1
index b53f8c9b89..aca5bac2da 100644
@@ -1415,6 +1415,8 @@ rte_flow_info_get(uint16_t port_id,
  int
  rte_flow_configure(uint16_t port_id,
  		   const struct rte_flow_port_attr *port_attr,
+		   uint16_t nb_queue,
+		   const struct rte_flow_queue_attr *queue_attr[],
  		   struct rte_flow_error *error)
  {
  	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
@@ -1424,7 +1426,8 @@ rte_flow_configure(uint16_t port_id,
  		return -rte_errno;
  	if (likely(!!ops->configure)) {
  		return flow_err(port_id,
-				ops->configure(dev, port_attr, error),
+				ops->configure(dev, port_attr,
+					       nb_queue, queue_attr, error),
  				error);
  	}
  	return rte_flow_error_set(error, ENOTSUP,
@@ -1578,3 +1581,173 @@ rte_flow_template_table_destroy(uint16_t port_id,
  				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
  				  NULL, rte_strerror(ENOTSUP));
  }
+
+struct rte_flow *
+rte_flow_q_flow_create(uint16_t port_id,
+		       uint32_t queue_id,
+		       const struct rte_flow_q_ops_attr *q_ops_attr,
+		       struct rte_flow_template_table *template_table,
+		       const struct rte_flow_item pattern[],
+		       uint8_t pattern_template_index,
+		       const struct rte_flow_action actions[],
+		       uint8_t actions_template_index,
+		       struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	struct rte_flow *flow;
+
+	if (unlikely(!ops))
+		return NULL;
+	if (likely(!!ops->q_flow_create)) {
+		flow = ops->q_flow_create(dev, queue_id,
+					  q_ops_attr, template_table,
+					  pattern, pattern_template_index,
+					  actions, actions_template_index,
+					  error);
+		if (flow == NULL)
+			flow_err(port_id, -rte_errno, error);
+		return flow;
+	}
+	rte_flow_error_set(error, ENOTSUP,
+			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+			   NULL, rte_strerror(ENOTSUP));
+	return NULL;
+}
+
+int
+rte_flow_q_flow_destroy(uint16_t port_id,
+			uint32_t queue_id,
+			const struct rte_flow_q_ops_attr *q_ops_attr,
+			struct rte_flow *flow,
+			struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->q_flow_destroy)) {
+		return flow_err(port_id,
+				ops->q_flow_destroy(dev, queue_id,
+						    q_ops_attr, flow, error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+struct rte_flow_action_handle *
+rte_flow_q_action_handle_create(uint16_t port_id,
+		uint32_t queue_id,
+		const struct rte_flow_q_ops_attr *q_ops_attr,
+		const struct rte_flow_indir_action_conf *indir_action_conf,
+		const struct rte_flow_action *action,
+		struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	struct rte_flow_action_handle *handle;
+
+	if (unlikely(!ops))
+		return NULL;
+	if (unlikely(!ops->q_action_handle_create)) {
+		rte_flow_error_set(error, ENOSYS,
+				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+				   rte_strerror(ENOSYS));
+		return NULL;
+	}
+	handle = ops->q_action_handle_create(dev, queue_id, q_ops_attr,
+					     indir_action_conf, action, error);
+	if (handle == NULL)
+		flow_err(port_id, -rte_errno, error);
+	return handle;
+}
+
+int
+rte_flow_q_action_handle_destroy(uint16_t port_id,
+		uint32_t queue_id,
+		const struct rte_flow_q_ops_attr *q_ops_attr,
+		struct rte_flow_action_handle *action_handle,
+		struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (unlikely(!ops->q_action_handle_destroy))
+		return rte_flow_error_set(error, ENOSYS,
+					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL, rte_strerror(ENOSYS));
+	ret = ops->q_action_handle_destroy(dev, queue_id, q_ops_attr,
+					   action_handle, error);
+	return flow_err(port_id, ret, error);
+}
+
+int
+rte_flow_q_action_handle_update(uint16_t port_id,
+		uint32_t queue_id,
+		const struct rte_flow_q_ops_attr *q_ops_attr,
+		struct rte_flow_action_handle *action_handle,
+		const void *update,
+		struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (unlikely(!ops->q_action_handle_update))
+		return rte_flow_error_set(error, ENOSYS,
+					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL, rte_strerror(ENOSYS));
+	ret = ops->q_action_handle_update(dev, queue_id, q_ops_attr,
+					  action_handle, update, error);
+	return flow_err(port_id, ret, error);
+}
+
+int
+rte_flow_q_push(uint16_t port_id,
+		uint32_t queue_id,
+		struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->q_push)) {
+		return flow_err(port_id,
+				ops->q_push(dev, queue_id, error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_q_pull(uint16_t port_id,
+		uint32_t queue_id,
+		struct rte_flow_q_op_res res[],
+		uint16_t n_res,
+		struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->q_pull)) {
+		ret = ops->q_pull(dev, queue_id, res, n_res, error);
+		return ret ? ret : flow_err(port_id, ret, error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +0 -0
index e87db5a540..b0d4f33bfd 100644

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4866

Quoted 5 lines
lib/ethdev/rte_flow.h +2 -0
@@ -4862,6 +4862,10 @@ rte_flow_flex_item_release(uint16_t port_id,
   *
   */
  struct rte_flow_port_info {
+	/**
+	 * Number of queues for asynchronous operations.

Is it a maximum number of queues?

Quoted 8 lines
lib/ethdev/rte_flow.h +2 -0
+	 */
+	uint32_t nb_queues;
  	/**
  	 * Number of pre-configurable counter actions.
  	 * @see RTE_FLOW_ACTION_TYPE_COUNT
@@ -4879,6 +4883,17 @@ struct rte_flow_port_info {
  	uint32_t nb_meters;
  };

lib/ethdev/rte_flow.h struct rte_flow_port_info { · line 4894

Quoted 10 lines
lib/ethdev/rte_flow.h +9 -0
 
+/**
+ * Flow engine queue configuration.
+ */
+__extension__
+struct rte_flow_queue_attr {
+	/**
+	 * Number of flow rule operations a queue can hold.
+	 */
+	uint32_t size;

Whar are the min/max sizes? 0 as the default size, if yes, do we need an API to find actual size?

Quoted 31 lines
lib/ethdev/rte_flow.h +10 -0
+};
+
  /**
   * @warning
   * @b EXPERIMENTAL: this API may change without prior notice.
@@ -4948,6 +4963,11 @@ struct rte_flow_port_attr {
   *   Port identifier of Ethernet device.
   * @param[in] port_attr
   *   Port configuration attributes.
+ * @param[in] nb_queue
+ *   Number of flow queues to be configured.
+ * @param[in] queue_attr
+ *   Array that holds attributes for each flow queue.
+ *   Number of elements is set in @p port_attr.nb_queues.
   * @param[out] error
   *   Perform verbose error reporting if not NULL.
   *   PMDs initialize this structure in case of error only.
@@ -4959,6 +4979,8 @@ __rte_experimental
  int
  rte_flow_configure(uint16_t port_id,
  		   const struct rte_flow_port_attr *port_attr,
+		   uint16_t nb_queue,
+		   const struct rte_flow_queue_attr *queue_attr[],
  		   struct rte_flow_error *error);
 
  /**
@@ -5221,6 +5243,318 @@ rte_flow_template_table_destroy(uint16_t port_id,
  		struct rte_flow_template_table *template_table,
  		struct rte_flow_error *error);
 
+/**

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5256

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Queue operation attributes.
+ */
+struct rte_flow_q_ops_attr {
+	/**
+	 * The user data that will be returned on the completion events.
+	 */
+	void *user_data;

IMHO it must not be hiddne in attrs. It is a key information which is used to understand the opration result. It should be passed separately.

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5259

Quoted 3 lines
lib/ethdev/rte_flow.h +3 -0
+	 /**
+	  * When set, the requested action will not be sent to the HW immediately.
+	  * The application must call the rte_flow_queue_push to actually send it.

Will the next operation without the attribute set implicitly push it? Is it mandatory for the driver to respect it? Or is it just a possible optimization hint?

Quoted 8 lines
lib/ethdev/rte_flow.h +8 -0
+	  */
+	uint32_t postpone:1;
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5277

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * Enqueue rule creation operation.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param queue_id
+ *   Flow queue used to insert the rule.
+ * @param[in] q_ops_attr
+ *   Rule creation operation attributes.
+ * @param[in] template_table
+ *   Template table to select templates from.

IMHO it should be done optional. I.e. NULL allows. If NULL, indecies are ignored and pattern+actions are full specificiation as in rte_flow_create(). The only missing bit is attributes.

Basically I'm sure that hardwiring queue-based flow rule control to template is the right solution. It should be possible without templates. May be it should be a separate API to be added later if/when required.

Quoted 8 lines
lib/ethdev/rte_flow.h +8 -0
+ * @param[in] pattern
+ *   List of pattern items to be used.
+ *   The list order should match the order in the pattern template.
+ *   The spec is the only relevant member of the item that is being used.
+ * @param[in] pattern_template_index
+ *   Pattern template index in the table.
+ * @param[in] actions
+ *   List of actions to be used.

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5295

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ *   The list order should match the order in the actions template.
+ * @param[in] actions_template_index
+ *   Actions template index in the table.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   Handle on success, NULL otherwise and rte_errno is set.
+ *   The rule handle doesn't mean that the rule was offloaded.

"was offloaded" sounds ambiguous. API says nothing about any kind of offloading before. "has been populated" or "has been created" (since API says "create").

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5300

Quoted 5 lines
lib/ethdev/rte_flow.h +5 -0
+ *   Only completion result indicates that the rule was offloaded.
+ */
+__rte_experimental
+struct rte_flow *
+rte_flow_q_flow_create(uint16_t port_id,

flow_q_flow does not sound like a good nameing, consider:
rte_flow_q_rule_create() is <subsystem>_<subtype>_<object>_<action>

Quoted 57 lines
lib/ethdev/rte_flow.h +57 -0
+		       uint32_t queue_id,
+		       const struct rte_flow_q_ops_attr *q_ops_attr,
+		       struct rte_flow_template_table *template_table,
+		       const struct rte_flow_item pattern[],
+		       uint8_t pattern_template_index,
+		       const struct rte_flow_action actions[],
+		       uint8_t actions_template_index,
+		       struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue rule destruction operation.
+ *
+ * This function enqueues a destruction operation on the queue.
+ * Application should assume that after calling this function
+ * the rule handle is not valid anymore.
+ * Completion indicates the full removal of the rule from the HW.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param queue_id
+ *   Flow queue which is used to destroy the rule.
+ *   This must match the queue on which the rule was created.
+ * @param[in] q_ops_attr
+ *   Rule destroy operation attributes.
+ * @param[in] flow
+ *   Flow handle to be destroyed.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_q_flow_destroy(uint16_t port_id,
+			uint32_t queue_id,
+			const struct rte_flow_q_ops_attr *q_ops_attr,
+			struct rte_flow *flow,
+			struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue indirect action creation operation.
+ * @see rte_flow_action_handle_create
+ *
+ * @param[in] port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] queue_id
+ *   Flow queue which is used to create the rule.
+ * @param[in] q_ops_attr
+ *   Queue operation attributes.

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5367

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * @param[in] indir_action_conf
+ *   Action configuration for the indirect action object creation.
+ * @param[in] action
+ *   Specific configuration of the indirect action object.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   - (0) if success.

Hold on. Pointer is returned by the function.

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5373

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - (-ENOSYS) if underlying device does not support this functionality.
+ *   - (-EIO) if underlying device is removed.
+ *   - (-ENOENT) if action pointed by *action* handle was not found.
+ *   - (-EBUSY) if action pointed by *action* handle still used by some rules
+ *   rte_errno is also set.

Which error code should be used if too many ops are enqueued (overflow)?

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5381

Quoted 8 lines
lib/ethdev/rte_flow.h +8 -0
+ */
+__rte_experimental
+struct rte_flow_action_handle *
+rte_flow_q_action_handle_create(uint16_t port_id,
+		uint32_t queue_id,
+		const struct rte_flow_q_ops_attr *q_ops_attr,
+		const struct rte_flow_indir_action_conf *indir_action_conf,
+		const struct rte_flow_action *action,

I don't understand why it differs so much from rule creation. Why is action template not used?
IMHO indirect actions should be dropped from the patch and added separately since it is a separate feature.

Quoted 157 lines
lib/ethdev/rte_flow.h +157 -0
+		struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue indirect action destruction operation.
+ * The destroy queue must be the same
+ * as the queue on which the action was created.
+ *
+ * @param[in] port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] queue_id
+ *   Flow queue which is used to destroy the rule.
+ * @param[in] q_ops_attr
+ *   Queue operation attributes.
+ * @param[in] action_handle
+ *   Handle for the indirect action object to be destroyed.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   - (0) if success.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - (-ENOSYS) if underlying device does not support this functionality.
+ *   - (-EIO) if underlying device is removed.
+ *   - (-ENOENT) if action pointed by *action* handle was not found.
+ *   - (-EBUSY) if action pointed by *action* handle still used by some rules
+ *   rte_errno is also set.
+ */
+__rte_experimental
+int
+rte_flow_q_action_handle_destroy(uint16_t port_id,
+		uint32_t queue_id,
+		const struct rte_flow_q_ops_attr *q_ops_attr,
+		struct rte_flow_action_handle *action_handle,
+		struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue indirect action update operation.
+ * @see rte_flow_action_handle_create
+ *
+ * @param[in] port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] queue_id
+ *   Flow queue which is used to update the rule.
+ * @param[in] q_ops_attr
+ *   Queue operation attributes.
+ * @param[in] action_handle
+ *   Handle for the indirect action object to be updated.
+ * @param[in] update
+ *   Update profile specification used to modify the action pointed by handle.
+ *   *update* could be with the same type of the immediate action corresponding
+ *   to the *handle* argument when creating, or a wrapper structure includes
+ *   action configuration to be updated and bit fields to indicate the member
+ *   of fields inside the action to update.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   - (0) if success.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - (-ENOSYS) if underlying device does not support this functionality.
+ *   - (-EIO) if underlying device is removed.
+ *   - (-ENOENT) if action pointed by *action* handle was not found.
+ *   - (-EBUSY) if action pointed by *action* handle still used by some rules
+ *   rte_errno is also set.
+ */
+__rte_experimental
+int
+rte_flow_q_action_handle_update(uint16_t port_id,
+		uint32_t queue_id,
+		const struct rte_flow_q_ops_attr *q_ops_attr,
+		struct rte_flow_action_handle *action_handle,
+		const void *update,
+		struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Push all internally stored rules to the HW.
+ * Postponed rules are rules that were inserted with the postpone flag set.
+ * Can be used to notify the HW about batch of rules prepared by the SW to
+ * reduce the number of communications between the HW and SW.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param queue_id
+ *   Flow queue to be pushed.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *    0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_q_push(uint16_t port_id,
+		uint32_t queue_id,
+		struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Queue operation status.
+ */
+enum rte_flow_q_op_status {
+	/**
+	 * The operation was completed successfully.
+	 */
+	RTE_FLOW_Q_OP_SUCCESS,
+	/**
+	 * The operation was not completed successfully.
+	 */
+	RTE_FLOW_Q_OP_ERROR,
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Queue operation results.
+ */
+__extension__
+struct rte_flow_q_op_res {
+	/**
+	 * Returns the status of the operation that this completion signals.
+	 */
+	enum rte_flow_q_op_status status;
+	/**
+	 * The user data that will be returned on the completion events.
+	 */
+	void *user_data;
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Pull a rte flow operation.
+ * The application must invoke this function in order to complete
+ * the flow rule offloading and to retrieve the flow rule operation status.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param queue_id
+ *   Flow queue which is used to pull the operation.
+ * @param[out] res
+ *   Array of results that will be set.

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5548

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * @param[in] n_res
+ *   Maximum number of results that can be returned.
+ *   This value is equal to the size of the res array.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   Number of results that were pulled,
+ *   a negative errno value otherwise and rte_errno is set.

Don't we want to define negative error code meaning?

Quoted 12 lines
lib/ethdev/rte_flow.h +9 -0
+ */
+__rte_experimental
+int
+rte_flow_q_pull(uint16_t port_id,
+		uint32_t queue_id,
+		struct rte_flow_q_op_res res[],
+		uint16_t n_res,
+		struct rte_flow_error *error);
+
  #ifdef __cplusplus
  }
  #endif
#116 lore raw

RE: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko <[email protected]>:

Quoted 719 lines · Alexander Kozyrev
Quoted 1 line

A new, faster, queue-based flow rules management mechanism is needed

for

Quoted 8 lines

applications offloading rules inside the datapath. This asynchronous and lockless mechanism frees the CPU for further packet processing and reduces the performance impact of the flow rules creation/destruction on the datapath. Note that queues are not thread-safe and the queue should be accessed from the same thread for all queue operations. It is the responsibility of the app to sync the queue functions in case of multi-threaded access to the same queue.

Quoted 4 lines

The rte_flow_q_flow_create() function enqueues a flow creation to the requested queue. It benefits from already configured resources and sets unique values on top of item and action templates. A flow rule is enqueued on the specified flow queue and offloaded asynchronously to the

hardware.

Quoted 11 lines

The function returns immediately to spare CPU for further packet processing. The application must invoke the rte_flow_q_pull() function to complete the flow rule operation offloading, to clear the queue, and to receive the operation status. The rte_flow_q_flow_destroy() function enqueues a flow destruction to the requested queue.

---
  doc/guides/prog_guide/img/rte_flow_q_init.svg | 205 ++++++++++
  .../prog_guide/img/rte_flow_q_usage.svg       | 351

++++++++++++++++++

Review

Quoted 11 lines
  doc/guides/prog_guide/rte_flow.rst            | 167 ++++++++-
  doc/guides/rel_notes/release_22_03.rst        |   8 +
  lib/ethdev/rte_flow.c                         | 175 ++++++++-
  lib/ethdev/rte_flow.h                         | 334 +++++++++++++++++
  lib/ethdev/rte_flow_driver.h                  |  55 +++
  lib/ethdev/version.map                        |   7 +
  8 files changed, 1300 insertions(+), 2 deletions(-)

create mode 100644 doc/guides/prog_guide/img/rte_flow_q_init.svg create mode 100644 doc/guides/prog_guide/img/rte_flow_q_usage.svg

(quoted diff) +0 -0

b/doc/guides/prog_guide/img/rte_flow_q_init.svg

Quoted 9 lines

new file mode 100644
index 0000000000..96160bde42

doc/guides/prog_guide/img/rte_flow_q_init.svg new file +4 -0
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- SPDX-License-Identifier: BSD-3-Clause -->
+
+<!-- Copyright(c) 2022 NVIDIA Corporation & Affiliates -->

doc/guides/prog_guide/img/rte_flow_q_init.svg line 14

Quoted 10 lines
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +10 -0
+
+<svg
+   width="485"
+   height="535"
+   overflow="hidden"
+   version="1.1"
+   id="svg61"
+   sodipodi:docname="rte_flow_q_init.svg"
+   inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
+

xmlns:inkscape="https://nam11.safelinks.protection.outlook.com/?url=http %3A%2F%2Fwww.inkscape.org%2Fnamespaces%2Finkscape&amp;data=04 %7C01%7Cakozyrev%40nvidia.com%7C17305c0b25ed4450b31008d9ed5bf333 %7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637801801473234111 %7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiL CJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=xpBAPvwrE5t1eHUc YHt%2FzLJ5seo%2F%2FomPwGvplYtAgv0%3D&amp;reserved=0"

doc/guides/prog_guide/img/rte_flow_q_init.svg line 15

Quoted 1 line
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +1 -0
+

xmlns:sodipodi="https://nam11.safelinks.protection.outlook.com/?url=http %3A%2F%2Fsodipodi.sourceforge.net%2FDTD%2Fsodipodi- 0.dtd&amp;data=04%7C01%7Cakozyrev%40nvidia.com%7C17305c0b25ed445 0b31008d9ed5bf333%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C 637801801473234111%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwM DAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata =yFZ8tT7Zge2JgcuCKPGPe8MhGNEfsD2fdWpHdkO8qoc%3D&amp;reserved= 0"

doc/guides/prog_guide/img/rte_flow_q_init.svg line 16

Quoted 1 line
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +1 -0
+

xmlns="https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F %2Fwww.w3.org%2F2000%2Fsvg&amp;data=04%7C01%7Cakozyrev%40nvidi a.com%7C17305c0b25ed4450b31008d9ed5bf333%7C43083d15727340c1b7db3 9efd9ccc17a%7C0%7C0%7C637801801473234111%7CUnknown%7CTWFpbGZs b3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn 0%3D%7C3000&amp;sdata=e2WMYQltdZPW%2FaZEm0RgJXXyaRFxJH%2B279 J1xTp9eg4%3D&amp;reserved=0"

doc/guides/prog_guide/img/rte_flow_q_init.svg line 17

Quoted 1 line
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +1 -0
+

xmlns:svg="https://nam11.safelinks.protection.outlook.com/?url=http%3A% 2F%2Fwww.w3.org%2F2000%2Fsvg&amp;data=04%7C01%7Cakozyrev%40nvi dia.com%7C17305c0b25ed4450b31008d9ed5bf333%7C43083d15727340c1b7d b39efd9ccc17a%7C0%7C0%7C637801801473234111%7CUnknown%7CTWFpb GZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI 6Mn0%3D%7C3000&amp;sdata=e2WMYQltdZPW%2FaZEm0RgJXXyaRFxJH%2 B279J1xTp9eg4%3D&amp;reserved=0">

Quoted 122 lines
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +122 -0
+  <sodipodi:namedview
+     id="namedview63"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageshadow="2"
+     inkscape:pageopacity="0.0"
+     inkscape:pagecheckerboard="0"
+     showgrid="false"
+     inkscape:zoom="1.517757"
+     inkscape:cx="242.79249"
+     inkscape:cy="267.17057"
+     inkscape:window-width="2400"
+     inkscape:window-height="1271"
+     inkscape:window-x="2391"
+     inkscape:window-y="-9"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="g59" />
+  <defs
+     id="defs5">
+    <clipPath
+       id="clip0">
+      <rect
+         x="0"
+         y="0"
+         width="485"
+         height="535"
+         id="rect2" />
+    </clipPath>
+  </defs>
+  <g
+     clip-path="url(#clip0)"
+     id="g59">
+    <rect
+       x="0"
+       y="0"
+       width="485"
+       height="535"
+       fill="#FFFFFF"
+       id="rect7" />
+    <rect
+       x="0.500053"
+       y="79.5001"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#A6A6A6"
+       id="rect9" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="24"
+       transform="translate(121.6 116)"
+       id="text13">
+         rte_eth_dev_configure
+         <tspan
+   font-size="24"
+   x="224.007"
+   y="0"
+   id="tspan11">()</tspan></text>
+    <rect
+       x="0.500053"
+       y="158.5"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect15" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="24"
+       transform="translate(140.273 195)"
+       id="text17">
+         rte_flow_configure()
+      </text>
+    <rect
+       x="0.500053"
+       y="236.5"
+       width="482"
+       height="60"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect19" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text21"
+       x="63.425903"
+       y="274">rte_flow_pattern_template_create()</text>
+    <rect
+       x="0.500053"
+       y="316.5"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect23" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text27"
+       x="69.379204"
+       y="353">rte_flow_actions_template_create()</text>
+    <rect
+       x="0.500053"
+       y="0.500053"
+       width="482"
+       height="60"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"

doc/guides/prog_guide/img/rte_flow_q_init.svg

Quoted 10 lines
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +10 -0
+       fill="#A6A6A6"
+       id="rect29" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       transform="translate(177.233,37)"
+       id="text33">rte_eal_init()</text>
+    <path
+       d="M2-1.09108e-05 2.00005 9.2445-1.99995 9.24452-2 1.09108e-

05ZM6.00004 7.24448 0.000104987 19.2445-5.99996 7.24455Z"

doc/guides/prog_guide/img/rte_flow_q_init.svg

Quoted 4 lines
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +4 -0
+       transform="matrix(-1 0 0 1 241 60)"
+       id="path35" />
+    <path
+       d="M2-1.08133e-05 2.00005 9.41805-1.99995 9.41807-2 1.08133e-

05ZM6.00004 7.41802 0.000104987 19.4181-5.99996 7.41809Z"

doc/guides/prog_guide/img/rte_flow_q_init.svg

Quoted 4 lines
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +4 -0
+       transform="matrix(-1 0 0 1 241 138)"
+       id="path37" />
+    <path
+       d="M2-1.09108e-05 2.00005 9.2445-1.99995 9.24452-2 1.09108e-

05ZM6.00004 7.24448 0.000104987 19.2445-5.99996 7.24455Z"

Quoted 11 lines
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +11 -0
+       transform="matrix(-1 0 0 1 241 217)"
+       id="path39" />
+    <rect
+       x="0.500053"
+       y="395.5"
+       width="482"
+       height="59"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"

doc/guides/prog_guide/img/rte_flow_q_init.svg

Quoted 10 lines
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +10 -0
+       id="rect41" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text47"
+       x="76.988998"
+       y="432">rte_flow_template_table_create()</text>
+    <path
+       d="M2-1.05859e-05 2.00005 9.83526-1.99995 9.83529-2 1.05859e-

05ZM6.00004 7.83524 0.000104987 19.8353-5.99996 7.83531Z"

doc/guides/prog_guide/img/rte_flow_q_init.svg

Quoted 4 lines
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +4 -0
+       transform="matrix(-1 0 0 1 241 296)"
+       id="path49" />
+    <path
+       d="M243 375 243 384.191 239 384.191 239 375ZM247 382.191 241

394.191 235 382.191Z"

Quoted 10 lines
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +10 -0
+       id="path51" />
+    <rect
+       x="0.500053"
+       y="473.5"
+       width="482"
+       height="60"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#A6A6A6"

doc/guides/prog_guide/img/rte_flow_q_init.svg

Quoted 10 lines
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +10 -0
+       id="rect53" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="24px"
+       id="text55"
+       x="149.30299"
+       y="511">rte_eth_dev_start()</text>
+    <path
+       d="M245 454 245 463.191 241 463.191 241 454ZM249 461.191 243

473.191 237 461.191Z"

Review

Quoted 4 lines
doc/guides/prog_guide/img/rte_flow_q_init.svg new file +3 -0
+       id="path57" />
+  </g>
+</svg>
(quoted diff) +0 -0

b/doc/guides/prog_guide/img/rte_flow_q_usage.svg

Quoted 9 lines

new file mode 100644
index 0000000000..a1f6c0a0a8

doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +4 -0
@@ -0,0 +1,351 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- SPDX-License-Identifier: BSD-3-Clause -->
+
+<!-- Copyright(c) 2022 NVIDIA Corporation & Affiliates -->

doc/guides/prog_guide/img/rte_flow_q_usage.svg line 14

Quoted 10 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +10 -0
+
+<svg
+   width="880"
+   height="610"
+   overflow="hidden"
+   version="1.1"
+   id="svg103"
+   sodipodi:docname="rte_flow_q_usage.svg"
+   inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
+

xmlns:inkscape="https://nam11.safelinks.protection.outlook.com/?url=http %3A%2F%2Fwww.inkscape.org%2Fnamespaces%2Finkscape&amp;data=04 %7C01%7Cakozyrev%40nvidia.com%7C17305c0b25ed4450b31008d9ed5bf333 %7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637801801473234111 %7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiL CJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=xpBAPvwrE5t1eHUc YHt%2FzLJ5seo%2F%2FomPwGvplYtAgv0%3D&amp;reserved=0"

doc/guides/prog_guide/img/rte_flow_q_usage.svg line 15

Quoted 1 line
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +1 -0
+

xmlns:sodipodi="https://nam11.safelinks.protection.outlook.com/?url=http %3A%2F%2Fsodipodi.sourceforge.net%2FDTD%2Fsodipodi- 0.dtd&amp;data=04%7C01%7Cakozyrev%40nvidia.com%7C17305c0b25ed445 0b31008d9ed5bf333%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C 637801801473234111%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwM DAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata =yFZ8tT7Zge2JgcuCKPGPe8MhGNEfsD2fdWpHdkO8qoc%3D&amp;reserved= 0"

doc/guides/prog_guide/img/rte_flow_q_usage.svg line 16

Quoted 1 line
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +1 -0
+

xmlns="https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F %2Fwww.w3.org%2F2000%2Fsvg&amp;data=04%7C01%7Cakozyrev%40nvidi a.com%7C17305c0b25ed4450b31008d9ed5bf333%7C43083d15727340c1b7db3 9efd9ccc17a%7C0%7C0%7C637801801473234111%7CUnknown%7CTWFpbGZs b3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn 0%3D%7C3000&amp;sdata=e2WMYQltdZPW%2FaZEm0RgJXXyaRFxJH%2B279 J1xTp9eg4%3D&amp;reserved=0"

doc/guides/prog_guide/img/rte_flow_q_usage.svg line 17

Quoted 1 line
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +1 -0
+

xmlns:svg="https://nam11.safelinks.protection.outlook.com/?url=http%3A% 2F%2Fwww.w3.org%2F2000%2Fsvg&amp;data=04%7C01%7Cakozyrev%40nvi dia.com%7C17305c0b25ed4450b31008d9ed5bf333%7C43083d15727340c1b7d b39efd9ccc17a%7C0%7C0%7C637801801473234111%7CUnknown%7CTWFpb GZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI 6Mn0%3D%7C3000&amp;sdata=e2WMYQltdZPW%2FaZEm0RgJXXyaRFxJH%2 B279J1xTp9eg4%3D&amp;reserved=0">

Quoted 102 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +102 -0
+  <sodipodi:namedview
+     id="namedview105"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageshadow="2"
+     inkscape:pageopacity="0.0"
+     inkscape:pagecheckerboard="0"
+     showgrid="false"
+     inkscape:zoom="1.3311475"
+     inkscape:cx="439.84606"
+     inkscape:cy="305.37562"
+     inkscape:window-width="2400"
+     inkscape:window-height="1271"
+     inkscape:window-x="2391"
+     inkscape:window-y="-9"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="g101" />
+  <defs
+     id="defs5">
+    <clipPath
+       id="clip0">
+      <rect
+         x="0"
+         y="0"
+         width="880"
+         height="610"
+         id="rect2" />
+    </clipPath>
+  </defs>
+  <g
+     clip-path="url(#clip0)"
+     id="g101">
+    <rect
+       x="0"
+       y="0"
+       width="880"
+       height="610"
+       fill="#FFFFFF"
+       id="rect7" />
+    <rect
+       x="333.5"
+       y="0.500053"
+       width="234"
+       height="45"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#A6A6A6"
+       id="rect9" />
+    <text
+       font-family="Consolas, Consolas_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="19px"
+       transform="translate(357.196,29)"
+       id="text11">rte_eth_rx_burst()</text>
+    <rect
+       x="333.5"
+       y="63.5001"
+       width="234"
+       height="45"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       id="rect13" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(394.666 91)"
+       id="text17">analyze <tspan
+   font-size="19"
+   x="60.9267"
+   y="0"
+   id="tspan15">packet </tspan></text>
+    <rect
+       x="572.5"
+       y="279.5"
+       width="234"
+       height="46"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect19" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(591.429 308)"
+       id="text21">rte_flow_q_flow_create()</text>
+    <path
+       d="M333.5 384 450.5 350.5 567.5 384 450.5 417.5Z"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       fill-rule="evenodd"
+       id="path23" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"

doc/guides/prog_guide/img/rte_flow_q_usage.svg

Quoted 10 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +10 -0
+       font-weight="400"
+       font-size="19"
+       transform="translate(430.069 378)"
+       id="text27">more <tspan
+   font-size="19"
+   x="-12.94"
+   y="23"
+   id="tspan25">packets?</tspan></text>
+    <path
+       d="M689.249 325.5 689.249 338.402 450.5 338.402 450.833 338.069

450.833 343.971 450.167 343.971 450.167 337.735 688.916 337.735 688.582 338.069 688.582 325.5ZM454.5 342.638 450.5 350.638 446.5 342.638Z"

doc/guides/prog_guide/img/rte_flow_q_usage.svg

Quoted 3 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +3 -0
+       id="path29" />
+    <path
+       d="M450.833 45.5 450.833 56.8197 450.167 56.8197 450.167

45.5001ZM454.5 55.4864 450.5 63.4864 446.5 55.4864Z"

doc/guides/prog_guide/img/rte_flow_q_usage.svg

Quoted 3 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +3 -0
+       id="path31" />
+    <path
+       d="M450.833 108.5 450.833 120.375 450.167 120.375 450.167

108.5ZM454.5 119.041 450.5 127.041 446.5 119.041Z"

doc/guides/prog_guide/img/rte_flow_q_usage.svg

Quoted 3 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +3 -0
+       id="path33" />
+    <path
+       d="M451.833 507.5 451.833 533.61 451.167 533.61 451.167

507.5ZM455.5 532.277 451.5 540.277 447.5 532.277Z"

doc/guides/prog_guide/img/rte_flow_q_usage.svg line 141

Quoted 3 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +3 -0
+       id="path35" />
+    <path
+       d="M0 0.333333-23.9993 0.333333-23.666 0-23.666 141.649-23.9993

141.316 562.966 141.316 562.633 141.649 562.633 124.315 563.299 124.315 563.299 141.983-24.3327 141.983-24.3327-0.333333 0-0.333333ZM558.966 125.649 562.966 117.649 566.966 125.649Z"

Quoted 12 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +12 -0
+       transform="matrix(-6.12323e-17 -1 -1 6.12323e-17 451.149 585.466)"
+       id="path37" />
+    <path
+       d="M333.5 160.5 450.5 126.5 567.5 160.5 450.5 194.5Z"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       fill-rule="evenodd"
+       id="path39" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"

doc/guides/prog_guide/img/rte_flow_q_usage.svg

Quoted 10 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +10 -0
+       font-weight="400"
+       font-size="19"
+       transform="translate(417.576 155)"
+       id="text43">add new <tspan
+   font-size="19"
+   x="13.2867"
+   y="23"
+   id="tspan41">rule?</tspan></text>
+    <path
+       d="M567.5 160.167 689.267 160.167 689.267 273.228 688.6 273.228

688.6 160.5 688.933 160.833 567.5 160.833ZM692.933 271.894 688.933 279.894 684.933 271.894Z"

Quoted 25 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +25 -0
+       id="path45" />
+    <rect
+       x="602.5"
+       y="127.5"
+       width="46"
+       height="30"
+       stroke="#000000"
+       stroke-width="0.666667"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       id="rect47" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(611.34 148)"
+       id="text49">yes</text>
+    <rect
+       x="254.5"
+       y="126.5"
+       width="46"
+       height="31"
+       stroke="#000000"
+       stroke-width="0.666667"
+       stroke-miterlimit="8"

doc/guides/prog_guide/img/rte_flow_q_usage.svg

Quoted 10 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +10 -0
+       fill="#D9D9D9"
+       id="rect51" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(267.182 147)"
+       id="text53">no</text>
+    <path
+       d="M0-0.333333 251.563-0.333333 251.563 298.328 8.00002 298.328

8.00002 297.662 251.229 297.662 250.896 297.995 250.896 0 251.229 0.333333 0 0.333333ZM9.33333 301.995 1.33333 297.995 9.33333 293.995Z"

Quoted 12 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +12 -0
+       transform="matrix(1 0 0 -1 567.5 383.495)"
+       id="path55" />
+    <path
+       d="M86.5001 213.5 203.5 180.5 320.5 213.5 203.5 246.5Z"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       fill-rule="evenodd"
+       id="path57" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"

doc/guides/prog_guide/img/rte_flow_q_usage.svg

Quoted 10 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +10 -0
+       font-weight="400"
+       font-size="19"
+       transform="translate(159.155 208)"
+       id="text61">destroy the <tspan
+   font-size="19"
+   x="24.0333"
+   y="23"
+   id="tspan59">rule?</tspan></text>
+    <path
+       d="M0-0.333333 131.029-0.333333 131.029 12.9778 130.363 12.9778

130.363 0 130.696 0.333333 0 0.333333ZM134.696 11.6445 130.696 19.6445 126.696 11.6445Z"

Quoted 10 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +10 -0
+       transform="matrix(-1 1.22465e-16 1.22465e-16 1 334.196 160.5)"
+       id="path63" />
+    <rect
+       x="81.5001"
+       y="280.5"
+       width="234"
+       height="45"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"

doc/guides/prog_guide/img/rte_flow_q_usage.svg

Quoted 10 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +10 -0
+       fill="#FFFFFF"
+       id="rect65" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(96.2282 308)"
+       id="text67">rte_flow_q_flow_destroy()</text>
+    <path
+       d="M0 0.333333-24.0001 0.333333-23.6667 0-23.6667 49.9498-24.0001

49.6165 121.748 49.6165 121.748 59.958 121.082 59.958 121.082 49.9498 121.415 50.2832-24.3334 50.2832-24.3334-0.333333 0-0.333333ZM125.415 58.6247 121.415 66.6247 117.415 58.6247Z"

doc/guides/prog_guide/img/rte_flow_q_usage.svg

Quoted 4 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +4 -0
+       transform="matrix(-1 0 0 1 319.915 213.5)"
+       id="path69" />
+    <path
+       d="M86.5001 213.833 62.5002 213.833 62.8335 213.5 62.8335 383.95

62.5002 383.617 327.511 383.617 327.511 384.283 62.1668 384.283 62.1668 213.167 86.5001 213.167ZM326.178 379.95 334.178 383.95 326.178 387.95Z"

doc/guides/prog_guide/img/rte_flow_q_usage.svg

Quoted 3 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +3 -0
+       id="path71" />
+    <path
+       d="M0-0.333333 12.8273-0.333333 12.8273 252.111 12.494 251.778

18.321 251.778 18.321 252.445 12.1607 252.445 12.1607 0 12.494 0.333333 0 0.333333ZM16.9877 248.111 24.9877 252.111 16.9877 256.111Z"

Quoted 27 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +27 -0
+       transform="matrix(1.83697e-16 1 1 -1.83697e-16 198.5 325.5)"
+       id="path73" />
+    <rect
+       x="334.5"
+       y="540.5"
+       width="234"
+       height="45"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"
+       fill="#FFFFFF"
+       id="rect75" />
+    <text
+       font-family="Calibri, Calibri_MSFontService, sans-serif"
+       font-weight="400"
+       font-size="19px"
+       id="text77"
+       x="385.08301"
+       y="569">rte_flow_q_pull()</text>
+    <rect
+       x="334.5"
+       y="462.5"
+       width="234"
+       height="45"
+       stroke="#000000"
+       stroke-width="1.33333"
+       stroke-miterlimit="8"

doc/guides/prog_guide/img/rte_flow_q_usage.svg

Quoted 10 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +10 -0
+       fill="#FFFFFF"
+       id="rect79" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(379.19 491)"
+       id="text81">rte_flow_q_push()</text>
+    <path
+       d="M450.833 417.495 451.402 455.999 450.735 456.008 450.167

417.505ZM455.048 454.611 451.167 462.669 447.049 454.729Z"

Review

Quoted 68 lines
doc/guides/prog_guide/img/rte_flow_q_usage.svg new file +67 -0
+       id="path83" />
+    <rect
+       x="0.500053"
+       y="287.5"
+       width="46"
+       height="30"
+       stroke="#000000"
+       stroke-width="0.666667"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       id="rect85" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(12.8617 308)"
+       id="text87">no</text>
+    <rect
+       x="357.5"
+       y="223.5"
+       width="47"
+       height="31"
+       stroke="#000000"
+       stroke-width="0.666667"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       id="rect89" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(367.001 244)"
+       id="text91">yes</text>
+    <rect
+       x="469.5"
+       y="421.5"
+       width="46"
+       height="30"
+       stroke="#000000"
+       stroke-width="0.666667"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       id="rect93" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(481.872 442)"
+       id="text95">no</text>
+    <rect
+       x="832.5"
+       y="223.5"
+       width="46"
+       height="31"
+       stroke="#000000"
+       stroke-width="0.666667"
+       stroke-miterlimit="8"
+       fill="#D9D9D9"
+       id="rect97" />
+    <text
+       font-family="Calibri,Calibri_MSFontService,sans-serif"
+       font-weight="400"
+       font-size="19"
+       transform="translate(841.777 244)"
+       id="text99">yes</text>
+  </g>
+</svg>
(quoted diff) +0 -0

b/doc/guides/prog_guide/rte_flow.rst

doc/guides/prog_guide/rte_flow.rst Expected number of counters or meters in an

Quoted 4 lines

index 5391648833..5d47f3bd21 100644

doc/guides/prog_guide/rte_flow.rst +0 -0
@@ -3607,12 +3607,16 @@ Expected number of counters or meters in an

application, for example,

Quoted 18 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
  allow PMD to prepare and optimize NIC memory layout in advance.
  ``rte_flow_configure()`` must be called before any flow rule is created,
  but after an Ethernet device is configured.
+It also creates flow queues for asynchronous flow rules operations via
+queue-based API, see `Asynchronous operations`_ section.
 
  .. code-block:: c
 
     int
     rte_flow_configure(uint16_t port_id,
                       const struct rte_flow_port_attr *port_attr,
+                     uint16_t nb_queue,
+                     const struct rte_flow_queue_attr *queue_attr[],
                       struct rte_flow_error *error);
 
  Information about resources that can benefit from pre-allocation can be
@@ -3737,7 +3741,7 @@ and pattern and actions templates are created.
 
Quoted 7 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created.

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +1 -1
  .. code-block:: c
 
-	rte_flow_configure(port, *port_attr, *error);
+	rte_flow_configure(port, *port_attr, nb_queue, *queue_attr,

*error);

* before queue_attr looks strange

Yes, it is a typo.

Quoted 17 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3746

Quoted 3 lines
doc/guides/prog_guide/rte_flow.rst +0 -0
  	struct rte_flow_pattern_template *pattern_templates[0] =
  		rte_flow_pattern_template_create(port, &itr, &pattern,

&error);

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3760

Quoted 8 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
@@ -3750,6 +3754,167 @@ and pattern and actions templates are created.
  				*actions_templates, nb_actions_templates,
  				*error);
 
+Asynchronous operations
+-----------------------
+
+Flow rules management can be done via special lockless flow

management queues.

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created.

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+- Queue operations are asynchronous and not thread-safe.
+
+- Operations can thus be invoked by the app's datapath,
+  packet processing can continue while queue operations are processed by
Quoted 6 lines

NIC.

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3766

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+
+- The queue number is configured at initialization stage.

I read "the queue number" as some number for a specific queue. May be "Number of queues is configured..."

No problem.

Quoted 9 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3771

Quoted 5 lines
doc/guides/prog_guide/rte_flow.rst +5 -0
+
+- Available operation types: rule creation, rule destruction,
+  indirect rule creation, indirect rule destruction, indirect rule update.
+
+- Operations may be reordered within a queue.

Do we want to have barriers?
E.g. create rule, destroy the same rule -> reoder -> destroy fails, rule lives forever.

API design is crafter with the throughput as the main goal in mind. We allow user to enforce any ordering outside these functions. Another point that not all PMDs/NIC will have this out-of-order execution.

Quoted 7 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3775

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+- Operations can be postponed and pushed to NIC in batches.
+
+- Results pulling must be done on time to avoid queue overflows.

polling? (as libc poll() which checks status of file descriptors) it is not pulling the door to open it :)

poll waits for some event on a file descriptor as it title says. And then user has to invoke read() to actually get any info from the fd. The point of our function is to return the result immediately, thus pulling. We had many names appearing in the thread for these functions. As we know, naming variables is the second hardest thing in programming. I wanted this pull for results pulling be a counterpart for the push for pushing the operations to a NIC. Another idea is pop/push pair, but they are more like for operations only, not for results.
Having said that I'm at the point of accepting any name here.

Quoted 386 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created.

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+- User data is returned as part of the result to identify an operation.
+
+- Flow handle is valid once the creation operation is enqueued and must

be

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3780

Quoted 1 line
doc/guides/prog_guide/rte_flow.rst +1 -0
+  destroyed even if the operation is not successful and the rule is not

inserted.

Quoted 16 lines
doc/guides/prog_guide/rte_flow.rst +16 -0
+
+The asynchronous flow rule insertion logic can be broken into two phases.
+
+1. Initialization stage as shown here:
+
+.. _figure_rte_flow_q_init:
+
+.. figure:: img/rte_flow_q_init.*
+
+2. Main loop as presented on a datapath application example:
+
+.. _figure_rte_flow_q_usage:
+
+.. figure:: img/rte_flow_q_usage.*
+
+Enqueue creation operation

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created.

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Enqueueing a flow rule creation operation is similar to simple creation.
+
+.. code-block:: c
+
+	struct rte_flow *
+	rte_flow_q_flow_create(uint16_t port_id,
+				uint32_t queue_id,
+				const struct rte_flow_q_ops_attr

*q_ops_attr,

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3807

Quoted 1 line
doc/guides/prog_guide/rte_flow.rst +1 -0
+				struct rte_flow_template_table

*template_table,

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created.

Quoted 8 lines
doc/guides/prog_guide/rte_flow.rst +8 -0
+				const struct rte_flow_item pattern[],
+				uint8_t pattern_template_index,
+				const struct rte_flow_action actions[],
+				uint8_t actions_template_index,
+				struct rte_flow_error *error);
+
+A valid handle in case of success is returned. It must be destroyed later
+by calling ``rte_flow_q_flow_destroy()`` even if the rule is rejected by

HW.

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created.

Quoted 5 lines
doc/guides/prog_guide/rte_flow.rst +5 -0
+
+Enqueue destruction operation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Enqueueing a flow rule destruction operation is similar to simple

destruction.

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created.

Quoted 7 lines
doc/guides/prog_guide/rte_flow.rst +7 -0
+
+.. code-block:: c
+
+	int
+	rte_flow_q_flow_destroy(uint16_t port_id,
+				uint32_t queue_id,
+				const struct rte_flow_q_ops_attr

*q_ops_attr,

Quoted 7 lines
doc/guides/prog_guide/rte_flow.rst +7 -0
+				struct rte_flow *flow,
+				struct rte_flow_error *error);
+
+Push enqueued operations
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Pushing all internally stored rules from a queue to the NIC.

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created.

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+
+.. code-block:: c
+
+	int
+	rte_flow_q_push(uint16_t port_id,
+			uint32_t queue_id,
+			struct rte_flow_error *error);
+
+There is the postpone attribute in the queue operation attributes.
+When it is set, multiple operations can be bulked together and not sent to

HW

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3845

Quoted 1 line
doc/guides/prog_guide/rte_flow.rst +1 -0
+right away to save SW/HW interactions and prioritize throughput over

latency.

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created.

Quoted 9 lines
doc/guides/prog_guide/rte_flow.rst +9 -0
+The application must invoke this function to actually push all outstanding
+operations to HW in this case.
+
+Pull enqueued operations
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Pulling asynchronous operations results.
+
+The application must invoke this function in order to complete

asynchronous

Quoted 18 lines
doc/guides/prog_guide/rte_flow.rst +18 -0
+flow rule operations and to receive flow rule operations statuses.
+
+.. code-block:: c
+
+	int
+	rte_flow_q_pull(uint16_t port_id,
+			uint32_t queue_id,
+			struct rte_flow_q_op_res res[],
+			uint16_t n_res,
+			struct rte_flow_error *error);
+
+Multiple outstanding operation results can be pulled simultaneously.
+User data may be provided during a flow creation/destruction in order
+to distinguish between multiple operations. User data is returned as part
+of the result to provide a method to detect which operation is completed.
+
+Enqueue indirect action creation operation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created.

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+
+Asynchronous version of indirect action creation API.
+
+.. code-block:: c
+
+	struct rte_flow_action_handle *
+	rte_flow_q_action_handle_create(uint16_t port_id,
+			uint32_t queue_id,
+			const struct rte_flow_q_ops_attr *q_ops_attr,
+			const struct rte_flow_indir_action_conf

*indir_action_conf,

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created.

Quoted 5 lines
doc/guides/prog_guide/rte_flow.rst +5 -0
+			const struct rte_flow_action *action,
+			struct rte_flow_error *error);
+
+A valid handle in case of success is returned. It must be destroyed later by
+calling ``rte_flow_q_action_handle_destroy()`` even if the rule is

rejected.

Review

Quoted 34 lines
doc/guides/prog_guide/rte_flow.rst +30 -0
+
+Enqueue indirect action destruction operation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Asynchronous version of indirect action destruction API.
+
+.. code-block:: c
+
+	int
+	rte_flow_q_action_handle_destroy(uint16_t port_id,
+			uint32_t queue_id,
+			const struct rte_flow_q_ops_attr *q_ops_attr,
+			struct rte_flow_action_handle *action_handle,
+			struct rte_flow_error *error);
+
+Enqueue indirect action update operation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Asynchronous version of indirect action update API.
+
+.. code-block:: c
+
+	int
+	rte_flow_q_action_handle_update(uint16_t port_id,
+			uint32_t queue_id,
+			const struct rte_flow_q_ops_attr *q_ops_attr,
+			struct rte_flow_action_handle *action_handle,
+			const void *update,
+			struct rte_flow_error *error);
+
  .. _flow_isolated_mode:
 
  Flow isolated mode
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_22_03.rst

doc/guides/rel_notes/release_22_03.rst New Features · line 83

Quoted 5 lines

index 6656b35295..87cea8a966 100644

doc/guides/rel_notes/release_22_03.rst +0 -0
@@ -83,6 +83,14 @@ New Features
      ``rte_flow_template_table_destroy``,

``rte_flow_pattern_template_destroy``

doc/guides/rel_notes/release_22_03.rst New Features

Quoted 3 lines
doc/guides/rel_notes/release_22_03.rst +1 -0
      and ``rte_flow_actions_template_destroy``.
 
+  * ethdev: Added ``rte_flow_q_flow_create`` and

``rte_flow_q_flow_destroy``

doc/guides/rel_notes/release_22_03.rst New Features · line 87

Quoted 1 line
doc/guides/rel_notes/release_22_03.rst +1 -0
+    API to enqueue flow creaion/destruction operations asynchronously as

well

doc/guides/rel_notes/release_22_03.rst New Features

Quoted 4 lines
doc/guides/rel_notes/release_22_03.rst +4 -0
+    as ``rte_flow_q_pull`` to poll and retrieve results of these operations
+    and ``rte_flow_q_push`` to push all the in-flight operations to the NIC.
+    Introduced asynchronous API for indirect actions management as well:
+    ``rte_flow_q_action_handle_create``,

``rte_flow_q_action_handle_destroy``

lib/ethdev/rte_flow.c rte_flow_template_table_destroy(uint16_t

Quoted 29 lines
doc/guides/rel_notes/release_22_03.rst +2 -0
+    and ``rte_flow_q_action_handle_update``.
+
  * **Updated AF_XDP PMD**
 
    * Added support for libxdp >=v1.2.2.
lib/ethdev/rte_flow.c +4 -1
index b53f8c9b89..aca5bac2da 100644
@@ -1415,6 +1415,8 @@ rte_flow_info_get(uint16_t port_id,
  int
  rte_flow_configure(uint16_t port_id,
  		   const struct rte_flow_port_attr *port_attr,
+		   uint16_t nb_queue,
+		   const struct rte_flow_queue_attr *queue_attr[],
  		   struct rte_flow_error *error)
  {
  	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
@@ -1424,7 +1426,8 @@ rte_flow_configure(uint16_t port_id,
  		return -rte_errno;
  	if (likely(!!ops->configure)) {
  		return flow_err(port_id,
-				ops->configure(dev, port_attr, error),
+				ops->configure(dev, port_attr,
+					       nb_queue, queue_attr, error),
  				error);
  	}
  	return rte_flow_error_set(error, ENOTSUP,
@@ -1578,3 +1581,173 @@ rte_flow_template_table_destroy(uint16_t

port_id,

Quoted 67 lines
lib/ethdev/rte_flow.c +64 -0
  				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
  				  NULL, rte_strerror(ENOTSUP));
  }
+
+struct rte_flow *
+rte_flow_q_flow_create(uint16_t port_id,
+		       uint32_t queue_id,
+		       const struct rte_flow_q_ops_attr *q_ops_attr,
+		       struct rte_flow_template_table *template_table,
+		       const struct rte_flow_item pattern[],
+		       uint8_t pattern_template_index,
+		       const struct rte_flow_action actions[],
+		       uint8_t actions_template_index,
+		       struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	struct rte_flow *flow;
+
+	if (unlikely(!ops))
+		return NULL;
+	if (likely(!!ops->q_flow_create)) {
+		flow = ops->q_flow_create(dev, queue_id,
+					  q_ops_attr, template_table,
+					  pattern, pattern_template_index,
+					  actions, actions_template_index,
+					  error);
+		if (flow == NULL)
+			flow_err(port_id, -rte_errno, error);
+		return flow;
+	}
+	rte_flow_error_set(error, ENOTSUP,
+			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+			   NULL, rte_strerror(ENOTSUP));
+	return NULL;
+}
+
+int
+rte_flow_q_flow_destroy(uint16_t port_id,
+			uint32_t queue_id,
+			const struct rte_flow_q_ops_attr *q_ops_attr,
+			struct rte_flow *flow,
+			struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->q_flow_destroy)) {
+		return flow_err(port_id,
+				ops->q_flow_destroy(dev, queue_id,
+						    q_ops_attr, flow, error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+struct rte_flow_action_handle *
+rte_flow_q_action_handle_create(uint16_t port_id,
+		uint32_t queue_id,
+		const struct rte_flow_q_ops_attr *q_ops_attr,
+		const struct rte_flow_indir_action_conf *indir_action_conf,
+		const struct rte_flow_action *action,
+		struct rte_flow_error *error)

lib/ethdev/rte_flow.c rte_flow_template_table_destroy(uint16_t port_id, · line 1683

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	struct rte_flow_action_handle *handle;
+
+	if (unlikely(!ops))
+		return NULL;
+	if (unlikely(!ops->q_action_handle_create)) {
+		rte_flow_error_set(error, ENOSYS,
+				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,

NULL,

Quoted 16 lines
lib/ethdev/rte_flow.c +16 -0
+				   rte_strerror(ENOSYS));
+		return NULL;
+	}
+	handle = ops->q_action_handle_create(dev, queue_id, q_ops_attr,
+					     indir_action_conf, action, error);
+	if (handle == NULL)
+		flow_err(port_id, -rte_errno, error);
+	return handle;
+}
+
+int
+rte_flow_q_action_handle_destroy(uint16_t port_id,
+		uint32_t queue_id,
+		const struct rte_flow_q_ops_attr *q_ops_attr,
+		struct rte_flow_action_handle *action_handle,
+		struct rte_flow_error *error)

lib/ethdev/rte_flow.c rte_flow_template_table_destroy(uint16_t port_id, · line 1689

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (unlikely(!ops->q_action_handle_destroy))
+		return rte_flow_error_set(error, ENOSYS,
+

RTE_FLOW_ERROR_TYPE_UNSPECIFIED,

Quoted 13 lines
lib/ethdev/rte_flow.c +13 -0
+					  NULL, rte_strerror(ENOSYS));
+	ret = ops->q_action_handle_destroy(dev, queue_id, q_ops_attr,
+					   action_handle, error);
+	return flow_err(port_id, ret, error);
+}
+
+int
+rte_flow_q_action_handle_update(uint16_t port_id,
+		uint32_t queue_id,
+		const struct rte_flow_q_ops_attr *q_ops_attr,
+		struct rte_flow_action_handle *action_handle,
+		const void *update,
+		struct rte_flow_error *error)

lib/ethdev/rte_flow.c rte_flow_template_table_destroy(uint16_t port_id, · line 1712

Quoted 10 lines
lib/ethdev/rte_flow.c +10 -0
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (unlikely(!ops->q_action_handle_update))
+		return rte_flow_error_set(error, ENOSYS,
+

RTE_FLOW_ERROR_TYPE_UNSPECIFIED,

Quoted 51 lines
lib/ethdev/rte_flow.c +47 -0
+					  NULL, rte_strerror(ENOSYS));
+	ret = ops->q_action_handle_update(dev, queue_id, q_ops_attr,
+					  action_handle, update, error);
+	return flow_err(port_id, ret, error);
+}
+
+int
+rte_flow_q_push(uint16_t port_id,
+		uint32_t queue_id,
+		struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->q_push)) {
+		return flow_err(port_id,
+				ops->q_push(dev, queue_id, error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_q_pull(uint16_t port_id,
+		uint32_t queue_id,
+		struct rte_flow_q_op_res res[],
+		uint16_t n_res,
+		struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->q_pull)) {
+		ret = ops->q_pull(dev, queue_id, res, n_res, error);
+		return ret ? ret : flow_err(port_id, ret, error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
lib/ethdev/rte_flow.h +0 -0
index e87db5a540..b0d4f33bfd 100644
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_flex_item_release(uint16_t port_id, · line 4866

Quoted 6 lines
lib/ethdev/rte_flow.h +2 -0
@@ -4862,6 +4862,10 @@ rte_flow_flex_item_release(uint16_t port_id,
   *
   */
  struct rte_flow_port_info {
+	/**
+	 * Number of queues for asynchronous operations.

Is it a maximum number of queues?

Yes, it is a maximum supported number of flow queues. Will rename.

Quoted 10 lines
Quoted 10 lines
lib/ethdev/rte_flow.h +2 -0
+	 */
+	uint32_t nb_queues;
  	/**
  	 * Number of pre-configurable counter actions.
  	 * @see RTE_FLOW_ACTION_TYPE_COUNT
@@ -4879,6 +4883,17 @@ struct rte_flow_port_info {
  	uint32_t nb_meters;
  };
 
Quoted 12 lines

lib/ethdev/rte_flow.h struct rte_flow_port_info { · line 4894

Quoted 9 lines
lib/ethdev/rte_flow.h +9 -0
+/**
+ * Flow engine queue configuration.
+ */
+__extension__
+struct rte_flow_queue_attr {
+	/**
+	 * Number of flow rule operations a queue can hold.
+	 */
+	uint32_t size;

Whar are the min/max sizes? 0 as the default size, if yes, do we need an API to find actual size?

Good catch, will extend rte_flow_info_get() to obtain this number.

Quoted 32 lines

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t

Quoted 28 lines
lib/ethdev/rte_flow.h +9 -0
+};
+
  /**
   * @warning
   * @b EXPERIMENTAL: this API may change without prior notice.
@@ -4948,6 +4963,11 @@ struct rte_flow_port_attr {
   *   Port identifier of Ethernet device.
   * @param[in] port_attr
   *   Port configuration attributes.
+ * @param[in] nb_queue
+ *   Number of flow queues to be configured.
+ * @param[in] queue_attr
+ *   Array that holds attributes for each flow queue.
+ *   Number of elements is set in @p port_attr.nb_queues.
   * @param[out] error
   *   Perform verbose error reporting if not NULL.
   *   PMDs initialize this structure in case of error only.
@@ -4959,6 +4979,8 @@ __rte_experimental
  int
  rte_flow_configure(uint16_t port_id,
  		   const struct rte_flow_port_attr *port_attr,
+		   uint16_t nb_queue,
+		   const struct rte_flow_queue_attr *queue_attr[],
  		   struct rte_flow_error *error);
 
  /**
@@ -5221,6 +5243,318 @@ rte_flow_template_table_destroy(uint16_t

port_id,

Quoted 3 lines
lib/ethdev/rte_flow.h +0 -0
  		struct rte_flow_template_table *template_table,
  		struct rte_flow_error *error);
 
Quoted 15 lines

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5256

Quoted 11 lines
lib/ethdev/rte_flow.h +11 -0
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Queue operation attributes.
+ */
+struct rte_flow_q_ops_attr {
+	/**
+	 * The user data that will be returned on the completion events.
+	 */
+	void *user_data;

IMHO it must not be hiddne in attrs. It is a key information which is used to understand the opration result. It should be passed separately.

Maybe, on the other hand it is optional and may not be needed by an application.

Quoted 9 lines

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t · line 5258

Quoted 2 lines
lib/ethdev/rte_flow.h +2 -0
+	 /**
+	  * When set, the requested action will not be sent to the HW

immediately.

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t · line 5259

Quoted 1 line
lib/ethdev/rte_flow.h +1 -0
+	  * The application must call the rte_flow_queue_push to actually

send it.

Will the next operation without the attribute set implicitly push it? Is it mandatory for the driver to respect it? Or is it just a possible optimization hint?

Yes, it will be pushed with all the operations in a queue once the postpone is cleared. It is not mandatory to respect this bit, PMD can use other optimization technics.

Quoted 20 lines
Quoted 9 lines
lib/ethdev/rte_flow.h +8 -0
+	  */
+	uint32_t postpone:1;
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5277

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * Enqueue rule creation operation.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param queue_id
+ *   Flow queue used to insert the rule.
+ * @param[in] q_ops_attr
+ *   Rule creation operation attributes.
+ * @param[in] template_table
+ *   Template table to select templates from.
Quoted 8 lines

IMHO it should be done optional. I.e. NULL allows.
If NULL, indecies are ignored and pattern+actions are full specificiation as in rte_flow_create(). The only missing bit is attributes.
Basically I'm sure that hardwiring queue-based flow rule control to template is the right solution. It should be possible without templates. May be it should be a separate API to be added later if/when required.

That ruins the whole point of templates - to use pre-existing hardware paths. But I agree less performant API may be added if need arises.

Quoted 19 lines
Quoted 8 lines
lib/ethdev/rte_flow.h +8 -0
+ * @param[in] pattern
+ *   List of pattern items to be used.
+ *   The list order should match the order in the pattern template.
+ *   The spec is the only relevant member of the item that is being used.
+ * @param[in] pattern_template_index
+ *   Pattern template index in the table.
+ * @param[in] actions
+ *   List of actions to be used.

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5295

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ *   The list order should match the order in the actions template.
+ * @param[in] actions_template_index
+ *   Actions template index in the table.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   Handle on success, NULL otherwise and rte_errno is set.
+ *   The rule handle doesn't mean that the rule was offloaded.
Quoted 3 lines

"was offloaded" sounds ambiguous. API says nothing about any kind of offloading before. "has been populated" or "has been created" (since API says "create").

Ok.

Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5300

Quoted 5 lines
lib/ethdev/rte_flow.h +5 -0
+ *   Only completion result indicates that the rule was offloaded.
+ */
+__rte_experimental
+struct rte_flow *
+rte_flow_q_flow_create(uint16_t port_id,

flow_q_flow does not sound like a good nameing, consider:
rte_flow_q_rule_create() is <subsystem>_<subtype>_<object>_<action>

More like:
<subsystem>_<subtype>_<object>_<action>
<rte>_<flow>_<rule_create_operation>_<queue>
Which is pretty lengthy name as for me.

Quoted 61 lines
Quoted 61 lines
lib/ethdev/rte_flow.h +61 -0
+		       uint32_t queue_id,
+		       const struct rte_flow_q_ops_attr *q_ops_attr,
+		       struct rte_flow_template_table *template_table,
+		       const struct rte_flow_item pattern[],
+		       uint8_t pattern_template_index,
+		       const struct rte_flow_action actions[],
+		       uint8_t actions_template_index,
+		       struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue rule destruction operation.
+ *
+ * This function enqueues a destruction operation on the queue.
+ * Application should assume that after calling this function
+ * the rule handle is not valid anymore.
+ * Completion indicates the full removal of the rule from the HW.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param queue_id
+ *   Flow queue which is used to destroy the rule.
+ *   This must match the queue on which the rule was created.
+ * @param[in] q_ops_attr
+ *   Rule destroy operation attributes.
+ * @param[in] flow
+ *   Flow handle to be destroyed.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_q_flow_destroy(uint16_t port_id,
+			uint32_t queue_id,
+			const struct rte_flow_q_ops_attr *q_ops_attr,
+			struct rte_flow *flow,
+			struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue indirect action creation operation.
+ * @see rte_flow_action_handle_create
+ *
+ * @param[in] port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] queue_id
+ *   Flow queue which is used to create the rule.
+ * @param[in] q_ops_attr
+ *   Queue operation attributes.
+ * @param[in] indir_action_conf
+ *   Action configuration for the indirect action object creation.
+ * @param[in] action
+ *   Specific configuration of the indirect action object.
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5367

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   - (0) if success.

Hold on. Pointer is returned by the function.

That is an error.

Quoted 9 lines

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5373

Quoted 7 lines
lib/ethdev/rte_flow.h +6 -0
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - (-ENOSYS) if underlying device does not support this functionality.
+ *   - (-EIO) if underlying device is removed.
+ *   - (-ENOENT) if action pointed by *action* handle was not found.
+ *   - (-EBUSY) if action pointed by *action* handle still used by some rules
+ *   rte_errno is also set.

Which error code should be used if too many ops are enqueued (overflow)?

EAGAIN

Quoted 14 lines

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5381

Quoted 9 lines
lib/ethdev/rte_flow.h +8 -0
+ */
+__rte_experimental
+struct rte_flow_action_handle *
+rte_flow_q_action_handle_create(uint16_t port_id,
+		uint32_t queue_id,
+		const struct rte_flow_q_ops_attr *q_ops_attr,
+		const struct rte_flow_indir_action_conf *indir_action_conf,
+		const struct rte_flow_action *action,

I don't understand why it differs so much from rule creation. Why is action template not used?
IMHO indirect actions should be dropped from the patch and added separately since it is a separate feature.

I agree, they deserve a sperate patch since they are rather resource creations. But, I'm afraid it is too late for RC1.

Quoted 167 lines
Quoted 46 lines
lib/ethdev/rte_flow.h +46 -0
+		struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue indirect action destruction operation.
+ * The destroy queue must be the same
+ * as the queue on which the action was created.
+ *
+ * @param[in] port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] queue_id
+ *   Flow queue which is used to destroy the rule.
+ * @param[in] q_ops_attr
+ *   Queue operation attributes.
+ * @param[in] action_handle
+ *   Handle for the indirect action object to be destroyed.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   - (0) if success.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - (-ENOSYS) if underlying device does not support this functionality.
+ *   - (-EIO) if underlying device is removed.
+ *   - (-ENOENT) if action pointed by *action* handle was not found.
+ *   - (-EBUSY) if action pointed by *action* handle still used by some rules
+ *   rte_errno is also set.
+ */
+__rte_experimental
+int
+rte_flow_q_action_handle_destroy(uint16_t port_id,
+		uint32_t queue_id,
+		const struct rte_flow_q_ops_attr *q_ops_attr,
+		struct rte_flow_action_handle *action_handle,
+		struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue indirect action update operation.
+ * @see rte_flow_action_handle_create
+ *

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id,

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+ * @param[in] port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] queue_id
+ *   Flow queue which is used to update the rule.
+ * @param[in] q_ops_attr
+ *   Queue operation attributes.
+ * @param[in] action_handle
+ *   Handle for the indirect action object to be updated.
+ * @param[in] update
+ *   Update profile specification used to modify the action pointed by

handle.

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t · line 5438

Quoted 1 line
lib/ethdev/rte_flow.h +1 -0
+ *   *update* could be with the same type of the immediate action

corresponding

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t · line 5439

Quoted 1 line
lib/ethdev/rte_flow.h +1 -0
+ *   to the *handle* argument when creating, or a wrapper structure

includes

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t · line 5440

Quoted 1 line
lib/ethdev/rte_flow.h +1 -0
+ *   action configuration to be updated and bit fields to indicate the

member

Quoted 19 lines
lib/ethdev/rte_flow.h +19 -0
+ *   of fields inside the action to update.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   - (0) if success.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - (-ENOSYS) if underlying device does not support this functionality.
+ *   - (-EIO) if underlying device is removed.
+ *   - (-ENOENT) if action pointed by *action* handle was not found.
+ *   - (-EBUSY) if action pointed by *action* handle still used by some rules
+ *   rte_errno is also set.
+ */
+__rte_experimental
+int
+rte_flow_q_action_handle_update(uint16_t port_id,
+		uint32_t queue_id,
+		const struct rte_flow_q_ops_attr *q_ops_attr,

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id,

Quoted 10 lines
lib/ethdev/rte_flow.h +10 -0
+		struct rte_flow_action_handle *action_handle,
+		const void *update,
+		struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Push all internally stored rules to the HW.
+ * Postponed rules are rules that were inserted with the postpone flag

set.

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t · line 5470

Quoted 1 line
lib/ethdev/rte_flow.h +1 -0
+ * Can be used to notify the HW about batch of rules prepared by the SW

to

Quoted 72 lines
lib/ethdev/rte_flow.h +72 -0
+ * reduce the number of communications between the HW and SW.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param queue_id
+ *   Flow queue to be pushed.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *    0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_q_push(uint16_t port_id,
+		uint32_t queue_id,
+		struct rte_flow_error *error);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Queue operation status.
+ */
+enum rte_flow_q_op_status {
+	/**
+	 * The operation was completed successfully.
+	 */
+	RTE_FLOW_Q_OP_SUCCESS,
+	/**
+	 * The operation was not completed successfully.
+	 */
+	RTE_FLOW_Q_OP_ERROR,
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Queue operation results.
+ */
+__extension__
+struct rte_flow_q_op_res {
+	/**
+	 * Returns the status of the operation that this completion signals.
+	 */
+	enum rte_flow_q_op_status status;
+	/**
+	 * The user data that will be returned on the completion events.
+	 */
+	void *user_data;
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Pull a rte flow operation.
+ * The application must invoke this function in order to complete
+ * the flow rule offloading and to retrieve the flow rule operation status.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param queue_id
+ *   Flow queue which is used to pull the operation.
+ * @param[out] res
+ *   Array of results that will be set.
+ * @param[in] n_res
+ *   Maximum number of results that can be returned.
+ *   This value is equal to the size of the res array.
+ * @param[out] error
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5548

Quoted 6 lines
lib/ethdev/rte_flow.h +6 -0
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   Number of results that were pulled,
+ *   a negative errno value otherwise and rte_errno is set.

Don't we want to define negative error code meaning?

They are all standard, don't think we need another copy-paste here.

Quoted 12 lines
Quoted 12 lines
lib/ethdev/rte_flow.h +9 -0
+ */
+__rte_experimental
+int
+rte_flow_q_pull(uint16_t port_id,
+		uint32_t queue_id,
+		struct rte_flow_q_op_res res[],
+		uint16_t n_res,
+		struct rte_flow_error *error);
+
  #ifdef __cplusplus
  }
  #endif
#117 lore raw

Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

12/02/2022 03:19, Alexander Kozyrev:

Quoted 9 lines

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko <[email protected]>:

Quoted 7 lines · Alexander Kozyrev

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5300

Quoted 3 lines
lib/ethdev/rte_flow.h +3 -0
+__rte_experimental
+struct rte_flow *
+rte_flow_q_flow_create(uint16_t port_id,

flow_q_flow does not sound like a good nameing, consider:
rte_flow_q_rule_create() is <subsystem>_<subtype>_<object>_<action>

Quoted 4 lines

More like:
<subsystem>_<subtype>_<object>_<action>
<rte>_<flow>_<rule_create_operation>_<queue>
Which is pretty lengthy name as for me.

Naming :)
This one may be improved I think.
What is the problem with replacing "flow" with "rule"? Is it the right meaning?

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
lib/ethdev/rte_flow.h +4 -0
+__rte_experimental
+struct rte_flow_action_handle *
+rte_flow_q_action_handle_create(uint16_t port_id,
+		uint32_t queue_id,
Quoted 8 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3883

Quoted 3 lines
doc/guides/prog_guide/rte_flow.rst +3 -0
+		const struct rte_flow_q_ops_attr *q_ops_attr,
+		const struct rte_flow_indir_action_conf *indir_action_conf,
+		const struct rte_flow_action *action,

I don't understand why it differs so much from rule creation. Why is action template not used?
IMHO indirect actions should be dropped from the patch and added separately since it is a separate feature.

Quoted 2 lines

I agree, they deserve a sperate patch since they are rather resource creations. But, I'm afraid it is too late for RC1.

I think it could be done for RC2.

Quoted 25 lines
Quoted 25 lines
Quoted 24 lines

+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Pull a rte flow operation.
+ * The application must invoke this function in order to complete
+ * the flow rule offloading and to retrieve the flow rule operation status.
+ *
+ * @param port_id
+ * Port identifier of Ethernet device.
+ * @param queue_id
+ * Flow queue which is used to pull the operation.
+ * @param[out] res
+ * Array of results that will be set.
+ * @param[in] n_res
+ * Maximum number of results that can be returned.
+ * This value is equal to the size of the res array.
+ * @param[out] error
+ * Perform verbose error reporting if not NULL.
+ * PMDs initialize this structure in case of error only.
+ *
+ * @return
+ * Number of results that were pulled,
+ * a negative errno value otherwise and rte_errno is set.

Quoted 3 lines
Quoted 1 line

Don't we want to define negative error code meaning?

They are all standard, don't think we need another copy-paste here.

That's an API, it needs to be all explicit.
I missed it before, we should add the error codes here.

#118 lore raw

RE: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Quoted 17 lines · On Sat, Feb 12, 2022 4:25 Thomas Monjalon <[email protected]> wrote:

12/02/2022 03:19, Alexander Kozyrev:

Quoted 1 line

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko

<[email protected]>:

Quoted 7 lines
Quoted 7 lines · Alexander Kozyrev

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5300

Quoted 3 lines
lib/ethdev/rte_flow.h +3 -0
+__rte_experimental
+struct rte_flow *
+rte_flow_q_flow_create(uint16_t port_id,

flow_q_flow does not sound like a good nameing, consider:
rte_flow_q_rule_create() is

<subsystem>_<subtype>_<object>_<action>

Quoted 5 lines

More like:
<subsystem>_<subtype>_<object>_<action>
<rte>_<flow>_<rule_create_operation>_<queue>
Which is pretty lengthy name as for me.

Quoted 4 lines

Naming :)
This one may be improved I think.
What is the problem with replacing "flow" with "rule"? Is it the right meaning?

I've got a better naming for all the functions. What do you think about this? Asynchronous rte_flow_async_create and rte_flow_async_destroy functions as an extension of synchronous rte_flow_create/ rte_flow_destroy API. The same is true for asynchronous API for indirect actions:

	rte_flow_async_action_handle_create;
	rte_flow_async_action_handle_destroy;
	rte_flow_async_action_handle_update;

And rte_flow_push/rte_flow_pull without "_q_" part to make them clearer. And yes, I'm still thinking pull is better than poll since we are actually retrieving something, not just checking if it has something we can retrieve.
Let me know if we can agree on this scheme? Look pretty close to existing one.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5381

Quoted 7 lines
lib/ethdev/rte_flow.h +7 -0
+__rte_experimental
+struct rte_flow_action_handle *
+rte_flow_q_action_handle_create(uint16_t port_id,
+		uint32_t queue_id,
+		const struct rte_flow_q_ops_attr *q_ops_attr,
+		const struct rte_flow_indir_action_conf *indir_action_conf,
+		const struct rte_flow_action *action,

I don't understand why it differs so much from rule creation. Why is action template not used?
IMHO indirect actions should be dropped from the patch and added separately since it is a separate feature.

Quoted 5 lines
Quoted 1 line

I agree, they deserve a sperate patch since they are rather resource

creations.

Quoted 1 line

But, I'm afraid it is too late for RC1.

I think it could be done for RC2.

No problem, I'll create a separate commit for indirect actions.

Quoted 27 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Pull a rte flow operation.
+ * The application must invoke this function in order to complete
+ * the flow rule offloading and to retrieve the flow rule operation

status.

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines

+ *
+ * @param port_id
+ * Port identifier of Ethernet device.
+ * @param queue_id
+ * Flow queue which is used to pull the operation.
+ * @param[out] res
+ * Array of results that will be set.
+ * @param[in] n_res
+ * Maximum number of results that can be returned.
+ * This value is equal to the size of the res array.
+ * @param[out] error
+ * Perform verbose error reporting if not NULL.
+ * PMDs initialize this structure in case of error only.
+ *
+ * @return
+ * Number of results that were pulled,
+ * a negative errno value otherwise and rte_errno is set.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Don't we want to define negative error code meaning?

They are all standard, don't think we need another copy-paste here.

That's an API, it needs to be all explicit.
I missed it before, we should add the error codes here.

I'll add if you want to see them listed.

#119 lore raw

Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

16/02/2022 23:49, Alexander Kozyrev:

Quoted 27 lines · On Sat, Feb 12, 2022 4:25 Thomas Monjalon <[email protected]> wrote:
Quoted 17 lines

12/02/2022 03:19, Alexander Kozyrev:

Quoted 1 line

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko

<[email protected]>:

Quoted 7 lines
Quoted 7 lines · Alexander Kozyrev

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5300

Quoted 3 lines
lib/ethdev/rte_flow.h +3 -0
+__rte_experimental
+struct rte_flow *
+rte_flow_q_flow_create(uint16_t port_id,

flow_q_flow does not sound like a good nameing, consider:
rte_flow_q_rule_create() is

<subsystem>_<subtype>_<object>_<action>

Quoted 5 lines

More like:
<subsystem>_<subtype>_<object>_<action>
<rte>_<flow>_<rule_create_operation>_<queue>
Which is pretty lengthy name as for me.

Quoted 4 lines

Naming :)
This one may be improved I think.
What is the problem with replacing "flow" with "rule"? Is it the right meaning?

I've got a better naming for all the functions. What do you think about this? Asynchronous rte_flow_async_create and rte_flow_async_destroy functions as an extension of synchronous rte_flow_create/ rte_flow_destroy API. The same is true for asynchronous API for indirect actions:

Quoted 7 lines
	rte_flow_async_action_handle_create;
	rte_flow_async_action_handle_destroy;
	rte_flow_async_action_handle_update;

And rte_flow_push/rte_flow_pull without "_q_" part to make them clearer. And yes, I'm still thinking pull is better than poll since we are actually retrieving something, not just checking if it has something we can retrieve.
Let me know if we can agree on this scheme? Look pretty close to existing one.

I like the "async" word.

In summary, you propose this change for the functions of this patch:

	rte_flow_q_flow_create           -> rte_flow_async_create
	rte_flow_q_flow_destroy          -> rte_flow_async_destroy
	rte_flow_q_action_handle_create  -> rte_flow_async_action_handle_create
	rte_flow_q_action_handle_destroy -> rte_flow_async_action_handle_destroy
	rte_flow_q_action_handle_update  -> rte_flow_async_action_handle_update
	rte_flow_q_push                  -> rte_flow_push
	rte_flow_q_pull                  -> rte_flow_pull

They are close to the exisiting synchronous function names:

rte_flow_create
rte_flow_destroy
rte_flow_action_handle_create
rte_flow_action_handle_destroy
rte_flow_action_handle_update

I think it is a good naming scheme.

#120 lore raw

Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Quoted 50 lines · Thomas Monjalon

16/02/2022 23:49, Alexander Kozyrev:

Quoted 27 lines · On Sat, Feb 12, 2022 4:25 Thomas Monjalon <[email protected]> wrote:
Quoted 17 lines

12/02/2022 03:19, Alexander Kozyrev:

Quoted 1 line

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko

<[email protected]>:

Quoted 7 lines
Quoted 7 lines · Alexander Kozyrev

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5300

Quoted 3 lines
lib/ethdev/rte_flow.h +3 -0
+__rte_experimental
+struct rte_flow *
+rte_flow_q_flow_create(uint16_t port_id,

flow_q_flow does not sound like a good nameing, consider:
rte_flow_q_rule_create() is

<subsystem>_<subtype>_<object>_<action>

Quoted 5 lines

More like:
<subsystem>_<subtype>_<object>_<action>
<rte>_<flow>_<rule_create_operation>_<queue>
Which is pretty lengthy name as for me.

Quoted 4 lines

Naming :)
This one may be improved I think.
What is the problem with replacing "flow" with "rule"? Is it the right meaning?

I've got a better naming for all the functions. What do you think about this? Asynchronous rte_flow_async_create and rte_flow_async_destroy functions as an extension of synchronous rte_flow_create/ rte_flow_destroy API. The same is true for asynchronous API for indirect actions:

Quoted 7 lines
	rte_flow_async_action_handle_create;
	rte_flow_async_action_handle_destroy;
	rte_flow_async_action_handle_update;

And rte_flow_push/rte_flow_pull without "_q_" part to make them clearer. And yes, I'm still thinking pull is better than poll since we are actually retrieving something, not just checking if it has something we can retrieve.
Let me know if we can agree on this scheme? Look pretty close to existing one.

I like the "async" word.

In summary, you propose this change for the functions of this patch:

	rte_flow_q_flow_create           -> rte_flow_async_create
	rte_flow_q_flow_destroy          -> rte_flow_async_destroy
	rte_flow_q_action_handle_create  -> rte_flow_async_action_handle_create
	rte_flow_q_action_handle_destroy -> rte_flow_async_action_handle_destroy
	rte_flow_q_action_handle_update  -> rte_flow_async_action_handle_update
	rte_flow_q_push                  -> rte_flow_push
	rte_flow_q_pull                  -> rte_flow_pull

They are close to the exisiting synchronous function names:

Quoted 7 lines

rte_flow_create
rte_flow_destroy
rte_flow_action_handle_create
rte_flow_action_handle_destroy
rte_flow_action_handle_update

I think it is a good naming scheme.

+1

#121 lore raw

Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

In reply to Alexander Kozyrev
Quoted 25 lines · Alexander Kozyrev

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko <[email protected]>:

Quoted 24 lines · Alexander Kozyrev
Quoted 1 line

A new, faster, queue-based flow rules management mechanism is needed

for

Quoted 8 lines

applications offloading rules inside the datapath. This asynchronous and lockless mechanism frees the CPU for further packet processing and reduces the performance impact of the flow rules creation/destruction on the datapath. Note that queues are not thread-safe and the queue should be accessed from the same thread for all queue operations. It is the responsibility of the app to sync the queue functions in case of multi-threaded access to the same queue.

Quoted 4 lines

The rte_flow_q_flow_create() function enqueues a flow creation to the requested queue. It benefits from already configured resources and sets unique values on top of item and action templates. A flow rule is enqueued on the specified flow queue and offloaded asynchronously to the

hardware.

Quoted 8 lines

The function returns immediately to spare CPU for further packet processing. The application must invoke the rte_flow_q_pull() function to complete the flow rule operation offloading, to clear the queue, and to receive the operation status. The rte_flow_q_flow_destroy() function enqueues a flow destruction to the requested queue.

[snip]

Quoted 10 lines
Quoted 9 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3771

Quoted 5 lines
doc/guides/prog_guide/rte_flow.rst +5 -0
+
+- Available operation types: rule creation, rule destruction,
+  indirect rule creation, indirect rule destruction, indirect rule update.
+
+- Operations may be reordered within a queue.

Do we want to have barriers?
E.g. create rule, destroy the same rule -> reoder -> destroy fails, rule lives forever.

Quoted 3 lines

API design is crafter with the throughput as the main goal in mind. We allow user to enforce any ordering outside these functions. Another point that not all PMDs/NIC will have this out-of-order execution.

Throughput is nice, but there more important requirements which must be satistied before talking about performance. Could you explain me what I should do based on which information from NIC in order to solve above problem?

Quoted 8 lines
Quoted 7 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3775

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+- Operations can be postponed and pushed to NIC in batches.
+
+- Results pulling must be done on time to avoid queue overflows.

polling? (as libc poll() which checks status of file descriptors) it is not pulling the door to open it :)

Quoted 9 lines

poll waits for some event on a file descriptor as it title says. And then user has to invoke read() to actually get any info from the fd. The point of our function is to return the result immediately, thus pulling. We had many names appearing in the thread for these functions. As we know, naming variables is the second hardest thing in programming. I wanted this pull for results pulling be a counterpart for the push for pushing the operations to a NIC. Another idea is pop/push pair, but they are more like for operations only, not for results.
Having said that I'm at the point of accepting any name here.

I agree that it is hard to choose good naming. Just want to say that polling is not alway waiting.

poll - check the status of (a device), especially as part of a repeated cycle.

Here we're checking status of flow engine requests and yes, finally in a repeated cycle.

[snip]

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
lib/ethdev/rte_flow.h +7 -0
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Queue operation attributes.
+ */
+struct rte_flow_q_ops_attr {
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5256

Quoted 4 lines
lib/ethdev/rte_flow.h +4 -0
+	/**
+	 * The user data that will be returned on the completion events.
+	 */
+	void *user_data;

IMHO it must not be hiddne in attrs. It is a key information which is used to understand the opration result. It should be passed separately.

Quoted 1 line

Maybe, on the other hand it is optional and may not be needed by an application.

I don't understand how it is possible. Without it application don't know fate of its requests.

Quoted 6 lines
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	 /**
+	  * When set, the requested action will not be sent to the HW

immediately.

Review

Quoted 1 line
(quoted diff) +1 -0
+	  * The application must call the rte_flow_queue_push to actually

send it.

Quoted 6 lines
Quoted 3 lines

Will the next operation without the attribute set implicitly push it? Is it mandatory for the driver to respect it? Or is it just a possible optimization hint?

Yes, it will be pushed with all the operations in a queue once the postpone is cleared. It is not mandatory to respect this bit, PMD can use other optimization technics.

Could you clarify it in the description.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
lib/ethdev/rte_flow.h +3 -0
+	  */
+	uint32_t postpone:1;
+};

[snip]

#122 lore raw

RE: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Hi Andew,

Quoted 44 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Wednesday, February 16, 2022 3:34 PM
Subject: Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Quoted 25 lines · Alexander Kozyrev

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko <[email protected]>:

Quoted 24 lines · Alexander Kozyrev
Quoted 1 line

A new, faster, queue-based flow rules management mechanism is needed

for

Quoted 8 lines

applications offloading rules inside the datapath. This asynchronous and lockless mechanism frees the CPU for further packet processing and reduces the performance impact of the flow rules creation/destruction on the datapath. Note that queues are not thread-safe and the queue should be accessed from the same thread for all queue operations. It is the responsibility of the app to sync the queue functions in case of multi-threaded access to the same queue.

Quoted 4 lines

The rte_flow_q_flow_create() function enqueues a flow creation to the requested queue. It benefits from already configured resources and sets unique values on top of item and action templates. A flow rule is enqueued on the specified flow queue and offloaded asynchronously to the

hardware.

Quoted 8 lines

The function returns immediately to spare CPU for further packet processing. The application must invoke the rte_flow_q_pull() function to complete the flow rule operation offloading, to clear the queue, and to receive the operation status. The rte_flow_q_flow_destroy() function enqueues a flow destruction to the requested queue.

[snip]

Quoted 10 lines
Quoted 9 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3771

Quoted 5 lines
doc/guides/prog_guide/rte_flow.rst +5 -0
+
+- Available operation types: rule creation, rule destruction,
+  indirect rule creation, indirect rule destruction, indirect rule update.
+
+- Operations may be reordered within a queue.

Do we want to have barriers?
E.g. create rule, destroy the same rule -> reoder -> destroy fails, rule lives forever.

Quoted 9 lines
Quoted 3 lines

API design is crafter with the throughput as the main goal in mind. We allow user to enforce any ordering outside these functions. Another point that not all PMDs/NIC will have this out-of-order execution.

Throughput is nice, but there more important requirements which must be satistied before talking about performance. Could you explain me what I should do based on which information from NIC in order to solve above problem?

The idea is that if application has dependency between the rules/ rules operations. It should wait for the completion of the operation before sending the dependent operation. In the example you provided above, according to the documeation application should wait for the completion of the flow creation before destroying it.

Quoted 45 lines
Quoted 8 lines
Quoted 7 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3775

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+- Operations can be postponed and pushed to NIC in batches.
+
+- Results pulling must be done on time to avoid queue overflows.

polling? (as libc poll() which checks status of file descriptors) it is not pulling the door to open it :)

Quoted 9 lines

poll waits for some event on a file descriptor as it title says. And then user has to invoke read() to actually get any info from the fd. The point of our function is to return the result immediately, thus pulling. We had many names appearing in the thread for these functions. As we know, naming variables is the second hardest thing in programming. I wanted this pull for results pulling be a counterpart for the push for pushing the operations to a NIC. Another idea is pop/push pair, but they are more like for operations only, not for results.
Having said that I'm at the point of accepting any name here.

I agree that it is hard to choose good naming. Just want to say that polling is not alway waiting.

poll - check the status of (a device), especially as part of a repeated cycle.

Here we're checking status of flow engine requests and yes, finally in a repeated cycle.

[snip]

Quoted 16 lines
Quoted 15 lines

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5256

Quoted 11 lines
lib/ethdev/rte_flow.h +11 -0
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Queue operation attributes.
+ */
+struct rte_flow_q_ops_attr {
+	/**
+	 * The user data that will be returned on the completion events.
+	 */
+	void *user_data;

IMHO it must not be hiddne in attrs. It is a key information which is used to understand the opration result. It should be passed separately.

Quoted 5 lines
Quoted 1 line

Maybe, on the other hand it is optional and may not be needed by an application.

I don't understand how it is possible. Without it application don't know fate of its requests.

IMHO since user_data should be in all related operations API along with the attr, splitting the user_data will just add extra parameter to each function call. Since we have number of functions and will add more in future I think it will be best to keep it in this location.

Quoted 13 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	 /**
+	  * When set, the requested action will not be sent to the HW

immediately.

Review

Quoted 1 line
(quoted diff) +1 -0
+	  * The application must call the rte_flow_queue_push to actually

send it.

Quoted 6 lines
Quoted 3 lines

Will the next operation without the attribute set implicitly push it? Is it mandatory for the driver to respect it? Or is it just a possible optimization hint?

Yes, it will be pushed with all the operations in a queue once the postpone is cleared. It is not mandatory to respect this bit, PMD can use other optimization technics.

Quoted 7 lines

Could you clarify it in the description.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
lib/ethdev/rte_flow.h +3 -0
+	  */
+	uint32_t postpone:1;
+};

[snip]

Best,
Ori

#123 lore raw

Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Hi Ori,

Quoted 56 lines · Ori Kam

Hi Andew,

Quoted 44 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Wednesday, February 16, 2022 3:34 PM
Subject: Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Quoted 25 lines · Alexander Kozyrev

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko <[email protected]>:

Quoted 24 lines · Alexander Kozyrev
Quoted 1 line

A new, faster, queue-based flow rules management mechanism is needed

for

Quoted 8 lines

applications offloading rules inside the datapath. This asynchronous and lockless mechanism frees the CPU for further packet processing and reduces the performance impact of the flow rules creation/destruction on the datapath. Note that queues are not thread-safe and the queue should be accessed from the same thread for all queue operations. It is the responsibility of the app to sync the queue functions in case of multi-threaded access to the same queue.

Quoted 4 lines

The rte_flow_q_flow_create() function enqueues a flow creation to the requested queue. It benefits from already configured resources and sets unique values on top of item and action templates. A flow rule is enqueued on the specified flow queue and offloaded asynchronously to the

hardware.

Quoted 8 lines

The function returns immediately to spare CPU for further packet processing. The application must invoke the rte_flow_q_pull() function to complete the flow rule operation offloading, to clear the queue, and to receive the operation status. The rte_flow_q_flow_destroy() function enqueues a flow destruction to the requested queue.

[snip]

Quoted 10 lines
Quoted 9 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3771

Quoted 5 lines
doc/guides/prog_guide/rte_flow.rst +5 -0
+
+- Available operation types: rule creation, rule destruction,
+  indirect rule creation, indirect rule destruction, indirect rule update.
+
+- Operations may be reordered within a queue.

Do we want to have barriers?
E.g. create rule, destroy the same rule -> reoder -> destroy fails, rule lives forever.

Quoted 9 lines
Quoted 3 lines

API design is crafter with the throughput as the main goal in mind. We allow user to enforce any ordering outside these functions. Another point that not all PMDs/NIC will have this out-of-order execution.

Throughput is nice, but there more important requirements which must be satistied before talking about performance. Could you explain me what I should do based on which information from NIC in order to solve above problem?

Quoted 4 lines

The idea is that if application has dependency between the rules/ rules operations. It should wait for the completion of the operation before sending the dependent operation. In the example you provided above, according to the documeation application should wait for the completion of the flow creation before destroying it.

I see, thanks. May be I read documentation not that attentive. I'll reread on the next version review cycle.

Quoted 47 lines
Quoted 47 lines
Quoted 8 lines
Quoted 7 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3775

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+- Operations can be postponed and pushed to NIC in batches.
+
+- Results pulling must be done on time to avoid queue overflows.

polling? (as libc poll() which checks status of file descriptors) it is not pulling the door to open it :)

Quoted 9 lines

poll waits for some event on a file descriptor as it title says. And then user has to invoke read() to actually get any info from the fd. The point of our function is to return the result immediately, thus pulling. We had many names appearing in the thread for these functions. As we know, naming variables is the second hardest thing in programming. I wanted this pull for results pulling be a counterpart for the push for pushing the operations to a NIC. Another idea is pop/push pair, but they are more like for operations only, not for results.
Having said that I'm at the point of accepting any name here.

I agree that it is hard to choose good naming. Just want to say that polling is not alway waiting.

poll - check the status of (a device), especially as part of a repeated cycle.

Here we're checking status of flow engine requests and yes, finally in a repeated cycle.

[snip]

Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
lib/ethdev/rte_flow.h +7 -0
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Queue operation attributes.
+ */
+struct rte_flow_q_ops_attr {
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5256

Quoted 4 lines
lib/ethdev/rte_flow.h +4 -0
+	/**
+	 * The user data that will be returned on the completion events.
+	 */
+	void *user_data;

IMHO it must not be hiddne in attrs. It is a key information which is used to understand the opration result. It should be passed separately.

Maybe, on the other hand it is optional and may not be needed by an application.

Quoted 7 lines
Quoted 3 lines

I don't understand how it is possible. Without it application don't know fate of its requests.

IMHO since user_data should be in all related operations API along with the attr, splitting the user_data will just add extra parameter to each function call. Since we have number of functions and will add more in future I think it will be best to keep it in this location.

My problem with hiding user_data inside attr is that 'user_data' is not an auxiliary attribute defining extra properties of the request. It is a key information. May be attr is not an ideal name for such grouping of parameters. Unfortunately I have no better ideas right now.

Andrew.

#124 lore raw

RE: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Hi Andrew,

Quoted 127 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Thursday, February 17, 2022 12:53 PM
Subject: Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Hi Ori,

Quoted 56 lines · Ori Kam

Hi Andew,

Quoted 44 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Wednesday, February 16, 2022 3:34 PM
Subject: Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Quoted 25 lines · Alexander Kozyrev

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko <[email protected]>:

Quoted 24 lines · Alexander Kozyrev
Quoted 1 line

A new, faster, queue-based flow rules management mechanism is needed

for

Quoted 8 lines

applications offloading rules inside the datapath. This asynchronous and lockless mechanism frees the CPU for further packet processing and reduces the performance impact of the flow rules creation/destruction on the datapath. Note that queues are not thread-safe and the queue should be accessed from the same thread for all queue operations. It is the responsibility of the app to sync the queue functions in case of multi-threaded access to the same queue.

Quoted 4 lines

The rte_flow_q_flow_create() function enqueues a flow creation to the requested queue. It benefits from already configured resources and sets unique values on top of item and action templates. A flow rule is enqueued on the specified flow queue and offloaded asynchronously to the

hardware.

Quoted 8 lines

The function returns immediately to spare CPU for further packet processing. The application must invoke the rte_flow_q_pull() function to complete the flow rule operation offloading, to clear the queue, and to receive the operation status. The rte_flow_q_flow_destroy() function enqueues a flow destruction to the requested queue.

[snip]

Quoted 10 lines
Quoted 9 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3771

Quoted 5 lines
doc/guides/prog_guide/rte_flow.rst +5 -0
+
+- Available operation types: rule creation, rule destruction,
+  indirect rule creation, indirect rule destruction, indirect rule update.
+
+- Operations may be reordered within a queue.

Do we want to have barriers?
E.g. create rule, destroy the same rule -> reoder -> destroy fails, rule lives forever.

Quoted 9 lines
Quoted 3 lines

API design is crafter with the throughput as the main goal in mind. We allow user to enforce any ordering outside these functions. Another point that not all PMDs/NIC will have this out-of-order execution.

Throughput is nice, but there more important requirements which must be satistied before talking about performance. Could you explain me what I should do based on which information from NIC in order to solve above problem?

Quoted 4 lines

The idea is that if application has dependency between the rules/ rules operations. It should wait for the completion of the operation before sending the dependent operation. In the example you provided above, according to the documeation application should wait for the completion of the flow creation before destroying it.

I see, thanks. May be I read documentation not that attentive. I'll reread on the next version review cycle.

Quoted 47 lines
Quoted 47 lines
Quoted 8 lines
Quoted 7 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3775

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+- Operations can be postponed and pushed to NIC in batches.
+
+- Results pulling must be done on time to avoid queue overflows.

polling? (as libc poll() which checks status of file descriptors) it is not pulling the door to open it :)

Quoted 9 lines

poll waits for some event on a file descriptor as it title says. And then user has to invoke read() to actually get any info from the fd. The point of our function is to return the result immediately, thus pulling. We had many names appearing in the thread for these functions. As we know, naming variables is the second hardest thing in programming. I wanted this pull for results pulling be a counterpart for the push for pushing the operations to a NIC. Another idea is pop/push pair, but they are more like for operations only, not for results.
Having said that I'm at the point of accepting any name here.

I agree that it is hard to choose good naming. Just want to say that polling is not alway waiting.

poll - check the status of (a device), especially as part of a repeated cycle.

Here we're checking status of flow engine requests and yes, finally in a repeated cycle.

[snip]

Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
lib/ethdev/rte_flow.h +7 -0
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Queue operation attributes.
+ */
+struct rte_flow_q_ops_attr {
Quoted 8 lines

lib/ethdev/rte_flow.h rte_flow_template_table_destroy(uint16_t port_id, · line 5256

Quoted 4 lines
lib/ethdev/rte_flow.h +4 -0
+	/**
+	 * The user data that will be returned on the completion events.
+	 */
+	void *user_data;

IMHO it must not be hiddne in attrs. It is a key information which is used to understand the opration result. It should be passed separately.

Maybe, on the other hand it is optional and may not be needed by an application.

Quoted 7 lines
Quoted 3 lines

I don't understand how it is possible. Without it application don't know fate of its requests.

IMHO since user_data should be in all related operations API along with the attr, splitting the user_data will just add extra parameter to each function call. Since we have number of functions and will add more in future I think it will be best to keep it in this location.

Quoted 6 lines

My problem with hiding user_data inside attr is that 'user_data' is not an auxiliary attribute defining extra properties of the request. It is a key information. May be attr is not an ideal name for such grouping of parameters. Unfortunately I have no better ideas right now.

I understand your point, if you don't have objections lets keep the current one and if needed we will modify.
Is that O.K?

Quoted 1 line

Andrew.

#125 lore raw

RE: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Hi Andrew,

Quoted 140 lines

-----Original Message-----
From: Ori Kam
Sent: Thursday, February 17, 2022 1:09 PM
Subject: RE: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Hi Andrew,

Quoted 127 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Thursday, February 17, 2022 12:53 PM
Subject: Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Hi Ori,

Quoted 56 lines · Ori Kam

Hi Andew,

Quoted 44 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Wednesday, February 16, 2022 3:34 PM
Subject: Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Quoted 25 lines · Alexander Kozyrev

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko <[email protected]>:

Quoted 24 lines · Alexander Kozyrev
Quoted 1 line

A new, faster, queue-based flow rules management mechanism is needed

for

Quoted 8 lines

applications offloading rules inside the datapath. This asynchronous and lockless mechanism frees the CPU for further packet processing and reduces the performance impact of the flow rules creation/destruction on the datapath. Note that queues are not thread-safe and the queue should be accessed from the same thread for all queue operations. It is the responsibility of the app to sync the queue functions in case of multi-threaded access to the same queue.

Quoted 4 lines

The rte_flow_q_flow_create() function enqueues a flow creation to the requested queue. It benefits from already configured resources and sets unique values on top of item and action templates. A flow rule is enqueued on the specified flow queue and offloaded asynchronously to the

hardware.

Quoted 8 lines

The function returns immediately to spare CPU for further packet processing. The application must invoke the rte_flow_q_pull() function to complete the flow rule operation offloading, to clear the queue, and to receive the operation status. The rte_flow_q_flow_destroy() function enqueues a flow destruction to the requested queue.

[snip]

Quoted 10 lines
Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+
+- Available operation types: rule creation, rule destruction,
+  indirect rule creation, indirect rule destruction, indirect rule update.
+
+- Operations may be reordered within a queue.

Do we want to have barriers?
E.g. create rule, destroy the same rule -> reoder -> destroy fails, rule lives forever.

Quoted 9 lines
Quoted 3 lines

API design is crafter with the throughput as the main goal in mind. We allow user to enforce any ordering outside these functions. Another point that not all PMDs/NIC will have this out-of-order execution.

Throughput is nice, but there more important requirements which must be satistied before talking about performance. Could you explain me what I should do based on which information from NIC in order to solve above problem?

Quoted 4 lines

The idea is that if application has dependency between the rules/ rules operations. It should wait for the completion of the operation before sending the dependent operation. In the example you provided above, according to the documeation application should wait for the completion of the flow creation before destroying it.

I see, thanks. May be I read documentation not that attentive. I'll reread on the next version review cycle.

Quoted 47 lines
Quoted 47 lines
Quoted 8 lines
Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+
+- Operations can be postponed and pushed to NIC in batches.
+
+- Results pulling must be done on time to avoid queue overflows.

polling? (as libc poll() which checks status of file descriptors) it is not pulling the door to open it :)

Quoted 9 lines

poll waits for some event on a file descriptor as it title says. And then user has to invoke read() to actually get any info from the fd. The point of our function is to return the result immediately, thus pulling. We had many names appearing in the thread for these functions. As we know, naming variables is the second hardest thing in programming. I wanted this pull for results pulling be a counterpart for the push for pushing the operations to a NIC. Another idea is pop/push pair, but they are more like for operations only, not for results.
Having said that I'm at the point of accepting any name here.

I agree that it is hard to choose good naming. Just want to say that polling is not alway waiting.

poll - check the status of (a device), especially as part of a repeated cycle.

Here we're checking status of flow engine requests and yes, finally in a repeated cycle.

[snip]

Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +7 -0
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Queue operation attributes.
+ */
+struct rte_flow_q_ops_attr {
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+	/**
+	 * The user data that will be returned on the completion events.
+	 */
+	void *user_data;

IMHO it must not be hiddne in attrs. It is a key information which is used to understand the opration result. It should be passed separately.

Maybe, on the other hand it is optional and may not be needed by an application.

Quoted 7 lines
Quoted 3 lines

I don't understand how it is possible. Without it application don't know fate of its requests.

IMHO since user_data should be in all related operations API along with the attr, splitting the user_data will just add extra parameter to each function call. Since we have number of functions and will add more in future I think it will be best to keep it in this location.

Quoted 6 lines

My problem with hiding user_data inside attr is that 'user_data' is not an auxiliary attribute defining extra properties of the request. It is a key information. May be attr is not an ideal name for such grouping of parameters. Unfortunately I have no better ideas right now.

Quoted 4 lines

I understand your point, if you don't have objections lets keep the current one and if needed we will modify.
Is that O.K?

Thinking about it again,
lets move it to a dedecated parameter.

Ori

Quoted 1 line
Quoted 1 line

Andrew.

#126 lore raw

Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

17/02/2022 15:16, Ori Kam:

Quoted 38 lines

From: Ori Kam

Quoted 37 lines

From: Andrew Rybchenko <[email protected]>

Quoted 36 lines · Ori Kam
Quoted 21 lines

From: Andrew Rybchenko <[email protected]>

Quoted 20 lines · Alexander Kozyrev
Quoted 18 lines

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko <[email protected]>:

Quoted 7 lines
Quoted 7 lines
(quoted diff) +7 -0
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Queue operation attributes.
+ */
+struct rte_flow_q_ops_attr {
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+	/**
+	 * The user data that will be returned on the completion events.
+	 */
+	void *user_data;

IMHO it must not be hiddne in attrs. It is a key information which is used to understand the opration result. It should be passed separately.

Maybe, on the other hand it is optional and may not be needed by an application.

Quoted 7 lines
Quoted 3 lines

I don't understand how it is possible. Without it application don't know fate of its requests.

IMHO since user_data should be in all related operations API along with the attr, splitting the user_data will just add extra parameter to each function call. Since we have number of functions and will add more in future I think it will be best to keep it in this location.

My problem with hiding user_data inside attr is that 'user_data' is not an auxiliary attribute defining extra properties of the request. It is a key information. May be attr is not an ideal name for such grouping of parameters. Unfortunately I have no better ideas right now.

Quoted 6 lines
Quoted 3 lines

I understand your point, if you don't have objections lets keep the current one and if needed we will modify.
Is that O.K?

Thinking about it again,
lets move it to a dedecated parameter.

I'm OK with the decision of moving user_data as a function parameter.

#127 lore raw

RE: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

In reply to Andrew Rybchenko

Hi Andew,

I missed on comments PSB,

Quoted 8 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Subject: Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Quoted 3 lines · Alexander Kozyrev

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko <[email protected]>:

Quoted 2 lines · Alexander Kozyrev
Quoted 1 line

A new, faster, queue-based flow rules management mechanism is needed

[Snip]

Quoted 18 lines
Quoted 8 lines
Quoted 7 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3775

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+- Operations can be postponed and pushed to NIC in batches.
+
+- Results pulling must be done on time to avoid queue overflows.

polling? (as libc poll() which checks status of file descriptors) it is not pulling the door to open it :)

Quoted 9 lines

poll waits for some event on a file descriptor as it title says. And then user has to invoke read() to actually get any info from the fd. The point of our function is to return the result immediately, thus pulling. We had many names appearing in the thread for these functions. As we know, naming variables is the second hardest thing in programming. I wanted this pull for results pulling be a counterpart for the push for pushing the operations to a NIC. Another idea is pop/push pair, but they are more like for operations only, not for results.
Having said that I'm at the point of accepting any name here.

Quoted 9 lines

I agree that it is hard to choose good naming. Just want to say that polling is not alway waiting.

poll - check the status of (a device), especially as part of a repeated cycle.

Here we're checking status of flow engine requests and yes, finally in a repeated cycle.

I think the best name should be dequeue since it means that
the calling app gets back info and also free space in the the qeueue. My second option is the pull, since again it implies that we are getting back something from the queue and not just waiting for event.

Best,
Ori

#128 lore raw

Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Quoted 37 lines · Ori Kam

Hi Andew,

I missed on comments PSB,

Quoted 8 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Subject: Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Quoted 3 lines · Alexander Kozyrev

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko <[email protected]>:

Quoted 2 lines · Alexander Kozyrev
Quoted 1 line

A new, faster, queue-based flow rules management mechanism is needed

[Snip]

Quoted 21 lines
Quoted 8 lines
Quoted 7 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3775

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+- Operations can be postponed and pushed to NIC in batches.
+
+- Results pulling must be done on time to avoid queue overflows.

polling? (as libc poll() which checks status of file descriptors) it is not pulling the door to open it :)

Quoted 9 lines

poll waits for some event on a file descriptor as it title says. And then user has to invoke read() to actually get any info from the fd. The point of our function is to return the result immediately, thus pulling. We had many names appearing in the thread for these functions. As we know, naming variables is the second hardest thing in programming. I wanted this pull for results pulling be a counterpart for the push for pushing the operations to a NIC. Another idea is pop/push pair, but they are more like for operations only, not for results.
Having said that I'm at the point of accepting any name here.

I agree that it is hard to choose good naming. Just want to say that polling is not alway waiting.

Quoted 8 lines
Quoted 6 lines

poll - check the status of (a device), especially as part of a repeated cycle.

Here we're checking status of flow engine requests and yes, finally in a repeated cycle.

I think the best name should be dequeue since it means that the calling app gets back info and also free space in the the qeueue.

Dequeue is bad since it is not a queue because of out-of-order completions. So, if it is a ring, completion of one request does not always free space in ring. May be it should not be treated as a ring.

Quoted 2 lines

My second option is the pull, since again it implies that we are getting back something from the queue and not just waiting for event.

I'll think a bit more about it.

#129 lore raw

RE: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Hi Andrew,

Quoted 49 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Thursday, February 17, 2022 1:11 PM
Subject: Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Quoted 43 lines · Ori Kam

Hi Andew,

I missed on comments PSB,

Quoted 8 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Subject: Re: [PATCH v5 03/10] ethdev: bring in async queue-based flow rules operations

Quoted 3 lines · Alexander Kozyrev

On Fri, Feb 11, 2022 7:42 Andrew Rybchenko <[email protected]>:

Quoted 2 lines · Alexander Kozyrev
Quoted 1 line

A new, faster, queue-based flow rules management mechanism is needed

[Snip]

Quoted 27 lines
Quoted 8 lines
Quoted 7 lines

doc/guides/prog_guide/rte_flow.rst and pattern and actions templates are created. · line 3775

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+- Operations can be postponed and pushed to NIC in batches.
+
+- Results pulling must be done on time to avoid queue overflows.

polling? (as libc poll() which checks status of file descriptors) it is not pulling the door to open it :)

Quoted 9 lines

poll waits for some event on a file descriptor as it title says. And then user has to invoke read() to actually get any info from the fd. The point of our function is to return the result immediately, thus pulling. We had many names appearing in the thread for these functions. As we know, naming variables is the second hardest thing in programming. I wanted this pull for results pulling be a counterpart for the push for pushing the operations to a NIC. Another idea is pop/push pair, but they are more like for operations only, not for results.
Having said that I'm at the point of accepting any name here.

I agree that it is hard to choose good naming. Just want to say that polling is not alway waiting.

poll - check the status of (a device), especially as part of a repeated cycle.

Here we're checking status of flow engine requests and yes, finally in a repeated cycle.

Quoted 8 lines
Quoted 2 lines

I think the best name should be dequeue since it means that the calling app gets back info and also free space in the the qeueue.

Dequeue is bad since it is not a queue because of out-of-order completions. So, if it is a ring, completion of one request does not always free space in ring. May be it should not be treated as a ring.

Like I said I'm O.K with the pull version.
I had many many descussions about the queue, I was also thinking about it the way you do, that saying queue means it is ordered, but that is not true by definition you can have unordered queue. (for example priority queues) or just your everyday queue in the store that at the end will be split to counters and each customer can finish before the one that he was after in the queue.

Important thing to notice, this function does clear space in the queue.

Quoted 4 lines
Quoted 2 lines

My second option is the pull, since again it implies that we are getting back something from the queue and not just waiting for event.

I'll think a bit more about it.

Thanks,

Best,
Ori

#130 lore raw

PATCH v5 4/10 app/testpmd: add flow engine configuration

In reply to Alexander Kozyrev

Add testpmd support for the rte_flow_configure API. Provide the command line interface for the Flow management. Usage example: flow configure 0 queues_number 8 queues_size 256

Implement rte_flow_info_get API to get available resources:
Usage example: flow info 0

---
 app/test-pmd/cmdline_flow.c                 | 126 +++++++++++++++++++-
 app/test-pmd/config.c                       |  55 +++++++++
 app/test-pmd/testpmd.h                      |   7 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  60 +++++++++-
 4 files changed, 245 insertions(+), 3 deletions(-)
app/test-pmd/cmdline_flow.c +125 -1
index 7b56b1b0ff..cc3003e6eb 100644
@@ -72,6 +72,8 @@ enum index {
 	/* Top-level command. */
 	FLOW,
 	/* Sub-level commands. */
+	INFO,
+	CONFIGURE,
 	INDIRECT_ACTION,
 	VALIDATE,
 	CREATE,
@@ -122,6 +124,13 @@ enum index {
 	DUMP_ALL,
 	DUMP_ONE,
 
+	/* Configure arguments */
+	CONFIG_QUEUES_NUMBER,
+	CONFIG_QUEUES_SIZE,
+	CONFIG_COUNTERS_NUMBER,
+	CONFIG_AGING_COUNTERS_NUMBER,
+	CONFIG_METERS_NUMBER,
+
 	/* Indirect action arguments */
 	INDIRECT_ACTION_CREATE,
 	INDIRECT_ACTION_UPDATE,
@@ -847,6 +856,11 @@ struct buffer {
 	enum index command; /**< Flow command. */
 	portid_t port; /**< Affected port ID. */
 	union {
+		struct {
+			struct rte_flow_port_attr port_attr;
+			uint32_t nb_queue;
+			struct rte_flow_queue_attr queue_attr;
+		} configure; /**< Configuration arguments. */
 		struct {
 			uint32_t *action_id;
 			uint32_t action_id_n;
@@ -928,6 +942,16 @@ static const enum index next_flex_item[] = {
 	ZERO,
 };
 
+static const enum index next_config_attr[] = {
+	CONFIG_QUEUES_NUMBER,
+	CONFIG_QUEUES_SIZE,
+	CONFIG_COUNTERS_NUMBER,
+	CONFIG_AGING_COUNTERS_NUMBER,
+	CONFIG_METERS_NUMBER,
+	END,
+	ZERO,
+};
+
 static const enum index next_ia_create_attr[] = {
 	INDIRECT_ACTION_CREATE_ID,
 	INDIRECT_ACTION_INGRESS,
@@ -1964,6 +1988,9 @@ static int parse_aged(struct context *, const struct token *,
 static int parse_isolate(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
+static int parse_configure(struct context *, const struct token *,
+			   const char *, unsigned int,
+			   void *, unsigned int);
 static int parse_tunnel(struct context *, const struct token *,
 			const char *, unsigned int,
 			void *, unsigned int);
@@ -2189,7 +2216,9 @@ static const struct token token_list[] = {
 		.type = "{command} {port_id} [{arg} [...]]",
 		.help = "manage ingress/egress flow rules",
 		.next = NEXT(NEXT_ENTRY
-			     (INDIRECT_ACTION,
+			     (INFO,
+			      CONFIGURE,
+			      INDIRECT_ACTION,
 			      VALIDATE,
 			      CREATE,
 			      DESTROY,
@@ -2204,6 +2233,65 @@ static const struct token token_list[] = {
 		.call = parse_init,
 	},
 	/* Top-level command. */
+	[INFO] = {
+		.name = "info",
+		.help = "get information about flow engine",
+		.next = NEXT(NEXT_ENTRY(END),
+			     NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_configure,
+	},
+	/* Top-level command. */
+	[CONFIGURE] = {
+		.name = "configure",
+		.help = "configure flow engine",
+		.next = NEXT(next_config_attr,
+			     NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_configure,
+	},
+	/* Configure arguments. */
+	[CONFIG_QUEUES_NUMBER] = {
+		.name = "queues_number",
+		.help = "number of queues",
+		.next = NEXT(next_config_attr,
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.configure.nb_queue)),
+	},
+	[CONFIG_QUEUES_SIZE] = {
+		.name = "queues_size",
+		.help = "number of elements in queues",
+		.next = NEXT(next_config_attr,
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.configure.queue_attr.size)),
+	},
+	[CONFIG_COUNTERS_NUMBER] = {
+		.name = "counters_number",
+		.help = "number of counters",
+		.next = NEXT(next_config_attr,
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.configure.port_attr.nb_counters)),
+	},
+	[CONFIG_AGING_COUNTERS_NUMBER] = {
+		.name = "aging_counters_number",
+		.help = "number of aging flows",
+		.next = NEXT(next_config_attr,
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.configure.port_attr.nb_aging_flows)),
+	},
+	[CONFIG_METERS_NUMBER] = {
+		.name = "meters_number",
+		.help = "number of meters",
+		.next = NEXT(next_config_attr,
+			     NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct buffer,
+					args.configure.port_attr.nb_meters)),
+	},
+	/* Top-level command. */
 	[INDIRECT_ACTION] = {
 		.name = "indirect_action",
 		.type = "{command} {port_id} [{arg} [...]]",
@@ -7480,6 +7568,33 @@ parse_isolate(struct context *ctx, const struct token *token,
 	return len;
 }
 
+/** Parse tokens for info/configure command. */
+static int
+parse_configure(struct context *ctx, const struct token *token,
+		const char *str, unsigned int len,
+		void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != INFO && ctx->curr != CONFIGURE)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+	}
+	return len;
+}
+
 static int
 parse_flex(struct context *ctx, const struct token *token,
 	     const char *str, unsigned int len,
@@ -8708,6 +8823,15 @@ static void
 cmd_flow_parsed(const struct buffer *in)
 {
 	switch (in->command) {
+	case INFO:
+		port_flow_get_info(in->port);
+		break;
+	case CONFIGURE:
+		port_flow_configure(in->port,
+				    &in->args.configure.port_attr,
+				    in->args.configure.nb_queue,
+				    &in->args.configure.queue_attr);
+		break;
 	case INDIRECT_ACTION_CREATE:
 		port_action_handle_create(
 				in->port, in->args.vc.attr.group,
app/test-pmd/config.c +55 -0

61 lines not on this page · raw message

app/test-pmd/testpmd.h +7 -0
index 9967825044..096b6825eb 100644
@@ -243,6 +243,8 @@ struct rte_port {
 	struct rte_eth_txconf   tx_conf[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue tx configuration */
 	struct rte_ether_addr   *mc_addr_pool; /**< pool of multicast addrs */
 	uint32_t                mc_addr_nb; /**< nb. of addr. in mc_addr_pool */
+	queueid_t               queue_nb; /**< nb. of queues for flow rules */
+	uint32_t                queue_sz; /**< size of a queue for flow rules */
 	uint8_t                 slave_flag; /**< bonding slave port */
 	struct port_flow        *flow_list; /**< Associated flows. */
 	struct port_indirect_action *actions_list;
@@ -885,6 +887,11 @@ struct rte_flow_action_handle *port_action_handle_get_by_id(portid_t port_id,
 							    uint32_t id);
 int port_action_handle_update(portid_t port_id, uint32_t id,
 			      const struct rte_flow_action *action);
+int port_flow_get_info(portid_t port_id);
+int port_flow_configure(portid_t port_id,
+			const struct rte_flow_port_attr *port_attr,
+			uint16_t nb_queue,
+			const struct rte_flow_queue_attr *queue_attr);
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
doc/guides/testpmd_app_ug/testpmd_funcs.rst +58 -2

78 lines not on this page · raw message

Signature · 1 line
2.18.2