mlx5: split multi-threaded flows per OS
Subsystems (2)
PATCH 1/1 mlx5: split multi-threaded flows per OS
multi-threaded flows feature uses pthread function pthread_key_create but for Windows the destruction option in the function is unimplemented.
to resolve it Windows will implement destruction mechanism to cleanup mlx5_flow_workspace object for each terminated thread.
Linux flow will keep the current behavior.
---
Depends-on: patch-85737 ("eal: add generic thread-local-storage functions")
--- drivers/net/mlx5/linux/meson.build | 1 + drivers/net/mlx5/linux/mlx5_flow_os.c | 39 +++++++ drivers/net/mlx5/mlx5.c | 8 ++ drivers/net/mlx5/mlx5_flow.c | 29 +----- drivers/net/mlx5/mlx5_flow.h | 10 ++ drivers/net/mlx5/windows/mlx5_flow_os.c | 174 ++++++++++++++++++++++++++++++++ 6 files changed, 237 insertions(+), 24 deletions(-) create mode 100644 drivers/net/mlx5/linux/mlx5_flow_os.c
drivers/net/mlx5/linux/meson.build +1 -0
@@ -9,5 +9,6 @@ sources += files( 'mlx5_verbs.c', 'mlx5_mp_os.c', 'mlx5_vlan_os.c', + 'mlx5_flow_os.c', )
drivers/net/mlx5/linux/mlx5_flow_os.c new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2020 Mellanox Technologies, Ltd +*/ + +#include "mlx5_flow_os.h" + +#include <rte_thread.h> + +/* Key of thread specific flow workspace data. */ +static rte_tls_key key_workspace; + +int +mlx5_flow_os_init_workspace_once (void ) +{ +if (rte_thread_tls_create_key (&key_workspace, flow_release_workspace)) { +DRV_LOG (ERR ,"Can't create flow workspace data thread key." ); +return ENOMEM ; + } +return 0 ; +} + +void * +mlx5_flow_os_get_specific_workspace (void ) +{ +return rte_thread_tls_get_value (key_workspace); +} + +int +mlx5_flow_os_set_specific_workspace (struct mlx5_flow_workspace *data) +{ +return rte_thread_tls_set_value (key_workspace, data); +} + +void +mlx5_flow_os_release_workspace (void ) +{ +rte_thread_tls_delete_key (key_workspace); +} +
drivers/net/mlx5/mlx5.c +8 -0
@@ -1004,6 +1004,11 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, err = rte_errno; goto error; } +if (LIST_EMPTY (&mlx5_dev_ctx_list)) { + err =mlx5_flow_os_init_workspace_once (); +if (err) + goto error; + }mlx5_flow_aging_init (sh);mlx5_flow_counters_mng_init (sh);mlx5_flow_ipool_create (sh, config);
@@ -1079,6 +1084,9 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)mlx5_mr_release_cache (&sh->share_cache);/* Remove context from the global device list. */ LIST_REMOVE (sh, next); +/* Release flow workspaces objects on the last device. */ +if (LIST_EMPTY (&mlx5_dev_ctx_list)) +mlx5_flow_os_release_workspace ();pthread_mutex_unlock (&mlx5_dev_ctx_list_mutex);/* * Ensure there is no async event handler installed.
drivers/net/mlx5/mlx5_flow.c +5 -24
@@ -696,11 +696,6 @@ static struct mlx5_flow_tunnel_info tunnels_info[] = { }, }; -/* Key of thread specific flow workspace data. */ -static pthread_key_t key_workspace; - -/* Thread specific flow workspace data once initialization data. */ -static pthread_once_t key_workspace_init;/**
@@ -5698,7 +5693,7 @@ mlx5_flow_start_default(struct rte_eth_dev *dev)/** * Release key of thread specific flow workspace data. */ -static void +void flow_release_workspace (void *data) {struct mlx5_flow_workspace *wks = data;
@@ -5712,16 +5707,6 @@ flow_release_workspace(void *data) } } -/** -* Initialize key of thread specific flow workspace data. -*/ -static void -flow_alloc_workspace (void ) -{ -if (pthread_key_create (&key_workspace, flow_release_workspace)) -DRV_LOG (ERR ,"Can't create flow workspace data thread key." ); -} -/** * Get thread specific current flow workspace. *
@@ -5732,7 +5717,7 @@ mlx5_flow_get_thread_workspace(void) {struct mlx5_flow_workspace *data; - data =pthread_getspecific (key_workspace); + data =mlx5_flow_os_get_specific_workspace ();MLX5_ASSERT (data && data->inuse);if (!data || !data->inuse)DRV_LOG (ERR ,"flow workspace not initialized." );
@@ -5780,11 +5765,7 @@ mlx5_flow_push_thread_workspace(void)struct mlx5_flow_workspace *curr;struct mlx5_flow_workspace *data; -if (pthread_once (&key_workspace_init, flow_alloc_workspace)) { -DRV_LOG (ERR ,"Failed to init flow workspace data thread key." ); -return NULL ; - } - curr =pthread_getspecific (key_workspace); + curr =mlx5_flow_os_get_specific_workspace ();if (!curr) { data =flow_alloc_thread_workspace ();if (!data)
@@ -5803,7 +5784,7 @@ mlx5_flow_push_thread_workspace(void) data->inuse =1 ; data->flow_idx =0 ;/* Set as current workspace */ -if (pthread_setspecific (key_workspace, data)) +if (mlx5_flow_os_set_specific_workspace (data))DRV_LOG (ERR ,"Failed to set flow workspace to thread." );return data; }
@@ -5829,7 +5810,7 @@ mlx5_flow_pop_thread_workspace(void) data->inuse =0 ;if (!data->prev)return ; -if (pthread_setspecific (key_workspace, data->prev)) +if (mlx5_flow_os_set_specific_workspace (data->prev))DRV_LOG (ERR ,"Failed to set flow workspace to thread." ); }
drivers/net/mlx5/mlx5_flow.h +10 -0
@@ -1503,4 +1503,14 @@ void flow_dv_dest_array_remove_cb(struct mlx5_cache_list *list, struct mlx5_cache_entry *entry);struct mlx5_aso_age_action *flow_aso_age_get_by_idx (struct rte_eth_dev *dev,uint32_t age_idx); +void +flow_release_workspace (void *data); +int +mlx5_flow_os_init_workspace_once (void ); +void * +mlx5_flow_os_get_specific_workspace (void ); +int +mlx5_flow_os_set_specific_workspace (struct mlx5_flow_workspace *data); +void +mlx5_flow_os_release_workspace (void );#endif /* RTE_PMD_MLX5_FLOW_H_ */
drivers/net/mlx5/windows/mlx5_flow_os.c +174 -0
183 lines not on this page · raw message
Signature · 1 line
2.16.1.windows.4
PATCH v2 1/1 mlx5: split multi-threaded flows per OS
multi-threaded flows feature uses pthread function pthread_key_create but for Windows the destruction option in the function is unimplemented.
to resolve it Windows will implement destruction mechanism to cleanup mlx5_flow_workspace object for each terminated thread.
Linux flow will keep the current behavior.
---
Depends-on: patch-85737 ("eal: add generic thread-local-storage functions")
v2: fix style issues
--- drivers/net/mlx5/linux/meson.build | 1 + drivers/net/mlx5/linux/mlx5_flow_os.c | 39 +++++++ drivers/net/mlx5/mlx5.c | 8 ++ drivers/net/mlx5/mlx5_flow.c | 29 +----- drivers/net/mlx5/mlx5_flow.h | 10 ++ drivers/net/mlx5/windows/mlx5_flow_os.c | 179 ++++++++++++++++++++++++++++++++ 6 files changed, 242 insertions(+), 24 deletions(-) create mode 100644 drivers/net/mlx5/linux/mlx5_flow_os.c
drivers/net/mlx5/linux/meson.build +1 -0
@@ -9,5 +9,6 @@ sources += files( 'mlx5_verbs.c', 'mlx5_mp_os.c', 'mlx5_vlan_os.c', + 'mlx5_flow_os.c', )
drivers/net/mlx5/linux/mlx5_flow_os.c new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2020 Mellanox Technologies, Ltd +*/ + +#include "mlx5_flow_os.h" + +#include <rte_thread.h> + +/* Key of thread specific flow workspace data. */ +static rte_tls_key key_workspace; + +int +mlx5_flow_os_init_workspace_once (void ) +{ +if (rte_thread_tls_create_key (&key_workspace, flow_release_workspace)) { +DRV_LOG (ERR ,"Can't create flow workspace data thread key." ); +return -ENOMEM ; + } +return 0 ; +} + +void * +mlx5_flow_os_get_specific_workspace (void ) +{ +return rte_thread_tls_get_value (key_workspace); +} + +int +mlx5_flow_os_set_specific_workspace (struct mlx5_flow_workspace *data) +{ +return rte_thread_tls_set_value (key_workspace, data); +} + +void +mlx5_flow_os_release_workspace (void ) +{ +rte_thread_tls_delete_key (key_workspace); +} +
drivers/net/mlx5/mlx5.c +8 -0
@@ -1004,6 +1004,11 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, err = rte_errno; goto error; } +if (LIST_EMPTY (&mlx5_dev_ctx_list)) { + err =mlx5_flow_os_init_workspace_once (); +if (err) + goto error; + }mlx5_flow_aging_init (sh);mlx5_flow_counters_mng_init (sh);mlx5_flow_ipool_create (sh, config);
@@ -1079,6 +1084,9 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)mlx5_mr_release_cache (&sh->share_cache);/* Remove context from the global device list. */ LIST_REMOVE (sh, next); +/* Release flow workspaces objects on the last device. */ +if (LIST_EMPTY (&mlx5_dev_ctx_list)) +mlx5_flow_os_release_workspace ();pthread_mutex_unlock (&mlx5_dev_ctx_list_mutex);/* * Ensure there is no async event handler installed.
drivers/net/mlx5/mlx5_flow.c +5 -24
@@ -696,11 +696,6 @@ static struct mlx5_flow_tunnel_info tunnels_info[] = { }, }; -/* Key of thread specific flow workspace data. */ -static pthread_key_t key_workspace; - -/* Thread specific flow workspace data once initialization data. */ -static pthread_once_t key_workspace_init;/**
@@ -5698,7 +5693,7 @@ mlx5_flow_start_default(struct rte_eth_dev *dev)/** * Release key of thread specific flow workspace data. */ -static void +void flow_release_workspace (void *data) {struct mlx5_flow_workspace *wks = data;
@@ -5712,16 +5707,6 @@ flow_release_workspace(void *data) } } -/** -* Initialize key of thread specific flow workspace data. -*/ -static void -flow_alloc_workspace (void ) -{ -if (pthread_key_create (&key_workspace, flow_release_workspace)) -DRV_LOG (ERR ,"Can't create flow workspace data thread key." ); -} -/** * Get thread specific current flow workspace. *
@@ -5732,7 +5717,7 @@ mlx5_flow_get_thread_workspace(void) {struct mlx5_flow_workspace *data; - data =pthread_getspecific (key_workspace); + data =mlx5_flow_os_get_specific_workspace ();MLX5_ASSERT (data && data->inuse);if (!data || !data->inuse)DRV_LOG (ERR ,"flow workspace not initialized." );
@@ -5780,11 +5765,7 @@ mlx5_flow_push_thread_workspace(void)struct mlx5_flow_workspace *curr;struct mlx5_flow_workspace *data; -if (pthread_once (&key_workspace_init, flow_alloc_workspace)) { -DRV_LOG (ERR ,"Failed to init flow workspace data thread key." ); -return NULL ; - } - curr =pthread_getspecific (key_workspace); + curr =mlx5_flow_os_get_specific_workspace ();if (!curr) { data =flow_alloc_thread_workspace ();if (!data)
@@ -5803,7 +5784,7 @@ mlx5_flow_push_thread_workspace(void) data->inuse =1 ; data->flow_idx =0 ;/* Set as current workspace */ -if (pthread_setspecific (key_workspace, data)) +if (mlx5_flow_os_set_specific_workspace (data))DRV_LOG (ERR ,"Failed to set flow workspace to thread." );return data; }
@@ -5829,7 +5810,7 @@ mlx5_flow_pop_thread_workspace(void) data->inuse =0 ;if (!data->prev)return ; -if (pthread_setspecific (key_workspace, data->prev)) +if (mlx5_flow_os_set_specific_workspace (data->prev))DRV_LOG (ERR ,"Failed to set flow workspace to thread." ); }
drivers/net/mlx5/mlx5_flow.h +10 -0
@@ -1503,4 +1503,14 @@ void flow_dv_dest_array_remove_cb(struct mlx5_cache_list *list, struct mlx5_cache_entry *entry);struct mlx5_aso_age_action *flow_aso_age_get_by_idx (struct rte_eth_dev *dev,uint32_t age_idx); +void +flow_release_workspace (void *data); +int +mlx5_flow_os_init_workspace_once (void ); +void * +mlx5_flow_os_get_specific_workspace (void ); +int +mlx5_flow_os_set_specific_workspace (struct mlx5_flow_workspace *data); +void +mlx5_flow_os_release_workspace (void );#endif /* RTE_PMD_MLX5_FLOW_H_ */
drivers/net/mlx5/windows/mlx5_flow_os.c +179 -0
188 lines not on this page · raw message
Signature · 1 line
2.16.1.windows.4
PATCH v3 1/1 mlx5: split multi-threaded flows per OS
multi-threaded flows feature uses pthread function pthread_key_create but for Windows the destruction option in the function is unimplemented.
to resolve it Windows will implement destruction mechanism to cleanup mlx5_flow_workspace object for each terminated thread.
Linux flow will keep the current behavior.
---
Depends-on: series-14562 ("support generic threading functions")
v2: fix style issues
v3: adjust to new API, remove nl from EOFs.
---
--- drivers/net/mlx5/linux/meson.build | 1 + drivers/net/mlx5/linux/mlx5_flow_os.c | 38 +++++++ drivers/net/mlx5/mlx5.c | 8 ++ drivers/net/mlx5/mlx5_flow.c | 29 +----- drivers/net/mlx5/mlx5_flow.h | 10 ++ drivers/net/mlx5/windows/mlx5_flow_os.c | 178 ++++++++++++++++++++++++++++++++ 6 files changed, 240 insertions(+), 24 deletions(-) create mode 100644 drivers/net/mlx5/linux/mlx5_flow_os.c
drivers/net/mlx5/linux/meson.build +1 -0
@@ -9,5 +9,6 @@ sources += files( 'mlx5_verbs.c', 'mlx5_mp_os.c', 'mlx5_vlan_os.c', + 'mlx5_flow_os.c', )
drivers/net/mlx5/linux/mlx5_flow_os.c new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2020 Mellanox Technologies, Ltd +*/ + +#include "mlx5_flow_os.h" + +#include <rte_thread.h> + +/* Key of thread specific flow workspace data. */ +static rte_tls_key key_workspace; + +int +mlx5_flow_os_init_workspace_once (void ) +{ +if (rte_thread_tls_key_create (&key_workspace, flow_release_workspace)) { +DRV_LOG (ERR ,"Can't create flow workspace data thread key." ); +return -ENOMEM ; + } +return 0 ; +} + +void * +mlx5_flow_os_get_specific_workspace (void ) +{ +return rte_thread_tls_value_get (key_workspace); +} + +int +mlx5_flow_os_set_specific_workspace (struct mlx5_flow_workspace *data) +{ +return rte_thread_tls_value_set (key_workspace, data); +} + +void +mlx5_flow_os_release_workspace (void ) +{ +rte_thread_tls_key_delete (key_workspace); +}
drivers/net/mlx5/mlx5.c +8 -0
@@ -1004,6 +1004,11 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, err = rte_errno; goto error; } +if (LIST_EMPTY (&mlx5_dev_ctx_list)) { + err =mlx5_flow_os_init_workspace_once (); +if (err) + goto error; + }mlx5_flow_aging_init (sh);mlx5_flow_counters_mng_init (sh);mlx5_flow_ipool_create (sh, config);
@@ -1079,6 +1084,9 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)mlx5_mr_release_cache (&sh->share_cache);/* Remove context from the global device list. */ LIST_REMOVE (sh, next); +/* Release flow workspaces objects on the last device. */ +if (LIST_EMPTY (&mlx5_dev_ctx_list)) +mlx5_flow_os_release_workspace ();pthread_mutex_unlock (&mlx5_dev_ctx_list_mutex);/* * Ensure there is no async event handler installed.
drivers/net/mlx5/mlx5_flow.c +5 -24
@@ -696,11 +696,6 @@ static struct mlx5_flow_tunnel_info tunnels_info[] = { }, }; -/* Key of thread specific flow workspace data. */ -static pthread_key_t key_workspace; - -/* Thread specific flow workspace data once initialization data. */ -static pthread_once_t key_workspace_init;/**
@@ -5698,7 +5693,7 @@ mlx5_flow_start_default(struct rte_eth_dev *dev)/** * Release key of thread specific flow workspace data. */ -static void +void flow_release_workspace (void *data) {struct mlx5_flow_workspace *wks = data;
@@ -5712,16 +5707,6 @@ flow_release_workspace(void *data) } } -/** -* Initialize key of thread specific flow workspace data. -*/ -static void -flow_alloc_workspace (void ) -{ -if (pthread_key_create (&key_workspace, flow_release_workspace)) -DRV_LOG (ERR ,"Can't create flow workspace data thread key." ); -} -/** * Get thread specific current flow workspace. *
@@ -5732,7 +5717,7 @@ mlx5_flow_get_thread_workspace(void) {struct mlx5_flow_workspace *data; - data =pthread_getspecific (key_workspace); + data =mlx5_flow_os_get_specific_workspace ();MLX5_ASSERT (data && data->inuse);if (!data || !data->inuse)DRV_LOG (ERR ,"flow workspace not initialized." );
@@ -5780,11 +5765,7 @@ mlx5_flow_push_thread_workspace(void)struct mlx5_flow_workspace *curr;struct mlx5_flow_workspace *data; -if (pthread_once (&key_workspace_init, flow_alloc_workspace)) { -DRV_LOG (ERR ,"Failed to init flow workspace data thread key." ); -return NULL ; - } - curr =pthread_getspecific (key_workspace); + curr =mlx5_flow_os_get_specific_workspace ();if (!curr) { data =flow_alloc_thread_workspace ();if (!data)
@@ -5803,7 +5784,7 @@ mlx5_flow_push_thread_workspace(void) data->inuse =1 ; data->flow_idx =0 ;/* Set as current workspace */ -if (pthread_setspecific (key_workspace, data)) +if (mlx5_flow_os_set_specific_workspace (data))DRV_LOG (ERR ,"Failed to set flow workspace to thread." );return data; }
@@ -5829,7 +5810,7 @@ mlx5_flow_pop_thread_workspace(void) data->inuse =0 ;if (!data->prev)return ; -if (pthread_setspecific (key_workspace, data->prev)) +if (mlx5_flow_os_set_specific_workspace (data->prev))DRV_LOG (ERR ,"Failed to set flow workspace to thread." ); }
drivers/net/mlx5/mlx5_flow.h +10 -0
@@ -1503,4 +1503,14 @@ void flow_dv_dest_array_remove_cb(struct mlx5_cache_list *list, struct mlx5_cache_entry *entry);struct mlx5_aso_age_action *flow_aso_age_get_by_idx (struct rte_eth_dev *dev,uint32_t age_idx); +void +flow_release_workspace (void *data); +int +mlx5_flow_os_init_workspace_once (void ); +void * +mlx5_flow_os_get_specific_workspace (void ); +int +mlx5_flow_os_set_specific_workspace (struct mlx5_flow_workspace *data); +void +mlx5_flow_os_release_workspace (void );#endif /* RTE_PMD_MLX5_FLOW_H_ */
drivers/net/mlx5/windows/mlx5_flow_os.c +178 -0
187 lines not on this page · raw message
Signature · 1 line
2.16.1.windows.4
Quoted 25 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of Tal Shnaiderman
Sent: Thursday, January 7, 2021 5:08 AM
To: [email protected]
Cc: thomas <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [EXTERNAL] [dpdk-dev] [PATCH v3] mlx5: split multi-threaded flows per OSmulti-threaded flows feature uses pthread function
pthread_key_createbut for Windows the destruction option in the function is unimplemented.to resolve it Windows will implement destruction mechanism to cleanup
mlx5_flow_workspaceobject for each terminated thread.Linux flow will keep the current behavior.
Signed-off-by Tal Shnaiderman <[email protected]>Acked-by Matan Azrad <[email protected]>---
Depends-on: series-14562 ("support generic threading functions")
v2: fix style issues
v3: adjust to new API, remove nl from EOFs.
---
Quoted 9 lines
--- drivers/net/mlx5/linux/meson.build | 1 + drivers/net/mlx5/linux/mlx5_flow_os.c | 38 +++++++ drivers/net/mlx5/mlx5.c | 8 ++ drivers/net/mlx5/mlx5_flow.c | 29 +----- drivers/net/mlx5/mlx5_flow.h | 10 ++ drivers/net/mlx5/windows/mlx5_flow_os.c | 178 ++++++++++++++++++++++++++++++++ 6 files changed, 240 insertions(+), 24 deletions(-)
07/01/2021 14:08, Tal Shnaiderman:
Quoted 10 lines
multi-threaded flows feature uses pthread function
pthread_key_createbut for Windows the destruction option in the function is unimplemented.to resolve it Windows will implement destruction mechanism to cleanup
mlx5_flow_workspaceobject for each terminated thread.Linux flow will keep the current behavior.
Signed-off-by Tal Shnaiderman <[email protected]>Acked-by Matan Azrad <[email protected]>
Applied in next-net-mlx, thanks.