Skip to contentSkip to conversation

net/mlx5: flow insertion performance improvements

PATCH Superseded Dariusz Sosnowski 3 participants 26 messages Feb 28, 2024 – Mar 3, 2024 Network drivers

lore
Share & tools
lore
#0 lore raw

cover net/mlx5: flow insertion performance improvements

Goal of this patchset is to improve the throughput of flow insertion and deletion in mlx5 PMD when HW Steering flow engine is used.

- Patch 1 - Use preallocated per-queue, per-actions template buffer for storing translated flow actions, instead of allocating and filling it on demand, on each flow operation.
- Patches 2-4 - Make resource index allocation optional. This allocation will be skipped when it is not required by the created template table.
- Patches 5-7 - Reduce memory footprint of the internal flow queue.
- Patch 8 - Remove indirection between flow job and flow itself, by using flow as an operation container.
- Patches 9-10 - Reduce memory footpring of flow struct by moving rarely used flow fields outside of the main flow struct. These fields will accesses only when needed.
Also remove unneeded zmalloc usage.
- Patch 11 - Remove unneeded device status check in flow create.

In general all of these changes result in the following improvements (all numbers are averaged Kflows/sec):

|              | Insertion) |   +%   | Deletion |   +%  |
|--------------|:----------:|:------:|:--------:|:-----:|
| baseline     |   6338.7   |        |  9739.6  |       |
| improvements |   6978.8   | +10.1% |  10432.4 | +7.1% |

The basic benchmark was run on ConnectX-6 Dx (22.40.1000), on the system with Intel Xeon Platinum 8380 CPU.

Bing Zhao (2):
net/mlx5: skip the unneeded resource index allocation net/mlx5: remove unneeded device status checking

Dariusz Sosnowski (7):
net/mlx5: allocate local DR rule action buffers
net/mlx5: remove action params from job
net/mlx5: remove flow pattern from job
net/mlx5: remove updated flow from job
net/mlx5: use flow as operation container
net/mlx5: move rarely used flow fields outside
net/mlx5: reuse flow fields

Erez Shitrit (2):
net/mlx5/hws: add check for matcher rule update support net/mlx5/hws: add check if matcher contains complex rules

 drivers/net/mlx5/hws/mlx5dr.h         |  16 +
 drivers/net/mlx5/hws/mlx5dr_action.c  |   6 +
 drivers/net/mlx5/hws/mlx5dr_action.h  |   2 +
 drivers/net/mlx5/hws/mlx5dr_matcher.c |  29 +
 drivers/net/mlx5/mlx5.h               |  29 +-
 drivers/net/mlx5/mlx5_flow.h          | 128 ++++-
 drivers/net/mlx5/mlx5_flow_hw.c       | 794 ++++++++++++++++----------
 7 files changed, 666 insertions(+), 338 deletions(-)

--
2.39.2

#1 lore raw

PATCH 1/11 net/mlx5: allocate local DR rule action buffers

Goal of this is to remove the unnecessary copying of precalculated mlx5dr_rule_action structures used to create HWS flow rules.

Before this patch, during template table creation an array of these structures was calculated for each actions template used. Each of these structures contained either full action definition or partial (depends on mask configuration).
During flow creation, this array was copied to stack and later passed to mlx5dr_rule_create().

This patch removes this copy by implementing the following:

- Allocate an array of mlx5dr_rule_action structures for each actions template and queue.
- Populate them with precalculated data from relevant actions templates.
- During flow creation, construction of unmasked actions works on an array dedicated for the specific queue and actions template.
- Pass this buffer to mlx5dr_rule_create directly.

---
 drivers/net/mlx5/mlx5_flow.h    | 13 +++++++++
 drivers/net/mlx5/mlx5_flow_hw.c | 51 +++++++++++++++++++++++++++++----
 2 files changed, 59 insertions(+), 5 deletions(-)
drivers/net/mlx5/mlx5_flow.h +13 -0
index 1530e6962f..11135645ef 100644
@@ -1554,6 +1554,10 @@ struct mlx5_matcher_info {
 	uint32_t refcnt;
 };
 
+struct mlx5_dr_rule_action_container {
+	struct mlx5dr_rule_action acts[MLX5_HW_MAX_ACTS];
+} __rte_cache_aligned;
+
 struct rte_flow_template_table {
 	LIST_ENTRY(rte_flow_template_table) next;
 	struct mlx5_flow_group *grp; /* The group rte_flow_template_table uses. */
@@ -1573,6 +1577,15 @@ struct rte_flow_template_table {
 	uint32_t refcnt; /* Table reference counter. */
 	struct mlx5_tbl_multi_pattern_ctx mpctx;
 	struct mlx5dr_matcher_attr matcher_attr;
+	/**
+	 * Variable length array of containers containing precalculated templates of DR actions
+	 * arrays. This array is allocated at template table creation time and contains
+	 * one container per each queue, per each actions template.
+	 * Essentially rule_acts is a 2-dimensional array indexed with (AT index, queue) pair.
+	 * Each container will provide a local "queue buffer" to work on for flow creation
+	 * operations when using a given actions template.
+	 */
+	struct mlx5_dr_rule_action_container rule_acts[];
 };
 
 static __rte_always_inline struct mlx5dr_matcher *
drivers/net/mlx5/mlx5_flow_hw.c +46 -5

124 lines not on this page · raw message

Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/11 net/mlx5/hws: add check for matcher rule update support

In reply to Dariusz Sosnowski

From: Erez Shitrit <[email protected]>

The user want to know before trying to update a rule if that matcher that keeps the original rule supports updating.

---
 drivers/net/mlx5/hws/mlx5dr.h         |  8 ++++++++
 drivers/net/mlx5/hws/mlx5dr_matcher.c | 12 ++++++++++++
 2 files changed, 20 insertions(+)
drivers/net/mlx5/hws/mlx5dr.h +8 -0
index d612f300c6..781b11e681 100644
@@ -491,6 +491,14 @@ int mlx5dr_matcher_resize_rule_move(struct mlx5dr_matcher *src_matcher,
 				    struct mlx5dr_rule *rule,
 				    struct mlx5dr_rule_attr *attr);
 
+/* Check matcher ability to update existing rules
+ *
+ * @param[in] matcher
+ *	that the rule belongs to.
+ * @return true when the matcher is updatable false otherwise.
+ */
+bool mlx5dr_matcher_is_updatable(struct mlx5dr_matcher *matcher);
+
 /* Get the size of the rule handle (mlx5dr_rule) to be used on rule creation.
  *
  * @return size in bytes of rule handle struct.
drivers/net/mlx5/hws/mlx5dr_matcher.c +12 -0
index 8a74a1ed7d..4e4da8e8f6 100644
@@ -1530,6 +1530,18 @@ int mlx5dr_match_template_destroy(struct mlx5dr_match_template *mt)
 	return 0;
 }
 
+bool mlx5dr_matcher_is_updatable(struct mlx5dr_matcher *matcher)
+{
+	if (mlx5dr_table_is_root(matcher->tbl) ||
+	    mlx5dr_matcher_req_fw_wqe(matcher) ||
+	    mlx5dr_matcher_is_resizable(matcher) ||
+	    (!matcher->attr.optimize_using_rule_idx &&
+	    !mlx5dr_matcher_is_insert_by_idx(matcher)))
+		return false;
+
+	return true;
+}
+
 static int mlx5dr_matcher_resize_precheck(struct mlx5dr_matcher *src_matcher,
 					  struct mlx5dr_matcher *dst_matcher)
 {
Signature · 1 line
2.39.2
#3 lore raw

PATCH 3/11 net/mlx5/hws: add check if matcher contains complex rules

In reply to Dariusz Sosnowski

From: Erez Shitrit <[email protected]>

The function returns true if that matcher can contain complicated rule, which means rule that needs more than one writing to the HW in order to have it.

---
 drivers/net/mlx5/hws/mlx5dr.h         |  8 ++++++++
 drivers/net/mlx5/hws/mlx5dr_action.c  |  6 ++++++
 drivers/net/mlx5/hws/mlx5dr_action.h  |  2 ++
 drivers/net/mlx5/hws/mlx5dr_matcher.c | 17 +++++++++++++++++
 4 files changed, 33 insertions(+)
drivers/net/mlx5/hws/mlx5dr.h +8 -0
index 781b11e681..d903decc1b 100644
@@ -499,6 +499,14 @@ int mlx5dr_matcher_resize_rule_move(struct mlx5dr_matcher *src_matcher,
  */
 bool mlx5dr_matcher_is_updatable(struct mlx5dr_matcher *matcher);
 
+/* Check matcher if might contain rules that need complex structure
+ *
+ * @param[in] matcher
+ *	that the rule belongs to.
+ * @return true when the matcher is contains such rules, false otherwise.
+ */
+bool mlx5dr_matcher_is_dependent(struct mlx5dr_matcher *matcher);
+
 /* Get the size of the rule handle (mlx5dr_rule) to be used on rule creation.
  *
  * @return size in bytes of rule handle struct.
drivers/net/mlx5/hws/mlx5dr_action.c +6 -0
index 631763dee0..494642d25c 100644
@@ -3265,6 +3265,7 @@ int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
 			setter->flags |= ASF_SINGLE1 | ASF_REMOVE;
 			setter->set_single = &mlx5dr_action_setter_ipv6_route_ext_pop;
 			setter->idx_single = i;
+			at->need_dep_write = true;
 			break;
 
 		case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
@@ -3291,6 +3292,7 @@ int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
 			setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
 			setter->idx_double = i;
 			setter->extra_data = 2;
+			at->need_dep_write = true;
 			break;
 
 		case MLX5DR_ACTION_TYP_MODIFY_HDR:
@@ -3299,6 +3301,7 @@ int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
 			setter->flags |= ASF_DOUBLE | ASF_MODIFY;
 			setter->set_double = &mlx5dr_action_setter_modify_header;
 			setter->idx_double = i;
+			at->need_dep_write = true;
 			break;
 
 		case MLX5DR_ACTION_TYP_ASO_METER:
@@ -3326,6 +3329,7 @@ int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
 			setter->flags |= ASF_DOUBLE | ASF_INSERT;
 			setter->set_double = &mlx5dr_action_setter_insert_ptr;
 			setter->idx_double = i;
+			at->need_dep_write = true;
 			break;
 
 		case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
@@ -3336,6 +3340,7 @@ int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
 			setter->idx_double = i;
 			setter->set_single = &mlx5dr_action_setter_common_decap;
 			setter->idx_single = i;
+			at->need_dep_write = true;
 			break;
 
 		case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
@@ -3344,6 +3349,7 @@ int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
 			setter->flags |= ASF_DOUBLE | ASF_MODIFY | ASF_INSERT;
 			setter->set_double = &mlx5dr_action_setter_tnl_l3_to_l2;
 			setter->idx_double = i;
+			at->need_dep_write = true;
 			break;
 
 		case MLX5DR_ACTION_TYP_TAG:
drivers/net/mlx5/hws/mlx5dr_action.h +2 -0
index 0c8e4bbb5a..68139ca092 100644
@@ -119,6 +119,8 @@ struct mlx5dr_action_template {
 	uint8_t num_of_action_stes;
 	uint8_t num_actions;
 	uint8_t only_term;
+	/* indicates rule might require dependent wqe */
+	bool need_dep_write;
 	uint32_t flags;
 };
 
drivers/net/mlx5/hws/mlx5dr_matcher.c +17 -0
index 4e4da8e8f6..1c64abfa57 100644
@@ -1542,6 +1542,23 @@ bool mlx5dr_matcher_is_updatable(struct mlx5dr_matcher *matcher)
 	return true;
 }
 
+bool mlx5dr_matcher_is_dependent(struct mlx5dr_matcher *matcher)
+{
+	int i;
+
+	if (matcher->action_ste.max_stes || mlx5dr_matcher_req_fw_wqe(matcher))
+		return true;
+
+	for (i = 0; i < matcher->num_of_at; i++) {
+		struct mlx5dr_action_template *at = &matcher->at[i];
+
+		if (at->need_dep_write)
+			return true;
+	}
+
+	return false;
+}
+
 static int mlx5dr_matcher_resize_precheck(struct mlx5dr_matcher *src_matcher,
 					  struct mlx5dr_matcher *dst_matcher)
 {
Signature · 1 line
2.39.2
#4 lore raw

PATCH 4/11 net/mlx5: skip the unneeded resource index allocation

In reply to Dariusz Sosnowski

From: Bing Zhao <[email protected]>

The resource index was introduced to decouple the flow rule and its resources used by hardware steering. This is needed only when a rule update is supported.

In some cases, the update is not supported on a table(matcher). E.g.:
* Table is resizable
* FW gets involved
* Root table
* Not index based or optimized (not applicable)

Or only one STE entry is required per rule. When doing an update, the operation is always atomic. There is no need for the extra resource index either.

If the matcher doesn't support rule update or the maximal entry is only 1 for this matcher, there is no need to manage the resource index allocation and free from the pool.

---
 drivers/net/mlx5/mlx5_flow_hw.c | 129 +++++++++++++++++++-------------
 1 file changed, 76 insertions(+), 53 deletions(-)
drivers/net/mlx5/mlx5_flow_hw.c +76 -53
index 442237f2b6..fcf493c771 100644
@@ -3364,9 +3364,6 @@ flow_hw_async_flow_create(struct rte_eth_dev *dev,
 	flow = mlx5_ipool_zmalloc(table->flow, &flow_idx);
 	if (!flow)
 		goto error;
-	mlx5_ipool_malloc(table->resource, &res_idx);
-	if (!res_idx)
-		goto error;
 	rule_acts = flow_hw_get_dr_action_buffer(priv, table, action_template_index, queue);
 	/*
 	 * Set the table here in order to know the destination table
@@ -3375,7 +3372,14 @@ flow_hw_async_flow_create(struct rte_eth_dev *dev,
 	flow->table = table;
 	flow->mt_idx = pattern_template_index;
 	flow->idx = flow_idx;
-	flow->res_idx = res_idx;
+	if (table->resource) {
+		mlx5_ipool_malloc(table->resource, &res_idx);
+		if (!res_idx)
+			goto error;
+		flow->res_idx = res_idx;
+	} else {
+		flow->res_idx = flow_idx;
+	}
 	/*
 	 * Set the job type here in order to know if the flow memory
 	 * should be freed or not when get the result from dequeue.
@@ -3385,11 +3389,10 @@ flow_hw_async_flow_create(struct rte_eth_dev *dev,
 	job->user_data = user_data;
 	rule_attr.user_data = job;
 	/*
-	 * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices for rule
-	 * insertion hints.
+	 * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices
+	 * for rule insertion hints.
 	 */
-	MLX5_ASSERT(res_idx > 0);
-	flow->rule_idx = res_idx - 1;
+	flow->rule_idx = flow->res_idx - 1;
 	rule_attr.rule_idx = flow->rule_idx;
 	/*
 	 * Construct the flow actions based on the input actions.
@@ -3432,12 +3435,12 @@ flow_hw_async_flow_create(struct rte_eth_dev *dev,
 	if (likely(!ret))
 		return (struct rte_flow *)flow;
 error:
-	if (job)
-		flow_hw_job_put(priv, job, queue);
+	if (table->resource && res_idx)
+		mlx5_ipool_free(table->resource, res_idx);
 	if (flow_idx)
 		mlx5_ipool_free(table->flow, flow_idx);
-	if (res_idx)
-		mlx5_ipool_free(table->resource, res_idx);
+	if (job)
+		flow_hw_job_put(priv, job, queue);
 	rte_flow_error_set(error, rte_errno,
 			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 			   "fail to create rte flow");
@@ -3508,9 +3511,6 @@ flow_hw_async_flow_create_by_index(struct rte_eth_dev *dev,
 	flow = mlx5_ipool_zmalloc(table->flow, &flow_idx);
 	if (!flow)
 		goto error;
-	mlx5_ipool_malloc(table->resource, &res_idx);
-	if (!res_idx)
-		goto error;
 	rule_acts = flow_hw_get_dr_action_buffer(priv, table, action_template_index, queue);
 	/*
 	 * Set the table here in order to know the destination table
@@ -3519,7 +3519,14 @@ flow_hw_async_flow_create_by_index(struct rte_eth_dev *dev,
 	flow->table = table;
 	flow->mt_idx = 0;
 	flow->idx = flow_idx;
-	flow->res_idx = res_idx;
+	if (table->resource) {
+		mlx5_ipool_malloc(table->resource, &res_idx);
+		if (!res_idx)
+			goto error;
+		flow->res_idx = res_idx;
+	} else {
+		flow->res_idx = flow_idx;
+	}
 	/*
 	 * Set the job type here in order to know if the flow memory
 	 * should be freed or not when get the result from dequeue.
@@ -3528,9 +3535,7 @@ flow_hw_async_flow_create_by_index(struct rte_eth_dev *dev,
 	job->flow = flow;
 	job->user_data = user_data;
 	rule_attr.user_data = job;
-	/*
-	 * Set the rule index.
-	 */
+	/* Set the rule index. */
 	flow->rule_idx = rule_index;
 	rule_attr.rule_idx = flow->rule_idx;
 	/*
@@ -3566,12 +3571,12 @@ flow_hw_async_flow_create_by_index(struct rte_eth_dev *dev,
 	if (likely(!ret))
 		return (struct rte_flow *)flow;
 error:
-	if (job)
-		flow_hw_job_put(priv, job, queue);
-	if (res_idx)
+	if (table->resource && res_idx)
 		mlx5_ipool_free(table->resource, res_idx);
 	if (flow_idx)
 		mlx5_ipool_free(table->flow, flow_idx);
+	if (job)
+		flow_hw_job_put(priv, job, queue);
 	rte_flow_error_set(error, rte_errno,
 			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 			   "fail to create rte flow");
@@ -3634,9 +3639,6 @@ flow_hw_async_flow_update(struct rte_eth_dev *dev,
 		rte_errno = ENOMEM;
 		goto error;
 	}
-	mlx5_ipool_malloc(table->resource, &res_idx);
-	if (!res_idx)
-		goto error;
 	nf = job->upd_flow;
 	memset(nf, 0, sizeof(struct rte_flow_hw));
 	rule_acts = flow_hw_get_dr_action_buffer(priv, table, action_template_index, queue);
@@ -3647,7 +3649,14 @@ flow_hw_async_flow_update(struct rte_eth_dev *dev,
 	nf->table = table;
 	nf->mt_idx = of->mt_idx;
 	nf->idx = of->idx;
-	nf->res_idx = res_idx;
+	if (table->resource) {
+		mlx5_ipool_malloc(table->resource, &res_idx);
+		if (!res_idx)
+			goto error;
+		nf->res_idx = res_idx;
+	} else {
+		nf->res_idx = of->res_idx;
+	}
 	/*
 	 * Set the job type here in order to know if the flow memory
 	 * should be freed or not when get the result from dequeue.
@@ -3657,11 +3666,11 @@ flow_hw_async_flow_update(struct rte_eth_dev *dev,
 	job->user_data = user_data;
 	rule_attr.user_data = job;
 	/*
-	 * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices for rule
-	 * insertion hints.
+	 * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices
+	 * for rule insertion hints.
+	 * If there is only one STE, the update will be atomic by nature.
 	 */
-	MLX5_ASSERT(res_idx > 0);
-	nf->rule_idx = res_idx - 1;
+	nf->rule_idx = nf->res_idx - 1;
 	rule_attr.rule_idx = nf->rule_idx;
 	/*
 	 * Construct the flow actions based on the input actions.
@@ -3687,14 +3696,14 @@ flow_hw_async_flow_update(struct rte_eth_dev *dev,
 	if (likely(!ret))
 		return 0;
 error:
+	if (table->resource && res_idx)
+		mlx5_ipool_free(table->resource, res_idx);
 	/* Flow created fail, return the descriptor and flow memory. */
 	if (job)
 		flow_hw_job_put(priv, job, queue);
-	if (res_idx)
-		mlx5_ipool_free(table->resource, res_idx);
 	return rte_flow_error_set(error, rte_errno,
-			RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
-			"fail to update rte flow");
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+				  "fail to update rte flow");
 }
 
 /**
@@ -3949,13 +3958,15 @@ hw_cmpl_flow_update_or_destroy(struct rte_eth_dev *dev,
 	}
 	if (job->type != MLX5_HW_Q_JOB_TYPE_UPDATE) {
 		if (table) {
-			mlx5_ipool_free(table->resource, res_idx);
+			if (table->resource)
+				mlx5_ipool_free(table->resource, res_idx);
 			mlx5_ipool_free(table->flow, flow->idx);
 		}
 	} else {
 		rte_memcpy(flow, job->upd_flow,
 			   offsetof(struct rte_flow_hw, rule));
-		mlx5_ipool_free(table->resource, res_idx);
+		if (table->resource)
+			mlx5_ipool_free(table->resource, res_idx);
 	}
 }
 
@@ -4455,6 +4466,7 @@ flow_hw_table_create(struct rte_eth_dev *dev,
 	uint32_t i = 0, max_tpl = MLX5_HW_TBL_MAX_ITEM_TEMPLATE;
 	uint32_t nb_flows = rte_align32pow2(attr->nb_flows);
 	bool port_started = !!dev->data->dev_started;
+	bool rpool_needed;
 	size_t tbl_mem_size;
 	int err;
 
@@ -4492,13 +4504,6 @@ flow_hw_table_create(struct rte_eth_dev *dev,
 	tbl->flow = mlx5_ipool_create(&cfg);
 	if (!tbl->flow)
 		goto error;
-	/* Allocate rule indexed pool. */
-	cfg.size = 0;
-	cfg.type = "mlx5_hw_table_rule";
-	cfg.max_idx += priv->hw_q[0].size;
-	tbl->resource = mlx5_ipool_create(&cfg);
-	if (!tbl->resource)
-		goto error;
 	/* Register the flow group. */
 	ge = mlx5_hlist_register(priv->sh->groups, attr->flow_attr.group, &ctx);
 	if (!ge)
@@ -4578,12 +4583,30 @@ flow_hw_table_create(struct rte_eth_dev *dev,
 	tbl->type = attr->flow_attr.transfer ? MLX5DR_TABLE_TYPE_FDB :
 		    (attr->flow_attr.egress ? MLX5DR_TABLE_TYPE_NIC_TX :
 		    MLX5DR_TABLE_TYPE_NIC_RX);
+	/*
+	 * Only the matcher supports update and needs more than 1 WQE, an additional
+	 * index is needed. Or else the flow index can be reused.
+	 */
+	rpool_needed = mlx5dr_matcher_is_updatable(tbl->matcher_info[0].matcher) &&
+		       mlx5dr_matcher_is_dependent(tbl->matcher_info[0].matcher);
+	if (rpool_needed) {
+		/* Allocate rule indexed pool. */
+		cfg.size = 0;
+		cfg.type = "mlx5_hw_table_rule";
+		cfg.max_idx += priv->hw_q[0].size;
+		tbl->resource = mlx5_ipool_create(&cfg);
+		if (!tbl->resource)
+			goto res_error;
+	}
 	if (port_started)
 		LIST_INSERT_HEAD(&priv->flow_hw_tbl, tbl, next);
 	else
 		LIST_INSERT_HEAD(&priv->flow_hw_tbl_ongo, tbl, next);
 	rte_rwlock_init(&tbl->matcher_replace_rwlk);
 	return tbl;
+res_error:
+	if (tbl->matcher_info[0].matcher)
+		(void)mlx5dr_matcher_destroy(tbl->matcher_info[0].matcher);
 at_error:
 	for (i = 0; i < nb_action_templates; i++) {
 		__flow_hw_action_template_destroy(dev, &tbl->ats[i].acts);
@@ -4601,8 +4624,6 @@ flow_hw_table_create(struct rte_eth_dev *dev,
 		if (tbl->grp)
 			mlx5_hlist_unregister(priv->sh->groups,
 					      &tbl->grp->entry);
-		if (tbl->resource)
-			mlx5_ipool_destroy(tbl->resource);
 		if (tbl->flow)
 			mlx5_ipool_destroy(tbl->flow);
 		mlx5_free(tbl);
@@ -4811,12 +4832,13 @@ flow_hw_table_destroy(struct rte_eth_dev *dev,
 	uint32_t ridx = 1;
 
 	/* Build ipool allocated object bitmap. */
-	mlx5_ipool_flush_cache(table->resource);
+	if (table->resource)
+		mlx5_ipool_flush_cache(table->resource);
 	mlx5_ipool_flush_cache(table->flow);
 	/* Check if ipool has allocated objects. */
 	if (table->refcnt ||
 	    mlx5_ipool_get_next(table->flow, &fidx) ||
-	    mlx5_ipool_get_next(table->resource, &ridx)) {
+	    (table->resource && mlx5_ipool_get_next(table->resource, &ridx))) {
 		DRV_LOG(WARNING, "Table %p is still in use.", (void *)table);
 		return rte_flow_error_set(error, EBUSY,
 				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
@@ -4838,7 +4860,8 @@ flow_hw_table_destroy(struct rte_eth_dev *dev,
 	if (table->matcher_info[1].matcher)
 		mlx5dr_matcher_destroy(table->matcher_info[1].matcher);
 	mlx5_hlist_unregister(priv->sh->groups, &table->grp->entry);
-	mlx5_ipool_destroy(table->resource);
+	if (table->resource)
+		mlx5_ipool_destroy(table->resource);
 	mlx5_ipool_destroy(table->flow);
 	mlx5_free(table);
 	return 0;
@@ -12340,11 +12363,11 @@ flow_hw_table_resize(struct rte_eth_dev *dev,
 		return rte_flow_error_set(error, EINVAL,
 					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 					  table, "cannot resize flows pool");
-	ret = mlx5_ipool_resize(table->resource, nb_flows);
-	if (ret)
-		return rte_flow_error_set(error, EINVAL,
-					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
-					  table, "cannot resize resources pool");
+	/*
+	 * A resizable matcher doesn't support rule update. In this case, the ipool
+	 * for the resource is not created and there is no need to resize it.
+	 */
+	MLX5_ASSERT(!table->resource);
 	if (mlx5_is_multi_pattern_active(&table->mpctx)) {
 		ret = flow_hw_table_resize_multi_pattern_actions(dev, table, nb_flows, error);
 		if (ret < 0)
Signature · 1 line
2.39.2
#5 lore raw

PATCH 5/11 net/mlx5: remove action params from job

In reply to Dariusz Sosnowski

mlx5_hw_q_job struct held references to buffers which contained:

- modify header commands array,
- encap/decap data buffer,
- IPv6 routing data buffer.

These buffers were passed as parameters to HWS layer during rule creation. They were needed only during the call to HWS layer when flow operation is enqueues (i.e. mlx5dr_rule_create()). After operation is enqueued, data stored there can be safely discarded and it is not required to store it during the whole lifecycle of a job.

This patch removes references to these buffers from mlx5_hw_q_job and removes relevant allocations to reduce job memory footprint. Buffers stored per job are replaced with stack allocated ones, contained in mlx5_flow_hw_action_params struct.

---
 drivers/net/mlx5/mlx5.h         |   3 -
 drivers/net/mlx5/mlx5_flow.h    |  10 +++
 drivers/net/mlx5/mlx5_flow_hw.c | 120 ++++++++++++++------------------
 3 files changed, 63 insertions(+), 70 deletions(-)
drivers/net/mlx5/mlx5.h +0 -3
index bb1853e797..bd0846d6bf 100644
@@ -401,9 +401,6 @@ struct mlx5_hw_q_job {
 		const void *action; /* Indirect action attached to the job. */
 	};
 	void *user_data; /* Job user data. */
-	uint8_t *encap_data; /* Encap data. */
-	uint8_t *push_data; /* IPv6 routing push data. */
-	struct mlx5_modification_cmd *mhdr_cmd;
 	struct rte_flow_item *items;
 	union {
 		struct {
drivers/net/mlx5/mlx5_flow.h +10 -0
index 11135645ef..df1c913017 100644
@@ -1294,6 +1294,16 @@ typedef int
 
 #define MLX5_MHDR_MAX_CMD ((MLX5_MAX_MODIFY_NUM) * 2 + 1)
 
+/** Container for flow action data constructed during flow rule creation. */
+struct mlx5_flow_hw_action_params {
+	/** Array of constructed modify header commands. */
+	struct mlx5_modification_cmd mhdr_cmd[MLX5_MHDR_MAX_CMD];
+	/** Constructed encap/decap data buffer. */
+	uint8_t encap_data[MLX5_ENCAP_MAX_LEN];
+	/** Constructed IPv6 routing data buffer. */
+	uint8_t ipv6_push_data[MLX5_PUSH_MAX_LEN];
+};
+
 /* rte flow action translate to DR action struct. */
 struct mlx5_action_construct_data {
 	LIST_ENTRY(mlx5_action_construct_data) next;
drivers/net/mlx5/mlx5_flow_hw.c +53 -67

359 lines not on this page · raw message

Signature · 1 line
2.39.2
#6 lore raw

PATCH 6/11 net/mlx5: remove flow pattern from job

In reply to Dariusz Sosnowski

mlx5_hw_q_job struct held a reference to temporary flow rule pattern and contained temporary REPRESENTED_PORT and TAG items structs. They are used whenever it is required to prepend a flow rule pattern, provided by the application with one of such items.
If prepending is required, then flow rule pattern is copied over to temporary buffer and a new item added internally in PMD. Such constructed buffer is passed to the HWS layer when flow create operation is being enqueued.
After operation is enqueued, temporary flow pattern can be safely discarded, so there is no need to store it during
the whole lifecycle of mlx5_hw_q_job.

This patch removes all references to flow rule pattern and items stored inside mlx5_hw_q_job and removes relevant allocations to reduce job memory footprint.
Temporary pattern and items stored per job are replaced with stack allocated ones, contained in mlx5_flow_hw_pattern_params struct.

---
 drivers/net/mlx5/mlx5.h         | 17 ++++-------
 drivers/net/mlx5/mlx5_flow.h    | 10 +++++++
 drivers/net/mlx5/mlx5_flow_hw.c | 51 ++++++++++++++-------------------
 3 files changed, 37 insertions(+), 41 deletions(-)
drivers/net/mlx5/mlx5.h +6 -11
index bd0846d6bf..fc3d28e6f2 100644
@@ -401,17 +401,12 @@ struct mlx5_hw_q_job {
 		const void *action; /* Indirect action attached to the job. */
 	};
 	void *user_data; /* Job user data. */
-	struct rte_flow_item *items;
-	union {
-		struct {
-			/* User memory for query output */
-			void *user;
-			/* Data extracted from hardware */
-			void *hw;
-		} __rte_packed query;
-		struct rte_flow_item_ethdev port_spec;
-		struct rte_flow_item_tag tag_spec;
-	} __rte_packed;
+	struct {
+		/* User memory for query output */
+		void *user;
+		/* Data extracted from hardware */
+		void *hw;
+	} query;
 	struct rte_flow_hw *upd_flow; /* Flow with updated values. */
 };
 
drivers/net/mlx5/mlx5_flow.h +10 -0
index df1c913017..96b43ce61e 100644
@@ -1304,6 +1304,16 @@ struct mlx5_flow_hw_action_params {
 	uint8_t ipv6_push_data[MLX5_PUSH_MAX_LEN];
 };
 
+/** Container for dynamically generated flow items used during flow rule creation. */
+struct mlx5_flow_hw_pattern_params {
+	/** Array of dynamically generated flow items. */
+	struct rte_flow_item items[MLX5_HW_MAX_ITEMS];
+	/** Temporary REPRESENTED_PORT item generated by PMD. */
+	struct rte_flow_item_ethdev port_spec;
+	/** Temporary TAG item generated by PMD. */
+	struct rte_flow_item_tag tag_spec;
+};
+
 /* rte flow action translate to DR action struct. */
 struct mlx5_action_construct_data {
 	LIST_ENTRY(mlx5_action_construct_data) next;
drivers/net/mlx5/mlx5_flow_hw.c +21 -30

122 lines not on this page · raw message

Signature · 1 line
2.39.2
#7 lore raw

PATCH 7/11 net/mlx5: remove updated flow from job

In reply to Dariusz Sosnowski

mlx5_hw_q_job struct held a reference to a temporary flow rule struct, used during flow rule update operation. It serves as a container for flow actions data calculated during actions construction. After flow rule update operation succeeds, data from temporary flow rule is copied over to original flow rule.

Although access to this temporary flow rule struct is required during both operation enqueue step and completion polling step, there can be only one ongoing flow update operation for a given flow rule. As a result there is no need to store it per job.

This patch removes all references to temporary flow rule struct stored in mlx5_hw_q_job and removes relevant allocations to reduce job memory footprint.
Temporary flow rule struct stored per job is replaced with:

- If table is not resizable - An array of rte_flow_hw_aux structs, stored in template table. This array holds one entry per each flow rule, each containing a single mentioned temporary struct.
- If table is resizable - Additional rte_flow_hw_aux struct, allocated alongside rte_flow_hw in resizable ipool.

---
 drivers/net/mlx5/mlx5.h         |   1 -
 drivers/net/mlx5/mlx5_flow.h    |   7 +++
 drivers/net/mlx5/mlx5_flow_hw.c | 100 ++++++++++++++++++++++++++------
 3 files changed, 89 insertions(+), 19 deletions(-)
drivers/net/mlx5/mlx5.h +0 -1
index fc3d28e6f2..0cc32bf67b 100644
@@ -407,7 +407,6 @@ struct mlx5_hw_q_job {
 		/* Data extracted from hardware */
 		void *hw;
 	} query;
-	struct rte_flow_hw *upd_flow; /* Flow with updated values. */
 };
 
 /* HW steering job descriptor LIFO pool. */
drivers/net/mlx5/mlx5_flow.h +7 -0
index 96b43ce61e..8fd07bdce4 100644
@@ -1281,6 +1281,12 @@ struct rte_flow_hw {
 	uint8_t rule[]; /* HWS layer data struct. */
 } __rte_packed;
 
+/** Auxiliary data stored per flow which is not required to be stored in main flow structure. */
+struct rte_flow_hw_aux {
+	/** Placeholder flow struct used during flow rule update operation. */
+	struct rte_flow_hw upd_flow;
+};
+
 #ifdef PEDANTIC
 #pragma GCC diagnostic error "-Wpedantic"
 #endif
@@ -1589,6 +1595,7 @@ struct rte_flow_template_table {
 	/* Action templates bind to the table. */
 	struct mlx5_hw_action_template ats[MLX5_HW_TBL_MAX_ACTION_TEMPLATE];
 	struct mlx5_indexed_pool *flow; /* The table's flow ipool. */
+	struct rte_flow_hw_aux *flow_aux; /**< Auxiliary data stored per flow. */
 	struct mlx5_indexed_pool *resource; /* The table's resource ipool. */
 	struct mlx5_flow_template_table_cfg cfg;
 	uint32_t type; /* Flow table type RX/TX/FDB. */
drivers/net/mlx5/mlx5_flow_hw.c +82 -18

182 lines not on this page · raw message

Signature · 1 line
2.39.2
#8 lore raw

PATCH 8/11 net/mlx5: use flow as operation container

In reply to Dariusz Sosnowski

While processing async flow operations in mlx5 PMD, mlx5_hw_q_job struct is used to hold the following data related to the ongoing operation.

- operation type,
- user data,
- flow reference.

Job itself is then passed to mlx5dr layer as its "user data". Other types of data required during flow operation processing are accessed through the flow itself.

Since most of the accessed fields are in the flow struct itself, the operation type and user data can be moved to the flow struct. This removes unnecessary memory indirection and reduces memory footprint of flow operations processing. It decreases cache stress and as a result can increase processing throughput.

This patch removes the mlx5_hw_q_job from async flow operations processing and from now on the flow itself can represent the ongoing operation. Async operations on indirect actions still use jobs.

---
 drivers/net/mlx5/mlx5.h         |   8 +-
 drivers/net/mlx5/mlx5_flow.h    |  13 ++
 drivers/net/mlx5/mlx5_flow_hw.c | 210 +++++++++++++++-----------------
 3 files changed, 116 insertions(+), 115 deletions(-)
drivers/net/mlx5/mlx5.h +3 -5
index 0cc32bf67b..4362efb02f 100644
@@ -396,10 +396,7 @@ enum mlx5_hw_indirect_type {
 struct mlx5_hw_q_job {
 	uint32_t type; /* Job type. */
 	uint32_t indirect_type;
-	union {
-		struct rte_flow_hw *flow; /* Flow attached to the job. */
-		const void *action; /* Indirect action attached to the job. */
-	};
+	const void *action; /* Indirect action attached to the job. */
 	void *user_data; /* Job user data. */
 	struct {
 		/* User memory for query output */
@@ -412,7 +409,8 @@ struct mlx5_hw_q_job {
 /* HW steering job descriptor LIFO pool. */
 struct mlx5_hw_q {
 	uint32_t job_idx; /* Free job index. */
-	uint32_t size; /* LIFO size. */
+	uint32_t size; /* Job LIFO queue size. */
+	uint32_t ongoing_flow_ops; /* Number of ongoing flow operations. */
 	struct mlx5_hw_q_job **job; /* LIFO header. */
 	struct rte_ring *indir_cq; /* Indirect action SW completion queue. */
 	struct rte_ring *indir_iq; /* Indirect action SW in progress queue. */
drivers/net/mlx5/mlx5_flow.h +13 -0
index 8fd07bdce4..2e3e7d0533 100644
@@ -1257,6 +1257,16 @@ typedef uint32_t cnt_id_t;
 
 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
 
+enum {
+	MLX5_FLOW_HW_FLOW_OP_TYPE_NONE,
+	MLX5_FLOW_HW_FLOW_OP_TYPE_CREATE,
+	MLX5_FLOW_HW_FLOW_OP_TYPE_DESTROY,
+	MLX5_FLOW_HW_FLOW_OP_TYPE_UPDATE,
+	MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_CREATE,
+	MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_DESTROY,
+	MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_MOVE,
+};
+
 #ifdef PEDANTIC
 #pragma GCC diagnostic ignored "-Wpedantic"
 #endif
@@ -1278,6 +1288,9 @@ struct rte_flow_hw {
 	cnt_id_t cnt_id;
 	uint32_t mtr_id;
 	uint32_t rule_idx;
+	uint8_t operation_type; /**< Ongoing flow operation type. */
+	void *user_data; /**< Application's private data passed to enqueued flow operation. */
+	uint8_t padding[1]; /**< Padding for proper alignment of mlx5dr rule struct. */
 	uint8_t rule[]; /* HWS layer data struct. */
 } __rte_packed;
 
drivers/net/mlx5/mlx5_flow_hw.c +100 -110

438 lines not on this page · raw message

Signature · 1 line
2.39.2
#9 lore raw

PATCH 9/11 net/mlx5: move rarely used flow fields outside

In reply to Dariusz Sosnowski

Some of the flow fields are either not always required or are used very rarely, e.g.:

- AGE action reference,
- direct METER/METER_MARK action reference,
- matcher selector for resizable tables.

This patch moves these fields to rte_flow_hw_aux struct in order to reduce the overall size of the flow struct, reducing the total size of working set for most common use cases.
This results in reduction of the frequency of cache invalidation during async flow operations processing.

---
 drivers/net/mlx5/mlx5_flow.h    |  61 +++++++++++-----
 drivers/net/mlx5/mlx5_flow_hw.c | 121 ++++++++++++++++++++++++--------
 2 files changed, 138 insertions(+), 44 deletions(-)
drivers/net/mlx5/mlx5_flow.h +45 -16
index 2e3e7d0533..1c67d8dd35 100644
@@ -1271,31 +1271,60 @@ enum {
 #pragma GCC diagnostic ignored "-Wpedantic"
 #endif
 
-/* HWS flow struct. */
+/** HWS flow struct. */
 struct rte_flow_hw {
-	uint32_t idx; /* Flow index from indexed pool. */
-	uint32_t res_idx; /* Resource index from indexed pool. */
-	uint32_t fate_type; /* Fate action type. */
+	/** The table flow allcated from. */
+	struct rte_flow_template_table *table;
+	/** Application's private data passed to enqueued flow operation. */
+	void *user_data;
+	/** Flow index from indexed pool. */
+	uint32_t idx;
+	/** Resource index from indexed pool. */
+	uint32_t res_idx;
+	/** HWS flow rule index passed to mlx5dr. */
+	uint32_t rule_idx;
+	/** Fate action type. */
+	uint32_t fate_type;
+	/** Ongoing flow operation type. */
+	uint8_t operation_type;
+	/** Index of pattern template this flow is based on. */
+	uint8_t mt_idx;
+
+	/** COUNT action index. */
+	cnt_id_t cnt_id;
 	union {
-		/* Jump action. */
+		/** Jump action. */
 		struct mlx5_hw_jump_action *jump;
-		struct mlx5_hrxq *hrxq; /* TIR action. */
+		/** TIR action. */
+		struct mlx5_hrxq *hrxq;
 	};
-	struct rte_flow_template_table *table; /* The table flow allcated from. */
-	uint8_t mt_idx;
-	uint8_t matcher_selector:1;
+
+	/**
+	 * Padding for alignment to 56 bytes.
+	 * Since mlx5dr rule is 72 bytes, whole flow is contained within 128 B (2 cache lines).
+	 * This space is reserved for future additions to flow struct.
+	 */
+	uint8_t padding[10];
+	/** HWS layer data struct. */
+	uint8_t rule[];
+} __rte_packed;
+
+/** Auxiliary data fields that are updatable. */
+struct rte_flow_hw_aux_fields {
+	/** AGE action index. */
 	uint32_t age_idx;
-	cnt_id_t cnt_id;
+	/** Direct meter (METER or METER_MARK) action index. */
 	uint32_t mtr_id;
-	uint32_t rule_idx;
-	uint8_t operation_type; /**< Ongoing flow operation type. */
-	void *user_data; /**< Application's private data passed to enqueued flow operation. */
-	uint8_t padding[1]; /**< Padding for proper alignment of mlx5dr rule struct. */
-	uint8_t rule[]; /* HWS layer data struct. */
-} __rte_packed;
+};
 
 /** Auxiliary data stored per flow which is not required to be stored in main flow structure. */
 struct rte_flow_hw_aux {
+	/** Auxiliary fields associated with the original flow. */
+	struct rte_flow_hw_aux_fields orig;
+	/** Auxiliary fields associated with the updated flow. */
+	struct rte_flow_hw_aux_fields upd;
+	/** Index of resizable matcher associated with this flow. */
+	uint8_t matcher_selector;
 	/** Placeholder flow struct used during flow rule update operation. */
 	struct rte_flow_hw upd_flow;
 };
drivers/net/mlx5/mlx5_flow_hw.c +93 -28

295 lines not on this page · raw message

Signature · 1 line
2.39.2
#10 lore raw

PATCH 10/11 net/mlx5: reuse flow fields

In reply to Dariusz Sosnowski

Each time a flow is allocated in mlx5 PMD the whole buffer, both rte_flow_hw and mlx5dr_rule parts, are zeroed. This introduces some wasted work because:

- mlx5dr layer does not assume that mlx5dr_rule must be initialized,
- flow action translation in mlx5 PMD does not need most of the fields of rte_flow_hw to be zeroed.

To reduce this wasted work, this patch introduces flags field to flow definition. Each flow field which is not always initialized during flow creation, will have a correspondent flag set if value is valid (in other words - it was set during flow creation). Utilizing this mechanism allows PMD to:

- remove zeroing from flow allocation,
- access some fields (especially from rte_flow_hw_aux) if and only if corresponding flag is set.

---
 drivers/net/mlx5/mlx5_flow.h    | 24 ++++++++-
 drivers/net/mlx5/mlx5_flow_hw.c | 93 +++++++++++++++++++++------------
 2 files changed, 83 insertions(+), 34 deletions(-)
drivers/net/mlx5/mlx5_flow.h +22 -2
index 1c67d8dd35..a01e970d04 100644
@@ -1267,6 +1267,26 @@ enum {
 	MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_MOVE,
 };
 
+enum {
+	MLX5_FLOW_HW_FLOW_FLAG_CNT_ID = RTE_BIT32(0),
+	MLX5_FLOW_HW_FLOW_FLAG_FATE_JUMP = RTE_BIT32(1),
+	MLX5_FLOW_HW_FLOW_FLAG_FATE_HRXQ = RTE_BIT32(2),
+	MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX = RTE_BIT32(3),
+	MLX5_FLOW_HW_FLOW_FLAG_MTR_ID = RTE_BIT32(4),
+	MLX5_FLOW_HW_FLOW_FLAG_MATCHER_SELECTOR = RTE_BIT32(5),
+	MLX5_FLOW_HW_FLOW_FLAG_UPD_FLOW = RTE_BIT32(6),
+};
+
+#define MLX5_FLOW_HW_FLOW_FLAGS_ALL ( \
+		MLX5_FLOW_HW_FLOW_FLAG_CNT_ID | \
+		MLX5_FLOW_HW_FLOW_FLAG_FATE_JUMP | \
+		MLX5_FLOW_HW_FLOW_FLAG_FATE_HRXQ | \
+		MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX | \
+		MLX5_FLOW_HW_FLOW_FLAG_MTR_ID | \
+		MLX5_FLOW_HW_FLOW_FLAG_MATCHER_SELECTOR | \
+		MLX5_FLOW_HW_FLOW_FLAG_UPD_FLOW \
+	)
+
 #ifdef PEDANTIC
 #pragma GCC diagnostic ignored "-Wpedantic"
 #endif
@@ -1283,8 +1303,8 @@ struct rte_flow_hw {
 	uint32_t res_idx;
 	/** HWS flow rule index passed to mlx5dr. */
 	uint32_t rule_idx;
-	/** Fate action type. */
-	uint32_t fate_type;
+	/** Which flow fields (inline or in auxiliary struct) are used. */
+	uint32_t flags;
 	/** Ongoing flow operation type. */
 	uint8_t operation_type;
 	/** Index of pattern template this flow is based on. */
drivers/net/mlx5/mlx5_flow_hw.c +61 -32

273 lines not on this page · raw message

Signature · 1 line
2.39.2
#11 lore raw

PATCH 11/11 net/mlx5: remove unneeded device status checking

In reply to Dariusz Sosnowski

From: Bing Zhao <[email protected]>

The flow rule can be inserted even before the device started. The only exception is for a queue or RSS action.

For the other interfaces of template API, the start status is not checked. The checking would cause some cache miss or eviction since the flag locates on some other cache line.

Fixes f1fecffa88df ("net/mlx5: support Direct Rules action template API")
---
 drivers/net/mlx5/mlx5_flow_hw.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/net/mlx5/mlx5_flow_hw.c +0 -5
index 4e4beb4428..8481a9b7f0 100644
@@ -3501,11 +3501,6 @@ flow_hw_async_flow_create(struct rte_eth_dev *dev,
 	uint32_t res_idx = 0;
 	int ret;
 
-	if (unlikely((!dev->data->dev_started))) {
-		rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
-				   "Port must be started before enqueueing flow operations");
-		return NULL;
-	}
 	flow = mlx5_ipool_malloc(table->flow, &flow_idx);
 	if (!flow)
 		goto error;
Signature · 1 line
2.39.2
#12 lore raw
In reply to Dariusz Sosnowski

Hi Dariusz,

Quoted 58 lines

-----Original Message-----
From: Dariusz Sosnowski <[email protected]>
Sent: Wednesday, February 28, 2024 7:01 PM

Goal of this patchset is to improve the throughput of flow insertion and deletion in mlx5 PMD when HW Steering flow engine is used.

- Patch 1 - Use preallocated per-queue, per-actions template buffer for storing translated flow actions, instead of allocating and filling it on demand, on each flow operation.
- Patches 2-4 - Make resource index allocation optional. This allocation will be skipped when it is not required by the created template table.
- Patches 5-7 - Reduce memory footprint of the internal flow queue.
- Patch 8 - Remove indirection between flow job and flow itself, by using flow as an operation container.
- Patches 9-10 - Reduce memory footpring of flow struct by moving rarely used flow fields outside of the main flow struct. These fields will accesses only when needed.
Also remove unneeded zmalloc usage.
- Patch 11 - Remove unneeded device status check in flow create.

In general all of these changes result in the following improvements (all numbers are averaged Kflows/sec):

|              | Insertion) |   +%   | Deletion |   +%  |
|--------------|:----------:|:------:|:--------:|:-----:|
| baseline     |   6338.7   |        |  9739.6  |       |
| improvements |   6978.8   | +10.1% |  10432.4 | +7.1% |

The basic benchmark was run on ConnectX-6 Dx (22.40.1000), on the system with Intel Xeon Platinum 8380 CPU.

Bing Zhao (2):
net/mlx5: skip the unneeded resource index allocation net/mlx5: remove unneeded device status checking

Dariusz Sosnowski (7):
net/mlx5: allocate local DR rule action buffers
net/mlx5: remove action params from job
net/mlx5: remove flow pattern from job
net/mlx5: remove updated flow from job
net/mlx5: use flow as operation container
net/mlx5: move rarely used flow fields outside
net/mlx5: reuse flow fields

Erez Shitrit (2):
net/mlx5/hws: add check for matcher rule update support net/mlx5/hws: add check if matcher contains complex rules

 drivers/net/mlx5/hws/mlx5dr.h         |  16 +
 drivers/net/mlx5/hws/mlx5dr_action.c  |   6 +
 drivers/net/mlx5/hws/mlx5dr_action.h  |   2 +
 drivers/net/mlx5/hws/mlx5dr_matcher.c |  29 +
 drivers/net/mlx5/mlx5.h               |  29 +-
 drivers/net/mlx5/mlx5_flow.h          | 128 ++++-
 drivers/net/mlx5/mlx5_flow_hw.c       | 794 ++++++++++++++++----------
 7 files changed, 666 insertions(+), 338 deletions(-)
Quoted 2 lines

--
2.39.2

Best,
Ori

#13 lore raw

v2 cover net/mlx5: flow insertion performance improvements

In reply to Dariusz Sosnowski

Goal of this patchset is to improve the throughput of flow insertion and deletion in mlx5 PMD when HW Steering flow engine is used.

- Patch 1 - Use preallocated per-queue, per-actions template buffer for storing translated flow actions, instead of allocating and filling it on demand, on each flow operation.
- Patches 2-4 - Make resource index allocation optional. This allocation will be skipped when it is not required by the created template table.
- Patches 5-7 - Reduce memory footprint of the internal flow queue.
- Patch 8 - Remove indirection between flow job and flow itself, by using flow as an operation container.
- Patches 9-10 - Reduce memory footpring of flow struct by moving rarely used flow fields outside of the main flow struct. These fields will accesses only when needed.
Also remove unneeded zmalloc usage.
- Patch 11 - Remove unneeded device status check in flow create.

In general all of these changes result in the following improvements (all numbers are averaged Kflows/sec):

|              | Insertion) |   +%   | Deletion |   +%  |
|--------------|:----------:|:------:|:--------:|:-----:|
| baseline     |   6338.7   |        |  9739.6  |       |
| improvements |   6978.8   | +10.1% |  10432.4 | +7.1% |

The basic benchmark was run on ConnectX-6 Dx (22.40.1000), on the system with Intel Xeon Platinum 8380 CPU.

v2:

- Rebased.
- Applied Acked-by tags from previous version.

Bing Zhao (2):
net/mlx5: skip the unneeded resource index allocation net/mlx5: remove unneeded device status checking

Dariusz Sosnowski (7):
net/mlx5: allocate local DR rule action buffers
net/mlx5: remove action params from job
net/mlx5: remove flow pattern from job
net/mlx5: remove updated flow from job
net/mlx5: use flow as operation container
net/mlx5: move rarely used flow fields outside
net/mlx5: reuse flow fields

Erez Shitrit (2):
net/mlx5/hws: add check for matcher rule update support net/mlx5/hws: add check if matcher contains complex rules

 drivers/net/mlx5/hws/mlx5dr.h         |  16 +
 drivers/net/mlx5/hws/mlx5dr_action.c  |   6 +
 drivers/net/mlx5/hws/mlx5dr_action.h  |   2 +
 drivers/net/mlx5/hws/mlx5dr_matcher.c |  29 +
 drivers/net/mlx5/mlx5.h               |  29 +-
 drivers/net/mlx5/mlx5_flow.h          | 128 ++++-
 drivers/net/mlx5/mlx5_flow_hw.c       | 794 ++++++++++++++++----------
 7 files changed, 666 insertions(+), 338 deletions(-)

--
2.39.2

#14 lore raw

PATCH v2 1/11 net/mlx5: allocate local DR rule action buffers

Goal of this is to remove the unnecessary copying of precalculated mlx5dr_rule_action structures used to create HWS flow rules.

Before this patch, during template table creation an array of these structures was calculated for each actions template used. Each of these structures contained either full action definition or partial (depends on mask configuration).
During flow creation, this array was copied to stack and later passed to mlx5dr_rule_create().

This patch removes this copy by implementing the following:

- Allocate an array of mlx5dr_rule_action structures for each actions template and queue.
- Populate them with precalculated data from relevant actions templates.
- During flow creation, construction of unmasked actions works on an array dedicated for the specific queue and actions template.
- Pass this buffer to mlx5dr_rule_create directly.

---
 drivers/net/mlx5/mlx5_flow.h    | 13 +++++++++
 drivers/net/mlx5/mlx5_flow_hw.c | 51 +++++++++++++++++++++++++++++----
 2 files changed, 59 insertions(+), 5 deletions(-)
drivers/net/mlx5/mlx5_flow.h +13 -0
index 7aa24f7c52..02af0a08fa 100644
@@ -1566,6 +1566,10 @@ struct mlx5_matcher_info {
 	uint32_t refcnt;
 };
 
+struct mlx5_dr_rule_action_container {
+	struct mlx5dr_rule_action acts[MLX5_HW_MAX_ACTS];
+} __rte_cache_aligned;
+
 struct rte_flow_template_table {
 	LIST_ENTRY(rte_flow_template_table) next;
 	struct mlx5_flow_group *grp; /* The group rte_flow_template_table uses. */
@@ -1585,6 +1589,15 @@ struct rte_flow_template_table {
 	uint32_t refcnt; /* Table reference counter. */
 	struct mlx5_tbl_multi_pattern_ctx mpctx;
 	struct mlx5dr_matcher_attr matcher_attr;
+	/**
+	 * Variable length array of containers containing precalculated templates of DR actions
+	 * arrays. This array is allocated at template table creation time and contains
+	 * one container per each queue, per each actions template.
+	 * Essentially rule_acts is a 2-dimensional array indexed with (AT index, queue) pair.
+	 * Each container will provide a local "queue buffer" to work on for flow creation
+	 * operations when using a given actions template.
+	 */
+	struct mlx5_dr_rule_action_container rule_acts[];
 };
 
 static __rte_always_inline struct mlx5dr_matcher *
drivers/net/mlx5/mlx5_flow_hw.c +46 -5

124 lines not on this page · raw message

Signature · 1 line
2.39.2
#15 lore raw

PATCH v2 2/11 net/mlx5/hws: add check for matcher rule update support

In reply to Dariusz Sosnowski

From: Erez Shitrit <[email protected]>

The user want to know before trying to update a rule if that matcher that keeps the original rule supports updating.

---
 drivers/net/mlx5/hws/mlx5dr.h         |  8 ++++++++
 drivers/net/mlx5/hws/mlx5dr_matcher.c | 12 ++++++++++++
 2 files changed, 20 insertions(+)
drivers/net/mlx5/hws/mlx5dr.h +8 -0
index 8441ae97e9..c5824a6480 100644
@@ -492,6 +492,14 @@ int mlx5dr_matcher_resize_rule_move(struct mlx5dr_matcher *src_matcher,
 				    struct mlx5dr_rule *rule,
 				    struct mlx5dr_rule_attr *attr);
 
+/* Check matcher ability to update existing rules
+ *
+ * @param[in] matcher
+ *	that the rule belongs to.
+ * @return true when the matcher is updatable false otherwise.
+ */
+bool mlx5dr_matcher_is_updatable(struct mlx5dr_matcher *matcher);
+
 /* Get the size of the rule handle (mlx5dr_rule) to be used on rule creation.
  *
  * @return size in bytes of rule handle struct.
drivers/net/mlx5/hws/mlx5dr_matcher.c +12 -0
index 8a74a1ed7d..4e4da8e8f6 100644
@@ -1530,6 +1530,18 @@ int mlx5dr_match_template_destroy(struct mlx5dr_match_template *mt)
 	return 0;
 }
 
+bool mlx5dr_matcher_is_updatable(struct mlx5dr_matcher *matcher)
+{
+	if (mlx5dr_table_is_root(matcher->tbl) ||
+	    mlx5dr_matcher_req_fw_wqe(matcher) ||
+	    mlx5dr_matcher_is_resizable(matcher) ||
+	    (!matcher->attr.optimize_using_rule_idx &&
+	    !mlx5dr_matcher_is_insert_by_idx(matcher)))
+		return false;
+
+	return true;
+}
+
 static int mlx5dr_matcher_resize_precheck(struct mlx5dr_matcher *src_matcher,
 					  struct mlx5dr_matcher *dst_matcher)
 {
Signature · 1 line
2.39.2
#16 lore raw

PATCH v2 3/11 net/mlx5/hws: add check if matcher contains complex rules

In reply to Dariusz Sosnowski

From: Erez Shitrit <[email protected]>

The function returns true if that matcher can contain complicated rule, which means rule that needs more than one writing to the HW in order to have it.

---
 drivers/net/mlx5/hws/mlx5dr.h         |  8 ++++++++
 drivers/net/mlx5/hws/mlx5dr_action.c  |  6 ++++++
 drivers/net/mlx5/hws/mlx5dr_action.h  |  2 ++
 drivers/net/mlx5/hws/mlx5dr_matcher.c | 17 +++++++++++++++++
 4 files changed, 33 insertions(+)
drivers/net/mlx5/hws/mlx5dr.h +8 -0
index c5824a6480..36ecccf9ac 100644
@@ -500,6 +500,14 @@ int mlx5dr_matcher_resize_rule_move(struct mlx5dr_matcher *src_matcher,
  */
 bool mlx5dr_matcher_is_updatable(struct mlx5dr_matcher *matcher);
 
+/* Check matcher if might contain rules that need complex structure
+ *
+ * @param[in] matcher
+ *	that the rule belongs to.
+ * @return true when the matcher is contains such rules, false otherwise.
+ */
+bool mlx5dr_matcher_is_dependent(struct mlx5dr_matcher *matcher);
+
 /* Get the size of the rule handle (mlx5dr_rule) to be used on rule creation.
  *
  * @return size in bytes of rule handle struct.
drivers/net/mlx5/hws/mlx5dr_action.c +6 -0
index 96cad553aa..084d4d606e 100644
@@ -3686,6 +3686,7 @@ int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
 			setter->flags |= ASF_SINGLE1 | ASF_REMOVE;
 			setter->set_single = &mlx5dr_action_setter_ipv6_route_ext_pop;
 			setter->idx_single = i;
+			at->need_dep_write = true;
 			break;
 
 		case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
@@ -3712,6 +3713,7 @@ int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
 			setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
 			setter->idx_double = i;
 			setter->extra_data = 2;
+			at->need_dep_write = true;
 			break;
 
 		case MLX5DR_ACTION_TYP_MODIFY_HDR:
@@ -3720,6 +3722,7 @@ int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
 			setter->flags |= ASF_DOUBLE | ASF_MODIFY;
 			setter->set_double = &mlx5dr_action_setter_modify_header;
 			setter->idx_double = i;
+			at->need_dep_write = true;
 			break;
 
 		case MLX5DR_ACTION_TYP_ASO_METER:
@@ -3747,6 +3750,7 @@ int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
 			setter->flags |= ASF_DOUBLE | ASF_INSERT;
 			setter->set_double = &mlx5dr_action_setter_insert_ptr;
 			setter->idx_double = i;
+			at->need_dep_write = true;
 			break;
 
 		case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
@@ -3757,6 +3761,7 @@ int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
 			setter->idx_double = i;
 			setter->set_single = &mlx5dr_action_setter_common_decap;
 			setter->idx_single = i;
+			at->need_dep_write = true;
 			break;
 
 		case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
@@ -3765,6 +3770,7 @@ int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
 			setter->flags |= ASF_DOUBLE | ASF_MODIFY | ASF_INSERT;
 			setter->set_double = &mlx5dr_action_setter_tnl_l3_to_l2;
 			setter->idx_double = i;
+			at->need_dep_write = true;
 			break;
 
 		case MLX5DR_ACTION_TYP_TAG:
drivers/net/mlx5/hws/mlx5dr_action.h +2 -0
index 064c18a90c..57e059a572 100644
@@ -151,6 +151,8 @@ struct mlx5dr_action_template {
 	uint8_t num_of_action_stes;
 	uint8_t num_actions;
 	uint8_t only_term;
+	/* indicates rule might require dependent wqe */
+	bool need_dep_write;
 	uint32_t flags;
 };
 
drivers/net/mlx5/hws/mlx5dr_matcher.c +17 -0
index 4e4da8e8f6..1c64abfa57 100644
@@ -1542,6 +1542,23 @@ bool mlx5dr_matcher_is_updatable(struct mlx5dr_matcher *matcher)
 	return true;
 }
 
+bool mlx5dr_matcher_is_dependent(struct mlx5dr_matcher *matcher)
+{
+	int i;
+
+	if (matcher->action_ste.max_stes || mlx5dr_matcher_req_fw_wqe(matcher))
+		return true;
+
+	for (i = 0; i < matcher->num_of_at; i++) {
+		struct mlx5dr_action_template *at = &matcher->at[i];
+
+		if (at->need_dep_write)
+			return true;
+	}
+
+	return false;
+}
+
 static int mlx5dr_matcher_resize_precheck(struct mlx5dr_matcher *src_matcher,
 					  struct mlx5dr_matcher *dst_matcher)
 {
Signature · 1 line
2.39.2
#17 lore raw

PATCH v2 4/11 net/mlx5: skip the unneeded resource index allocation

In reply to Dariusz Sosnowski

From: Bing Zhao <[email protected]>

The resource index was introduced to decouple the flow rule and its resources used by hardware steering. This is needed only when a rule update is supported.

In some cases, the update is not supported on a table(matcher). E.g.:
* Table is resizable
* FW gets involved
* Root table
* Not index based or optimized (not applicable)

Or only one STE entry is required per rule. When doing an update, the operation is always atomic. There is no need for the extra resource index either.

If the matcher doesn't support rule update or the maximal entry is only 1 for this matcher, there is no need to manage the resource index allocation and free from the pool.

---
 drivers/net/mlx5/mlx5_flow_hw.c | 129 +++++++++++++++++++-------------
 1 file changed, 76 insertions(+), 53 deletions(-)
drivers/net/mlx5/mlx5_flow_hw.c +76 -53
index ef91a23a9b..1fe8f42618 100644
@@ -3383,9 +3383,6 @@ flow_hw_async_flow_create(struct rte_eth_dev *dev,
 	flow = mlx5_ipool_zmalloc(table->flow, &flow_idx);
 	if (!flow)
 		goto error;
-	mlx5_ipool_malloc(table->resource, &res_idx);
-	if (!res_idx)
-		goto error;
 	rule_acts = flow_hw_get_dr_action_buffer(priv, table, action_template_index, queue);
 	/*
 	 * Set the table here in order to know the destination table
@@ -3394,7 +3391,14 @@ flow_hw_async_flow_create(struct rte_eth_dev *dev,
 	flow->table = table;
 	flow->mt_idx = pattern_template_index;
 	flow->idx = flow_idx;
-	flow->res_idx = res_idx;
+	if (table->resource) {
+		mlx5_ipool_malloc(table->resource, &res_idx);
+		if (!res_idx)
+			goto error;
+		flow->res_idx = res_idx;
+	} else {
+		flow->res_idx = flow_idx;
+	}
 	/*
 	 * Set the job type here in order to know if the flow memory
 	 * should be freed or not when get the result from dequeue.
@@ -3404,11 +3408,10 @@ flow_hw_async_flow_create(struct rte_eth_dev *dev,
 	job->user_data = user_data;
 	rule_attr.user_data = job;
 	/*
-	 * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices for rule
-	 * insertion hints.
+	 * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices
+	 * for rule insertion hints.
 	 */
-	MLX5_ASSERT(res_idx > 0);
-	flow->rule_idx = res_idx - 1;
+	flow->rule_idx = flow->res_idx - 1;
 	rule_attr.rule_idx = flow->rule_idx;
 	/*
 	 * Construct the flow actions based on the input actions.
@@ -3451,12 +3454,12 @@ flow_hw_async_flow_create(struct rte_eth_dev *dev,
 	if (likely(!ret))
 		return (struct rte_flow *)flow;
 error:
-	if (job)
-		flow_hw_job_put(priv, job, queue);
+	if (table->resource && res_idx)
+		mlx5_ipool_free(table->resource, res_idx);
 	if (flow_idx)
 		mlx5_ipool_free(table->flow, flow_idx);
-	if (res_idx)
-		mlx5_ipool_free(table->resource, res_idx);
+	if (job)
+		flow_hw_job_put(priv, job, queue);
 	rte_flow_error_set(error, rte_errno,
 			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 			   "fail to create rte flow");
@@ -3527,9 +3530,6 @@ flow_hw_async_flow_create_by_index(struct rte_eth_dev *dev,
 	flow = mlx5_ipool_zmalloc(table->flow, &flow_idx);
 	if (!flow)
 		goto error;
-	mlx5_ipool_malloc(table->resource, &res_idx);
-	if (!res_idx)
-		goto error;
 	rule_acts = flow_hw_get_dr_action_buffer(priv, table, action_template_index, queue);
 	/*
 	 * Set the table here in order to know the destination table
@@ -3538,7 +3538,14 @@ flow_hw_async_flow_create_by_index(struct rte_eth_dev *dev,
 	flow->table = table;
 	flow->mt_idx = 0;
 	flow->idx = flow_idx;
-	flow->res_idx = res_idx;
+	if (table->resource) {
+		mlx5_ipool_malloc(table->resource, &res_idx);
+		if (!res_idx)
+			goto error;
+		flow->res_idx = res_idx;
+	} else {
+		flow->res_idx = flow_idx;
+	}
 	/*
 	 * Set the job type here in order to know if the flow memory
 	 * should be freed or not when get the result from dequeue.
@@ -3547,9 +3554,7 @@ flow_hw_async_flow_create_by_index(struct rte_eth_dev *dev,
 	job->flow = flow;
 	job->user_data = user_data;
 	rule_attr.user_data = job;
-	/*
-	 * Set the rule index.
-	 */
+	/* Set the rule index. */
 	flow->rule_idx = rule_index;
 	rule_attr.rule_idx = flow->rule_idx;
 	/*
@@ -3585,12 +3590,12 @@ flow_hw_async_flow_create_by_index(struct rte_eth_dev *dev,
 	if (likely(!ret))
 		return (struct rte_flow *)flow;
 error:
-	if (job)
-		flow_hw_job_put(priv, job, queue);
-	if (res_idx)
+	if (table->resource && res_idx)
 		mlx5_ipool_free(table->resource, res_idx);
 	if (flow_idx)
 		mlx5_ipool_free(table->flow, flow_idx);
+	if (job)
+		flow_hw_job_put(priv, job, queue);
 	rte_flow_error_set(error, rte_errno,
 			   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
 			   "fail to create rte flow");
@@ -3653,9 +3658,6 @@ flow_hw_async_flow_update(struct rte_eth_dev *dev,
 		rte_errno = ENOMEM;
 		goto error;
 	}
-	mlx5_ipool_malloc(table->resource, &res_idx);
-	if (!res_idx)
-		goto error;
 	nf = job->upd_flow;
 	memset(nf, 0, sizeof(struct rte_flow_hw));
 	rule_acts = flow_hw_get_dr_action_buffer(priv, table, action_template_index, queue);
@@ -3666,7 +3668,14 @@ flow_hw_async_flow_update(struct rte_eth_dev *dev,
 	nf->table = table;
 	nf->mt_idx = of->mt_idx;
 	nf->idx = of->idx;
-	nf->res_idx = res_idx;
+	if (table->resource) {
+		mlx5_ipool_malloc(table->resource, &res_idx);
+		if (!res_idx)
+			goto error;
+		nf->res_idx = res_idx;
+	} else {
+		nf->res_idx = of->res_idx;
+	}
 	/*
 	 * Set the job type here in order to know if the flow memory
 	 * should be freed or not when get the result from dequeue.
@@ -3676,11 +3685,11 @@ flow_hw_async_flow_update(struct rte_eth_dev *dev,
 	job->user_data = user_data;
 	rule_attr.user_data = job;
 	/*
-	 * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices for rule
-	 * insertion hints.
+	 * Indexed pool returns 1-based indices, but mlx5dr expects 0-based indices
+	 * for rule insertion hints.
+	 * If there is only one STE, the update will be atomic by nature.
 	 */
-	MLX5_ASSERT(res_idx > 0);
-	nf->rule_idx = res_idx - 1;
+	nf->rule_idx = nf->res_idx - 1;
 	rule_attr.rule_idx = nf->rule_idx;
 	/*
 	 * Construct the flow actions based on the input actions.
@@ -3706,14 +3715,14 @@ flow_hw_async_flow_update(struct rte_eth_dev *dev,
 	if (likely(!ret))
 		return 0;
 error:
+	if (table->resource && res_idx)
+		mlx5_ipool_free(table->resource, res_idx);
 	/* Flow created fail, return the descriptor and flow memory. */
 	if (job)
 		flow_hw_job_put(priv, job, queue);
-	if (res_idx)
-		mlx5_ipool_free(table->resource, res_idx);
 	return rte_flow_error_set(error, rte_errno,
-			RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
-			"fail to update rte flow");
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+				  "fail to update rte flow");
 }
 
 /**
@@ -3968,13 +3977,15 @@ hw_cmpl_flow_update_or_destroy(struct rte_eth_dev *dev,
 	}
 	if (job->type != MLX5_HW_Q_JOB_TYPE_UPDATE) {
 		if (table) {
-			mlx5_ipool_free(table->resource, res_idx);
+			if (table->resource)
+				mlx5_ipool_free(table->resource, res_idx);
 			mlx5_ipool_free(table->flow, flow->idx);
 		}
 	} else {
 		rte_memcpy(flow, job->upd_flow,
 			   offsetof(struct rte_flow_hw, rule));
-		mlx5_ipool_free(table->resource, res_idx);
+		if (table->resource)
+			mlx5_ipool_free(table->resource, res_idx);
 	}
 }
 
@@ -4474,6 +4485,7 @@ flow_hw_table_create(struct rte_eth_dev *dev,
 	uint32_t i = 0, max_tpl = MLX5_HW_TBL_MAX_ITEM_TEMPLATE;
 	uint32_t nb_flows = rte_align32pow2(attr->nb_flows);
 	bool port_started = !!dev->data->dev_started;
+	bool rpool_needed;
 	size_t tbl_mem_size;
 	int err;
 
@@ -4511,13 +4523,6 @@ flow_hw_table_create(struct rte_eth_dev *dev,
 	tbl->flow = mlx5_ipool_create(&cfg);
 	if (!tbl->flow)
 		goto error;
-	/* Allocate rule indexed pool. */
-	cfg.size = 0;
-	cfg.type = "mlx5_hw_table_rule";
-	cfg.max_idx += priv->hw_q[0].size;
-	tbl->resource = mlx5_ipool_create(&cfg);
-	if (!tbl->resource)
-		goto error;
 	/* Register the flow group. */
 	ge = mlx5_hlist_register(priv->sh->groups, attr->flow_attr.group, &ctx);
 	if (!ge)
@@ -4597,12 +4602,30 @@ flow_hw_table_create(struct rte_eth_dev *dev,
 	tbl->type = attr->flow_attr.transfer ? MLX5DR_TABLE_TYPE_FDB :
 		    (attr->flow_attr.egress ? MLX5DR_TABLE_TYPE_NIC_TX :
 		    MLX5DR_TABLE_TYPE_NIC_RX);
+	/*
+	 * Only the matcher supports update and needs more than 1 WQE, an additional
+	 * index is needed. Or else the flow index can be reused.
+	 */
+	rpool_needed = mlx5dr_matcher_is_updatable(tbl->matcher_info[0].matcher) &&
+		       mlx5dr_matcher_is_dependent(tbl->matcher_info[0].matcher);
+	if (rpool_needed) {
+		/* Allocate rule indexed pool. */
+		cfg.size = 0;
+		cfg.type = "mlx5_hw_table_rule";
+		cfg.max_idx += priv->hw_q[0].size;
+		tbl->resource = mlx5_ipool_create(&cfg);
+		if (!tbl->resource)
+			goto res_error;
+	}
 	if (port_started)
 		LIST_INSERT_HEAD(&priv->flow_hw_tbl, tbl, next);
 	else
 		LIST_INSERT_HEAD(&priv->flow_hw_tbl_ongo, tbl, next);
 	rte_rwlock_init(&tbl->matcher_replace_rwlk);
 	return tbl;
+res_error:
+	if (tbl->matcher_info[0].matcher)
+		(void)mlx5dr_matcher_destroy(tbl->matcher_info[0].matcher);
 at_error:
 	for (i = 0; i < nb_action_templates; i++) {
 		__flow_hw_action_template_destroy(dev, &tbl->ats[i].acts);
@@ -4620,8 +4643,6 @@ flow_hw_table_create(struct rte_eth_dev *dev,
 		if (tbl->grp)
 			mlx5_hlist_unregister(priv->sh->groups,
 					      &tbl->grp->entry);
-		if (tbl->resource)
-			mlx5_ipool_destroy(tbl->resource);
 		if (tbl->flow)
 			mlx5_ipool_destroy(tbl->flow);
 		mlx5_free(tbl);
@@ -4830,12 +4851,13 @@ flow_hw_table_destroy(struct rte_eth_dev *dev,
 	uint32_t ridx = 1;
 
 	/* Build ipool allocated object bitmap. */
-	mlx5_ipool_flush_cache(table->resource);
+	if (table->resource)
+		mlx5_ipool_flush_cache(table->resource);
 	mlx5_ipool_flush_cache(table->flow);
 	/* Check if ipool has allocated objects. */
 	if (table->refcnt ||
 	    mlx5_ipool_get_next(table->flow, &fidx) ||
-	    mlx5_ipool_get_next(table->resource, &ridx)) {
+	    (table->resource && mlx5_ipool_get_next(table->resource, &ridx))) {
 		DRV_LOG(WARNING, "Table %p is still in use.", (void *)table);
 		return rte_flow_error_set(error, EBUSY,
 				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
@@ -4857,7 +4879,8 @@ flow_hw_table_destroy(struct rte_eth_dev *dev,
 	if (table->matcher_info[1].matcher)
 		mlx5dr_matcher_destroy(table->matcher_info[1].matcher);
 	mlx5_hlist_unregister(priv->sh->groups, &table->grp->entry);
-	mlx5_ipool_destroy(table->resource);
+	if (table->resource)
+		mlx5_ipool_destroy(table->resource);
 	mlx5_ipool_destroy(table->flow);
 	mlx5_free(table);
 	return 0;
@@ -12476,11 +12499,11 @@ flow_hw_table_resize(struct rte_eth_dev *dev,
 		return rte_flow_error_set(error, EINVAL,
 					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 					  table, "cannot resize flows pool");
-	ret = mlx5_ipool_resize(table->resource, nb_flows);
-	if (ret)
-		return rte_flow_error_set(error, EINVAL,
-					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
-					  table, "cannot resize resources pool");
+	/*
+	 * A resizable matcher doesn't support rule update. In this case, the ipool
+	 * for the resource is not created and there is no need to resize it.
+	 */
+	MLX5_ASSERT(!table->resource);
 	if (mlx5_is_multi_pattern_active(&table->mpctx)) {
 		ret = flow_hw_table_resize_multi_pattern_actions(dev, table, nb_flows, error);
 		if (ret < 0)
Signature · 1 line
2.39.2
#18 lore raw

PATCH v2 5/11 net/mlx5: remove action params from job

In reply to Dariusz Sosnowski

mlx5_hw_q_job struct held references to buffers which contained:

- modify header commands array,
- encap/decap data buffer,
- IPv6 routing data buffer.

These buffers were passed as parameters to HWS layer during rule creation. They were needed only during the call to HWS layer when flow operation is enqueues (i.e. mlx5dr_rule_create()). After operation is enqueued, data stored there can be safely discarded and it is not required to store it during the whole lifecycle of a job.

This patch removes references to these buffers from mlx5_hw_q_job and removes relevant allocations to reduce job memory footprint. Buffers stored per job are replaced with stack allocated ones, contained in mlx5_flow_hw_action_params struct.

---
 drivers/net/mlx5/mlx5.h         |   3 -
 drivers/net/mlx5/mlx5_flow.h    |  10 +++
 drivers/net/mlx5/mlx5_flow_hw.c | 120 ++++++++++++++------------------
 3 files changed, 63 insertions(+), 70 deletions(-)
drivers/net/mlx5/mlx5.h +0 -3
index f11a0181b8..42dc312a87 100644
@@ -401,9 +401,6 @@ struct mlx5_hw_q_job {
 		const void *action; /* Indirect action attached to the job. */
 	};
 	void *user_data; /* Job user data. */
-	uint8_t *encap_data; /* Encap data. */
-	uint8_t *push_data; /* IPv6 routing push data. */
-	struct mlx5_modification_cmd *mhdr_cmd;
 	struct rte_flow_item *items;
 	union {
 		struct {
drivers/net/mlx5/mlx5_flow.h +10 -0
index 02af0a08fa..9ed356e1c2 100644
@@ -1306,6 +1306,16 @@ typedef int
 
 #define MLX5_MHDR_MAX_CMD ((MLX5_MAX_MODIFY_NUM) * 2 + 1)
 
+/** Container for flow action data constructed during flow rule creation. */
+struct mlx5_flow_hw_action_params {
+	/** Array of constructed modify header commands. */
+	struct mlx5_modification_cmd mhdr_cmd[MLX5_MHDR_MAX_CMD];
+	/** Constructed encap/decap data buffer. */
+	uint8_t encap_data[MLX5_ENCAP_MAX_LEN];
+	/** Constructed IPv6 routing data buffer. */
+	uint8_t ipv6_push_data[MLX5_PUSH_MAX_LEN];
+};
+
 /* rte flow action translate to DR action struct. */
 struct mlx5_action_construct_data {
 	LIST_ENTRY(mlx5_action_construct_data) next;
drivers/net/mlx5/mlx5_flow_hw.c +53 -67

359 lines not on this page · raw message

Signature · 1 line
2.39.2
#19 lore raw

PATCH v2 6/11 net/mlx5: remove flow pattern from job

In reply to Dariusz Sosnowski

mlx5_hw_q_job struct held a reference to temporary flow rule pattern and contained temporary REPRESENTED_PORT and TAG items structs. They are used whenever it is required to prepend a flow rule pattern, provided by the application with one of such items.
If prepending is required, then flow rule pattern is copied over to temporary buffer and a new item added internally in PMD. Such constructed buffer is passed to the HWS layer when flow create operation is being enqueued.
After operation is enqueued, temporary flow pattern can be safely discarded, so there is no need to store it during
the whole lifecycle of mlx5_hw_q_job.

This patch removes all references to flow rule pattern and items stored inside mlx5_hw_q_job and removes relevant allocations to reduce job memory footprint.
Temporary pattern and items stored per job are replaced with stack allocated ones, contained in mlx5_flow_hw_pattern_params struct.

---
 drivers/net/mlx5/mlx5.h         | 17 ++++-------
 drivers/net/mlx5/mlx5_flow.h    | 10 +++++++
 drivers/net/mlx5/mlx5_flow_hw.c | 51 ++++++++++++++-------------------
 3 files changed, 37 insertions(+), 41 deletions(-)
drivers/net/mlx5/mlx5.h +6 -11
index 42dc312a87..1ca6223f95 100644
@@ -401,17 +401,12 @@ struct mlx5_hw_q_job {
 		const void *action; /* Indirect action attached to the job. */
 	};
 	void *user_data; /* Job user data. */
-	struct rte_flow_item *items;
-	union {
-		struct {
-			/* User memory for query output */
-			void *user;
-			/* Data extracted from hardware */
-			void *hw;
-		} __rte_packed query;
-		struct rte_flow_item_ethdev port_spec;
-		struct rte_flow_item_tag tag_spec;
-	} __rte_packed;
+	struct {
+		/* User memory for query output */
+		void *user;
+		/* Data extracted from hardware */
+		void *hw;
+	} query;
 	struct rte_flow_hw *upd_flow; /* Flow with updated values. */
 };
 
drivers/net/mlx5/mlx5_flow.h +10 -0
index 9ed356e1c2..436d1391bc 100644
@@ -1316,6 +1316,16 @@ struct mlx5_flow_hw_action_params {
 	uint8_t ipv6_push_data[MLX5_PUSH_MAX_LEN];
 };
 
+/** Container for dynamically generated flow items used during flow rule creation. */
+struct mlx5_flow_hw_pattern_params {
+	/** Array of dynamically generated flow items. */
+	struct rte_flow_item items[MLX5_HW_MAX_ITEMS];
+	/** Temporary REPRESENTED_PORT item generated by PMD. */
+	struct rte_flow_item_ethdev port_spec;
+	/** Temporary TAG item generated by PMD. */
+	struct rte_flow_item_tag tag_spec;
+};
+
 /* rte flow action translate to DR action struct. */
 struct mlx5_action_construct_data {
 	LIST_ENTRY(mlx5_action_construct_data) next;
drivers/net/mlx5/mlx5_flow_hw.c +21 -30

122 lines not on this page · raw message

Signature · 1 line
2.39.2
#20 lore raw

PATCH v2 7/11 net/mlx5: remove updated flow from job

In reply to Dariusz Sosnowski

mlx5_hw_q_job struct held a reference to a temporary flow rule struct, used during flow rule update operation. It serves as a container for flow actions data calculated during actions construction. After flow rule update operation succeeds, data from temporary flow rule is copied over to original flow rule.

Although access to this temporary flow rule struct is required during both operation enqueue step and completion polling step, there can be only one ongoing flow update operation for a given flow rule. As a result there is no need to store it per job.

This patch removes all references to temporary flow rule struct stored in mlx5_hw_q_job and removes relevant allocations to reduce job memory footprint.
Temporary flow rule struct stored per job is replaced with:

- If table is not resizable - An array of rte_flow_hw_aux structs, stored in template table. This array holds one entry per each flow rule, each containing a single mentioned temporary struct.
- If table is resizable - Additional rte_flow_hw_aux struct, allocated alongside rte_flow_hw in resizable ipool.

---
 drivers/net/mlx5/mlx5.h         |   1 -
 drivers/net/mlx5/mlx5_flow.h    |   7 +++
 drivers/net/mlx5/mlx5_flow_hw.c | 100 ++++++++++++++++++++++++++------
 3 files changed, 89 insertions(+), 19 deletions(-)
drivers/net/mlx5/mlx5.h +0 -1
index 1ca6223f95..2e2504f20f 100644
@@ -407,7 +407,6 @@ struct mlx5_hw_q_job {
 		/* Data extracted from hardware */
 		void *hw;
 	} query;
-	struct rte_flow_hw *upd_flow; /* Flow with updated values. */
 };
 
 /* HW steering job descriptor LIFO pool. */
drivers/net/mlx5/mlx5_flow.h +7 -0
index 436d1391bc..a204f94624 100644
@@ -1293,6 +1293,12 @@ struct rte_flow_hw {
 	uint8_t rule[]; /* HWS layer data struct. */
 } __rte_packed;
 
+/** Auxiliary data stored per flow which is not required to be stored in main flow structure. */
+struct rte_flow_hw_aux {
+	/** Placeholder flow struct used during flow rule update operation. */
+	struct rte_flow_hw upd_flow;
+};
+
 #ifdef PEDANTIC
 #pragma GCC diagnostic error "-Wpedantic"
 #endif
@@ -1601,6 +1607,7 @@ struct rte_flow_template_table {
 	/* Action templates bind to the table. */
 	struct mlx5_hw_action_template ats[MLX5_HW_TBL_MAX_ACTION_TEMPLATE];
 	struct mlx5_indexed_pool *flow; /* The table's flow ipool. */
+	struct rte_flow_hw_aux *flow_aux; /**< Auxiliary data stored per flow. */
 	struct mlx5_indexed_pool *resource; /* The table's resource ipool. */
 	struct mlx5_flow_template_table_cfg cfg;
 	uint32_t type; /* Flow table type RX/TX/FDB. */
drivers/net/mlx5/mlx5_flow_hw.c +82 -18

182 lines not on this page · raw message

Signature · 1 line
2.39.2
#21 lore raw

PATCH v2 8/11 net/mlx5: use flow as operation container

In reply to Dariusz Sosnowski

While processing async flow operations in mlx5 PMD, mlx5_hw_q_job struct is used to hold the following data related to the ongoing operation.

- operation type,
- user data,
- flow reference.

Job itself is then passed to mlx5dr layer as its "user data". Other types of data required during flow operation processing are accessed through the flow itself.

Since most of the accessed fields are in the flow struct itself, the operation type and user data can be moved to the flow struct. This removes unnecessary memory indirection and reduces memory footprint of flow operations processing. It decreases cache stress and as a result can increase processing throughput.

This patch removes the mlx5_hw_q_job from async flow operations processing and from now on the flow itself can represent the ongoing operation. Async operations on indirect actions still use jobs.

---
 drivers/net/mlx5/mlx5.h         |   8 +-
 drivers/net/mlx5/mlx5_flow.h    |  13 ++
 drivers/net/mlx5/mlx5_flow_hw.c | 210 +++++++++++++++-----------------
 3 files changed, 116 insertions(+), 115 deletions(-)
drivers/net/mlx5/mlx5.h +3 -5
index 2e2504f20f..8acb79e7bb 100644
@@ -396,10 +396,7 @@ enum mlx5_hw_indirect_type {
 struct mlx5_hw_q_job {
 	uint32_t type; /* Job type. */
 	uint32_t indirect_type;
-	union {
-		struct rte_flow_hw *flow; /* Flow attached to the job. */
-		const void *action; /* Indirect action attached to the job. */
-	};
+	const void *action; /* Indirect action attached to the job. */
 	void *user_data; /* Job user data. */
 	struct {
 		/* User memory for query output */
@@ -412,7 +409,8 @@ struct mlx5_hw_q_job {
 /* HW steering job descriptor LIFO pool. */
 struct mlx5_hw_q {
 	uint32_t job_idx; /* Free job index. */
-	uint32_t size; /* LIFO size. */
+	uint32_t size; /* Job LIFO queue size. */
+	uint32_t ongoing_flow_ops; /* Number of ongoing flow operations. */
 	struct mlx5_hw_q_job **job; /* LIFO header. */
 	struct rte_ring *indir_cq; /* Indirect action SW completion queue. */
 	struct rte_ring *indir_iq; /* Indirect action SW in progress queue. */
drivers/net/mlx5/mlx5_flow.h +13 -0
index a204f94624..46d8ce1775 100644
@@ -1269,6 +1269,16 @@ typedef uint32_t cnt_id_t;
 
 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
 
+enum {
+	MLX5_FLOW_HW_FLOW_OP_TYPE_NONE,
+	MLX5_FLOW_HW_FLOW_OP_TYPE_CREATE,
+	MLX5_FLOW_HW_FLOW_OP_TYPE_DESTROY,
+	MLX5_FLOW_HW_FLOW_OP_TYPE_UPDATE,
+	MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_CREATE,
+	MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_DESTROY,
+	MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_MOVE,
+};
+
 #ifdef PEDANTIC
 #pragma GCC diagnostic ignored "-Wpedantic"
 #endif
@@ -1290,6 +1300,9 @@ struct rte_flow_hw {
 	cnt_id_t cnt_id;
 	uint32_t mtr_id;
 	uint32_t rule_idx;
+	uint8_t operation_type; /**< Ongoing flow operation type. */
+	void *user_data; /**< Application's private data passed to enqueued flow operation. */
+	uint8_t padding[1]; /**< Padding for proper alignment of mlx5dr rule struct. */
 	uint8_t rule[]; /* HWS layer data struct. */
 } __rte_packed;
 
drivers/net/mlx5/mlx5_flow_hw.c +100 -110

438 lines not on this page · raw message

Signature · 1 line
2.39.2
#22 lore raw

PATCH v2 9/11 net/mlx5: move rarely used flow fields outside

In reply to Dariusz Sosnowski

Some of the flow fields are either not always required or are used very rarely, e.g.:

- AGE action reference,
- direct METER/METER_MARK action reference,
- matcher selector for resizable tables.

This patch moves these fields to rte_flow_hw_aux struct in order to reduce the overall size of the flow struct, reducing the total size of working set for most common use cases.
This results in reduction of the frequency of cache invalidation during async flow operations processing.

---
 drivers/net/mlx5/mlx5_flow.h    |  61 +++++++++++-----
 drivers/net/mlx5/mlx5_flow_hw.c | 121 ++++++++++++++++++++++++--------
 2 files changed, 138 insertions(+), 44 deletions(-)
drivers/net/mlx5/mlx5_flow.h +45 -16
index 46d8ce1775..e8f4d2cb16 100644
@@ -1283,31 +1283,60 @@ enum {
 #pragma GCC diagnostic ignored "-Wpedantic"
 #endif
 
-/* HWS flow struct. */
+/** HWS flow struct. */
 struct rte_flow_hw {
-	uint32_t idx; /* Flow index from indexed pool. */
-	uint32_t res_idx; /* Resource index from indexed pool. */
-	uint32_t fate_type; /* Fate action type. */
+	/** The table flow allcated from. */
+	struct rte_flow_template_table *table;
+	/** Application's private data passed to enqueued flow operation. */
+	void *user_data;
+	/** Flow index from indexed pool. */
+	uint32_t idx;
+	/** Resource index from indexed pool. */
+	uint32_t res_idx;
+	/** HWS flow rule index passed to mlx5dr. */
+	uint32_t rule_idx;
+	/** Fate action type. */
+	uint32_t fate_type;
+	/** Ongoing flow operation type. */
+	uint8_t operation_type;
+	/** Index of pattern template this flow is based on. */
+	uint8_t mt_idx;
+
+	/** COUNT action index. */
+	cnt_id_t cnt_id;
 	union {
-		/* Jump action. */
+		/** Jump action. */
 		struct mlx5_hw_jump_action *jump;
-		struct mlx5_hrxq *hrxq; /* TIR action. */
+		/** TIR action. */
+		struct mlx5_hrxq *hrxq;
 	};
-	struct rte_flow_template_table *table; /* The table flow allcated from. */
-	uint8_t mt_idx;
-	uint8_t matcher_selector:1;
+
+	/**
+	 * Padding for alignment to 56 bytes.
+	 * Since mlx5dr rule is 72 bytes, whole flow is contained within 128 B (2 cache lines).
+	 * This space is reserved for future additions to flow struct.
+	 */
+	uint8_t padding[10];
+	/** HWS layer data struct. */
+	uint8_t rule[];
+} __rte_packed;
+
+/** Auxiliary data fields that are updatable. */
+struct rte_flow_hw_aux_fields {
+	/** AGE action index. */
 	uint32_t age_idx;
-	cnt_id_t cnt_id;
+	/** Direct meter (METER or METER_MARK) action index. */
 	uint32_t mtr_id;
-	uint32_t rule_idx;
-	uint8_t operation_type; /**< Ongoing flow operation type. */
-	void *user_data; /**< Application's private data passed to enqueued flow operation. */
-	uint8_t padding[1]; /**< Padding for proper alignment of mlx5dr rule struct. */
-	uint8_t rule[]; /* HWS layer data struct. */
-} __rte_packed;
+};
 
 /** Auxiliary data stored per flow which is not required to be stored in main flow structure. */
 struct rte_flow_hw_aux {
+	/** Auxiliary fields associated with the original flow. */
+	struct rte_flow_hw_aux_fields orig;
+	/** Auxiliary fields associated with the updated flow. */
+	struct rte_flow_hw_aux_fields upd;
+	/** Index of resizable matcher associated with this flow. */
+	uint8_t matcher_selector;
 	/** Placeholder flow struct used during flow rule update operation. */
 	struct rte_flow_hw upd_flow;
 };
drivers/net/mlx5/mlx5_flow_hw.c +93 -28

295 lines not on this page · raw message

Signature · 1 line
2.39.2
#23 lore raw

PATCH v2 10/11 net/mlx5: reuse flow fields

In reply to Dariusz Sosnowski

Each time a flow is allocated in mlx5 PMD the whole buffer, both rte_flow_hw and mlx5dr_rule parts, are zeroed. This introduces some wasted work because:

- mlx5dr layer does not assume that mlx5dr_rule must be initialized,
- flow action translation in mlx5 PMD does not need most of the fields of rte_flow_hw to be zeroed.

To reduce this wasted work, this patch introduces flags field to flow definition. Each flow field which is not always initialized during flow creation, will have a correspondent flag set if value is valid (in other words - it was set during flow creation). Utilizing this mechanism allows PMD to:

- remove zeroing from flow allocation,
- access some fields (especially from rte_flow_hw_aux) if and only if corresponding flag is set.

---
 drivers/net/mlx5/mlx5_flow.h    | 24 ++++++++-
 drivers/net/mlx5/mlx5_flow_hw.c | 93 +++++++++++++++++++++------------
 2 files changed, 83 insertions(+), 34 deletions(-)
drivers/net/mlx5/mlx5_flow.h +22 -2
index e8f4d2cb16..db65825eab 100644
@@ -1279,6 +1279,26 @@ enum {
 	MLX5_FLOW_HW_FLOW_OP_TYPE_RSZ_TBL_MOVE,
 };
 
+enum {
+	MLX5_FLOW_HW_FLOW_FLAG_CNT_ID = RTE_BIT32(0),
+	MLX5_FLOW_HW_FLOW_FLAG_FATE_JUMP = RTE_BIT32(1),
+	MLX5_FLOW_HW_FLOW_FLAG_FATE_HRXQ = RTE_BIT32(2),
+	MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX = RTE_BIT32(3),
+	MLX5_FLOW_HW_FLOW_FLAG_MTR_ID = RTE_BIT32(4),
+	MLX5_FLOW_HW_FLOW_FLAG_MATCHER_SELECTOR = RTE_BIT32(5),
+	MLX5_FLOW_HW_FLOW_FLAG_UPD_FLOW = RTE_BIT32(6),
+};
+
+#define MLX5_FLOW_HW_FLOW_FLAGS_ALL ( \
+		MLX5_FLOW_HW_FLOW_FLAG_CNT_ID | \
+		MLX5_FLOW_HW_FLOW_FLAG_FATE_JUMP | \
+		MLX5_FLOW_HW_FLOW_FLAG_FATE_HRXQ | \
+		MLX5_FLOW_HW_FLOW_FLAG_AGE_IDX | \
+		MLX5_FLOW_HW_FLOW_FLAG_MTR_ID | \
+		MLX5_FLOW_HW_FLOW_FLAG_MATCHER_SELECTOR | \
+		MLX5_FLOW_HW_FLOW_FLAG_UPD_FLOW \
+	)
+
 #ifdef PEDANTIC
 #pragma GCC diagnostic ignored "-Wpedantic"
 #endif
@@ -1295,8 +1315,8 @@ struct rte_flow_hw {
 	uint32_t res_idx;
 	/** HWS flow rule index passed to mlx5dr. */
 	uint32_t rule_idx;
-	/** Fate action type. */
-	uint32_t fate_type;
+	/** Which flow fields (inline or in auxiliary struct) are used. */
+	uint32_t flags;
 	/** Ongoing flow operation type. */
 	uint8_t operation_type;
 	/** Index of pattern template this flow is based on. */
drivers/net/mlx5/mlx5_flow_hw.c +61 -32

273 lines not on this page · raw message

Signature · 1 line
2.39.2
#24 lore raw

PATCH v2 11/11 net/mlx5: remove unneeded device status checking

In reply to Dariusz Sosnowski

From: Bing Zhao <[email protected]>

The flow rule can be inserted even before the device started. The only exception is for a queue or RSS action.

For the other interfaces of template API, the start status is not checked. The checking would cause some cache miss or eviction since the flag locates on some other cache line.

Fixes f1fecffa88df ("net/mlx5: support Direct Rules action template API")
---
 drivers/net/mlx5/mlx5_flow_hw.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/net/mlx5/mlx5_flow_hw.c +0 -5
index 979be4764a..285ec603d3 100644
@@ -3520,11 +3520,6 @@ flow_hw_async_flow_create(struct rte_eth_dev *dev,
 	uint32_t res_idx = 0;
 	int ret;
 
-	if (unlikely((!dev->data->dev_started))) {
-		rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
-				   "Port must be started before enqueueing flow operations");
-		return NULL;
-	}
 	flow = mlx5_ipool_malloc(table->flow, &flow_idx);
 	if (!flow)
 		goto error;
Signature · 1 line
2.39.2
#25 lore raw
In reply to Dariusz Sosnowski

Hi.

Quoted 70 lines

-----Original Message-----
From: Dariusz Sosnowski <[email protected]>
Sent: Thursday, February 29, 2024 1:52 PM
To: Slava Ovsiienko <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Raslan Darawsheh <[email protected]>; Bing Zhao <[email protected]>
Subject: [PATCH v2 00/11] net/mlx5: flow insertion performance improvements

Goal of this patchset is to improve the throughput of flow insertion and deletion in mlx5 PMD when HW Steering flow engine is used.

- Patch 1 - Use preallocated per-queue, per-actions template buffer for storing translated flow actions, instead of allocating and filling it on demand, on each flow operation.
- Patches 2-4 - Make resource index allocation optional. This allocation will be skipped when it is not required by the created template table.
- Patches 5-7 - Reduce memory footprint of the internal flow queue.
- Patch 8 - Remove indirection between flow job and flow itself, by using flow as an operation container.
- Patches 9-10 - Reduce memory footpring of flow struct by moving rarely used flow fields outside of the main flow struct. These fields will accesses only when needed.
Also remove unneeded zmalloc usage.
- Patch 11 - Remove unneeded device status check in flow create.

In general all of these changes result in the following improvements (all numbers are averaged Kflows/sec):

|              | Insertion) |   +%   | Deletion |   +%  |
|--------------|:----------:|:------:|:--------:|:-----:|
| baseline     |   6338.7   |        |  9739.6  |       |
| improvements |   6978.8   | +10.1% |  10432.4 | +7.1% |

The basic benchmark was run on ConnectX-6 Dx (22.40.1000), on the system with Intel Xeon Platinum 8380 CPU.

v2:

- Rebased.
- Applied Acked-by tags from previous version.

Bing Zhao (2):
net/mlx5: skip the unneeded resource index allocation net/mlx5: remove unneeded device status checking

Dariusz Sosnowski (7):
net/mlx5: allocate local DR rule action buffers
net/mlx5: remove action params from job
net/mlx5: remove flow pattern from job
net/mlx5: remove updated flow from job
net/mlx5: use flow as operation container
net/mlx5: move rarely used flow fields outside
net/mlx5: reuse flow fields

Erez Shitrit (2):
net/mlx5/hws: add check for matcher rule update support net/mlx5/hws: add check if matcher contains complex rules

 drivers/net/mlx5/hws/mlx5dr.h         |  16 +
 drivers/net/mlx5/hws/mlx5dr_action.c  |   6 +
 drivers/net/mlx5/hws/mlx5dr_action.h  |   2 +
 drivers/net/mlx5/hws/mlx5dr_matcher.c |  29 +
 drivers/net/mlx5/mlx5.h               |  29 +-
 drivers/net/mlx5/mlx5_flow.h          | 128 ++++-
 drivers/net/mlx5/mlx5_flow_hw.c       | 794 ++++++++++++++++----------
 7 files changed, 666 insertions(+), 338 deletions(-)
Quoted 2 lines

--
2.39.2

Series applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh