patch 'net/mlx5: fix flow workspace destruction' has been queued to stable release 22.11.3
Xueming Li
xuemingl at nvidia.com
Thu Aug 10 01:59:01 CEST 2023
Hi,
FYI, your patch has been queued to stable release 22.11.3
Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 08/11/23. So please
shout if anyone has objections.
Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.
Queued patches are on a temporary branch at:
https://git.dpdk.org/dpdk-stable/log/?h=22.11-staging
This queued commit can be viewed at:
https://git.dpdk.org/dpdk-stable/commit/?h=22.11-staging&id=68b7edcd1e6fb1cb855de0f6a98979d5bbdaba50
Thanks.
Xueming Li <xuemingl at nvidia.com>
---
>From 68b7edcd1e6fb1cb855de0f6a98979d5bbdaba50 Mon Sep 17 00:00:00 2001
From: Gregory Etelson <getelson at nvidia.com>
Date: Mon, 3 Jul 2023 12:50:52 +0300
Subject: [PATCH] net/mlx5: fix flow workspace destruction
Cc: Xueming Li <xuemingl at nvidia.com>
[ upstream commit dc7c5e0aa905b675c56a66b2014b01b7f5ae8a1d ]
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")
Reported-by: David Marchand <david.marchand at redhat.com>
Signed-off-by: Gregory Etelson <getelson at nvidia.com>
Signed-off-by: Bing Zhao <bingz at nvidia.com>
Acked-by: Matan Azrad <matan at nvidia.com>
---
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(-)
diff --git a/drivers/net/mlx5/linux/mlx5_flow_os.c b/drivers/net/mlx5/linux/mlx5_flow_os.c
index 3c9a823edf..b139bb75b9 100644
--- a/drivers/net/mlx5/linux/mlx5_flow_os.c
+++ b/drivers/net/mlx5/linux/mlx5_flow_os.c
@@ -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;
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index b8643cebdd..79ccea5003 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -1730,6 +1730,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) {
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 54cab0ec05..a359f1e97c 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -6931,36 +6931,6 @@ flow_tunnel_from_rule(const struct mlx5_flow *flow)
return tunnel;
}
-/**
- * Adjust flow RSS workspace if needed.
- *
- * @param wks
- * Pointer to thread flow work space.
- * @param rss_desc
- * Pointer to RSS descriptor.
- * @param[in] nrssq_num
- * New RSS queue number.
- *
- * @return
- * 0 on success, -1 otherwise and rte_errno is set.
- */
-static int
-flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks,
- struct mlx5_flow_rss_desc *rss_desc,
- uint32_t nrssq_num)
-{
- if (likely(nrssq_num <= wks->rssq_num))
- return 0;
- rss_desc->queue = realloc(rss_desc->queue,
- sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2));
- if (!rss_desc->queue) {
- rte_errno = ENOMEM;
- return -1;
- }
- wks->rssq_num = RTE_ALIGN(nrssq_num, 2);
- return 0;
-}
-
/**
* Create a flow and add it to @p list.
*
@@ -7079,8 +7049,7 @@ flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
if (attr->ingress)
rss = flow_get_rss_action(dev, p_actions_rx);
if (rss) {
- if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num))
- return 0;
+ MLX5_ASSERT(rss->queue_num <= RTE_ETH_RSS_RETA_SIZE_512);
/*
* The following information is required by
* mlx5_flow_hashfields_adjust() in advance.
@@ -7568,12 +7537,34 @@ flow_release_workspace(void *data)
while (wks) {
next = wks->next;
- free(wks->rss_desc.queue);
free(wks);
wks = next;
}
}
+static struct mlx5_flow_workspace *gc_head;
+static rte_spinlock_t mlx5_flow_workspace_lock = RTE_SPINLOCK_INITIALIZER;
+
+static void
+mlx5_flow_workspace_gc_add(struct mlx5_flow_workspace *ws)
+{
+ rte_spinlock_lock(&mlx5_flow_workspace_lock);
+ ws->gc = gc_head;
+ gc_head = ws;
+ rte_spinlock_unlock(&mlx5_flow_workspace_lock);
+}
+
+void
+mlx5_flow_workspace_gc_release(void)
+{
+ while (gc_head) {
+ struct mlx5_flow_workspace *wks = gc_head;
+
+ gc_head = wks->gc;
+ flow_release_workspace(wks);
+ }
+}
+
/**
* Get thread specific current flow workspace.
*
@@ -7599,23 +7590,17 @@ mlx5_flow_get_thread_workspace(void)
static struct mlx5_flow_workspace*
flow_alloc_thread_workspace(void)
{
- struct mlx5_flow_workspace *data = calloc(1, sizeof(*data));
+ size_t data_size = RTE_ALIGN(sizeof(struct mlx5_flow_workspace), sizeof(long));
+ size_t rss_queue_array_size = sizeof(uint16_t) * RTE_ETH_RSS_RETA_SIZE_512;
+ struct mlx5_flow_workspace *data = calloc(1, data_size +
+ rss_queue_array_size);
if (!data) {
- DRV_LOG(ERR, "Failed to allocate flow workspace "
- "memory.");
+ DRV_LOG(ERR, "Failed to allocate flow workspace memory.");
return NULL;
}
- data->rss_desc.queue = calloc(1,
- sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM);
- if (!data->rss_desc.queue)
- goto err;
- data->rssq_num = MLX5_RSSQ_DEFAULT_NUM;
+ data->rss_desc.queue = RTE_PTR_ADD(data, data_size);
return data;
-err:
- free(data->rss_desc.queue);
- free(data);
- return NULL;
}
/**
@@ -7636,6 +7621,7 @@ mlx5_flow_push_thread_workspace(void)
data = flow_alloc_thread_workspace();
if (!data)
return NULL;
+ mlx5_flow_workspace_gc_add(data);
} else if (!curr->inuse) {
data = curr;
} else if (curr->next) {
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index f4eecbcb0a..9724b88996 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -1437,10 +1437,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;
@@ -1926,6 +1926,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;
--
2.25.1
---
Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- - 2023-08-09 21:51:20.304573600 +0800
+++ 0082-net-mlx5-fix-flow-workspace-destruction.patch 2023-08-09 21:51:18.244352000 +0800
@@ -1 +1 @@
-From dc7c5e0aa905b675c56a66b2014b01b7f5ae8a1d Mon Sep 17 00:00:00 2001
+From 68b7edcd1e6fb1cb855de0f6a98979d5bbdaba50 Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit dc7c5e0aa905b675c56a66b2014b01b7f5ae8a1d ]
@@ -25 +27,0 @@
-Cc: stable at dpdk.org
@@ -52 +54 @@
-index 5f0aa296ba..fd9b76027d 100644
+index b8643cebdd..79ccea5003 100644
@@ -55 +57 @@
-@@ -1838,6 +1838,7 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
+@@ -1730,6 +1730,7 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
@@ -64 +66 @@
-index abb86241fc..1071ef0c3e 100644
+index 54cab0ec05..a359f1e97c 100644
@@ -67 +69 @@
-@@ -7155,36 +7155,6 @@ flow_tunnel_from_rule(const struct mlx5_flow *flow)
+@@ -6931,36 +6931,6 @@ flow_tunnel_from_rule(const struct mlx5_flow *flow)
@@ -104 +106 @@
-@@ -7303,8 +7273,7 @@ flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
+@@ -7079,8 +7049,7 @@ flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
@@ -114 +116 @@
-@@ -8072,12 +8041,34 @@ flow_release_workspace(void *data)
+@@ -7568,12 +7537,34 @@ flow_release_workspace(void *data)
@@ -150 +152 @@
-@@ -8103,23 +8094,17 @@ mlx5_flow_get_thread_workspace(void)
+@@ -7599,23 +7590,17 @@ mlx5_flow_get_thread_workspace(void)
@@ -180 +182 @@
-@@ -8140,6 +8125,7 @@ mlx5_flow_push_thread_workspace(void)
+@@ -7636,6 +7621,7 @@ mlx5_flow_push_thread_workspace(void)
@@ -189 +191 @@
-index 003e7da3a6..62789853ab 100644
+index f4eecbcb0a..9724b88996 100644
@@ -192 +194 @@
-@@ -1496,10 +1496,10 @@ struct mlx5_flow_workspace {
+@@ -1437,10 +1437,10 @@ struct mlx5_flow_workspace {
@@ -204 +206 @@
-@@ -2022,6 +2022,8 @@ struct mlx5_flow_driver_ops {
+@@ -1926,6 +1926,8 @@ struct mlx5_flow_driver_ops {
More information about the stable
mailing list