DPDK patches and discussions
 help / color / mirror / Atom feed
From: Suanming Mou <suanmingm@mellanox.com>
To: viacheslavo@mellanox.com, matan@mellanox.com
Cc: orika@mellanox.com, wentaoc@mellanox.com, rasland@mellanox.com,
	dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2 01/10] net/mlx5: reorganize fate actions as union
Date: Thu, 16 Apr 2020 16:34:22 +0800	[thread overview]
Message-ID: <1587026071-422636-2-git-send-email-suanmingm@mellanox.com> (raw)
In-Reply-To: <1587026071-422636-1-git-send-email-suanmingm@mellanox.com>

Currently, one flow only has one fate action, the fate actions members
in the flow struct can be reorganized as union to save the memory for
flow struct.

This commit reorganizes the fate actions as union, the act_flags helps
to identify the fate action type when flow destroys.

Signed-off-by: Suanming Mou <suanmingm@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
 drivers/net/mlx5/mlx5_flow.h       | 11 +++++----
 drivers/net/mlx5/mlx5_flow_dv.c    | 48 +++++++++++++++++++++++++-------------
 drivers/net/mlx5/mlx5_flow_verbs.c | 22 ++++++++++++-----
 3 files changed, 54 insertions(+), 27 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index a2ea122..fc97424 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -488,10 +488,6 @@ struct mlx5_flow_handle_dv {
 	/**< Index to encap/decap resource in cache. */
 	struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
 	/**< Pointer to modify header resource in cache. */
-	uint32_t jump;
-	/**< Index to the jump action resource. */
-	uint32_t port_id_action;
-	/**< Index to port ID action resource. */
 	struct mlx5_vf_vlan vf_vlan;
 	/**< Structure for VF VLAN workaround. */
 	uint32_t push_vlan_res;
@@ -509,12 +505,17 @@ struct mlx5_flow_handle {
 	uint64_t act_flags;
 	/**< Bit-fields of detected actions, see MLX5_FLOW_ACTION_*. */
 	void *ib_flow; /**< Verbs flow pointer. */
-	uint32_t hrxq; /**< Hash Rx queue object index. */
 	struct mlx5_vf_vlan vf_vlan; /**< Structure for VF VLAN workaround. */
 	union {
 		uint32_t qrss_id; /**< Uniqie Q/RSS suffix subflow tag. */
 		uint32_t mtr_flow_id; /**< Unique meter match flow id. */
 	};
+	union {
+		uint32_t hrxq; /**< Hash Rx queue object index. */
+		uint32_t jump; /**< Index to the jump action resource. */
+		uint32_t port_id_action;
+		/**< Index to port ID action resource. */
+	};
 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
 	struct mlx5_flow_handle_dv dvh;
 #endif
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index f001b34..a44265b 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -2572,7 +2572,7 @@ struct field_modify_info modify_tcp[] = {
 			(void *)&tbl_data->jump, cnt);
 	}
 	rte_atomic32_inc(&tbl_data->jump.refcnt);
-	dev_flow->handle->dvh.jump = tbl_data->idx;
+	dev_flow->handle->jump = tbl_data->idx;
 	dev_flow->dv.jump = &tbl_data->jump;
 	return 0;
 }
@@ -2613,14 +2613,14 @@ struct field_modify_info modify_tcp[] = {
 				(void *)cache_resource,
 				rte_atomic32_read(&cache_resource->refcnt));
 			rte_atomic32_inc(&cache_resource->refcnt);
-			dev_flow->handle->dvh.port_id_action = idx;
+			dev_flow->handle->port_id_action = idx;
 			dev_flow->dv.port_id_action = cache_resource;
 			return 0;
 		}
 	}
 	/* Register new port id action resource. */
 	cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID],
-				       &dev_flow->handle->dvh.port_id_action);
+				       &dev_flow->handle->port_id_action);
 	if (!cache_resource)
 		return rte_flow_error_set(error, ENOMEM,
 					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
@@ -2643,8 +2643,7 @@ struct field_modify_info modify_tcp[] = {
 	rte_atomic32_init(&cache_resource->refcnt);
 	rte_atomic32_inc(&cache_resource->refcnt);
 	ILIST_INSERT(sh->ipool[MLX5_IPOOL_PORT_ID], &sh->port_id_action_list,
-		     dev_flow->handle->dvh.port_id_action, cache_resource,
-		     next);
+		     dev_flow->handle->port_id_action, cache_resource, next);
 	dev_flow->dv.port_id_action = cache_resource;
 	DRV_LOG(DEBUG, "new port id action resource %p: refcnt %d++",
 		(void *)cache_resource,
@@ -7442,7 +7441,7 @@ struct field_modify_info modify_tcp[] = {
 			if (flow_dv_port_id_action_resource_register
 			    (dev, &port_id_resource, dev_flow, error))
 				return -rte_errno;
-			MLX5_ASSERT(!handle->dvh.port_id_action);
+			MLX5_ASSERT(!handle->port_id_action);
 			dev_flow->dv.actions[actions_n++] =
 					dev_flow->dv.port_id_action->action;
 			action_flags |= MLX5_FLOW_ACTION_PORT_ID;
@@ -8115,6 +8114,13 @@ struct field_modify_info modify_tcp[] = {
 						 "cannot get drop hash queue");
 					goto error;
 				}
+				/*
+				 * Drop queues will be released by the specify
+				 * mlx5_hrxq_drop_release() function. Assign
+				 * the special index to hrxq to mark the queue
+				 * has been allocated.
+				 */
+				dh->hrxq = UINT32_MAX;
 				dv->actions[n++] = drop_hrxq->action;
 			}
 		} else if (dh->act_flags &
@@ -8177,12 +8183,17 @@ struct field_modify_info modify_tcp[] = {
 	err = rte_errno; /* Save rte_errno before cleanup. */
 	SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
 		       handle_idx, dh, next) {
+		/* hrxq is union, don't clear it if the flag is not set. */
 		if (dh->hrxq) {
-			if (dh->act_flags & MLX5_FLOW_ACTION_DROP)
+			if (dh->act_flags & MLX5_FLOW_ACTION_DROP) {
 				mlx5_hrxq_drop_release(dev);
-			else
+				dh->hrxq = 0;
+			} else if (dh->act_flags &
+				  (MLX5_FLOW_ACTION_QUEUE |
+				  MLX5_FLOW_ACTION_RSS)) {
 				mlx5_hrxq_release(dev, dh->hrxq);
-			dh->hrxq = 0;
+				dh->hrxq = 0;
+			}
 		}
 		if (dh->vf_vlan.tag && dh->vf_vlan.created)
 			mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
@@ -8287,7 +8298,7 @@ struct field_modify_info modify_tcp[] = {
 	struct mlx5_flow_tbl_data_entry *tbl_data;
 
 	tbl_data = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_JUMP],
-			     handle->dvh.jump);
+			     handle->jump);
 	if (!tbl_data)
 		return 0;
 	cache_resource = &tbl_data->jump;
@@ -8355,7 +8366,7 @@ struct field_modify_info modify_tcp[] = {
 {
 	struct mlx5_priv *priv = dev->data->dev_private;
 	struct mlx5_flow_dv_port_id_action_resource *cache_resource;
-	uint32_t idx = handle->dvh.port_id_action;
+	uint32_t idx = handle->port_id_action;
 
 	cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID],
 					idx);
@@ -8448,12 +8459,17 @@ struct field_modify_info modify_tcp[] = {
 			claim_zero(mlx5_glue->dv_destroy_flow(dh->ib_flow));
 			dh->ib_flow = NULL;
 		}
+		/* hrxq is union, don't touch it only the flag is set. */
 		if (dh->hrxq) {
-			if (dh->act_flags & MLX5_FLOW_ACTION_DROP)
+			if (dh->act_flags & MLX5_FLOW_ACTION_DROP) {
 				mlx5_hrxq_drop_release(dev);
-			else
+				dh->hrxq = 0;
+			} else if (dh->act_flags &
+				  (MLX5_FLOW_ACTION_QUEUE |
+				  MLX5_FLOW_ACTION_RSS)) {
 				mlx5_hrxq_release(dev, dh->hrxq);
-			dh->hrxq = 0;
+				dh->hrxq = 0;
+			}
 		}
 		if (dh->vf_vlan.tag && dh->vf_vlan.created)
 			mlx5_vlan_vmwa_release(dev, &dh->vf_vlan);
@@ -8501,9 +8517,9 @@ struct field_modify_info modify_tcp[] = {
 			flow_dv_encap_decap_resource_release(dev, dev_handle);
 		if (dev_handle->dvh.modify_hdr)
 			flow_dv_modify_hdr_resource_release(dev_handle);
-		if (dev_handle->dvh.jump)
+		if (dev_handle->act_flags & MLX5_FLOW_ACTION_JUMP)
 			flow_dv_jump_tbl_resource_release(dev, dev_handle);
-		if (dev_handle->dvh.port_id_action)
+		if (dev_handle->act_flags & MLX5_FLOW_ACTION_PORT_ID)
 			flow_dv_port_id_action_resource_release(dev,
 								dev_handle);
 		if (dev_handle->dvh.push_vlan_res)
diff --git a/drivers/net/mlx5/mlx5_flow_verbs.c b/drivers/net/mlx5/mlx5_flow_verbs.c
index 9525fd4..931d547 100644
--- a/drivers/net/mlx5/mlx5_flow_verbs.c
+++ b/drivers/net/mlx5/mlx5_flow_verbs.c
@@ -1754,12 +1754,17 @@
 			claim_zero(mlx5_glue->destroy_flow(handle->ib_flow));
 			handle->ib_flow = NULL;
 		}
+		/* hrxq is union, don't touch it only the flag is set. */
 		if (handle->hrxq) {
-			if (handle->act_flags & MLX5_FLOW_ACTION_DROP)
+			if (handle->act_flags & MLX5_FLOW_ACTION_DROP) {
 				mlx5_hrxq_drop_release(dev);
-			else
+				handle->hrxq = 0;
+			} else if (handle->act_flags &
+				  (MLX5_FLOW_ACTION_QUEUE |
+				  MLX5_FLOW_ACTION_RSS)) {
 				mlx5_hrxq_release(dev, handle->hrxq);
-			handle->hrxq = 0;
+				handle->hrxq = 0;
+			}
 		}
 		if (handle->vf_vlan.tag && handle->vf_vlan.created)
 			mlx5_vlan_vmwa_release(dev, &handle->vf_vlan);
@@ -1891,12 +1896,17 @@
 	err = rte_errno; /* Save rte_errno before cleanup. */
 	SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
 		       dev_handles, handle, next) {
+		/* hrxq is union, don't touch it only the flag is set. */
 		if (handle->hrxq) {
-			if (handle->act_flags & MLX5_FLOW_ACTION_DROP)
+			if (handle->act_flags & MLX5_FLOW_ACTION_DROP) {
 				mlx5_hrxq_drop_release(dev);
-			else
+				handle->hrxq = 0;
+			} else if (handle->act_flags &
+				  (MLX5_FLOW_ACTION_QUEUE |
+				  MLX5_FLOW_ACTION_RSS)) {
 				mlx5_hrxq_release(dev, handle->hrxq);
-			handle->hrxq = 0;
+				handle->hrxq = 0;
+			}
 		}
 		if (handle->vf_vlan.tag && handle->vf_vlan.created)
 			mlx5_vlan_vmwa_release(dev, &handle->vf_vlan);
-- 
1.8.3.1


  reply	other threads:[~2020-04-16  8:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <https://patches.dpdk.org/cover/68470/>
2020-04-16  8:34 ` [dpdk-dev] [PATCH v2 00/10] net/mlx5: optimize flow structure Suanming Mou
2020-04-16  8:34   ` Suanming Mou [this message]
2020-04-16  8:34   ` [dpdk-dev] [PATCH v2 02/10] net/mlx5: optimize action flags in flow handle Suanming Mou
2020-04-16  8:34   ` [dpdk-dev] [PATCH v2 03/10] net/mlx5: reorganize the mlx5 flow handle struct Suanming Mou
2020-04-16  8:34   ` [dpdk-dev] [PATCH v2 04/10] net/mlx5: optimize flow meter handle type Suanming Mou
2020-04-16  8:34   ` [dpdk-dev] [PATCH v2 05/10] net/mlx5: allocate meter from indexed pool Suanming Mou
2020-04-16  8:34   ` [dpdk-dev] [PATCH v2 06/10] net/mlx5: convert mark copy resource to indexed Suanming Mou
2020-04-16  8:34   ` [dpdk-dev] [PATCH v2 07/10] net/mlx5: optimize flow director filter memory Suanming Mou
2020-04-16  8:34   ` [dpdk-dev] [PATCH v2 08/10] net/mlx5: optimize mlx5 flow RSS struct Suanming Mou
2020-04-16  8:34   ` [dpdk-dev] [PATCH v2 09/10] net/mlx5: allocate rte flow from indexed pool Suanming Mou
2020-04-16  8:34   ` [dpdk-dev] [PATCH v2 10/10] net/mlx5: reorganize rte flow structure Suanming Mou
2020-04-16 17:08   ` [dpdk-dev] [PATCH v2 00/10] net/mlx5: optimize " Raslan Darawsheh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1587026071-422636-2-git-send-email-suanmingm@mellanox.com \
    --to=suanmingm@mellanox.com \
    --cc=dev@dpdk.org \
    --cc=matan@mellanox.com \
    --cc=orika@mellanox.com \
    --cc=rasland@mellanox.com \
    --cc=viacheslavo@mellanox.com \
    --cc=wentaoc@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).