Skip to contentSkip to conversation

net/mlx5: fix flow workspace destruction

PATCH Superseded Bing Zhao 3 participants 5 messages Jul 1, 2023 – Jul 3, 2023 Network drivers

lore
Share & tools
lore

Bing Zhao

author
#0 lore raw

PATCH 1/1 net/mlx5: fix flow workspace destruction

From: Gregory Etelson <[email protected]>

PMD uses pthread key to allocate and access per thread flow workspace memory buffers.

PMD registered a key destructor function to clean up flow workspace buffers. However, the key destructor was not called by the pthread library.

The patch keeps track of per-thread flow workspaces in PMD. Flow workspaces memory release is activated from PMD destructor.

In the meanwhile, workspace buffer and RSS queues array are allocated in a single memory chunk with this patch. The maximal number of queues RTE_ETH_RSS_RETA_SIZE_512 is chosen. Then the workspace adjustment can be removed to reduce the software hiccup:
1. realloc and content copy
2. spinlock aquire and release

Fixes 5d55a494f4e6 ("net/mlx5: split multi-thread flow handling per OS")
---
 drivers/net/mlx5/linux/mlx5_flow_os.c |  2 +-
 drivers/net/mlx5/mlx5.c               |  1 +
 drivers/net/mlx5/mlx5_flow.c          | 76 +++++++++++----------------
 drivers/net/mlx5/mlx5_flow.h          |  4 +-
 4 files changed, 36 insertions(+), 47 deletions(-)
drivers/net/mlx5/linux/mlx5_flow_os.c +1 -1
index 3c9a823edf..b139bb75b9 100644
@@ -51,7 +51,7 @@ mlx5_flow_os_validate_item_esp(const struct rte_flow_item *item,
 int
 mlx5_flow_os_init_workspace_once(void)
 {
-	if (rte_thread_key_create(&key_workspace, flow_release_workspace)) {
+	if (rte_thread_key_create(&key_workspace, NULL)) {
 		DRV_LOG(ERR, "Can't create flow workspace data thread key.");
 		rte_errno = ENOMEM;
 		return -rte_errno;
drivers/net/mlx5/mlx5.c +1 -0
index 5f0aa296ba..fd9b76027d 100644
@@ -1838,6 +1838,7 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
 	if (LIST_EMPTY(&mlx5_dev_ctx_list)) {
 		mlx5_os_net_cleanup();
 		mlx5_flow_os_release_workspace();
+		mlx5_flow_workspace_gc_release();
 	}
 	pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
 	if (sh->flex_parsers_dv) {
drivers/net/mlx5/mlx5_flow.c +31 -45

116 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +3 -1
index 003e7da3a6..62789853ab 100644
@@ -1496,10 +1496,10 @@ struct mlx5_flow_workspace {
 	/* If creating another flow in same thread, push new as stack. */
 	struct mlx5_flow_workspace *prev;
 	struct mlx5_flow_workspace *next;
+	struct mlx5_flow_workspace *gc;
 	uint32_t inuse; /* can't create new flow with current. */
 	struct mlx5_flow flows[MLX5_NUM_MAX_DEV_FLOWS];
 	struct mlx5_flow_rss_desc rss_desc;
-	uint32_t rssq_num; /* Allocated queue num in rss_desc. */
 	uint32_t flow_idx; /* Intermediate device flow index. */
 	struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */
 	struct mlx5_flow_meter_policy *policy;
@@ -2022,6 +2022,8 @@ struct mlx5_flow_driver_ops {
 struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void);
 void mlx5_flow_pop_thread_workspace(void);
 struct mlx5_flow_workspace *mlx5_flow_get_thread_workspace(void);
+void mlx5_flow_workspace_gc_release(void);
+
 __extension__
 struct flow_grp_info {
 	uint64_t external:1;
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/1 net/mlx5: fix flow workspace destruction

From: Gregory Etelson <[email protected]>

PMD uses pthread key to allocate and access per thread flow workspace memory buffers.

PMD registered a key destructor function to clean up flow workspace buffers. However, the key destructor was not called by the pthread library.

The patch keeps track of per-thread flow workspaces in PMD. Flow workspaces memory release is activated from PMD destructor.

In the meanwhile, workspace buffer and RSS queues array are allocated in a single memory chunk with this patch. The maximal number of queues RTE_ETH_RSS_RETA_SIZE_512 is chosen. Then the workspace adjustment can be removed to reduce the software hiccup:
1. realloc and content copy
2. spinlock acquire and release

Fixes 5d55a494f4e6 ("net/mlx5: split multi-thread flow handling per OS")

---
v2: fix typo in the commit message and remove the needless NULL
pointer initialization for static variable.

---
 drivers/net/mlx5/linux/mlx5_flow_os.c |  2 +-
 drivers/net/mlx5/mlx5.c               |  1 +
 drivers/net/mlx5/mlx5_flow.c          | 76 +++++++++++----------------
 drivers/net/mlx5/mlx5_flow.h          |  4 +-
 4 files changed, 36 insertions(+), 47 deletions(-)
drivers/net/mlx5/linux/mlx5_flow_os.c +1 -1
index 3c9a823edf..b139bb75b9 100644
@@ -51,7 +51,7 @@ mlx5_flow_os_validate_item_esp(const struct rte_flow_item *item,
 int
 mlx5_flow_os_init_workspace_once(void)
 {
-	if (rte_thread_key_create(&key_workspace, flow_release_workspace)) {
+	if (rte_thread_key_create(&key_workspace, NULL)) {
 		DRV_LOG(ERR, "Can't create flow workspace data thread key.");
 		rte_errno = ENOMEM;
 		return -rte_errno;
drivers/net/mlx5/mlx5.c +1 -0
index 5f0aa296ba..fd9b76027d 100644
@@ -1838,6 +1838,7 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
 	if (LIST_EMPTY(&mlx5_dev_ctx_list)) {
 		mlx5_os_net_cleanup();
 		mlx5_flow_os_release_workspace();
+		mlx5_flow_workspace_gc_release();
 	}
 	pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
 	if (sh->flex_parsers_dv) {
drivers/net/mlx5/mlx5_flow.c +31 -45

116 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +3 -1
index 003e7da3a6..62789853ab 100644
@@ -1496,10 +1496,10 @@ struct mlx5_flow_workspace {
 	/* If creating another flow in same thread, push new as stack. */
 	struct mlx5_flow_workspace *prev;
 	struct mlx5_flow_workspace *next;
+	struct mlx5_flow_workspace *gc;
 	uint32_t inuse; /* can't create new flow with current. */
 	struct mlx5_flow flows[MLX5_NUM_MAX_DEV_FLOWS];
 	struct mlx5_flow_rss_desc rss_desc;
-	uint32_t rssq_num; /* Allocated queue num in rss_desc. */
 	uint32_t flow_idx; /* Intermediate device flow index. */
 	struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */
 	struct mlx5_flow_meter_policy *policy;
@@ -2022,6 +2022,8 @@ struct mlx5_flow_driver_ops {
 struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void);
 void mlx5_flow_pop_thread_workspace(void);
 struct mlx5_flow_workspace *mlx5_flow_get_thread_workspace(void);
+void mlx5_flow_workspace_gc_release(void);
+
 __extension__
 struct flow_grp_info {
 	uint64_t external:1;
Signature · 1 line
2.34.1
Acked-by on v2 1/1
#2 lore raw

From: Bing Zhao <[email protected]>

Quoted 16 lines

PMD uses pthread key to allocate and access per thread flow workspace memory buffers.

PMD registered a key destructor function to clean up flow workspace buffers. However, the key destructor was not called by the pthread library.

The patch keeps track of per-thread flow workspaces in PMD. Flow workspaces memory release is activated from PMD destructor.

In the meanwhile, workspace buffer and RSS queues array are allocated in a single memory chunk with this patch. The maximal number of queues RTE_ETH_RSS_RETA_SIZE_512 is chosen. Then the workspace adjustment can be removed to reduce the software hiccup:
1. realloc and content copy
2. spinlock acquire and release

Quoted 5 lines
Fixes 5d55a494f4e6 ("net/mlx5: split multi-thread flow handling per OS")
author
#3 lore raw

PATCH v3 1/1 net/mlx5: fix flow workspace destruction

In reply to Bing Zhao

From: Gregory Etelson <[email protected]>

PMD uses pthread key to allocate and access per thread flow workspace memory buffers.

PMD registered a key destructor function to clean up flow workspace buffers. However, the key destructor was not called by the pthread library.

The patch keeps track of per-thread flow workspaces in PMD. Flow workspaces memory release is activated from PMD destructor.

In the meanwhile, workspace buffer and RSS queues array are allocated in a single memory chunk with this patch. The maximal number of queues RTE_ETH_RSS_RETA_SIZE_512 is chosen. Then the workspace adjustment can be removed to reduce the software hiccup:
1. realloc and content copy
2. spinlock acquire and release

Bugzilla ID: 1255

Fixes 5d55a494f4e6 ("net/mlx5: split multi-thread flow handling per OS")

---
v2: fix typo and code style
v3: add bugzilla information

---
 drivers/net/mlx5/linux/mlx5_flow_os.c |  2 +-
 drivers/net/mlx5/mlx5.c               |  1 +
 drivers/net/mlx5/mlx5_flow.c          | 76 +++++++++++----------------
 drivers/net/mlx5/mlx5_flow.h          |  4 +-
 4 files changed, 36 insertions(+), 47 deletions(-)
drivers/net/mlx5/linux/mlx5_flow_os.c +1 -1
index 3c9a823edf..b139bb75b9 100644
@@ -51,7 +51,7 @@ mlx5_flow_os_validate_item_esp(const struct rte_flow_item *item,
 int
 mlx5_flow_os_init_workspace_once(void)
 {
-	if (rte_thread_key_create(&key_workspace, flow_release_workspace)) {
+	if (rte_thread_key_create(&key_workspace, NULL)) {
 		DRV_LOG(ERR, "Can't create flow workspace data thread key.");
 		rte_errno = ENOMEM;
 		return -rte_errno;
drivers/net/mlx5/mlx5.c +1 -0
index 5f0aa296ba..fd9b76027d 100644
@@ -1838,6 +1838,7 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
 	if (LIST_EMPTY(&mlx5_dev_ctx_list)) {
 		mlx5_os_net_cleanup();
 		mlx5_flow_os_release_workspace();
+		mlx5_flow_workspace_gc_release();
 	}
 	pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
 	if (sh->flex_parsers_dv) {
drivers/net/mlx5/mlx5_flow.c +31 -45

116 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +3 -1
index 003e7da3a6..62789853ab 100644
@@ -1496,10 +1496,10 @@ struct mlx5_flow_workspace {
 	/* If creating another flow in same thread, push new as stack. */
 	struct mlx5_flow_workspace *prev;
 	struct mlx5_flow_workspace *next;
+	struct mlx5_flow_workspace *gc;
 	uint32_t inuse; /* can't create new flow with current. */
 	struct mlx5_flow flows[MLX5_NUM_MAX_DEV_FLOWS];
 	struct mlx5_flow_rss_desc rss_desc;
-	uint32_t rssq_num; /* Allocated queue num in rss_desc. */
 	uint32_t flow_idx; /* Intermediate device flow index. */
 	struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */
 	struct mlx5_flow_meter_policy *policy;
@@ -2022,6 +2022,8 @@ struct mlx5_flow_driver_ops {
 struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void);
 void mlx5_flow_pop_thread_workspace(void);
 struct mlx5_flow_workspace *mlx5_flow_get_thread_workspace(void);
+void mlx5_flow_workspace_gc_release(void);
+
 __extension__
 struct flow_grp_info {
 	uint64_t external:1;
Signature · 1 line
2.34.1
#4 lore raw

Hi,

Quoted 33 lines

-----Original Message-----
From: Bing Zhao <[email protected]>
Sent: Monday, July 3, 2023 12:51 PM
To: Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Raslan Darawsheh <[email protected]>
Cc: [email protected]; Gregory Etelson <[email protected]>; [email protected]; David Marchand <[email protected]>
Subject: [PATCH v3] net/mlx5: fix flow workspace destruction

From: Gregory Etelson <[email protected]>

PMD uses pthread key to allocate and access per thread flow workspace memory buffers.

PMD registered a key destructor function to clean up flow workspace buffers. However, the key destructor was not called by the pthread library.

The patch keeps track of per-thread flow workspaces in PMD. Flow workspaces memory release is activated from PMD destructor.

In the meanwhile, workspace buffer and RSS queues array are allocated in a single memory chunk with this patch. The maximal number of queues RTE_ETH_RSS_RETA_SIZE_512 is chosen. Then the workspace adjustment can be removed to reduce the software hiccup:
1. realloc and content copy
2. spinlock acquire and release

Bugzilla ID: 1255

Fixes 5d55a494f4e6 ("net/mlx5: split multi-thread flow handling per OS")
Quoted 7 lines

---
v2: fix typo and code style
v3: add bugzilla information

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh