DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bing Zhao <bingz@mellanox.com>
To: viacheslavo@mellanox.com
Cc: Bing Zhao <bingz@mellanox.com>,
	orika@mellanox.com, rasland@mellanox.com,  dev@dpdk.org,
	Bing Zhao <bingz@mtbc-r640-01.mtbc.labs.mlnx>
Subject: [dpdk-dev] [PATCH v2 2/3] net/mlx5: reorganize jump table resources
Date: Fri,  8 Nov 2019 17:23:09 +0200	[thread overview]
Message-ID: <1573226590-69757-3-git-send-email-bingz@pegasus02.mtr.labs.mlnx> (raw)
In-Reply-To: <1573226590-69757-1-git-send-email-bingz@pegasus02.mtr.labs.mlnx>

From: Bing Zhao <bingz@mellanox.com>

Jump object is associated with table object, so there is no need to
use a single linked list to store it. All the jump objects could be
put together with related flow tables.

Signed-off-by: Bing Zhao <bingz@mellanox.com>
Signed-off-by: Bing Zhao <bingz@mtbc-r640-01.mtbc.labs.mlnx>
---
 drivers/net/mlx5/mlx5.h         |  1 -
 drivers/net/mlx5/mlx5_flow.h    |  7 ++--
 drivers/net/mlx5/mlx5_flow_dv.c | 82 +++++++++++++++++------------------------
 3 files changed, 37 insertions(+), 53 deletions(-)

diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 2f4ccb7..021c9db 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -674,7 +674,6 @@ struct mlx5_ibv_shared {
 	LIST_HEAD(encap_decap, mlx5_flow_dv_encap_decap_resource) encaps_decaps;
 	LIST_HEAD(modify_cmd, mlx5_flow_dv_modify_hdr_resource) modify_cmds;
 	LIST_HEAD(tag, mlx5_flow_dv_tag_resource) tags;
-	LIST_HEAD(jump, mlx5_flow_dv_jump_tbl_resource) jump_tbl;
 	LIST_HEAD(port_id_action_list, mlx5_flow_dv_port_id_action_resource)
 		port_id_action_list; /* List of port ID actions. */
 	LIST_HEAD(push_vlan_action_list, mlx5_flow_dv_push_vlan_action_resource)
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index c0fc357..7bcdd5f 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -394,12 +394,9 @@ struct mlx5_flow_dv_modify_hdr_resource {
 
 /* Jump action resource structure. */
 struct mlx5_flow_dv_jump_tbl_resource {
-	LIST_ENTRY(mlx5_flow_dv_jump_tbl_resource) next;
-	/* Pointer to next element. */
 	rte_atomic32_t refcnt; /**< Reference counter. */
-	void *action; /**< Pointer to the rdma core action. */
 	uint8_t ft_type; /**< Flow table type, Rx or Tx. */
-	struct mlx5_flow_tbl_resource *tbl; /**< The target table. */
+	void *action; /**< Pointer to the rdma core action. */
 };
 
 /* Port ID resource structure. */
@@ -443,6 +440,8 @@ struct mlx5_flow_tbl_data_entry {
 	/**< flow table resource, better to locate at the beginning. */
 	struct mlx5_flow_tbl_resource tbl;
 	/**< flow table resource, better to locate at the beginning. */
+	struct mlx5_flow_dv_jump_tbl_resource jump;
+	/**< jump resource, at most one for each table created. */
 };
 
 /*
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index a2963de..d3faac3 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -2292,8 +2292,8 @@ struct field_modify_info modify_tcp[] = {
  *
  * @param[in, out] dev
  *   Pointer to rte_eth_dev structure.
- * @param[in, out] resource
- *   Pointer to jump table resource.
+ * @param[in, out] tbl
+ *   Pointer to flow table resource.
  * @parm[in, out] dev_flow
  *   Pointer to the dev_flow.
  * @param[out] error
@@ -2304,49 +2304,34 @@ struct field_modify_info modify_tcp[] = {
  */
 static int
 flow_dv_jump_tbl_resource_register
-			(struct rte_eth_dev *dev,
-			 struct mlx5_flow_dv_jump_tbl_resource *resource,
+			(struct rte_eth_dev *dev __rte_unused,
+			 struct mlx5_flow_tbl_resource *tbl,
 			 struct mlx5_flow *dev_flow,
 			 struct rte_flow_error *error)
 {
-	struct mlx5_priv *priv = dev->data->dev_private;
-	struct mlx5_ibv_shared *sh = priv->sh;
-	struct mlx5_flow_dv_jump_tbl_resource *cache_resource;
+	struct mlx5_flow_tbl_data_entry *tbl_data =
+		container_of(tbl, struct mlx5_flow_tbl_data_entry, tbl);
+	int cnt;
 
-	/* Lookup a matching resource from cache. */
-	LIST_FOREACH(cache_resource, &sh->jump_tbl, next) {
-		if (resource->tbl == cache_resource->tbl) {
-			DRV_LOG(DEBUG, "jump table resource resource %p: refcnt %d++",
-				(void *)cache_resource,
-				rte_atomic32_read(&cache_resource->refcnt));
-			rte_atomic32_inc(&cache_resource->refcnt);
-			dev_flow->dv.jump = cache_resource;
-			return 0;
-		}
-	}
-	/* Register new jump table resource. */
-	cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);
-	if (!cache_resource)
-		return rte_flow_error_set(error, ENOMEM,
-					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
-					  "cannot allocate resource memory");
-	*cache_resource = *resource;
-	cache_resource->action =
-		mlx5_glue->dr_create_flow_action_dest_flow_tbl
-		(resource->tbl->obj);
-	if (!cache_resource->action) {
-		rte_free(cache_resource);
-		return rte_flow_error_set(error, ENOMEM,
-					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
-					  NULL, "cannot create action");
+	assert(tbl);
+	cnt = rte_atomic32_read(&tbl_data->jump.refcnt);
+	if (!cnt) {
+		tbl_data->jump.action =
+			mlx5_glue->dr_create_flow_action_dest_flow_tbl
+			(tbl->obj);
+		if (!tbl_data->jump.action)
+			return rte_flow_error_set(error, ENOMEM,
+					RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					NULL, "cannot create jump action");
+		DRV_LOG(DEBUG, "new jump table resource %p: refcnt %d++",
+			(void *)&tbl_data->jump, cnt);
+	} else {
+		assert(tbl_data->jump.action);
+		DRV_LOG(DEBUG, "existed jump table resource %p: refcnt %d++",
+			(void *)&tbl_data->jump, cnt);
 	}
-	rte_atomic32_init(&cache_resource->refcnt);
-	rte_atomic32_inc(&cache_resource->refcnt);
-	LIST_INSERT_HEAD(&sh->jump_tbl, cache_resource, next);
-	dev_flow->dv.jump = cache_resource;
-	DRV_LOG(DEBUG, "new jump table  resource %p: refcnt %d++",
-		(void *)cache_resource,
-		rte_atomic32_read(&cache_resource->refcnt));
+	rte_atomic32_inc(&tbl_data->jump.refcnt);
+	dev_flow->dv.jump = &tbl_data->jump;
 	return 0;
 }
 
@@ -6238,6 +6223,8 @@ struct field_modify_info modify_tcp[] = {
 	 * count before insert it into the hash list.
 	 */
 	rte_atomic32_init(&tbl->refcnt);
+	/* Jump action reference count is initialized here. */
+	rte_atomic32_init(&tbl_data->jump.refcnt);
 	pos->key = table_key.v64;
 	ret = mlx5_hlist_insert(sh->flow_tbls, pos);
 	if (ret < 0) {
@@ -6648,7 +6635,6 @@ struct field_modify_info modify_tcp[] = {
 		const uint8_t *rss_key;
 		const struct rte_flow_action_jump *jump_data;
 		const struct rte_flow_action_meter *mtr;
-		struct mlx5_flow_dv_jump_tbl_resource jump_tbl_resource;
 		struct mlx5_flow_tbl_resource *tbl;
 		uint32_t port_id = 0;
 		struct mlx5_flow_dv_port_id_action_resource port_id_resource;
@@ -6913,9 +6899,8 @@ struct field_modify_info modify_tcp[] = {
 						 RTE_FLOW_ERROR_TYPE_ACTION,
 						 NULL,
 						 "cannot create jump action.");
-			jump_tbl_resource.tbl = tbl;
 			if (flow_dv_jump_tbl_resource_register
-			    (dev, &jump_tbl_resource, dev_flow, error)) {
+			    (dev, tbl, dev_flow, error)) {
 				flow_dv_tbl_resource_release(dev, tbl);
 				return rte_flow_error_set
 						(error, errno,
@@ -7477,8 +7462,10 @@ struct field_modify_info modify_tcp[] = {
 flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev,
 				  struct mlx5_flow *flow)
 {
-	struct mlx5_flow_dv_jump_tbl_resource *cache_resource =
-						flow->dv.jump;
+	struct mlx5_flow_dv_jump_tbl_resource *cache_resource = flow->dv.jump;
+	struct mlx5_flow_tbl_data_entry *tbl_data =
+			container_of(cache_resource,
+				     struct mlx5_flow_tbl_data_entry, jump);
 
 	assert(cache_resource->action);
 	DRV_LOG(DEBUG, "jump table resource %p: refcnt %d--",
@@ -7487,9 +7474,8 @@ struct field_modify_info modify_tcp[] = {
 	if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {
 		claim_zero(mlx5_glue->destroy_flow_action
 				(cache_resource->action));
-		LIST_REMOVE(cache_resource, next);
-		flow_dv_tbl_resource_release(dev, cache_resource->tbl);
-		rte_free(cache_resource);
+		/* jump action memory free is inside the table release. */
+		flow_dv_tbl_resource_release(dev, &tbl_data->tbl);
 		DRV_LOG(DEBUG, "jump table resource %p: removed",
 			(void *)cache_resource);
 		return 0;
-- 
1.8.3.1


  parent reply	other threads:[~2019-11-08 15:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-08  4:44 [dpdk-dev] [PATCH 0/3] Reorganize resources of flow tables Bing Zhao
2019-11-08  4:44 ` [dpdk-dev] [PATCH 1/3] net/mlx5: reorganize flow tables with hash list Bing Zhao
2019-11-08  8:15   ` Slava Ovsiienko
2019-11-08 15:23   ` [dpdk-dev] [PATCH v2 0/3] Reorganize resources of flow tables Bing Zhao
2019-11-08 15:23     ` [dpdk-dev] [PATCH v2 1/3] net/mlx5: reorganize flow tables with hash list Bing Zhao
2019-11-08 15:23     ` Bing Zhao [this message]
2019-11-08 15:23     ` [dpdk-dev] [PATCH v2 3/3] net/mlx5: reorganize flow matcher resources Bing Zhao
2019-11-08 15:56     ` [dpdk-dev] [PATCH v2 0/3] Reorganize resources of flow tables Raslan Darawsheh
2019-11-08  4:44 ` [dpdk-dev] [PATCH 2/3] net/mlx5: reorganize jump table resources Bing Zhao
2019-11-08  6:38   ` Slava Ovsiienko
2019-11-08  4:44 ` [dpdk-dev] [PATCH 3/3] net/mlx5: reorganize flow matcher resources Bing Zhao
2019-11-08  8:16   ` Slava Ovsiienko
2019-11-08  6:37 ` [dpdk-dev] [PATCH 0/3] Reorganize resources of flow tables Slava Ovsiienko

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=1573226590-69757-3-git-send-email-bingz@pegasus02.mtr.labs.mlnx \
    --to=bingz@mellanox.com \
    --cc=bingz@mtbc-r640-01.mtbc.labs.mlnx \
    --cc=dev@dpdk.org \
    --cc=orika@mellanox.com \
    --cc=rasland@mellanox.com \
    --cc=viacheslavo@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).