* [PATCH 00/11] rework thread management @ 2023-09-06 16:12 Thomas Monjalon 2023-09-06 16:12 ` [PATCH 01/11] devtools: warn when adding some pthread calls Thomas Monjalon ` (13 more replies) 0 siblings, 14 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-06 16:12 UTC (permalink / raw) To: dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit The main effect of this patch series is to remove calls to pthread functions except for pthread_cancel and locks. The function rte_thread_create_control() does not take attributes anymore as it looks a useless complication of the API. Then the rte_thread API is made stable, so we can remove the old deprecated functions rte_thread_setname() and rte_ctrl_thread_create(). Some new internal functions are added in rte_thread to make sure all internal thread names are prefixed with "dpdk-". Few other cleanups are done. Future work about pthread portability are about: - cancel - mutex Thomas Monjalon (11): devtools: warn when adding some pthread calls eal: rename thread name length definition eal: remove attributes from control thread creation eal: promote thread API as stable eal: force prefix for internal threads lib: convert to internal control threads drivers: convert to internal control threads examples: convert to normal control threads test: convert threads creation eal: remove deprecated thread functions lib: remove pthread.h from includes app/test/process.h | 10 +- app/test/test_lcores.c | 9 +- app/test/test_link_bonding.c | 2 + app/test/test_pdump.c | 6 +- app/test/test_pdump.h | 2 +- app/test/test_threads.c | 2 +- devtools/checkpatches.sh | 16 +++ .../prog_guide/env_abstraction_layer.rst | 2 +- doc/guides/rel_notes/deprecation.rst | 5 - doc/guides/rel_notes/release_23_11.rst | 6 + drivers/common/cnxk/roc_dev.c | 16 +-- drivers/common/cnxk/roc_dev_priv.h | 2 +- drivers/common/cnxk/roc_nix_inl_dev.c | 9 +- drivers/common/cnxk/roc_nix_inl_priv.h | 2 +- drivers/common/cnxk/roc_platform.h | 3 +- drivers/common/mlx5/mlx5_common.c | 1 + drivers/common/mlx5/windows/mlx5_win_ext.h | 2 + drivers/dma/skeleton/skeleton_dmadev.c | 8 +- drivers/event/dlb2/pf/base/dlb2_osdep.h | 14 +- drivers/event/dlb2/pf/base/dlb2_resource.c | 39 +++--- drivers/event/dlb2/pf/dlb2_main.h | 1 - drivers/net/ark/ark_ethdev.c | 11 +- drivers/net/ark/ark_pktgen.c | 8 +- drivers/net/ark/ark_pktgen.h | 2 +- drivers/net/bnxt/bnxt.h | 1 + drivers/net/iavf/iavf_vchnl.c | 4 +- drivers/net/ice/ice_dcf_parent.c | 7 +- drivers/net/ipn3ke/ipn3ke_representor.c | 17 ++- drivers/net/ixgbe/ixgbe_ethdev.c | 8 +- drivers/net/mlx5/mlx5.h | 2 +- drivers/net/mlx5/mlx5_hws_cnt.c | 42 +++--- drivers/net/qede/base/bcm_osal.h | 1 + drivers/net/sfc/sfc_mae.h | 2 +- drivers/net/sfc/sfc_mae_counter.c | 11 +- drivers/net/txgbe/txgbe_ethdev.c | 6 +- drivers/raw/ifpga/base/opae_osdep.h | 1 + drivers/raw/ifpga/ifpga_rawdev.c | 19 ++- drivers/vdpa/ifc/ifcvf_vdpa.c | 86 ++++++------ drivers/vdpa/mlx5/mlx5_vdpa.c | 2 +- drivers/vdpa/mlx5/mlx5_vdpa.h | 10 +- drivers/vdpa/mlx5/mlx5_vdpa_cthread.c | 70 +++------- drivers/vdpa/mlx5/mlx5_vdpa_event.c | 64 +++------ drivers/vdpa/sfc/sfc_vdpa.c | 1 + drivers/vdpa/sfc/sfc_vdpa_ops.c | 15 +- drivers/vdpa/sfc/sfc_vdpa_ops.h | 3 +- examples/vhost/main.c | 9 +- examples/vhost_blk/vhost_blk.c | 21 +-- lib/eal/common/eal_common_options.c | 1 + lib/eal/common/eal_common_proc.c | 15 +- lib/eal/common/eal_common_thread.c | 101 +++++--------- lib/eal/common/eal_common_trace.c | 1 + lib/eal/common/malloc_mp.c | 1 + lib/eal/freebsd/eal.c | 2 +- lib/eal/freebsd/eal_alarm.c | 1 + lib/eal/freebsd/eal_interrupts.c | 10 +- lib/eal/freebsd/eal_thread.c | 9 +- lib/eal/include/rte_eal.h | 3 - lib/eal/include/rte_lcore.h | 42 ------ lib/eal/include/rte_per_lcore.h | 2 - lib/eal/include/rte_thread.h | 131 +++++++++--------- lib/eal/linux/eal.c | 2 +- lib/eal/linux/eal_alarm.c | 1 + lib/eal/linux/eal_interrupts.c | 10 +- lib/eal/linux/eal_thread.c | 18 +-- lib/eal/linux/eal_timer.c | 11 +- lib/eal/unix/rte_thread.c | 2 +- lib/eal/version.map | 44 +++--- lib/eal/windows/eal.c | 2 +- lib/eal/windows/eal_interrupts.c | 2 +- lib/eal/windows/eal_thread.c | 8 -- lib/eal/windows/rte_thread.c | 2 +- lib/ethdev/ethdev_driver.c | 1 + lib/ethdev/ethdev_driver.h | 2 + lib/ethdev/rte_ethdev_core.h | 2 - lib/ethdev/rte_flow.c | 1 + lib/eventdev/rte_event_eth_rx_adapter.c | 24 ++-- lib/vhost/fd_man.c | 6 +- lib/vhost/fd_man.h | 2 +- lib/vhost/socket.c | 23 ++- lib/vhost/vduse.c | 5 +- lib/vhost/vhost.c | 1 + 81 files changed, 451 insertions(+), 617 deletions(-) -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 01/11] devtools: warn when adding some pthread calls 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon @ 2023-09-06 16:12 ` Thomas Monjalon 2023-09-07 8:20 ` David Marchand 2023-09-06 16:12 ` [PATCH 02/11] eal: rename thread name length definition Thomas Monjalon ` (12 subsequent siblings) 13 siblings, 1 reply; 60+ messages in thread From: Thomas Monjalon @ 2023-09-06 16:12 UTC (permalink / raw) To: dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit All pthread functions below have an equivalent in rte_thread API: - pthread_create - pthread_join - pthread_detach - pthread_setname_np - pthread_set_name_np - pthread_setaffinity_np - pthread_attr_setinheritsched - pthread_attr_setschedpolicy Usage of these functions will be raised to encourage rte_thread adoption. The pthread functions for locks and cancel are still allowed. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> --- devtools/checkpatches.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 55fabc5458..131ffbcebe 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -119,6 +119,14 @@ check_forbidden_additions() { # <patch> -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ "$1" || res=1 + # refrain from using some pthread functions + awk -v FOLDERS="lib drivers app examples" \ + -v EXPRESSIONS="pthread_(create|join|detach|set((|_)name_np|affinity_np)|attr_set(inheritsched|schedpolicy))\\\(" \ + -v RET_ON_FAIL=1 \ + -v MESSAGE='Using pthread functions, prefer rte_thread' \ + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ + "$1" || res=1 + # forbid use of __reserved which is a reserved keyword in Windows system headers awk -v FOLDERS="lib drivers app examples" \ -v EXPRESSIONS='\\<__reserved\\>' \ -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 01/11] devtools: warn when adding some pthread calls 2023-09-06 16:12 ` [PATCH 01/11] devtools: warn when adding some pthread calls Thomas Monjalon @ 2023-09-07 8:20 ` David Marchand 0 siblings, 0 replies; 60+ messages in thread From: David Marchand @ 2023-09-07 8:20 UTC (permalink / raw) To: Thomas Monjalon; +Cc: dev, Tyler Retzlaff, Ferruh Yigit Hello Thomas, On Wed, Sep 6, 2023 at 6:22 PM Thomas Monjalon <thomas@monjalon.net> wrote: > > All pthread functions below have an equivalent in rte_thread API: > - pthread_create > - pthread_join > - pthread_detach > - pthread_setname_np > - pthread_set_name_np > - pthread_setaffinity_np > - pthread_attr_setinheritsched > - pthread_attr_setschedpolicy > Usage of these functions will be raised to encourage rte_thread adoption. > > The pthread functions for locks and cancel are still allowed. > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net> > --- > devtools/checkpatches.sh | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh > index 55fabc5458..131ffbcebe 100755 > --- a/devtools/checkpatches.sh > +++ b/devtools/checkpatches.sh > @@ -119,6 +119,14 @@ check_forbidden_additions() { # <patch> > -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ > "$1" || res=1 > > + # refrain from using some pthread functions > + awk -v FOLDERS="lib drivers app examples" \ > + -v EXPRESSIONS="pthread_(create|join|detach|set((|_)name_np|affinity_np)|attr_set(inheritsched|schedpolicy))\\\(" \ I remember some awk (was it Alpine Linux? or FreeBSD ?..) does not like empty pattern like (|plop). For this case here, it is better (and kind of more readable) to use _? > + -v RET_ON_FAIL=1 \ > + -v MESSAGE='Using pthread functions, prefer rte_thread' \ > + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ > + "$1" || res=1 > + > # forbid use of __reserved which is a reserved keyword in Windows system headers > awk -v FOLDERS="lib drivers app examples" \ > -v EXPRESSIONS='\\<__reserved\\>' \ > -- > 2.42.0 > -- David Marchand ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 02/11] eal: rename thread name length definition 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon 2023-09-06 16:12 ` [PATCH 01/11] devtools: warn when adding some pthread calls Thomas Monjalon @ 2023-09-06 16:12 ` Thomas Monjalon 2023-09-08 4:00 ` Tyler Retzlaff 2023-09-06 16:12 ` [PATCH 03/11] eal: remove attributes from control thread creation Thomas Monjalon ` (11 subsequent siblings) 13 siblings, 1 reply; 60+ messages in thread From: Thomas Monjalon @ 2023-09-06 16:12 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Bruce Richardson, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam RTE_MAX_THREAD_NAME_LEN is including the NUL character, so it should be named "size" instead of "length". A new constant RTE_THREAD_NAME_SIZE is introduced for naming accuracy. For API compatibility, the old name is kept. At the same time, the original definition is moved from rte_eal.h to rte_thread.h. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> --- lib/eal/freebsd/eal.c | 2 +- lib/eal/freebsd/eal_thread.c | 2 +- lib/eal/include/rte_eal.h | 3 --- lib/eal/include/rte_thread.h | 9 +++++++-- lib/eal/linux/eal.c | 2 +- lib/eal/linux/eal_thread.c | 2 +- lib/eal/windows/eal.c | 2 +- lib/eal/windows/rte_thread.c | 2 +- 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 9e1e267955..39a2868523 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -583,7 +583,7 @@ rte_eal_init(int argc, char **argv) static uint32_t run_once; uint32_t has_run = 0; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; - char thread_name[RTE_MAX_THREAD_NAME_LEN]; + char thread_name[RTE_THREAD_NAME_SIZE]; const struct rte_config *config = rte_eal_get_configuration(); struct internal_config *internal_conf = eal_get_internal_configuration(); diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c index 3227d9b8a2..ba9b25c2c0 100644 --- a/lib/eal/freebsd/eal_thread.c +++ b/lib/eal/freebsd/eal_thread.c @@ -34,7 +34,7 @@ int rte_sys_gettid(void) void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) { - char truncated[RTE_MAX_THREAD_NAME_LEN]; + char truncated[RTE_THREAD_NAME_SIZE]; const size_t truncatedsz = sizeof(truncated); if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz) diff --git a/lib/eal/include/rte_eal.h b/lib/eal/include/rte_eal.h index 53c4a5519e..cd318ee141 100644 --- a/lib/eal/include/rte_eal.h +++ b/lib/eal/include/rte_eal.h @@ -27,9 +27,6 @@ extern "C" { #define RTE_MAGIC 19820526 /**< Magic number written by the main partition when ready. */ -/* Maximum thread_name length. */ -#define RTE_MAX_THREAD_NAME_LEN 16 - /** * The type of process in a linux, multi-process setup */ diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index 369e2375f6..6233142322 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -23,6 +23,11 @@ extern "C" { #endif +/** Maximum thread name length (including '\0'). */ +#define RTE_THREAD_NAME_SIZE 16 +/* Old definition, aliased for compatibility. */ +#define RTE_MAX_THREAD_NAME_LEN RTE_THREAD_NAME_SIZE + /** * Thread id descriptor. */ @@ -110,7 +115,7 @@ int rte_thread_create(rte_thread_t *thread_id, * Filled with the thread id of the new created thread. * @param name * The name of the control thread - * (max RTE_MAX_THREAD_NAME_LEN characters including '\0'). + * (max RTE_THREAD_NAME_SIZE characters including '\0'). * @param thread_attr * Attributes for the new thread. * @param thread_func @@ -188,7 +193,7 @@ rte_thread_t rte_thread_self(void); * The id of the thread to set name. * * @param thread_name - * The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN, + * The name to set. Truncated to RTE_THREAD_NAME_SIZE, * including terminating NUL if necessary. */ __rte_experimental diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index a26822f667..5f4b2fb005 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -970,7 +970,7 @@ rte_eal_init(int argc, char **argv) static uint32_t run_once; uint32_t has_run = 0; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; - char thread_name[RTE_MAX_THREAD_NAME_LEN]; + char thread_name[RTE_THREAD_NAME_SIZE]; bool phys_addrs; const struct rte_config *config = rte_eal_get_configuration(); struct internal_config *internal_conf = diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c index c07ad9d8a4..b9a126f3a8 100644 --- a/lib/eal/linux/eal_thread.c +++ b/lib/eal/linux/eal_thread.c @@ -24,7 +24,7 @@ void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) int ret = ENOSYS; #if defined(__GLIBC__) && defined(__GLIBC_PREREQ) #if __GLIBC_PREREQ(2, 12) - char truncated[RTE_MAX_THREAD_NAME_LEN]; + char truncated[RTE_THREAD_NAME_SIZE]; const size_t truncatedsz = sizeof(truncated); if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz) diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 16c1ba1596..7ec2152211 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -283,7 +283,7 @@ rte_eal_init(int argc, char **argv) enum rte_iova_mode iova_mode; int ret; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; - char thread_name[RTE_MAX_THREAD_NAME_LEN]; + char thread_name[RTE_THREAD_NAME_SIZE]; eal_log_init(NULL, 0); diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c index e528ac9991..acf648456c 100644 --- a/lib/eal/windows/rte_thread.c +++ b/lib/eal/windows/rte_thread.c @@ -324,7 +324,7 @@ void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) { int ret = 0; - wchar_t wname[RTE_MAX_THREAD_NAME_LEN]; + wchar_t wname[RTE_THREAD_NAME_SIZE]; mbstate_t state = {0}; size_t rv; HANDLE thread_handle; -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 02/11] eal: rename thread name length definition 2023-09-06 16:12 ` [PATCH 02/11] eal: rename thread name length definition Thomas Monjalon @ 2023-09-08 4:00 ` Tyler Retzlaff 0 siblings, 0 replies; 60+ messages in thread From: Tyler Retzlaff @ 2023-09-08 4:00 UTC (permalink / raw) To: Thomas Monjalon Cc: dev, David Marchand, Ferruh Yigit, Bruce Richardson, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam On Wed, Sep 06, 2023 at 06:12:19PM +0200, Thomas Monjalon wrote: > RTE_MAX_THREAD_NAME_LEN is including the NUL character, > so it should be named "size" instead of "length". > A new constant RTE_THREAD_NAME_SIZE is introduced for naming accuracy. > For API compatibility, the old name is kept. > > At the same time, the original definition is moved > from rte_eal.h to rte_thread.h. > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net> > --- lgtm Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 03/11] eal: remove attributes from control thread creation 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon 2023-09-06 16:12 ` [PATCH 01/11] devtools: warn when adding some pthread calls Thomas Monjalon 2023-09-06 16:12 ` [PATCH 02/11] eal: rename thread name length definition Thomas Monjalon @ 2023-09-06 16:12 ` Thomas Monjalon 2023-09-08 4:02 ` Tyler Retzlaff 2023-09-06 16:12 ` [PATCH 04/11] eal: promote thread API as stable Thomas Monjalon ` (10 subsequent siblings) 13 siblings, 1 reply; 60+ messages in thread From: Thomas Monjalon @ 2023-09-06 16:12 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Chengwen Feng, Kevin Laatz, Bruce Richardson, Jingjing Wu, Beilei Xing, Qiming Yang, Qi Zhang, Wenjun Wu, Jiawen Wu, Jian Wang, Harman Kalra, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam The experimental function rte_thread_create_control() is supposed to wrap actions needed to create a control thread in DPDK. This function should be easy to port on any OS. As such, the thread attributes should not be customizable in this API. The thread priority should be normal, and the affinity is on "free cores". That's why the custom attributes parameter thread_attr is dropped. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> --- app/test/test_threads.c | 2 +- doc/guides/rel_notes/release_23_11.rst | 3 +++ drivers/dma/skeleton/skeleton_dmadev.c | 3 +-- drivers/net/iavf/iavf_vchnl.c | 2 +- drivers/net/ice/ice_dcf_parent.c | 2 +- drivers/net/ixgbe/ixgbe_ethdev.c | 1 - drivers/net/txgbe/txgbe_ethdev.c | 2 +- lib/eal/common/eal_common_thread.c | 5 ++--- lib/eal/include/rte_thread.h | 5 +---- lib/eal/windows/eal_interrupts.c | 2 +- 10 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/test/test_threads.c b/app/test/test_threads.c index 8c27e2bae1..4ac3f2671a 100644 --- a/app/test/test_threads.c +++ b/app/test/test_threads.c @@ -240,7 +240,7 @@ test_thread_control_create_join(void) thread_id_ready = 0; RTE_TEST_ASSERT(rte_thread_create_control(&thread_id, "dpdk-test-thcc", - NULL, thread_main, &thread_main_id) == 0, + thread_main, &thread_main_id) == 0, "Failed to create thread."); while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0) diff --git a/doc/guides/rel_notes/release_23_11.rst b/doc/guides/rel_notes/release_23_11.rst index 333e1d95a2..d3d500f294 100644 --- a/doc/guides/rel_notes/release_23_11.rst +++ b/doc/guides/rel_notes/release_23_11.rst @@ -113,6 +113,9 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* eal: The thread API has changed. + The function ``rte_thread_create_control()`` does not take attributes anymore. + ABI Changes ----------- diff --git a/drivers/dma/skeleton/skeleton_dmadev.c b/drivers/dma/skeleton/skeleton_dmadev.c index 493224542f..4fc2319668 100644 --- a/drivers/dma/skeleton/skeleton_dmadev.c +++ b/drivers/dma/skeleton/skeleton_dmadev.c @@ -128,8 +128,7 @@ skeldma_start(struct rte_dma_dev *dev) rte_mb(); snprintf(name, sizeof(name), "dpdk-dma-skel%d", dev->data->dev_id); - ret = rte_thread_create_control(&hw->thread, name, NULL, - cpucopy_thread, dev); + ret = rte_thread_create_control(&hw->thread, name, cpucopy_thread, dev); if (ret) { SKELDMA_LOG(ERR, "Start cpucopy thread fail!"); return -EINVAL; diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c index c31a6d5c98..6baa6d5955 100644 --- a/drivers/net/iavf/iavf_vchnl.c +++ b/drivers/net/iavf/iavf_vchnl.c @@ -136,7 +136,7 @@ iavf_dev_event_handler_init(void) pthread_mutex_init(&handler->lock, NULL); if (rte_thread_create_control(&handler->tid, "dpdk-iavf-event", - NULL, iavf_dev_event_handle, NULL)) { + iavf_dev_event_handle, NULL)) { __atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED); return -1; } diff --git a/drivers/net/ice/ice_dcf_parent.c b/drivers/net/ice/ice_dcf_parent.c index ad98a531de..d3bb65874f 100644 --- a/drivers/net/ice/ice_dcf_parent.c +++ b/drivers/net/ice/ice_dcf_parent.c @@ -182,7 +182,7 @@ start_vsi_reset_thread(struct ice_dcf_hw *dcf_hw, bool vfr, uint16_t vf_id) param->vf_id = vf_id; snprintf(name, sizeof(name), "dpdk-ice-rst%u", vf_id); - ret = rte_thread_create_control(&thread, name, NULL, + ret = rte_thread_create_control(&thread, name, ice_dcf_vsi_update_service_handler, param); if (ret != 0) { PMD_DRV_LOG(ERR, "Failed to start the thread for reset handling"); diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c index 7eac05ee60..64e7e5d7d6 100644 --- a/drivers/net/ixgbe/ixgbe_ethdev.c +++ b/drivers/net/ixgbe/ixgbe_ethdev.c @@ -4330,7 +4330,6 @@ ixgbe_dev_link_update_share(struct rte_eth_dev *dev, intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; if (rte_thread_create_control(&ad->link_thread_tid, "dpdk-ixgbe-link", - NULL, ixgbe_dev_setup_link_thread_handler, dev) < 0) { PMD_DRV_LOG(ERR, diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c index 6f2f5a1841..198fac8318 100644 --- a/drivers/net/txgbe/txgbe_ethdev.c +++ b/drivers/net/txgbe/txgbe_ethdev.c @@ -2897,7 +2897,7 @@ txgbe_dev_link_update_share(struct rte_eth_dev *dev, */ intr->flags |= TXGBE_FLAG_NEED_LINK_CONFIG; if (rte_thread_create_control(&ad->link_thread_tid, - "dpdk-txgbe-link", NULL, + "dpdk-txgbe-link", txgbe_dev_setup_link_thread_handler, dev) < 0) { PMD_DRV_LOG(ERR, "Create link thread failed!"); __atomic_clear(&ad->link_thread_running, __ATOMIC_SEQ_CST); diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 6605bd017e..07ac721da1 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -349,8 +349,7 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, int rte_thread_create_control(rte_thread_t *thread, const char *name, - const rte_thread_attr_t *attr, rte_thread_func start_routine, - void *arg) + rte_thread_func start_routine, void *arg) { struct rte_thread_ctrl_params *params; enum __rte_ctrl_thread_status ctrl_thread_status; @@ -365,7 +364,7 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, params->ret = 0; params->ctrl_thread_status = CTRL_THREAD_LAUNCHING; - ret = rte_thread_create(thread, attr, control_thread_start, params); + ret = rte_thread_create(thread, NULL, control_thread_start, params); if (ret != 0) { free(params); return -ret; diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index 6233142322..28cc5220a4 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -116,8 +116,6 @@ int rte_thread_create(rte_thread_t *thread_id, * @param name * The name of the control thread * (max RTE_THREAD_NAME_SIZE characters including '\0'). - * @param thread_attr - * Attributes for the new thread. * @param thread_func * Function to be executed by the new thread. * @param arg @@ -129,8 +127,7 @@ int rte_thread_create(rte_thread_t *thread_id, __rte_experimental int rte_thread_create_control(rte_thread_t *thread, const char *name, - const rte_thread_attr_t *thread_attr, rte_thread_func thread_func, - void *arg); + rte_thread_func thread_func, void *arg); /** * @warning diff --git a/lib/eal/windows/eal_interrupts.c b/lib/eal/windows/eal_interrupts.c index b1b1228c2b..66a49c844a 100644 --- a/lib/eal/windows/eal_interrupts.c +++ b/lib/eal/windows/eal_interrupts.c @@ -98,7 +98,7 @@ rte_eal_intr_init(void) return -1; } - ret = rte_thread_create_control(&intr_thread, "dpdk-intr", NULL, + ret = rte_thread_create_control(&intr_thread, "dpdk-intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 03/11] eal: remove attributes from control thread creation 2023-09-06 16:12 ` [PATCH 03/11] eal: remove attributes from control thread creation Thomas Monjalon @ 2023-09-08 4:02 ` Tyler Retzlaff 0 siblings, 0 replies; 60+ messages in thread From: Tyler Retzlaff @ 2023-09-08 4:02 UTC (permalink / raw) To: Thomas Monjalon Cc: dev, David Marchand, Ferruh Yigit, Chengwen Feng, Kevin Laatz, Bruce Richardson, Jingjing Wu, Beilei Xing, Qiming Yang, Qi Zhang, Wenjun Wu, Jiawen Wu, Jian Wang, Harman Kalra, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam On Wed, Sep 06, 2023 at 06:12:20PM +0200, Thomas Monjalon wrote: > The experimental function rte_thread_create_control() > is supposed to wrap actions needed to create a control thread in DPDK. > This function should be easy to port on any OS. > > As such, the thread attributes should not be customizable in this API. > The thread priority should be normal, and the affinity is on "free cores". > That's why the custom attributes parameter thread_attr is dropped. > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net> > --- Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 04/11] eal: promote thread API as stable 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon ` (2 preceding siblings ...) 2023-09-06 16:12 ` [PATCH 03/11] eal: remove attributes from control thread creation Thomas Monjalon @ 2023-09-06 16:12 ` Thomas Monjalon 2023-09-08 4:04 ` Tyler Retzlaff 2023-09-06 16:12 ` [PATCH 05/11] eal: force prefix for internal threads Thomas Monjalon ` (9 subsequent siblings) 13 siblings, 1 reply; 60+ messages in thread From: Thomas Monjalon @ 2023-09-06 16:12 UTC (permalink / raw) To: dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit The rte_thread API must be used to ease OS porting. One step of this process is to mark the necessary API as stable. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> --- doc/guides/rel_notes/release_23_11.rst | 1 + lib/eal/include/rte_thread.h | 64 -------------------------- lib/eal/version.map | 40 ++++++++-------- 3 files changed, 20 insertions(+), 85 deletions(-) diff --git a/doc/guides/rel_notes/release_23_11.rst b/doc/guides/rel_notes/release_23_11.rst index d3d500f294..d7562fd646 100644 --- a/doc/guides/rel_notes/release_23_11.rst +++ b/doc/guides/rel_notes/release_23_11.rst @@ -115,6 +115,7 @@ API Changes * eal: The thread API has changed. The function ``rte_thread_create_control()`` does not take attributes anymore. + The whole thread API was promoted to stable level. ABI Changes diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index 28cc5220a4..dd1f62523f 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -73,9 +73,6 @@ typedef struct { typedef struct eal_tls_key *rte_thread_key; /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Create a new thread that will invoke the 'thread_func' routine. * * @param thread_id @@ -94,15 +91,11 @@ typedef struct eal_tls_key *rte_thread_key; * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_create(rte_thread_t *thread_id, const rte_thread_attr_t *thread_attr, rte_thread_func thread_func, void *arg); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Create a control thread. * * Creates a control thread with the given name and attributes. The @@ -124,15 +117,11 @@ int rte_thread_create(rte_thread_t *thread_id, * On success, returns 0; on error, it returns a negative value * corresponding to the error number. */ -__rte_experimental int rte_thread_create_control(rte_thread_t *thread, const char *name, rte_thread_func thread_func, void *arg); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Waits for the thread identified by 'thread_id' to terminate * * @param thread_id @@ -145,13 +134,9 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_join(rte_thread_t thread_id, uint32_t *value_ptr); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Indicate that the return value of the thread is not needed and * all thread resources should be release when the thread terminates. * @@ -162,25 +147,17 @@ int rte_thread_join(rte_thread_t thread_id, uint32_t *value_ptr); * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_detach(rte_thread_t thread_id); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Get the id of the calling thread. * * @return * Return the thread id of the calling thread. */ -__rte_experimental rte_thread_t rte_thread_self(void); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the name of the thread. * This API is a noop if the underlying platform does not * support setting the thread name or the platform-specific @@ -193,14 +170,10 @@ rte_thread_t rte_thread_self(void); * The name to set. Truncated to RTE_THREAD_NAME_SIZE, * including terminating NUL if necessary. */ -__rte_experimental void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Check if 2 thread ids are equal. * * @param t1 @@ -213,13 +186,9 @@ rte_thread_set_name(rte_thread_t thread_id, const char *thread_name); * If the ids are equal, return nonzero. * Otherwise, return 0. */ -__rte_experimental int rte_thread_equal(rte_thread_t t1, rte_thread_t t2); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Initialize the attributes of a thread. * These attributes can be passed to the rte_thread_create() function * that will create a new thread and set its attributes according to attr. @@ -231,13 +200,9 @@ int rte_thread_equal(rte_thread_t t1, rte_thread_t t2); * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_attr_init(rte_thread_attr_t *attr); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the thread priority value in the thread attributes pointed to * by 'thread_attr'. * @@ -251,16 +216,12 @@ int rte_thread_attr_init(rte_thread_attr_t *attr); * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr, enum rte_thread_priority priority); #ifdef RTE_HAS_CPUSET /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the CPU affinity value in the thread attributes pointed to * by 'thread_attr'. * @@ -274,14 +235,10 @@ int rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr, rte_cpuset_t *cpuset); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Get the value of CPU affinity that is set in the thread attributes pointed * to by 'thread_attr'. * @@ -295,14 +252,10 @@ int rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr, rte_cpuset_t *cpuset); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the affinity of thread 'thread_id' to the cpu set * specified by 'cpuset'. * @@ -316,14 +269,10 @@ int rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_set_affinity_by_id(rte_thread_t thread_id, const rte_cpuset_t *cpuset); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Get the affinity of thread 'thread_id' and store it * in 'cpuset'. * @@ -337,7 +286,6 @@ int rte_thread_set_affinity_by_id(rte_thread_t thread_id, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_get_affinity_by_id(rte_thread_t thread_id, rte_cpuset_t *cpuset); @@ -364,9 +312,6 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp); #endif /* RTE_HAS_CPUSET */ /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Get the priority of a thread. * * @param thread_id @@ -379,14 +324,10 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp); * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_get_priority(rte_thread_t thread_id, enum rte_thread_priority *priority); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the priority of a thread. * * @param thread_id @@ -399,7 +340,6 @@ int rte_thread_get_priority(rte_thread_t thread_id, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_set_priority(rte_thread_t thread_id, enum rte_thread_priority priority); @@ -421,7 +361,6 @@ int rte_thread_set_priority(rte_thread_t thread_id, * ENOEXEC - Specific OS error. */ -__rte_experimental int rte_thread_key_create(rte_thread_key *key, void (*destructor)(void *)); @@ -437,7 +376,6 @@ int rte_thread_key_create(rte_thread_key *key, * rte_errno can be: EINVAL - Invalid parameter passed. * ENOEXEC - Specific OS error. */ -__rte_experimental int rte_thread_key_delete(rte_thread_key key); /** @@ -454,7 +392,6 @@ int rte_thread_key_delete(rte_thread_key key); * rte_errno can be: EINVAL - Invalid parameter passed. * ENOEXEC - Specific OS error. */ -__rte_experimental int rte_thread_value_set(rte_thread_key key, const void *value); /** @@ -469,7 +406,6 @@ int rte_thread_value_set(rte_thread_key key, const void *value); * rte_errno can be: EINVAL - Invalid parameter passed. * ENOEXEC - Specific OS error. */ -__rte_experimental void *rte_thread_value_get(rte_thread_key key); #ifdef __cplusplus diff --git a/lib/eal/version.map b/lib/eal/version.map index 7940431e5a..33b853d7be 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -257,12 +257,31 @@ DPDK_24 { rte_strscpy; rte_strsplit; rte_sys_gettid; + rte_thread_attr_get_affinity; + rte_thread_attr_init; + rte_thread_attr_set_affinity; + rte_thread_attr_set_priority; + rte_thread_create; + rte_thread_create_control; + rte_thread_detach; + rte_thread_equal; rte_thread_get_affinity; + rte_thread_get_affinity_by_id; + rte_thread_get_priority; rte_thread_is_intr; + rte_thread_join; + rte_thread_key_create; + rte_thread_key_delete; rte_thread_register; + rte_thread_self; rte_thread_set_affinity; + rte_thread_set_affinity_by_id; + rte_thread_set_name; + rte_thread_set_priority; rte_thread_setname; rte_thread_unregister; + rte_thread_value_get; + rte_thread_value_set; rte_uuid_compare; rte_uuid_is_null; rte_uuid_parse; @@ -368,10 +387,6 @@ EXPERIMENTAL { # added in 21.05 rte_devargs_reset; rte_intr_callback_unregister_sync; - rte_thread_key_create; - rte_thread_key_delete; - rte_thread_value_get; - rte_thread_value_set; rte_version_minor; rte_version_month; rte_version_prefix; @@ -392,26 +407,9 @@ EXPERIMENTAL { # added in 22.07 rte_drand; - rte_thread_get_affinity_by_id; - rte_thread_get_priority; - rte_thread_self; - rte_thread_set_affinity_by_id; - rte_thread_set_priority; - - # added in 22.11 - rte_thread_attr_get_affinity; - rte_thread_attr_init; - rte_thread_attr_set_affinity; - rte_thread_attr_set_priority; - rte_thread_create; - rte_thread_detach; - rte_thread_equal; - rte_thread_join; # added in 23.03 rte_lcore_register_usage_cb; - rte_thread_create_control; - rte_thread_set_name; __rte_eal_trace_generic_blob; # added in 23.07 -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 04/11] eal: promote thread API as stable 2023-09-06 16:12 ` [PATCH 04/11] eal: promote thread API as stable Thomas Monjalon @ 2023-09-08 4:04 ` Tyler Retzlaff 0 siblings, 0 replies; 60+ messages in thread From: Tyler Retzlaff @ 2023-09-08 4:04 UTC (permalink / raw) To: Thomas Monjalon; +Cc: dev, David Marchand, Ferruh Yigit On Wed, Sep 06, 2023 at 06:12:21PM +0200, Thomas Monjalon wrote: > The rte_thread API must be used to ease OS porting. > One step of this process is to mark the necessary API as stable. > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net> > --- Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 05/11] eal: force prefix for internal threads 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon ` (3 preceding siblings ...) 2023-09-06 16:12 ` [PATCH 04/11] eal: promote thread API as stable Thomas Monjalon @ 2023-09-06 16:12 ` Thomas Monjalon 2023-09-07 8:28 ` David Marchand 2023-09-06 16:12 ` [PATCH 06/11] lib: convert to internal control threads Thomas Monjalon ` (8 subsequent siblings) 13 siblings, 1 reply; 60+ messages in thread From: Thomas Monjalon @ 2023-09-06 16:12 UTC (permalink / raw) To: dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit In order to make sure all threads created in DPDK drivers and libraries have the same prefix in their name, some wrapper functions are added for internal use when creating a control thread or setting a thread name: - rte_thread_create_internal_control - rte_thread_set_prefixed_name The equivalent public functions are then forbidden for internal use: - rte_thread_create_control - rte_thread_set_name Note: the libraries and drivers conversion is done in next patches, while doing other thread-related changes. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> --- devtools/checkpatches.sh | 8 +++++ lib/eal/common/eal_common_thread.c | 30 ++++++++++++++++ lib/eal/include/rte_thread.h | 57 +++++++++++++++++++++++++++++- lib/eal/version.map | 2 ++ 4 files changed, 96 insertions(+), 1 deletion(-) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 131ffbcebe..18ad6fbb7f 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -159,6 +159,14 @@ check_forbidden_additions() { # <patch> -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ "$1" || res=1 + # forbid non-internal thread in drivers and libs + awk -v FOLDERS='lib drivers' \ + -v EXPRESSIONS="rte_thread_(set_name|create_control)\\\(" \ + -v RET_ON_FAIL=1 \ + -v MESSAGE='Prefer rte_thread_(set_prefixed_name|create_internal_control) in lib & drivers' \ + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ + "$1" || res=1 + # forbid inclusion of driver specific headers in apps and examples awk -v FOLDERS='app examples' \ -v EXPRESSIONS='include.*_driver\\.h include.*_pmd\\.h' \ diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 07ac721da1..31c37e3102 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -392,6 +392,36 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, return ret; } +static void +add_internal_prefix(char *prefixed_name, const char *name, size_t size) +{ + const char *prefix = "dpdk-"; + size_t prefixlen; + + prefixlen = strlen(prefix); + strlcpy(prefixed_name, prefix, size); + strlcpy(prefixed_name + prefixlen, name, size - prefixlen); +} + +int +rte_thread_create_internal_control(rte_thread_t *id, const char *name, + rte_thread_func func, void *arg) +{ + char prefixed_name[RTE_THREAD_NAME_SIZE]; + + add_internal_prefix(prefixed_name, name, sizeof(prefixed_name)); + return rte_thread_create_control(id, prefixed_name, func, arg); +} + +void +rte_thread_set_prefixed_name(rte_thread_t id, const char *name) +{ + char prefixed_name[RTE_THREAD_NAME_SIZE]; + + add_internal_prefix(prefixed_name, name, sizeof(prefixed_name)); + rte_thread_set_name(id, prefixed_name); +} + int rte_thread_register(void) { diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index dd1f62523f..4b1135df4f 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -28,6 +28,9 @@ extern "C" { /* Old definition, aliased for compatibility. */ #define RTE_MAX_THREAD_NAME_LEN RTE_THREAD_NAME_SIZE +/** Maximum internal thread name length (including '\0'). */ +#define RTE_THREAD_INTERNAL_NAME_SIZE 11 + /** * Thread id descriptor. */ @@ -112,7 +115,7 @@ int rte_thread_create(rte_thread_t *thread_id, * @param thread_func * Function to be executed by the new thread. * @param arg - * Argument passed to start_routine. + * Argument passed to thread_func. * @return * On success, returns 0; on error, it returns a negative value * corresponding to the error number. @@ -121,6 +124,36 @@ int rte_thread_create_control(rte_thread_t *thread, const char *name, rte_thread_func thread_func, void *arg); +/** + * Create an internal control thread. + * + * Creates a control thread with the given name prefixed with "dpdk-". + * If setting the name of the thread fails, the error is ignored and logged. + * + * The affinity of the new thread is based on the CPU affinity retrieved + * at the time rte_eal_init() was called, the EAL threads are then excluded. + * + * @param id + * Filled with the thread ID of the new created thread. + * @param name + * The name of the control thread + * (maximum 10 characters excluding terminating '\0'). + * See RTE_THREAD_INTERNAL_NAME_SIZE. + * The name of the driver or library should be first, + * then followed by a hyphen and more details. + * It will be prefixed with "dpdk-" by this function. + * @param func + * Function to be executed by the new thread. + * @param arg + * Argument passed to func. + * @return + * On success, returns 0; a negative value otherwise. + */ +__rte_internal +int +rte_thread_create_internal_control(rte_thread_t *id, const char *name, + rte_thread_func func, void *arg); + /** * Waits for the thread identified by 'thread_id' to terminate * @@ -159,6 +192,7 @@ rte_thread_t rte_thread_self(void); /** * Set the name of the thread. + * * This API is a noop if the underlying platform does not * support setting the thread name or the platform-specific * API used to set the thread name fails. @@ -173,6 +207,27 @@ rte_thread_t rte_thread_self(void); void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name); +/** + * Set the name of an internal thread with adding a "dpdk-" prefix. + * + * This API is a noop if the underlying platform does not support + * setting the thread name, or if it fails. + * + * @param id + * The ID of the thread to set name. + * + * @param name + * The name to set after being prefixed + * (maximum 10 characters excluding terminating '\0'). + * See RTE_THREAD_INTERNAL_NAME_SIZE. + * The name of the driver or library should be first, + * then followed by a hyphen and more details. + * It will be prefixed with "dpdk-" by this function. + */ +__rte_internal +void +rte_thread_set_prefixed_name(rte_thread_t id, const char *name); + /** * Check if 2 thread ids are equal. * diff --git a/lib/eal/version.map b/lib/eal/version.map index 33b853d7be..6d32c19286 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -462,4 +462,6 @@ INTERNAL { rte_mem_map; rte_mem_page_size; rte_mem_unmap; + rte_thread_create_internal_control; + rte_thread_set_prefixed_name; }; -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 05/11] eal: force prefix for internal threads 2023-09-06 16:12 ` [PATCH 05/11] eal: force prefix for internal threads Thomas Monjalon @ 2023-09-07 8:28 ` David Marchand 2023-09-07 8:50 ` Morten Brørup 0 siblings, 1 reply; 60+ messages in thread From: David Marchand @ 2023-09-07 8:28 UTC (permalink / raw) To: Thomas Monjalon; +Cc: dev, Tyler Retzlaff, Ferruh Yigit On Wed, Sep 6, 2023 at 6:23 PM Thomas Monjalon <thomas@monjalon.net> wrote: > > In order to make sure all threads created in DPDK drivers and libraries > have the same prefix in their name, some wrapper functions are added > for internal use when creating a control thread or setting a thread name: > - rte_thread_create_internal_control > - rte_thread_set_prefixed_name > > The equivalent public functions are then forbidden for internal use: > - rte_thread_create_control > - rte_thread_set_name > > Note: the libraries and drivers conversion is done in next patches, > while doing other thread-related changes. > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net> > --- > devtools/checkpatches.sh | 8 +++++ > lib/eal/common/eal_common_thread.c | 30 ++++++++++++++++ > lib/eal/include/rte_thread.h | 57 +++++++++++++++++++++++++++++- > lib/eal/version.map | 2 ++ > 4 files changed, 96 insertions(+), 1 deletion(-) > > diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh > index 131ffbcebe..18ad6fbb7f 100755 > --- a/devtools/checkpatches.sh > +++ b/devtools/checkpatches.sh > @@ -159,6 +159,14 @@ check_forbidden_additions() { # <patch> > -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ > "$1" || res=1 > > + # forbid non-internal thread in drivers and libs > + awk -v FOLDERS='lib drivers' \ > + -v EXPRESSIONS="rte_thread_(set_name|create_control)\\\(" \ > + -v RET_ON_FAIL=1 \ > + -v MESSAGE='Prefer rte_thread_(set_prefixed_name|create_internal_control) in lib & drivers' \ > + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ > + "$1" || res=1 > + > # forbid inclusion of driver specific headers in apps and examples > awk -v FOLDERS='app examples' \ > -v EXPRESSIONS='include.*_driver\\.h include.*_pmd\\.h' \ > diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c > index 07ac721da1..31c37e3102 100644 > --- a/lib/eal/common/eal_common_thread.c > +++ b/lib/eal/common/eal_common_thread.c > @@ -392,6 +392,36 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, > return ret; > } > > +static void > +add_internal_prefix(char *prefixed_name, const char *name, size_t size) > +{ > + const char *prefix = "dpdk-"; Can you add some BUILD_BUG_ON to check RTE_THREAD_INTERNAL_NAME_SIZE is still relevant to the prefix? > + size_t prefixlen; > + > + prefixlen = strlen(prefix); > + strlcpy(prefixed_name, prefix, size); > + strlcpy(prefixed_name + prefixlen, name, size - prefixlen); > +} > + > +int > +rte_thread_create_internal_control(rte_thread_t *id, const char *name, > + rte_thread_func func, void *arg) > +{ > + char prefixed_name[RTE_THREAD_NAME_SIZE]; > + > + add_internal_prefix(prefixed_name, name, sizeof(prefixed_name)); > + return rte_thread_create_control(id, prefixed_name, func, arg); > +} > + > +void > +rte_thread_set_prefixed_name(rte_thread_t id, const char *name) > +{ > + char prefixed_name[RTE_THREAD_NAME_SIZE]; > + > + add_internal_prefix(prefixed_name, name, sizeof(prefixed_name)); > + rte_thread_set_name(id, prefixed_name); > +} > + > int > rte_thread_register(void) > { > diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h > index dd1f62523f..4b1135df4f 100644 > --- a/lib/eal/include/rte_thread.h > +++ b/lib/eal/include/rte_thread.h > @@ -28,6 +28,9 @@ extern "C" { > /* Old definition, aliased for compatibility. */ > #define RTE_MAX_THREAD_NAME_LEN RTE_THREAD_NAME_SIZE > > +/** Maximum internal thread name length (including '\0'). */ > +#define RTE_THREAD_INTERNAL_NAME_SIZE 11 > + > /** > * Thread id descriptor. > */ > @@ -112,7 +115,7 @@ int rte_thread_create(rte_thread_t *thread_id, > * @param thread_func > * Function to be executed by the new thread. > * @param arg > - * Argument passed to start_routine. > + * Argument passed to thread_func. > * @return > * On success, returns 0; on error, it returns a negative value > * corresponding to the error number. > @@ -121,6 +124,36 @@ int > rte_thread_create_control(rte_thread_t *thread, const char *name, > rte_thread_func thread_func, void *arg); > > +/** > + * Create an internal control thread. > + * > + * Creates a control thread with the given name prefixed with "dpdk-". I don't like having a hardcoded comment here. Plus try to grep dpdk- and you will see it is likely we will miss some if we change the prefix. > + * If setting the name of the thread fails, the error is ignored and logged. > + * > + * The affinity of the new thread is based on the CPU affinity retrieved > + * at the time rte_eal_init() was called, the EAL threads are then excluded. > + * > + * @param id > + * Filled with the thread ID of the new created thread. > + * @param name > + * The name of the control thread > + * (maximum 10 characters excluding terminating '\0'). This 10 value in the comment is easy to miss if some change with the prefix is done. Mentionning RTE_THREAD_INTERNAL_NAME_SIZE is enough. > + * See RTE_THREAD_INTERNAL_NAME_SIZE. > + * The name of the driver or library should be first, > + * then followed by a hyphen and more details. > + * It will be prefixed with "dpdk-" by this function. > + * @param func > + * Function to be executed by the new thread. > + * @param arg > + * Argument passed to func. > + * @return > + * On success, returns 0; a negative value otherwise. > + */ > +__rte_internal > +int > +rte_thread_create_internal_control(rte_thread_t *id, const char *name, > + rte_thread_func func, void *arg); > + > /** > * Waits for the thread identified by 'thread_id' to terminate > * > @@ -159,6 +192,7 @@ rte_thread_t rte_thread_self(void); > > /** > * Set the name of the thread. > + * > * This API is a noop if the underlying platform does not > * support setting the thread name or the platform-specific > * API used to set the thread name fails. > @@ -173,6 +207,27 @@ rte_thread_t rte_thread_self(void); > void > rte_thread_set_name(rte_thread_t thread_id, const char *thread_name); > > +/** > + * Set the name of an internal thread with adding a "dpdk-" prefix. > + * > + * This API is a noop if the underlying platform does not support > + * setting the thread name, or if it fails. > + * > + * @param id > + * The ID of the thread to set name. > + * > + * @param name > + * The name to set after being prefixed > + * (maximum 10 characters excluding terminating '\0'). > + * See RTE_THREAD_INTERNAL_NAME_SIZE. > + * The name of the driver or library should be first, > + * then followed by a hyphen and more details. > + * It will be prefixed with "dpdk-" by this function. > + */ > +__rte_internal > +void > +rte_thread_set_prefixed_name(rte_thread_t id, const char *name); > + > /** > * Check if 2 thread ids are equal. > * > diff --git a/lib/eal/version.map b/lib/eal/version.map > index 33b853d7be..6d32c19286 100644 > --- a/lib/eal/version.map > +++ b/lib/eal/version.map > @@ -462,4 +462,6 @@ INTERNAL { > rte_mem_map; > rte_mem_page_size; > rte_mem_unmap; > + rte_thread_create_internal_control; > + rte_thread_set_prefixed_name; > }; > -- > 2.42.0 > -- David Marchand ^ permalink raw reply [flat|nested] 60+ messages in thread
* RE: [PATCH 05/11] eal: force prefix for internal threads 2023-09-07 8:28 ` David Marchand @ 2023-09-07 8:50 ` Morten Brørup 2023-09-07 8:53 ` David Marchand 0 siblings, 1 reply; 60+ messages in thread From: Morten Brørup @ 2023-09-07 8:50 UTC (permalink / raw) To: David Marchand, Thomas Monjalon; +Cc: dev, Tyler Retzlaff, Ferruh Yigit > From: David Marchand [mailto:david.marchand@redhat.com] > Sent: Thursday, 7 September 2023 10.28 > > On Wed, Sep 6, 2023 at 6:23 PM Thomas Monjalon <thomas@monjalon.net> wrote: > > > > In order to make sure all threads created in DPDK drivers and libraries > > have the same prefix in their name, some wrapper functions are added > > for internal use when creating a control thread or setting a thread name: > > - rte_thread_create_internal_control > > - rte_thread_set_prefixed_name > > > > The equivalent public functions are then forbidden for internal use: > > - rte_thread_create_control > > - rte_thread_set_name > > > > Note: the libraries and drivers conversion is done in next patches, > > while doing other thread-related changes. > > > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net> > > --- > > devtools/checkpatches.sh | 8 +++++ > > lib/eal/common/eal_common_thread.c | 30 ++++++++++++++++ > > lib/eal/include/rte_thread.h | 57 +++++++++++++++++++++++++++++- > > lib/eal/version.map | 2 ++ > > 4 files changed, 96 insertions(+), 1 deletion(-) > > > > diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh > > index 131ffbcebe..18ad6fbb7f 100755 > > --- a/devtools/checkpatches.sh > > +++ b/devtools/checkpatches.sh > > @@ -159,6 +159,14 @@ check_forbidden_additions() { # <patch> > > -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ > > "$1" || res=1 > > > > + # forbid non-internal thread in drivers and libs > > + awk -v FOLDERS='lib drivers' \ > > + -v EXPRESSIONS="rte_thread_(set_name|create_control)\\\(" \ > > + -v RET_ON_FAIL=1 \ > > + -v MESSAGE='Prefer > rte_thread_(set_prefixed_name|create_internal_control) in lib & drivers' \ > > + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ > > + "$1" || res=1 > > + > > # forbid inclusion of driver specific headers in apps and examples > > awk -v FOLDERS='app examples' \ > > -v EXPRESSIONS='include.*_driver\\.h include.*_pmd\\.h' \ > > diff --git a/lib/eal/common/eal_common_thread.c > b/lib/eal/common/eal_common_thread.c > > index 07ac721da1..31c37e3102 100644 > > --- a/lib/eal/common/eal_common_thread.c > > +++ b/lib/eal/common/eal_common_thread.c > > @@ -392,6 +392,36 @@ rte_thread_create_control(rte_thread_t *thread, const > char *name, > > return ret; > > } > > > > +static void > > +add_internal_prefix(char *prefixed_name, const char *name, size_t size) > > +{ > > + const char *prefix = "dpdk-"; > > Can you add some BUILD_BUG_ON to check RTE_THREAD_INTERNAL_NAME_SIZE > is still relevant to the prefix? > > > > + size_t prefixlen; > > + > > + prefixlen = strlen(prefix); > > + strlcpy(prefixed_name, prefix, size); > > + strlcpy(prefixed_name + prefixlen, name, size - prefixlen); > > +} > > + > > +int > > +rte_thread_create_internal_control(rte_thread_t *id, const char *name, > > + rte_thread_func func, void *arg) > > +{ > > + char prefixed_name[RTE_THREAD_NAME_SIZE]; > > + > > + add_internal_prefix(prefixed_name, name, sizeof(prefixed_name)); > > + return rte_thread_create_control(id, prefixed_name, func, arg); > > +} > > + > > +void > > +rte_thread_set_prefixed_name(rte_thread_t id, const char *name) > > +{ > > + char prefixed_name[RTE_THREAD_NAME_SIZE]; > > + > > + add_internal_prefix(prefixed_name, name, sizeof(prefixed_name)); > > + rte_thread_set_name(id, prefixed_name); > > +} > > + > > int > > rte_thread_register(void) > > { > > diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h > > index dd1f62523f..4b1135df4f 100644 > > --- a/lib/eal/include/rte_thread.h > > +++ b/lib/eal/include/rte_thread.h > > @@ -28,6 +28,9 @@ extern "C" { > > /* Old definition, aliased for compatibility. */ > > #define RTE_MAX_THREAD_NAME_LEN RTE_THREAD_NAME_SIZE > > > > +/** Maximum internal thread name length (including '\0'). */ > > +#define RTE_THREAD_INTERNAL_NAME_SIZE 11 > > + > > /** > > * Thread id descriptor. > > */ > > @@ -112,7 +115,7 @@ int rte_thread_create(rte_thread_t *thread_id, > > * @param thread_func > > * Function to be executed by the new thread. > > * @param arg > > - * Argument passed to start_routine. > > + * Argument passed to thread_func. > > * @return > > * On success, returns 0; on error, it returns a negative value > > * corresponding to the error number. > > @@ -121,6 +124,36 @@ int > > rte_thread_create_control(rte_thread_t *thread, const char *name, > > rte_thread_func thread_func, void *arg); > > > > +/** > > + * Create an internal control thread. > > + * > > + * Creates a control thread with the given name prefixed with "dpdk-". > > I don't like having a hardcoded comment here. > Plus try to grep dpdk- and you will see it is likely we will miss some > if we change the prefix. You could do something like the memzone name prefixes, which for the ring looks like this [1]: #define RTE_RING_MZ_PREFIX "RG_" /** The maximum length of a ring name. */ #define RTE_RING_NAMESIZE (RTE_MEMZONE_NAMESIZE - \ sizeof(RTE_RING_MZ_PREFIX) + 1) So, for the thread names: #define RTE_THREAD_NAME_PREFIX "dpdk-" #define RTE_THREAD_INTERNAL_NAME_SIZE (RTE_THREAD_NAME_SIZE - \ sizeof(RTE_THREAD_NAME_PREFIX) + 1) > > > > + * If setting the name of the thread fails, the error is ignored and > logged. > > + * > > + * The affinity of the new thread is based on the CPU affinity retrieved > > + * at the time rte_eal_init() was called, the EAL threads are then > excluded. > > + * > > + * @param id > > + * Filled with the thread ID of the new created thread. > > + * @param name > > + * The name of the control thread > > + * (maximum 10 characters excluding terminating '\0'). > > This 10 value in the comment is easy to miss if some change with the > prefix is done. > Mentionning RTE_THREAD_INTERNAL_NAME_SIZE is enough. I disagree with David's comment to this. The function documentation is easier to read if the actual number is also mentioned. For the best of both worlds, you can add something like this nearby: _Static_assert(sizeof(RTE_THREAD_NAME_PREFIX) == sizeof("dpdk-"), "Length of RTE_THREAD_NAME_PREFIX has changed; " "the documentation needs updating."); > > > > + * See RTE_THREAD_INTERNAL_NAME_SIZE. > > + * The name of the driver or library should be first, > > + * then followed by a hyphen and more details. > > + * It will be prefixed with "dpdk-" by this function. > > + * @param func > > + * Function to be executed by the new thread. > > + * @param arg > > + * Argument passed to func. > > + * @return > > + * On success, returns 0; a negative value otherwise. > > + */ > > +__rte_internal > > +int > > +rte_thread_create_internal_control(rte_thread_t *id, const char *name, > > + rte_thread_func func, void *arg); > > + > > /** > > * Waits for the thread identified by 'thread_id' to terminate > > * > > @@ -159,6 +192,7 @@ rte_thread_t rte_thread_self(void); > > > > /** > > * Set the name of the thread. > > + * > > * This API is a noop if the underlying platform does not > > * support setting the thread name or the platform-specific > > * API used to set the thread name fails. > > @@ -173,6 +207,27 @@ rte_thread_t rte_thread_self(void); > > void > > rte_thread_set_name(rte_thread_t thread_id, const char *thread_name); > > > > +/** > > + * Set the name of an internal thread with adding a "dpdk-" prefix. > > + * > > + * This API is a noop if the underlying platform does not support > > + * setting the thread name, or if it fails. > > + * > > + * @param id > > + * The ID of the thread to set name. > > + * > > + * @param name > > + * The name to set after being prefixed > > + * (maximum 10 characters excluding terminating '\0'). > > + * See RTE_THREAD_INTERNAL_NAME_SIZE. > > + * The name of the driver or library should be first, > > + * then followed by a hyphen and more details. > > + * It will be prefixed with "dpdk-" by this function. > > + */ > > +__rte_internal > > +void > > +rte_thread_set_prefixed_name(rte_thread_t id, const char *name); > > + > > /** > > * Check if 2 thread ids are equal. > > * > > diff --git a/lib/eal/version.map b/lib/eal/version.map > > index 33b853d7be..6d32c19286 100644 > > --- a/lib/eal/version.map > > +++ b/lib/eal/version.map > > @@ -462,4 +462,6 @@ INTERNAL { > > rte_mem_map; > > rte_mem_page_size; > > rte_mem_unmap; > > + rte_thread_create_internal_control; > > + rte_thread_set_prefixed_name; > > }; > > -- > > 2.42.0 > > > > > -- > David Marchand ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 05/11] eal: force prefix for internal threads 2023-09-07 8:50 ` Morten Brørup @ 2023-09-07 8:53 ` David Marchand 2023-09-07 8:55 ` David Marchand 0 siblings, 1 reply; 60+ messages in thread From: David Marchand @ 2023-09-07 8:53 UTC (permalink / raw) To: Morten Brørup; +Cc: Thomas Monjalon, dev, Tyler Retzlaff, Ferruh Yigit On Thu, Sep 7, 2023 at 10:50 AM Morten Brørup <mb@smartsharesystems.com> wrote: > > This 10 value in the comment is easy to miss if some change with the > > prefix is done. > > Mentionning RTE_THREAD_INTERNAL_NAME_SIZE is enough. > > I disagree with David's comment to this. > > The function documentation is easier to read if the actual number is also mentioned. > > For the best of both worlds, you can add something like this nearby: > > _Static_assert(sizeof(RTE_THREAD_NAME_PREFIX) == sizeof("dpdk-"), > "Length of RTE_THREAD_NAME_PREFIX has changed; " > "the documentation needs updating."); And how will it catch the comment about 10 characters ? -- David Marchand ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 05/11] eal: force prefix for internal threads 2023-09-07 8:53 ` David Marchand @ 2023-09-07 8:55 ` David Marchand 2023-09-07 11:10 ` Morten Brørup 0 siblings, 1 reply; 60+ messages in thread From: David Marchand @ 2023-09-07 8:55 UTC (permalink / raw) To: Morten Brørup; +Cc: Thomas Monjalon, dev, Tyler Retzlaff, Ferruh Yigit On Thu, Sep 7, 2023 at 10:53 AM David Marchand <david.marchand@redhat.com> wrote: > > On Thu, Sep 7, 2023 at 10:50 AM Morten Brørup <mb@smartsharesystems.com> wrote: > > > This 10 value in the comment is easy to miss if some change with the > > > prefix is done. > > > Mentionning RTE_THREAD_INTERNAL_NAME_SIZE is enough. > > > > I disagree with David's comment to this. > > > > The function documentation is easier to read if the actual number is also mentioned. > > > > For the best of both worlds, you can add something like this nearby: > > > > _Static_assert(sizeof(RTE_THREAD_NAME_PREFIX) == sizeof("dpdk-"), > > "Length of RTE_THREAD_NAME_PREFIX has changed; " > > "the documentation needs updating."); > > And how will it catch the comment about 10 characters ? I mean you still have to re-read the whole documentation and look for some reference somewhere about 10 characters. -- David Marchand ^ permalink raw reply [flat|nested] 60+ messages in thread
* RE: [PATCH 05/11] eal: force prefix for internal threads 2023-09-07 8:55 ` David Marchand @ 2023-09-07 11:10 ` Morten Brørup 2023-09-11 16:26 ` Thomas Monjalon 0 siblings, 1 reply; 60+ messages in thread From: Morten Brørup @ 2023-09-07 11:10 UTC (permalink / raw) To: David Marchand; +Cc: Thomas Monjalon, dev, Tyler Retzlaff, Ferruh Yigit > From: David Marchand [mailto:david.marchand@redhat.com] > Sent: Thursday, 7 September 2023 10.55 > > On Thu, Sep 7, 2023 at 10:53 AM David Marchand > <david.marchand@redhat.com> wrote: > > > > On Thu, Sep 7, 2023 at 10:50 AM Morten Brørup <mb@smartsharesystems.com> > wrote: > > > > This 10 value in the comment is easy to miss if some change with the > > > > prefix is done. > > > > Mentionning RTE_THREAD_INTERNAL_NAME_SIZE is enough. > > > > > > I disagree with David's comment to this. > > > > > > The function documentation is easier to read if the actual number is also > mentioned. > > > > > > For the best of both worlds, you can add something like this nearby: > > > > > > _Static_assert(sizeof(RTE_THREAD_NAME_PREFIX) == sizeof("dpdk-"), > > > "Length of RTE_THREAD_NAME_PREFIX has changed; " > > > "the documentation needs updating."); > > > > And how will it catch the comment about 10 characters ? > > I mean you still have to re-read the whole documentation and look for > some reference somewhere about 10 characters. The trick is to put the _Static_assert close to where the expectation occurs. That makes it easier to find where changes are necessary. And the _Static_assert can be added at all the locations where changes would be necessary. (Generally, we should add a lot more _Static_assert to the code where it makes assumptions about e.g. the ordering of fields in a struct, such as the vector optimized code.) Also, the failure message could be improved to include help about what to look for. PS: The reference to RTE_THREAD_INTERNAL_NAME_SIZE should remain in the documentation, so perhaps look for "RTE_THREAD_INTERNAL_NAME_SIZE". ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 05/11] eal: force prefix for internal threads 2023-09-07 11:10 ` Morten Brørup @ 2023-09-11 16:26 ` Thomas Monjalon 2023-09-11 21:32 ` Morten Brørup 0 siblings, 1 reply; 60+ messages in thread From: Thomas Monjalon @ 2023-09-11 16:26 UTC (permalink / raw) To: David Marchand, dev, Morten Brørup; +Cc: Tyler Retzlaff, Ferruh Yigit 07/09/2023 13:10, Morten Brørup: > > From: David Marchand [mailto:david.marchand@redhat.com] > > Sent: Thursday, 7 September 2023 10.55 > > > > On Thu, Sep 7, 2023 at 10:53 AM David Marchand > > <david.marchand@redhat.com> wrote: > > > > > > On Thu, Sep 7, 2023 at 10:50 AM Morten Brørup <mb@smartsharesystems.com> > > wrote: > > > > > This 10 value in the comment is easy to miss if some change with the > > > > > prefix is done. > > > > > Mentionning RTE_THREAD_INTERNAL_NAME_SIZE is enough. > > > > > > > > I disagree with David's comment to this. > > > > > > > > The function documentation is easier to read if the actual number is also > > mentioned. > > > > > > > > For the best of both worlds, you can add something like this nearby: > > > > > > > > _Static_assert(sizeof(RTE_THREAD_NAME_PREFIX) == sizeof("dpdk-"), > > > > "Length of RTE_THREAD_NAME_PREFIX has changed; " > > > > "the documentation needs updating."); > > > > > > And how will it catch the comment about 10 characters ? > > > > I mean you still have to re-read the whole documentation and look for > > some reference somewhere about 10 characters. > > The trick is to put the _Static_assert close to where the expectation occurs. That makes it easier to find where changes are necessary. > > And the _Static_assert can be added at all the locations where changes would be necessary. (Generally, we should add a lot more _Static_assert to the code where it makes assumptions about e.g. the ordering of fields in a struct, such as the vector optimized code.) > > Also, the failure message could be improved to include help about what to look for. > > PS: The reference to RTE_THREAD_INTERNAL_NAME_SIZE should remain in the documentation, so perhaps look for "RTE_THREAD_INTERNAL_NAME_SIZE". I agree with David, it is easier to maintain if not mentioning the exact value in the doc, and having a mention to RTE_THREAD_INTERNAL_NAME_SIZE is enough if it defined as "11". Then we need only one static assert (or RTE_BUILD_BUG_ON) below the definition to make sure the number is still valid. ^ permalink raw reply [flat|nested] 60+ messages in thread
* RE: [PATCH 05/11] eal: force prefix for internal threads 2023-09-11 16:26 ` Thomas Monjalon @ 2023-09-11 21:32 ` Morten Brørup 0 siblings, 0 replies; 60+ messages in thread From: Morten Brørup @ 2023-09-11 21:32 UTC (permalink / raw) To: Thomas Monjalon, David Marchand, dev; +Cc: Tyler Retzlaff, Ferruh Yigit > From: Thomas Monjalon [mailto:thomas@monjalon.net] > Sent: Monday, 11 September 2023 17.26 > > 07/09/2023 13:10, Morten Brørup: > > > From: David Marchand [mailto:david.marchand@redhat.com] > > > Sent: Thursday, 7 September 2023 10.55 > > > > > > On Thu, Sep 7, 2023 at 10:53 AM David Marchand > > > <david.marchand@redhat.com> wrote: > > > > > > > > On Thu, Sep 7, 2023 at 10:50 AM Morten Brørup > <mb@smartsharesystems.com> > > > wrote: > > > > > > This 10 value in the comment is easy to miss if some change > with the > > > > > > prefix is done. > > > > > > Mentionning RTE_THREAD_INTERNAL_NAME_SIZE is enough. > > > > > > > > > > I disagree with David's comment to this. > > > > > > > > > > The function documentation is easier to read if the actual > number is also > > > mentioned. > > > > > > > > > > For the best of both worlds, you can add something like this > nearby: > > > > > > > > > > _Static_assert(sizeof(RTE_THREAD_NAME_PREFIX) == sizeof("dpdk- > "), > > > > > "Length of RTE_THREAD_NAME_PREFIX has changed; " > > > > > "the documentation needs updating."); > > > > > > > > And how will it catch the comment about 10 characters ? > > > > > > I mean you still have to re-read the whole documentation and look > for > > > some reference somewhere about 10 characters. > > > > The trick is to put the _Static_assert close to where the expectation > occurs. That makes it easier to find where changes are necessary. > > > > And the _Static_assert can be added at all the locations where changes > would be necessary. (Generally, we should add a lot more _Static_assert > to the code where it makes assumptions about e.g. the ordering of fields > in a struct, such as the vector optimized code.) > > > > Also, the failure message could be improved to include help about what > to look for. > > > > PS: The reference to RTE_THREAD_INTERNAL_NAME_SIZE should remain in > the documentation, so perhaps look for "RTE_THREAD_INTERNAL_NAME_SIZE". > > I agree with David, it is easier to maintain if not mentioning > the exact value in the doc, > and having a mention to RTE_THREAD_INTERNAL_NAME_SIZE is enough > if it defined as "11". > Then we need only one static assert (or RTE_BUILD_BUG_ON) > below the definition to make sure the number is still valid. Sorry. Bad choice of words. David is obviously right that it is easy to miss if the prefix changes. My intention was to suggest a mitigation, so we could keep the exact value in the comment, making the documentation easier to read. Anyway, no objections from me. ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 06/11] lib: convert to internal control threads 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon ` (4 preceding siblings ...) 2023-09-06 16:12 ` [PATCH 05/11] eal: force prefix for internal threads Thomas Monjalon @ 2023-09-06 16:12 ` Thomas Monjalon 2023-09-06 16:12 ` [PATCH 07/11] drivers: " Thomas Monjalon ` (7 subsequent siblings) 13 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-06 16:12 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Anatoly Burakov, Harman Kalra, Bruce Richardson, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam, Naga Harish K S V, Jerin Jacob, Maxime Coquelin, Chenbo Xia Calls to rte_ctrl_thread_create() are replaced with rte_thread_create_internal_control(). Other pthread-related functions are replaced with the rte_thread API. Only pthread_cancel() has no replacement. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> --- lib/eal/common/eal_common_proc.c | 15 ++++++++------- lib/eal/freebsd/eal_interrupts.c | 10 +++++----- lib/eal/linux/eal_interrupts.c | 10 +++++----- lib/eal/linux/eal_timer.c | 11 ++++++----- lib/eal/unix/rte_thread.c | 2 +- lib/eal/windows/eal_interrupts.c | 2 +- lib/eventdev/rte_event_eth_rx_adapter.c | 23 ++++++++++++----------- lib/vhost/fd_man.c | 6 +++--- lib/vhost/fd_man.h | 2 +- lib/vhost/socket.c | 23 +++++++++++------------ lib/vhost/vduse.c | 5 +++-- 11 files changed, 56 insertions(+), 53 deletions(-) diff --git a/lib/eal/common/eal_common_proc.c b/lib/eal/common/eal_common_proc.c index 26e6b78f8f..f20a348ede 100644 --- a/lib/eal/common/eal_common_proc.c +++ b/lib/eal/common/eal_common_proc.c @@ -26,6 +26,7 @@ #include <rte_errno.h> #include <rte_lcore.h> #include <rte_log.h> +#include <rte_thread.h> #include "eal_memcfg.h" #include "eal_private.h" @@ -33,7 +34,7 @@ #include "eal_internal_cfg.h" static int mp_fd = -1; -static pthread_t mp_handle_tid; +static rte_thread_t mp_handle_tid; static char mp_filter[PATH_MAX]; /* Filter for secondary process sockets */ static char mp_dir_path[PATH_MAX]; /* The directory path for all mp sockets */ static pthread_mutex_t mp_mutex_action = PTHREAD_MUTEX_INITIALIZER; @@ -396,7 +397,7 @@ process_msg(struct mp_msg_internal *m, struct sockaddr_un *s) } } -static void * +static uint32_t mp_handle(void *arg __rte_unused) { struct mp_msg_internal msg; @@ -413,7 +414,7 @@ mp_handle(void *arg __rte_unused) process_msg(&msg, &sa); } - return NULL; + return 0; } static int @@ -646,8 +647,8 @@ rte_mp_channel_init(void) return -1; } - if (rte_ctrl_thread_create(&mp_handle_tid, "dpdk-mp-msg", - NULL, mp_handle, NULL) < 0) { + if (rte_thread_create_internal_control(&mp_handle_tid, "mp-msg", + mp_handle, NULL) < 0) { RTE_LOG(ERR, EAL, "failed to create mp thread: %s\n", strerror(errno)); close(dir_fd); @@ -671,8 +672,8 @@ rte_mp_channel_cleanup(void) if (fd < 0) return; - pthread_cancel(mp_handle_tid); - pthread_join(mp_handle_tid, NULL); + pthread_cancel((pthread_t)mp_handle_tid.opaque_id); + rte_thread_join(mp_handle_tid, NULL); close_socket_fd(fd); } diff --git a/lib/eal/freebsd/eal_interrupts.c b/lib/eal/freebsd/eal_interrupts.c index 68cdb9deb3..2b31dfb099 100644 --- a/lib/eal/freebsd/eal_interrupts.c +++ b/lib/eal/freebsd/eal_interrupts.c @@ -52,7 +52,7 @@ static rte_spinlock_t intr_lock = RTE_SPINLOCK_INITIALIZER; static struct rte_intr_source_list intr_sources; /* interrupt handling thread */ -static pthread_t intr_thread; +static rte_thread_t intr_thread; static volatile int kq = -1; @@ -591,7 +591,7 @@ eal_intr_process_interrupts(struct kevent *events, int nfds) } } -static void * +static uint32_t eal_intr_thread_main(void *arg __rte_unused) { struct kevent events[MAX_INTR_EVENTS]; @@ -619,7 +619,7 @@ eal_intr_thread_main(void *arg __rte_unused) } close(kq); kq = -1; - return NULL; + return 0; } int @@ -637,7 +637,7 @@ rte_eal_intr_init(void) } /* create the host thread to wait/handle the interrupt */ - ret = rte_ctrl_thread_create(&intr_thread, "dpdk-intr", NULL, + ret = rte_thread_create_internal_control(&intr_thread, "intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; @@ -746,5 +746,5 @@ rte_intr_free_epoll_fd(struct rte_intr_handle *intr_handle) int rte_thread_is_intr(void) { - return pthread_equal(intr_thread, pthread_self()); + return rte_thread_equal(intr_thread, rte_thread_self()); } diff --git a/lib/eal/linux/eal_interrupts.c b/lib/eal/linux/eal_interrupts.c index 19b36787b8..24fff3d3c2 100644 --- a/lib/eal/linux/eal_interrupts.c +++ b/lib/eal/linux/eal_interrupts.c @@ -5,7 +5,6 @@ #include <stdio.h> #include <stdint.h> #include <stdlib.h> -#include <pthread.h> #include <sys/queue.h> #include <unistd.h> #include <string.h> @@ -19,6 +18,7 @@ #include <eal_trace_internal.h> #include <rte_common.h> #include <rte_interrupts.h> +#include <rte_thread.h> #include <rte_per_lcore.h> #include <rte_lcore.h> #include <rte_branch_prediction.h> @@ -89,7 +89,7 @@ static union intr_pipefds intr_pipe; static struct rte_intr_source_list intr_sources; /* interrupt handling thread */ -static pthread_t intr_thread; +static rte_thread_t intr_thread; /* VFIO interrupts */ #ifdef VFIO_PRESENT @@ -1103,7 +1103,7 @@ eal_intr_handle_interrupts(int pfd, unsigned totalfds) * @return * never return; */ -static __rte_noreturn void * +static __rte_noreturn uint32_t eal_intr_thread_main(__rte_unused void *arg) { /* host thread, never break out */ @@ -1188,7 +1188,7 @@ rte_eal_intr_init(void) } /* create the host thread to wait/handle the interrupt */ - ret = rte_ctrl_thread_create(&intr_thread, "dpdk-intr", NULL, + ret = rte_thread_create_internal_control(&intr_thread, "intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; @@ -1601,5 +1601,5 @@ rte_intr_cap_multiple(struct rte_intr_handle *intr_handle) int rte_thread_is_intr(void) { - return pthread_equal(intr_thread, pthread_self()); + return rte_thread_equal(intr_thread, rte_thread_self()); } diff --git a/lib/eal/linux/eal_timer.c b/lib/eal/linux/eal_timer.c index 1898709700..3a30284e3a 100644 --- a/lib/eal/linux/eal_timer.c +++ b/lib/eal/linux/eal_timer.c @@ -14,6 +14,7 @@ #include <rte_common.h> #include <rte_cycles.h> +#include <rte_thread.h> #include "eal_private.h" @@ -71,14 +72,14 @@ static uint64_t eal_hpet_resolution_hz = 0; /* Incremented 4 times during one 32bits hpet full count */ static uint32_t eal_hpet_msb; -static pthread_t msb_inc_thread_id; +static rte_thread_t msb_inc_thread_id; /* * This function runs on a specific thread to update a global variable * containing used to process MSB of the HPET (unfortunately, we need * this because hpet is 32 bits by default under linux). */ -static void * +static uint32_t hpet_msb_inc(__rte_unused void *arg) { uint32_t t; @@ -89,7 +90,7 @@ hpet_msb_inc(__rte_unused void *arg) eal_hpet_msb ++; sleep(10); } - return NULL; + return 0; } uint64_t @@ -176,8 +177,8 @@ rte_eal_hpet_init(int make_default) /* create a thread that will increment a global variable for * msb (hpet is 32 bits by default under linux) */ - ret = rte_ctrl_thread_create(&msb_inc_thread_id, "dpdk-hpet-msb", NULL, - hpet_msb_inc, NULL); + ret = rte_thread_create_internal_control(&msb_inc_thread_id, "hpet-msb", + hpet_msb_inc, NULL); if (ret != 0) { RTE_LOG(ERR, EAL, "ERROR: Cannot create HPET timer thread!\n"); internal_conf->no_hpet = 1; diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c index f4076122a4..36a21ab2f9 100644 --- a/lib/eal/unix/rte_thread.c +++ b/lib/eal/unix/rte_thread.c @@ -190,7 +190,7 @@ rte_thread_create(rte_thread_t *thread_id, pthread_mutex_unlock(&ctx.wrapper_mutex); if (ret != 0) - pthread_join((pthread_t)thread_id->opaque_id, NULL); + rte_thread_join(*thread_id, NULL); cleanup: if (attrp != NULL) diff --git a/lib/eal/windows/eal_interrupts.c b/lib/eal/windows/eal_interrupts.c index 66a49c844a..49efdc098c 100644 --- a/lib/eal/windows/eal_interrupts.c +++ b/lib/eal/windows/eal_interrupts.c @@ -98,7 +98,7 @@ rte_eal_intr_init(void) return -1; } - ret = rte_thread_create_control(&intr_thread, "dpdk-intr", + ret = rte_thread_create_internal_control(&intr_thread, "intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c index 3ebfa5366d..c166ef69a8 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -10,6 +10,7 @@ #include <unistd.h> #include <rte_cycles.h> +#include <rte_thread.h> #include <rte_common.h> #include <dev_driver.h> #include <rte_errno.h> @@ -165,7 +166,7 @@ struct event_eth_rx_adapter { /* Count of interrupt vectors in use */ uint32_t num_intr_vec; /* Thread blocked on Rx interrupts */ - pthread_t rx_intr_thread; + rte_thread_t rx_intr_thread; /* Configuration callback for rte_service configuration */ rte_event_eth_rx_adapter_conf_cb conf_cb; /* Configuration callback argument */ @@ -1154,13 +1155,13 @@ rxa_intr_ring_del_entries(struct event_eth_rx_adapter *rx_adapter, rte_spinlock_unlock(&rx_adapter->intr_ring_lock); } -/* pthread callback handling interrupt mode receive queues +/* thread callback handling interrupt mode receive queues * After receiving an Rx interrupt, it enqueues the port id and queue id of the * interrupting queue to the adapter's ring buffer for interrupt events. * These events are picked up by rxa_intr_ring_dequeue() which is invoked from * the adapter service function. */ -static void * +static uint32_t rxa_intr_thread(void *arg) { struct event_eth_rx_adapter *rx_adapter = arg; @@ -1179,7 +1180,7 @@ rxa_intr_thread(void *arg) } } - return NULL; + return 0; } /* Dequeue <port, q> from interrupt ring and enqueue received @@ -1595,7 +1596,7 @@ static int rxa_create_intr_thread(struct event_eth_rx_adapter *rx_adapter) { int err; - char thread_name[RTE_MAX_THREAD_NAME_LEN]; + char thread_name[RTE_THREAD_INTERNAL_NAME_SIZE]; if (rx_adapter->intr_ring) return 0; @@ -1618,11 +1619,11 @@ rxa_create_intr_thread(struct event_eth_rx_adapter *rx_adapter) rte_spinlock_init(&rx_adapter->intr_ring_lock); - snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, - "dpdk-evt-rx%d", rx_adapter->id); + snprintf(thread_name, sizeof(thread_name), + "evt-rx%d", rx_adapter->id); - err = rte_ctrl_thread_create(&rx_adapter->rx_intr_thread, thread_name, - NULL, rxa_intr_thread, rx_adapter); + err = rte_thread_create_internal_control(&rx_adapter->rx_intr_thread, + thread_name, rxa_intr_thread, rx_adapter); if (!err) return 0; @@ -1640,12 +1641,12 @@ rxa_destroy_intr_thread(struct event_eth_rx_adapter *rx_adapter) { int err; - err = pthread_cancel(rx_adapter->rx_intr_thread); + err = pthread_cancel((pthread_t)rx_adapter->rx_intr_thread.opaque_id); if (err) RTE_EDEV_LOG_ERR("Can't cancel interrupt thread err = %d\n", err); - err = pthread_join(rx_adapter->rx_intr_thread, NULL); + err = rte_thread_join(rx_adapter->rx_intr_thread, NULL); if (err) RTE_EDEV_LOG_ERR("Can't join interrupt thread err = %d\n", err); diff --git a/lib/vhost/fd_man.c b/lib/vhost/fd_man.c index 1876fada33..134414fb4b 100644 --- a/lib/vhost/fd_man.c +++ b/lib/vhost/fd_man.c @@ -212,7 +212,7 @@ fdset_try_del(struct fdset *pfdset, int fd) * will wait until the flag is reset to zero(which indicates the callback is * finished), then it could free the context after fdset_del. */ -void * +uint32_t fdset_event_dispatch(void *arg) { int i; @@ -227,7 +227,7 @@ fdset_event_dispatch(void *arg) int val; if (pfdset == NULL) - return NULL; + return 0; while (1) { @@ -303,7 +303,7 @@ fdset_event_dispatch(void *arg) fdset_shrink(pfdset); } - return NULL; + return 0; } static void diff --git a/lib/vhost/fd_man.h b/lib/vhost/fd_man.h index 6f4499bdfa..6315904c8e 100644 --- a/lib/vhost/fd_man.h +++ b/lib/vhost/fd_man.h @@ -46,7 +46,7 @@ int fdset_add(struct fdset *pfdset, int fd, void *fdset_del(struct fdset *pfdset, int fd); int fdset_try_del(struct fdset *pfdset, int fd); -void *fdset_event_dispatch(void *arg); +uint32_t fdset_event_dispatch(void *arg); int fdset_pipe_init(struct fdset *fdset); diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c index 12095b0e1a..5882e44176 100644 --- a/lib/vhost/socket.c +++ b/lib/vhost/socket.c @@ -13,8 +13,8 @@ #include <sys/queue.h> #include <errno.h> #include <fcntl.h> -#include <pthread.h> +#include <rte_thread.h> #include <rte_log.h> #include "fd_man.h" @@ -431,7 +431,7 @@ struct vhost_user_reconnect_list { }; static struct vhost_user_reconnect_list reconn_list; -static pthread_t reconn_tid; +static rte_thread_t reconn_tid; static int vhost_user_connect_nonblock(char *path, int fd, struct sockaddr *un, size_t sz) @@ -455,7 +455,7 @@ vhost_user_connect_nonblock(char *path, int fd, struct sockaddr *un, size_t sz) return 0; } -static void * +static uint32_t vhost_user_client_reconnect(void *arg __rte_unused) { int ret; @@ -496,7 +496,7 @@ vhost_user_client_reconnect(void *arg __rte_unused) sleep(1); } - return NULL; + return 0; } static int @@ -511,8 +511,8 @@ vhost_user_reconnect_init(void) } TAILQ_INIT(&reconn_list.head); - ret = rte_ctrl_thread_create(&reconn_tid, "dpdk-vhost-reco", NULL, - vhost_user_client_reconnect, NULL); + ret = rte_thread_create_internal_control(&reconn_tid, "vhost-reco", + vhost_user_client_reconnect, NULL); if (ret != 0) { VHOST_LOG_CONFIG("thread", ERR, "failed to create reconnect thread\n"); if (pthread_mutex_destroy(&reconn_list.mutex)) @@ -1004,7 +1004,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags) if (!vsocket->is_vduse) { if ((flags & RTE_VHOST_USER_CLIENT) != 0) { vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT); - if (vsocket->reconnect && reconn_tid == 0) { + if (vsocket->reconnect && reconn_tid.opaque_id == 0) { if (vhost_user_reconnect_init() != 0) goto out_mutex; } @@ -1174,7 +1174,7 @@ int rte_vhost_driver_start(const char *path) { struct vhost_user_socket *vsocket; - static pthread_t fdset_tid; + static rte_thread_t fdset_tid; pthread_mutex_lock(&vhost_user.mutex); vsocket = find_vhost_user_socket(path); @@ -1186,7 +1186,7 @@ rte_vhost_driver_start(const char *path) if (vsocket->is_vduse) return vduse_device_create(path, vsocket->net_compliant_ol_flags); - if (fdset_tid == 0) { + if (fdset_tid.opaque_id == 0) { /** * create a pipe which will be waited by poll and notified to * rebuild the wait list of poll. @@ -1196,9 +1196,8 @@ rte_vhost_driver_start(const char *path) return -1; } - int ret = rte_ctrl_thread_create(&fdset_tid, - "dpdk-vhost-evt", NULL, fdset_event_dispatch, - &vhost_user.fdset); + int ret = rte_thread_create_internal_control(&fdset_tid, + "vhost-evt", fdset_event_dispatch, &vhost_user.fdset); if (ret != 0) { VHOST_LOG_CONFIG(path, ERR, "failed to create fdset handling thread\n"); fdset_pipe_uninit(&vhost_user.fdset); diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index 7770259f37..e342f53b81 100644 --- a/lib/vhost/vduse.c +++ b/lib/vhost/vduse.c @@ -16,6 +16,7 @@ #include <sys/stat.h> #include <rte_common.h> +#include <rte_thread.h> #include "fd_man.h" #include "iotlb.h" @@ -415,7 +416,7 @@ int vduse_device_create(const char *path, bool compliant_ol_flags) { int control_fd, dev_fd, vid, ret; - pthread_t fdset_tid; + rte_thread_t fdset_tid; uint32_t i, max_queue_pairs, total_queues; struct virtio_net *dev; struct virtio_net_config vnet_config = {{ 0 }}; @@ -435,7 +436,7 @@ vduse_device_create(const char *path, bool compliant_ol_flags) return -1; } - ret = rte_ctrl_thread_create(&fdset_tid, "dpdk-vduse-evt", NULL, + ret = rte_thread_create_internal_control(&fdset_tid, "vduse-evt", fdset_event_dispatch, &vduse.fdset); if (ret != 0) { VHOST_LOG_CONFIG(path, ERR, "failed to create vduse fdset handling thread\n"); -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 07/11] drivers: convert to internal control threads 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon ` (5 preceding siblings ...) 2023-09-06 16:12 ` [PATCH 06/11] lib: convert to internal control threads Thomas Monjalon @ 2023-09-06 16:12 ` Thomas Monjalon 2023-09-11 13:35 ` Andrew Rybchenko 2023-09-06 16:12 ` [PATCH 08/11] examples: convert to normal " Thomas Monjalon ` (6 subsequent siblings) 13 siblings, 1 reply; 60+ messages in thread From: Thomas Monjalon @ 2023-09-06 16:12 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao, Chengwen Feng, Kevin Laatz, Bruce Richardson, Abdullah Sevincer, Shepard Siegel, Ed Czeck, John Miller, Jingjing Wu, Beilei Xing, Qiming Yang, Qi Zhang, Rosen Xu, Wenjun Wu, Matan Azrad, Viacheslav Ovsiienko, Ori Kam, Suanming Mou, Andrew Rybchenko, Jiawen Wu, Jian Wang, Tianfei Zhang, Xiao Wang, Vijay Kumar Srivastava Calls to rte_ctrl_thread_create() are replaced with rte_thread_create_internal_control(). Other pthread-related functions are replaced with the rte_thread API. Only pthread_cancel() has no replacement. The mlx5 vDPA control threads were real-time threads with an affinity on the core specified by the devarg "event_core". As there is no heavy performance requirement, these threads are converted into real control threads. Some threads in dlb2 and mlx5 are not control threads because they are designed to run on some specific cores. It would be interesting to rework them in future. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> --- drivers/common/cnxk/roc_dev.c | 16 ++-- drivers/common/cnxk/roc_dev_priv.h | 2 +- drivers/common/cnxk/roc_nix_inl_dev.c | 9 +-- drivers/common/cnxk/roc_nix_inl_priv.h | 2 +- drivers/common/cnxk/roc_platform.h | 3 +- drivers/dma/skeleton/skeleton_dmadev.c | 7 +- drivers/event/dlb2/pf/base/dlb2_osdep.h | 14 ++-- drivers/event/dlb2/pf/base/dlb2_resource.c | 39 +++++----- drivers/event/dlb2/pf/dlb2_main.h | 1 - drivers/net/ark/ark_ethdev.c | 11 ++- drivers/net/ark/ark_pktgen.c | 8 +- drivers/net/ark/ark_pktgen.h | 2 +- drivers/net/iavf/iavf_vchnl.c | 2 +- drivers/net/ice/ice_dcf_parent.c | 7 +- drivers/net/ipn3ke/ipn3ke_representor.c | 17 ++--- drivers/net/ixgbe/ixgbe_ethdev.c | 7 +- drivers/net/mlx5/mlx5.h | 2 +- drivers/net/mlx5/mlx5_hws_cnt.c | 42 ++++++----- drivers/net/sfc/sfc_mae.h | 2 +- drivers/net/sfc/sfc_mae_counter.c | 11 ++- drivers/net/txgbe/txgbe_ethdev.c | 6 +- drivers/raw/ifpga/ifpga_rawdev.c | 19 +++-- drivers/vdpa/ifc/ifcvf_vdpa.c | 86 ++++++++++------------ drivers/vdpa/mlx5/mlx5_vdpa.c | 2 +- drivers/vdpa/mlx5/mlx5_vdpa.h | 10 +-- drivers/vdpa/mlx5/mlx5_vdpa_cthread.c | 70 +++++------------- drivers/vdpa/mlx5/mlx5_vdpa_event.c | 64 +++++----------- drivers/vdpa/sfc/sfc_vdpa_ops.c | 15 ++-- drivers/vdpa/sfc/sfc_vdpa_ops.h | 3 +- 29 files changed, 203 insertions(+), 276 deletions(-) diff --git a/drivers/common/cnxk/roc_dev.c b/drivers/common/cnxk/roc_dev.c index 13d3eece47..08fd13f741 100644 --- a/drivers/common/cnxk/roc_dev.c +++ b/drivers/common/cnxk/roc_dev.c @@ -18,7 +18,7 @@ #define ROC_PCI_SRIOV_TOTAL_VF 0x0e /* Total VFs */ /* VF Mbox handler thread name */ -#define MBOX_HANDLER_NAME_MAX_LEN 25 +#define MBOX_HANDLER_NAME_MAX_LEN RTE_THREAD_INTERNAL_NAME_SIZE /* VF interrupt message pending bits - mbox or flr */ #define ROC_DEV_MBOX_PEND BIT_ULL(0) @@ -1070,7 +1070,7 @@ vf_flr_handle_msg(void *param, dev_intr_t *flr) } } -static void * +static uint32_t pf_vf_mbox_thread_main(void *arg) { struct dev *dev = arg; @@ -1114,7 +1114,7 @@ pf_vf_mbox_thread_main(void *arg) pthread_mutex_unlock(&dev->sync.mutex); - return NULL; + return 0; } static void @@ -1455,10 +1455,10 @@ dev_init(struct dev *dev, struct plt_pci_device *pci_dev) pthread_cond_init(&dev->sync.pfvf_msg_cond, NULL); pthread_mutex_init(&dev->sync.mutex, NULL); - snprintf(name, MBOX_HANDLER_NAME_MAX_LEN, "pf%d_vf_msg_hndlr", dev->pf); + snprintf(name, MBOX_HANDLER_NAME_MAX_LEN, "mbox_pf%d", dev->pf); dev->sync.start_thread = true; - rc = plt_ctrl_thread_create(&dev->sync.pfvf_msg_thread, name, NULL, - pf_vf_mbox_thread_main, dev); + rc = plt_thread_create_control(&dev->sync.pfvf_msg_thread, name, + pf_vf_mbox_thread_main, dev); if (rc != 0) { plt_err("Failed to create thread for VF mbox handling\n"); goto iounmap; @@ -1488,7 +1488,7 @@ dev_init(struct dev *dev, struct plt_pci_device *pci_dev) if (dev->sync.start_thread) { dev->sync.start_thread = false; pthread_cond_signal(&dev->sync.pfvf_msg_cond); - pthread_join(dev->sync.pfvf_msg_thread, NULL); + plt_thread_join(dev->sync.pfvf_msg_thread, NULL); pthread_mutex_destroy(&dev->sync.mutex); pthread_cond_destroy(&dev->sync.pfvf_msg_cond); } @@ -1519,7 +1519,7 @@ dev_fini(struct dev *dev, struct plt_pci_device *pci_dev) if (dev->sync.start_thread) { dev->sync.start_thread = false; pthread_cond_signal(&dev->sync.pfvf_msg_cond); - pthread_join(dev->sync.pfvf_msg_thread, NULL); + plt_thread_join(dev->sync.pfvf_msg_thread, NULL); pthread_mutex_destroy(&dev->sync.mutex); pthread_cond_destroy(&dev->sync.pfvf_msg_cond); } diff --git a/drivers/common/cnxk/roc_dev_priv.h b/drivers/common/cnxk/roc_dev_priv.h index 1f84f74ff3..c1a37aa4f0 100644 --- a/drivers/common/cnxk/roc_dev_priv.h +++ b/drivers/common/cnxk/roc_dev_priv.h @@ -73,7 +73,7 @@ dev_is_afvf(uint16_t pf_func) struct mbox_sync { bool start_thread; uint8_t msg_avail; - pthread_t pfvf_msg_thread; + rte_thread_t pfvf_msg_thread; pthread_cond_t pfvf_msg_cond; pthread_mutex_t mutex; }; diff --git a/drivers/common/cnxk/roc_nix_inl_dev.c b/drivers/common/cnxk/roc_nix_inl_dev.c index d76158e30d..7400069309 100644 --- a/drivers/common/cnxk/roc_nix_inl_dev.c +++ b/drivers/common/cnxk/roc_nix_inl_dev.c @@ -746,7 +746,7 @@ inl_outb_soft_exp_poll(struct nix_inl_dev *inl_dev, uint32_t ring_idx) } } -static void * +static uint32_t nix_inl_outb_poll_thread(void *args) { struct nix_inl_dev *inl_dev = args; @@ -816,9 +816,8 @@ nix_inl_outb_poll_thread_setup(struct nix_inl_dev *inl_dev) soft_exp_consumer_cnt = 0; soft_exp_poll_thread_exit = false; - rc = plt_ctrl_thread_create(&inl_dev->soft_exp_poll_thread, - "OUTB_SOFT_EXP_POLL_THREAD", NULL, - nix_inl_outb_poll_thread, inl_dev); + rc = plt_thread_create_control(&inl_dev->soft_exp_poll_thread, + "outb-poll", nix_inl_outb_poll_thread, inl_dev); if (rc) { plt_bitmap_free(inl_dev->soft_exp_ring_bmap); plt_free(inl_dev->soft_exp_ring_bmap_mem); @@ -1020,7 +1019,7 @@ roc_nix_inl_dev_fini(struct roc_nix_inl_dev *roc_inl_dev) if (inl_dev->set_soft_exp_poll) { soft_exp_poll_thread_exit = true; - pthread_join(inl_dev->soft_exp_poll_thread, NULL); + rte_thread_join(inl_dev->soft_exp_poll_thread, NULL); plt_bitmap_free(inl_dev->soft_exp_ring_bmap); plt_free(inl_dev->soft_exp_ring_bmap_mem); plt_free(inl_dev->sa_soft_exp_ring); diff --git a/drivers/common/cnxk/roc_nix_inl_priv.h b/drivers/common/cnxk/roc_nix_inl_priv.h index b0a8976c6b..b2b89227b1 100644 --- a/drivers/common/cnxk/roc_nix_inl_priv.h +++ b/drivers/common/cnxk/roc_nix_inl_priv.h @@ -67,7 +67,7 @@ struct nix_inl_dev { struct roc_cpt_lf cpt_lf; /* OUTB soft expiry poll thread */ - pthread_t soft_exp_poll_thread; + rte_thread_t soft_exp_poll_thread; uint32_t soft_exp_poll_freq; uint64_t *sa_soft_exp_ring; bool set_soft_exp_poll; diff --git a/drivers/common/cnxk/roc_platform.h b/drivers/common/cnxk/roc_platform.h index 08f83aba12..d8f2707a6e 100644 --- a/drivers/common/cnxk/roc_platform.h +++ b/drivers/common/cnxk/roc_platform.h @@ -134,7 +134,8 @@ #define plt_intr_disable rte_intr_disable #define plt_thread_is_intr rte_thread_is_intr #define plt_intr_callback_fn rte_intr_callback_fn -#define plt_ctrl_thread_create rte_ctrl_thread_create +#define plt_thread_create_control rte_thread_create_internal_control +#define plt_thread_join rte_thread_join #define plt_intr_efd_counter_size_get rte_intr_efd_counter_size_get #define plt_intr_efd_counter_size_set rte_intr_efd_counter_size_set diff --git a/drivers/dma/skeleton/skeleton_dmadev.c b/drivers/dma/skeleton/skeleton_dmadev.c index 4fc2319668..eabe88fada 100644 --- a/drivers/dma/skeleton/skeleton_dmadev.c +++ b/drivers/dma/skeleton/skeleton_dmadev.c @@ -100,7 +100,7 @@ static int skeldma_start(struct rte_dma_dev *dev) { struct skeldma_hw *hw = dev->data->dev_private; - char name[RTE_MAX_THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; rte_cpuset_t cpuset; int ret; @@ -127,8 +127,9 @@ skeldma_start(struct rte_dma_dev *dev) rte_mb(); - snprintf(name, sizeof(name), "dpdk-dma-skel%d", dev->data->dev_id); - ret = rte_thread_create_control(&hw->thread, name, cpucopy_thread, dev); + snprintf(name, sizeof(name), "dma-skel%d", dev->data->dev_id); + ret = rte_thread_create_internal_control(&hw->thread, name, + cpucopy_thread, dev); if (ret) { SKELDMA_LOG(ERR, "Start cpucopy thread fail!"); return -EINVAL; diff --git a/drivers/event/dlb2/pf/base/dlb2_osdep.h b/drivers/event/dlb2/pf/base/dlb2_osdep.h index 75860cca4d..06d69f39b1 100644 --- a/drivers/event/dlb2/pf/base/dlb2_osdep.h +++ b/drivers/event/dlb2/pf/base/dlb2_osdep.h @@ -8,7 +8,6 @@ #include <string.h> #include <time.h> #include <unistd.h> -#include <pthread.h> #include <rte_string_fns.h> #include <rte_cycles.h> @@ -154,7 +153,7 @@ static inline void os_fence_hcw(struct dlb2_hw *hw, u64 *pp_addr) * map and unmap requests. To prevent deadlock, this function gives other * threads a chance to grab the resource mutex and configure hardware. */ -static void *dlb2_complete_queue_map_unmap(void *__args) +static uint32_t dlb2_complete_queue_map_unmap(void *__args) { struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)__args; int ret; @@ -180,7 +179,7 @@ static void *dlb2_complete_queue_map_unmap(void *__args) rte_spinlock_unlock(&dlb2_dev->resource_mutex); - return NULL; + return 0; } @@ -194,16 +193,13 @@ static void *dlb2_complete_queue_map_unmap(void *__args) static inline void os_schedule_work(struct dlb2_hw *hw) { struct dlb2_dev *dlb2_dev; - pthread_t complete_queue_map_unmap_thread; + rte_thread_t complete_queue_map_unmap_thread; int ret; dlb2_dev = container_of(hw, struct dlb2_dev, hw); - ret = rte_ctrl_thread_create(&complete_queue_map_unmap_thread, - "dpdk-dlb-qunmap", - NULL, - dlb2_complete_queue_map_unmap, - dlb2_dev); + ret = rte_thread_create_internal_control(&complete_queue_map_unmap_thread, + "dlb-qunmap", dlb2_complete_queue_map_unmap, dlb2_dev); if (ret) DLB2_ERR(dlb2_dev, "Could not create queue complete map/unmap thread, err=%d\n", diff --git a/drivers/event/dlb2/pf/base/dlb2_resource.c b/drivers/event/dlb2/pf/base/dlb2_resource.c index dd8390a013..7ce3e3531c 100644 --- a/drivers/event/dlb2/pf/base/dlb2_resource.c +++ b/drivers/event/dlb2/pf/base/dlb2_resource.c @@ -759,18 +759,13 @@ static int dlb2_attach_ldb_queues(struct dlb2_hw *hw, } static int -dlb2_pp_profile(struct dlb2_hw *hw, int port, int cpu, bool is_ldb) +dlb2_pp_profile(struct dlb2_hw *hw, int port, bool is_ldb) { u64 cycle_start = 0ULL, cycle_end = 0ULL; struct dlb2_hcw hcw_mem[DLB2_HCW_MEM_SIZE], *hcw; void __iomem *pp_addr; - cpu_set_t cpuset; int i; - CPU_ZERO(&cpuset); - CPU_SET(cpu, &cpuset); - sched_setaffinity(0, sizeof(cpuset), &cpuset); - pp_addr = os_map_producer_port(hw, port, is_ldb); /* Point hcw to a 64B-aligned location */ @@ -797,18 +792,15 @@ dlb2_pp_profile(struct dlb2_hw *hw, int port, int cpu, bool is_ldb) return (int)(cycle_end - cycle_start); } -static void * +static uint32_t dlb2_pp_profile_func(void *data) { struct dlb2_pp_thread_data *thread_data = data; - int cycles; - cycles = dlb2_pp_profile(thread_data->hw, thread_data->pp, - thread_data->cpu, thread_data->is_ldb); + thread_data->cycles = dlb2_pp_profile(thread_data->hw, + thread_data->pp, thread_data->is_ldb); - thread_data->cycles = cycles; - - return NULL; + return 0; } static int dlb2_pp_cycle_comp(const void *a, const void *b) @@ -831,7 +823,9 @@ dlb2_get_pp_allocation(struct dlb2_hw *hw, int cpu, int port_type) int num_ports_per_sort, num_ports, num_sort, i, err; bool is_ldb = (port_type == DLB2_LDB_PORT); int *port_allocations; - pthread_t pthread; + rte_thread_t thread; + rte_thread_attr_t th_attr; + char th_name[RTE_THREAD_INTERNAL_NAME_SIZE]; if (is_ldb) { port_allocations = hw->ldb_pp_allocations; @@ -857,16 +851,25 @@ dlb2_get_pp_allocation(struct dlb2_hw *hw, int cpu, int port_type) dlb2_thread_data[i].pp = i; dlb2_thread_data[i].cycles = 0; dlb2_thread_data[i].hw = hw; - dlb2_thread_data[i].cpu = cpu; - err = pthread_create(&pthread, NULL, &dlb2_pp_profile_func, - &dlb2_thread_data[i]); + err = rte_thread_attr_init(&th_attr); + if (err != 0) { + DLB2_LOG_ERR(": thread attribute failed! err=%d", err); + return; + } + CPU_SET(cpu, &th_attr.cpuset); + + err = rte_thread_create(&thread, &th_attr, + &dlb2_pp_profile_func, &dlb2_thread_data[i]); if (err) { DLB2_LOG_ERR(": thread creation failed! err=%d", err); return; } - err = pthread_join(pthread, NULL); + snprintf(th_name, sizeof(th_name), "dlb2-pp%d", cpu); + rte_thread_set_prefixed_name(thread, th_name); + + err = rte_thread_join(thread, NULL); if (err) { DLB2_LOG_ERR(": thread join failed! err=%d", err); return; diff --git a/drivers/event/dlb2/pf/dlb2_main.h b/drivers/event/dlb2/pf/dlb2_main.h index 4c64d72e9c..12912a2dec 100644 --- a/drivers/event/dlb2/pf/dlb2_main.h +++ b/drivers/event/dlb2/pf/dlb2_main.h @@ -52,7 +52,6 @@ struct dlb2_dev { struct dlb2_pp_thread_data { struct dlb2_hw *hw; int pp; - int cpu; bool is_ldb; int cycles; }; diff --git a/drivers/net/ark/ark_ethdev.c b/drivers/net/ark/ark_ethdev.c index 30814650bf..3ddcc9b461 100644 --- a/drivers/net/ark/ark_ethdev.c +++ b/drivers/net/ark/ark_ethdev.c @@ -598,17 +598,16 @@ eth_ark_dev_start(struct rte_eth_dev *dev) ark_pktchkr_run(ark->pc); if (!ark->isvf && ark->start_pg && !ark->pg_running) { - pthread_t thread; + rte_thread_t thread; /* Delay packet generator start allow the hardware to be ready * This is only used for sanity checking with internal generator */ - char tname[32]; - snprintf(tname, sizeof(tname), "dpdk-ark-pg%d", - dev->data->port_id); + char tname[RTE_THREAD_INTERNAL_NAME_SIZE]; + snprintf(tname, sizeof(tname), "ark-pg%d", dev->data->port_id); - if (rte_ctrl_thread_create(&thread, tname, NULL, - ark_pktgen_delay_start, ark->pg)) { + if (rte_thread_create_internal_control(&thread, tname, + ark_pktgen_delay_start, ark->pg)) { ARK_PMD_LOG(ERR, "Could not create pktgen " "starter thread\n"); return -1; diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c index cd2d3adc51..69ff7072b2 100644 --- a/drivers/net/ark/ark_pktgen.c +++ b/drivers/net/ark/ark_pktgen.c @@ -4,10 +4,10 @@ #include <stdlib.h> #include <unistd.h> -#include <pthread.h> #include <rte_string_fns.h> #include <rte_malloc.h> +#include <rte_thread.h> #include "ark_pktgen.h" #include "ark_logs.h" @@ -467,7 +467,7 @@ ark_pktgen_setup(ark_pkt_gen_t handle) } } -void * +uint32_t ark_pktgen_delay_start(void *arg) { struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)arg; @@ -476,8 +476,8 @@ ark_pktgen_delay_start(void *arg) * perform a blind sleep here to ensure that the external test * application has time to setup the test before we generate packets */ - pthread_detach(pthread_self()); + rte_thread_detach(rte_thread_self()); usleep(100000); ark_pktgen_run(inst); - return NULL; + return 0; } diff --git a/drivers/net/ark/ark_pktgen.h b/drivers/net/ark/ark_pktgen.h index 7147fe1bd4..925058367c 100644 --- a/drivers/net/ark/ark_pktgen.h +++ b/drivers/net/ark/ark_pktgen.h @@ -75,6 +75,6 @@ void ark_pktgen_set_hdr_dW(ark_pkt_gen_t handle, uint32_t *hdr); void ark_pktgen_set_start_offset(ark_pkt_gen_t handle, uint32_t x); void ark_pktgen_parse(char *argv); void ark_pktgen_setup(ark_pkt_gen_t handle); -void *ark_pktgen_delay_start(void *arg); +uint32_t ark_pktgen_delay_start(void *arg); #endif diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c index 6baa6d5955..b3e106b41f 100644 --- a/drivers/net/iavf/iavf_vchnl.c +++ b/drivers/net/iavf/iavf_vchnl.c @@ -135,7 +135,7 @@ iavf_dev_event_handler_init(void) TAILQ_INIT(&handler->pending); pthread_mutex_init(&handler->lock, NULL); - if (rte_thread_create_control(&handler->tid, "dpdk-iavf-event", + if (rte_thread_create_internal_control(&handler->tid, "iavf-event", iavf_dev_event_handle, NULL)) { __atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED); return -1; diff --git a/drivers/net/ice/ice_dcf_parent.c b/drivers/net/ice/ice_dcf_parent.c index d3bb65874f..173ed9f81d 100644 --- a/drivers/net/ice/ice_dcf_parent.c +++ b/drivers/net/ice/ice_dcf_parent.c @@ -165,9 +165,8 @@ ice_dcf_vsi_update_service_handler(void *param) static void start_vsi_reset_thread(struct ice_dcf_hw *dcf_hw, bool vfr, uint16_t vf_id) { -#define THREAD_NAME_LEN 16 struct ice_dcf_reset_event_param *param; - char name[THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; rte_thread_t thread; int ret; @@ -181,8 +180,8 @@ start_vsi_reset_thread(struct ice_dcf_hw *dcf_hw, bool vfr, uint16_t vf_id) param->vfr = vfr; param->vf_id = vf_id; - snprintf(name, sizeof(name), "dpdk-ice-rst%u", vf_id); - ret = rte_thread_create_control(&thread, name, + snprintf(name, sizeof(name), "ice-rst%u", vf_id); + ret = rte_thread_create_internal_control(&thread, name, ice_dcf_vsi_update_service_handler, param); if (ret != 0) { PMD_DRV_LOG(ERR, "Failed to start the thread for reset handling"); diff --git a/drivers/net/ipn3ke/ipn3ke_representor.c b/drivers/net/ipn3ke/ipn3ke_representor.c index c82f8b5333..57ec7a19bc 100644 --- a/drivers/net/ipn3ke/ipn3ke_representor.c +++ b/drivers/net/ipn3ke/ipn3ke_representor.c @@ -27,7 +27,7 @@ #include "ipn3ke_ethdev.h" static int ipn3ke_rpst_scan_num; -static pthread_t ipn3ke_rpst_scan_thread; +static rte_thread_t ipn3ke_rpst_scan_thread; /** Double linked list of representor port. */ TAILQ_HEAD(ipn3ke_rpst_list, ipn3ke_rpst); @@ -2558,7 +2558,7 @@ ipn3ke_rpst_link_check(struct ipn3ke_rpst *rpst) return 0; } -static void * +static uint32_t ipn3ke_rpst_scan_handle_request(__rte_unused void *param) { struct ipn3ke_rpst *rpst; @@ -2580,10 +2580,10 @@ ipn3ke_rpst_scan_handle_request(__rte_unused void *param) rte_delay_us(50 * MS); if (num == 0 || num == 0xffffff) - return NULL; + return 0; } - return NULL; + return 0; } static int @@ -2592,20 +2592,19 @@ ipn3ke_rpst_scan_check(void) int ret; if (ipn3ke_rpst_scan_num == 1) { - ret = rte_ctrl_thread_create(&ipn3ke_rpst_scan_thread, - "dpdk-ipn3ke-scn", - NULL, + ret = rte_thread_create_internal_control(&ipn3ke_rpst_scan_thread, + "ipn3ke-scn", ipn3ke_rpst_scan_handle_request, NULL); if (ret) { IPN3KE_AFU_PMD_ERR("Fail to create ipn3ke rpst scan thread"); return -1; } } else if (ipn3ke_rpst_scan_num == 0) { - ret = pthread_cancel(ipn3ke_rpst_scan_thread); + ret = pthread_cancel((pthread_t)ipn3ke_rpst_scan_thread.opaque_id); if (ret) IPN3KE_AFU_PMD_ERR("Can't cancel the thread"); - ret = pthread_join(ipn3ke_rpst_scan_thread, NULL); + ret = rte_thread_join(ipn3ke_rpst_scan_thread, NULL); if (ret) IPN3KE_AFU_PMD_ERR("Can't join the thread"); diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c index 64e7e5d7d6..cd4a85b3a7 100644 --- a/drivers/net/ixgbe/ixgbe_ethdev.c +++ b/drivers/net/ixgbe/ixgbe_ethdev.c @@ -4328,10 +4328,9 @@ ixgbe_dev_link_update_share(struct rte_eth_dev *dev, * when there is no link thread running. */ intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; - if (rte_thread_create_control(&ad->link_thread_tid, - "dpdk-ixgbe-link", - ixgbe_dev_setup_link_thread_handler, - dev) < 0) { + if (rte_thread_create_internal_control(&ad->link_thread_tid, + "ixgbe-link", + ixgbe_dev_setup_link_thread_handler, dev) < 0) { PMD_DRV_LOG(ERR, "Create link thread failed!"); /* NOTE: review for potential ordering optimization */ diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 3785103308..c587e13c63 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1368,7 +1368,7 @@ struct mlx5_hws_cnt_svc_mng { uint32_t refcnt; uint32_t service_core; uint32_t query_interval; - pthread_t service_thread; + rte_thread_t service_thread; uint8_t svc_running; struct mlx5_hws_aso_mng aso_mng __rte_cache_aligned; }; diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c index a0f0febbc7..f556a9fbcc 100644 --- a/drivers/net/mlx5/mlx5_hws_cnt.c +++ b/drivers/net/mlx5/mlx5_hws_cnt.c @@ -9,6 +9,7 @@ #include <mlx5_devx_cmds.h> #include <rte_cycles.h> #include <rte_eal_paging.h> +#include <rte_thread.h> #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) @@ -286,7 +287,7 @@ mlx5_hws_cnt_raw_data_alloc(struct mlx5_dev_ctx_shared *sh, uint32_t n) return NULL; } -static void * +static uint32_t mlx5_hws_cnt_svc(void *opaque) { struct mlx5_dev_ctx_shared *sh = @@ -318,7 +319,7 @@ mlx5_hws_cnt_svc(void *opaque) if (interval > query_us) rte_delay_us_sleep(sleep_us); } - return NULL; + return 0; } static void @@ -438,36 +439,37 @@ mlx5_hws_cnt_pool_init(struct mlx5_dev_ctx_shared *sh, int mlx5_hws_cnt_service_thread_create(struct mlx5_dev_ctx_shared *sh) { - char name[RTE_MAX_THREAD_NAME_LEN]; - rte_cpuset_t cpuset; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; + rte_thread_attr_t attr; int ret; uint32_t service_core = sh->cnt_svc->service_core; - CPU_ZERO(&cpuset); + ret = rte_thread_attr_init(&attr); + if (ret != 0) + goto error; + CPU_SET(service_core, &attr.cpuset); sh->cnt_svc->svc_running = 1; - ret = pthread_create(&sh->cnt_svc->service_thread, NULL, - mlx5_hws_cnt_svc, sh); - if (ret != 0) { - DRV_LOG(ERR, "Failed to create HW steering's counter service thread."); - return -ENOSYS; - } - snprintf(name, RTE_MAX_THREAD_NAME_LEN, "dpdk-mlx5-%d", service_core); - rte_thread_set_name((rte_thread_t){(uintptr_t)sh->cnt_svc->service_thread}, - name); - CPU_SET(service_core, &cpuset); - pthread_setaffinity_np(sh->cnt_svc->service_thread, sizeof(cpuset), - &cpuset); + ret = rte_thread_create(&sh->cnt_svc->service_thread, + &attr, mlx5_hws_cnt_svc, sh); + if (ret != 0) + goto error; + snprintf(name, sizeof(name), "mlx5-cn%d", service_core); + rte_thread_set_prefixed_name(sh->cnt_svc->service_thread, name); + return 0; +error: + DRV_LOG(ERR, "Failed to create HW steering's counter service thread."); + return ret; } void mlx5_hws_cnt_service_thread_destroy(struct mlx5_dev_ctx_shared *sh) { - if (sh->cnt_svc->service_thread == 0) + if (sh->cnt_svc->service_thread.opaque_id == 0) return; sh->cnt_svc->svc_running = 0; - pthread_join(sh->cnt_svc->service_thread, NULL); - sh->cnt_svc->service_thread = 0; + rte_thread_join(sh->cnt_svc->service_thread, NULL); + sh->cnt_svc->service_thread.opaque_id = 0; } static int diff --git a/drivers/net/sfc/sfc_mae.h b/drivers/net/sfc/sfc_mae.h index 646d055ac1..7988424449 100644 --- a/drivers/net/sfc/sfc_mae.h +++ b/drivers/net/sfc/sfc_mae.h @@ -196,7 +196,7 @@ struct sfc_mae_counter_registry { } service; struct { /** Counter thread ID */ - pthread_t id; + rte_thread_t id; /** The thread should keep running */ bool run; } thread; diff --git a/drivers/net/sfc/sfc_mae_counter.c b/drivers/net/sfc/sfc_mae_counter.c index 631b54afeb..ba17295719 100644 --- a/drivers/net/sfc/sfc_mae_counter.c +++ b/drivers/net/sfc/sfc_mae_counter.c @@ -490,7 +490,7 @@ sfc_mae_counter_service_routine(void *arg) return 0; } -static void * +static uint32_t sfc_mae_counter_thread(void *data) { struct sfc_adapter *sa = data; @@ -521,7 +521,7 @@ sfc_mae_counter_thread(void *data) } } - return NULL; + return 0; } static void @@ -687,7 +687,7 @@ sfc_mae_counter_thread_stop(struct sfc_adapter *sa) __atomic_store_n(&counter_registry->polling.thread.run, false, __ATOMIC_RELEASE); - rc = pthread_join(counter_registry->polling.thread.id, NULL); + rc = rte_thread_join(counter_registry->polling.thread.id, NULL); if (rc != 0) sfc_err(sa, "failed to join the MAE counter polling thread"); @@ -710,9 +710,8 @@ sfc_mae_counter_thread_spawn(struct sfc_adapter *sa, counter_registry->polling_mode = SFC_MAE_COUNTER_POLLING_THREAD; counter_registry->polling.thread.run = true; - rc = rte_ctrl_thread_create(&sa->mae.counter_registry.polling.thread.id, - "dpdk-sfc-maecnt", NULL, - sfc_mae_counter_thread, sa); + rc = rte_thread_create_internal_control(&sa->mae.counter_registry.polling.thread.id, + "sfc-maecnt", sfc_mae_counter_thread, sa); return rc; } diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c index 198fac8318..15911a3621 100644 --- a/drivers/net/txgbe/txgbe_ethdev.c +++ b/drivers/net/txgbe/txgbe_ethdev.c @@ -2896,9 +2896,9 @@ txgbe_dev_link_update_share(struct rte_eth_dev *dev, * when there is no link thread running. */ intr->flags |= TXGBE_FLAG_NEED_LINK_CONFIG; - if (rte_thread_create_control(&ad->link_thread_tid, - "dpdk-txgbe-link", - txgbe_dev_setup_link_thread_handler, dev) < 0) { + if (rte_thread_create_internal_control(&ad->link_thread_tid, + "txgbe-link", + txgbe_dev_setup_link_thread_handler, dev) < 0) { PMD_DRV_LOG(ERR, "Create link thread failed!"); __atomic_clear(&ad->link_thread_running, __ATOMIC_SEQ_CST); } diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c index a7b18299de..f89bd3f9e2 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.c +++ b/drivers/raw/ifpga/ifpga_rawdev.c @@ -74,7 +74,7 @@ static const struct rte_pci_id pci_ifpga_map[] = { static struct ifpga_rawdev ifpga_rawdevices[IFPGA_RAWDEV_NUM]; static int ifpga_monitor_refcnt; -static pthread_t ifpga_monitor_start_thread; +static rte_thread_t ifpga_monitor_start_thread; static struct ifpga_rawdev * ifpga_rawdev_allocate(struct rte_rawdev *rawdev); @@ -504,7 +504,7 @@ static int set_surprise_link_check_aer( return -EFAULT; } -static void * +static uint32_t ifpga_rawdev_gsd_handle(__rte_unused void *param) { struct ifpga_rawdev *ifpga_rdev; @@ -532,7 +532,7 @@ ifpga_rawdev_gsd_handle(__rte_unused void *param) rte_delay_us(100 * MS); } - return NULL; + return 0; } static int @@ -550,11 +550,10 @@ ifpga_monitor_start_func(struct ifpga_rawdev *dev) dev->poll_enabled = 1; if (!__atomic_fetch_add(&ifpga_monitor_refcnt, 1, __ATOMIC_RELAXED)) { - ret = rte_ctrl_thread_create(&ifpga_monitor_start_thread, - "dpdk-ifpga-mon", NULL, - ifpga_rawdev_gsd_handle, NULL); + ret = rte_thread_create_internal_control(&ifpga_monitor_start_thread, + "ifpga-mon", ifpga_rawdev_gsd_handle, NULL); if (ret != 0) { - ifpga_monitor_start_thread = 0; + ifpga_monitor_start_thread.opaque_id = 0; IFPGA_RAWDEV_PMD_ERR( "Fail to create ifpga monitor thread"); return -1; @@ -575,12 +574,12 @@ ifpga_monitor_stop_func(struct ifpga_rawdev *dev) dev->poll_enabled = 0; if (!(__atomic_fetch_sub(&ifpga_monitor_refcnt, 1, __ATOMIC_RELAXED) - 1) && - ifpga_monitor_start_thread) { - ret = pthread_cancel(ifpga_monitor_start_thread); + ifpga_monitor_start_thread.opaque_id != 0) { + ret = pthread_cancel((pthread_t)ifpga_monitor_start_thread.opaque_id); if (ret) IFPGA_RAWDEV_PMD_ERR("Can't cancel the thread"); - ret = pthread_join(ifpga_monitor_start_thread, NULL); + ret = rte_thread_join(ifpga_monitor_start_thread, NULL); if (ret) IFPGA_RAWDEV_PMD_ERR("Can't join the thread"); diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c index 55346bbc08..f034bd59ba 100644 --- a/drivers/vdpa/ifc/ifcvf_vdpa.c +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c @@ -58,8 +58,8 @@ struct ifcvf_internal { int vfio_container_fd; int vfio_group_fd; int vfio_dev_fd; - pthread_t tid; /* thread for notify relay */ - pthread_t intr_tid; /* thread for config space change interrupt relay */ + rte_thread_t tid; /* thread for notify relay */ + rte_thread_t intr_tid; /* thread for config space change interrupt relay */ int epfd; int csc_epfd; int vid; @@ -496,7 +496,7 @@ vdpa_disable_vfio_intr(struct ifcvf_internal *internal) return 0; } -static void * +static uint32_t notify_relay(void *arg) { int i, kickfd, epfd, nfds = 0; @@ -514,7 +514,7 @@ notify_relay(void *arg) epfd = epoll_create(IFCVF_MAX_QUEUES * 2); if (epfd < 0) { DRV_LOG(ERR, "failed to create epoll instance."); - return NULL; + return 1; } internal->epfd = epfd; @@ -527,7 +527,7 @@ notify_relay(void *arg) ev.data.u64 = qid | (uint64_t)vring.kickfd << 32; if (epoll_ctl(epfd, EPOLL_CTL_ADD, vring.kickfd, &ev) < 0) { DRV_LOG(ERR, "epoll add error: %s", strerror(errno)); - return NULL; + return 1; } } @@ -537,7 +537,7 @@ notify_relay(void *arg) if (errno == EINTR) continue; DRV_LOG(ERR, "epoll_wait return fail\n"); - return NULL; + return 1; } for (i = 0; i < nfds; i++) { @@ -561,18 +561,18 @@ notify_relay(void *arg) } } - return NULL; + return 0; } static int setup_notify_relay(struct ifcvf_internal *internal) { - char name[THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; int ret; - snprintf(name, sizeof(name), "dpdk-ifc-noti%d", internal->vid); - ret = rte_ctrl_thread_create(&internal->tid, name, NULL, notify_relay, - (void *)internal); + snprintf(name, sizeof(name), "ifc-noti%d", internal->vid); + ret = rte_thread_create_internal_control(&internal->tid, name, + notify_relay, internal); if (ret != 0) { DRV_LOG(ERR, "failed to create notify relay pthread."); return -1; @@ -584,13 +584,11 @@ setup_notify_relay(struct ifcvf_internal *internal) static int unset_notify_relay(struct ifcvf_internal *internal) { - void *status; - - if (internal->tid) { - pthread_cancel(internal->tid); - pthread_join(internal->tid, &status); + if (internal->tid.opaque_id != 0) { + pthread_cancel((pthread_t)internal->tid.opaque_id); + rte_thread_join(internal->tid, NULL); } - internal->tid = 0; + internal->tid.opaque_id = 0; if (internal->epfd >= 0) close(internal->epfd); @@ -610,7 +608,7 @@ virtio_interrupt_handler(struct ifcvf_internal *internal) DRV_LOG(ERR, "failed to notify the guest about configuration space change."); } -static void * +static uint32_t intr_relay(void *arg) { struct ifcvf_internal *internal = (struct ifcvf_internal *)arg; @@ -623,7 +621,7 @@ intr_relay(void *arg) csc_epfd = epoll_create(1); if (csc_epfd < 0) { DRV_LOG(ERR, "failed to create epoll for config space change."); - return NULL; + return 1; } ev.events = EPOLLIN | EPOLLPRI | EPOLLRDHUP | EPOLLHUP; @@ -672,18 +670,18 @@ intr_relay(void *arg) close(csc_epfd); internal->csc_epfd = -1; - return NULL; + return 0; } static int setup_intr_relay(struct ifcvf_internal *internal) { - char name[THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; int ret; - snprintf(name, sizeof(name), "dpdk-ifc-int%d", internal->vid); - ret = rte_ctrl_thread_create(&internal->intr_tid, name, NULL, - intr_relay, (void *)internal); + snprintf(name, sizeof(name), "ifc-int%d", internal->vid); + ret = rte_thread_create_internal_control(&internal->intr_tid, name, + intr_relay, (void *)internal); if (ret) { DRV_LOG(ERR, "failed to create notify relay pthread."); return -1; @@ -694,13 +692,11 @@ setup_intr_relay(struct ifcvf_internal *internal) static void unset_intr_relay(struct ifcvf_internal *internal) { - void *status; - - if (internal->intr_tid) { - pthread_cancel(internal->intr_tid); - pthread_join(internal->intr_tid, &status); + if (internal->intr_tid.opaque_id != 0) { + pthread_cancel((pthread_t)internal->intr_tid.opaque_id); + rte_thread_join(internal->intr_tid, NULL); } - internal->intr_tid = 0; + internal->intr_tid.opaque_id = 0; if (internal->csc_epfd >= 0) close(internal->csc_epfd); @@ -922,7 +918,7 @@ update_used_ring(struct ifcvf_internal *internal, uint16_t qid) rte_vhost_vring_call(internal->vid, qid); } -static void * +static uint32_t vring_relay(void *arg) { int i, vid, epfd, fd, nfds; @@ -941,7 +937,7 @@ vring_relay(void *arg) epfd = epoll_create(IFCVF_MAX_QUEUES * 2); if (epfd < 0) { DRV_LOG(ERR, "failed to create epoll instance."); - return NULL; + return 1; } internal->epfd = epfd; @@ -952,7 +948,7 @@ vring_relay(void *arg) ev.data.u64 = qid << 1 | (uint64_t)vring.kickfd << 32; if (epoll_ctl(epfd, EPOLL_CTL_ADD, vring.kickfd, &ev) < 0) { DRV_LOG(ERR, "epoll add error: %s", strerror(errno)); - return NULL; + return 1; } } @@ -966,7 +962,7 @@ vring_relay(void *arg) if (epoll_ctl(epfd, EPOLL_CTL_ADD, internal->intr_fd[qid], &ev) < 0) { DRV_LOG(ERR, "epoll add error: %s", strerror(errno)); - return NULL; + return 1; } update_used_ring(internal, qid); } @@ -982,7 +978,7 @@ vring_relay(void *arg) if (errno == EINTR) continue; DRV_LOG(ERR, "epoll_wait return fail."); - return NULL; + return 1; } for (i = 0; i < nfds; i++) { @@ -1010,18 +1006,18 @@ vring_relay(void *arg) } } - return NULL; + return 0; } static int setup_vring_relay(struct ifcvf_internal *internal) { - char name[THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; int ret; - snprintf(name, sizeof(name), "dpdk-ifc-ring%d", internal->vid); - ret = rte_ctrl_thread_create(&internal->tid, name, NULL, vring_relay, - (void *)internal); + snprintf(name, sizeof(name), "ifc-ring%d", internal->vid); + ret = rte_thread_create_internal_control(&internal->tid, name, + vring_relay, internal); if (ret != 0) { DRV_LOG(ERR, "failed to create ring relay pthread."); return -1; @@ -1033,13 +1029,11 @@ setup_vring_relay(struct ifcvf_internal *internal) static int unset_vring_relay(struct ifcvf_internal *internal) { - void *status; - - if (internal->tid) { - pthread_cancel(internal->tid); - pthread_join(internal->tid, &status); + if (internal->tid.opaque_id != 0) { + pthread_cancel((pthread_t)internal->tid.opaque_id); + rte_thread_join(internal->tid, NULL); } - internal->tid = 0; + internal->tid.opaque_id = 0; if (internal->epfd >= 0) close(internal->epfd); diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c index f1737f82a8..01a5877d08 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c @@ -844,7 +844,7 @@ mlx5_vdpa_dev_probe(struct mlx5_common_device *cdev, mlx5_vdpa_config_get(mkvlist, priv); if (priv->use_c_thread) { if (conf_thread_mng.initializer_priv == priv) - if (mlx5_vdpa_mult_threads_create(priv->event_core)) + if (mlx5_vdpa_mult_threads_create()) goto error; __atomic_fetch_add(&conf_thread_mng.refcnt, 1, __ATOMIC_RELAXED); diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h index dc4dfba5ed..7b37c98e74 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/mlx5_vdpa.h @@ -19,6 +19,7 @@ #endif #include <rte_spinlock.h> #include <rte_interrupts.h> +#include <rte_thread.h> #include <mlx5_glue.h> #include <mlx5_devx_cmds.h> @@ -99,7 +100,7 @@ struct mlx5_vdpa_task { /* Generic mlx5_vdpa_c_thread information. */ struct mlx5_vdpa_c_thread { - pthread_t tid; + rte_thread_t tid; struct rte_ring *rng; pthread_cond_t c_cond; }; @@ -182,7 +183,7 @@ struct mlx5_vdpa_priv { rte_spinlock_t db_lock; pthread_mutex_t steer_update_lock; uint64_t no_traffic_counter; - pthread_t timer_tid; + rte_thread_t timer_tid; int event_mode; int event_core; /* Event thread cpu affinity core. */ uint32_t event_us; @@ -563,14 +564,11 @@ mlx5_vdpa_is_modify_virtq_supported(struct mlx5_vdpa_priv *priv); /** * Create configuration multi-threads resource * - * @param[in] cpu_core - * CPU core number to set configuration threads affinity to. - * * @return * 0 on success, a negative value otherwise. */ int -mlx5_vdpa_mult_threads_create(int cpu_core); +mlx5_vdpa_mult_threads_create(void); /** * Destroy configuration multi-threads resource diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_cthread.c b/drivers/vdpa/mlx5/mlx5_vdpa_cthread.c index a1d291bf71..1a5fd3eb17 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa_cthread.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa_cthread.c @@ -96,11 +96,10 @@ mlx5_vdpa_c_thread_wait_bulk_tasks_done(uint32_t *remaining_cnt, return false; } -static void * +static uint32_t mlx5_vdpa_c_thread_handle(void *arg) { struct mlx5_vdpa_conf_thread_mng *multhrd = arg; - pthread_t thread_id = pthread_self(); struct mlx5_vdpa_virtq *virtq; struct mlx5_vdpa_priv *priv; struct mlx5_vdpa_task task; @@ -112,10 +111,10 @@ mlx5_vdpa_c_thread_handle(void *arg) for (thrd_idx = 0; thrd_idx < multhrd->max_thrds; thrd_idx++) - if (multhrd->cthrd[thrd_idx].tid == thread_id) + if (rte_thread_equal(multhrd->cthrd[thrd_idx].tid, rte_thread_self())) break; if (thrd_idx >= multhrd->max_thrds) - return NULL; + return 1; rng = multhrd->cthrd[thrd_idx].rng; while (1) { task_num = mlx5_vdpa_c_thrd_ring_dequeue_bulk(rng, @@ -227,16 +226,17 @@ mlx5_vdpa_c_thread_handle(void *arg) __atomic_fetch_sub(task.remaining_cnt, 1, __ATOMIC_RELAXED); } - return NULL; + return 0; } static void mlx5_vdpa_c_thread_destroy(uint32_t thrd_idx, bool need_unlock) { - if (conf_thread_mng.cthrd[thrd_idx].tid) { - pthread_cancel(conf_thread_mng.cthrd[thrd_idx].tid); - pthread_join(conf_thread_mng.cthrd[thrd_idx].tid, NULL); - conf_thread_mng.cthrd[thrd_idx].tid = 0; + pthread_t *tid = (pthread_t *)&conf_thread_mng.cthrd[thrd_idx].tid.opaque_id; + if (*tid != 0) { + pthread_cancel(*tid); + rte_thread_join(conf_thread_mng.cthrd[thrd_idx].tid, NULL); + *tid = 0; if (need_unlock) pthread_mutex_init(&conf_thread_mng.cthrd_lock, NULL); } @@ -247,30 +247,14 @@ mlx5_vdpa_c_thread_destroy(uint32_t thrd_idx, bool need_unlock) } static int -mlx5_vdpa_c_thread_create(int cpu_core) +mlx5_vdpa_c_thread_create(void) { - const struct sched_param sp = { - .sched_priority = sched_get_priority_max(SCHED_RR), - }; - rte_cpuset_t cpuset; - pthread_attr_t attr; uint32_t thrd_idx; uint32_t ring_num; - char name[32]; + char name[RTE_RING_NAMESIZE]; int ret; pthread_mutex_lock(&conf_thread_mng.cthrd_lock); - pthread_attr_init(&attr); - ret = pthread_attr_setschedpolicy(&attr, SCHED_RR); - if (ret) { - DRV_LOG(ERR, "Failed to set thread sched policy = RR."); - goto c_thread_err; - } - ret = pthread_attr_setschedparam(&attr, &sp); - if (ret) { - DRV_LOG(ERR, "Failed to set thread priority."); - goto c_thread_err; - } ring_num = MLX5_VDPA_MAX_TASKS_PER_THRD / conf_thread_mng.max_thrds; if (!ring_num) { DRV_LOG(ERR, "Invalid ring number for thread."); @@ -291,35 +275,15 @@ mlx5_vdpa_c_thread_create(int cpu_core) thrd_idx); goto c_thread_err; } - ret = pthread_create(&conf_thread_mng.cthrd[thrd_idx].tid, - &attr, mlx5_vdpa_c_thread_handle, - (void *)&conf_thread_mng); + snprintf(name, RTE_THREAD_INTERNAL_NAME_SIZE, "vmlx5-c%d", thrd_idx); + ret = rte_thread_create_internal_control(&conf_thread_mng.cthrd[thrd_idx].tid, + name, + mlx5_vdpa_c_thread_handle, &conf_thread_mng); if (ret) { DRV_LOG(ERR, "Failed to create vdpa multi-threads %d.", thrd_idx); goto c_thread_err; } - CPU_ZERO(&cpuset); - if (cpu_core != -1) - CPU_SET(cpu_core, &cpuset); - else - cpuset = rte_lcore_cpuset(rte_get_main_lcore()); - ret = pthread_setaffinity_np( - conf_thread_mng.cthrd[thrd_idx].tid, - sizeof(cpuset), &cpuset); - if (ret) { - DRV_LOG(ERR, "Failed to set thread affinity for " - "vdpa multi-threads %d.", thrd_idx); - goto c_thread_err; - } - snprintf(name, sizeof(name), "dpdk-vmlx5-c%d", thrd_idx); - ret = pthread_setname_np( - conf_thread_mng.cthrd[thrd_idx].tid, name); - if (ret) - DRV_LOG(ERR, "Failed to set vdpa multi-threads name %s.", - name); - else - DRV_LOG(DEBUG, "Thread name: %s.", name); pthread_cond_init(&conf_thread_mng.cthrd[thrd_idx].c_cond, NULL); } @@ -334,10 +298,10 @@ mlx5_vdpa_c_thread_create(int cpu_core) } int -mlx5_vdpa_mult_threads_create(int cpu_core) +mlx5_vdpa_mult_threads_create(void) { pthread_mutex_init(&conf_thread_mng.cthrd_lock, NULL); - if (mlx5_vdpa_c_thread_create(cpu_core)) { + if (mlx5_vdpa_c_thread_create()) { DRV_LOG(ERR, "Cannot create vDPA configuration threads."); mlx5_vdpa_mult_threads_destroy(false); return -1; diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c index c486ded598..fa26471b18 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c @@ -284,7 +284,7 @@ mlx5_vdpa_event_wait(struct mlx5_vdpa_priv *priv __rte_unused) return NULL; } -static void * +static uint32_t mlx5_vdpa_event_handle(void *arg) { struct mlx5_vdpa_priv *priv = arg; @@ -324,7 +324,7 @@ mlx5_vdpa_event_handle(void *arg) } mlx5_vdpa_timer_sleep(priv, max); } - return NULL; + return 0; case MLX5_VDPA_EVENT_MODE_ONLY_INTERRUPT: do { virtq = mlx5_vdpa_event_wait(priv); @@ -336,9 +336,9 @@ mlx5_vdpa_event_handle(void *arg) pthread_mutex_unlock(&virtq->virtq_lock); } } while (1); - return NULL; + return 0; default: - return NULL; + return 0; } } @@ -503,54 +503,31 @@ int mlx5_vdpa_cqe_event_setup(struct mlx5_vdpa_priv *priv) { int ret; - rte_cpuset_t cpuset; - pthread_attr_t *attrp = NULL; - pthread_attr_t attr; - char name[16]; - const struct sched_param sp = { - .sched_priority = sched_get_priority_max(SCHED_RR) - 1, - }; + rte_thread_attr_t attr; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; if (!priv->eventc) /* All virtqs are in poll mode. */ return 0; - ret = pthread_attr_init(&attr); + ret = rte_thread_attr_init(&attr); if (ret != 0) { DRV_LOG(ERR, "Failed to initialize thread attributes"); goto out; } - attrp = &attr; - ret = pthread_attr_setschedpolicy(attrp, SCHED_RR); - if (ret) { - DRV_LOG(ERR, "Failed to set thread sched policy = RR."); - goto out; - } - ret = pthread_attr_setschedparam(attrp, &sp); - if (ret) { - DRV_LOG(ERR, "Failed to set thread priority."); - goto out; - } - ret = pthread_create(&priv->timer_tid, attrp, mlx5_vdpa_event_handle, - (void *)priv); - if (ret) { - DRV_LOG(ERR, "Failed to create timer thread."); - goto out; - } - CPU_ZERO(&cpuset); + attr.priority = RTE_THREAD_PRIORITY_REALTIME_CRITICAL; if (priv->event_core != -1) - CPU_SET(priv->event_core, &cpuset); + CPU_SET(priv->event_core, &attr.cpuset); else - cpuset = rte_lcore_cpuset(rte_get_main_lcore()); - ret = pthread_setaffinity_np(priv->timer_tid, sizeof(cpuset), &cpuset); - if (ret) { - DRV_LOG(ERR, "Failed to set thread affinity."); + attr.cpuset = rte_lcore_cpuset(rte_get_main_lcore()); + ret = rte_thread_create(&priv->timer_tid, + &attr, mlx5_vdpa_event_handle, priv); + if (ret != 0) { + DRV_LOG(ERR, "Failed to create timer thread."); goto out; } - snprintf(name, sizeof(name), "dpdk-vmlx5-%d", priv->vid); - rte_thread_set_name((rte_thread_t){(uintptr_t)priv->timer_tid}, name); + snprintf(name, sizeof(name), "vmlx5-%d", priv->vid); + rte_thread_set_prefixed_name(priv->timer_tid, name); out: - if (attrp != NULL) - pthread_attr_destroy(attrp); if (ret != 0) return -1; return 0; @@ -560,19 +537,18 @@ void mlx5_vdpa_cqe_event_unset(struct mlx5_vdpa_priv *priv) { struct mlx5_vdpa_virtq *virtq; - void *status; int i; - if (priv->timer_tid) { - pthread_cancel(priv->timer_tid); - pthread_join(priv->timer_tid, &status); + if (priv->timer_tid.opaque_id != 0) { + pthread_cancel((pthread_t)priv->timer_tid.opaque_id); + rte_thread_join(priv->timer_tid, NULL); /* The mutex may stay locked after event thread cancel, initiate it. */ for (i = 0; i < priv->nr_virtqs; i++) { virtq = &priv->virtqs[i]; pthread_mutex_init(&virtq->virtq_lock, NULL); } } - priv->timer_tid = 0; + priv->timer_tid.opaque_id = 0; } void diff --git a/drivers/vdpa/sfc/sfc_vdpa_ops.c b/drivers/vdpa/sfc/sfc_vdpa_ops.c index f63af7d478..00f9a4b04c 100644 --- a/drivers/vdpa/sfc/sfc_vdpa_ops.c +++ b/drivers/vdpa/sfc/sfc_vdpa_ops.c @@ -567,7 +567,7 @@ sfc_vdpa_get_protocol_features(struct rte_vdpa_device *vdpa_dev, return 0; } -static void * +static uint32_t sfc_vdpa_notify_ctrl(void *arg) { struct sfc_vdpa_ops_data *ops_data; @@ -575,7 +575,7 @@ sfc_vdpa_notify_ctrl(void *arg) ops_data = arg; if (ops_data == NULL) - return NULL; + return 0; sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle)); @@ -588,7 +588,7 @@ sfc_vdpa_notify_ctrl(void *arg) sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle)); - return NULL; + return 0; } static int @@ -603,8 +603,8 @@ sfc_vdpa_setup_notify_ctrl(struct sfc_vdpa_ops_data *ops_data) * dead lock scenario when multiple VFs are used in single vdpa * application and multiple VFs are passed to a single VM. */ - ret = pthread_create(&ops_data->notify_tid, NULL, - sfc_vdpa_notify_ctrl, ops_data); + ret = rte_thread_create_internal_control(&ops_data->notify_tid, + "sfc-vdpa", sfc_vdpa_notify_ctrl, ops_data); if (ret != 0) { sfc_vdpa_err(ops_data->dev_handle, "failed to create notify_ctrl thread: %s", @@ -690,15 +690,14 @@ sfc_vdpa_dev_close(int vid) sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle)); if (ops_data->is_notify_thread_started == true) { - void *status; - ret = pthread_cancel(ops_data->notify_tid); + ret = pthread_cancel((pthread_t)ops_data->notify_tid.opaque_id); if (ret != 0) { sfc_vdpa_err(ops_data->dev_handle, "failed to cancel notify_ctrl thread: %s", rte_strerror(ret)); } - ret = pthread_join(ops_data->notify_tid, &status); + ret = rte_thread_join(ops_data->notify_tid, NULL); if (ret != 0) { sfc_vdpa_err(ops_data->dev_handle, "failed to join terminated notify_ctrl thread: %s", diff --git a/drivers/vdpa/sfc/sfc_vdpa_ops.h b/drivers/vdpa/sfc/sfc_vdpa_ops.h index 5c8e352de3..10ea239434 100644 --- a/drivers/vdpa/sfc/sfc_vdpa_ops.h +++ b/drivers/vdpa/sfc/sfc_vdpa_ops.h @@ -6,6 +6,7 @@ #define _SFC_VDPA_OPS_H #include <rte_vdpa.h> +#include <rte_thread.h> #define SFC_VDPA_MAX_QUEUE_PAIRS 8 @@ -48,7 +49,7 @@ struct sfc_vdpa_ops_data { struct rte_vdpa_device *vdpa_dev; enum sfc_vdpa_context vdpa_context; enum sfc_vdpa_state state; - pthread_t notify_tid; + rte_thread_t notify_tid; bool is_notify_thread_started; uint64_t dev_features; -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 07/11] drivers: convert to internal control threads 2023-09-06 16:12 ` [PATCH 07/11] drivers: " Thomas Monjalon @ 2023-09-11 13:35 ` Andrew Rybchenko 0 siblings, 0 replies; 60+ messages in thread From: Andrew Rybchenko @ 2023-09-11 13:35 UTC (permalink / raw) To: Thomas Monjalon, dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao, Chengwen Feng, Kevin Laatz, Bruce Richardson, Abdullah Sevincer, Shepard Siegel, Ed Czeck, John Miller, Jingjing Wu, Beilei Xing, Qiming Yang, Qi Zhang, Rosen Xu, Wenjun Wu, Matan Azrad, Viacheslav Ovsiienko, Ori Kam, Suanming Mou, Jiawen Wu, Jian Wang, Tianfei Zhang, Xiao Wang, Vijay Kumar Srivastava On 9/6/23 19:12, Thomas Monjalon wrote: > Calls to rte_ctrl_thread_create() are replaced with > rte_thread_create_internal_control(). > Other pthread-related functions are replaced with the rte_thread API. > Only pthread_cancel() has no replacement. > > The mlx5 vDPA control threads were real-time threads > with an affinity on the core specified by the devarg "event_core". > As there is no heavy performance requirement, > these threads are converted into real control threads. > > Some threads in dlb2 and mlx5 are not control threads > because they are designed to run on some specific cores. > It would be interesting to rework them in future. > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net> For net/sfc Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru> ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 08/11] examples: convert to normal control threads 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon ` (6 preceding siblings ...) 2023-09-06 16:12 ` [PATCH 07/11] drivers: " Thomas Monjalon @ 2023-09-06 16:12 ` Thomas Monjalon 2023-09-08 4:10 ` Tyler Retzlaff 2023-09-06 16:12 ` [PATCH 09/11] test: convert threads creation Thomas Monjalon ` (5 subsequent siblings) 13 siblings, 1 reply; 60+ messages in thread From: Thomas Monjalon @ 2023-09-06 16:12 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Maxime Coquelin, Chenbo Xia Calls to rte_ctrl_thread_create() are replaced with rte_thread_create_control(). In vhost_blk, the control thread is not forced to be scheduled on core 0 anymore. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> --- examples/vhost/main.c | 9 +++++---- examples/vhost_blk/vhost_blk.c | 21 ++++++--------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 9ff2c1f31b..ce5c1efddf 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -28,6 +28,7 @@ #include <rte_pause.h> #include <rte_dmadev.h> #include <rte_vhost_async.h> +#include <rte_thread.h> #include "main.h" @@ -1807,7 +1808,7 @@ static const struct rte_vhost_device_ops virtio_net_device_ops = * This is a thread will wake up after a period to print stats if the user has * enabled them. */ -static void * +static uint32_t print_stats(__rte_unused void *arg) { struct vhost_dev *vdev; @@ -1852,7 +1853,7 @@ print_stats(__rte_unused void *arg) fflush(stdout); } - return NULL; + return 0; } static void @@ -1907,7 +1908,7 @@ main(int argc, char *argv[]) unsigned nb_ports, valid_num_ports; int ret, i; uint16_t portid; - static pthread_t tid; + rte_thread_t tid; uint64_t flags = RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS; signal(SIGINT, sigint_handler); @@ -1986,7 +1987,7 @@ main(int argc, char *argv[]) /* Enable stats if the user option is set. */ if (enable_stats) { - ret = rte_ctrl_thread_create(&tid, "dpdk-vhost-stat", NULL, + ret = rte_thread_create_control(&tid, "dpdk-vhost-stat", print_stats, NULL); if (ret < 0) rte_exit(EXIT_FAILURE, diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c index 45699eb0b3..376f7b89a7 100644 --- a/examples/vhost_blk/vhost_blk.c +++ b/examples/vhost_blk/vhost_blk.c @@ -5,8 +5,6 @@ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif -#include <pthread.h> -#include <sched.h> #include <stdint.h> #include <stdlib.h> @@ -529,12 +527,10 @@ process_vq(struct vhost_blk_queue *vq) } } -static void * +static uint32_t ctrlr_worker(void *arg) { struct vhost_blk_ctrlr *ctrlr = (struct vhost_blk_ctrlr *)arg; - cpu_set_t cpuset; - pthread_t thread; int i; fprintf(stdout, "Ctrlr Worker Thread start\n"); @@ -546,11 +542,6 @@ ctrlr_worker(void *arg) exit(0); } - thread = pthread_self(); - CPU_ZERO(&cpuset); - CPU_SET(0, &cpuset); - pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset); - for (i = 0; i < NUM_OF_BLK_QUEUES; i++) submit_inflight_vq(&ctrlr->queues[i]); @@ -560,7 +551,7 @@ ctrlr_worker(void *arg) fprintf(stdout, "Ctrlr Worker Thread Exiting\n"); sem_post(&exit_sem); - return NULL; + return 0; } static int @@ -605,7 +596,7 @@ new_device(int vid) struct vhost_blk_queue *vq; char path[PATH_MAX]; uint64_t features, protocol_features; - pthread_t tid; + rte_thread_t tid; int i, ret; bool packed_ring, inflight_shmfd; @@ -686,15 +677,15 @@ new_device(int vid) /* start polling vring */ worker_thread_status = WORKER_STATE_START; fprintf(stdout, "New Device %s, Device ID %d\n", path, vid); - if (rte_ctrl_thread_create(&tid, "dpdk-vhost-blk", NULL, - &ctrlr_worker, ctrlr) != 0) { + if (rte_thread_create_control(&tid, "dpdk-vhost-blk", + &ctrlr_worker, ctrlr) != 0) { fprintf(stderr, "Worker Thread Started Failed\n"); return -1; } /* device has been started */ ctrlr->started = 1; - pthread_detach(tid); + rte_thread_detach(tid); return 0; } -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 08/11] examples: convert to normal control threads 2023-09-06 16:12 ` [PATCH 08/11] examples: convert to normal " Thomas Monjalon @ 2023-09-08 4:10 ` Tyler Retzlaff 0 siblings, 0 replies; 60+ messages in thread From: Tyler Retzlaff @ 2023-09-08 4:10 UTC (permalink / raw) To: Thomas Monjalon Cc: dev, David Marchand, Ferruh Yigit, Maxime Coquelin, Chenbo Xia On Wed, Sep 06, 2023 at 06:12:25PM +0200, Thomas Monjalon wrote: > Calls to rte_ctrl_thread_create() are replaced with > rte_thread_create_control(). > > In vhost_blk, the control thread is not forced > to be scheduled on core 0 anymore. > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net> > --- Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 09/11] test: convert threads creation 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon ` (7 preceding siblings ...) 2023-09-06 16:12 ` [PATCH 08/11] examples: convert to normal " Thomas Monjalon @ 2023-09-06 16:12 ` Thomas Monjalon 2023-09-08 4:12 ` Tyler Retzlaff 2023-09-06 16:12 ` [PATCH 10/11] eal: remove deprecated thread functions Thomas Monjalon ` (4 subsequent siblings) 13 siblings, 1 reply; 60+ messages in thread From: Thomas Monjalon @ 2023-09-06 16:12 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Reshma Pattan, Stephen Hemminger Calls to pthread for thread creation are replaced with the rte_thread API. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> --- app/test/process.h | 10 +++++----- app/test/test_lcores.c | 9 ++++----- app/test/test_pdump.c | 6 +++--- app/test/test_pdump.h | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/test/process.h b/app/test/process.h index 1f073b9c5c..af7bc3e0de 100644 --- a/app/test/process.h +++ b/app/test/process.h @@ -28,8 +28,8 @@ #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING -#include <pthread.h> -extern void *send_pkts(void *empty); +#include <rte_thread.h> +extern uint32_t send_pkts(void *empty); extern uint16_t flag_for_send_pkts; #endif #endif @@ -49,7 +49,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) char path[32]; #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING - pthread_t thread; + rte_thread_t thread; int rc; #endif #endif @@ -136,7 +136,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING if ((strcmp(env_value, "run_pdump_server_tests") == 0)) { - rc = pthread_create(&thread, NULL, &send_pkts, NULL); + rc = rte_thread_create(&thread, NULL, send_pkts, NULL); if (rc != 0) { rte_panic("Cannot start send pkts thread: %s\n", strerror(rc)); @@ -151,7 +151,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) #ifdef RTE_NET_RING if ((strcmp(env_value, "run_pdump_server_tests") == 0)) { flag_for_send_pkts = 0; - pthread_join(thread, NULL); + rte_thread_join(thread, NULL); } #endif #endif diff --git a/app/test/test_lcores.c b/app/test/test_lcores.c index 0c96faa4cb..22225a9fd3 100644 --- a/app/test/test_lcores.c +++ b/app/test/test_lcores.c @@ -2,7 +2,6 @@ * Copyright (c) 2020 Red Hat, Inc. */ -#include <pthread.h> #include <string.h> #include <rte_common.h> @@ -341,7 +340,7 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count) return -1; } -static void *ctrl_thread_loop(void *arg) +static uint32_t ctrl_thread_loop(void *arg) { struct thread_context *t = arg; @@ -350,7 +349,7 @@ static void *ctrl_thread_loop(void *arg) /* Set the thread state to DONE */ t->state = Thread_DONE; - return NULL; + return 0; } static int @@ -362,8 +361,8 @@ test_ctrl_thread(void) /* Create one control thread */ t = &ctrl_thread_context; t->state = Thread_INIT; - if (rte_ctrl_thread_create((pthread_t *)&t->id, "dpdk-test-ctrlt", - NULL, ctrl_thread_loop, t) != 0) + if (rte_thread_create_control(&t->id, "dpdk-test-ctrlt", + ctrl_thread_loop, t) != 0) return -1; /* Wait till the control thread exits. diff --git a/app/test/test_pdump.c b/app/test/test_pdump.c index ea03056b47..adf49f0b54 100644 --- a/app/test/test_pdump.c +++ b/app/test/test_pdump.c @@ -136,8 +136,8 @@ test_pdump_uninit(void) return ret; } -void * -send_pkts(void *empty) +uint32_t +send_pkts(void *empty __rte_unused) { int ret = 0; struct rte_mbuf *pbuf[NUM_PACKETS] = { }; @@ -161,7 +161,7 @@ send_pkts(void *empty) rte_eth_dev_stop(portid); test_put_mbuf_to_pool(mp, pbuf); - return empty; + return 0; } /* diff --git a/app/test/test_pdump.h b/app/test/test_pdump.h index abef9a85ec..8746d61269 100644 --- a/app/test/test_pdump.h +++ b/app/test/test_pdump.h @@ -9,7 +9,7 @@ #define NUM_ITR 3 /* sample test to send packets to the pdump client recursively */ -void *send_pkts(void *port); +uint32_t send_pkts(void *empty); /* Sample test to create setup for the pdump server tests */ int test_pdump_init(void); -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 09/11] test: convert threads creation 2023-09-06 16:12 ` [PATCH 09/11] test: convert threads creation Thomas Monjalon @ 2023-09-08 4:12 ` Tyler Retzlaff 0 siblings, 0 replies; 60+ messages in thread From: Tyler Retzlaff @ 2023-09-08 4:12 UTC (permalink / raw) To: Thomas Monjalon Cc: dev, David Marchand, Ferruh Yigit, Reshma Pattan, Stephen Hemminger On Wed, Sep 06, 2023 at 06:12:26PM +0200, Thomas Monjalon wrote: > Calls to pthread for thread creation are replaced with the rte_thread API. > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net> > --- Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 10/11] eal: remove deprecated thread functions 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon ` (8 preceding siblings ...) 2023-09-06 16:12 ` [PATCH 09/11] test: convert threads creation Thomas Monjalon @ 2023-09-06 16:12 ` Thomas Monjalon 2023-09-08 4:22 ` Tyler Retzlaff 2023-09-06 16:12 ` [PATCH 11/11] lib: remove pthread.h from includes Thomas Monjalon ` (3 subsequent siblings) 13 siblings, 1 reply; 60+ messages in thread From: Thomas Monjalon @ 2023-09-06 16:12 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Anatoly Burakov, Bruce Richardson, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam The deprecated functions rte_thread_setname() and rte_ctrl_thread_create() are replaced with the new rte_thread API: rte_thread_setname() can be replaced with rte_thread_set_name() or rte_thread_set_prefixed_name() rte_ctrl_thread_create() can be replaced with rte_thread_create_control() or rte_thread_create_internal_control() Signed-off-by: Thomas Monjalon <thomas@monjalon.net> --- .../prog_guide/env_abstraction_layer.rst | 2 +- doc/guides/rel_notes/deprecation.rst | 5 -- doc/guides/rel_notes/release_23_11.rst | 4 +- lib/eal/common/eal_common_thread.c | 66 +------------------ lib/eal/freebsd/eal_thread.c | 7 -- lib/eal/include/rte_lcore.h | 42 ------------ lib/eal/linux/eal_thread.c | 16 ----- lib/eal/version.map | 2 - lib/eal/windows/eal_thread.c | 8 --- 9 files changed, 6 insertions(+), 146 deletions(-) diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst index 89014789de..6debf54efb 100644 --- a/doc/guides/prog_guide/env_abstraction_layer.rst +++ b/doc/guides/prog_guide/env_abstraction_layer.rst @@ -756,7 +756,7 @@ Control Thread API ~~~~~~~~~~~~~~~~~~ It is possible to create Control Threads using the public API -``rte_ctrl_thread_create()``. +``rte_thread_create_control()``. Those threads can be used for management/infrastructure tasks and are used internally by DPDK for multi process support and interrupt handling. diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index 3e48908b51..8c8873006d 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -29,11 +29,6 @@ Deprecation Notices are renamed to ``rte_tel_data_add_array_uint`` and ``rte_tel_data_add_dict_uint`` respectively. As such, the old function names are deprecated and will be removed in a future release. -* eal: The functions ``rte_thread_setname`` and ``rte_ctrl_thread_create`` - are planned to be deprecated starting with the 23.07 release, subject to - the replacement API rte_thread_set_name and rte_thread_create_control being - marked as stable, and planned to be removed by the 23.11 release. - * eal: ``RTE_CPUFLAG_NUMFLAGS`` will be removed in DPDK 23.11 release. This is to allow new CPU features to be added without ABI breakage. diff --git a/doc/guides/rel_notes/release_23_11.rst b/doc/guides/rel_notes/release_23_11.rst index d7562fd646..9746809a66 100644 --- a/doc/guides/rel_notes/release_23_11.rst +++ b/doc/guides/rel_notes/release_23_11.rst @@ -115,7 +115,9 @@ API Changes * eal: The thread API has changed. The function ``rte_thread_create_control()`` does not take attributes anymore. - The whole thread API was promoted to stable level. + The whole thread API was promoted to stable level, + except ``rte_thread_setname()`` and ``rte_ctrl_thread_create()`` which are + replaced with ``rte_thread_set_name()`` and ``rte_thread_create_control()``. ABI Changes diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 31c37e3102..78f643af73 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -248,7 +248,7 @@ struct rte_thread_ctrl_params { enum __rte_ctrl_thread_status ctrl_thread_status; }; -static int ctrl_thread_init(void *arg) +static int control_thread_init(void *arg) { struct internal_config *internal_conf = eal_get_internal_configuration(); @@ -273,80 +273,18 @@ static int ctrl_thread_init(void *arg) return 0; } -static void *ctrl_thread_start(void *arg) -{ - struct rte_thread_ctrl_params *params = arg; - void *start_arg = params->arg; - void *(*start_routine)(void *) = params->u.ctrl_start_routine; - - if (ctrl_thread_init(arg) != 0) - return NULL; - - return start_routine(start_arg); -} - static uint32_t control_thread_start(void *arg) { struct rte_thread_ctrl_params *params = arg; void *start_arg = params->arg; rte_thread_func start_routine = params->u.control_start_routine; - if (ctrl_thread_init(arg) != 0) + if (control_thread_init(arg) != 0) return 0; return start_routine(start_arg); } -int -rte_ctrl_thread_create(pthread_t *thread, const char *name, - const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg) -{ - struct rte_thread_ctrl_params *params; - enum __rte_ctrl_thread_status ctrl_thread_status; - int ret; - - params = malloc(sizeof(*params)); - if (!params) - return -ENOMEM; - - params->u.ctrl_start_routine = start_routine; - params->arg = arg; - params->ret = 0; - params->ctrl_thread_status = CTRL_THREAD_LAUNCHING; - - ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params); - if (ret != 0) { - free(params); - return -ret; - } - - if (name != NULL) - rte_thread_set_name((rte_thread_t){(uintptr_t)*thread}, name); - - /* Wait for the control thread to initialize successfully */ - while ((ctrl_thread_status = - __atomic_load_n(¶ms->ctrl_thread_status, - __ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) { - /* Yield the CPU. Using sched_yield call requires maintaining - * another implementation for Windows as sched_yield is not - * supported on Windows. - */ - rte_delay_us_sleep(1); - } - - /* Check if the control thread encountered an error */ - if (ctrl_thread_status == CTRL_THREAD_ERROR) { - /* ctrl thread is exiting */ - rte_thread_join((rte_thread_t){(uintptr_t)*thread}, NULL); - } - - ret = params->ret; - free(params); - - return -ret; -} - int rte_thread_create_control(rte_thread_t *thread, const char *name, rte_thread_func start_routine, void *arg) diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c index ba9b25c2c0..6f97a3c2c1 100644 --- a/lib/eal/freebsd/eal_thread.c +++ b/lib/eal/freebsd/eal_thread.c @@ -42,10 +42,3 @@ void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated); } - -int rte_thread_setname(pthread_t id, const char *name) -{ - /* this BSD function returns no error */ - pthread_set_name_np(id, name); - return 0; -} diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h index 6ce810b876..7deae47af3 100644 --- a/lib/eal/include/rte_lcore.h +++ b/lib/eal/include/rte_lcore.h @@ -385,20 +385,6 @@ void rte_lcore_register_usage_cb(rte_lcore_usage_cb cb); void rte_lcore_dump(FILE *f); -/** - * Set thread names. - * - * @note It fails with glibc < 2.12. - * - * @param id - * Thread id. - * @param name - * Thread name to set. - * @return - * On success, return 0; otherwise return a negative value. - */ -int rte_thread_setname(pthread_t id, const char *name); - /** * Register current non-EAL thread as a lcore. * @@ -421,34 +407,6 @@ rte_thread_register(void); void rte_thread_unregister(void); -/** - * Create a control thread. - * - * Creates a control thread with the given name and attributes. The - * affinity of the new thread is based on the CPU affinity retrieved - * at the time rte_eal_init() was called, the dataplane and service - * lcores are then excluded. If setting the name of the thread fails, - * the error is ignored and a debug message is logged. - * - * @param thread - * Filled with the thread id of the new created thread. - * @param name - * The name of the control thread (max 16 characters including '\0'). - * @param attr - * Attributes for the new thread. - * @param start_routine - * Function to be executed by the new thread. - * @param arg - * Argument passed to start_routine. - * @return - * On success, returns 0; on error, it returns a negative value - * corresponding to the error number. - */ -int -rte_ctrl_thread_create(pthread_t *thread, const char *name, - const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg); - #ifdef __cplusplus } #endif diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c index b9a126f3a8..880070c627 100644 --- a/lib/eal/linux/eal_thread.c +++ b/lib/eal/linux/eal_thread.c @@ -39,19 +39,3 @@ void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) if (ret != 0) RTE_LOG(DEBUG, EAL, "Failed to set thread name\n"); } - -int rte_thread_setname(pthread_t id, const char *name) -{ - int ret = ENOSYS; -#if defined(__GLIBC__) && defined(__GLIBC_PREREQ) -#if __GLIBC_PREREQ(2, 12) - char truncated[16]; - - strlcpy(truncated, name, sizeof(truncated)); - ret = pthread_setname_np(id, truncated); -#endif -#endif - RTE_SET_USED(id); - RTE_SET_USED(name); - return -ret; -} diff --git a/lib/eal/version.map b/lib/eal/version.map index 6d32c19286..915057b325 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -20,7 +20,6 @@ DPDK_24 { rte_cpu_get_flag_enabled; rte_cpu_get_flag_name; rte_cpu_is_supported; # WINDOWS_NO_EXPORT - rte_ctrl_thread_create; rte_cycles_vmware_tsc_map; # WINDOWS_NO_EXPORT rte_delay_us; rte_delay_us_block; @@ -278,7 +277,6 @@ DPDK_24 { rte_thread_set_affinity_by_id; rte_thread_set_name; rte_thread_set_priority; - rte_thread_setname; rte_thread_unregister; rte_thread_value_get; rte_thread_value_set; diff --git a/lib/eal/windows/eal_thread.c b/lib/eal/windows/eal_thread.c index 464d510838..9e3df200b9 100644 --- a/lib/eal/windows/eal_thread.c +++ b/lib/eal/windows/eal_thread.c @@ -76,11 +76,3 @@ rte_sys_gettid(void) { return GetCurrentThreadId(); } - -int -rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name) -{ - /* TODO */ - /* This is a stub, not the expected result */ - return 0; -} -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 10/11] eal: remove deprecated thread functions 2023-09-06 16:12 ` [PATCH 10/11] eal: remove deprecated thread functions Thomas Monjalon @ 2023-09-08 4:22 ` Tyler Retzlaff 2023-09-11 16:13 ` Thomas Monjalon 0 siblings, 1 reply; 60+ messages in thread From: Tyler Retzlaff @ 2023-09-08 4:22 UTC (permalink / raw) To: Thomas Monjalon Cc: dev, David Marchand, Ferruh Yigit, Anatoly Burakov, Bruce Richardson, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam On Wed, Sep 06, 2023 at 06:12:27PM +0200, Thomas Monjalon wrote: > The deprecated functions rte_thread_setname() and rte_ctrl_thread_create() > are replaced with the new rte_thread API: > > rte_thread_setname() > can be replaced with > rte_thread_set_name() > or rte_thread_set_prefixed_name() > > rte_ctrl_thread_create() > can be replaced with > rte_thread_create_control() > or rte_thread_create_internal_control() > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net> > --- Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> with suggestions. ... > ABI Changes > diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c > index 31c37e3102..78f643af73 100644 > --- a/lib/eal/common/eal_common_thread.c > +++ b/lib/eal/common/eal_common_thread.c > @@ -248,7 +248,7 @@ struct rte_thread_ctrl_params { > enum __rte_ctrl_thread_status ctrl_thread_status; > }; the code above here struct rte_thread_ctrl_params i think can now get renamed to rte_thread_control_params and i think we can get rid of the union. if i look through the code history i only added it to help maintain compatibility while we had both ctrl and control thread APIs. > > -static int ctrl_thread_init(void *arg) > +static int control_thread_init(void *arg) > { > struct internal_config *internal_conf = > eal_get_internal_configuration(); > @@ -273,80 +273,18 @@ static int ctrl_thread_init(void *arg) > return 0; > } ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 10/11] eal: remove deprecated thread functions 2023-09-08 4:22 ` Tyler Retzlaff @ 2023-09-11 16:13 ` Thomas Monjalon 2023-09-12 0:49 ` Tyler Retzlaff 0 siblings, 1 reply; 60+ messages in thread From: Thomas Monjalon @ 2023-09-11 16:13 UTC (permalink / raw) To: Tyler Retzlaff Cc: dev, David Marchand, Ferruh Yigit, Anatoly Burakov, Bruce Richardson, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam 08/09/2023 06:22, Tyler Retzlaff: > On Wed, Sep 06, 2023 at 06:12:27PM +0200, Thomas Monjalon wrote: > > --- a/lib/eal/common/eal_common_thread.c > > +++ b/lib/eal/common/eal_common_thread.c > > @@ -248,7 +248,7 @@ struct rte_thread_ctrl_params { > > enum __rte_ctrl_thread_status ctrl_thread_status; > > }; > > the code above here > > struct rte_thread_ctrl_params i think can now get renamed to > rte_thread_control_params and i think we can get rid of the union. > if i look through the code history i only added it to help maintain > compatibility while we had both ctrl and control thread APIs. Yes I can do this cleanup. Instead of rte_thread_control_params, I would call it control_thread_params as it is private. ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 10/11] eal: remove deprecated thread functions 2023-09-11 16:13 ` Thomas Monjalon @ 2023-09-12 0:49 ` Tyler Retzlaff 0 siblings, 0 replies; 60+ messages in thread From: Tyler Retzlaff @ 2023-09-12 0:49 UTC (permalink / raw) To: Thomas Monjalon Cc: dev, David Marchand, Ferruh Yigit, Anatoly Burakov, Bruce Richardson, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam On Mon, Sep 11, 2023 at 06:13:48PM +0200, Thomas Monjalon wrote: > 08/09/2023 06:22, Tyler Retzlaff: > > On Wed, Sep 06, 2023 at 06:12:27PM +0200, Thomas Monjalon wrote: > > > --- a/lib/eal/common/eal_common_thread.c > > > +++ b/lib/eal/common/eal_common_thread.c > > > @@ -248,7 +248,7 @@ struct rte_thread_ctrl_params { > > > enum __rte_ctrl_thread_status ctrl_thread_status; > > > }; > > > > the code above here > > > > struct rte_thread_ctrl_params i think can now get renamed to > > rte_thread_control_params and i think we can get rid of the union. > > if i look through the code history i only added it to help maintain > > compatibility while we had both ctrl and control thread APIs. > > Yes I can do this cleanup. > Instead of rte_thread_control_params, > I would call it control_thread_params as it is private. sounds good to me, i didn't intend to express a preference about the name just that it could be cleaned up. > ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH 11/11] lib: remove pthread.h from includes 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon ` (9 preceding siblings ...) 2023-09-06 16:12 ` [PATCH 10/11] eal: remove deprecated thread functions Thomas Monjalon @ 2023-09-06 16:12 ` Thomas Monjalon 2023-09-08 4:25 ` Tyler Retzlaff 2023-09-10 2:55 ` Xu, Rosen 2023-09-07 8:30 ` [PATCH 00/11] rework thread management Morten Brørup ` (2 subsequent siblings) 13 siblings, 2 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-06 16:12 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Chas Williams, Min Hu (Connor), Matan Azrad, Viacheslav Ovsiienko, Ori Kam, Suanming Mou, Ajit Khaparde, Somnath Kotur, Devendra Singh Rawat, Alok Prasad, Rosen Xu, Tianfei Zhang, Vijay Kumar Srivastava, Jerin Jacob, Sunil Kumar Kori, Anatoly Burakov, Bruce Richardson, Andrew Rybchenko, Naga Harish K S V, Maxime Coquelin, Chenbo Xia The header files should have the minimum embedded includes. The file pthread.h can logically be removed from rte_per_lcore.h and rte_ethdev_core.h files. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> --- app/test/test_link_bonding.c | 2 ++ drivers/common/mlx5/mlx5_common.c | 1 + drivers/common/mlx5/windows/mlx5_win_ext.h | 2 ++ drivers/net/bnxt/bnxt.h | 1 + drivers/net/qede/base/bcm_osal.h | 1 + drivers/raw/ifpga/base/opae_osdep.h | 1 + drivers/vdpa/sfc/sfc_vdpa.c | 1 + lib/eal/common/eal_common_options.c | 1 + lib/eal/common/eal_common_trace.c | 1 + lib/eal/common/malloc_mp.c | 1 + lib/eal/freebsd/eal_alarm.c | 1 + lib/eal/include/rte_per_lcore.h | 2 -- lib/eal/linux/eal_alarm.c | 1 + lib/ethdev/ethdev_driver.c | 1 + lib/ethdev/ethdev_driver.h | 2 ++ lib/ethdev/rte_ethdev_core.h | 2 -- lib/ethdev/rte_flow.c | 1 + lib/eventdev/rte_event_eth_rx_adapter.c | 1 + lib/vhost/vhost.c | 1 + 19 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/test/test_link_bonding.c b/app/test/test_link_bonding.c index 2f46e4c6ee..d6b6ebc2f2 100644 --- a/app/test/test_link_bonding.c +++ b/app/test/test_link_bonding.c @@ -10,8 +10,10 @@ #include <stdint.h> #include <inttypes.h> #include <errno.h> +#include <pthread.h> #include <sys/queue.h> #include <sys/time.h> + #include <rte_cycles.h> #include <rte_byteorder.h> #include <rte_common.h> diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c index 0ad14a48c7..ca8543e36e 100644 --- a/drivers/common/mlx5/mlx5_common.c +++ b/drivers/common/mlx5/mlx5_common.c @@ -5,6 +5,7 @@ #include <unistd.h> #include <string.h> #include <stdio.h> +#include <pthread.h> #include <rte_errno.h> #include <rte_mempool.h> diff --git a/drivers/common/mlx5/windows/mlx5_win_ext.h b/drivers/common/mlx5/windows/mlx5_win_ext.h index 6f69329a6f..a71c69bff5 100644 --- a/drivers/common/mlx5/windows/mlx5_win_ext.h +++ b/drivers/common/mlx5/windows/mlx5_win_ext.h @@ -5,6 +5,8 @@ #ifndef __MLX5_WIN_ETX_H__ #define __MLX5_WIN_ETX_H__ +#include <pthread.h> + #include "mlx5_prm.h" #include "mlx5devx.h" diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h index ed21ba7f29..0e01b1d4ba 100644 --- a/drivers/net/bnxt/bnxt.h +++ b/drivers/net/bnxt/bnxt.h @@ -8,6 +8,7 @@ #include <inttypes.h> #include <stdbool.h> +#include <pthread.h> #include <sys/queue.h> #include <rte_pci.h> diff --git a/drivers/net/qede/base/bcm_osal.h b/drivers/net/qede/base/bcm_osal.h index 97e261d306..11019b5623 100644 --- a/drivers/net/qede/base/bcm_osal.h +++ b/drivers/net/qede/base/bcm_osal.h @@ -8,6 +8,7 @@ #define __BCM_OSAL_H #include <stdbool.h> +#include <pthread.h> #include <time.h> #include <rte_bitops.h> #include <rte_byteorder.h> diff --git a/drivers/raw/ifpga/base/opae_osdep.h b/drivers/raw/ifpga/base/opae_osdep.h index 033b7e098c..e91205f536 100644 --- a/drivers/raw/ifpga/base/opae_osdep.h +++ b/drivers/raw/ifpga/base/opae_osdep.h @@ -7,6 +7,7 @@ #include <string.h> #include <stdbool.h> +#include <pthread.h> #ifdef RTE_LIB_EAL #include "osdep_rte/osdep_generic.h" diff --git a/drivers/vdpa/sfc/sfc_vdpa.c b/drivers/vdpa/sfc/sfc_vdpa.c index bd6ecde450..9db87fcb7d 100644 --- a/drivers/vdpa/sfc/sfc_vdpa.c +++ b/drivers/vdpa/sfc/sfc_vdpa.c @@ -4,6 +4,7 @@ #include <stdbool.h> #include <stdint.h> +#include <pthread.h> #include <sys/queue.h> #include <rte_common.h> diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index d74b581567..a6d21f1cba 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -5,6 +5,7 @@ #include <stdlib.h> #include <string.h> +#include <pthread.h> #ifndef RTE_EXEC_ENV_WINDOWS #include <syslog.h> #endif diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index cb980af06d..b21e61bf39 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include <fnmatch.h> +#include <pthread.h> #include <sys/queue.h> #include <regex.h> diff --git a/lib/eal/common/malloc_mp.c b/lib/eal/common/malloc_mp.c index 7270c2ec90..4d62397aba 100644 --- a/lib/eal/common/malloc_mp.c +++ b/lib/eal/common/malloc_mp.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include <string.h> +#include <pthread.h> #include <sys/time.h> #include <rte_errno.h> diff --git a/lib/eal/freebsd/eal_alarm.c b/lib/eal/freebsd/eal_alarm.c index acdcf53804..e5b0909a45 100644 --- a/lib/eal/freebsd/eal_alarm.c +++ b/lib/eal/freebsd/eal_alarm.c @@ -4,6 +4,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <pthread.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> diff --git a/lib/eal/include/rte_per_lcore.h b/lib/eal/include/rte_per_lcore.h index 2b846f9337..5a1497631a 100644 --- a/lib/eal/include/rte_per_lcore.h +++ b/lib/eal/include/rte_per_lcore.h @@ -22,8 +22,6 @@ extern "C" { #endif -#include <pthread.h> - #ifdef RTE_TOOLCHAIN_MSVC /** * Macro to define a per lcore variable "var" of type "type", don't diff --git a/lib/eal/linux/eal_alarm.c b/lib/eal/linux/eal_alarm.c index 397f25d7d5..766ba2c251 100644 --- a/lib/eal/linux/eal_alarm.c +++ b/lib/eal/linux/eal_alarm.c @@ -5,6 +5,7 @@ #include <stdint.h> #include <stdlib.h> #include <errno.h> +#include <pthread.h> #include <sys/queue.h> #include <sys/time.h> #include <sys/timerfd.h> diff --git a/lib/ethdev/ethdev_driver.c b/lib/ethdev/ethdev_driver.c index 0be1e8ca04..30db839a77 100644 --- a/lib/ethdev/ethdev_driver.c +++ b/lib/ethdev/ethdev_driver.c @@ -3,6 +3,7 @@ */ #include <stdlib.h> +#include <pthread.h> #include <rte_kvargs.h> #include <rte_malloc.h> diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h index 980f837ab6..3fa8b309c1 100644 --- a/lib/ethdev/ethdev_driver.h +++ b/lib/ethdev/ethdev_driver.h @@ -18,6 +18,8 @@ extern "C" { * use them. */ +#include <pthread.h> + #include <dev_driver.h> #include <rte_compat.h> #include <rte_ethdev.h> diff --git a/lib/ethdev/rte_ethdev_core.h b/lib/ethdev/rte_ethdev_core.h index 46e9721e07..8d260584b4 100644 --- a/lib/ethdev/rte_ethdev_core.h +++ b/lib/ethdev/rte_ethdev_core.h @@ -5,8 +5,6 @@ #ifndef _RTE_ETHDEV_CORE_H_ #define _RTE_ETHDEV_CORE_H_ -#include <pthread.h> - /** * @file * diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c index 271d854f78..0c5aabea45 100644 --- a/lib/ethdev/rte_flow.c +++ b/lib/ethdev/rte_flow.c @@ -6,6 +6,7 @@ #include <errno.h> #include <stddef.h> #include <stdint.h> +#include <pthread.h> #include <rte_common.h> #include <rte_errno.h> diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c index c166ef69a8..2145d803e4 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -4,6 +4,7 @@ */ #include <ctype.h> #include <stdlib.h> +#include <pthread.h> #if defined(LINUX) #include <sys/epoll.h> #endif diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index eb6309b681..c03bb9c6eb 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -6,6 +6,7 @@ #include <linux/virtio_net.h> #include <stdint.h> #include <stdlib.h> +#include <pthread.h> #ifdef RTE_LIBRTE_VHOST_NUMA #include <numa.h> #include <numaif.h> -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 11/11] lib: remove pthread.h from includes 2023-09-06 16:12 ` [PATCH 11/11] lib: remove pthread.h from includes Thomas Monjalon @ 2023-09-08 4:25 ` Tyler Retzlaff 2023-09-08 4:49 ` Ajit Khaparde 2023-09-10 2:55 ` Xu, Rosen 1 sibling, 1 reply; 60+ messages in thread From: Tyler Retzlaff @ 2023-09-08 4:25 UTC (permalink / raw) To: Thomas Monjalon Cc: dev, David Marchand, Ferruh Yigit, Chas Williams, Min Hu (Connor), Matan Azrad, Viacheslav Ovsiienko, Ori Kam, Suanming Mou, Ajit Khaparde, Somnath Kotur, Devendra Singh Rawat, Alok Prasad, Rosen Xu, Tianfei Zhang, Vijay Kumar Srivastava, Jerin Jacob, Sunil Kumar Kori, Anatoly Burakov, Bruce Richardson, Andrew Rybchenko, Naga Harish K S V, Maxime Coquelin, Chenbo Xia On Wed, Sep 06, 2023 at 06:12:28PM +0200, Thomas Monjalon wrote: > The header files should have the minimum embedded includes. > The file pthread.h can logically be removed from > rte_per_lcore.h and rte_ethdev_core.h files. > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net> > --- Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 11/11] lib: remove pthread.h from includes 2023-09-08 4:25 ` Tyler Retzlaff @ 2023-09-08 4:49 ` Ajit Khaparde 0 siblings, 0 replies; 60+ messages in thread From: Ajit Khaparde @ 2023-09-08 4:49 UTC (permalink / raw) To: Tyler Retzlaff Cc: Thomas Monjalon, dev, David Marchand, Ferruh Yigit, Chas Williams, Min Hu (Connor), Matan Azrad, Viacheslav Ovsiienko, Ori Kam, Suanming Mou, Somnath Kotur, Devendra Singh Rawat, Alok Prasad, Rosen Xu, Tianfei Zhang, Vijay Kumar Srivastava, Jerin Jacob, Sunil Kumar Kori, Anatoly Burakov, Bruce Richardson, Andrew Rybchenko, Naga Harish K S V, Maxime Coquelin, Chenbo Xia [-- Attachment #1: Type: text/plain, Size: 520 bytes --] On Thu, Sep 7, 2023 at 9:25 PM Tyler Retzlaff <roretzla@linux.microsoft.com> wrote: > > On Wed, Sep 06, 2023 at 06:12:28PM +0200, Thomas Monjalon wrote: > > The header files should have the minimum embedded includes. > > The file pthread.h can logically be removed from > > rte_per_lcore.h and rte_ethdev_core.h files. > > > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net> > > --- > Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com> > [-- Attachment #2: S/MIME Cryptographic Signature --] [-- Type: application/pkcs7-signature, Size: 4218 bytes --] ^ permalink raw reply [flat|nested] 60+ messages in thread
* RE: [PATCH 11/11] lib: remove pthread.h from includes 2023-09-06 16:12 ` [PATCH 11/11] lib: remove pthread.h from includes Thomas Monjalon 2023-09-08 4:25 ` Tyler Retzlaff @ 2023-09-10 2:55 ` Xu, Rosen 1 sibling, 0 replies; 60+ messages in thread From: Xu, Rosen @ 2023-09-10 2:55 UTC (permalink / raw) To: Thomas Monjalon, dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Chas Williams, Min Hu (Connor), Matan Azrad, Viacheslav Ovsiienko, Ori Kam, Suanming Mou, Ajit Khaparde, Somnath Kotur, Devendra Singh Rawat, Alok Prasad, Zhang, Tianfei, Vijay Kumar Srivastava, Jerin Jacob, Sunil Kumar Kori, Burakov, Anatoly, Richardson, Bruce, Andrew Rybchenko, Naga Harish K, S V, Maxime Coquelin, Xia, Chenbo Hi, > -----Original Message----- > From: Thomas Monjalon <thomas@monjalon.net> > Sent: Thursday, September 7, 2023 12:12 AM > To: dev@dpdk.org > Cc: Tyler Retzlaff <roretzla@linux.microsoft.com>; David Marchand > <david.marchand@redhat.com>; Ferruh Yigit <ferruh.yigit@amd.com>; Chas > Williams <chas3@att.com>; Min Hu (Connor) <humin29@huawei.com>; > Matan Azrad <matan@nvidia.com>; Viacheslav Ovsiienko > <viacheslavo@nvidia.com>; Ori Kam <orika@nvidia.com>; Suanming Mou > <suanmingm@nvidia.com>; Ajit Khaparde <ajit.khaparde@broadcom.com>; > Somnath Kotur <somnath.kotur@broadcom.com>; Devendra Singh Rawat > <dsinghrawat@marvell.com>; Alok Prasad <palok@marvell.com>; Xu, Rosen > <rosen.xu@intel.com>; Zhang, Tianfei <tianfei.zhang@intel.com>; Vijay > Kumar Srivastava <vsrivast@xilinx.com>; Jerin Jacob <jerinj@marvell.com>; > Sunil Kumar Kori <skori@marvell.com>; Burakov, Anatoly > <anatoly.burakov@intel.com>; Richardson, Bruce > <bruce.richardson@intel.com>; Andrew Rybchenko > <andrew.rybchenko@oktetlabs.ru>; Naga Harish K, S V > <s.v.naga.harish.k@intel.com>; Maxime Coquelin > <maxime.coquelin@redhat.com>; Xia, Chenbo <chenbo.xia@intel.com> > Subject: [PATCH 11/11] lib: remove pthread.h from includes > > The header files should have the minimum embedded includes. > The file pthread.h can logically be removed from rte_per_lcore.h and > rte_ethdev_core.h files. > > Signed-off-by: Thomas Monjalon <thomas@monjalon.net> > --- > drivers/raw/ifpga/base/opae_osdep.h | 1 + Acked-by: Rosen Xu <rosen.xu@intel.com> ^ permalink raw reply [flat|nested] 60+ messages in thread
* RE: [PATCH 00/11] rework thread management 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon ` (10 preceding siblings ...) 2023-09-06 16:12 ` [PATCH 11/11] lib: remove pthread.h from includes Thomas Monjalon @ 2023-09-07 8:30 ` Morten Brørup 2023-09-08 4:26 ` Tyler Retzlaff 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon 13 siblings, 1 reply; 60+ messages in thread From: Morten Brørup @ 2023-09-07 8:30 UTC (permalink / raw) To: Thomas Monjalon, dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit > From: Thomas Monjalon [mailto:thomas@monjalon.net] > Sent: Wednesday, 6 September 2023 18.12 > > The main effect of this patch series is to > remove calls to pthread functions except for pthread_cancel and locks. > > The function rte_thread_create_control() does not take attributes anymore > as it looks a useless complication of the API. Note for other reviewers: The "args" parameter, passed to the thread function, is still there. > Then the rte_thread API is made stable, > so we can remove the old deprecated functions > rte_thread_setname() and rte_ctrl_thread_create(). > > Some new internal functions are added in rte_thread to make sure > all internal thread names are prefixed with "dpdk-". > > Few other cleanups are done. > > Future work about pthread portability are about: > - cancel > - mutex > > > Thomas Monjalon (11): > devtools: warn when adding some pthread calls > eal: rename thread name length definition > eal: remove attributes from control thread creation > eal: promote thread API as stable > eal: force prefix for internal threads > lib: convert to internal control threads > drivers: convert to internal control threads > examples: convert to normal control threads > test: convert threads creation > eal: remove deprecated thread functions > lib: remove pthread.h from includes Thank you for cleaning all this up, Thomas. Series-acked-by: Morten Brørup <mb@smartsharesystems.com> ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH 00/11] rework thread management 2023-09-07 8:30 ` [PATCH 00/11] rework thread management Morten Brørup @ 2023-09-08 4:26 ` Tyler Retzlaff 0 siblings, 0 replies; 60+ messages in thread From: Tyler Retzlaff @ 2023-09-08 4:26 UTC (permalink / raw) To: Morten Brørup; +Cc: Thomas Monjalon, dev, David Marchand, Ferruh Yigit On Thu, Sep 07, 2023 at 10:30:59AM +0200, Morten Brørup wrote: > > From: Thomas Monjalon [mailto:thomas@monjalon.net] > > Sent: Wednesday, 6 September 2023 18.12 > > > > The main effect of this patch series is to > > remove calls to pthread functions except for pthread_cancel and locks. > > > > The function rte_thread_create_control() does not take attributes anymore > > as it looks a useless complication of the API. > > Note for other reviewers: The "args" parameter, passed to the thread function, is still there. > > > Then the rte_thread API is made stable, > > so we can remove the old deprecated functions > > rte_thread_setname() and rte_ctrl_thread_create(). > > > > Some new internal functions are added in rte_thread to make sure > > all internal thread names are prefixed with "dpdk-". > > > > Few other cleanups are done. > > > > Future work about pthread portability are about: > > - cancel > > - mutex > > > > > > Thomas Monjalon (11): > > devtools: warn when adding some pthread calls > > eal: rename thread name length definition > > eal: remove attributes from control thread creation > > eal: promote thread API as stable > > eal: force prefix for internal threads > > lib: convert to internal control threads > > drivers: convert to internal control threads > > examples: convert to normal control threads > > test: convert threads creation > > eal: remove deprecated thread functions > > lib: remove pthread.h from includes > > Thank you for cleaning all this up, Thomas. > > Series-acked-by: Morten Brørup <mb@smartsharesystems.com> +1 thank you very much, this has been on my todo list it's really appreciated! Series-acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v2 00/11] rework thread management 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon ` (11 preceding siblings ...) 2023-09-07 8:30 ` [PATCH 00/11] rework thread management Morten Brørup @ 2023-09-13 10:34 ` Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 01/11] devtools: warn when adding some pthread calls Thomas Monjalon ` (10 more replies) 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon 13 siblings, 11 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 10:34 UTC (permalink / raw) To: dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit The main effect of this patch series is to remove calls to pthread functions except for pthread_cancel and locks. The function rte_thread_create_control() does not take thread attributes settings anymore as it looks a useless complication of the API. Then the rte_thread API is made stable, so we can remove the old deprecated functions rte_thread_setname() and rte_ctrl_thread_create(). Some new internal functions are added in rte_thread to make sure all internal thread names are prefixed with "dpdk-". Few other cleanups are done. Future work about pthread portability are about: - cancel - mutex --- v2 changes: - replace (|_) with _? in checkpatch - simplify thread name size doc - build time check of internal thread name size - clean control thread params struct Thomas Monjalon (11): devtools: warn when adding some pthread calls eal: rename thread name length definition eal: remove attributes from control thread creation eal: promote thread API as stable eal: force prefix for internal threads lib: convert to internal control threads drivers: convert to internal control threads examples: convert to normal control threads test: convert threads creation eal: remove deprecated thread functions lib: remove pthread.h from includes app/test/process.h | 10 +- app/test/test_lcores.c | 9 +- app/test/test_link_bonding.c | 2 + app/test/test_pdump.c | 6 +- app/test/test_pdump.h | 2 +- app/test/test_threads.c | 2 +- devtools/checkpatches.sh | 16 +++ .../prog_guide/env_abstraction_layer.rst | 2 +- doc/guides/rel_notes/deprecation.rst | 5 - doc/guides/rel_notes/release_23_11.rst | 6 + drivers/common/cnxk/roc_dev.c | 16 +-- drivers/common/cnxk/roc_dev_priv.h | 2 +- drivers/common/cnxk/roc_nix_inl_dev.c | 9 +- drivers/common/cnxk/roc_nix_inl_priv.h | 2 +- drivers/common/cnxk/roc_platform.h | 3 +- drivers/common/mlx5/mlx5_common.c | 1 + drivers/common/mlx5/windows/mlx5_win_ext.h | 2 + drivers/dma/skeleton/skeleton_dmadev.c | 8 +- drivers/event/dlb2/pf/base/dlb2_osdep.h | 14 +- drivers/event/dlb2/pf/base/dlb2_resource.c | 39 ++--- drivers/event/dlb2/pf/dlb2_main.h | 1 - drivers/net/ark/ark_ethdev.c | 11 +- drivers/net/ark/ark_pktgen.c | 8 +- drivers/net/ark/ark_pktgen.h | 2 +- drivers/net/bnxt/bnxt.h | 1 + drivers/net/iavf/iavf_vchnl.c | 4 +- drivers/net/ice/ice_dcf_parent.c | 7 +- drivers/net/ipn3ke/ipn3ke_representor.c | 17 ++- drivers/net/ixgbe/ixgbe_ethdev.c | 8 +- drivers/net/mlx5/mlx5.h | 2 +- drivers/net/mlx5/mlx5_hws_cnt.c | 42 +++--- drivers/net/qede/base/bcm_osal.h | 1 + drivers/net/sfc/sfc_mae.h | 2 +- drivers/net/sfc/sfc_mae_counter.c | 11 +- drivers/net/txgbe/txgbe_ethdev.c | 6 +- drivers/raw/ifpga/base/opae_osdep.h | 1 + drivers/raw/ifpga/ifpga_rawdev.c | 19 ++- drivers/vdpa/ifc/ifcvf_vdpa.c | 86 ++++++----- drivers/vdpa/mlx5/mlx5_vdpa.c | 2 +- drivers/vdpa/mlx5/mlx5_vdpa.h | 10 +- drivers/vdpa/mlx5/mlx5_vdpa_cthread.c | 70 +++------ drivers/vdpa/mlx5/mlx5_vdpa_event.c | 64 +++------ drivers/vdpa/sfc/sfc_vdpa.c | 1 + drivers/vdpa/sfc/sfc_vdpa_ops.c | 15 +- drivers/vdpa/sfc/sfc_vdpa_ops.h | 3 +- examples/vhost/main.c | 9 +- examples/vhost_blk/vhost_blk.c | 21 +-- lib/eal/common/eal_common_options.c | 1 + lib/eal/common/eal_common_proc.c | 15 +- lib/eal/common/eal_common_thread.c | 127 ++++++----------- lib/eal/common/eal_common_trace.c | 1 + lib/eal/common/malloc_mp.c | 1 + lib/eal/freebsd/eal.c | 2 +- lib/eal/freebsd/eal_alarm.c | 1 + lib/eal/freebsd/eal_interrupts.c | 10 +- lib/eal/freebsd/eal_thread.c | 9 +- lib/eal/include/rte_eal.h | 3 - lib/eal/include/rte_lcore.h | 42 ------ lib/eal/include/rte_per_lcore.h | 2 - lib/eal/include/rte_thread.h | 133 +++++++++--------- lib/eal/linux/eal.c | 2 +- lib/eal/linux/eal_alarm.c | 1 + lib/eal/linux/eal_interrupts.c | 10 +- lib/eal/linux/eal_thread.c | 18 +-- lib/eal/linux/eal_timer.c | 11 +- lib/eal/unix/rte_thread.c | 2 +- lib/eal/version.map | 44 +++--- lib/eal/windows/eal.c | 2 +- lib/eal/windows/eal_interrupts.c | 2 +- lib/eal/windows/eal_thread.c | 8 -- lib/eal/windows/rte_thread.c | 2 +- lib/ethdev/ethdev_driver.c | 1 + lib/ethdev/ethdev_driver.h | 2 + lib/ethdev/rte_ethdev_core.h | 2 - lib/ethdev/rte_flow.c | 1 + lib/eventdev/rte_event_eth_rx_adapter.c | 24 ++-- lib/vhost/fd_man.c | 6 +- lib/vhost/fd_man.h | 2 +- lib/vhost/socket.c | 23 ++- lib/vhost/vduse.c | 5 +- lib/vhost/vhost.c | 1 + 81 files changed, 464 insertions(+), 632 deletions(-) -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v2 01/11] devtools: warn when adding some pthread calls 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon @ 2023-09-13 10:34 ` Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 02/11] eal: rename thread name length definition Thomas Monjalon ` (9 subsequent siblings) 10 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 10:34 UTC (permalink / raw) To: dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup All pthread functions below have an equivalent in rte_thread API: - pthread_create - pthread_join - pthread_detach - pthread_setname_np - pthread_set_name_np - pthread_setaffinity_np - pthread_attr_setinheritsched - pthread_attr_setschedpolicy Usage of these functions will be raised to encourage rte_thread adoption. The pthread functions for locks and cancel are still allowed. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- v2: replace (|_) with _? --- devtools/checkpatches.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 55fabc5458..ec9d232393 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -119,6 +119,14 @@ check_forbidden_additions() { # <patch> -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ "$1" || res=1 + # refrain from using some pthread functions + awk -v FOLDERS="lib drivers app examples" \ + -v EXPRESSIONS="pthread_(create|join|detach|set(_?name_np|affinity_np)|attr_set(inheritsched|schedpolicy))\\\(" \ + -v RET_ON_FAIL=1 \ + -v MESSAGE='Using pthread functions, prefer rte_thread' \ + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ + "$1" || res=1 + # forbid use of __reserved which is a reserved keyword in Windows system headers awk -v FOLDERS="lib drivers app examples" \ -v EXPRESSIONS='\\<__reserved\\>' \ -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v2 02/11] eal: rename thread name length definition 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 01/11] devtools: warn when adding some pthread calls Thomas Monjalon @ 2023-09-13 10:34 ` Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 03/11] eal: remove attributes from control thread creation Thomas Monjalon ` (8 subsequent siblings) 10 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 10:34 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Bruce Richardson, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam RTE_MAX_THREAD_NAME_LEN is including the NUL character, so it should be named "size" instead of "length". A new constant RTE_THREAD_NAME_SIZE is introduced for naming accuracy. For API compatibility, the old name is kept. At the same time, the original definition is moved from rte_eal.h to rte_thread.h. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- lib/eal/freebsd/eal.c | 2 +- lib/eal/freebsd/eal_thread.c | 2 +- lib/eal/include/rte_eal.h | 3 --- lib/eal/include/rte_thread.h | 9 +++++++-- lib/eal/linux/eal.c | 2 +- lib/eal/linux/eal_thread.c | 2 +- lib/eal/windows/eal.c | 2 +- lib/eal/windows/rte_thread.c | 2 +- 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 9e1e267955..39a2868523 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -583,7 +583,7 @@ rte_eal_init(int argc, char **argv) static uint32_t run_once; uint32_t has_run = 0; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; - char thread_name[RTE_MAX_THREAD_NAME_LEN]; + char thread_name[RTE_THREAD_NAME_SIZE]; const struct rte_config *config = rte_eal_get_configuration(); struct internal_config *internal_conf = eal_get_internal_configuration(); diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c index 3227d9b8a2..ba9b25c2c0 100644 --- a/lib/eal/freebsd/eal_thread.c +++ b/lib/eal/freebsd/eal_thread.c @@ -34,7 +34,7 @@ int rte_sys_gettid(void) void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) { - char truncated[RTE_MAX_THREAD_NAME_LEN]; + char truncated[RTE_THREAD_NAME_SIZE]; const size_t truncatedsz = sizeof(truncated); if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz) diff --git a/lib/eal/include/rte_eal.h b/lib/eal/include/rte_eal.h index 53c4a5519e..cd318ee141 100644 --- a/lib/eal/include/rte_eal.h +++ b/lib/eal/include/rte_eal.h @@ -27,9 +27,6 @@ extern "C" { #define RTE_MAGIC 19820526 /**< Magic number written by the main partition when ready. */ -/* Maximum thread_name length. */ -#define RTE_MAX_THREAD_NAME_LEN 16 - /** * The type of process in a linux, multi-process setup */ diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index 369e2375f6..6233142322 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -23,6 +23,11 @@ extern "C" { #endif +/** Maximum thread name length (including '\0'). */ +#define RTE_THREAD_NAME_SIZE 16 +/* Old definition, aliased for compatibility. */ +#define RTE_MAX_THREAD_NAME_LEN RTE_THREAD_NAME_SIZE + /** * Thread id descriptor. */ @@ -110,7 +115,7 @@ int rte_thread_create(rte_thread_t *thread_id, * Filled with the thread id of the new created thread. * @param name * The name of the control thread - * (max RTE_MAX_THREAD_NAME_LEN characters including '\0'). + * (max RTE_THREAD_NAME_SIZE characters including '\0'). * @param thread_attr * Attributes for the new thread. * @param thread_func @@ -188,7 +193,7 @@ rte_thread_t rte_thread_self(void); * The id of the thread to set name. * * @param thread_name - * The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN, + * The name to set. Truncated to RTE_THREAD_NAME_SIZE, * including terminating NUL if necessary. */ __rte_experimental diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index a26822f667..5f4b2fb005 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -970,7 +970,7 @@ rte_eal_init(int argc, char **argv) static uint32_t run_once; uint32_t has_run = 0; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; - char thread_name[RTE_MAX_THREAD_NAME_LEN]; + char thread_name[RTE_THREAD_NAME_SIZE]; bool phys_addrs; const struct rte_config *config = rte_eal_get_configuration(); struct internal_config *internal_conf = diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c index c07ad9d8a4..b9a126f3a8 100644 --- a/lib/eal/linux/eal_thread.c +++ b/lib/eal/linux/eal_thread.c @@ -24,7 +24,7 @@ void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) int ret = ENOSYS; #if defined(__GLIBC__) && defined(__GLIBC_PREREQ) #if __GLIBC_PREREQ(2, 12) - char truncated[RTE_MAX_THREAD_NAME_LEN]; + char truncated[RTE_THREAD_NAME_SIZE]; const size_t truncatedsz = sizeof(truncated); if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz) diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 16c1ba1596..7ec2152211 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -283,7 +283,7 @@ rte_eal_init(int argc, char **argv) enum rte_iova_mode iova_mode; int ret; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; - char thread_name[RTE_MAX_THREAD_NAME_LEN]; + char thread_name[RTE_THREAD_NAME_SIZE]; eal_log_init(NULL, 0); diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c index e528ac9991..acf648456c 100644 --- a/lib/eal/windows/rte_thread.c +++ b/lib/eal/windows/rte_thread.c @@ -324,7 +324,7 @@ void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) { int ret = 0; - wchar_t wname[RTE_MAX_THREAD_NAME_LEN]; + wchar_t wname[RTE_THREAD_NAME_SIZE]; mbstate_t state = {0}; size_t rv; HANDLE thread_handle; -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v2 03/11] eal: remove attributes from control thread creation 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 01/11] devtools: warn when adding some pthread calls Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 02/11] eal: rename thread name length definition Thomas Monjalon @ 2023-09-13 10:34 ` Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 04/11] eal: promote thread API as stable Thomas Monjalon ` (7 subsequent siblings) 10 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 10:34 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Chengwen Feng, Kevin Laatz, Bruce Richardson, Jingjing Wu, Beilei Xing, Qiming Yang, Qi Zhang, Wenjun Wu, Jiawen Wu, Jian Wang, Harman Kalra, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam The experimental function rte_thread_create_control() is supposed to wrap actions needed to create a control thread in DPDK. This function should be easy to port on any OS. As such, the thread attributes should not be customizable in this API. The thread priority should be normal, and the affinity is on "free cores". That's why the custom attributes parameter thread_attr is dropped. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- app/test/test_threads.c | 2 +- doc/guides/rel_notes/release_23_11.rst | 3 +++ drivers/dma/skeleton/skeleton_dmadev.c | 3 +-- drivers/net/iavf/iavf_vchnl.c | 2 +- drivers/net/ice/ice_dcf_parent.c | 2 +- drivers/net/ixgbe/ixgbe_ethdev.c | 1 - drivers/net/txgbe/txgbe_ethdev.c | 2 +- lib/eal/common/eal_common_thread.c | 5 ++--- lib/eal/include/rte_thread.h | 5 +---- lib/eal/windows/eal_interrupts.c | 2 +- 10 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/test/test_threads.c b/app/test/test_threads.c index 8c27e2bae1..4ac3f2671a 100644 --- a/app/test/test_threads.c +++ b/app/test/test_threads.c @@ -240,7 +240,7 @@ test_thread_control_create_join(void) thread_id_ready = 0; RTE_TEST_ASSERT(rte_thread_create_control(&thread_id, "dpdk-test-thcc", - NULL, thread_main, &thread_main_id) == 0, + thread_main, &thread_main_id) == 0, "Failed to create thread."); while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0) diff --git a/doc/guides/rel_notes/release_23_11.rst b/doc/guides/rel_notes/release_23_11.rst index 333e1d95a2..d3d500f294 100644 --- a/doc/guides/rel_notes/release_23_11.rst +++ b/doc/guides/rel_notes/release_23_11.rst @@ -113,6 +113,9 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* eal: The thread API has changed. + The function ``rte_thread_create_control()`` does not take attributes anymore. + ABI Changes ----------- diff --git a/drivers/dma/skeleton/skeleton_dmadev.c b/drivers/dma/skeleton/skeleton_dmadev.c index 493224542f..4fc2319668 100644 --- a/drivers/dma/skeleton/skeleton_dmadev.c +++ b/drivers/dma/skeleton/skeleton_dmadev.c @@ -128,8 +128,7 @@ skeldma_start(struct rte_dma_dev *dev) rte_mb(); snprintf(name, sizeof(name), "dpdk-dma-skel%d", dev->data->dev_id); - ret = rte_thread_create_control(&hw->thread, name, NULL, - cpucopy_thread, dev); + ret = rte_thread_create_control(&hw->thread, name, cpucopy_thread, dev); if (ret) { SKELDMA_LOG(ERR, "Start cpucopy thread fail!"); return -EINVAL; diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c index c31a6d5c98..6baa6d5955 100644 --- a/drivers/net/iavf/iavf_vchnl.c +++ b/drivers/net/iavf/iavf_vchnl.c @@ -136,7 +136,7 @@ iavf_dev_event_handler_init(void) pthread_mutex_init(&handler->lock, NULL); if (rte_thread_create_control(&handler->tid, "dpdk-iavf-event", - NULL, iavf_dev_event_handle, NULL)) { + iavf_dev_event_handle, NULL)) { __atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED); return -1; } diff --git a/drivers/net/ice/ice_dcf_parent.c b/drivers/net/ice/ice_dcf_parent.c index ad98a531de..d3bb65874f 100644 --- a/drivers/net/ice/ice_dcf_parent.c +++ b/drivers/net/ice/ice_dcf_parent.c @@ -182,7 +182,7 @@ start_vsi_reset_thread(struct ice_dcf_hw *dcf_hw, bool vfr, uint16_t vf_id) param->vf_id = vf_id; snprintf(name, sizeof(name), "dpdk-ice-rst%u", vf_id); - ret = rte_thread_create_control(&thread, name, NULL, + ret = rte_thread_create_control(&thread, name, ice_dcf_vsi_update_service_handler, param); if (ret != 0) { PMD_DRV_LOG(ERR, "Failed to start the thread for reset handling"); diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c index 7eac05ee60..64e7e5d7d6 100644 --- a/drivers/net/ixgbe/ixgbe_ethdev.c +++ b/drivers/net/ixgbe/ixgbe_ethdev.c @@ -4330,7 +4330,6 @@ ixgbe_dev_link_update_share(struct rte_eth_dev *dev, intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; if (rte_thread_create_control(&ad->link_thread_tid, "dpdk-ixgbe-link", - NULL, ixgbe_dev_setup_link_thread_handler, dev) < 0) { PMD_DRV_LOG(ERR, diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c index 6f2f5a1841..198fac8318 100644 --- a/drivers/net/txgbe/txgbe_ethdev.c +++ b/drivers/net/txgbe/txgbe_ethdev.c @@ -2897,7 +2897,7 @@ txgbe_dev_link_update_share(struct rte_eth_dev *dev, */ intr->flags |= TXGBE_FLAG_NEED_LINK_CONFIG; if (rte_thread_create_control(&ad->link_thread_tid, - "dpdk-txgbe-link", NULL, + "dpdk-txgbe-link", txgbe_dev_setup_link_thread_handler, dev) < 0) { PMD_DRV_LOG(ERR, "Create link thread failed!"); __atomic_clear(&ad->link_thread_running, __ATOMIC_SEQ_CST); diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 6605bd017e..07ac721da1 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -349,8 +349,7 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, int rte_thread_create_control(rte_thread_t *thread, const char *name, - const rte_thread_attr_t *attr, rte_thread_func start_routine, - void *arg) + rte_thread_func start_routine, void *arg) { struct rte_thread_ctrl_params *params; enum __rte_ctrl_thread_status ctrl_thread_status; @@ -365,7 +364,7 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, params->ret = 0; params->ctrl_thread_status = CTRL_THREAD_LAUNCHING; - ret = rte_thread_create(thread, attr, control_thread_start, params); + ret = rte_thread_create(thread, NULL, control_thread_start, params); if (ret != 0) { free(params); return -ret; diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index 6233142322..28cc5220a4 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -116,8 +116,6 @@ int rte_thread_create(rte_thread_t *thread_id, * @param name * The name of the control thread * (max RTE_THREAD_NAME_SIZE characters including '\0'). - * @param thread_attr - * Attributes for the new thread. * @param thread_func * Function to be executed by the new thread. * @param arg @@ -129,8 +127,7 @@ int rte_thread_create(rte_thread_t *thread_id, __rte_experimental int rte_thread_create_control(rte_thread_t *thread, const char *name, - const rte_thread_attr_t *thread_attr, rte_thread_func thread_func, - void *arg); + rte_thread_func thread_func, void *arg); /** * @warning diff --git a/lib/eal/windows/eal_interrupts.c b/lib/eal/windows/eal_interrupts.c index b1b1228c2b..66a49c844a 100644 --- a/lib/eal/windows/eal_interrupts.c +++ b/lib/eal/windows/eal_interrupts.c @@ -98,7 +98,7 @@ rte_eal_intr_init(void) return -1; } - ret = rte_thread_create_control(&intr_thread, "dpdk-intr", NULL, + ret = rte_thread_create_control(&intr_thread, "dpdk-intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v2 04/11] eal: promote thread API as stable 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon ` (2 preceding siblings ...) 2023-09-13 10:34 ` [PATCH v2 03/11] eal: remove attributes from control thread creation Thomas Monjalon @ 2023-09-13 10:34 ` Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 05/11] eal: force prefix for internal threads Thomas Monjalon ` (6 subsequent siblings) 10 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 10:34 UTC (permalink / raw) To: dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup The rte_thread API must be used to ease OS porting. One step of this process is to mark the necessary API as stable. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- doc/guides/rel_notes/release_23_11.rst | 1 + lib/eal/include/rte_thread.h | 64 -------------------------- lib/eal/version.map | 40 ++++++++-------- 3 files changed, 20 insertions(+), 85 deletions(-) diff --git a/doc/guides/rel_notes/release_23_11.rst b/doc/guides/rel_notes/release_23_11.rst index d3d500f294..d7562fd646 100644 --- a/doc/guides/rel_notes/release_23_11.rst +++ b/doc/guides/rel_notes/release_23_11.rst @@ -115,6 +115,7 @@ API Changes * eal: The thread API has changed. The function ``rte_thread_create_control()`` does not take attributes anymore. + The whole thread API was promoted to stable level. ABI Changes diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index 28cc5220a4..dd1f62523f 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -73,9 +73,6 @@ typedef struct { typedef struct eal_tls_key *rte_thread_key; /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Create a new thread that will invoke the 'thread_func' routine. * * @param thread_id @@ -94,15 +91,11 @@ typedef struct eal_tls_key *rte_thread_key; * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_create(rte_thread_t *thread_id, const rte_thread_attr_t *thread_attr, rte_thread_func thread_func, void *arg); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Create a control thread. * * Creates a control thread with the given name and attributes. The @@ -124,15 +117,11 @@ int rte_thread_create(rte_thread_t *thread_id, * On success, returns 0; on error, it returns a negative value * corresponding to the error number. */ -__rte_experimental int rte_thread_create_control(rte_thread_t *thread, const char *name, rte_thread_func thread_func, void *arg); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Waits for the thread identified by 'thread_id' to terminate * * @param thread_id @@ -145,13 +134,9 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_join(rte_thread_t thread_id, uint32_t *value_ptr); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Indicate that the return value of the thread is not needed and * all thread resources should be release when the thread terminates. * @@ -162,25 +147,17 @@ int rte_thread_join(rte_thread_t thread_id, uint32_t *value_ptr); * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_detach(rte_thread_t thread_id); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Get the id of the calling thread. * * @return * Return the thread id of the calling thread. */ -__rte_experimental rte_thread_t rte_thread_self(void); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the name of the thread. * This API is a noop if the underlying platform does not * support setting the thread name or the platform-specific @@ -193,14 +170,10 @@ rte_thread_t rte_thread_self(void); * The name to set. Truncated to RTE_THREAD_NAME_SIZE, * including terminating NUL if necessary. */ -__rte_experimental void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Check if 2 thread ids are equal. * * @param t1 @@ -213,13 +186,9 @@ rte_thread_set_name(rte_thread_t thread_id, const char *thread_name); * If the ids are equal, return nonzero. * Otherwise, return 0. */ -__rte_experimental int rte_thread_equal(rte_thread_t t1, rte_thread_t t2); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Initialize the attributes of a thread. * These attributes can be passed to the rte_thread_create() function * that will create a new thread and set its attributes according to attr. @@ -231,13 +200,9 @@ int rte_thread_equal(rte_thread_t t1, rte_thread_t t2); * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_attr_init(rte_thread_attr_t *attr); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the thread priority value in the thread attributes pointed to * by 'thread_attr'. * @@ -251,16 +216,12 @@ int rte_thread_attr_init(rte_thread_attr_t *attr); * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr, enum rte_thread_priority priority); #ifdef RTE_HAS_CPUSET /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the CPU affinity value in the thread attributes pointed to * by 'thread_attr'. * @@ -274,14 +235,10 @@ int rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr, rte_cpuset_t *cpuset); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Get the value of CPU affinity that is set in the thread attributes pointed * to by 'thread_attr'. * @@ -295,14 +252,10 @@ int rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr, rte_cpuset_t *cpuset); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the affinity of thread 'thread_id' to the cpu set * specified by 'cpuset'. * @@ -316,14 +269,10 @@ int rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_set_affinity_by_id(rte_thread_t thread_id, const rte_cpuset_t *cpuset); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Get the affinity of thread 'thread_id' and store it * in 'cpuset'. * @@ -337,7 +286,6 @@ int rte_thread_set_affinity_by_id(rte_thread_t thread_id, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_get_affinity_by_id(rte_thread_t thread_id, rte_cpuset_t *cpuset); @@ -364,9 +312,6 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp); #endif /* RTE_HAS_CPUSET */ /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Get the priority of a thread. * * @param thread_id @@ -379,14 +324,10 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp); * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_get_priority(rte_thread_t thread_id, enum rte_thread_priority *priority); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the priority of a thread. * * @param thread_id @@ -399,7 +340,6 @@ int rte_thread_get_priority(rte_thread_t thread_id, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_set_priority(rte_thread_t thread_id, enum rte_thread_priority priority); @@ -421,7 +361,6 @@ int rte_thread_set_priority(rte_thread_t thread_id, * ENOEXEC - Specific OS error. */ -__rte_experimental int rte_thread_key_create(rte_thread_key *key, void (*destructor)(void *)); @@ -437,7 +376,6 @@ int rte_thread_key_create(rte_thread_key *key, * rte_errno can be: EINVAL - Invalid parameter passed. * ENOEXEC - Specific OS error. */ -__rte_experimental int rte_thread_key_delete(rte_thread_key key); /** @@ -454,7 +392,6 @@ int rte_thread_key_delete(rte_thread_key key); * rte_errno can be: EINVAL - Invalid parameter passed. * ENOEXEC - Specific OS error. */ -__rte_experimental int rte_thread_value_set(rte_thread_key key, const void *value); /** @@ -469,7 +406,6 @@ int rte_thread_value_set(rte_thread_key key, const void *value); * rte_errno can be: EINVAL - Invalid parameter passed. * ENOEXEC - Specific OS error. */ -__rte_experimental void *rte_thread_value_get(rte_thread_key key); #ifdef __cplusplus diff --git a/lib/eal/version.map b/lib/eal/version.map index 7940431e5a..33b853d7be 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -257,12 +257,31 @@ DPDK_24 { rte_strscpy; rte_strsplit; rte_sys_gettid; + rte_thread_attr_get_affinity; + rte_thread_attr_init; + rte_thread_attr_set_affinity; + rte_thread_attr_set_priority; + rte_thread_create; + rte_thread_create_control; + rte_thread_detach; + rte_thread_equal; rte_thread_get_affinity; + rte_thread_get_affinity_by_id; + rte_thread_get_priority; rte_thread_is_intr; + rte_thread_join; + rte_thread_key_create; + rte_thread_key_delete; rte_thread_register; + rte_thread_self; rte_thread_set_affinity; + rte_thread_set_affinity_by_id; + rte_thread_set_name; + rte_thread_set_priority; rte_thread_setname; rte_thread_unregister; + rte_thread_value_get; + rte_thread_value_set; rte_uuid_compare; rte_uuid_is_null; rte_uuid_parse; @@ -368,10 +387,6 @@ EXPERIMENTAL { # added in 21.05 rte_devargs_reset; rte_intr_callback_unregister_sync; - rte_thread_key_create; - rte_thread_key_delete; - rte_thread_value_get; - rte_thread_value_set; rte_version_minor; rte_version_month; rte_version_prefix; @@ -392,26 +407,9 @@ EXPERIMENTAL { # added in 22.07 rte_drand; - rte_thread_get_affinity_by_id; - rte_thread_get_priority; - rte_thread_self; - rte_thread_set_affinity_by_id; - rte_thread_set_priority; - - # added in 22.11 - rte_thread_attr_get_affinity; - rte_thread_attr_init; - rte_thread_attr_set_affinity; - rte_thread_attr_set_priority; - rte_thread_create; - rte_thread_detach; - rte_thread_equal; - rte_thread_join; # added in 23.03 rte_lcore_register_usage_cb; - rte_thread_create_control; - rte_thread_set_name; __rte_eal_trace_generic_blob; # added in 23.07 -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v2 05/11] eal: force prefix for internal threads 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon ` (3 preceding siblings ...) 2023-09-13 10:34 ` [PATCH v2 04/11] eal: promote thread API as stable Thomas Monjalon @ 2023-09-13 10:34 ` Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 06/11] lib: convert to internal control threads Thomas Monjalon ` (5 subsequent siblings) 10 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 10:34 UTC (permalink / raw) To: dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup In order to make sure all threads created in DPDK drivers and libraries have the same prefix in their name, some wrapper functions are added for internal use when creating a control thread or setting a thread name: - rte_thread_create_internal_control - rte_thread_set_prefixed_name The equivalent public functions are then forbidden for internal use: - rte_thread_create_control - rte_thread_set_name Note: the libraries and drivers conversion is done in next patches, while doing other thread-related changes. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- v2: simplify size doc + build time check of internal name size --- devtools/checkpatches.sh | 8 ++++ lib/eal/common/eal_common_thread.c | 29 +++++++++++++++ lib/eal/include/rte_thread.h | 59 +++++++++++++++++++++++++++++- lib/eal/version.map | 2 + 4 files changed, 97 insertions(+), 1 deletion(-) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index ec9d232393..e97811192a 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -159,6 +159,14 @@ check_forbidden_additions() { # <patch> -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ "$1" || res=1 + # forbid non-internal thread in drivers and libs + awk -v FOLDERS='lib drivers' \ + -v EXPRESSIONS="rte_thread_(set_name|create_control)\\\(" \ + -v RET_ON_FAIL=1 \ + -v MESSAGE='Prefer rte_thread_(set_prefixed_name|create_internal_control) in lib & drivers' \ + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ + "$1" || res=1 + # forbid inclusion of driver specific headers in apps and examples awk -v FOLDERS='app examples' \ -v EXPRESSIONS='include.*_driver\\.h include.*_pmd\\.h' \ diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 07ac721da1..cd6e00fe8a 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -392,6 +392,35 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, return ret; } +static void +add_internal_prefix(char *prefixed_name, const char *name, size_t size) +{ + size_t prefixlen; + + prefixlen = strlen(RTE_THREAD_INTERNAL_PREFIX); + strlcpy(prefixed_name, RTE_THREAD_INTERNAL_PREFIX, size); + strlcpy(prefixed_name + prefixlen, name, size - prefixlen); +} + +int +rte_thread_create_internal_control(rte_thread_t *id, const char *name, + rte_thread_func func, void *arg) +{ + char prefixed_name[RTE_THREAD_NAME_SIZE]; + + add_internal_prefix(prefixed_name, name, sizeof(prefixed_name)); + return rte_thread_create_control(id, prefixed_name, func, arg); +} + +void +rte_thread_set_prefixed_name(rte_thread_t id, const char *name) +{ + char prefixed_name[RTE_THREAD_NAME_SIZE]; + + add_internal_prefix(prefixed_name, name, sizeof(prefixed_name)); + rte_thread_set_name(id, prefixed_name); +} + int rte_thread_register(void) { diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index dd1f62523f..afede97bed 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -28,6 +28,13 @@ extern "C" { /* Old definition, aliased for compatibility. */ #define RTE_MAX_THREAD_NAME_LEN RTE_THREAD_NAME_SIZE +/** Thread name prefix automatically added to all internal threads. */ +#define RTE_THREAD_INTERNAL_PREFIX "dpdk-" +/** Maximum internal thread name length (including '\0'). */ +#define RTE_THREAD_INTERNAL_NAME_SIZE 11 +RTE_BUILD_BUG_ON(RTE_THREAD_INTERNAL_NAME_SIZE != + RTE_THREAD_NAME_SIZE - sizeof(RTE_THREAD_INTERNAL_PREFIX) + 1) + /** * Thread id descriptor. */ @@ -112,7 +119,7 @@ int rte_thread_create(rte_thread_t *thread_id, * @param thread_func * Function to be executed by the new thread. * @param arg - * Argument passed to start_routine. + * Argument passed to thread_func. * @return * On success, returns 0; on error, it returns a negative value * corresponding to the error number. @@ -121,6 +128,35 @@ int rte_thread_create_control(rte_thread_t *thread, const char *name, rte_thread_func thread_func, void *arg); +/** + * Create an internal control thread. + * + * Creates a control thread with the given name prefixed. + * If setting the name of the thread fails, the error is ignored and logged. + * + * The affinity of the new thread is based on the CPU affinity retrieved + * at the time rte_eal_init() was called, the EAL threads are then excluded. + * + * @param id + * Filled with the thread ID of the new created thread. + * @param name + * The name of the control thread. + * See RTE_THREAD_INTERNAL_NAME_SIZE for maximum length. + * The name of the driver or library should be first, + * then followed by a hyphen and more details. + * It will be prefixed with RTE_THREAD_INTERNAL_PREFIX by this function. + * @param func + * Function to be executed by the new thread. + * @param arg + * Argument passed to func. + * @return + * On success, returns 0; a negative value otherwise. + */ +__rte_internal +int +rte_thread_create_internal_control(rte_thread_t *id, const char *name, + rte_thread_func func, void *arg); + /** * Waits for the thread identified by 'thread_id' to terminate * @@ -159,6 +195,7 @@ rte_thread_t rte_thread_self(void); /** * Set the name of the thread. + * * This API is a noop if the underlying platform does not * support setting the thread name or the platform-specific * API used to set the thread name fails. @@ -173,6 +210,26 @@ rte_thread_t rte_thread_self(void); void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name); +/** + * Set the name of an internal thread with the common prefix. + * + * This API is a noop if the underlying platform does not support + * setting the thread name, or if it fails. + * + * @param id + * The ID of the thread to set name. + * + * @param name + * The name to set after being prefixed. + * See RTE_THREAD_INTERNAL_NAME_SIZE for maximum length. + * The name of the driver or library should be first, + * then followed by a hyphen and more details. + * It will be prefixed with RTE_THREAD_INTERNAL_PREFIX by this function. + */ +__rte_internal +void +rte_thread_set_prefixed_name(rte_thread_t id, const char *name); + /** * Check if 2 thread ids are equal. * diff --git a/lib/eal/version.map b/lib/eal/version.map index 33b853d7be..6d32c19286 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -462,4 +462,6 @@ INTERNAL { rte_mem_map; rte_mem_page_size; rte_mem_unmap; + rte_thread_create_internal_control; + rte_thread_set_prefixed_name; }; -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v2 06/11] lib: convert to internal control threads 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon ` (4 preceding siblings ...) 2023-09-13 10:34 ` [PATCH v2 05/11] eal: force prefix for internal threads Thomas Monjalon @ 2023-09-13 10:34 ` Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 07/11] drivers: " Thomas Monjalon ` (4 subsequent siblings) 10 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 10:34 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Anatoly Burakov, Harman Kalra, Bruce Richardson, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam, Naga Harish K S V, Jerin Jacob, Maxime Coquelin, Chenbo Xia Calls to rte_ctrl_thread_create() are replaced with rte_thread_create_internal_control(). Other pthread-related functions are replaced with the rte_thread API. Only pthread_cancel() has no replacement. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- lib/eal/common/eal_common_proc.c | 15 ++++++++------- lib/eal/freebsd/eal_interrupts.c | 10 +++++----- lib/eal/linux/eal_interrupts.c | 10 +++++----- lib/eal/linux/eal_timer.c | 11 ++++++----- lib/eal/unix/rte_thread.c | 2 +- lib/eal/windows/eal_interrupts.c | 2 +- lib/eventdev/rte_event_eth_rx_adapter.c | 23 ++++++++++++----------- lib/vhost/fd_man.c | 6 +++--- lib/vhost/fd_man.h | 2 +- lib/vhost/socket.c | 23 +++++++++++------------ lib/vhost/vduse.c | 5 +++-- 11 files changed, 56 insertions(+), 53 deletions(-) diff --git a/lib/eal/common/eal_common_proc.c b/lib/eal/common/eal_common_proc.c index 26e6b78f8f..f20a348ede 100644 --- a/lib/eal/common/eal_common_proc.c +++ b/lib/eal/common/eal_common_proc.c @@ -26,6 +26,7 @@ #include <rte_errno.h> #include <rte_lcore.h> #include <rte_log.h> +#include <rte_thread.h> #include "eal_memcfg.h" #include "eal_private.h" @@ -33,7 +34,7 @@ #include "eal_internal_cfg.h" static int mp_fd = -1; -static pthread_t mp_handle_tid; +static rte_thread_t mp_handle_tid; static char mp_filter[PATH_MAX]; /* Filter for secondary process sockets */ static char mp_dir_path[PATH_MAX]; /* The directory path for all mp sockets */ static pthread_mutex_t mp_mutex_action = PTHREAD_MUTEX_INITIALIZER; @@ -396,7 +397,7 @@ process_msg(struct mp_msg_internal *m, struct sockaddr_un *s) } } -static void * +static uint32_t mp_handle(void *arg __rte_unused) { struct mp_msg_internal msg; @@ -413,7 +414,7 @@ mp_handle(void *arg __rte_unused) process_msg(&msg, &sa); } - return NULL; + return 0; } static int @@ -646,8 +647,8 @@ rte_mp_channel_init(void) return -1; } - if (rte_ctrl_thread_create(&mp_handle_tid, "dpdk-mp-msg", - NULL, mp_handle, NULL) < 0) { + if (rte_thread_create_internal_control(&mp_handle_tid, "mp-msg", + mp_handle, NULL) < 0) { RTE_LOG(ERR, EAL, "failed to create mp thread: %s\n", strerror(errno)); close(dir_fd); @@ -671,8 +672,8 @@ rte_mp_channel_cleanup(void) if (fd < 0) return; - pthread_cancel(mp_handle_tid); - pthread_join(mp_handle_tid, NULL); + pthread_cancel((pthread_t)mp_handle_tid.opaque_id); + rte_thread_join(mp_handle_tid, NULL); close_socket_fd(fd); } diff --git a/lib/eal/freebsd/eal_interrupts.c b/lib/eal/freebsd/eal_interrupts.c index 68cdb9deb3..2b31dfb099 100644 --- a/lib/eal/freebsd/eal_interrupts.c +++ b/lib/eal/freebsd/eal_interrupts.c @@ -52,7 +52,7 @@ static rte_spinlock_t intr_lock = RTE_SPINLOCK_INITIALIZER; static struct rte_intr_source_list intr_sources; /* interrupt handling thread */ -static pthread_t intr_thread; +static rte_thread_t intr_thread; static volatile int kq = -1; @@ -591,7 +591,7 @@ eal_intr_process_interrupts(struct kevent *events, int nfds) } } -static void * +static uint32_t eal_intr_thread_main(void *arg __rte_unused) { struct kevent events[MAX_INTR_EVENTS]; @@ -619,7 +619,7 @@ eal_intr_thread_main(void *arg __rte_unused) } close(kq); kq = -1; - return NULL; + return 0; } int @@ -637,7 +637,7 @@ rte_eal_intr_init(void) } /* create the host thread to wait/handle the interrupt */ - ret = rte_ctrl_thread_create(&intr_thread, "dpdk-intr", NULL, + ret = rte_thread_create_internal_control(&intr_thread, "intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; @@ -746,5 +746,5 @@ rte_intr_free_epoll_fd(struct rte_intr_handle *intr_handle) int rte_thread_is_intr(void) { - return pthread_equal(intr_thread, pthread_self()); + return rte_thread_equal(intr_thread, rte_thread_self()); } diff --git a/lib/eal/linux/eal_interrupts.c b/lib/eal/linux/eal_interrupts.c index 19b36787b8..24fff3d3c2 100644 --- a/lib/eal/linux/eal_interrupts.c +++ b/lib/eal/linux/eal_interrupts.c @@ -5,7 +5,6 @@ #include <stdio.h> #include <stdint.h> #include <stdlib.h> -#include <pthread.h> #include <sys/queue.h> #include <unistd.h> #include <string.h> @@ -19,6 +18,7 @@ #include <eal_trace_internal.h> #include <rte_common.h> #include <rte_interrupts.h> +#include <rte_thread.h> #include <rte_per_lcore.h> #include <rte_lcore.h> #include <rte_branch_prediction.h> @@ -89,7 +89,7 @@ static union intr_pipefds intr_pipe; static struct rte_intr_source_list intr_sources; /* interrupt handling thread */ -static pthread_t intr_thread; +static rte_thread_t intr_thread; /* VFIO interrupts */ #ifdef VFIO_PRESENT @@ -1103,7 +1103,7 @@ eal_intr_handle_interrupts(int pfd, unsigned totalfds) * @return * never return; */ -static __rte_noreturn void * +static __rte_noreturn uint32_t eal_intr_thread_main(__rte_unused void *arg) { /* host thread, never break out */ @@ -1188,7 +1188,7 @@ rte_eal_intr_init(void) } /* create the host thread to wait/handle the interrupt */ - ret = rte_ctrl_thread_create(&intr_thread, "dpdk-intr", NULL, + ret = rte_thread_create_internal_control(&intr_thread, "intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; @@ -1601,5 +1601,5 @@ rte_intr_cap_multiple(struct rte_intr_handle *intr_handle) int rte_thread_is_intr(void) { - return pthread_equal(intr_thread, pthread_self()); + return rte_thread_equal(intr_thread, rte_thread_self()); } diff --git a/lib/eal/linux/eal_timer.c b/lib/eal/linux/eal_timer.c index 1898709700..3a30284e3a 100644 --- a/lib/eal/linux/eal_timer.c +++ b/lib/eal/linux/eal_timer.c @@ -14,6 +14,7 @@ #include <rte_common.h> #include <rte_cycles.h> +#include <rte_thread.h> #include "eal_private.h" @@ -71,14 +72,14 @@ static uint64_t eal_hpet_resolution_hz = 0; /* Incremented 4 times during one 32bits hpet full count */ static uint32_t eal_hpet_msb; -static pthread_t msb_inc_thread_id; +static rte_thread_t msb_inc_thread_id; /* * This function runs on a specific thread to update a global variable * containing used to process MSB of the HPET (unfortunately, we need * this because hpet is 32 bits by default under linux). */ -static void * +static uint32_t hpet_msb_inc(__rte_unused void *arg) { uint32_t t; @@ -89,7 +90,7 @@ hpet_msb_inc(__rte_unused void *arg) eal_hpet_msb ++; sleep(10); } - return NULL; + return 0; } uint64_t @@ -176,8 +177,8 @@ rte_eal_hpet_init(int make_default) /* create a thread that will increment a global variable for * msb (hpet is 32 bits by default under linux) */ - ret = rte_ctrl_thread_create(&msb_inc_thread_id, "dpdk-hpet-msb", NULL, - hpet_msb_inc, NULL); + ret = rte_thread_create_internal_control(&msb_inc_thread_id, "hpet-msb", + hpet_msb_inc, NULL); if (ret != 0) { RTE_LOG(ERR, EAL, "ERROR: Cannot create HPET timer thread!\n"); internal_conf->no_hpet = 1; diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c index f4076122a4..36a21ab2f9 100644 --- a/lib/eal/unix/rte_thread.c +++ b/lib/eal/unix/rte_thread.c @@ -190,7 +190,7 @@ rte_thread_create(rte_thread_t *thread_id, pthread_mutex_unlock(&ctx.wrapper_mutex); if (ret != 0) - pthread_join((pthread_t)thread_id->opaque_id, NULL); + rte_thread_join(*thread_id, NULL); cleanup: if (attrp != NULL) diff --git a/lib/eal/windows/eal_interrupts.c b/lib/eal/windows/eal_interrupts.c index 66a49c844a..49efdc098c 100644 --- a/lib/eal/windows/eal_interrupts.c +++ b/lib/eal/windows/eal_interrupts.c @@ -98,7 +98,7 @@ rte_eal_intr_init(void) return -1; } - ret = rte_thread_create_control(&intr_thread, "dpdk-intr", + ret = rte_thread_create_internal_control(&intr_thread, "intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c index 3ebfa5366d..c166ef69a8 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -10,6 +10,7 @@ #include <unistd.h> #include <rte_cycles.h> +#include <rte_thread.h> #include <rte_common.h> #include <dev_driver.h> #include <rte_errno.h> @@ -165,7 +166,7 @@ struct event_eth_rx_adapter { /* Count of interrupt vectors in use */ uint32_t num_intr_vec; /* Thread blocked on Rx interrupts */ - pthread_t rx_intr_thread; + rte_thread_t rx_intr_thread; /* Configuration callback for rte_service configuration */ rte_event_eth_rx_adapter_conf_cb conf_cb; /* Configuration callback argument */ @@ -1154,13 +1155,13 @@ rxa_intr_ring_del_entries(struct event_eth_rx_adapter *rx_adapter, rte_spinlock_unlock(&rx_adapter->intr_ring_lock); } -/* pthread callback handling interrupt mode receive queues +/* thread callback handling interrupt mode receive queues * After receiving an Rx interrupt, it enqueues the port id and queue id of the * interrupting queue to the adapter's ring buffer for interrupt events. * These events are picked up by rxa_intr_ring_dequeue() which is invoked from * the adapter service function. */ -static void * +static uint32_t rxa_intr_thread(void *arg) { struct event_eth_rx_adapter *rx_adapter = arg; @@ -1179,7 +1180,7 @@ rxa_intr_thread(void *arg) } } - return NULL; + return 0; } /* Dequeue <port, q> from interrupt ring and enqueue received @@ -1595,7 +1596,7 @@ static int rxa_create_intr_thread(struct event_eth_rx_adapter *rx_adapter) { int err; - char thread_name[RTE_MAX_THREAD_NAME_LEN]; + char thread_name[RTE_THREAD_INTERNAL_NAME_SIZE]; if (rx_adapter->intr_ring) return 0; @@ -1618,11 +1619,11 @@ rxa_create_intr_thread(struct event_eth_rx_adapter *rx_adapter) rte_spinlock_init(&rx_adapter->intr_ring_lock); - snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, - "dpdk-evt-rx%d", rx_adapter->id); + snprintf(thread_name, sizeof(thread_name), + "evt-rx%d", rx_adapter->id); - err = rte_ctrl_thread_create(&rx_adapter->rx_intr_thread, thread_name, - NULL, rxa_intr_thread, rx_adapter); + err = rte_thread_create_internal_control(&rx_adapter->rx_intr_thread, + thread_name, rxa_intr_thread, rx_adapter); if (!err) return 0; @@ -1640,12 +1641,12 @@ rxa_destroy_intr_thread(struct event_eth_rx_adapter *rx_adapter) { int err; - err = pthread_cancel(rx_adapter->rx_intr_thread); + err = pthread_cancel((pthread_t)rx_adapter->rx_intr_thread.opaque_id); if (err) RTE_EDEV_LOG_ERR("Can't cancel interrupt thread err = %d\n", err); - err = pthread_join(rx_adapter->rx_intr_thread, NULL); + err = rte_thread_join(rx_adapter->rx_intr_thread, NULL); if (err) RTE_EDEV_LOG_ERR("Can't join interrupt thread err = %d\n", err); diff --git a/lib/vhost/fd_man.c b/lib/vhost/fd_man.c index 1876fada33..134414fb4b 100644 --- a/lib/vhost/fd_man.c +++ b/lib/vhost/fd_man.c @@ -212,7 +212,7 @@ fdset_try_del(struct fdset *pfdset, int fd) * will wait until the flag is reset to zero(which indicates the callback is * finished), then it could free the context after fdset_del. */ -void * +uint32_t fdset_event_dispatch(void *arg) { int i; @@ -227,7 +227,7 @@ fdset_event_dispatch(void *arg) int val; if (pfdset == NULL) - return NULL; + return 0; while (1) { @@ -303,7 +303,7 @@ fdset_event_dispatch(void *arg) fdset_shrink(pfdset); } - return NULL; + return 0; } static void diff --git a/lib/vhost/fd_man.h b/lib/vhost/fd_man.h index 6f4499bdfa..6315904c8e 100644 --- a/lib/vhost/fd_man.h +++ b/lib/vhost/fd_man.h @@ -46,7 +46,7 @@ int fdset_add(struct fdset *pfdset, int fd, void *fdset_del(struct fdset *pfdset, int fd); int fdset_try_del(struct fdset *pfdset, int fd); -void *fdset_event_dispatch(void *arg); +uint32_t fdset_event_dispatch(void *arg); int fdset_pipe_init(struct fdset *fdset); diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c index 12095b0e1a..5882e44176 100644 --- a/lib/vhost/socket.c +++ b/lib/vhost/socket.c @@ -13,8 +13,8 @@ #include <sys/queue.h> #include <errno.h> #include <fcntl.h> -#include <pthread.h> +#include <rte_thread.h> #include <rte_log.h> #include "fd_man.h" @@ -431,7 +431,7 @@ struct vhost_user_reconnect_list { }; static struct vhost_user_reconnect_list reconn_list; -static pthread_t reconn_tid; +static rte_thread_t reconn_tid; static int vhost_user_connect_nonblock(char *path, int fd, struct sockaddr *un, size_t sz) @@ -455,7 +455,7 @@ vhost_user_connect_nonblock(char *path, int fd, struct sockaddr *un, size_t sz) return 0; } -static void * +static uint32_t vhost_user_client_reconnect(void *arg __rte_unused) { int ret; @@ -496,7 +496,7 @@ vhost_user_client_reconnect(void *arg __rte_unused) sleep(1); } - return NULL; + return 0; } static int @@ -511,8 +511,8 @@ vhost_user_reconnect_init(void) } TAILQ_INIT(&reconn_list.head); - ret = rte_ctrl_thread_create(&reconn_tid, "dpdk-vhost-reco", NULL, - vhost_user_client_reconnect, NULL); + ret = rte_thread_create_internal_control(&reconn_tid, "vhost-reco", + vhost_user_client_reconnect, NULL); if (ret != 0) { VHOST_LOG_CONFIG("thread", ERR, "failed to create reconnect thread\n"); if (pthread_mutex_destroy(&reconn_list.mutex)) @@ -1004,7 +1004,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags) if (!vsocket->is_vduse) { if ((flags & RTE_VHOST_USER_CLIENT) != 0) { vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT); - if (vsocket->reconnect && reconn_tid == 0) { + if (vsocket->reconnect && reconn_tid.opaque_id == 0) { if (vhost_user_reconnect_init() != 0) goto out_mutex; } @@ -1174,7 +1174,7 @@ int rte_vhost_driver_start(const char *path) { struct vhost_user_socket *vsocket; - static pthread_t fdset_tid; + static rte_thread_t fdset_tid; pthread_mutex_lock(&vhost_user.mutex); vsocket = find_vhost_user_socket(path); @@ -1186,7 +1186,7 @@ rte_vhost_driver_start(const char *path) if (vsocket->is_vduse) return vduse_device_create(path, vsocket->net_compliant_ol_flags); - if (fdset_tid == 0) { + if (fdset_tid.opaque_id == 0) { /** * create a pipe which will be waited by poll and notified to * rebuild the wait list of poll. @@ -1196,9 +1196,8 @@ rte_vhost_driver_start(const char *path) return -1; } - int ret = rte_ctrl_thread_create(&fdset_tid, - "dpdk-vhost-evt", NULL, fdset_event_dispatch, - &vhost_user.fdset); + int ret = rte_thread_create_internal_control(&fdset_tid, + "vhost-evt", fdset_event_dispatch, &vhost_user.fdset); if (ret != 0) { VHOST_LOG_CONFIG(path, ERR, "failed to create fdset handling thread\n"); fdset_pipe_uninit(&vhost_user.fdset); diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index 7770259f37..e342f53b81 100644 --- a/lib/vhost/vduse.c +++ b/lib/vhost/vduse.c @@ -16,6 +16,7 @@ #include <sys/stat.h> #include <rte_common.h> +#include <rte_thread.h> #include "fd_man.h" #include "iotlb.h" @@ -415,7 +416,7 @@ int vduse_device_create(const char *path, bool compliant_ol_flags) { int control_fd, dev_fd, vid, ret; - pthread_t fdset_tid; + rte_thread_t fdset_tid; uint32_t i, max_queue_pairs, total_queues; struct virtio_net *dev; struct virtio_net_config vnet_config = {{ 0 }}; @@ -435,7 +436,7 @@ vduse_device_create(const char *path, bool compliant_ol_flags) return -1; } - ret = rte_ctrl_thread_create(&fdset_tid, "dpdk-vduse-evt", NULL, + ret = rte_thread_create_internal_control(&fdset_tid, "vduse-evt", fdset_event_dispatch, &vduse.fdset); if (ret != 0) { VHOST_LOG_CONFIG(path, ERR, "failed to create vduse fdset handling thread\n"); -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v2 07/11] drivers: convert to internal control threads 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon ` (5 preceding siblings ...) 2023-09-13 10:34 ` [PATCH v2 06/11] lib: convert to internal control threads Thomas Monjalon @ 2023-09-13 10:34 ` Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 08/11] examples: convert to normal " Thomas Monjalon ` (3 subsequent siblings) 10 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 10:34 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Andrew Rybchenko, Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao, Chengwen Feng, Kevin Laatz, Bruce Richardson, Abdullah Sevincer, Shepard Siegel, Ed Czeck, John Miller, Jingjing Wu, Beilei Xing, Qiming Yang, Qi Zhang, Rosen Xu, Wenjun Wu, Matan Azrad, Viacheslav Ovsiienko, Ori Kam, Suanming Mou, Jiawen Wu, Jian Wang, Tianfei Zhang, Xiao Wang, Vijay Kumar Srivastava Calls to rte_ctrl_thread_create() are replaced with rte_thread_create_internal_control(). Other pthread-related functions are replaced with the rte_thread API. Only pthread_cancel() has no replacement. The mlx5 vDPA control threads were real-time threads with an affinity on the core specified by the devarg "event_core". As there is no heavy performance requirement, these threads are converted into real control threads. Some threads in dlb2 and mlx5 are not control threads because they are designed to run on some specific cores. It would be interesting to rework them in future. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru> --- drivers/common/cnxk/roc_dev.c | 16 ++-- drivers/common/cnxk/roc_dev_priv.h | 2 +- drivers/common/cnxk/roc_nix_inl_dev.c | 9 +-- drivers/common/cnxk/roc_nix_inl_priv.h | 2 +- drivers/common/cnxk/roc_platform.h | 3 +- drivers/dma/skeleton/skeleton_dmadev.c | 7 +- drivers/event/dlb2/pf/base/dlb2_osdep.h | 14 ++-- drivers/event/dlb2/pf/base/dlb2_resource.c | 39 +++++----- drivers/event/dlb2/pf/dlb2_main.h | 1 - drivers/net/ark/ark_ethdev.c | 11 ++- drivers/net/ark/ark_pktgen.c | 8 +- drivers/net/ark/ark_pktgen.h | 2 +- drivers/net/iavf/iavf_vchnl.c | 2 +- drivers/net/ice/ice_dcf_parent.c | 7 +- drivers/net/ipn3ke/ipn3ke_representor.c | 17 ++--- drivers/net/ixgbe/ixgbe_ethdev.c | 7 +- drivers/net/mlx5/mlx5.h | 2 +- drivers/net/mlx5/mlx5_hws_cnt.c | 42 ++++++----- drivers/net/sfc/sfc_mae.h | 2 +- drivers/net/sfc/sfc_mae_counter.c | 11 ++- drivers/net/txgbe/txgbe_ethdev.c | 6 +- drivers/raw/ifpga/ifpga_rawdev.c | 19 +++-- drivers/vdpa/ifc/ifcvf_vdpa.c | 86 ++++++++++------------ drivers/vdpa/mlx5/mlx5_vdpa.c | 2 +- drivers/vdpa/mlx5/mlx5_vdpa.h | 10 +-- drivers/vdpa/mlx5/mlx5_vdpa_cthread.c | 70 +++++------------- drivers/vdpa/mlx5/mlx5_vdpa_event.c | 64 +++++----------- drivers/vdpa/sfc/sfc_vdpa_ops.c | 15 ++-- drivers/vdpa/sfc/sfc_vdpa_ops.h | 3 +- 29 files changed, 203 insertions(+), 276 deletions(-) diff --git a/drivers/common/cnxk/roc_dev.c b/drivers/common/cnxk/roc_dev.c index 13d3eece47..08fd13f741 100644 --- a/drivers/common/cnxk/roc_dev.c +++ b/drivers/common/cnxk/roc_dev.c @@ -18,7 +18,7 @@ #define ROC_PCI_SRIOV_TOTAL_VF 0x0e /* Total VFs */ /* VF Mbox handler thread name */ -#define MBOX_HANDLER_NAME_MAX_LEN 25 +#define MBOX_HANDLER_NAME_MAX_LEN RTE_THREAD_INTERNAL_NAME_SIZE /* VF interrupt message pending bits - mbox or flr */ #define ROC_DEV_MBOX_PEND BIT_ULL(0) @@ -1070,7 +1070,7 @@ vf_flr_handle_msg(void *param, dev_intr_t *flr) } } -static void * +static uint32_t pf_vf_mbox_thread_main(void *arg) { struct dev *dev = arg; @@ -1114,7 +1114,7 @@ pf_vf_mbox_thread_main(void *arg) pthread_mutex_unlock(&dev->sync.mutex); - return NULL; + return 0; } static void @@ -1455,10 +1455,10 @@ dev_init(struct dev *dev, struct plt_pci_device *pci_dev) pthread_cond_init(&dev->sync.pfvf_msg_cond, NULL); pthread_mutex_init(&dev->sync.mutex, NULL); - snprintf(name, MBOX_HANDLER_NAME_MAX_LEN, "pf%d_vf_msg_hndlr", dev->pf); + snprintf(name, MBOX_HANDLER_NAME_MAX_LEN, "mbox_pf%d", dev->pf); dev->sync.start_thread = true; - rc = plt_ctrl_thread_create(&dev->sync.pfvf_msg_thread, name, NULL, - pf_vf_mbox_thread_main, dev); + rc = plt_thread_create_control(&dev->sync.pfvf_msg_thread, name, + pf_vf_mbox_thread_main, dev); if (rc != 0) { plt_err("Failed to create thread for VF mbox handling\n"); goto iounmap; @@ -1488,7 +1488,7 @@ dev_init(struct dev *dev, struct plt_pci_device *pci_dev) if (dev->sync.start_thread) { dev->sync.start_thread = false; pthread_cond_signal(&dev->sync.pfvf_msg_cond); - pthread_join(dev->sync.pfvf_msg_thread, NULL); + plt_thread_join(dev->sync.pfvf_msg_thread, NULL); pthread_mutex_destroy(&dev->sync.mutex); pthread_cond_destroy(&dev->sync.pfvf_msg_cond); } @@ -1519,7 +1519,7 @@ dev_fini(struct dev *dev, struct plt_pci_device *pci_dev) if (dev->sync.start_thread) { dev->sync.start_thread = false; pthread_cond_signal(&dev->sync.pfvf_msg_cond); - pthread_join(dev->sync.pfvf_msg_thread, NULL); + plt_thread_join(dev->sync.pfvf_msg_thread, NULL); pthread_mutex_destroy(&dev->sync.mutex); pthread_cond_destroy(&dev->sync.pfvf_msg_cond); } diff --git a/drivers/common/cnxk/roc_dev_priv.h b/drivers/common/cnxk/roc_dev_priv.h index 1f84f74ff3..c1a37aa4f0 100644 --- a/drivers/common/cnxk/roc_dev_priv.h +++ b/drivers/common/cnxk/roc_dev_priv.h @@ -73,7 +73,7 @@ dev_is_afvf(uint16_t pf_func) struct mbox_sync { bool start_thread; uint8_t msg_avail; - pthread_t pfvf_msg_thread; + rte_thread_t pfvf_msg_thread; pthread_cond_t pfvf_msg_cond; pthread_mutex_t mutex; }; diff --git a/drivers/common/cnxk/roc_nix_inl_dev.c b/drivers/common/cnxk/roc_nix_inl_dev.c index d76158e30d..7400069309 100644 --- a/drivers/common/cnxk/roc_nix_inl_dev.c +++ b/drivers/common/cnxk/roc_nix_inl_dev.c @@ -746,7 +746,7 @@ inl_outb_soft_exp_poll(struct nix_inl_dev *inl_dev, uint32_t ring_idx) } } -static void * +static uint32_t nix_inl_outb_poll_thread(void *args) { struct nix_inl_dev *inl_dev = args; @@ -816,9 +816,8 @@ nix_inl_outb_poll_thread_setup(struct nix_inl_dev *inl_dev) soft_exp_consumer_cnt = 0; soft_exp_poll_thread_exit = false; - rc = plt_ctrl_thread_create(&inl_dev->soft_exp_poll_thread, - "OUTB_SOFT_EXP_POLL_THREAD", NULL, - nix_inl_outb_poll_thread, inl_dev); + rc = plt_thread_create_control(&inl_dev->soft_exp_poll_thread, + "outb-poll", nix_inl_outb_poll_thread, inl_dev); if (rc) { plt_bitmap_free(inl_dev->soft_exp_ring_bmap); plt_free(inl_dev->soft_exp_ring_bmap_mem); @@ -1020,7 +1019,7 @@ roc_nix_inl_dev_fini(struct roc_nix_inl_dev *roc_inl_dev) if (inl_dev->set_soft_exp_poll) { soft_exp_poll_thread_exit = true; - pthread_join(inl_dev->soft_exp_poll_thread, NULL); + rte_thread_join(inl_dev->soft_exp_poll_thread, NULL); plt_bitmap_free(inl_dev->soft_exp_ring_bmap); plt_free(inl_dev->soft_exp_ring_bmap_mem); plt_free(inl_dev->sa_soft_exp_ring); diff --git a/drivers/common/cnxk/roc_nix_inl_priv.h b/drivers/common/cnxk/roc_nix_inl_priv.h index b0a8976c6b..b2b89227b1 100644 --- a/drivers/common/cnxk/roc_nix_inl_priv.h +++ b/drivers/common/cnxk/roc_nix_inl_priv.h @@ -67,7 +67,7 @@ struct nix_inl_dev { struct roc_cpt_lf cpt_lf; /* OUTB soft expiry poll thread */ - pthread_t soft_exp_poll_thread; + rte_thread_t soft_exp_poll_thread; uint32_t soft_exp_poll_freq; uint64_t *sa_soft_exp_ring; bool set_soft_exp_poll; diff --git a/drivers/common/cnxk/roc_platform.h b/drivers/common/cnxk/roc_platform.h index 08f83aba12..d8f2707a6e 100644 --- a/drivers/common/cnxk/roc_platform.h +++ b/drivers/common/cnxk/roc_platform.h @@ -134,7 +134,8 @@ #define plt_intr_disable rte_intr_disable #define plt_thread_is_intr rte_thread_is_intr #define plt_intr_callback_fn rte_intr_callback_fn -#define plt_ctrl_thread_create rte_ctrl_thread_create +#define plt_thread_create_control rte_thread_create_internal_control +#define plt_thread_join rte_thread_join #define plt_intr_efd_counter_size_get rte_intr_efd_counter_size_get #define plt_intr_efd_counter_size_set rte_intr_efd_counter_size_set diff --git a/drivers/dma/skeleton/skeleton_dmadev.c b/drivers/dma/skeleton/skeleton_dmadev.c index 4fc2319668..eabe88fada 100644 --- a/drivers/dma/skeleton/skeleton_dmadev.c +++ b/drivers/dma/skeleton/skeleton_dmadev.c @@ -100,7 +100,7 @@ static int skeldma_start(struct rte_dma_dev *dev) { struct skeldma_hw *hw = dev->data->dev_private; - char name[RTE_MAX_THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; rte_cpuset_t cpuset; int ret; @@ -127,8 +127,9 @@ skeldma_start(struct rte_dma_dev *dev) rte_mb(); - snprintf(name, sizeof(name), "dpdk-dma-skel%d", dev->data->dev_id); - ret = rte_thread_create_control(&hw->thread, name, cpucopy_thread, dev); + snprintf(name, sizeof(name), "dma-skel%d", dev->data->dev_id); + ret = rte_thread_create_internal_control(&hw->thread, name, + cpucopy_thread, dev); if (ret) { SKELDMA_LOG(ERR, "Start cpucopy thread fail!"); return -EINVAL; diff --git a/drivers/event/dlb2/pf/base/dlb2_osdep.h b/drivers/event/dlb2/pf/base/dlb2_osdep.h index 75860cca4d..06d69f39b1 100644 --- a/drivers/event/dlb2/pf/base/dlb2_osdep.h +++ b/drivers/event/dlb2/pf/base/dlb2_osdep.h @@ -8,7 +8,6 @@ #include <string.h> #include <time.h> #include <unistd.h> -#include <pthread.h> #include <rte_string_fns.h> #include <rte_cycles.h> @@ -154,7 +153,7 @@ static inline void os_fence_hcw(struct dlb2_hw *hw, u64 *pp_addr) * map and unmap requests. To prevent deadlock, this function gives other * threads a chance to grab the resource mutex and configure hardware. */ -static void *dlb2_complete_queue_map_unmap(void *__args) +static uint32_t dlb2_complete_queue_map_unmap(void *__args) { struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)__args; int ret; @@ -180,7 +179,7 @@ static void *dlb2_complete_queue_map_unmap(void *__args) rte_spinlock_unlock(&dlb2_dev->resource_mutex); - return NULL; + return 0; } @@ -194,16 +193,13 @@ static void *dlb2_complete_queue_map_unmap(void *__args) static inline void os_schedule_work(struct dlb2_hw *hw) { struct dlb2_dev *dlb2_dev; - pthread_t complete_queue_map_unmap_thread; + rte_thread_t complete_queue_map_unmap_thread; int ret; dlb2_dev = container_of(hw, struct dlb2_dev, hw); - ret = rte_ctrl_thread_create(&complete_queue_map_unmap_thread, - "dpdk-dlb-qunmap", - NULL, - dlb2_complete_queue_map_unmap, - dlb2_dev); + ret = rte_thread_create_internal_control(&complete_queue_map_unmap_thread, + "dlb-qunmap", dlb2_complete_queue_map_unmap, dlb2_dev); if (ret) DLB2_ERR(dlb2_dev, "Could not create queue complete map/unmap thread, err=%d\n", diff --git a/drivers/event/dlb2/pf/base/dlb2_resource.c b/drivers/event/dlb2/pf/base/dlb2_resource.c index dd8390a013..7ce3e3531c 100644 --- a/drivers/event/dlb2/pf/base/dlb2_resource.c +++ b/drivers/event/dlb2/pf/base/dlb2_resource.c @@ -759,18 +759,13 @@ static int dlb2_attach_ldb_queues(struct dlb2_hw *hw, } static int -dlb2_pp_profile(struct dlb2_hw *hw, int port, int cpu, bool is_ldb) +dlb2_pp_profile(struct dlb2_hw *hw, int port, bool is_ldb) { u64 cycle_start = 0ULL, cycle_end = 0ULL; struct dlb2_hcw hcw_mem[DLB2_HCW_MEM_SIZE], *hcw; void __iomem *pp_addr; - cpu_set_t cpuset; int i; - CPU_ZERO(&cpuset); - CPU_SET(cpu, &cpuset); - sched_setaffinity(0, sizeof(cpuset), &cpuset); - pp_addr = os_map_producer_port(hw, port, is_ldb); /* Point hcw to a 64B-aligned location */ @@ -797,18 +792,15 @@ dlb2_pp_profile(struct dlb2_hw *hw, int port, int cpu, bool is_ldb) return (int)(cycle_end - cycle_start); } -static void * +static uint32_t dlb2_pp_profile_func(void *data) { struct dlb2_pp_thread_data *thread_data = data; - int cycles; - cycles = dlb2_pp_profile(thread_data->hw, thread_data->pp, - thread_data->cpu, thread_data->is_ldb); + thread_data->cycles = dlb2_pp_profile(thread_data->hw, + thread_data->pp, thread_data->is_ldb); - thread_data->cycles = cycles; - - return NULL; + return 0; } static int dlb2_pp_cycle_comp(const void *a, const void *b) @@ -831,7 +823,9 @@ dlb2_get_pp_allocation(struct dlb2_hw *hw, int cpu, int port_type) int num_ports_per_sort, num_ports, num_sort, i, err; bool is_ldb = (port_type == DLB2_LDB_PORT); int *port_allocations; - pthread_t pthread; + rte_thread_t thread; + rte_thread_attr_t th_attr; + char th_name[RTE_THREAD_INTERNAL_NAME_SIZE]; if (is_ldb) { port_allocations = hw->ldb_pp_allocations; @@ -857,16 +851,25 @@ dlb2_get_pp_allocation(struct dlb2_hw *hw, int cpu, int port_type) dlb2_thread_data[i].pp = i; dlb2_thread_data[i].cycles = 0; dlb2_thread_data[i].hw = hw; - dlb2_thread_data[i].cpu = cpu; - err = pthread_create(&pthread, NULL, &dlb2_pp_profile_func, - &dlb2_thread_data[i]); + err = rte_thread_attr_init(&th_attr); + if (err != 0) { + DLB2_LOG_ERR(": thread attribute failed! err=%d", err); + return; + } + CPU_SET(cpu, &th_attr.cpuset); + + err = rte_thread_create(&thread, &th_attr, + &dlb2_pp_profile_func, &dlb2_thread_data[i]); if (err) { DLB2_LOG_ERR(": thread creation failed! err=%d", err); return; } - err = pthread_join(pthread, NULL); + snprintf(th_name, sizeof(th_name), "dlb2-pp%d", cpu); + rte_thread_set_prefixed_name(thread, th_name); + + err = rte_thread_join(thread, NULL); if (err) { DLB2_LOG_ERR(": thread join failed! err=%d", err); return; diff --git a/drivers/event/dlb2/pf/dlb2_main.h b/drivers/event/dlb2/pf/dlb2_main.h index 4c64d72e9c..12912a2dec 100644 --- a/drivers/event/dlb2/pf/dlb2_main.h +++ b/drivers/event/dlb2/pf/dlb2_main.h @@ -52,7 +52,6 @@ struct dlb2_dev { struct dlb2_pp_thread_data { struct dlb2_hw *hw; int pp; - int cpu; bool is_ldb; int cycles; }; diff --git a/drivers/net/ark/ark_ethdev.c b/drivers/net/ark/ark_ethdev.c index 30814650bf..3ddcc9b461 100644 --- a/drivers/net/ark/ark_ethdev.c +++ b/drivers/net/ark/ark_ethdev.c @@ -598,17 +598,16 @@ eth_ark_dev_start(struct rte_eth_dev *dev) ark_pktchkr_run(ark->pc); if (!ark->isvf && ark->start_pg && !ark->pg_running) { - pthread_t thread; + rte_thread_t thread; /* Delay packet generator start allow the hardware to be ready * This is only used for sanity checking with internal generator */ - char tname[32]; - snprintf(tname, sizeof(tname), "dpdk-ark-pg%d", - dev->data->port_id); + char tname[RTE_THREAD_INTERNAL_NAME_SIZE]; + snprintf(tname, sizeof(tname), "ark-pg%d", dev->data->port_id); - if (rte_ctrl_thread_create(&thread, tname, NULL, - ark_pktgen_delay_start, ark->pg)) { + if (rte_thread_create_internal_control(&thread, tname, + ark_pktgen_delay_start, ark->pg)) { ARK_PMD_LOG(ERR, "Could not create pktgen " "starter thread\n"); return -1; diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c index cd2d3adc51..69ff7072b2 100644 --- a/drivers/net/ark/ark_pktgen.c +++ b/drivers/net/ark/ark_pktgen.c @@ -4,10 +4,10 @@ #include <stdlib.h> #include <unistd.h> -#include <pthread.h> #include <rte_string_fns.h> #include <rte_malloc.h> +#include <rte_thread.h> #include "ark_pktgen.h" #include "ark_logs.h" @@ -467,7 +467,7 @@ ark_pktgen_setup(ark_pkt_gen_t handle) } } -void * +uint32_t ark_pktgen_delay_start(void *arg) { struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)arg; @@ -476,8 +476,8 @@ ark_pktgen_delay_start(void *arg) * perform a blind sleep here to ensure that the external test * application has time to setup the test before we generate packets */ - pthread_detach(pthread_self()); + rte_thread_detach(rte_thread_self()); usleep(100000); ark_pktgen_run(inst); - return NULL; + return 0; } diff --git a/drivers/net/ark/ark_pktgen.h b/drivers/net/ark/ark_pktgen.h index 7147fe1bd4..925058367c 100644 --- a/drivers/net/ark/ark_pktgen.h +++ b/drivers/net/ark/ark_pktgen.h @@ -75,6 +75,6 @@ void ark_pktgen_set_hdr_dW(ark_pkt_gen_t handle, uint32_t *hdr); void ark_pktgen_set_start_offset(ark_pkt_gen_t handle, uint32_t x); void ark_pktgen_parse(char *argv); void ark_pktgen_setup(ark_pkt_gen_t handle); -void *ark_pktgen_delay_start(void *arg); +uint32_t ark_pktgen_delay_start(void *arg); #endif diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c index 6baa6d5955..b3e106b41f 100644 --- a/drivers/net/iavf/iavf_vchnl.c +++ b/drivers/net/iavf/iavf_vchnl.c @@ -135,7 +135,7 @@ iavf_dev_event_handler_init(void) TAILQ_INIT(&handler->pending); pthread_mutex_init(&handler->lock, NULL); - if (rte_thread_create_control(&handler->tid, "dpdk-iavf-event", + if (rte_thread_create_internal_control(&handler->tid, "iavf-event", iavf_dev_event_handle, NULL)) { __atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED); return -1; diff --git a/drivers/net/ice/ice_dcf_parent.c b/drivers/net/ice/ice_dcf_parent.c index d3bb65874f..173ed9f81d 100644 --- a/drivers/net/ice/ice_dcf_parent.c +++ b/drivers/net/ice/ice_dcf_parent.c @@ -165,9 +165,8 @@ ice_dcf_vsi_update_service_handler(void *param) static void start_vsi_reset_thread(struct ice_dcf_hw *dcf_hw, bool vfr, uint16_t vf_id) { -#define THREAD_NAME_LEN 16 struct ice_dcf_reset_event_param *param; - char name[THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; rte_thread_t thread; int ret; @@ -181,8 +180,8 @@ start_vsi_reset_thread(struct ice_dcf_hw *dcf_hw, bool vfr, uint16_t vf_id) param->vfr = vfr; param->vf_id = vf_id; - snprintf(name, sizeof(name), "dpdk-ice-rst%u", vf_id); - ret = rte_thread_create_control(&thread, name, + snprintf(name, sizeof(name), "ice-rst%u", vf_id); + ret = rte_thread_create_internal_control(&thread, name, ice_dcf_vsi_update_service_handler, param); if (ret != 0) { PMD_DRV_LOG(ERR, "Failed to start the thread for reset handling"); diff --git a/drivers/net/ipn3ke/ipn3ke_representor.c b/drivers/net/ipn3ke/ipn3ke_representor.c index c82f8b5333..57ec7a19bc 100644 --- a/drivers/net/ipn3ke/ipn3ke_representor.c +++ b/drivers/net/ipn3ke/ipn3ke_representor.c @@ -27,7 +27,7 @@ #include "ipn3ke_ethdev.h" static int ipn3ke_rpst_scan_num; -static pthread_t ipn3ke_rpst_scan_thread; +static rte_thread_t ipn3ke_rpst_scan_thread; /** Double linked list of representor port. */ TAILQ_HEAD(ipn3ke_rpst_list, ipn3ke_rpst); @@ -2558,7 +2558,7 @@ ipn3ke_rpst_link_check(struct ipn3ke_rpst *rpst) return 0; } -static void * +static uint32_t ipn3ke_rpst_scan_handle_request(__rte_unused void *param) { struct ipn3ke_rpst *rpst; @@ -2580,10 +2580,10 @@ ipn3ke_rpst_scan_handle_request(__rte_unused void *param) rte_delay_us(50 * MS); if (num == 0 || num == 0xffffff) - return NULL; + return 0; } - return NULL; + return 0; } static int @@ -2592,20 +2592,19 @@ ipn3ke_rpst_scan_check(void) int ret; if (ipn3ke_rpst_scan_num == 1) { - ret = rte_ctrl_thread_create(&ipn3ke_rpst_scan_thread, - "dpdk-ipn3ke-scn", - NULL, + ret = rte_thread_create_internal_control(&ipn3ke_rpst_scan_thread, + "ipn3ke-scn", ipn3ke_rpst_scan_handle_request, NULL); if (ret) { IPN3KE_AFU_PMD_ERR("Fail to create ipn3ke rpst scan thread"); return -1; } } else if (ipn3ke_rpst_scan_num == 0) { - ret = pthread_cancel(ipn3ke_rpst_scan_thread); + ret = pthread_cancel((pthread_t)ipn3ke_rpst_scan_thread.opaque_id); if (ret) IPN3KE_AFU_PMD_ERR("Can't cancel the thread"); - ret = pthread_join(ipn3ke_rpst_scan_thread, NULL); + ret = rte_thread_join(ipn3ke_rpst_scan_thread, NULL); if (ret) IPN3KE_AFU_PMD_ERR("Can't join the thread"); diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c index 64e7e5d7d6..cd4a85b3a7 100644 --- a/drivers/net/ixgbe/ixgbe_ethdev.c +++ b/drivers/net/ixgbe/ixgbe_ethdev.c @@ -4328,10 +4328,9 @@ ixgbe_dev_link_update_share(struct rte_eth_dev *dev, * when there is no link thread running. */ intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; - if (rte_thread_create_control(&ad->link_thread_tid, - "dpdk-ixgbe-link", - ixgbe_dev_setup_link_thread_handler, - dev) < 0) { + if (rte_thread_create_internal_control(&ad->link_thread_tid, + "ixgbe-link", + ixgbe_dev_setup_link_thread_handler, dev) < 0) { PMD_DRV_LOG(ERR, "Create link thread failed!"); /* NOTE: review for potential ordering optimization */ diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 3785103308..c587e13c63 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1368,7 +1368,7 @@ struct mlx5_hws_cnt_svc_mng { uint32_t refcnt; uint32_t service_core; uint32_t query_interval; - pthread_t service_thread; + rte_thread_t service_thread; uint8_t svc_running; struct mlx5_hws_aso_mng aso_mng __rte_cache_aligned; }; diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c index a0f0febbc7..f556a9fbcc 100644 --- a/drivers/net/mlx5/mlx5_hws_cnt.c +++ b/drivers/net/mlx5/mlx5_hws_cnt.c @@ -9,6 +9,7 @@ #include <mlx5_devx_cmds.h> #include <rte_cycles.h> #include <rte_eal_paging.h> +#include <rte_thread.h> #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) @@ -286,7 +287,7 @@ mlx5_hws_cnt_raw_data_alloc(struct mlx5_dev_ctx_shared *sh, uint32_t n) return NULL; } -static void * +static uint32_t mlx5_hws_cnt_svc(void *opaque) { struct mlx5_dev_ctx_shared *sh = @@ -318,7 +319,7 @@ mlx5_hws_cnt_svc(void *opaque) if (interval > query_us) rte_delay_us_sleep(sleep_us); } - return NULL; + return 0; } static void @@ -438,36 +439,37 @@ mlx5_hws_cnt_pool_init(struct mlx5_dev_ctx_shared *sh, int mlx5_hws_cnt_service_thread_create(struct mlx5_dev_ctx_shared *sh) { - char name[RTE_MAX_THREAD_NAME_LEN]; - rte_cpuset_t cpuset; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; + rte_thread_attr_t attr; int ret; uint32_t service_core = sh->cnt_svc->service_core; - CPU_ZERO(&cpuset); + ret = rte_thread_attr_init(&attr); + if (ret != 0) + goto error; + CPU_SET(service_core, &attr.cpuset); sh->cnt_svc->svc_running = 1; - ret = pthread_create(&sh->cnt_svc->service_thread, NULL, - mlx5_hws_cnt_svc, sh); - if (ret != 0) { - DRV_LOG(ERR, "Failed to create HW steering's counter service thread."); - return -ENOSYS; - } - snprintf(name, RTE_MAX_THREAD_NAME_LEN, "dpdk-mlx5-%d", service_core); - rte_thread_set_name((rte_thread_t){(uintptr_t)sh->cnt_svc->service_thread}, - name); - CPU_SET(service_core, &cpuset); - pthread_setaffinity_np(sh->cnt_svc->service_thread, sizeof(cpuset), - &cpuset); + ret = rte_thread_create(&sh->cnt_svc->service_thread, + &attr, mlx5_hws_cnt_svc, sh); + if (ret != 0) + goto error; + snprintf(name, sizeof(name), "mlx5-cn%d", service_core); + rte_thread_set_prefixed_name(sh->cnt_svc->service_thread, name); + return 0; +error: + DRV_LOG(ERR, "Failed to create HW steering's counter service thread."); + return ret; } void mlx5_hws_cnt_service_thread_destroy(struct mlx5_dev_ctx_shared *sh) { - if (sh->cnt_svc->service_thread == 0) + if (sh->cnt_svc->service_thread.opaque_id == 0) return; sh->cnt_svc->svc_running = 0; - pthread_join(sh->cnt_svc->service_thread, NULL); - sh->cnt_svc->service_thread = 0; + rte_thread_join(sh->cnt_svc->service_thread, NULL); + sh->cnt_svc->service_thread.opaque_id = 0; } static int diff --git a/drivers/net/sfc/sfc_mae.h b/drivers/net/sfc/sfc_mae.h index 646d055ac1..7988424449 100644 --- a/drivers/net/sfc/sfc_mae.h +++ b/drivers/net/sfc/sfc_mae.h @@ -196,7 +196,7 @@ struct sfc_mae_counter_registry { } service; struct { /** Counter thread ID */ - pthread_t id; + rte_thread_t id; /** The thread should keep running */ bool run; } thread; diff --git a/drivers/net/sfc/sfc_mae_counter.c b/drivers/net/sfc/sfc_mae_counter.c index 631b54afeb..ba17295719 100644 --- a/drivers/net/sfc/sfc_mae_counter.c +++ b/drivers/net/sfc/sfc_mae_counter.c @@ -490,7 +490,7 @@ sfc_mae_counter_service_routine(void *arg) return 0; } -static void * +static uint32_t sfc_mae_counter_thread(void *data) { struct sfc_adapter *sa = data; @@ -521,7 +521,7 @@ sfc_mae_counter_thread(void *data) } } - return NULL; + return 0; } static void @@ -687,7 +687,7 @@ sfc_mae_counter_thread_stop(struct sfc_adapter *sa) __atomic_store_n(&counter_registry->polling.thread.run, false, __ATOMIC_RELEASE); - rc = pthread_join(counter_registry->polling.thread.id, NULL); + rc = rte_thread_join(counter_registry->polling.thread.id, NULL); if (rc != 0) sfc_err(sa, "failed to join the MAE counter polling thread"); @@ -710,9 +710,8 @@ sfc_mae_counter_thread_spawn(struct sfc_adapter *sa, counter_registry->polling_mode = SFC_MAE_COUNTER_POLLING_THREAD; counter_registry->polling.thread.run = true; - rc = rte_ctrl_thread_create(&sa->mae.counter_registry.polling.thread.id, - "dpdk-sfc-maecnt", NULL, - sfc_mae_counter_thread, sa); + rc = rte_thread_create_internal_control(&sa->mae.counter_registry.polling.thread.id, + "sfc-maecnt", sfc_mae_counter_thread, sa); return rc; } diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c index 198fac8318..15911a3621 100644 --- a/drivers/net/txgbe/txgbe_ethdev.c +++ b/drivers/net/txgbe/txgbe_ethdev.c @@ -2896,9 +2896,9 @@ txgbe_dev_link_update_share(struct rte_eth_dev *dev, * when there is no link thread running. */ intr->flags |= TXGBE_FLAG_NEED_LINK_CONFIG; - if (rte_thread_create_control(&ad->link_thread_tid, - "dpdk-txgbe-link", - txgbe_dev_setup_link_thread_handler, dev) < 0) { + if (rte_thread_create_internal_control(&ad->link_thread_tid, + "txgbe-link", + txgbe_dev_setup_link_thread_handler, dev) < 0) { PMD_DRV_LOG(ERR, "Create link thread failed!"); __atomic_clear(&ad->link_thread_running, __ATOMIC_SEQ_CST); } diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c index a7b18299de..f89bd3f9e2 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.c +++ b/drivers/raw/ifpga/ifpga_rawdev.c @@ -74,7 +74,7 @@ static const struct rte_pci_id pci_ifpga_map[] = { static struct ifpga_rawdev ifpga_rawdevices[IFPGA_RAWDEV_NUM]; static int ifpga_monitor_refcnt; -static pthread_t ifpga_monitor_start_thread; +static rte_thread_t ifpga_monitor_start_thread; static struct ifpga_rawdev * ifpga_rawdev_allocate(struct rte_rawdev *rawdev); @@ -504,7 +504,7 @@ static int set_surprise_link_check_aer( return -EFAULT; } -static void * +static uint32_t ifpga_rawdev_gsd_handle(__rte_unused void *param) { struct ifpga_rawdev *ifpga_rdev; @@ -532,7 +532,7 @@ ifpga_rawdev_gsd_handle(__rte_unused void *param) rte_delay_us(100 * MS); } - return NULL; + return 0; } static int @@ -550,11 +550,10 @@ ifpga_monitor_start_func(struct ifpga_rawdev *dev) dev->poll_enabled = 1; if (!__atomic_fetch_add(&ifpga_monitor_refcnt, 1, __ATOMIC_RELAXED)) { - ret = rte_ctrl_thread_create(&ifpga_monitor_start_thread, - "dpdk-ifpga-mon", NULL, - ifpga_rawdev_gsd_handle, NULL); + ret = rte_thread_create_internal_control(&ifpga_monitor_start_thread, + "ifpga-mon", ifpga_rawdev_gsd_handle, NULL); if (ret != 0) { - ifpga_monitor_start_thread = 0; + ifpga_monitor_start_thread.opaque_id = 0; IFPGA_RAWDEV_PMD_ERR( "Fail to create ifpga monitor thread"); return -1; @@ -575,12 +574,12 @@ ifpga_monitor_stop_func(struct ifpga_rawdev *dev) dev->poll_enabled = 0; if (!(__atomic_fetch_sub(&ifpga_monitor_refcnt, 1, __ATOMIC_RELAXED) - 1) && - ifpga_monitor_start_thread) { - ret = pthread_cancel(ifpga_monitor_start_thread); + ifpga_monitor_start_thread.opaque_id != 0) { + ret = pthread_cancel((pthread_t)ifpga_monitor_start_thread.opaque_id); if (ret) IFPGA_RAWDEV_PMD_ERR("Can't cancel the thread"); - ret = pthread_join(ifpga_monitor_start_thread, NULL); + ret = rte_thread_join(ifpga_monitor_start_thread, NULL); if (ret) IFPGA_RAWDEV_PMD_ERR("Can't join the thread"); diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c index 55346bbc08..f034bd59ba 100644 --- a/drivers/vdpa/ifc/ifcvf_vdpa.c +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c @@ -58,8 +58,8 @@ struct ifcvf_internal { int vfio_container_fd; int vfio_group_fd; int vfio_dev_fd; - pthread_t tid; /* thread for notify relay */ - pthread_t intr_tid; /* thread for config space change interrupt relay */ + rte_thread_t tid; /* thread for notify relay */ + rte_thread_t intr_tid; /* thread for config space change interrupt relay */ int epfd; int csc_epfd; int vid; @@ -496,7 +496,7 @@ vdpa_disable_vfio_intr(struct ifcvf_internal *internal) return 0; } -static void * +static uint32_t notify_relay(void *arg) { int i, kickfd, epfd, nfds = 0; @@ -514,7 +514,7 @@ notify_relay(void *arg) epfd = epoll_create(IFCVF_MAX_QUEUES * 2); if (epfd < 0) { DRV_LOG(ERR, "failed to create epoll instance."); - return NULL; + return 1; } internal->epfd = epfd; @@ -527,7 +527,7 @@ notify_relay(void *arg) ev.data.u64 = qid | (uint64_t)vring.kickfd << 32; if (epoll_ctl(epfd, EPOLL_CTL_ADD, vring.kickfd, &ev) < 0) { DRV_LOG(ERR, "epoll add error: %s", strerror(errno)); - return NULL; + return 1; } } @@ -537,7 +537,7 @@ notify_relay(void *arg) if (errno == EINTR) continue; DRV_LOG(ERR, "epoll_wait return fail\n"); - return NULL; + return 1; } for (i = 0; i < nfds; i++) { @@ -561,18 +561,18 @@ notify_relay(void *arg) } } - return NULL; + return 0; } static int setup_notify_relay(struct ifcvf_internal *internal) { - char name[THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; int ret; - snprintf(name, sizeof(name), "dpdk-ifc-noti%d", internal->vid); - ret = rte_ctrl_thread_create(&internal->tid, name, NULL, notify_relay, - (void *)internal); + snprintf(name, sizeof(name), "ifc-noti%d", internal->vid); + ret = rte_thread_create_internal_control(&internal->tid, name, + notify_relay, internal); if (ret != 0) { DRV_LOG(ERR, "failed to create notify relay pthread."); return -1; @@ -584,13 +584,11 @@ setup_notify_relay(struct ifcvf_internal *internal) static int unset_notify_relay(struct ifcvf_internal *internal) { - void *status; - - if (internal->tid) { - pthread_cancel(internal->tid); - pthread_join(internal->tid, &status); + if (internal->tid.opaque_id != 0) { + pthread_cancel((pthread_t)internal->tid.opaque_id); + rte_thread_join(internal->tid, NULL); } - internal->tid = 0; + internal->tid.opaque_id = 0; if (internal->epfd >= 0) close(internal->epfd); @@ -610,7 +608,7 @@ virtio_interrupt_handler(struct ifcvf_internal *internal) DRV_LOG(ERR, "failed to notify the guest about configuration space change."); } -static void * +static uint32_t intr_relay(void *arg) { struct ifcvf_internal *internal = (struct ifcvf_internal *)arg; @@ -623,7 +621,7 @@ intr_relay(void *arg) csc_epfd = epoll_create(1); if (csc_epfd < 0) { DRV_LOG(ERR, "failed to create epoll for config space change."); - return NULL; + return 1; } ev.events = EPOLLIN | EPOLLPRI | EPOLLRDHUP | EPOLLHUP; @@ -672,18 +670,18 @@ intr_relay(void *arg) close(csc_epfd); internal->csc_epfd = -1; - return NULL; + return 0; } static int setup_intr_relay(struct ifcvf_internal *internal) { - char name[THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; int ret; - snprintf(name, sizeof(name), "dpdk-ifc-int%d", internal->vid); - ret = rte_ctrl_thread_create(&internal->intr_tid, name, NULL, - intr_relay, (void *)internal); + snprintf(name, sizeof(name), "ifc-int%d", internal->vid); + ret = rte_thread_create_internal_control(&internal->intr_tid, name, + intr_relay, (void *)internal); if (ret) { DRV_LOG(ERR, "failed to create notify relay pthread."); return -1; @@ -694,13 +692,11 @@ setup_intr_relay(struct ifcvf_internal *internal) static void unset_intr_relay(struct ifcvf_internal *internal) { - void *status; - - if (internal->intr_tid) { - pthread_cancel(internal->intr_tid); - pthread_join(internal->intr_tid, &status); + if (internal->intr_tid.opaque_id != 0) { + pthread_cancel((pthread_t)internal->intr_tid.opaque_id); + rte_thread_join(internal->intr_tid, NULL); } - internal->intr_tid = 0; + internal->intr_tid.opaque_id = 0; if (internal->csc_epfd >= 0) close(internal->csc_epfd); @@ -922,7 +918,7 @@ update_used_ring(struct ifcvf_internal *internal, uint16_t qid) rte_vhost_vring_call(internal->vid, qid); } -static void * +static uint32_t vring_relay(void *arg) { int i, vid, epfd, fd, nfds; @@ -941,7 +937,7 @@ vring_relay(void *arg) epfd = epoll_create(IFCVF_MAX_QUEUES * 2); if (epfd < 0) { DRV_LOG(ERR, "failed to create epoll instance."); - return NULL; + return 1; } internal->epfd = epfd; @@ -952,7 +948,7 @@ vring_relay(void *arg) ev.data.u64 = qid << 1 | (uint64_t)vring.kickfd << 32; if (epoll_ctl(epfd, EPOLL_CTL_ADD, vring.kickfd, &ev) < 0) { DRV_LOG(ERR, "epoll add error: %s", strerror(errno)); - return NULL; + return 1; } } @@ -966,7 +962,7 @@ vring_relay(void *arg) if (epoll_ctl(epfd, EPOLL_CTL_ADD, internal->intr_fd[qid], &ev) < 0) { DRV_LOG(ERR, "epoll add error: %s", strerror(errno)); - return NULL; + return 1; } update_used_ring(internal, qid); } @@ -982,7 +978,7 @@ vring_relay(void *arg) if (errno == EINTR) continue; DRV_LOG(ERR, "epoll_wait return fail."); - return NULL; + return 1; } for (i = 0; i < nfds; i++) { @@ -1010,18 +1006,18 @@ vring_relay(void *arg) } } - return NULL; + return 0; } static int setup_vring_relay(struct ifcvf_internal *internal) { - char name[THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; int ret; - snprintf(name, sizeof(name), "dpdk-ifc-ring%d", internal->vid); - ret = rte_ctrl_thread_create(&internal->tid, name, NULL, vring_relay, - (void *)internal); + snprintf(name, sizeof(name), "ifc-ring%d", internal->vid); + ret = rte_thread_create_internal_control(&internal->tid, name, + vring_relay, internal); if (ret != 0) { DRV_LOG(ERR, "failed to create ring relay pthread."); return -1; @@ -1033,13 +1029,11 @@ setup_vring_relay(struct ifcvf_internal *internal) static int unset_vring_relay(struct ifcvf_internal *internal) { - void *status; - - if (internal->tid) { - pthread_cancel(internal->tid); - pthread_join(internal->tid, &status); + if (internal->tid.opaque_id != 0) { + pthread_cancel((pthread_t)internal->tid.opaque_id); + rte_thread_join(internal->tid, NULL); } - internal->tid = 0; + internal->tid.opaque_id = 0; if (internal->epfd >= 0) close(internal->epfd); diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c index f1737f82a8..01a5877d08 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c @@ -844,7 +844,7 @@ mlx5_vdpa_dev_probe(struct mlx5_common_device *cdev, mlx5_vdpa_config_get(mkvlist, priv); if (priv->use_c_thread) { if (conf_thread_mng.initializer_priv == priv) - if (mlx5_vdpa_mult_threads_create(priv->event_core)) + if (mlx5_vdpa_mult_threads_create()) goto error; __atomic_fetch_add(&conf_thread_mng.refcnt, 1, __ATOMIC_RELAXED); diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h index dc4dfba5ed..7b37c98e74 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/mlx5_vdpa.h @@ -19,6 +19,7 @@ #endif #include <rte_spinlock.h> #include <rte_interrupts.h> +#include <rte_thread.h> #include <mlx5_glue.h> #include <mlx5_devx_cmds.h> @@ -99,7 +100,7 @@ struct mlx5_vdpa_task { /* Generic mlx5_vdpa_c_thread information. */ struct mlx5_vdpa_c_thread { - pthread_t tid; + rte_thread_t tid; struct rte_ring *rng; pthread_cond_t c_cond; }; @@ -182,7 +183,7 @@ struct mlx5_vdpa_priv { rte_spinlock_t db_lock; pthread_mutex_t steer_update_lock; uint64_t no_traffic_counter; - pthread_t timer_tid; + rte_thread_t timer_tid; int event_mode; int event_core; /* Event thread cpu affinity core. */ uint32_t event_us; @@ -563,14 +564,11 @@ mlx5_vdpa_is_modify_virtq_supported(struct mlx5_vdpa_priv *priv); /** * Create configuration multi-threads resource * - * @param[in] cpu_core - * CPU core number to set configuration threads affinity to. - * * @return * 0 on success, a negative value otherwise. */ int -mlx5_vdpa_mult_threads_create(int cpu_core); +mlx5_vdpa_mult_threads_create(void); /** * Destroy configuration multi-threads resource diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_cthread.c b/drivers/vdpa/mlx5/mlx5_vdpa_cthread.c index a1d291bf71..1a5fd3eb17 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa_cthread.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa_cthread.c @@ -96,11 +96,10 @@ mlx5_vdpa_c_thread_wait_bulk_tasks_done(uint32_t *remaining_cnt, return false; } -static void * +static uint32_t mlx5_vdpa_c_thread_handle(void *arg) { struct mlx5_vdpa_conf_thread_mng *multhrd = arg; - pthread_t thread_id = pthread_self(); struct mlx5_vdpa_virtq *virtq; struct mlx5_vdpa_priv *priv; struct mlx5_vdpa_task task; @@ -112,10 +111,10 @@ mlx5_vdpa_c_thread_handle(void *arg) for (thrd_idx = 0; thrd_idx < multhrd->max_thrds; thrd_idx++) - if (multhrd->cthrd[thrd_idx].tid == thread_id) + if (rte_thread_equal(multhrd->cthrd[thrd_idx].tid, rte_thread_self())) break; if (thrd_idx >= multhrd->max_thrds) - return NULL; + return 1; rng = multhrd->cthrd[thrd_idx].rng; while (1) { task_num = mlx5_vdpa_c_thrd_ring_dequeue_bulk(rng, @@ -227,16 +226,17 @@ mlx5_vdpa_c_thread_handle(void *arg) __atomic_fetch_sub(task.remaining_cnt, 1, __ATOMIC_RELAXED); } - return NULL; + return 0; } static void mlx5_vdpa_c_thread_destroy(uint32_t thrd_idx, bool need_unlock) { - if (conf_thread_mng.cthrd[thrd_idx].tid) { - pthread_cancel(conf_thread_mng.cthrd[thrd_idx].tid); - pthread_join(conf_thread_mng.cthrd[thrd_idx].tid, NULL); - conf_thread_mng.cthrd[thrd_idx].tid = 0; + pthread_t *tid = (pthread_t *)&conf_thread_mng.cthrd[thrd_idx].tid.opaque_id; + if (*tid != 0) { + pthread_cancel(*tid); + rte_thread_join(conf_thread_mng.cthrd[thrd_idx].tid, NULL); + *tid = 0; if (need_unlock) pthread_mutex_init(&conf_thread_mng.cthrd_lock, NULL); } @@ -247,30 +247,14 @@ mlx5_vdpa_c_thread_destroy(uint32_t thrd_idx, bool need_unlock) } static int -mlx5_vdpa_c_thread_create(int cpu_core) +mlx5_vdpa_c_thread_create(void) { - const struct sched_param sp = { - .sched_priority = sched_get_priority_max(SCHED_RR), - }; - rte_cpuset_t cpuset; - pthread_attr_t attr; uint32_t thrd_idx; uint32_t ring_num; - char name[32]; + char name[RTE_RING_NAMESIZE]; int ret; pthread_mutex_lock(&conf_thread_mng.cthrd_lock); - pthread_attr_init(&attr); - ret = pthread_attr_setschedpolicy(&attr, SCHED_RR); - if (ret) { - DRV_LOG(ERR, "Failed to set thread sched policy = RR."); - goto c_thread_err; - } - ret = pthread_attr_setschedparam(&attr, &sp); - if (ret) { - DRV_LOG(ERR, "Failed to set thread priority."); - goto c_thread_err; - } ring_num = MLX5_VDPA_MAX_TASKS_PER_THRD / conf_thread_mng.max_thrds; if (!ring_num) { DRV_LOG(ERR, "Invalid ring number for thread."); @@ -291,35 +275,15 @@ mlx5_vdpa_c_thread_create(int cpu_core) thrd_idx); goto c_thread_err; } - ret = pthread_create(&conf_thread_mng.cthrd[thrd_idx].tid, - &attr, mlx5_vdpa_c_thread_handle, - (void *)&conf_thread_mng); + snprintf(name, RTE_THREAD_INTERNAL_NAME_SIZE, "vmlx5-c%d", thrd_idx); + ret = rte_thread_create_internal_control(&conf_thread_mng.cthrd[thrd_idx].tid, + name, + mlx5_vdpa_c_thread_handle, &conf_thread_mng); if (ret) { DRV_LOG(ERR, "Failed to create vdpa multi-threads %d.", thrd_idx); goto c_thread_err; } - CPU_ZERO(&cpuset); - if (cpu_core != -1) - CPU_SET(cpu_core, &cpuset); - else - cpuset = rte_lcore_cpuset(rte_get_main_lcore()); - ret = pthread_setaffinity_np( - conf_thread_mng.cthrd[thrd_idx].tid, - sizeof(cpuset), &cpuset); - if (ret) { - DRV_LOG(ERR, "Failed to set thread affinity for " - "vdpa multi-threads %d.", thrd_idx); - goto c_thread_err; - } - snprintf(name, sizeof(name), "dpdk-vmlx5-c%d", thrd_idx); - ret = pthread_setname_np( - conf_thread_mng.cthrd[thrd_idx].tid, name); - if (ret) - DRV_LOG(ERR, "Failed to set vdpa multi-threads name %s.", - name); - else - DRV_LOG(DEBUG, "Thread name: %s.", name); pthread_cond_init(&conf_thread_mng.cthrd[thrd_idx].c_cond, NULL); } @@ -334,10 +298,10 @@ mlx5_vdpa_c_thread_create(int cpu_core) } int -mlx5_vdpa_mult_threads_create(int cpu_core) +mlx5_vdpa_mult_threads_create(void) { pthread_mutex_init(&conf_thread_mng.cthrd_lock, NULL); - if (mlx5_vdpa_c_thread_create(cpu_core)) { + if (mlx5_vdpa_c_thread_create()) { DRV_LOG(ERR, "Cannot create vDPA configuration threads."); mlx5_vdpa_mult_threads_destroy(false); return -1; diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c index c486ded598..fa26471b18 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c @@ -284,7 +284,7 @@ mlx5_vdpa_event_wait(struct mlx5_vdpa_priv *priv __rte_unused) return NULL; } -static void * +static uint32_t mlx5_vdpa_event_handle(void *arg) { struct mlx5_vdpa_priv *priv = arg; @@ -324,7 +324,7 @@ mlx5_vdpa_event_handle(void *arg) } mlx5_vdpa_timer_sleep(priv, max); } - return NULL; + return 0; case MLX5_VDPA_EVENT_MODE_ONLY_INTERRUPT: do { virtq = mlx5_vdpa_event_wait(priv); @@ -336,9 +336,9 @@ mlx5_vdpa_event_handle(void *arg) pthread_mutex_unlock(&virtq->virtq_lock); } } while (1); - return NULL; + return 0; default: - return NULL; + return 0; } } @@ -503,54 +503,31 @@ int mlx5_vdpa_cqe_event_setup(struct mlx5_vdpa_priv *priv) { int ret; - rte_cpuset_t cpuset; - pthread_attr_t *attrp = NULL; - pthread_attr_t attr; - char name[16]; - const struct sched_param sp = { - .sched_priority = sched_get_priority_max(SCHED_RR) - 1, - }; + rte_thread_attr_t attr; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; if (!priv->eventc) /* All virtqs are in poll mode. */ return 0; - ret = pthread_attr_init(&attr); + ret = rte_thread_attr_init(&attr); if (ret != 0) { DRV_LOG(ERR, "Failed to initialize thread attributes"); goto out; } - attrp = &attr; - ret = pthread_attr_setschedpolicy(attrp, SCHED_RR); - if (ret) { - DRV_LOG(ERR, "Failed to set thread sched policy = RR."); - goto out; - } - ret = pthread_attr_setschedparam(attrp, &sp); - if (ret) { - DRV_LOG(ERR, "Failed to set thread priority."); - goto out; - } - ret = pthread_create(&priv->timer_tid, attrp, mlx5_vdpa_event_handle, - (void *)priv); - if (ret) { - DRV_LOG(ERR, "Failed to create timer thread."); - goto out; - } - CPU_ZERO(&cpuset); + attr.priority = RTE_THREAD_PRIORITY_REALTIME_CRITICAL; if (priv->event_core != -1) - CPU_SET(priv->event_core, &cpuset); + CPU_SET(priv->event_core, &attr.cpuset); else - cpuset = rte_lcore_cpuset(rte_get_main_lcore()); - ret = pthread_setaffinity_np(priv->timer_tid, sizeof(cpuset), &cpuset); - if (ret) { - DRV_LOG(ERR, "Failed to set thread affinity."); + attr.cpuset = rte_lcore_cpuset(rte_get_main_lcore()); + ret = rte_thread_create(&priv->timer_tid, + &attr, mlx5_vdpa_event_handle, priv); + if (ret != 0) { + DRV_LOG(ERR, "Failed to create timer thread."); goto out; } - snprintf(name, sizeof(name), "dpdk-vmlx5-%d", priv->vid); - rte_thread_set_name((rte_thread_t){(uintptr_t)priv->timer_tid}, name); + snprintf(name, sizeof(name), "vmlx5-%d", priv->vid); + rte_thread_set_prefixed_name(priv->timer_tid, name); out: - if (attrp != NULL) - pthread_attr_destroy(attrp); if (ret != 0) return -1; return 0; @@ -560,19 +537,18 @@ void mlx5_vdpa_cqe_event_unset(struct mlx5_vdpa_priv *priv) { struct mlx5_vdpa_virtq *virtq; - void *status; int i; - if (priv->timer_tid) { - pthread_cancel(priv->timer_tid); - pthread_join(priv->timer_tid, &status); + if (priv->timer_tid.opaque_id != 0) { + pthread_cancel((pthread_t)priv->timer_tid.opaque_id); + rte_thread_join(priv->timer_tid, NULL); /* The mutex may stay locked after event thread cancel, initiate it. */ for (i = 0; i < priv->nr_virtqs; i++) { virtq = &priv->virtqs[i]; pthread_mutex_init(&virtq->virtq_lock, NULL); } } - priv->timer_tid = 0; + priv->timer_tid.opaque_id = 0; } void diff --git a/drivers/vdpa/sfc/sfc_vdpa_ops.c b/drivers/vdpa/sfc/sfc_vdpa_ops.c index f63af7d478..00f9a4b04c 100644 --- a/drivers/vdpa/sfc/sfc_vdpa_ops.c +++ b/drivers/vdpa/sfc/sfc_vdpa_ops.c @@ -567,7 +567,7 @@ sfc_vdpa_get_protocol_features(struct rte_vdpa_device *vdpa_dev, return 0; } -static void * +static uint32_t sfc_vdpa_notify_ctrl(void *arg) { struct sfc_vdpa_ops_data *ops_data; @@ -575,7 +575,7 @@ sfc_vdpa_notify_ctrl(void *arg) ops_data = arg; if (ops_data == NULL) - return NULL; + return 0; sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle)); @@ -588,7 +588,7 @@ sfc_vdpa_notify_ctrl(void *arg) sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle)); - return NULL; + return 0; } static int @@ -603,8 +603,8 @@ sfc_vdpa_setup_notify_ctrl(struct sfc_vdpa_ops_data *ops_data) * dead lock scenario when multiple VFs are used in single vdpa * application and multiple VFs are passed to a single VM. */ - ret = pthread_create(&ops_data->notify_tid, NULL, - sfc_vdpa_notify_ctrl, ops_data); + ret = rte_thread_create_internal_control(&ops_data->notify_tid, + "sfc-vdpa", sfc_vdpa_notify_ctrl, ops_data); if (ret != 0) { sfc_vdpa_err(ops_data->dev_handle, "failed to create notify_ctrl thread: %s", @@ -690,15 +690,14 @@ sfc_vdpa_dev_close(int vid) sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle)); if (ops_data->is_notify_thread_started == true) { - void *status; - ret = pthread_cancel(ops_data->notify_tid); + ret = pthread_cancel((pthread_t)ops_data->notify_tid.opaque_id); if (ret != 0) { sfc_vdpa_err(ops_data->dev_handle, "failed to cancel notify_ctrl thread: %s", rte_strerror(ret)); } - ret = pthread_join(ops_data->notify_tid, &status); + ret = rte_thread_join(ops_data->notify_tid, NULL); if (ret != 0) { sfc_vdpa_err(ops_data->dev_handle, "failed to join terminated notify_ctrl thread: %s", diff --git a/drivers/vdpa/sfc/sfc_vdpa_ops.h b/drivers/vdpa/sfc/sfc_vdpa_ops.h index 5c8e352de3..10ea239434 100644 --- a/drivers/vdpa/sfc/sfc_vdpa_ops.h +++ b/drivers/vdpa/sfc/sfc_vdpa_ops.h @@ -6,6 +6,7 @@ #define _SFC_VDPA_OPS_H #include <rte_vdpa.h> +#include <rte_thread.h> #define SFC_VDPA_MAX_QUEUE_PAIRS 8 @@ -48,7 +49,7 @@ struct sfc_vdpa_ops_data { struct rte_vdpa_device *vdpa_dev; enum sfc_vdpa_context vdpa_context; enum sfc_vdpa_state state; - pthread_t notify_tid; + rte_thread_t notify_tid; bool is_notify_thread_started; uint64_t dev_features; -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v2 08/11] examples: convert to normal control threads 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon ` (6 preceding siblings ...) 2023-09-13 10:34 ` [PATCH v2 07/11] drivers: " Thomas Monjalon @ 2023-09-13 10:34 ` Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 09/11] test: convert threads creation Thomas Monjalon ` (2 subsequent siblings) 10 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 10:34 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Maxime Coquelin, Chenbo Xia Calls to rte_ctrl_thread_create() are replaced with rte_thread_create_control(). In vhost_blk, the control thread is not forced to be scheduled on core 0 anymore. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- examples/vhost/main.c | 9 +++++---- examples/vhost_blk/vhost_blk.c | 21 ++++++--------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 9ff2c1f31b..ce5c1efddf 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -28,6 +28,7 @@ #include <rte_pause.h> #include <rte_dmadev.h> #include <rte_vhost_async.h> +#include <rte_thread.h> #include "main.h" @@ -1807,7 +1808,7 @@ static const struct rte_vhost_device_ops virtio_net_device_ops = * This is a thread will wake up after a period to print stats if the user has * enabled them. */ -static void * +static uint32_t print_stats(__rte_unused void *arg) { struct vhost_dev *vdev; @@ -1852,7 +1853,7 @@ print_stats(__rte_unused void *arg) fflush(stdout); } - return NULL; + return 0; } static void @@ -1907,7 +1908,7 @@ main(int argc, char *argv[]) unsigned nb_ports, valid_num_ports; int ret, i; uint16_t portid; - static pthread_t tid; + rte_thread_t tid; uint64_t flags = RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS; signal(SIGINT, sigint_handler); @@ -1986,7 +1987,7 @@ main(int argc, char *argv[]) /* Enable stats if the user option is set. */ if (enable_stats) { - ret = rte_ctrl_thread_create(&tid, "dpdk-vhost-stat", NULL, + ret = rte_thread_create_control(&tid, "dpdk-vhost-stat", print_stats, NULL); if (ret < 0) rte_exit(EXIT_FAILURE, diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c index 45699eb0b3..376f7b89a7 100644 --- a/examples/vhost_blk/vhost_blk.c +++ b/examples/vhost_blk/vhost_blk.c @@ -5,8 +5,6 @@ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif -#include <pthread.h> -#include <sched.h> #include <stdint.h> #include <stdlib.h> @@ -529,12 +527,10 @@ process_vq(struct vhost_blk_queue *vq) } } -static void * +static uint32_t ctrlr_worker(void *arg) { struct vhost_blk_ctrlr *ctrlr = (struct vhost_blk_ctrlr *)arg; - cpu_set_t cpuset; - pthread_t thread; int i; fprintf(stdout, "Ctrlr Worker Thread start\n"); @@ -546,11 +542,6 @@ ctrlr_worker(void *arg) exit(0); } - thread = pthread_self(); - CPU_ZERO(&cpuset); - CPU_SET(0, &cpuset); - pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset); - for (i = 0; i < NUM_OF_BLK_QUEUES; i++) submit_inflight_vq(&ctrlr->queues[i]); @@ -560,7 +551,7 @@ ctrlr_worker(void *arg) fprintf(stdout, "Ctrlr Worker Thread Exiting\n"); sem_post(&exit_sem); - return NULL; + return 0; } static int @@ -605,7 +596,7 @@ new_device(int vid) struct vhost_blk_queue *vq; char path[PATH_MAX]; uint64_t features, protocol_features; - pthread_t tid; + rte_thread_t tid; int i, ret; bool packed_ring, inflight_shmfd; @@ -686,15 +677,15 @@ new_device(int vid) /* start polling vring */ worker_thread_status = WORKER_STATE_START; fprintf(stdout, "New Device %s, Device ID %d\n", path, vid); - if (rte_ctrl_thread_create(&tid, "dpdk-vhost-blk", NULL, - &ctrlr_worker, ctrlr) != 0) { + if (rte_thread_create_control(&tid, "dpdk-vhost-blk", + &ctrlr_worker, ctrlr) != 0) { fprintf(stderr, "Worker Thread Started Failed\n"); return -1; } /* device has been started */ ctrlr->started = 1; - pthread_detach(tid); + rte_thread_detach(tid); return 0; } -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v2 09/11] test: convert threads creation 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon ` (7 preceding siblings ...) 2023-09-13 10:34 ` [PATCH v2 08/11] examples: convert to normal " Thomas Monjalon @ 2023-09-13 10:34 ` Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 10/11] eal: remove deprecated thread functions Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 11/11] lib: remove pthread.h from includes Thomas Monjalon 10 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 10:34 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Reshma Pattan, Stephen Hemminger Calls to pthread for thread creation are replaced with the rte_thread API. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- app/test/process.h | 10 +++++----- app/test/test_lcores.c | 9 ++++----- app/test/test_pdump.c | 6 +++--- app/test/test_pdump.h | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/test/process.h b/app/test/process.h index 1f073b9c5c..af7bc3e0de 100644 --- a/app/test/process.h +++ b/app/test/process.h @@ -28,8 +28,8 @@ #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING -#include <pthread.h> -extern void *send_pkts(void *empty); +#include <rte_thread.h> +extern uint32_t send_pkts(void *empty); extern uint16_t flag_for_send_pkts; #endif #endif @@ -49,7 +49,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) char path[32]; #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING - pthread_t thread; + rte_thread_t thread; int rc; #endif #endif @@ -136,7 +136,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING if ((strcmp(env_value, "run_pdump_server_tests") == 0)) { - rc = pthread_create(&thread, NULL, &send_pkts, NULL); + rc = rte_thread_create(&thread, NULL, send_pkts, NULL); if (rc != 0) { rte_panic("Cannot start send pkts thread: %s\n", strerror(rc)); @@ -151,7 +151,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) #ifdef RTE_NET_RING if ((strcmp(env_value, "run_pdump_server_tests") == 0)) { flag_for_send_pkts = 0; - pthread_join(thread, NULL); + rte_thread_join(thread, NULL); } #endif #endif diff --git a/app/test/test_lcores.c b/app/test/test_lcores.c index 0c96faa4cb..22225a9fd3 100644 --- a/app/test/test_lcores.c +++ b/app/test/test_lcores.c @@ -2,7 +2,6 @@ * Copyright (c) 2020 Red Hat, Inc. */ -#include <pthread.h> #include <string.h> #include <rte_common.h> @@ -341,7 +340,7 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count) return -1; } -static void *ctrl_thread_loop(void *arg) +static uint32_t ctrl_thread_loop(void *arg) { struct thread_context *t = arg; @@ -350,7 +349,7 @@ static void *ctrl_thread_loop(void *arg) /* Set the thread state to DONE */ t->state = Thread_DONE; - return NULL; + return 0; } static int @@ -362,8 +361,8 @@ test_ctrl_thread(void) /* Create one control thread */ t = &ctrl_thread_context; t->state = Thread_INIT; - if (rte_ctrl_thread_create((pthread_t *)&t->id, "dpdk-test-ctrlt", - NULL, ctrl_thread_loop, t) != 0) + if (rte_thread_create_control(&t->id, "dpdk-test-ctrlt", + ctrl_thread_loop, t) != 0) return -1; /* Wait till the control thread exits. diff --git a/app/test/test_pdump.c b/app/test/test_pdump.c index ea03056b47..adf49f0b54 100644 --- a/app/test/test_pdump.c +++ b/app/test/test_pdump.c @@ -136,8 +136,8 @@ test_pdump_uninit(void) return ret; } -void * -send_pkts(void *empty) +uint32_t +send_pkts(void *empty __rte_unused) { int ret = 0; struct rte_mbuf *pbuf[NUM_PACKETS] = { }; @@ -161,7 +161,7 @@ send_pkts(void *empty) rte_eth_dev_stop(portid); test_put_mbuf_to_pool(mp, pbuf); - return empty; + return 0; } /* diff --git a/app/test/test_pdump.h b/app/test/test_pdump.h index abef9a85ec..8746d61269 100644 --- a/app/test/test_pdump.h +++ b/app/test/test_pdump.h @@ -9,7 +9,7 @@ #define NUM_ITR 3 /* sample test to send packets to the pdump client recursively */ -void *send_pkts(void *port); +uint32_t send_pkts(void *empty); /* Sample test to create setup for the pdump server tests */ int test_pdump_init(void); -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v2 10/11] eal: remove deprecated thread functions 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon ` (8 preceding siblings ...) 2023-09-13 10:34 ` [PATCH v2 09/11] test: convert threads creation Thomas Monjalon @ 2023-09-13 10:34 ` Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 11/11] lib: remove pthread.h from includes Thomas Monjalon 10 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 10:34 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Anatoly Burakov, Bruce Richardson, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam The deprecated functions rte_thread_setname() and rte_ctrl_thread_create() are replaced with the new rte_thread API: rte_thread_setname() can be replaced with rte_thread_set_name() or rte_thread_set_prefixed_name() rte_ctrl_thread_create() can be replaced with rte_thread_create_control() or rte_thread_create_internal_control() Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- v2: clean control thread params struct --- .../prog_guide/env_abstraction_layer.rst | 2 +- doc/guides/rel_notes/deprecation.rst | 5 - doc/guides/rel_notes/release_23_11.rst | 4 +- lib/eal/common/eal_common_thread.c | 93 +++---------------- lib/eal/freebsd/eal_thread.c | 7 -- lib/eal/include/rte_lcore.h | 42 --------- lib/eal/linux/eal_thread.c | 16 ---- lib/eal/version.map | 2 - lib/eal/windows/eal_thread.c | 8 -- 9 files changed, 18 insertions(+), 161 deletions(-) diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst index 89014789de..6debf54efb 100644 --- a/doc/guides/prog_guide/env_abstraction_layer.rst +++ b/doc/guides/prog_guide/env_abstraction_layer.rst @@ -756,7 +756,7 @@ Control Thread API ~~~~~~~~~~~~~~~~~~ It is possible to create Control Threads using the public API -``rte_ctrl_thread_create()``. +``rte_thread_create_control()``. Those threads can be used for management/infrastructure tasks and are used internally by DPDK for multi process support and interrupt handling. diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index 3e48908b51..8c8873006d 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -29,11 +29,6 @@ Deprecation Notices are renamed to ``rte_tel_data_add_array_uint`` and ``rte_tel_data_add_dict_uint`` respectively. As such, the old function names are deprecated and will be removed in a future release. -* eal: The functions ``rte_thread_setname`` and ``rte_ctrl_thread_create`` - are planned to be deprecated starting with the 23.07 release, subject to - the replacement API rte_thread_set_name and rte_thread_create_control being - marked as stable, and planned to be removed by the 23.11 release. - * eal: ``RTE_CPUFLAG_NUMFLAGS`` will be removed in DPDK 23.11 release. This is to allow new CPU features to be added without ABI breakage. diff --git a/doc/guides/rel_notes/release_23_11.rst b/doc/guides/rel_notes/release_23_11.rst index d7562fd646..9746809a66 100644 --- a/doc/guides/rel_notes/release_23_11.rst +++ b/doc/guides/rel_notes/release_23_11.rst @@ -115,7 +115,9 @@ API Changes * eal: The thread API has changed. The function ``rte_thread_create_control()`` does not take attributes anymore. - The whole thread API was promoted to stable level. + The whole thread API was promoted to stable level, + except ``rte_thread_setname()`` and ``rte_ctrl_thread_create()`` which are + replaced with ``rte_thread_set_name()`` and ``rte_thread_create_control()``. ABI Changes diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index cd6e00fe8a..a71142662a 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -235,25 +235,22 @@ enum __rte_ctrl_thread_status { CTRL_THREAD_ERROR /* Control thread encountered an error */ }; -struct rte_thread_ctrl_params { - union { - void *(*ctrl_start_routine)(void *arg); - rte_thread_func control_start_routine; - } u; +struct control_thread_params { + rte_thread_func start_routine; void *arg; int ret; /* Control thread status. * If the status is CTRL_THREAD_ERROR, 'ret' has the error code. */ - enum __rte_ctrl_thread_status ctrl_thread_status; + enum __rte_ctrl_thread_status status; }; -static int ctrl_thread_init(void *arg) +static int control_thread_init(void *arg) { struct internal_config *internal_conf = eal_get_internal_configuration(); rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset; - struct rte_thread_ctrl_params *params = arg; + struct control_thread_params *params = arg; __rte_thread_init(rte_lcore_id(), cpuset); /* Set control thread socket ID to SOCKET_ID_ANY @@ -262,96 +259,34 @@ static int ctrl_thread_init(void *arg) RTE_PER_LCORE(_socket_id) = SOCKET_ID_ANY; params->ret = rte_thread_set_affinity_by_id(rte_thread_self(), cpuset); if (params->ret != 0) { - __atomic_store_n(¶ms->ctrl_thread_status, + __atomic_store_n(¶ms->status, CTRL_THREAD_ERROR, __ATOMIC_RELEASE); return 1; } - __atomic_store_n(¶ms->ctrl_thread_status, + __atomic_store_n(¶ms->status, CTRL_THREAD_RUNNING, __ATOMIC_RELEASE); return 0; } -static void *ctrl_thread_start(void *arg) -{ - struct rte_thread_ctrl_params *params = arg; - void *start_arg = params->arg; - void *(*start_routine)(void *) = params->u.ctrl_start_routine; - - if (ctrl_thread_init(arg) != 0) - return NULL; - - return start_routine(start_arg); -} - static uint32_t control_thread_start(void *arg) { - struct rte_thread_ctrl_params *params = arg; + struct control_thread_params *params = arg; void *start_arg = params->arg; - rte_thread_func start_routine = params->u.control_start_routine; + rte_thread_func start_routine = params->start_routine; - if (ctrl_thread_init(arg) != 0) + if (control_thread_init(arg) != 0) return 0; return start_routine(start_arg); } -int -rte_ctrl_thread_create(pthread_t *thread, const char *name, - const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg) -{ - struct rte_thread_ctrl_params *params; - enum __rte_ctrl_thread_status ctrl_thread_status; - int ret; - - params = malloc(sizeof(*params)); - if (!params) - return -ENOMEM; - - params->u.ctrl_start_routine = start_routine; - params->arg = arg; - params->ret = 0; - params->ctrl_thread_status = CTRL_THREAD_LAUNCHING; - - ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params); - if (ret != 0) { - free(params); - return -ret; - } - - if (name != NULL) - rte_thread_set_name((rte_thread_t){(uintptr_t)*thread}, name); - - /* Wait for the control thread to initialize successfully */ - while ((ctrl_thread_status = - __atomic_load_n(¶ms->ctrl_thread_status, - __ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) { - /* Yield the CPU. Using sched_yield call requires maintaining - * another implementation for Windows as sched_yield is not - * supported on Windows. - */ - rte_delay_us_sleep(1); - } - - /* Check if the control thread encountered an error */ - if (ctrl_thread_status == CTRL_THREAD_ERROR) { - /* ctrl thread is exiting */ - rte_thread_join((rte_thread_t){(uintptr_t)*thread}, NULL); - } - - ret = params->ret; - free(params); - - return -ret; -} - int rte_thread_create_control(rte_thread_t *thread, const char *name, rte_thread_func start_routine, void *arg) { - struct rte_thread_ctrl_params *params; + struct control_thread_params *params; enum __rte_ctrl_thread_status ctrl_thread_status; int ret; @@ -359,10 +294,10 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, if (params == NULL) return -ENOMEM; - params->u.control_start_routine = start_routine; + params->start_routine = start_routine; params->arg = arg; params->ret = 0; - params->ctrl_thread_status = CTRL_THREAD_LAUNCHING; + params->status = CTRL_THREAD_LAUNCHING; ret = rte_thread_create(thread, NULL, control_thread_start, params); if (ret != 0) { @@ -375,7 +310,7 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, /* Wait for the control thread to initialize successfully */ while ((ctrl_thread_status = - __atomic_load_n(¶ms->ctrl_thread_status, + __atomic_load_n(¶ms->status, __ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) { rte_delay_us_sleep(1); } diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c index ba9b25c2c0..6f97a3c2c1 100644 --- a/lib/eal/freebsd/eal_thread.c +++ b/lib/eal/freebsd/eal_thread.c @@ -42,10 +42,3 @@ void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated); } - -int rte_thread_setname(pthread_t id, const char *name) -{ - /* this BSD function returns no error */ - pthread_set_name_np(id, name); - return 0; -} diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h index 6ce810b876..7deae47af3 100644 --- a/lib/eal/include/rte_lcore.h +++ b/lib/eal/include/rte_lcore.h @@ -385,20 +385,6 @@ void rte_lcore_register_usage_cb(rte_lcore_usage_cb cb); void rte_lcore_dump(FILE *f); -/** - * Set thread names. - * - * @note It fails with glibc < 2.12. - * - * @param id - * Thread id. - * @param name - * Thread name to set. - * @return - * On success, return 0; otherwise return a negative value. - */ -int rte_thread_setname(pthread_t id, const char *name); - /** * Register current non-EAL thread as a lcore. * @@ -421,34 +407,6 @@ rte_thread_register(void); void rte_thread_unregister(void); -/** - * Create a control thread. - * - * Creates a control thread with the given name and attributes. The - * affinity of the new thread is based on the CPU affinity retrieved - * at the time rte_eal_init() was called, the dataplane and service - * lcores are then excluded. If setting the name of the thread fails, - * the error is ignored and a debug message is logged. - * - * @param thread - * Filled with the thread id of the new created thread. - * @param name - * The name of the control thread (max 16 characters including '\0'). - * @param attr - * Attributes for the new thread. - * @param start_routine - * Function to be executed by the new thread. - * @param arg - * Argument passed to start_routine. - * @return - * On success, returns 0; on error, it returns a negative value - * corresponding to the error number. - */ -int -rte_ctrl_thread_create(pthread_t *thread, const char *name, - const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg); - #ifdef __cplusplus } #endif diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c index b9a126f3a8..880070c627 100644 --- a/lib/eal/linux/eal_thread.c +++ b/lib/eal/linux/eal_thread.c @@ -39,19 +39,3 @@ void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) if (ret != 0) RTE_LOG(DEBUG, EAL, "Failed to set thread name\n"); } - -int rte_thread_setname(pthread_t id, const char *name) -{ - int ret = ENOSYS; -#if defined(__GLIBC__) && defined(__GLIBC_PREREQ) -#if __GLIBC_PREREQ(2, 12) - char truncated[16]; - - strlcpy(truncated, name, sizeof(truncated)); - ret = pthread_setname_np(id, truncated); -#endif -#endif - RTE_SET_USED(id); - RTE_SET_USED(name); - return -ret; -} diff --git a/lib/eal/version.map b/lib/eal/version.map index 6d32c19286..915057b325 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -20,7 +20,6 @@ DPDK_24 { rte_cpu_get_flag_enabled; rte_cpu_get_flag_name; rte_cpu_is_supported; # WINDOWS_NO_EXPORT - rte_ctrl_thread_create; rte_cycles_vmware_tsc_map; # WINDOWS_NO_EXPORT rte_delay_us; rte_delay_us_block; @@ -278,7 +277,6 @@ DPDK_24 { rte_thread_set_affinity_by_id; rte_thread_set_name; rte_thread_set_priority; - rte_thread_setname; rte_thread_unregister; rte_thread_value_get; rte_thread_value_set; diff --git a/lib/eal/windows/eal_thread.c b/lib/eal/windows/eal_thread.c index 464d510838..9e3df200b9 100644 --- a/lib/eal/windows/eal_thread.c +++ b/lib/eal/windows/eal_thread.c @@ -76,11 +76,3 @@ rte_sys_gettid(void) { return GetCurrentThreadId(); } - -int -rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name) -{ - /* TODO */ - /* This is a stub, not the expected result */ - return 0; -} -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v2 11/11] lib: remove pthread.h from includes 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon ` (9 preceding siblings ...) 2023-09-13 10:34 ` [PATCH v2 10/11] eal: remove deprecated thread functions Thomas Monjalon @ 2023-09-13 10:34 ` Thomas Monjalon 10 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 10:34 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Ajit Khaparde, Rosen Xu, Chas Williams, Min Hu (Connor), Matan Azrad, Viacheslav Ovsiienko, Ori Kam, Suanming Mou, Somnath Kotur, Devendra Singh Rawat, Alok Prasad, Tianfei Zhang, Vijay Kumar Srivastava, Jerin Jacob, Sunil Kumar Kori, Anatoly Burakov, Bruce Richardson, Andrew Rybchenko, Naga Harish K S V, Maxime Coquelin, Chenbo Xia The header files should have the minimum embedded includes. The file pthread.h can logically be removed from rte_per_lcore.h and rte_ethdev_core.h files. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com> Acked-by: Rosen Xu <rosen.xu@intel.com> --- app/test/test_link_bonding.c | 2 ++ drivers/common/mlx5/mlx5_common.c | 1 + drivers/common/mlx5/windows/mlx5_win_ext.h | 2 ++ drivers/net/bnxt/bnxt.h | 1 + drivers/net/qede/base/bcm_osal.h | 1 + drivers/raw/ifpga/base/opae_osdep.h | 1 + drivers/vdpa/sfc/sfc_vdpa.c | 1 + lib/eal/common/eal_common_options.c | 1 + lib/eal/common/eal_common_trace.c | 1 + lib/eal/common/malloc_mp.c | 1 + lib/eal/freebsd/eal_alarm.c | 1 + lib/eal/include/rte_per_lcore.h | 2 -- lib/eal/linux/eal_alarm.c | 1 + lib/ethdev/ethdev_driver.c | 1 + lib/ethdev/ethdev_driver.h | 2 ++ lib/ethdev/rte_ethdev_core.h | 2 -- lib/ethdev/rte_flow.c | 1 + lib/eventdev/rte_event_eth_rx_adapter.c | 1 + lib/vhost/vhost.c | 1 + 19 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/test/test_link_bonding.c b/app/test/test_link_bonding.c index 2f46e4c6ee..d6b6ebc2f2 100644 --- a/app/test/test_link_bonding.c +++ b/app/test/test_link_bonding.c @@ -10,8 +10,10 @@ #include <stdint.h> #include <inttypes.h> #include <errno.h> +#include <pthread.h> #include <sys/queue.h> #include <sys/time.h> + #include <rte_cycles.h> #include <rte_byteorder.h> #include <rte_common.h> diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c index 0ad14a48c7..ca8543e36e 100644 --- a/drivers/common/mlx5/mlx5_common.c +++ b/drivers/common/mlx5/mlx5_common.c @@ -5,6 +5,7 @@ #include <unistd.h> #include <string.h> #include <stdio.h> +#include <pthread.h> #include <rte_errno.h> #include <rte_mempool.h> diff --git a/drivers/common/mlx5/windows/mlx5_win_ext.h b/drivers/common/mlx5/windows/mlx5_win_ext.h index 6f69329a6f..a71c69bff5 100644 --- a/drivers/common/mlx5/windows/mlx5_win_ext.h +++ b/drivers/common/mlx5/windows/mlx5_win_ext.h @@ -5,6 +5,8 @@ #ifndef __MLX5_WIN_ETX_H__ #define __MLX5_WIN_ETX_H__ +#include <pthread.h> + #include "mlx5_prm.h" #include "mlx5devx.h" diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h index ed21ba7f29..0e01b1d4ba 100644 --- a/drivers/net/bnxt/bnxt.h +++ b/drivers/net/bnxt/bnxt.h @@ -8,6 +8,7 @@ #include <inttypes.h> #include <stdbool.h> +#include <pthread.h> #include <sys/queue.h> #include <rte_pci.h> diff --git a/drivers/net/qede/base/bcm_osal.h b/drivers/net/qede/base/bcm_osal.h index 97e261d306..11019b5623 100644 --- a/drivers/net/qede/base/bcm_osal.h +++ b/drivers/net/qede/base/bcm_osal.h @@ -8,6 +8,7 @@ #define __BCM_OSAL_H #include <stdbool.h> +#include <pthread.h> #include <time.h> #include <rte_bitops.h> #include <rte_byteorder.h> diff --git a/drivers/raw/ifpga/base/opae_osdep.h b/drivers/raw/ifpga/base/opae_osdep.h index 033b7e098c..e91205f536 100644 --- a/drivers/raw/ifpga/base/opae_osdep.h +++ b/drivers/raw/ifpga/base/opae_osdep.h @@ -7,6 +7,7 @@ #include <string.h> #include <stdbool.h> +#include <pthread.h> #ifdef RTE_LIB_EAL #include "osdep_rte/osdep_generic.h" diff --git a/drivers/vdpa/sfc/sfc_vdpa.c b/drivers/vdpa/sfc/sfc_vdpa.c index bd6ecde450..9db87fcb7d 100644 --- a/drivers/vdpa/sfc/sfc_vdpa.c +++ b/drivers/vdpa/sfc/sfc_vdpa.c @@ -4,6 +4,7 @@ #include <stdbool.h> #include <stdint.h> +#include <pthread.h> #include <sys/queue.h> #include <rte_common.h> diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index d74b581567..a6d21f1cba 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -5,6 +5,7 @@ #include <stdlib.h> #include <string.h> +#include <pthread.h> #ifndef RTE_EXEC_ENV_WINDOWS #include <syslog.h> #endif diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index cb980af06d..b21e61bf39 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include <fnmatch.h> +#include <pthread.h> #include <sys/queue.h> #include <regex.h> diff --git a/lib/eal/common/malloc_mp.c b/lib/eal/common/malloc_mp.c index 7270c2ec90..4d62397aba 100644 --- a/lib/eal/common/malloc_mp.c +++ b/lib/eal/common/malloc_mp.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include <string.h> +#include <pthread.h> #include <sys/time.h> #include <rte_errno.h> diff --git a/lib/eal/freebsd/eal_alarm.c b/lib/eal/freebsd/eal_alarm.c index acdcf53804..e5b0909a45 100644 --- a/lib/eal/freebsd/eal_alarm.c +++ b/lib/eal/freebsd/eal_alarm.c @@ -4,6 +4,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <pthread.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> diff --git a/lib/eal/include/rte_per_lcore.h b/lib/eal/include/rte_per_lcore.h index 2b846f9337..5a1497631a 100644 --- a/lib/eal/include/rte_per_lcore.h +++ b/lib/eal/include/rte_per_lcore.h @@ -22,8 +22,6 @@ extern "C" { #endif -#include <pthread.h> - #ifdef RTE_TOOLCHAIN_MSVC /** * Macro to define a per lcore variable "var" of type "type", don't diff --git a/lib/eal/linux/eal_alarm.c b/lib/eal/linux/eal_alarm.c index 397f25d7d5..766ba2c251 100644 --- a/lib/eal/linux/eal_alarm.c +++ b/lib/eal/linux/eal_alarm.c @@ -5,6 +5,7 @@ #include <stdint.h> #include <stdlib.h> #include <errno.h> +#include <pthread.h> #include <sys/queue.h> #include <sys/time.h> #include <sys/timerfd.h> diff --git a/lib/ethdev/ethdev_driver.c b/lib/ethdev/ethdev_driver.c index 0be1e8ca04..30db839a77 100644 --- a/lib/ethdev/ethdev_driver.c +++ b/lib/ethdev/ethdev_driver.c @@ -3,6 +3,7 @@ */ #include <stdlib.h> +#include <pthread.h> #include <rte_kvargs.h> #include <rte_malloc.h> diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h index 980f837ab6..3fa8b309c1 100644 --- a/lib/ethdev/ethdev_driver.h +++ b/lib/ethdev/ethdev_driver.h @@ -18,6 +18,8 @@ extern "C" { * use them. */ +#include <pthread.h> + #include <dev_driver.h> #include <rte_compat.h> #include <rte_ethdev.h> diff --git a/lib/ethdev/rte_ethdev_core.h b/lib/ethdev/rte_ethdev_core.h index 46e9721e07..8d260584b4 100644 --- a/lib/ethdev/rte_ethdev_core.h +++ b/lib/ethdev/rte_ethdev_core.h @@ -5,8 +5,6 @@ #ifndef _RTE_ETHDEV_CORE_H_ #define _RTE_ETHDEV_CORE_H_ -#include <pthread.h> - /** * @file * diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c index 271d854f78..0c5aabea45 100644 --- a/lib/ethdev/rte_flow.c +++ b/lib/ethdev/rte_flow.c @@ -6,6 +6,7 @@ #include <errno.h> #include <stddef.h> #include <stdint.h> +#include <pthread.h> #include <rte_common.h> #include <rte_errno.h> diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c index c166ef69a8..2145d803e4 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -4,6 +4,7 @@ */ #include <ctype.h> #include <stdlib.h> +#include <pthread.h> #if defined(LINUX) #include <sys/epoll.h> #endif diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index eb6309b681..c03bb9c6eb 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -6,6 +6,7 @@ #include <linux/virtio_net.h> #include <stdint.h> #include <stdlib.h> +#include <pthread.h> #ifdef RTE_LIBRTE_VHOST_NUMA #include <numa.h> #include <numaif.h> -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v3 00/11] rework thread management 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon ` (12 preceding siblings ...) 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon @ 2023-09-13 11:28 ` Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 01/11] devtools: warn when adding some pthread calls Thomas Monjalon ` (12 more replies) 13 siblings, 13 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 11:28 UTC (permalink / raw) To: dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit The main effect of this patch series is to remove calls to pthread functions except for pthread_cancel and locks. The function rte_thread_create_control() does not take thread attributes settings anymore as it looks a useless complication of the API. Then the rte_thread API is made stable, so we can remove the old deprecated functions rte_thread_setname() and rte_ctrl_thread_create(). Some new internal functions are added in rte_thread to make sure all internal thread names are prefixed with "dpdk-". Few other cleanups are done. Future work about pthread portability are about: - cancel - mutex --- v2 changes: - replace (|_) with _? in checkpatch - simplify thread name size doc - build time check of internal thread name size - clean control thread params struct v3 change: - fix build (wrong placement of RTE_BUILD_BUG_ON) note for later: never send a patch during a summit! Thomas Monjalon (11): devtools: warn when adding some pthread calls eal: rename thread name length definition eal: remove attributes from control thread creation eal: promote thread API as stable eal: force prefix for internal threads lib: convert to internal control threads drivers: convert to internal control threads examples: convert to normal control threads test: convert threads creation eal: remove deprecated thread functions lib: remove pthread.h from includes app/test/process.h | 10 +- app/test/test_lcores.c | 9 +- app/test/test_link_bonding.c | 2 + app/test/test_pdump.c | 6 +- app/test/test_pdump.h | 2 +- app/test/test_threads.c | 2 +- devtools/checkpatches.sh | 16 +++ .../prog_guide/env_abstraction_layer.rst | 2 +- doc/guides/rel_notes/deprecation.rst | 5 - doc/guides/rel_notes/release_23_11.rst | 6 + drivers/common/cnxk/roc_dev.c | 16 +-- drivers/common/cnxk/roc_dev_priv.h | 2 +- drivers/common/cnxk/roc_nix_inl_dev.c | 9 +- drivers/common/cnxk/roc_nix_inl_priv.h | 2 +- drivers/common/cnxk/roc_platform.h | 3 +- drivers/common/mlx5/mlx5_common.c | 1 + drivers/common/mlx5/windows/mlx5_win_ext.h | 2 + drivers/dma/skeleton/skeleton_dmadev.c | 8 +- drivers/event/dlb2/pf/base/dlb2_osdep.h | 14 +- drivers/event/dlb2/pf/base/dlb2_resource.c | 39 +++--- drivers/event/dlb2/pf/dlb2_main.h | 1 - drivers/net/ark/ark_ethdev.c | 11 +- drivers/net/ark/ark_pktgen.c | 8 +- drivers/net/ark/ark_pktgen.h | 2 +- drivers/net/bnxt/bnxt.h | 1 + drivers/net/iavf/iavf_vchnl.c | 4 +- drivers/net/ice/ice_dcf_parent.c | 7 +- drivers/net/ipn3ke/ipn3ke_representor.c | 17 ++- drivers/net/ixgbe/ixgbe_ethdev.c | 8 +- drivers/net/mlx5/mlx5.h | 2 +- drivers/net/mlx5/mlx5_hws_cnt.c | 42 +++--- drivers/net/qede/base/bcm_osal.h | 1 + drivers/net/sfc/sfc_mae.h | 2 +- drivers/net/sfc/sfc_mae_counter.c | 11 +- drivers/net/txgbe/txgbe_ethdev.c | 6 +- drivers/raw/ifpga/base/opae_osdep.h | 1 + drivers/raw/ifpga/ifpga_rawdev.c | 19 ++- drivers/vdpa/ifc/ifcvf_vdpa.c | 86 ++++++------ drivers/vdpa/mlx5/mlx5_vdpa.c | 2 +- drivers/vdpa/mlx5/mlx5_vdpa.h | 10 +- drivers/vdpa/mlx5/mlx5_vdpa_cthread.c | 70 +++------- drivers/vdpa/mlx5/mlx5_vdpa_event.c | 64 +++------ drivers/vdpa/sfc/sfc_vdpa.c | 1 + drivers/vdpa/sfc/sfc_vdpa_ops.c | 15 +- drivers/vdpa/sfc/sfc_vdpa_ops.h | 3 +- examples/vhost/main.c | 9 +- examples/vhost_blk/vhost_blk.c | 21 +-- lib/eal/common/eal_common_options.c | 1 + lib/eal/common/eal_common_proc.c | 15 +- lib/eal/common/eal_common_thread.c | 131 +++++++----------- lib/eal/common/eal_common_trace.c | 1 + lib/eal/common/malloc_mp.c | 1 + lib/eal/freebsd/eal.c | 2 +- lib/eal/freebsd/eal_alarm.c | 1 + lib/eal/freebsd/eal_interrupts.c | 10 +- lib/eal/freebsd/eal_thread.c | 9 +- lib/eal/include/rte_eal.h | 3 - lib/eal/include/rte_lcore.h | 42 ------ lib/eal/include/rte_per_lcore.h | 2 - lib/eal/include/rte_thread.h | 131 +++++++++--------- lib/eal/linux/eal.c | 2 +- lib/eal/linux/eal_alarm.c | 1 + lib/eal/linux/eal_interrupts.c | 10 +- lib/eal/linux/eal_thread.c | 18 +-- lib/eal/linux/eal_timer.c | 11 +- lib/eal/unix/rte_thread.c | 2 +- lib/eal/version.map | 44 +++--- lib/eal/windows/eal.c | 2 +- lib/eal/windows/eal_interrupts.c | 2 +- lib/eal/windows/eal_thread.c | 8 -- lib/eal/windows/rte_thread.c | 2 +- lib/ethdev/ethdev_driver.c | 1 + lib/ethdev/ethdev_driver.h | 2 + lib/ethdev/rte_ethdev_core.h | 2 - lib/ethdev/rte_flow.c | 1 + lib/eventdev/rte_event_eth_rx_adapter.c | 24 ++-- lib/vhost/fd_man.c | 6 +- lib/vhost/fd_man.h | 2 +- lib/vhost/socket.c | 23 ++- lib/vhost/vduse.c | 5 +- lib/vhost/vhost.c | 1 + 81 files changed, 466 insertions(+), 632 deletions(-) -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v3 01/11] devtools: warn when adding some pthread calls 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon @ 2023-09-13 11:28 ` Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 02/11] eal: rename thread name length definition Thomas Monjalon ` (11 subsequent siblings) 12 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 11:28 UTC (permalink / raw) To: dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup All pthread functions below have an equivalent in rte_thread API: - pthread_create - pthread_join - pthread_detach - pthread_setname_np - pthread_set_name_np - pthread_setaffinity_np - pthread_attr_setinheritsched - pthread_attr_setschedpolicy Usage of these functions will be raised to encourage rte_thread adoption. The pthread functions for locks and cancel are still allowed. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- v2: replace (|_) with _? --- devtools/checkpatches.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 55fabc5458..ec9d232393 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -119,6 +119,14 @@ check_forbidden_additions() { # <patch> -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ "$1" || res=1 + # refrain from using some pthread functions + awk -v FOLDERS="lib drivers app examples" \ + -v EXPRESSIONS="pthread_(create|join|detach|set(_?name_np|affinity_np)|attr_set(inheritsched|schedpolicy))\\\(" \ + -v RET_ON_FAIL=1 \ + -v MESSAGE='Using pthread functions, prefer rte_thread' \ + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ + "$1" || res=1 + # forbid use of __reserved which is a reserved keyword in Windows system headers awk -v FOLDERS="lib drivers app examples" \ -v EXPRESSIONS='\\<__reserved\\>' \ -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v3 02/11] eal: rename thread name length definition 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 01/11] devtools: warn when adding some pthread calls Thomas Monjalon @ 2023-09-13 11:28 ` Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 03/11] eal: remove attributes from control thread creation Thomas Monjalon ` (10 subsequent siblings) 12 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 11:28 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Bruce Richardson, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam RTE_MAX_THREAD_NAME_LEN is including the NUL character, so it should be named "size" instead of "length". A new constant RTE_THREAD_NAME_SIZE is introduced for naming accuracy. For API compatibility, the old name is kept. At the same time, the original definition is moved from rte_eal.h to rte_thread.h. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- lib/eal/freebsd/eal.c | 2 +- lib/eal/freebsd/eal_thread.c | 2 +- lib/eal/include/rte_eal.h | 3 --- lib/eal/include/rte_thread.h | 9 +++++++-- lib/eal/linux/eal.c | 2 +- lib/eal/linux/eal_thread.c | 2 +- lib/eal/windows/eal.c | 2 +- lib/eal/windows/rte_thread.c | 2 +- 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 9e1e267955..39a2868523 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -583,7 +583,7 @@ rte_eal_init(int argc, char **argv) static uint32_t run_once; uint32_t has_run = 0; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; - char thread_name[RTE_MAX_THREAD_NAME_LEN]; + char thread_name[RTE_THREAD_NAME_SIZE]; const struct rte_config *config = rte_eal_get_configuration(); struct internal_config *internal_conf = eal_get_internal_configuration(); diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c index 3227d9b8a2..ba9b25c2c0 100644 --- a/lib/eal/freebsd/eal_thread.c +++ b/lib/eal/freebsd/eal_thread.c @@ -34,7 +34,7 @@ int rte_sys_gettid(void) void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) { - char truncated[RTE_MAX_THREAD_NAME_LEN]; + char truncated[RTE_THREAD_NAME_SIZE]; const size_t truncatedsz = sizeof(truncated); if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz) diff --git a/lib/eal/include/rte_eal.h b/lib/eal/include/rte_eal.h index 53c4a5519e..cd318ee141 100644 --- a/lib/eal/include/rte_eal.h +++ b/lib/eal/include/rte_eal.h @@ -27,9 +27,6 @@ extern "C" { #define RTE_MAGIC 19820526 /**< Magic number written by the main partition when ready. */ -/* Maximum thread_name length. */ -#define RTE_MAX_THREAD_NAME_LEN 16 - /** * The type of process in a linux, multi-process setup */ diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index 369e2375f6..6233142322 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -23,6 +23,11 @@ extern "C" { #endif +/** Maximum thread name length (including '\0'). */ +#define RTE_THREAD_NAME_SIZE 16 +/* Old definition, aliased for compatibility. */ +#define RTE_MAX_THREAD_NAME_LEN RTE_THREAD_NAME_SIZE + /** * Thread id descriptor. */ @@ -110,7 +115,7 @@ int rte_thread_create(rte_thread_t *thread_id, * Filled with the thread id of the new created thread. * @param name * The name of the control thread - * (max RTE_MAX_THREAD_NAME_LEN characters including '\0'). + * (max RTE_THREAD_NAME_SIZE characters including '\0'). * @param thread_attr * Attributes for the new thread. * @param thread_func @@ -188,7 +193,7 @@ rte_thread_t rte_thread_self(void); * The id of the thread to set name. * * @param thread_name - * The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN, + * The name to set. Truncated to RTE_THREAD_NAME_SIZE, * including terminating NUL if necessary. */ __rte_experimental diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index a26822f667..5f4b2fb005 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -970,7 +970,7 @@ rte_eal_init(int argc, char **argv) static uint32_t run_once; uint32_t has_run = 0; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; - char thread_name[RTE_MAX_THREAD_NAME_LEN]; + char thread_name[RTE_THREAD_NAME_SIZE]; bool phys_addrs; const struct rte_config *config = rte_eal_get_configuration(); struct internal_config *internal_conf = diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c index c07ad9d8a4..b9a126f3a8 100644 --- a/lib/eal/linux/eal_thread.c +++ b/lib/eal/linux/eal_thread.c @@ -24,7 +24,7 @@ void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) int ret = ENOSYS; #if defined(__GLIBC__) && defined(__GLIBC_PREREQ) #if __GLIBC_PREREQ(2, 12) - char truncated[RTE_MAX_THREAD_NAME_LEN]; + char truncated[RTE_THREAD_NAME_SIZE]; const size_t truncatedsz = sizeof(truncated); if (strlcpy(truncated, thread_name, truncatedsz) >= truncatedsz) diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 16c1ba1596..7ec2152211 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -283,7 +283,7 @@ rte_eal_init(int argc, char **argv) enum rte_iova_mode iova_mode; int ret; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; - char thread_name[RTE_MAX_THREAD_NAME_LEN]; + char thread_name[RTE_THREAD_NAME_SIZE]; eal_log_init(NULL, 0); diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c index e528ac9991..acf648456c 100644 --- a/lib/eal/windows/rte_thread.c +++ b/lib/eal/windows/rte_thread.c @@ -324,7 +324,7 @@ void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) { int ret = 0; - wchar_t wname[RTE_MAX_THREAD_NAME_LEN]; + wchar_t wname[RTE_THREAD_NAME_SIZE]; mbstate_t state = {0}; size_t rv; HANDLE thread_handle; -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v3 03/11] eal: remove attributes from control thread creation 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 01/11] devtools: warn when adding some pthread calls Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 02/11] eal: rename thread name length definition Thomas Monjalon @ 2023-09-13 11:28 ` Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 04/11] eal: promote thread API as stable Thomas Monjalon ` (9 subsequent siblings) 12 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 11:28 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Chengwen Feng, Kevin Laatz, Bruce Richardson, Jingjing Wu, Beilei Xing, Qiming Yang, Qi Zhang, Wenjun Wu, Jiawen Wu, Jian Wang, Harman Kalra, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam The experimental function rte_thread_create_control() is supposed to wrap actions needed to create a control thread in DPDK. This function should be easy to port on any OS. As such, the thread attributes should not be customizable in this API. The thread priority should be normal, and the affinity is on "free cores". That's why the custom attributes parameter thread_attr is dropped. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- app/test/test_threads.c | 2 +- doc/guides/rel_notes/release_23_11.rst | 3 +++ drivers/dma/skeleton/skeleton_dmadev.c | 3 +-- drivers/net/iavf/iavf_vchnl.c | 2 +- drivers/net/ice/ice_dcf_parent.c | 2 +- drivers/net/ixgbe/ixgbe_ethdev.c | 1 - drivers/net/txgbe/txgbe_ethdev.c | 2 +- lib/eal/common/eal_common_thread.c | 5 ++--- lib/eal/include/rte_thread.h | 5 +---- lib/eal/windows/eal_interrupts.c | 2 +- 10 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/test/test_threads.c b/app/test/test_threads.c index 8c27e2bae1..4ac3f2671a 100644 --- a/app/test/test_threads.c +++ b/app/test/test_threads.c @@ -240,7 +240,7 @@ test_thread_control_create_join(void) thread_id_ready = 0; RTE_TEST_ASSERT(rte_thread_create_control(&thread_id, "dpdk-test-thcc", - NULL, thread_main, &thread_main_id) == 0, + thread_main, &thread_main_id) == 0, "Failed to create thread."); while (__atomic_load_n(&thread_id_ready, __ATOMIC_ACQUIRE) == 0) diff --git a/doc/guides/rel_notes/release_23_11.rst b/doc/guides/rel_notes/release_23_11.rst index 333e1d95a2..d3d500f294 100644 --- a/doc/guides/rel_notes/release_23_11.rst +++ b/doc/guides/rel_notes/release_23_11.rst @@ -113,6 +113,9 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* eal: The thread API has changed. + The function ``rte_thread_create_control()`` does not take attributes anymore. + ABI Changes ----------- diff --git a/drivers/dma/skeleton/skeleton_dmadev.c b/drivers/dma/skeleton/skeleton_dmadev.c index 493224542f..4fc2319668 100644 --- a/drivers/dma/skeleton/skeleton_dmadev.c +++ b/drivers/dma/skeleton/skeleton_dmadev.c @@ -128,8 +128,7 @@ skeldma_start(struct rte_dma_dev *dev) rte_mb(); snprintf(name, sizeof(name), "dpdk-dma-skel%d", dev->data->dev_id); - ret = rte_thread_create_control(&hw->thread, name, NULL, - cpucopy_thread, dev); + ret = rte_thread_create_control(&hw->thread, name, cpucopy_thread, dev); if (ret) { SKELDMA_LOG(ERR, "Start cpucopy thread fail!"); return -EINVAL; diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c index c31a6d5c98..6baa6d5955 100644 --- a/drivers/net/iavf/iavf_vchnl.c +++ b/drivers/net/iavf/iavf_vchnl.c @@ -136,7 +136,7 @@ iavf_dev_event_handler_init(void) pthread_mutex_init(&handler->lock, NULL); if (rte_thread_create_control(&handler->tid, "dpdk-iavf-event", - NULL, iavf_dev_event_handle, NULL)) { + iavf_dev_event_handle, NULL)) { __atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED); return -1; } diff --git a/drivers/net/ice/ice_dcf_parent.c b/drivers/net/ice/ice_dcf_parent.c index ad98a531de..d3bb65874f 100644 --- a/drivers/net/ice/ice_dcf_parent.c +++ b/drivers/net/ice/ice_dcf_parent.c @@ -182,7 +182,7 @@ start_vsi_reset_thread(struct ice_dcf_hw *dcf_hw, bool vfr, uint16_t vf_id) param->vf_id = vf_id; snprintf(name, sizeof(name), "dpdk-ice-rst%u", vf_id); - ret = rte_thread_create_control(&thread, name, NULL, + ret = rte_thread_create_control(&thread, name, ice_dcf_vsi_update_service_handler, param); if (ret != 0) { PMD_DRV_LOG(ERR, "Failed to start the thread for reset handling"); diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c index 7eac05ee60..64e7e5d7d6 100644 --- a/drivers/net/ixgbe/ixgbe_ethdev.c +++ b/drivers/net/ixgbe/ixgbe_ethdev.c @@ -4330,7 +4330,6 @@ ixgbe_dev_link_update_share(struct rte_eth_dev *dev, intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; if (rte_thread_create_control(&ad->link_thread_tid, "dpdk-ixgbe-link", - NULL, ixgbe_dev_setup_link_thread_handler, dev) < 0) { PMD_DRV_LOG(ERR, diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c index 6f2f5a1841..198fac8318 100644 --- a/drivers/net/txgbe/txgbe_ethdev.c +++ b/drivers/net/txgbe/txgbe_ethdev.c @@ -2897,7 +2897,7 @@ txgbe_dev_link_update_share(struct rte_eth_dev *dev, */ intr->flags |= TXGBE_FLAG_NEED_LINK_CONFIG; if (rte_thread_create_control(&ad->link_thread_tid, - "dpdk-txgbe-link", NULL, + "dpdk-txgbe-link", txgbe_dev_setup_link_thread_handler, dev) < 0) { PMD_DRV_LOG(ERR, "Create link thread failed!"); __atomic_clear(&ad->link_thread_running, __ATOMIC_SEQ_CST); diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 6605bd017e..07ac721da1 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -349,8 +349,7 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, int rte_thread_create_control(rte_thread_t *thread, const char *name, - const rte_thread_attr_t *attr, rte_thread_func start_routine, - void *arg) + rte_thread_func start_routine, void *arg) { struct rte_thread_ctrl_params *params; enum __rte_ctrl_thread_status ctrl_thread_status; @@ -365,7 +364,7 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, params->ret = 0; params->ctrl_thread_status = CTRL_THREAD_LAUNCHING; - ret = rte_thread_create(thread, attr, control_thread_start, params); + ret = rte_thread_create(thread, NULL, control_thread_start, params); if (ret != 0) { free(params); return -ret; diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index 6233142322..28cc5220a4 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -116,8 +116,6 @@ int rte_thread_create(rte_thread_t *thread_id, * @param name * The name of the control thread * (max RTE_THREAD_NAME_SIZE characters including '\0'). - * @param thread_attr - * Attributes for the new thread. * @param thread_func * Function to be executed by the new thread. * @param arg @@ -129,8 +127,7 @@ int rte_thread_create(rte_thread_t *thread_id, __rte_experimental int rte_thread_create_control(rte_thread_t *thread, const char *name, - const rte_thread_attr_t *thread_attr, rte_thread_func thread_func, - void *arg); + rte_thread_func thread_func, void *arg); /** * @warning diff --git a/lib/eal/windows/eal_interrupts.c b/lib/eal/windows/eal_interrupts.c index b1b1228c2b..66a49c844a 100644 --- a/lib/eal/windows/eal_interrupts.c +++ b/lib/eal/windows/eal_interrupts.c @@ -98,7 +98,7 @@ rte_eal_intr_init(void) return -1; } - ret = rte_thread_create_control(&intr_thread, "dpdk-intr", NULL, + ret = rte_thread_create_control(&intr_thread, "dpdk-intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v3 04/11] eal: promote thread API as stable 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon ` (2 preceding siblings ...) 2023-09-13 11:28 ` [PATCH v3 03/11] eal: remove attributes from control thread creation Thomas Monjalon @ 2023-09-13 11:28 ` Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 05/11] eal: force prefix for internal threads Thomas Monjalon ` (8 subsequent siblings) 12 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 11:28 UTC (permalink / raw) To: dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup The rte_thread API must be used to ease OS porting. One step of this process is to mark the necessary API as stable. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- doc/guides/rel_notes/release_23_11.rst | 1 + lib/eal/include/rte_thread.h | 64 -------------------------- lib/eal/version.map | 40 ++++++++-------- 3 files changed, 20 insertions(+), 85 deletions(-) diff --git a/doc/guides/rel_notes/release_23_11.rst b/doc/guides/rel_notes/release_23_11.rst index d3d500f294..d7562fd646 100644 --- a/doc/guides/rel_notes/release_23_11.rst +++ b/doc/guides/rel_notes/release_23_11.rst @@ -115,6 +115,7 @@ API Changes * eal: The thread API has changed. The function ``rte_thread_create_control()`` does not take attributes anymore. + The whole thread API was promoted to stable level. ABI Changes diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index 28cc5220a4..dd1f62523f 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -73,9 +73,6 @@ typedef struct { typedef struct eal_tls_key *rte_thread_key; /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Create a new thread that will invoke the 'thread_func' routine. * * @param thread_id @@ -94,15 +91,11 @@ typedef struct eal_tls_key *rte_thread_key; * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_create(rte_thread_t *thread_id, const rte_thread_attr_t *thread_attr, rte_thread_func thread_func, void *arg); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Create a control thread. * * Creates a control thread with the given name and attributes. The @@ -124,15 +117,11 @@ int rte_thread_create(rte_thread_t *thread_id, * On success, returns 0; on error, it returns a negative value * corresponding to the error number. */ -__rte_experimental int rte_thread_create_control(rte_thread_t *thread, const char *name, rte_thread_func thread_func, void *arg); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Waits for the thread identified by 'thread_id' to terminate * * @param thread_id @@ -145,13 +134,9 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_join(rte_thread_t thread_id, uint32_t *value_ptr); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Indicate that the return value of the thread is not needed and * all thread resources should be release when the thread terminates. * @@ -162,25 +147,17 @@ int rte_thread_join(rte_thread_t thread_id, uint32_t *value_ptr); * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_detach(rte_thread_t thread_id); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Get the id of the calling thread. * * @return * Return the thread id of the calling thread. */ -__rte_experimental rte_thread_t rte_thread_self(void); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the name of the thread. * This API is a noop if the underlying platform does not * support setting the thread name or the platform-specific @@ -193,14 +170,10 @@ rte_thread_t rte_thread_self(void); * The name to set. Truncated to RTE_THREAD_NAME_SIZE, * including terminating NUL if necessary. */ -__rte_experimental void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Check if 2 thread ids are equal. * * @param t1 @@ -213,13 +186,9 @@ rte_thread_set_name(rte_thread_t thread_id, const char *thread_name); * If the ids are equal, return nonzero. * Otherwise, return 0. */ -__rte_experimental int rte_thread_equal(rte_thread_t t1, rte_thread_t t2); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Initialize the attributes of a thread. * These attributes can be passed to the rte_thread_create() function * that will create a new thread and set its attributes according to attr. @@ -231,13 +200,9 @@ int rte_thread_equal(rte_thread_t t1, rte_thread_t t2); * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_attr_init(rte_thread_attr_t *attr); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the thread priority value in the thread attributes pointed to * by 'thread_attr'. * @@ -251,16 +216,12 @@ int rte_thread_attr_init(rte_thread_attr_t *attr); * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr, enum rte_thread_priority priority); #ifdef RTE_HAS_CPUSET /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the CPU affinity value in the thread attributes pointed to * by 'thread_attr'. * @@ -274,14 +235,10 @@ int rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr, rte_cpuset_t *cpuset); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Get the value of CPU affinity that is set in the thread attributes pointed * to by 'thread_attr'. * @@ -295,14 +252,10 @@ int rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr, rte_cpuset_t *cpuset); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the affinity of thread 'thread_id' to the cpu set * specified by 'cpuset'. * @@ -316,14 +269,10 @@ int rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_set_affinity_by_id(rte_thread_t thread_id, const rte_cpuset_t *cpuset); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Get the affinity of thread 'thread_id' and store it * in 'cpuset'. * @@ -337,7 +286,6 @@ int rte_thread_set_affinity_by_id(rte_thread_t thread_id, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_get_affinity_by_id(rte_thread_t thread_id, rte_cpuset_t *cpuset); @@ -364,9 +312,6 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp); #endif /* RTE_HAS_CPUSET */ /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Get the priority of a thread. * * @param thread_id @@ -379,14 +324,10 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp); * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_get_priority(rte_thread_t thread_id, enum rte_thread_priority *priority); /** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * * Set the priority of a thread. * * @param thread_id @@ -399,7 +340,6 @@ int rte_thread_get_priority(rte_thread_t thread_id, * On success, return 0. * On failure, return a positive errno-style error number. */ -__rte_experimental int rte_thread_set_priority(rte_thread_t thread_id, enum rte_thread_priority priority); @@ -421,7 +361,6 @@ int rte_thread_set_priority(rte_thread_t thread_id, * ENOEXEC - Specific OS error. */ -__rte_experimental int rte_thread_key_create(rte_thread_key *key, void (*destructor)(void *)); @@ -437,7 +376,6 @@ int rte_thread_key_create(rte_thread_key *key, * rte_errno can be: EINVAL - Invalid parameter passed. * ENOEXEC - Specific OS error. */ -__rte_experimental int rte_thread_key_delete(rte_thread_key key); /** @@ -454,7 +392,6 @@ int rte_thread_key_delete(rte_thread_key key); * rte_errno can be: EINVAL - Invalid parameter passed. * ENOEXEC - Specific OS error. */ -__rte_experimental int rte_thread_value_set(rte_thread_key key, const void *value); /** @@ -469,7 +406,6 @@ int rte_thread_value_set(rte_thread_key key, const void *value); * rte_errno can be: EINVAL - Invalid parameter passed. * ENOEXEC - Specific OS error. */ -__rte_experimental void *rte_thread_value_get(rte_thread_key key); #ifdef __cplusplus diff --git a/lib/eal/version.map b/lib/eal/version.map index 7940431e5a..33b853d7be 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -257,12 +257,31 @@ DPDK_24 { rte_strscpy; rte_strsplit; rte_sys_gettid; + rte_thread_attr_get_affinity; + rte_thread_attr_init; + rte_thread_attr_set_affinity; + rte_thread_attr_set_priority; + rte_thread_create; + rte_thread_create_control; + rte_thread_detach; + rte_thread_equal; rte_thread_get_affinity; + rte_thread_get_affinity_by_id; + rte_thread_get_priority; rte_thread_is_intr; + rte_thread_join; + rte_thread_key_create; + rte_thread_key_delete; rte_thread_register; + rte_thread_self; rte_thread_set_affinity; + rte_thread_set_affinity_by_id; + rte_thread_set_name; + rte_thread_set_priority; rte_thread_setname; rte_thread_unregister; + rte_thread_value_get; + rte_thread_value_set; rte_uuid_compare; rte_uuid_is_null; rte_uuid_parse; @@ -368,10 +387,6 @@ EXPERIMENTAL { # added in 21.05 rte_devargs_reset; rte_intr_callback_unregister_sync; - rte_thread_key_create; - rte_thread_key_delete; - rte_thread_value_get; - rte_thread_value_set; rte_version_minor; rte_version_month; rte_version_prefix; @@ -392,26 +407,9 @@ EXPERIMENTAL { # added in 22.07 rte_drand; - rte_thread_get_affinity_by_id; - rte_thread_get_priority; - rte_thread_self; - rte_thread_set_affinity_by_id; - rte_thread_set_priority; - - # added in 22.11 - rte_thread_attr_get_affinity; - rte_thread_attr_init; - rte_thread_attr_set_affinity; - rte_thread_attr_set_priority; - rte_thread_create; - rte_thread_detach; - rte_thread_equal; - rte_thread_join; # added in 23.03 rte_lcore_register_usage_cb; - rte_thread_create_control; - rte_thread_set_name; __rte_eal_trace_generic_blob; # added in 23.07 -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v3 05/11] eal: force prefix for internal threads 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon ` (3 preceding siblings ...) 2023-09-13 11:28 ` [PATCH v3 04/11] eal: promote thread API as stable Thomas Monjalon @ 2023-09-13 11:28 ` Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 06/11] lib: convert to internal control threads Thomas Monjalon ` (7 subsequent siblings) 12 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 11:28 UTC (permalink / raw) To: dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup In order to make sure all threads created in DPDK drivers and libraries have the same prefix in their name, some wrapper functions are added for internal use when creating a control thread or setting a thread name: - rte_thread_create_internal_control - rte_thread_set_prefixed_name The equivalent public functions are then forbidden for internal use: - rte_thread_create_control - rte_thread_set_name Note: the libraries and drivers conversion is done in next patches, while doing other thread-related changes. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- v2: simplify size doc + build time check of internal name size v3: fix build of RTE_BUILD_BUG_ON --- devtools/checkpatches.sh | 8 +++++ lib/eal/common/eal_common_thread.c | 33 +++++++++++++++++ lib/eal/include/rte_thread.h | 57 +++++++++++++++++++++++++++++- lib/eal/version.map | 2 ++ 4 files changed, 99 insertions(+), 1 deletion(-) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index ec9d232393..e97811192a 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -159,6 +159,14 @@ check_forbidden_additions() { # <patch> -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ "$1" || res=1 + # forbid non-internal thread in drivers and libs + awk -v FOLDERS='lib drivers' \ + -v EXPRESSIONS="rte_thread_(set_name|create_control)\\\(" \ + -v RET_ON_FAIL=1 \ + -v MESSAGE='Prefer rte_thread_(set_prefixed_name|create_internal_control) in lib & drivers' \ + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ + "$1" || res=1 + # forbid inclusion of driver specific headers in apps and examples awk -v FOLDERS='app examples' \ -v EXPRESSIONS='include.*_driver\\.h include.*_pmd\\.h' \ diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 07ac721da1..830273813f 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -392,6 +392,39 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, return ret; } +static void +add_internal_prefix(char *prefixed_name, const char *name, size_t size) +{ + size_t prefixlen; + + /* Check RTE_THREAD_INTERNAL_NAME_SIZE definition. */ + RTE_BUILD_BUG_ON(RTE_THREAD_INTERNAL_NAME_SIZE != + RTE_THREAD_NAME_SIZE - sizeof(RTE_THREAD_INTERNAL_PREFIX) + 1); + + prefixlen = strlen(RTE_THREAD_INTERNAL_PREFIX); + strlcpy(prefixed_name, RTE_THREAD_INTERNAL_PREFIX, size); + strlcpy(prefixed_name + prefixlen, name, size - prefixlen); +} + +int +rte_thread_create_internal_control(rte_thread_t *id, const char *name, + rte_thread_func func, void *arg) +{ + char prefixed_name[RTE_THREAD_NAME_SIZE]; + + add_internal_prefix(prefixed_name, name, sizeof(prefixed_name)); + return rte_thread_create_control(id, prefixed_name, func, arg); +} + +void +rte_thread_set_prefixed_name(rte_thread_t id, const char *name) +{ + char prefixed_name[RTE_THREAD_NAME_SIZE]; + + add_internal_prefix(prefixed_name, name, sizeof(prefixed_name)); + rte_thread_set_name(id, prefixed_name); +} + int rte_thread_register(void) { diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index dd1f62523f..8da9d4d3fb 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -28,6 +28,11 @@ extern "C" { /* Old definition, aliased for compatibility. */ #define RTE_MAX_THREAD_NAME_LEN RTE_THREAD_NAME_SIZE +/** Thread name prefix automatically added to all internal threads. */ +#define RTE_THREAD_INTERNAL_PREFIX "dpdk-" +/** Maximum internal thread name length (including '\0'). */ +#define RTE_THREAD_INTERNAL_NAME_SIZE 11 + /** * Thread id descriptor. */ @@ -112,7 +117,7 @@ int rte_thread_create(rte_thread_t *thread_id, * @param thread_func * Function to be executed by the new thread. * @param arg - * Argument passed to start_routine. + * Argument passed to thread_func. * @return * On success, returns 0; on error, it returns a negative value * corresponding to the error number. @@ -121,6 +126,35 @@ int rte_thread_create_control(rte_thread_t *thread, const char *name, rte_thread_func thread_func, void *arg); +/** + * Create an internal control thread. + * + * Creates a control thread with the given name prefixed. + * If setting the name of the thread fails, the error is ignored and logged. + * + * The affinity of the new thread is based on the CPU affinity retrieved + * at the time rte_eal_init() was called, the EAL threads are then excluded. + * + * @param id + * Filled with the thread ID of the new created thread. + * @param name + * The name of the control thread. + * See RTE_THREAD_INTERNAL_NAME_SIZE for maximum length. + * The name of the driver or library should be first, + * then followed by a hyphen and more details. + * It will be prefixed with RTE_THREAD_INTERNAL_PREFIX by this function. + * @param func + * Function to be executed by the new thread. + * @param arg + * Argument passed to func. + * @return + * On success, returns 0; a negative value otherwise. + */ +__rte_internal +int +rte_thread_create_internal_control(rte_thread_t *id, const char *name, + rte_thread_func func, void *arg); + /** * Waits for the thread identified by 'thread_id' to terminate * @@ -159,6 +193,7 @@ rte_thread_t rte_thread_self(void); /** * Set the name of the thread. + * * This API is a noop if the underlying platform does not * support setting the thread name or the platform-specific * API used to set the thread name fails. @@ -173,6 +208,26 @@ rte_thread_t rte_thread_self(void); void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name); +/** + * Set the name of an internal thread with the common prefix. + * + * This API is a noop if the underlying platform does not support + * setting the thread name, or if it fails. + * + * @param id + * The ID of the thread to set name. + * + * @param name + * The name to set after being prefixed. + * See RTE_THREAD_INTERNAL_NAME_SIZE for maximum length. + * The name of the driver or library should be first, + * then followed by a hyphen and more details. + * It will be prefixed with RTE_THREAD_INTERNAL_PREFIX by this function. + */ +__rte_internal +void +rte_thread_set_prefixed_name(rte_thread_t id, const char *name); + /** * Check if 2 thread ids are equal. * diff --git a/lib/eal/version.map b/lib/eal/version.map index 33b853d7be..6d32c19286 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -462,4 +462,6 @@ INTERNAL { rte_mem_map; rte_mem_page_size; rte_mem_unmap; + rte_thread_create_internal_control; + rte_thread_set_prefixed_name; }; -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v3 06/11] lib: convert to internal control threads 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon ` (4 preceding siblings ...) 2023-09-13 11:28 ` [PATCH v3 05/11] eal: force prefix for internal threads Thomas Monjalon @ 2023-09-13 11:28 ` Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 07/11] drivers: " Thomas Monjalon ` (6 subsequent siblings) 12 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 11:28 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Anatoly Burakov, Harman Kalra, Bruce Richardson, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam, Naga Harish K S V, Jerin Jacob, Maxime Coquelin, Chenbo Xia Calls to rte_ctrl_thread_create() are replaced with rte_thread_create_internal_control(). Other pthread-related functions are replaced with the rte_thread API. Only pthread_cancel() has no replacement. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- lib/eal/common/eal_common_proc.c | 15 ++++++++------- lib/eal/freebsd/eal_interrupts.c | 10 +++++----- lib/eal/linux/eal_interrupts.c | 10 +++++----- lib/eal/linux/eal_timer.c | 11 ++++++----- lib/eal/unix/rte_thread.c | 2 +- lib/eal/windows/eal_interrupts.c | 2 +- lib/eventdev/rte_event_eth_rx_adapter.c | 23 ++++++++++++----------- lib/vhost/fd_man.c | 6 +++--- lib/vhost/fd_man.h | 2 +- lib/vhost/socket.c | 23 +++++++++++------------ lib/vhost/vduse.c | 5 +++-- 11 files changed, 56 insertions(+), 53 deletions(-) diff --git a/lib/eal/common/eal_common_proc.c b/lib/eal/common/eal_common_proc.c index 26e6b78f8f..f20a348ede 100644 --- a/lib/eal/common/eal_common_proc.c +++ b/lib/eal/common/eal_common_proc.c @@ -26,6 +26,7 @@ #include <rte_errno.h> #include <rte_lcore.h> #include <rte_log.h> +#include <rte_thread.h> #include "eal_memcfg.h" #include "eal_private.h" @@ -33,7 +34,7 @@ #include "eal_internal_cfg.h" static int mp_fd = -1; -static pthread_t mp_handle_tid; +static rte_thread_t mp_handle_tid; static char mp_filter[PATH_MAX]; /* Filter for secondary process sockets */ static char mp_dir_path[PATH_MAX]; /* The directory path for all mp sockets */ static pthread_mutex_t mp_mutex_action = PTHREAD_MUTEX_INITIALIZER; @@ -396,7 +397,7 @@ process_msg(struct mp_msg_internal *m, struct sockaddr_un *s) } } -static void * +static uint32_t mp_handle(void *arg __rte_unused) { struct mp_msg_internal msg; @@ -413,7 +414,7 @@ mp_handle(void *arg __rte_unused) process_msg(&msg, &sa); } - return NULL; + return 0; } static int @@ -646,8 +647,8 @@ rte_mp_channel_init(void) return -1; } - if (rte_ctrl_thread_create(&mp_handle_tid, "dpdk-mp-msg", - NULL, mp_handle, NULL) < 0) { + if (rte_thread_create_internal_control(&mp_handle_tid, "mp-msg", + mp_handle, NULL) < 0) { RTE_LOG(ERR, EAL, "failed to create mp thread: %s\n", strerror(errno)); close(dir_fd); @@ -671,8 +672,8 @@ rte_mp_channel_cleanup(void) if (fd < 0) return; - pthread_cancel(mp_handle_tid); - pthread_join(mp_handle_tid, NULL); + pthread_cancel((pthread_t)mp_handle_tid.opaque_id); + rte_thread_join(mp_handle_tid, NULL); close_socket_fd(fd); } diff --git a/lib/eal/freebsd/eal_interrupts.c b/lib/eal/freebsd/eal_interrupts.c index 68cdb9deb3..2b31dfb099 100644 --- a/lib/eal/freebsd/eal_interrupts.c +++ b/lib/eal/freebsd/eal_interrupts.c @@ -52,7 +52,7 @@ static rte_spinlock_t intr_lock = RTE_SPINLOCK_INITIALIZER; static struct rte_intr_source_list intr_sources; /* interrupt handling thread */ -static pthread_t intr_thread; +static rte_thread_t intr_thread; static volatile int kq = -1; @@ -591,7 +591,7 @@ eal_intr_process_interrupts(struct kevent *events, int nfds) } } -static void * +static uint32_t eal_intr_thread_main(void *arg __rte_unused) { struct kevent events[MAX_INTR_EVENTS]; @@ -619,7 +619,7 @@ eal_intr_thread_main(void *arg __rte_unused) } close(kq); kq = -1; - return NULL; + return 0; } int @@ -637,7 +637,7 @@ rte_eal_intr_init(void) } /* create the host thread to wait/handle the interrupt */ - ret = rte_ctrl_thread_create(&intr_thread, "dpdk-intr", NULL, + ret = rte_thread_create_internal_control(&intr_thread, "intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; @@ -746,5 +746,5 @@ rte_intr_free_epoll_fd(struct rte_intr_handle *intr_handle) int rte_thread_is_intr(void) { - return pthread_equal(intr_thread, pthread_self()); + return rte_thread_equal(intr_thread, rte_thread_self()); } diff --git a/lib/eal/linux/eal_interrupts.c b/lib/eal/linux/eal_interrupts.c index 19b36787b8..24fff3d3c2 100644 --- a/lib/eal/linux/eal_interrupts.c +++ b/lib/eal/linux/eal_interrupts.c @@ -5,7 +5,6 @@ #include <stdio.h> #include <stdint.h> #include <stdlib.h> -#include <pthread.h> #include <sys/queue.h> #include <unistd.h> #include <string.h> @@ -19,6 +18,7 @@ #include <eal_trace_internal.h> #include <rte_common.h> #include <rte_interrupts.h> +#include <rte_thread.h> #include <rte_per_lcore.h> #include <rte_lcore.h> #include <rte_branch_prediction.h> @@ -89,7 +89,7 @@ static union intr_pipefds intr_pipe; static struct rte_intr_source_list intr_sources; /* interrupt handling thread */ -static pthread_t intr_thread; +static rte_thread_t intr_thread; /* VFIO interrupts */ #ifdef VFIO_PRESENT @@ -1103,7 +1103,7 @@ eal_intr_handle_interrupts(int pfd, unsigned totalfds) * @return * never return; */ -static __rte_noreturn void * +static __rte_noreturn uint32_t eal_intr_thread_main(__rte_unused void *arg) { /* host thread, never break out */ @@ -1188,7 +1188,7 @@ rte_eal_intr_init(void) } /* create the host thread to wait/handle the interrupt */ - ret = rte_ctrl_thread_create(&intr_thread, "dpdk-intr", NULL, + ret = rte_thread_create_internal_control(&intr_thread, "intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; @@ -1601,5 +1601,5 @@ rte_intr_cap_multiple(struct rte_intr_handle *intr_handle) int rte_thread_is_intr(void) { - return pthread_equal(intr_thread, pthread_self()); + return rte_thread_equal(intr_thread, rte_thread_self()); } diff --git a/lib/eal/linux/eal_timer.c b/lib/eal/linux/eal_timer.c index 1898709700..3a30284e3a 100644 --- a/lib/eal/linux/eal_timer.c +++ b/lib/eal/linux/eal_timer.c @@ -14,6 +14,7 @@ #include <rte_common.h> #include <rte_cycles.h> +#include <rte_thread.h> #include "eal_private.h" @@ -71,14 +72,14 @@ static uint64_t eal_hpet_resolution_hz = 0; /* Incremented 4 times during one 32bits hpet full count */ static uint32_t eal_hpet_msb; -static pthread_t msb_inc_thread_id; +static rte_thread_t msb_inc_thread_id; /* * This function runs on a specific thread to update a global variable * containing used to process MSB of the HPET (unfortunately, we need * this because hpet is 32 bits by default under linux). */ -static void * +static uint32_t hpet_msb_inc(__rte_unused void *arg) { uint32_t t; @@ -89,7 +90,7 @@ hpet_msb_inc(__rte_unused void *arg) eal_hpet_msb ++; sleep(10); } - return NULL; + return 0; } uint64_t @@ -176,8 +177,8 @@ rte_eal_hpet_init(int make_default) /* create a thread that will increment a global variable for * msb (hpet is 32 bits by default under linux) */ - ret = rte_ctrl_thread_create(&msb_inc_thread_id, "dpdk-hpet-msb", NULL, - hpet_msb_inc, NULL); + ret = rte_thread_create_internal_control(&msb_inc_thread_id, "hpet-msb", + hpet_msb_inc, NULL); if (ret != 0) { RTE_LOG(ERR, EAL, "ERROR: Cannot create HPET timer thread!\n"); internal_conf->no_hpet = 1; diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c index f4076122a4..36a21ab2f9 100644 --- a/lib/eal/unix/rte_thread.c +++ b/lib/eal/unix/rte_thread.c @@ -190,7 +190,7 @@ rte_thread_create(rte_thread_t *thread_id, pthread_mutex_unlock(&ctx.wrapper_mutex); if (ret != 0) - pthread_join((pthread_t)thread_id->opaque_id, NULL); + rte_thread_join(*thread_id, NULL); cleanup: if (attrp != NULL) diff --git a/lib/eal/windows/eal_interrupts.c b/lib/eal/windows/eal_interrupts.c index 66a49c844a..49efdc098c 100644 --- a/lib/eal/windows/eal_interrupts.c +++ b/lib/eal/windows/eal_interrupts.c @@ -98,7 +98,7 @@ rte_eal_intr_init(void) return -1; } - ret = rte_thread_create_control(&intr_thread, "dpdk-intr", + ret = rte_thread_create_internal_control(&intr_thread, "intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c index 3ebfa5366d..c166ef69a8 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -10,6 +10,7 @@ #include <unistd.h> #include <rte_cycles.h> +#include <rte_thread.h> #include <rte_common.h> #include <dev_driver.h> #include <rte_errno.h> @@ -165,7 +166,7 @@ struct event_eth_rx_adapter { /* Count of interrupt vectors in use */ uint32_t num_intr_vec; /* Thread blocked on Rx interrupts */ - pthread_t rx_intr_thread; + rte_thread_t rx_intr_thread; /* Configuration callback for rte_service configuration */ rte_event_eth_rx_adapter_conf_cb conf_cb; /* Configuration callback argument */ @@ -1154,13 +1155,13 @@ rxa_intr_ring_del_entries(struct event_eth_rx_adapter *rx_adapter, rte_spinlock_unlock(&rx_adapter->intr_ring_lock); } -/* pthread callback handling interrupt mode receive queues +/* thread callback handling interrupt mode receive queues * After receiving an Rx interrupt, it enqueues the port id and queue id of the * interrupting queue to the adapter's ring buffer for interrupt events. * These events are picked up by rxa_intr_ring_dequeue() which is invoked from * the adapter service function. */ -static void * +static uint32_t rxa_intr_thread(void *arg) { struct event_eth_rx_adapter *rx_adapter = arg; @@ -1179,7 +1180,7 @@ rxa_intr_thread(void *arg) } } - return NULL; + return 0; } /* Dequeue <port, q> from interrupt ring and enqueue received @@ -1595,7 +1596,7 @@ static int rxa_create_intr_thread(struct event_eth_rx_adapter *rx_adapter) { int err; - char thread_name[RTE_MAX_THREAD_NAME_LEN]; + char thread_name[RTE_THREAD_INTERNAL_NAME_SIZE]; if (rx_adapter->intr_ring) return 0; @@ -1618,11 +1619,11 @@ rxa_create_intr_thread(struct event_eth_rx_adapter *rx_adapter) rte_spinlock_init(&rx_adapter->intr_ring_lock); - snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, - "dpdk-evt-rx%d", rx_adapter->id); + snprintf(thread_name, sizeof(thread_name), + "evt-rx%d", rx_adapter->id); - err = rte_ctrl_thread_create(&rx_adapter->rx_intr_thread, thread_name, - NULL, rxa_intr_thread, rx_adapter); + err = rte_thread_create_internal_control(&rx_adapter->rx_intr_thread, + thread_name, rxa_intr_thread, rx_adapter); if (!err) return 0; @@ -1640,12 +1641,12 @@ rxa_destroy_intr_thread(struct event_eth_rx_adapter *rx_adapter) { int err; - err = pthread_cancel(rx_adapter->rx_intr_thread); + err = pthread_cancel((pthread_t)rx_adapter->rx_intr_thread.opaque_id); if (err) RTE_EDEV_LOG_ERR("Can't cancel interrupt thread err = %d\n", err); - err = pthread_join(rx_adapter->rx_intr_thread, NULL); + err = rte_thread_join(rx_adapter->rx_intr_thread, NULL); if (err) RTE_EDEV_LOG_ERR("Can't join interrupt thread err = %d\n", err); diff --git a/lib/vhost/fd_man.c b/lib/vhost/fd_man.c index 1876fada33..134414fb4b 100644 --- a/lib/vhost/fd_man.c +++ b/lib/vhost/fd_man.c @@ -212,7 +212,7 @@ fdset_try_del(struct fdset *pfdset, int fd) * will wait until the flag is reset to zero(which indicates the callback is * finished), then it could free the context after fdset_del. */ -void * +uint32_t fdset_event_dispatch(void *arg) { int i; @@ -227,7 +227,7 @@ fdset_event_dispatch(void *arg) int val; if (pfdset == NULL) - return NULL; + return 0; while (1) { @@ -303,7 +303,7 @@ fdset_event_dispatch(void *arg) fdset_shrink(pfdset); } - return NULL; + return 0; } static void diff --git a/lib/vhost/fd_man.h b/lib/vhost/fd_man.h index 6f4499bdfa..6315904c8e 100644 --- a/lib/vhost/fd_man.h +++ b/lib/vhost/fd_man.h @@ -46,7 +46,7 @@ int fdset_add(struct fdset *pfdset, int fd, void *fdset_del(struct fdset *pfdset, int fd); int fdset_try_del(struct fdset *pfdset, int fd); -void *fdset_event_dispatch(void *arg); +uint32_t fdset_event_dispatch(void *arg); int fdset_pipe_init(struct fdset *fdset); diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c index 12095b0e1a..5882e44176 100644 --- a/lib/vhost/socket.c +++ b/lib/vhost/socket.c @@ -13,8 +13,8 @@ #include <sys/queue.h> #include <errno.h> #include <fcntl.h> -#include <pthread.h> +#include <rte_thread.h> #include <rte_log.h> #include "fd_man.h" @@ -431,7 +431,7 @@ struct vhost_user_reconnect_list { }; static struct vhost_user_reconnect_list reconn_list; -static pthread_t reconn_tid; +static rte_thread_t reconn_tid; static int vhost_user_connect_nonblock(char *path, int fd, struct sockaddr *un, size_t sz) @@ -455,7 +455,7 @@ vhost_user_connect_nonblock(char *path, int fd, struct sockaddr *un, size_t sz) return 0; } -static void * +static uint32_t vhost_user_client_reconnect(void *arg __rte_unused) { int ret; @@ -496,7 +496,7 @@ vhost_user_client_reconnect(void *arg __rte_unused) sleep(1); } - return NULL; + return 0; } static int @@ -511,8 +511,8 @@ vhost_user_reconnect_init(void) } TAILQ_INIT(&reconn_list.head); - ret = rte_ctrl_thread_create(&reconn_tid, "dpdk-vhost-reco", NULL, - vhost_user_client_reconnect, NULL); + ret = rte_thread_create_internal_control(&reconn_tid, "vhost-reco", + vhost_user_client_reconnect, NULL); if (ret != 0) { VHOST_LOG_CONFIG("thread", ERR, "failed to create reconnect thread\n"); if (pthread_mutex_destroy(&reconn_list.mutex)) @@ -1004,7 +1004,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags) if (!vsocket->is_vduse) { if ((flags & RTE_VHOST_USER_CLIENT) != 0) { vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT); - if (vsocket->reconnect && reconn_tid == 0) { + if (vsocket->reconnect && reconn_tid.opaque_id == 0) { if (vhost_user_reconnect_init() != 0) goto out_mutex; } @@ -1174,7 +1174,7 @@ int rte_vhost_driver_start(const char *path) { struct vhost_user_socket *vsocket; - static pthread_t fdset_tid; + static rte_thread_t fdset_tid; pthread_mutex_lock(&vhost_user.mutex); vsocket = find_vhost_user_socket(path); @@ -1186,7 +1186,7 @@ rte_vhost_driver_start(const char *path) if (vsocket->is_vduse) return vduse_device_create(path, vsocket->net_compliant_ol_flags); - if (fdset_tid == 0) { + if (fdset_tid.opaque_id == 0) { /** * create a pipe which will be waited by poll and notified to * rebuild the wait list of poll. @@ -1196,9 +1196,8 @@ rte_vhost_driver_start(const char *path) return -1; } - int ret = rte_ctrl_thread_create(&fdset_tid, - "dpdk-vhost-evt", NULL, fdset_event_dispatch, - &vhost_user.fdset); + int ret = rte_thread_create_internal_control(&fdset_tid, + "vhost-evt", fdset_event_dispatch, &vhost_user.fdset); if (ret != 0) { VHOST_LOG_CONFIG(path, ERR, "failed to create fdset handling thread\n"); fdset_pipe_uninit(&vhost_user.fdset); diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index 7770259f37..e342f53b81 100644 --- a/lib/vhost/vduse.c +++ b/lib/vhost/vduse.c @@ -16,6 +16,7 @@ #include <sys/stat.h> #include <rte_common.h> +#include <rte_thread.h> #include "fd_man.h" #include "iotlb.h" @@ -415,7 +416,7 @@ int vduse_device_create(const char *path, bool compliant_ol_flags) { int control_fd, dev_fd, vid, ret; - pthread_t fdset_tid; + rte_thread_t fdset_tid; uint32_t i, max_queue_pairs, total_queues; struct virtio_net *dev; struct virtio_net_config vnet_config = {{ 0 }}; @@ -435,7 +436,7 @@ vduse_device_create(const char *path, bool compliant_ol_flags) return -1; } - ret = rte_ctrl_thread_create(&fdset_tid, "dpdk-vduse-evt", NULL, + ret = rte_thread_create_internal_control(&fdset_tid, "vduse-evt", fdset_event_dispatch, &vduse.fdset); if (ret != 0) { VHOST_LOG_CONFIG(path, ERR, "failed to create vduse fdset handling thread\n"); -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v3 07/11] drivers: convert to internal control threads 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon ` (5 preceding siblings ...) 2023-09-13 11:28 ` [PATCH v3 06/11] lib: convert to internal control threads Thomas Monjalon @ 2023-09-13 11:28 ` Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 08/11] examples: convert to normal " Thomas Monjalon ` (5 subsequent siblings) 12 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 11:28 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Andrew Rybchenko, Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao, Chengwen Feng, Kevin Laatz, Bruce Richardson, Abdullah Sevincer, Shepard Siegel, Ed Czeck, John Miller, Jingjing Wu, Beilei Xing, Qiming Yang, Qi Zhang, Rosen Xu, Wenjun Wu, Matan Azrad, Viacheslav Ovsiienko, Ori Kam, Suanming Mou, Jiawen Wu, Jian Wang, Tianfei Zhang, Xiao Wang, Vijay Kumar Srivastava Calls to rte_ctrl_thread_create() are replaced with rte_thread_create_internal_control(). Other pthread-related functions are replaced with the rte_thread API. Only pthread_cancel() has no replacement. The mlx5 vDPA control threads were real-time threads with an affinity on the core specified by the devarg "event_core". As there is no heavy performance requirement, these threads are converted into real control threads. Some threads in dlb2 and mlx5 are not control threads because they are designed to run on some specific cores. It would be interesting to rework them in future. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru> --- drivers/common/cnxk/roc_dev.c | 16 ++-- drivers/common/cnxk/roc_dev_priv.h | 2 +- drivers/common/cnxk/roc_nix_inl_dev.c | 9 +-- drivers/common/cnxk/roc_nix_inl_priv.h | 2 +- drivers/common/cnxk/roc_platform.h | 3 +- drivers/dma/skeleton/skeleton_dmadev.c | 7 +- drivers/event/dlb2/pf/base/dlb2_osdep.h | 14 ++-- drivers/event/dlb2/pf/base/dlb2_resource.c | 39 +++++----- drivers/event/dlb2/pf/dlb2_main.h | 1 - drivers/net/ark/ark_ethdev.c | 11 ++- drivers/net/ark/ark_pktgen.c | 8 +- drivers/net/ark/ark_pktgen.h | 2 +- drivers/net/iavf/iavf_vchnl.c | 2 +- drivers/net/ice/ice_dcf_parent.c | 7 +- drivers/net/ipn3ke/ipn3ke_representor.c | 17 ++--- drivers/net/ixgbe/ixgbe_ethdev.c | 7 +- drivers/net/mlx5/mlx5.h | 2 +- drivers/net/mlx5/mlx5_hws_cnt.c | 42 ++++++----- drivers/net/sfc/sfc_mae.h | 2 +- drivers/net/sfc/sfc_mae_counter.c | 11 ++- drivers/net/txgbe/txgbe_ethdev.c | 6 +- drivers/raw/ifpga/ifpga_rawdev.c | 19 +++-- drivers/vdpa/ifc/ifcvf_vdpa.c | 86 ++++++++++------------ drivers/vdpa/mlx5/mlx5_vdpa.c | 2 +- drivers/vdpa/mlx5/mlx5_vdpa.h | 10 +-- drivers/vdpa/mlx5/mlx5_vdpa_cthread.c | 70 +++++------------- drivers/vdpa/mlx5/mlx5_vdpa_event.c | 64 +++++----------- drivers/vdpa/sfc/sfc_vdpa_ops.c | 15 ++-- drivers/vdpa/sfc/sfc_vdpa_ops.h | 3 +- 29 files changed, 203 insertions(+), 276 deletions(-) diff --git a/drivers/common/cnxk/roc_dev.c b/drivers/common/cnxk/roc_dev.c index 13d3eece47..08fd13f741 100644 --- a/drivers/common/cnxk/roc_dev.c +++ b/drivers/common/cnxk/roc_dev.c @@ -18,7 +18,7 @@ #define ROC_PCI_SRIOV_TOTAL_VF 0x0e /* Total VFs */ /* VF Mbox handler thread name */ -#define MBOX_HANDLER_NAME_MAX_LEN 25 +#define MBOX_HANDLER_NAME_MAX_LEN RTE_THREAD_INTERNAL_NAME_SIZE /* VF interrupt message pending bits - mbox or flr */ #define ROC_DEV_MBOX_PEND BIT_ULL(0) @@ -1070,7 +1070,7 @@ vf_flr_handle_msg(void *param, dev_intr_t *flr) } } -static void * +static uint32_t pf_vf_mbox_thread_main(void *arg) { struct dev *dev = arg; @@ -1114,7 +1114,7 @@ pf_vf_mbox_thread_main(void *arg) pthread_mutex_unlock(&dev->sync.mutex); - return NULL; + return 0; } static void @@ -1455,10 +1455,10 @@ dev_init(struct dev *dev, struct plt_pci_device *pci_dev) pthread_cond_init(&dev->sync.pfvf_msg_cond, NULL); pthread_mutex_init(&dev->sync.mutex, NULL); - snprintf(name, MBOX_HANDLER_NAME_MAX_LEN, "pf%d_vf_msg_hndlr", dev->pf); + snprintf(name, MBOX_HANDLER_NAME_MAX_LEN, "mbox_pf%d", dev->pf); dev->sync.start_thread = true; - rc = plt_ctrl_thread_create(&dev->sync.pfvf_msg_thread, name, NULL, - pf_vf_mbox_thread_main, dev); + rc = plt_thread_create_control(&dev->sync.pfvf_msg_thread, name, + pf_vf_mbox_thread_main, dev); if (rc != 0) { plt_err("Failed to create thread for VF mbox handling\n"); goto iounmap; @@ -1488,7 +1488,7 @@ dev_init(struct dev *dev, struct plt_pci_device *pci_dev) if (dev->sync.start_thread) { dev->sync.start_thread = false; pthread_cond_signal(&dev->sync.pfvf_msg_cond); - pthread_join(dev->sync.pfvf_msg_thread, NULL); + plt_thread_join(dev->sync.pfvf_msg_thread, NULL); pthread_mutex_destroy(&dev->sync.mutex); pthread_cond_destroy(&dev->sync.pfvf_msg_cond); } @@ -1519,7 +1519,7 @@ dev_fini(struct dev *dev, struct plt_pci_device *pci_dev) if (dev->sync.start_thread) { dev->sync.start_thread = false; pthread_cond_signal(&dev->sync.pfvf_msg_cond); - pthread_join(dev->sync.pfvf_msg_thread, NULL); + plt_thread_join(dev->sync.pfvf_msg_thread, NULL); pthread_mutex_destroy(&dev->sync.mutex); pthread_cond_destroy(&dev->sync.pfvf_msg_cond); } diff --git a/drivers/common/cnxk/roc_dev_priv.h b/drivers/common/cnxk/roc_dev_priv.h index 1f84f74ff3..c1a37aa4f0 100644 --- a/drivers/common/cnxk/roc_dev_priv.h +++ b/drivers/common/cnxk/roc_dev_priv.h @@ -73,7 +73,7 @@ dev_is_afvf(uint16_t pf_func) struct mbox_sync { bool start_thread; uint8_t msg_avail; - pthread_t pfvf_msg_thread; + rte_thread_t pfvf_msg_thread; pthread_cond_t pfvf_msg_cond; pthread_mutex_t mutex; }; diff --git a/drivers/common/cnxk/roc_nix_inl_dev.c b/drivers/common/cnxk/roc_nix_inl_dev.c index d76158e30d..7400069309 100644 --- a/drivers/common/cnxk/roc_nix_inl_dev.c +++ b/drivers/common/cnxk/roc_nix_inl_dev.c @@ -746,7 +746,7 @@ inl_outb_soft_exp_poll(struct nix_inl_dev *inl_dev, uint32_t ring_idx) } } -static void * +static uint32_t nix_inl_outb_poll_thread(void *args) { struct nix_inl_dev *inl_dev = args; @@ -816,9 +816,8 @@ nix_inl_outb_poll_thread_setup(struct nix_inl_dev *inl_dev) soft_exp_consumer_cnt = 0; soft_exp_poll_thread_exit = false; - rc = plt_ctrl_thread_create(&inl_dev->soft_exp_poll_thread, - "OUTB_SOFT_EXP_POLL_THREAD", NULL, - nix_inl_outb_poll_thread, inl_dev); + rc = plt_thread_create_control(&inl_dev->soft_exp_poll_thread, + "outb-poll", nix_inl_outb_poll_thread, inl_dev); if (rc) { plt_bitmap_free(inl_dev->soft_exp_ring_bmap); plt_free(inl_dev->soft_exp_ring_bmap_mem); @@ -1020,7 +1019,7 @@ roc_nix_inl_dev_fini(struct roc_nix_inl_dev *roc_inl_dev) if (inl_dev->set_soft_exp_poll) { soft_exp_poll_thread_exit = true; - pthread_join(inl_dev->soft_exp_poll_thread, NULL); + rte_thread_join(inl_dev->soft_exp_poll_thread, NULL); plt_bitmap_free(inl_dev->soft_exp_ring_bmap); plt_free(inl_dev->soft_exp_ring_bmap_mem); plt_free(inl_dev->sa_soft_exp_ring); diff --git a/drivers/common/cnxk/roc_nix_inl_priv.h b/drivers/common/cnxk/roc_nix_inl_priv.h index b0a8976c6b..b2b89227b1 100644 --- a/drivers/common/cnxk/roc_nix_inl_priv.h +++ b/drivers/common/cnxk/roc_nix_inl_priv.h @@ -67,7 +67,7 @@ struct nix_inl_dev { struct roc_cpt_lf cpt_lf; /* OUTB soft expiry poll thread */ - pthread_t soft_exp_poll_thread; + rte_thread_t soft_exp_poll_thread; uint32_t soft_exp_poll_freq; uint64_t *sa_soft_exp_ring; bool set_soft_exp_poll; diff --git a/drivers/common/cnxk/roc_platform.h b/drivers/common/cnxk/roc_platform.h index 08f83aba12..d8f2707a6e 100644 --- a/drivers/common/cnxk/roc_platform.h +++ b/drivers/common/cnxk/roc_platform.h @@ -134,7 +134,8 @@ #define plt_intr_disable rte_intr_disable #define plt_thread_is_intr rte_thread_is_intr #define plt_intr_callback_fn rte_intr_callback_fn -#define plt_ctrl_thread_create rte_ctrl_thread_create +#define plt_thread_create_control rte_thread_create_internal_control +#define plt_thread_join rte_thread_join #define plt_intr_efd_counter_size_get rte_intr_efd_counter_size_get #define plt_intr_efd_counter_size_set rte_intr_efd_counter_size_set diff --git a/drivers/dma/skeleton/skeleton_dmadev.c b/drivers/dma/skeleton/skeleton_dmadev.c index 4fc2319668..eabe88fada 100644 --- a/drivers/dma/skeleton/skeleton_dmadev.c +++ b/drivers/dma/skeleton/skeleton_dmadev.c @@ -100,7 +100,7 @@ static int skeldma_start(struct rte_dma_dev *dev) { struct skeldma_hw *hw = dev->data->dev_private; - char name[RTE_MAX_THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; rte_cpuset_t cpuset; int ret; @@ -127,8 +127,9 @@ skeldma_start(struct rte_dma_dev *dev) rte_mb(); - snprintf(name, sizeof(name), "dpdk-dma-skel%d", dev->data->dev_id); - ret = rte_thread_create_control(&hw->thread, name, cpucopy_thread, dev); + snprintf(name, sizeof(name), "dma-skel%d", dev->data->dev_id); + ret = rte_thread_create_internal_control(&hw->thread, name, + cpucopy_thread, dev); if (ret) { SKELDMA_LOG(ERR, "Start cpucopy thread fail!"); return -EINVAL; diff --git a/drivers/event/dlb2/pf/base/dlb2_osdep.h b/drivers/event/dlb2/pf/base/dlb2_osdep.h index 75860cca4d..06d69f39b1 100644 --- a/drivers/event/dlb2/pf/base/dlb2_osdep.h +++ b/drivers/event/dlb2/pf/base/dlb2_osdep.h @@ -8,7 +8,6 @@ #include <string.h> #include <time.h> #include <unistd.h> -#include <pthread.h> #include <rte_string_fns.h> #include <rte_cycles.h> @@ -154,7 +153,7 @@ static inline void os_fence_hcw(struct dlb2_hw *hw, u64 *pp_addr) * map and unmap requests. To prevent deadlock, this function gives other * threads a chance to grab the resource mutex and configure hardware. */ -static void *dlb2_complete_queue_map_unmap(void *__args) +static uint32_t dlb2_complete_queue_map_unmap(void *__args) { struct dlb2_dev *dlb2_dev = (struct dlb2_dev *)__args; int ret; @@ -180,7 +179,7 @@ static void *dlb2_complete_queue_map_unmap(void *__args) rte_spinlock_unlock(&dlb2_dev->resource_mutex); - return NULL; + return 0; } @@ -194,16 +193,13 @@ static void *dlb2_complete_queue_map_unmap(void *__args) static inline void os_schedule_work(struct dlb2_hw *hw) { struct dlb2_dev *dlb2_dev; - pthread_t complete_queue_map_unmap_thread; + rte_thread_t complete_queue_map_unmap_thread; int ret; dlb2_dev = container_of(hw, struct dlb2_dev, hw); - ret = rte_ctrl_thread_create(&complete_queue_map_unmap_thread, - "dpdk-dlb-qunmap", - NULL, - dlb2_complete_queue_map_unmap, - dlb2_dev); + ret = rte_thread_create_internal_control(&complete_queue_map_unmap_thread, + "dlb-qunmap", dlb2_complete_queue_map_unmap, dlb2_dev); if (ret) DLB2_ERR(dlb2_dev, "Could not create queue complete map/unmap thread, err=%d\n", diff --git a/drivers/event/dlb2/pf/base/dlb2_resource.c b/drivers/event/dlb2/pf/base/dlb2_resource.c index dd8390a013..7ce3e3531c 100644 --- a/drivers/event/dlb2/pf/base/dlb2_resource.c +++ b/drivers/event/dlb2/pf/base/dlb2_resource.c @@ -759,18 +759,13 @@ static int dlb2_attach_ldb_queues(struct dlb2_hw *hw, } static int -dlb2_pp_profile(struct dlb2_hw *hw, int port, int cpu, bool is_ldb) +dlb2_pp_profile(struct dlb2_hw *hw, int port, bool is_ldb) { u64 cycle_start = 0ULL, cycle_end = 0ULL; struct dlb2_hcw hcw_mem[DLB2_HCW_MEM_SIZE], *hcw; void __iomem *pp_addr; - cpu_set_t cpuset; int i; - CPU_ZERO(&cpuset); - CPU_SET(cpu, &cpuset); - sched_setaffinity(0, sizeof(cpuset), &cpuset); - pp_addr = os_map_producer_port(hw, port, is_ldb); /* Point hcw to a 64B-aligned location */ @@ -797,18 +792,15 @@ dlb2_pp_profile(struct dlb2_hw *hw, int port, int cpu, bool is_ldb) return (int)(cycle_end - cycle_start); } -static void * +static uint32_t dlb2_pp_profile_func(void *data) { struct dlb2_pp_thread_data *thread_data = data; - int cycles; - cycles = dlb2_pp_profile(thread_data->hw, thread_data->pp, - thread_data->cpu, thread_data->is_ldb); + thread_data->cycles = dlb2_pp_profile(thread_data->hw, + thread_data->pp, thread_data->is_ldb); - thread_data->cycles = cycles; - - return NULL; + return 0; } static int dlb2_pp_cycle_comp(const void *a, const void *b) @@ -831,7 +823,9 @@ dlb2_get_pp_allocation(struct dlb2_hw *hw, int cpu, int port_type) int num_ports_per_sort, num_ports, num_sort, i, err; bool is_ldb = (port_type == DLB2_LDB_PORT); int *port_allocations; - pthread_t pthread; + rte_thread_t thread; + rte_thread_attr_t th_attr; + char th_name[RTE_THREAD_INTERNAL_NAME_SIZE]; if (is_ldb) { port_allocations = hw->ldb_pp_allocations; @@ -857,16 +851,25 @@ dlb2_get_pp_allocation(struct dlb2_hw *hw, int cpu, int port_type) dlb2_thread_data[i].pp = i; dlb2_thread_data[i].cycles = 0; dlb2_thread_data[i].hw = hw; - dlb2_thread_data[i].cpu = cpu; - err = pthread_create(&pthread, NULL, &dlb2_pp_profile_func, - &dlb2_thread_data[i]); + err = rte_thread_attr_init(&th_attr); + if (err != 0) { + DLB2_LOG_ERR(": thread attribute failed! err=%d", err); + return; + } + CPU_SET(cpu, &th_attr.cpuset); + + err = rte_thread_create(&thread, &th_attr, + &dlb2_pp_profile_func, &dlb2_thread_data[i]); if (err) { DLB2_LOG_ERR(": thread creation failed! err=%d", err); return; } - err = pthread_join(pthread, NULL); + snprintf(th_name, sizeof(th_name), "dlb2-pp%d", cpu); + rte_thread_set_prefixed_name(thread, th_name); + + err = rte_thread_join(thread, NULL); if (err) { DLB2_LOG_ERR(": thread join failed! err=%d", err); return; diff --git a/drivers/event/dlb2/pf/dlb2_main.h b/drivers/event/dlb2/pf/dlb2_main.h index 4c64d72e9c..12912a2dec 100644 --- a/drivers/event/dlb2/pf/dlb2_main.h +++ b/drivers/event/dlb2/pf/dlb2_main.h @@ -52,7 +52,6 @@ struct dlb2_dev { struct dlb2_pp_thread_data { struct dlb2_hw *hw; int pp; - int cpu; bool is_ldb; int cycles; }; diff --git a/drivers/net/ark/ark_ethdev.c b/drivers/net/ark/ark_ethdev.c index 30814650bf..3ddcc9b461 100644 --- a/drivers/net/ark/ark_ethdev.c +++ b/drivers/net/ark/ark_ethdev.c @@ -598,17 +598,16 @@ eth_ark_dev_start(struct rte_eth_dev *dev) ark_pktchkr_run(ark->pc); if (!ark->isvf && ark->start_pg && !ark->pg_running) { - pthread_t thread; + rte_thread_t thread; /* Delay packet generator start allow the hardware to be ready * This is only used for sanity checking with internal generator */ - char tname[32]; - snprintf(tname, sizeof(tname), "dpdk-ark-pg%d", - dev->data->port_id); + char tname[RTE_THREAD_INTERNAL_NAME_SIZE]; + snprintf(tname, sizeof(tname), "ark-pg%d", dev->data->port_id); - if (rte_ctrl_thread_create(&thread, tname, NULL, - ark_pktgen_delay_start, ark->pg)) { + if (rte_thread_create_internal_control(&thread, tname, + ark_pktgen_delay_start, ark->pg)) { ARK_PMD_LOG(ERR, "Could not create pktgen " "starter thread\n"); return -1; diff --git a/drivers/net/ark/ark_pktgen.c b/drivers/net/ark/ark_pktgen.c index cd2d3adc51..69ff7072b2 100644 --- a/drivers/net/ark/ark_pktgen.c +++ b/drivers/net/ark/ark_pktgen.c @@ -4,10 +4,10 @@ #include <stdlib.h> #include <unistd.h> -#include <pthread.h> #include <rte_string_fns.h> #include <rte_malloc.h> +#include <rte_thread.h> #include "ark_pktgen.h" #include "ark_logs.h" @@ -467,7 +467,7 @@ ark_pktgen_setup(ark_pkt_gen_t handle) } } -void * +uint32_t ark_pktgen_delay_start(void *arg) { struct ark_pkt_gen_inst *inst = (struct ark_pkt_gen_inst *)arg; @@ -476,8 +476,8 @@ ark_pktgen_delay_start(void *arg) * perform a blind sleep here to ensure that the external test * application has time to setup the test before we generate packets */ - pthread_detach(pthread_self()); + rte_thread_detach(rte_thread_self()); usleep(100000); ark_pktgen_run(inst); - return NULL; + return 0; } diff --git a/drivers/net/ark/ark_pktgen.h b/drivers/net/ark/ark_pktgen.h index 7147fe1bd4..925058367c 100644 --- a/drivers/net/ark/ark_pktgen.h +++ b/drivers/net/ark/ark_pktgen.h @@ -75,6 +75,6 @@ void ark_pktgen_set_hdr_dW(ark_pkt_gen_t handle, uint32_t *hdr); void ark_pktgen_set_start_offset(ark_pkt_gen_t handle, uint32_t x); void ark_pktgen_parse(char *argv); void ark_pktgen_setup(ark_pkt_gen_t handle); -void *ark_pktgen_delay_start(void *arg); +uint32_t ark_pktgen_delay_start(void *arg); #endif diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c index 6baa6d5955..b3e106b41f 100644 --- a/drivers/net/iavf/iavf_vchnl.c +++ b/drivers/net/iavf/iavf_vchnl.c @@ -135,7 +135,7 @@ iavf_dev_event_handler_init(void) TAILQ_INIT(&handler->pending); pthread_mutex_init(&handler->lock, NULL); - if (rte_thread_create_control(&handler->tid, "dpdk-iavf-event", + if (rte_thread_create_internal_control(&handler->tid, "iavf-event", iavf_dev_event_handle, NULL)) { __atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED); return -1; diff --git a/drivers/net/ice/ice_dcf_parent.c b/drivers/net/ice/ice_dcf_parent.c index d3bb65874f..173ed9f81d 100644 --- a/drivers/net/ice/ice_dcf_parent.c +++ b/drivers/net/ice/ice_dcf_parent.c @@ -165,9 +165,8 @@ ice_dcf_vsi_update_service_handler(void *param) static void start_vsi_reset_thread(struct ice_dcf_hw *dcf_hw, bool vfr, uint16_t vf_id) { -#define THREAD_NAME_LEN 16 struct ice_dcf_reset_event_param *param; - char name[THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; rte_thread_t thread; int ret; @@ -181,8 +180,8 @@ start_vsi_reset_thread(struct ice_dcf_hw *dcf_hw, bool vfr, uint16_t vf_id) param->vfr = vfr; param->vf_id = vf_id; - snprintf(name, sizeof(name), "dpdk-ice-rst%u", vf_id); - ret = rte_thread_create_control(&thread, name, + snprintf(name, sizeof(name), "ice-rst%u", vf_id); + ret = rte_thread_create_internal_control(&thread, name, ice_dcf_vsi_update_service_handler, param); if (ret != 0) { PMD_DRV_LOG(ERR, "Failed to start the thread for reset handling"); diff --git a/drivers/net/ipn3ke/ipn3ke_representor.c b/drivers/net/ipn3ke/ipn3ke_representor.c index c82f8b5333..57ec7a19bc 100644 --- a/drivers/net/ipn3ke/ipn3ke_representor.c +++ b/drivers/net/ipn3ke/ipn3ke_representor.c @@ -27,7 +27,7 @@ #include "ipn3ke_ethdev.h" static int ipn3ke_rpst_scan_num; -static pthread_t ipn3ke_rpst_scan_thread; +static rte_thread_t ipn3ke_rpst_scan_thread; /** Double linked list of representor port. */ TAILQ_HEAD(ipn3ke_rpst_list, ipn3ke_rpst); @@ -2558,7 +2558,7 @@ ipn3ke_rpst_link_check(struct ipn3ke_rpst *rpst) return 0; } -static void * +static uint32_t ipn3ke_rpst_scan_handle_request(__rte_unused void *param) { struct ipn3ke_rpst *rpst; @@ -2580,10 +2580,10 @@ ipn3ke_rpst_scan_handle_request(__rte_unused void *param) rte_delay_us(50 * MS); if (num == 0 || num == 0xffffff) - return NULL; + return 0; } - return NULL; + return 0; } static int @@ -2592,20 +2592,19 @@ ipn3ke_rpst_scan_check(void) int ret; if (ipn3ke_rpst_scan_num == 1) { - ret = rte_ctrl_thread_create(&ipn3ke_rpst_scan_thread, - "dpdk-ipn3ke-scn", - NULL, + ret = rte_thread_create_internal_control(&ipn3ke_rpst_scan_thread, + "ipn3ke-scn", ipn3ke_rpst_scan_handle_request, NULL); if (ret) { IPN3KE_AFU_PMD_ERR("Fail to create ipn3ke rpst scan thread"); return -1; } } else if (ipn3ke_rpst_scan_num == 0) { - ret = pthread_cancel(ipn3ke_rpst_scan_thread); + ret = pthread_cancel((pthread_t)ipn3ke_rpst_scan_thread.opaque_id); if (ret) IPN3KE_AFU_PMD_ERR("Can't cancel the thread"); - ret = pthread_join(ipn3ke_rpst_scan_thread, NULL); + ret = rte_thread_join(ipn3ke_rpst_scan_thread, NULL); if (ret) IPN3KE_AFU_PMD_ERR("Can't join the thread"); diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c index 64e7e5d7d6..cd4a85b3a7 100644 --- a/drivers/net/ixgbe/ixgbe_ethdev.c +++ b/drivers/net/ixgbe/ixgbe_ethdev.c @@ -4328,10 +4328,9 @@ ixgbe_dev_link_update_share(struct rte_eth_dev *dev, * when there is no link thread running. */ intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; - if (rte_thread_create_control(&ad->link_thread_tid, - "dpdk-ixgbe-link", - ixgbe_dev_setup_link_thread_handler, - dev) < 0) { + if (rte_thread_create_internal_control(&ad->link_thread_tid, + "ixgbe-link", + ixgbe_dev_setup_link_thread_handler, dev) < 0) { PMD_DRV_LOG(ERR, "Create link thread failed!"); /* NOTE: review for potential ordering optimization */ diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 3785103308..c587e13c63 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1368,7 +1368,7 @@ struct mlx5_hws_cnt_svc_mng { uint32_t refcnt; uint32_t service_core; uint32_t query_interval; - pthread_t service_thread; + rte_thread_t service_thread; uint8_t svc_running; struct mlx5_hws_aso_mng aso_mng __rte_cache_aligned; }; diff --git a/drivers/net/mlx5/mlx5_hws_cnt.c b/drivers/net/mlx5/mlx5_hws_cnt.c index a0f0febbc7..f556a9fbcc 100644 --- a/drivers/net/mlx5/mlx5_hws_cnt.c +++ b/drivers/net/mlx5/mlx5_hws_cnt.c @@ -9,6 +9,7 @@ #include <mlx5_devx_cmds.h> #include <rte_cycles.h> #include <rte_eal_paging.h> +#include <rte_thread.h> #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) @@ -286,7 +287,7 @@ mlx5_hws_cnt_raw_data_alloc(struct mlx5_dev_ctx_shared *sh, uint32_t n) return NULL; } -static void * +static uint32_t mlx5_hws_cnt_svc(void *opaque) { struct mlx5_dev_ctx_shared *sh = @@ -318,7 +319,7 @@ mlx5_hws_cnt_svc(void *opaque) if (interval > query_us) rte_delay_us_sleep(sleep_us); } - return NULL; + return 0; } static void @@ -438,36 +439,37 @@ mlx5_hws_cnt_pool_init(struct mlx5_dev_ctx_shared *sh, int mlx5_hws_cnt_service_thread_create(struct mlx5_dev_ctx_shared *sh) { - char name[RTE_MAX_THREAD_NAME_LEN]; - rte_cpuset_t cpuset; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; + rte_thread_attr_t attr; int ret; uint32_t service_core = sh->cnt_svc->service_core; - CPU_ZERO(&cpuset); + ret = rte_thread_attr_init(&attr); + if (ret != 0) + goto error; + CPU_SET(service_core, &attr.cpuset); sh->cnt_svc->svc_running = 1; - ret = pthread_create(&sh->cnt_svc->service_thread, NULL, - mlx5_hws_cnt_svc, sh); - if (ret != 0) { - DRV_LOG(ERR, "Failed to create HW steering's counter service thread."); - return -ENOSYS; - } - snprintf(name, RTE_MAX_THREAD_NAME_LEN, "dpdk-mlx5-%d", service_core); - rte_thread_set_name((rte_thread_t){(uintptr_t)sh->cnt_svc->service_thread}, - name); - CPU_SET(service_core, &cpuset); - pthread_setaffinity_np(sh->cnt_svc->service_thread, sizeof(cpuset), - &cpuset); + ret = rte_thread_create(&sh->cnt_svc->service_thread, + &attr, mlx5_hws_cnt_svc, sh); + if (ret != 0) + goto error; + snprintf(name, sizeof(name), "mlx5-cn%d", service_core); + rte_thread_set_prefixed_name(sh->cnt_svc->service_thread, name); + return 0; +error: + DRV_LOG(ERR, "Failed to create HW steering's counter service thread."); + return ret; } void mlx5_hws_cnt_service_thread_destroy(struct mlx5_dev_ctx_shared *sh) { - if (sh->cnt_svc->service_thread == 0) + if (sh->cnt_svc->service_thread.opaque_id == 0) return; sh->cnt_svc->svc_running = 0; - pthread_join(sh->cnt_svc->service_thread, NULL); - sh->cnt_svc->service_thread = 0; + rte_thread_join(sh->cnt_svc->service_thread, NULL); + sh->cnt_svc->service_thread.opaque_id = 0; } static int diff --git a/drivers/net/sfc/sfc_mae.h b/drivers/net/sfc/sfc_mae.h index 646d055ac1..7988424449 100644 --- a/drivers/net/sfc/sfc_mae.h +++ b/drivers/net/sfc/sfc_mae.h @@ -196,7 +196,7 @@ struct sfc_mae_counter_registry { } service; struct { /** Counter thread ID */ - pthread_t id; + rte_thread_t id; /** The thread should keep running */ bool run; } thread; diff --git a/drivers/net/sfc/sfc_mae_counter.c b/drivers/net/sfc/sfc_mae_counter.c index 631b54afeb..ba17295719 100644 --- a/drivers/net/sfc/sfc_mae_counter.c +++ b/drivers/net/sfc/sfc_mae_counter.c @@ -490,7 +490,7 @@ sfc_mae_counter_service_routine(void *arg) return 0; } -static void * +static uint32_t sfc_mae_counter_thread(void *data) { struct sfc_adapter *sa = data; @@ -521,7 +521,7 @@ sfc_mae_counter_thread(void *data) } } - return NULL; + return 0; } static void @@ -687,7 +687,7 @@ sfc_mae_counter_thread_stop(struct sfc_adapter *sa) __atomic_store_n(&counter_registry->polling.thread.run, false, __ATOMIC_RELEASE); - rc = pthread_join(counter_registry->polling.thread.id, NULL); + rc = rte_thread_join(counter_registry->polling.thread.id, NULL); if (rc != 0) sfc_err(sa, "failed to join the MAE counter polling thread"); @@ -710,9 +710,8 @@ sfc_mae_counter_thread_spawn(struct sfc_adapter *sa, counter_registry->polling_mode = SFC_MAE_COUNTER_POLLING_THREAD; counter_registry->polling.thread.run = true; - rc = rte_ctrl_thread_create(&sa->mae.counter_registry.polling.thread.id, - "dpdk-sfc-maecnt", NULL, - sfc_mae_counter_thread, sa); + rc = rte_thread_create_internal_control(&sa->mae.counter_registry.polling.thread.id, + "sfc-maecnt", sfc_mae_counter_thread, sa); return rc; } diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c index 198fac8318..15911a3621 100644 --- a/drivers/net/txgbe/txgbe_ethdev.c +++ b/drivers/net/txgbe/txgbe_ethdev.c @@ -2896,9 +2896,9 @@ txgbe_dev_link_update_share(struct rte_eth_dev *dev, * when there is no link thread running. */ intr->flags |= TXGBE_FLAG_NEED_LINK_CONFIG; - if (rte_thread_create_control(&ad->link_thread_tid, - "dpdk-txgbe-link", - txgbe_dev_setup_link_thread_handler, dev) < 0) { + if (rte_thread_create_internal_control(&ad->link_thread_tid, + "txgbe-link", + txgbe_dev_setup_link_thread_handler, dev) < 0) { PMD_DRV_LOG(ERR, "Create link thread failed!"); __atomic_clear(&ad->link_thread_running, __ATOMIC_SEQ_CST); } diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c index a7b18299de..f89bd3f9e2 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.c +++ b/drivers/raw/ifpga/ifpga_rawdev.c @@ -74,7 +74,7 @@ static const struct rte_pci_id pci_ifpga_map[] = { static struct ifpga_rawdev ifpga_rawdevices[IFPGA_RAWDEV_NUM]; static int ifpga_monitor_refcnt; -static pthread_t ifpga_monitor_start_thread; +static rte_thread_t ifpga_monitor_start_thread; static struct ifpga_rawdev * ifpga_rawdev_allocate(struct rte_rawdev *rawdev); @@ -504,7 +504,7 @@ static int set_surprise_link_check_aer( return -EFAULT; } -static void * +static uint32_t ifpga_rawdev_gsd_handle(__rte_unused void *param) { struct ifpga_rawdev *ifpga_rdev; @@ -532,7 +532,7 @@ ifpga_rawdev_gsd_handle(__rte_unused void *param) rte_delay_us(100 * MS); } - return NULL; + return 0; } static int @@ -550,11 +550,10 @@ ifpga_monitor_start_func(struct ifpga_rawdev *dev) dev->poll_enabled = 1; if (!__atomic_fetch_add(&ifpga_monitor_refcnt, 1, __ATOMIC_RELAXED)) { - ret = rte_ctrl_thread_create(&ifpga_monitor_start_thread, - "dpdk-ifpga-mon", NULL, - ifpga_rawdev_gsd_handle, NULL); + ret = rte_thread_create_internal_control(&ifpga_monitor_start_thread, + "ifpga-mon", ifpga_rawdev_gsd_handle, NULL); if (ret != 0) { - ifpga_monitor_start_thread = 0; + ifpga_monitor_start_thread.opaque_id = 0; IFPGA_RAWDEV_PMD_ERR( "Fail to create ifpga monitor thread"); return -1; @@ -575,12 +574,12 @@ ifpga_monitor_stop_func(struct ifpga_rawdev *dev) dev->poll_enabled = 0; if (!(__atomic_fetch_sub(&ifpga_monitor_refcnt, 1, __ATOMIC_RELAXED) - 1) && - ifpga_monitor_start_thread) { - ret = pthread_cancel(ifpga_monitor_start_thread); + ifpga_monitor_start_thread.opaque_id != 0) { + ret = pthread_cancel((pthread_t)ifpga_monitor_start_thread.opaque_id); if (ret) IFPGA_RAWDEV_PMD_ERR("Can't cancel the thread"); - ret = pthread_join(ifpga_monitor_start_thread, NULL); + ret = rte_thread_join(ifpga_monitor_start_thread, NULL); if (ret) IFPGA_RAWDEV_PMD_ERR("Can't join the thread"); diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c index 55346bbc08..f034bd59ba 100644 --- a/drivers/vdpa/ifc/ifcvf_vdpa.c +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c @@ -58,8 +58,8 @@ struct ifcvf_internal { int vfio_container_fd; int vfio_group_fd; int vfio_dev_fd; - pthread_t tid; /* thread for notify relay */ - pthread_t intr_tid; /* thread for config space change interrupt relay */ + rte_thread_t tid; /* thread for notify relay */ + rte_thread_t intr_tid; /* thread for config space change interrupt relay */ int epfd; int csc_epfd; int vid; @@ -496,7 +496,7 @@ vdpa_disable_vfio_intr(struct ifcvf_internal *internal) return 0; } -static void * +static uint32_t notify_relay(void *arg) { int i, kickfd, epfd, nfds = 0; @@ -514,7 +514,7 @@ notify_relay(void *arg) epfd = epoll_create(IFCVF_MAX_QUEUES * 2); if (epfd < 0) { DRV_LOG(ERR, "failed to create epoll instance."); - return NULL; + return 1; } internal->epfd = epfd; @@ -527,7 +527,7 @@ notify_relay(void *arg) ev.data.u64 = qid | (uint64_t)vring.kickfd << 32; if (epoll_ctl(epfd, EPOLL_CTL_ADD, vring.kickfd, &ev) < 0) { DRV_LOG(ERR, "epoll add error: %s", strerror(errno)); - return NULL; + return 1; } } @@ -537,7 +537,7 @@ notify_relay(void *arg) if (errno == EINTR) continue; DRV_LOG(ERR, "epoll_wait return fail\n"); - return NULL; + return 1; } for (i = 0; i < nfds; i++) { @@ -561,18 +561,18 @@ notify_relay(void *arg) } } - return NULL; + return 0; } static int setup_notify_relay(struct ifcvf_internal *internal) { - char name[THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; int ret; - snprintf(name, sizeof(name), "dpdk-ifc-noti%d", internal->vid); - ret = rte_ctrl_thread_create(&internal->tid, name, NULL, notify_relay, - (void *)internal); + snprintf(name, sizeof(name), "ifc-noti%d", internal->vid); + ret = rte_thread_create_internal_control(&internal->tid, name, + notify_relay, internal); if (ret != 0) { DRV_LOG(ERR, "failed to create notify relay pthread."); return -1; @@ -584,13 +584,11 @@ setup_notify_relay(struct ifcvf_internal *internal) static int unset_notify_relay(struct ifcvf_internal *internal) { - void *status; - - if (internal->tid) { - pthread_cancel(internal->tid); - pthread_join(internal->tid, &status); + if (internal->tid.opaque_id != 0) { + pthread_cancel((pthread_t)internal->tid.opaque_id); + rte_thread_join(internal->tid, NULL); } - internal->tid = 0; + internal->tid.opaque_id = 0; if (internal->epfd >= 0) close(internal->epfd); @@ -610,7 +608,7 @@ virtio_interrupt_handler(struct ifcvf_internal *internal) DRV_LOG(ERR, "failed to notify the guest about configuration space change."); } -static void * +static uint32_t intr_relay(void *arg) { struct ifcvf_internal *internal = (struct ifcvf_internal *)arg; @@ -623,7 +621,7 @@ intr_relay(void *arg) csc_epfd = epoll_create(1); if (csc_epfd < 0) { DRV_LOG(ERR, "failed to create epoll for config space change."); - return NULL; + return 1; } ev.events = EPOLLIN | EPOLLPRI | EPOLLRDHUP | EPOLLHUP; @@ -672,18 +670,18 @@ intr_relay(void *arg) close(csc_epfd); internal->csc_epfd = -1; - return NULL; + return 0; } static int setup_intr_relay(struct ifcvf_internal *internal) { - char name[THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; int ret; - snprintf(name, sizeof(name), "dpdk-ifc-int%d", internal->vid); - ret = rte_ctrl_thread_create(&internal->intr_tid, name, NULL, - intr_relay, (void *)internal); + snprintf(name, sizeof(name), "ifc-int%d", internal->vid); + ret = rte_thread_create_internal_control(&internal->intr_tid, name, + intr_relay, (void *)internal); if (ret) { DRV_LOG(ERR, "failed to create notify relay pthread."); return -1; @@ -694,13 +692,11 @@ setup_intr_relay(struct ifcvf_internal *internal) static void unset_intr_relay(struct ifcvf_internal *internal) { - void *status; - - if (internal->intr_tid) { - pthread_cancel(internal->intr_tid); - pthread_join(internal->intr_tid, &status); + if (internal->intr_tid.opaque_id != 0) { + pthread_cancel((pthread_t)internal->intr_tid.opaque_id); + rte_thread_join(internal->intr_tid, NULL); } - internal->intr_tid = 0; + internal->intr_tid.opaque_id = 0; if (internal->csc_epfd >= 0) close(internal->csc_epfd); @@ -922,7 +918,7 @@ update_used_ring(struct ifcvf_internal *internal, uint16_t qid) rte_vhost_vring_call(internal->vid, qid); } -static void * +static uint32_t vring_relay(void *arg) { int i, vid, epfd, fd, nfds; @@ -941,7 +937,7 @@ vring_relay(void *arg) epfd = epoll_create(IFCVF_MAX_QUEUES * 2); if (epfd < 0) { DRV_LOG(ERR, "failed to create epoll instance."); - return NULL; + return 1; } internal->epfd = epfd; @@ -952,7 +948,7 @@ vring_relay(void *arg) ev.data.u64 = qid << 1 | (uint64_t)vring.kickfd << 32; if (epoll_ctl(epfd, EPOLL_CTL_ADD, vring.kickfd, &ev) < 0) { DRV_LOG(ERR, "epoll add error: %s", strerror(errno)); - return NULL; + return 1; } } @@ -966,7 +962,7 @@ vring_relay(void *arg) if (epoll_ctl(epfd, EPOLL_CTL_ADD, internal->intr_fd[qid], &ev) < 0) { DRV_LOG(ERR, "epoll add error: %s", strerror(errno)); - return NULL; + return 1; } update_used_ring(internal, qid); } @@ -982,7 +978,7 @@ vring_relay(void *arg) if (errno == EINTR) continue; DRV_LOG(ERR, "epoll_wait return fail."); - return NULL; + return 1; } for (i = 0; i < nfds; i++) { @@ -1010,18 +1006,18 @@ vring_relay(void *arg) } } - return NULL; + return 0; } static int setup_vring_relay(struct ifcvf_internal *internal) { - char name[THREAD_NAME_LEN]; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; int ret; - snprintf(name, sizeof(name), "dpdk-ifc-ring%d", internal->vid); - ret = rte_ctrl_thread_create(&internal->tid, name, NULL, vring_relay, - (void *)internal); + snprintf(name, sizeof(name), "ifc-ring%d", internal->vid); + ret = rte_thread_create_internal_control(&internal->tid, name, + vring_relay, internal); if (ret != 0) { DRV_LOG(ERR, "failed to create ring relay pthread."); return -1; @@ -1033,13 +1029,11 @@ setup_vring_relay(struct ifcvf_internal *internal) static int unset_vring_relay(struct ifcvf_internal *internal) { - void *status; - - if (internal->tid) { - pthread_cancel(internal->tid); - pthread_join(internal->tid, &status); + if (internal->tid.opaque_id != 0) { + pthread_cancel((pthread_t)internal->tid.opaque_id); + rte_thread_join(internal->tid, NULL); } - internal->tid = 0; + internal->tid.opaque_id = 0; if (internal->epfd >= 0) close(internal->epfd); diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c index f1737f82a8..01a5877d08 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c @@ -844,7 +844,7 @@ mlx5_vdpa_dev_probe(struct mlx5_common_device *cdev, mlx5_vdpa_config_get(mkvlist, priv); if (priv->use_c_thread) { if (conf_thread_mng.initializer_priv == priv) - if (mlx5_vdpa_mult_threads_create(priv->event_core)) + if (mlx5_vdpa_mult_threads_create()) goto error; __atomic_fetch_add(&conf_thread_mng.refcnt, 1, __ATOMIC_RELAXED); diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h index dc4dfba5ed..7b37c98e74 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/mlx5_vdpa.h @@ -19,6 +19,7 @@ #endif #include <rte_spinlock.h> #include <rte_interrupts.h> +#include <rte_thread.h> #include <mlx5_glue.h> #include <mlx5_devx_cmds.h> @@ -99,7 +100,7 @@ struct mlx5_vdpa_task { /* Generic mlx5_vdpa_c_thread information. */ struct mlx5_vdpa_c_thread { - pthread_t tid; + rte_thread_t tid; struct rte_ring *rng; pthread_cond_t c_cond; }; @@ -182,7 +183,7 @@ struct mlx5_vdpa_priv { rte_spinlock_t db_lock; pthread_mutex_t steer_update_lock; uint64_t no_traffic_counter; - pthread_t timer_tid; + rte_thread_t timer_tid; int event_mode; int event_core; /* Event thread cpu affinity core. */ uint32_t event_us; @@ -563,14 +564,11 @@ mlx5_vdpa_is_modify_virtq_supported(struct mlx5_vdpa_priv *priv); /** * Create configuration multi-threads resource * - * @param[in] cpu_core - * CPU core number to set configuration threads affinity to. - * * @return * 0 on success, a negative value otherwise. */ int -mlx5_vdpa_mult_threads_create(int cpu_core); +mlx5_vdpa_mult_threads_create(void); /** * Destroy configuration multi-threads resource diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_cthread.c b/drivers/vdpa/mlx5/mlx5_vdpa_cthread.c index a1d291bf71..1a5fd3eb17 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa_cthread.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa_cthread.c @@ -96,11 +96,10 @@ mlx5_vdpa_c_thread_wait_bulk_tasks_done(uint32_t *remaining_cnt, return false; } -static void * +static uint32_t mlx5_vdpa_c_thread_handle(void *arg) { struct mlx5_vdpa_conf_thread_mng *multhrd = arg; - pthread_t thread_id = pthread_self(); struct mlx5_vdpa_virtq *virtq; struct mlx5_vdpa_priv *priv; struct mlx5_vdpa_task task; @@ -112,10 +111,10 @@ mlx5_vdpa_c_thread_handle(void *arg) for (thrd_idx = 0; thrd_idx < multhrd->max_thrds; thrd_idx++) - if (multhrd->cthrd[thrd_idx].tid == thread_id) + if (rte_thread_equal(multhrd->cthrd[thrd_idx].tid, rte_thread_self())) break; if (thrd_idx >= multhrd->max_thrds) - return NULL; + return 1; rng = multhrd->cthrd[thrd_idx].rng; while (1) { task_num = mlx5_vdpa_c_thrd_ring_dequeue_bulk(rng, @@ -227,16 +226,17 @@ mlx5_vdpa_c_thread_handle(void *arg) __atomic_fetch_sub(task.remaining_cnt, 1, __ATOMIC_RELAXED); } - return NULL; + return 0; } static void mlx5_vdpa_c_thread_destroy(uint32_t thrd_idx, bool need_unlock) { - if (conf_thread_mng.cthrd[thrd_idx].tid) { - pthread_cancel(conf_thread_mng.cthrd[thrd_idx].tid); - pthread_join(conf_thread_mng.cthrd[thrd_idx].tid, NULL); - conf_thread_mng.cthrd[thrd_idx].tid = 0; + pthread_t *tid = (pthread_t *)&conf_thread_mng.cthrd[thrd_idx].tid.opaque_id; + if (*tid != 0) { + pthread_cancel(*tid); + rte_thread_join(conf_thread_mng.cthrd[thrd_idx].tid, NULL); + *tid = 0; if (need_unlock) pthread_mutex_init(&conf_thread_mng.cthrd_lock, NULL); } @@ -247,30 +247,14 @@ mlx5_vdpa_c_thread_destroy(uint32_t thrd_idx, bool need_unlock) } static int -mlx5_vdpa_c_thread_create(int cpu_core) +mlx5_vdpa_c_thread_create(void) { - const struct sched_param sp = { - .sched_priority = sched_get_priority_max(SCHED_RR), - }; - rte_cpuset_t cpuset; - pthread_attr_t attr; uint32_t thrd_idx; uint32_t ring_num; - char name[32]; + char name[RTE_RING_NAMESIZE]; int ret; pthread_mutex_lock(&conf_thread_mng.cthrd_lock); - pthread_attr_init(&attr); - ret = pthread_attr_setschedpolicy(&attr, SCHED_RR); - if (ret) { - DRV_LOG(ERR, "Failed to set thread sched policy = RR."); - goto c_thread_err; - } - ret = pthread_attr_setschedparam(&attr, &sp); - if (ret) { - DRV_LOG(ERR, "Failed to set thread priority."); - goto c_thread_err; - } ring_num = MLX5_VDPA_MAX_TASKS_PER_THRD / conf_thread_mng.max_thrds; if (!ring_num) { DRV_LOG(ERR, "Invalid ring number for thread."); @@ -291,35 +275,15 @@ mlx5_vdpa_c_thread_create(int cpu_core) thrd_idx); goto c_thread_err; } - ret = pthread_create(&conf_thread_mng.cthrd[thrd_idx].tid, - &attr, mlx5_vdpa_c_thread_handle, - (void *)&conf_thread_mng); + snprintf(name, RTE_THREAD_INTERNAL_NAME_SIZE, "vmlx5-c%d", thrd_idx); + ret = rte_thread_create_internal_control(&conf_thread_mng.cthrd[thrd_idx].tid, + name, + mlx5_vdpa_c_thread_handle, &conf_thread_mng); if (ret) { DRV_LOG(ERR, "Failed to create vdpa multi-threads %d.", thrd_idx); goto c_thread_err; } - CPU_ZERO(&cpuset); - if (cpu_core != -1) - CPU_SET(cpu_core, &cpuset); - else - cpuset = rte_lcore_cpuset(rte_get_main_lcore()); - ret = pthread_setaffinity_np( - conf_thread_mng.cthrd[thrd_idx].tid, - sizeof(cpuset), &cpuset); - if (ret) { - DRV_LOG(ERR, "Failed to set thread affinity for " - "vdpa multi-threads %d.", thrd_idx); - goto c_thread_err; - } - snprintf(name, sizeof(name), "dpdk-vmlx5-c%d", thrd_idx); - ret = pthread_setname_np( - conf_thread_mng.cthrd[thrd_idx].tid, name); - if (ret) - DRV_LOG(ERR, "Failed to set vdpa multi-threads name %s.", - name); - else - DRV_LOG(DEBUG, "Thread name: %s.", name); pthread_cond_init(&conf_thread_mng.cthrd[thrd_idx].c_cond, NULL); } @@ -334,10 +298,10 @@ mlx5_vdpa_c_thread_create(int cpu_core) } int -mlx5_vdpa_mult_threads_create(int cpu_core) +mlx5_vdpa_mult_threads_create(void) { pthread_mutex_init(&conf_thread_mng.cthrd_lock, NULL); - if (mlx5_vdpa_c_thread_create(cpu_core)) { + if (mlx5_vdpa_c_thread_create()) { DRV_LOG(ERR, "Cannot create vDPA configuration threads."); mlx5_vdpa_mult_threads_destroy(false); return -1; diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_event.c b/drivers/vdpa/mlx5/mlx5_vdpa_event.c index c486ded598..fa26471b18 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa_event.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa_event.c @@ -284,7 +284,7 @@ mlx5_vdpa_event_wait(struct mlx5_vdpa_priv *priv __rte_unused) return NULL; } -static void * +static uint32_t mlx5_vdpa_event_handle(void *arg) { struct mlx5_vdpa_priv *priv = arg; @@ -324,7 +324,7 @@ mlx5_vdpa_event_handle(void *arg) } mlx5_vdpa_timer_sleep(priv, max); } - return NULL; + return 0; case MLX5_VDPA_EVENT_MODE_ONLY_INTERRUPT: do { virtq = mlx5_vdpa_event_wait(priv); @@ -336,9 +336,9 @@ mlx5_vdpa_event_handle(void *arg) pthread_mutex_unlock(&virtq->virtq_lock); } } while (1); - return NULL; + return 0; default: - return NULL; + return 0; } } @@ -503,54 +503,31 @@ int mlx5_vdpa_cqe_event_setup(struct mlx5_vdpa_priv *priv) { int ret; - rte_cpuset_t cpuset; - pthread_attr_t *attrp = NULL; - pthread_attr_t attr; - char name[16]; - const struct sched_param sp = { - .sched_priority = sched_get_priority_max(SCHED_RR) - 1, - }; + rte_thread_attr_t attr; + char name[RTE_THREAD_INTERNAL_NAME_SIZE]; if (!priv->eventc) /* All virtqs are in poll mode. */ return 0; - ret = pthread_attr_init(&attr); + ret = rte_thread_attr_init(&attr); if (ret != 0) { DRV_LOG(ERR, "Failed to initialize thread attributes"); goto out; } - attrp = &attr; - ret = pthread_attr_setschedpolicy(attrp, SCHED_RR); - if (ret) { - DRV_LOG(ERR, "Failed to set thread sched policy = RR."); - goto out; - } - ret = pthread_attr_setschedparam(attrp, &sp); - if (ret) { - DRV_LOG(ERR, "Failed to set thread priority."); - goto out; - } - ret = pthread_create(&priv->timer_tid, attrp, mlx5_vdpa_event_handle, - (void *)priv); - if (ret) { - DRV_LOG(ERR, "Failed to create timer thread."); - goto out; - } - CPU_ZERO(&cpuset); + attr.priority = RTE_THREAD_PRIORITY_REALTIME_CRITICAL; if (priv->event_core != -1) - CPU_SET(priv->event_core, &cpuset); + CPU_SET(priv->event_core, &attr.cpuset); else - cpuset = rte_lcore_cpuset(rte_get_main_lcore()); - ret = pthread_setaffinity_np(priv->timer_tid, sizeof(cpuset), &cpuset); - if (ret) { - DRV_LOG(ERR, "Failed to set thread affinity."); + attr.cpuset = rte_lcore_cpuset(rte_get_main_lcore()); + ret = rte_thread_create(&priv->timer_tid, + &attr, mlx5_vdpa_event_handle, priv); + if (ret != 0) { + DRV_LOG(ERR, "Failed to create timer thread."); goto out; } - snprintf(name, sizeof(name), "dpdk-vmlx5-%d", priv->vid); - rte_thread_set_name((rte_thread_t){(uintptr_t)priv->timer_tid}, name); + snprintf(name, sizeof(name), "vmlx5-%d", priv->vid); + rte_thread_set_prefixed_name(priv->timer_tid, name); out: - if (attrp != NULL) - pthread_attr_destroy(attrp); if (ret != 0) return -1; return 0; @@ -560,19 +537,18 @@ void mlx5_vdpa_cqe_event_unset(struct mlx5_vdpa_priv *priv) { struct mlx5_vdpa_virtq *virtq; - void *status; int i; - if (priv->timer_tid) { - pthread_cancel(priv->timer_tid); - pthread_join(priv->timer_tid, &status); + if (priv->timer_tid.opaque_id != 0) { + pthread_cancel((pthread_t)priv->timer_tid.opaque_id); + rte_thread_join(priv->timer_tid, NULL); /* The mutex may stay locked after event thread cancel, initiate it. */ for (i = 0; i < priv->nr_virtqs; i++) { virtq = &priv->virtqs[i]; pthread_mutex_init(&virtq->virtq_lock, NULL); } } - priv->timer_tid = 0; + priv->timer_tid.opaque_id = 0; } void diff --git a/drivers/vdpa/sfc/sfc_vdpa_ops.c b/drivers/vdpa/sfc/sfc_vdpa_ops.c index f63af7d478..00f9a4b04c 100644 --- a/drivers/vdpa/sfc/sfc_vdpa_ops.c +++ b/drivers/vdpa/sfc/sfc_vdpa_ops.c @@ -567,7 +567,7 @@ sfc_vdpa_get_protocol_features(struct rte_vdpa_device *vdpa_dev, return 0; } -static void * +static uint32_t sfc_vdpa_notify_ctrl(void *arg) { struct sfc_vdpa_ops_data *ops_data; @@ -575,7 +575,7 @@ sfc_vdpa_notify_ctrl(void *arg) ops_data = arg; if (ops_data == NULL) - return NULL; + return 0; sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle)); @@ -588,7 +588,7 @@ sfc_vdpa_notify_ctrl(void *arg) sfc_vdpa_adapter_unlock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle)); - return NULL; + return 0; } static int @@ -603,8 +603,8 @@ sfc_vdpa_setup_notify_ctrl(struct sfc_vdpa_ops_data *ops_data) * dead lock scenario when multiple VFs are used in single vdpa * application and multiple VFs are passed to a single VM. */ - ret = pthread_create(&ops_data->notify_tid, NULL, - sfc_vdpa_notify_ctrl, ops_data); + ret = rte_thread_create_internal_control(&ops_data->notify_tid, + "sfc-vdpa", sfc_vdpa_notify_ctrl, ops_data); if (ret != 0) { sfc_vdpa_err(ops_data->dev_handle, "failed to create notify_ctrl thread: %s", @@ -690,15 +690,14 @@ sfc_vdpa_dev_close(int vid) sfc_vdpa_adapter_lock(sfc_vdpa_adapter_by_dev_handle(ops_data->dev_handle)); if (ops_data->is_notify_thread_started == true) { - void *status; - ret = pthread_cancel(ops_data->notify_tid); + ret = pthread_cancel((pthread_t)ops_data->notify_tid.opaque_id); if (ret != 0) { sfc_vdpa_err(ops_data->dev_handle, "failed to cancel notify_ctrl thread: %s", rte_strerror(ret)); } - ret = pthread_join(ops_data->notify_tid, &status); + ret = rte_thread_join(ops_data->notify_tid, NULL); if (ret != 0) { sfc_vdpa_err(ops_data->dev_handle, "failed to join terminated notify_ctrl thread: %s", diff --git a/drivers/vdpa/sfc/sfc_vdpa_ops.h b/drivers/vdpa/sfc/sfc_vdpa_ops.h index 5c8e352de3..10ea239434 100644 --- a/drivers/vdpa/sfc/sfc_vdpa_ops.h +++ b/drivers/vdpa/sfc/sfc_vdpa_ops.h @@ -6,6 +6,7 @@ #define _SFC_VDPA_OPS_H #include <rte_vdpa.h> +#include <rte_thread.h> #define SFC_VDPA_MAX_QUEUE_PAIRS 8 @@ -48,7 +49,7 @@ struct sfc_vdpa_ops_data { struct rte_vdpa_device *vdpa_dev; enum sfc_vdpa_context vdpa_context; enum sfc_vdpa_state state; - pthread_t notify_tid; + rte_thread_t notify_tid; bool is_notify_thread_started; uint64_t dev_features; -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v3 08/11] examples: convert to normal control threads 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon ` (6 preceding siblings ...) 2023-09-13 11:28 ` [PATCH v3 07/11] drivers: " Thomas Monjalon @ 2023-09-13 11:28 ` Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 09/11] test: convert threads creation Thomas Monjalon ` (4 subsequent siblings) 12 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 11:28 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Maxime Coquelin, Chenbo Xia Calls to rte_ctrl_thread_create() are replaced with rte_thread_create_control(). In vhost_blk, the control thread is not forced to be scheduled on core 0 anymore. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- examples/vhost/main.c | 9 +++++---- examples/vhost_blk/vhost_blk.c | 21 ++++++--------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 9ff2c1f31b..ce5c1efddf 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -28,6 +28,7 @@ #include <rte_pause.h> #include <rte_dmadev.h> #include <rte_vhost_async.h> +#include <rte_thread.h> #include "main.h" @@ -1807,7 +1808,7 @@ static const struct rte_vhost_device_ops virtio_net_device_ops = * This is a thread will wake up after a period to print stats if the user has * enabled them. */ -static void * +static uint32_t print_stats(__rte_unused void *arg) { struct vhost_dev *vdev; @@ -1852,7 +1853,7 @@ print_stats(__rte_unused void *arg) fflush(stdout); } - return NULL; + return 0; } static void @@ -1907,7 +1908,7 @@ main(int argc, char *argv[]) unsigned nb_ports, valid_num_ports; int ret, i; uint16_t portid; - static pthread_t tid; + rte_thread_t tid; uint64_t flags = RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS; signal(SIGINT, sigint_handler); @@ -1986,7 +1987,7 @@ main(int argc, char *argv[]) /* Enable stats if the user option is set. */ if (enable_stats) { - ret = rte_ctrl_thread_create(&tid, "dpdk-vhost-stat", NULL, + ret = rte_thread_create_control(&tid, "dpdk-vhost-stat", print_stats, NULL); if (ret < 0) rte_exit(EXIT_FAILURE, diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c index 45699eb0b3..376f7b89a7 100644 --- a/examples/vhost_blk/vhost_blk.c +++ b/examples/vhost_blk/vhost_blk.c @@ -5,8 +5,6 @@ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif -#include <pthread.h> -#include <sched.h> #include <stdint.h> #include <stdlib.h> @@ -529,12 +527,10 @@ process_vq(struct vhost_blk_queue *vq) } } -static void * +static uint32_t ctrlr_worker(void *arg) { struct vhost_blk_ctrlr *ctrlr = (struct vhost_blk_ctrlr *)arg; - cpu_set_t cpuset; - pthread_t thread; int i; fprintf(stdout, "Ctrlr Worker Thread start\n"); @@ -546,11 +542,6 @@ ctrlr_worker(void *arg) exit(0); } - thread = pthread_self(); - CPU_ZERO(&cpuset); - CPU_SET(0, &cpuset); - pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset); - for (i = 0; i < NUM_OF_BLK_QUEUES; i++) submit_inflight_vq(&ctrlr->queues[i]); @@ -560,7 +551,7 @@ ctrlr_worker(void *arg) fprintf(stdout, "Ctrlr Worker Thread Exiting\n"); sem_post(&exit_sem); - return NULL; + return 0; } static int @@ -605,7 +596,7 @@ new_device(int vid) struct vhost_blk_queue *vq; char path[PATH_MAX]; uint64_t features, protocol_features; - pthread_t tid; + rte_thread_t tid; int i, ret; bool packed_ring, inflight_shmfd; @@ -686,15 +677,15 @@ new_device(int vid) /* start polling vring */ worker_thread_status = WORKER_STATE_START; fprintf(stdout, "New Device %s, Device ID %d\n", path, vid); - if (rte_ctrl_thread_create(&tid, "dpdk-vhost-blk", NULL, - &ctrlr_worker, ctrlr) != 0) { + if (rte_thread_create_control(&tid, "dpdk-vhost-blk", + &ctrlr_worker, ctrlr) != 0) { fprintf(stderr, "Worker Thread Started Failed\n"); return -1; } /* device has been started */ ctrlr->started = 1; - pthread_detach(tid); + rte_thread_detach(tid); return 0; } -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v3 09/11] test: convert threads creation 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon ` (7 preceding siblings ...) 2023-09-13 11:28 ` [PATCH v3 08/11] examples: convert to normal " Thomas Monjalon @ 2023-09-13 11:28 ` Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 10/11] eal: remove deprecated thread functions Thomas Monjalon ` (3 subsequent siblings) 12 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 11:28 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Reshma Pattan, Stephen Hemminger Calls to pthread for thread creation are replaced with the rte_thread API. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- app/test/process.h | 10 +++++----- app/test/test_lcores.c | 9 ++++----- app/test/test_pdump.c | 6 +++--- app/test/test_pdump.h | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/test/process.h b/app/test/process.h index 1f073b9c5c..af7bc3e0de 100644 --- a/app/test/process.h +++ b/app/test/process.h @@ -28,8 +28,8 @@ #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING -#include <pthread.h> -extern void *send_pkts(void *empty); +#include <rte_thread.h> +extern uint32_t send_pkts(void *empty); extern uint16_t flag_for_send_pkts; #endif #endif @@ -49,7 +49,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) char path[32]; #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING - pthread_t thread; + rte_thread_t thread; int rc; #endif #endif @@ -136,7 +136,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING if ((strcmp(env_value, "run_pdump_server_tests") == 0)) { - rc = pthread_create(&thread, NULL, &send_pkts, NULL); + rc = rte_thread_create(&thread, NULL, send_pkts, NULL); if (rc != 0) { rte_panic("Cannot start send pkts thread: %s\n", strerror(rc)); @@ -151,7 +151,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) #ifdef RTE_NET_RING if ((strcmp(env_value, "run_pdump_server_tests") == 0)) { flag_for_send_pkts = 0; - pthread_join(thread, NULL); + rte_thread_join(thread, NULL); } #endif #endif diff --git a/app/test/test_lcores.c b/app/test/test_lcores.c index 0c96faa4cb..22225a9fd3 100644 --- a/app/test/test_lcores.c +++ b/app/test/test_lcores.c @@ -2,7 +2,6 @@ * Copyright (c) 2020 Red Hat, Inc. */ -#include <pthread.h> #include <string.h> #include <rte_common.h> @@ -341,7 +340,7 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count) return -1; } -static void *ctrl_thread_loop(void *arg) +static uint32_t ctrl_thread_loop(void *arg) { struct thread_context *t = arg; @@ -350,7 +349,7 @@ static void *ctrl_thread_loop(void *arg) /* Set the thread state to DONE */ t->state = Thread_DONE; - return NULL; + return 0; } static int @@ -362,8 +361,8 @@ test_ctrl_thread(void) /* Create one control thread */ t = &ctrl_thread_context; t->state = Thread_INIT; - if (rte_ctrl_thread_create((pthread_t *)&t->id, "dpdk-test-ctrlt", - NULL, ctrl_thread_loop, t) != 0) + if (rte_thread_create_control(&t->id, "dpdk-test-ctrlt", + ctrl_thread_loop, t) != 0) return -1; /* Wait till the control thread exits. diff --git a/app/test/test_pdump.c b/app/test/test_pdump.c index ea03056b47..adf49f0b54 100644 --- a/app/test/test_pdump.c +++ b/app/test/test_pdump.c @@ -136,8 +136,8 @@ test_pdump_uninit(void) return ret; } -void * -send_pkts(void *empty) +uint32_t +send_pkts(void *empty __rte_unused) { int ret = 0; struct rte_mbuf *pbuf[NUM_PACKETS] = { }; @@ -161,7 +161,7 @@ send_pkts(void *empty) rte_eth_dev_stop(portid); test_put_mbuf_to_pool(mp, pbuf); - return empty; + return 0; } /* diff --git a/app/test/test_pdump.h b/app/test/test_pdump.h index abef9a85ec..8746d61269 100644 --- a/app/test/test_pdump.h +++ b/app/test/test_pdump.h @@ -9,7 +9,7 @@ #define NUM_ITR 3 /* sample test to send packets to the pdump client recursively */ -void *send_pkts(void *port); +uint32_t send_pkts(void *empty); /* Sample test to create setup for the pdump server tests */ int test_pdump_init(void); -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v3 10/11] eal: remove deprecated thread functions 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon ` (8 preceding siblings ...) 2023-09-13 11:28 ` [PATCH v3 09/11] test: convert threads creation Thomas Monjalon @ 2023-09-13 11:28 ` Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 11/11] lib: remove pthread.h from includes Thomas Monjalon ` (2 subsequent siblings) 12 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 11:28 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Anatoly Burakov, Bruce Richardson, Dmitry Kozlyuk, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam The deprecated functions rte_thread_setname() and rte_ctrl_thread_create() are replaced with the new rte_thread API: rte_thread_setname() can be replaced with rte_thread_set_name() or rte_thread_set_prefixed_name() rte_ctrl_thread_create() can be replaced with rte_thread_create_control() or rte_thread_create_internal_control() Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> --- v2: clean control thread params struct --- .../prog_guide/env_abstraction_layer.rst | 2 +- doc/guides/rel_notes/deprecation.rst | 5 - doc/guides/rel_notes/release_23_11.rst | 4 +- lib/eal/common/eal_common_thread.c | 93 +++---------------- lib/eal/freebsd/eal_thread.c | 7 -- lib/eal/include/rte_lcore.h | 42 --------- lib/eal/linux/eal_thread.c | 16 ---- lib/eal/version.map | 2 - lib/eal/windows/eal_thread.c | 8 -- 9 files changed, 18 insertions(+), 161 deletions(-) diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst index 89014789de..6debf54efb 100644 --- a/doc/guides/prog_guide/env_abstraction_layer.rst +++ b/doc/guides/prog_guide/env_abstraction_layer.rst @@ -756,7 +756,7 @@ Control Thread API ~~~~~~~~~~~~~~~~~~ It is possible to create Control Threads using the public API -``rte_ctrl_thread_create()``. +``rte_thread_create_control()``. Those threads can be used for management/infrastructure tasks and are used internally by DPDK for multi process support and interrupt handling. diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index 3e48908b51..8c8873006d 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -29,11 +29,6 @@ Deprecation Notices are renamed to ``rte_tel_data_add_array_uint`` and ``rte_tel_data_add_dict_uint`` respectively. As such, the old function names are deprecated and will be removed in a future release. -* eal: The functions ``rte_thread_setname`` and ``rte_ctrl_thread_create`` - are planned to be deprecated starting with the 23.07 release, subject to - the replacement API rte_thread_set_name and rte_thread_create_control being - marked as stable, and planned to be removed by the 23.11 release. - * eal: ``RTE_CPUFLAG_NUMFLAGS`` will be removed in DPDK 23.11 release. This is to allow new CPU features to be added without ABI breakage. diff --git a/doc/guides/rel_notes/release_23_11.rst b/doc/guides/rel_notes/release_23_11.rst index d7562fd646..9746809a66 100644 --- a/doc/guides/rel_notes/release_23_11.rst +++ b/doc/guides/rel_notes/release_23_11.rst @@ -115,7 +115,9 @@ API Changes * eal: The thread API has changed. The function ``rte_thread_create_control()`` does not take attributes anymore. - The whole thread API was promoted to stable level. + The whole thread API was promoted to stable level, + except ``rte_thread_setname()`` and ``rte_ctrl_thread_create()`` which are + replaced with ``rte_thread_set_name()`` and ``rte_thread_create_control()``. ABI Changes diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 830273813f..668b1ed96b 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -235,25 +235,22 @@ enum __rte_ctrl_thread_status { CTRL_THREAD_ERROR /* Control thread encountered an error */ }; -struct rte_thread_ctrl_params { - union { - void *(*ctrl_start_routine)(void *arg); - rte_thread_func control_start_routine; - } u; +struct control_thread_params { + rte_thread_func start_routine; void *arg; int ret; /* Control thread status. * If the status is CTRL_THREAD_ERROR, 'ret' has the error code. */ - enum __rte_ctrl_thread_status ctrl_thread_status; + enum __rte_ctrl_thread_status status; }; -static int ctrl_thread_init(void *arg) +static int control_thread_init(void *arg) { struct internal_config *internal_conf = eal_get_internal_configuration(); rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset; - struct rte_thread_ctrl_params *params = arg; + struct control_thread_params *params = arg; __rte_thread_init(rte_lcore_id(), cpuset); /* Set control thread socket ID to SOCKET_ID_ANY @@ -262,96 +259,34 @@ static int ctrl_thread_init(void *arg) RTE_PER_LCORE(_socket_id) = SOCKET_ID_ANY; params->ret = rte_thread_set_affinity_by_id(rte_thread_self(), cpuset); if (params->ret != 0) { - __atomic_store_n(¶ms->ctrl_thread_status, + __atomic_store_n(¶ms->status, CTRL_THREAD_ERROR, __ATOMIC_RELEASE); return 1; } - __atomic_store_n(¶ms->ctrl_thread_status, + __atomic_store_n(¶ms->status, CTRL_THREAD_RUNNING, __ATOMIC_RELEASE); return 0; } -static void *ctrl_thread_start(void *arg) -{ - struct rte_thread_ctrl_params *params = arg; - void *start_arg = params->arg; - void *(*start_routine)(void *) = params->u.ctrl_start_routine; - - if (ctrl_thread_init(arg) != 0) - return NULL; - - return start_routine(start_arg); -} - static uint32_t control_thread_start(void *arg) { - struct rte_thread_ctrl_params *params = arg; + struct control_thread_params *params = arg; void *start_arg = params->arg; - rte_thread_func start_routine = params->u.control_start_routine; + rte_thread_func start_routine = params->start_routine; - if (ctrl_thread_init(arg) != 0) + if (control_thread_init(arg) != 0) return 0; return start_routine(start_arg); } -int -rte_ctrl_thread_create(pthread_t *thread, const char *name, - const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg) -{ - struct rte_thread_ctrl_params *params; - enum __rte_ctrl_thread_status ctrl_thread_status; - int ret; - - params = malloc(sizeof(*params)); - if (!params) - return -ENOMEM; - - params->u.ctrl_start_routine = start_routine; - params->arg = arg; - params->ret = 0; - params->ctrl_thread_status = CTRL_THREAD_LAUNCHING; - - ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params); - if (ret != 0) { - free(params); - return -ret; - } - - if (name != NULL) - rte_thread_set_name((rte_thread_t){(uintptr_t)*thread}, name); - - /* Wait for the control thread to initialize successfully */ - while ((ctrl_thread_status = - __atomic_load_n(¶ms->ctrl_thread_status, - __ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) { - /* Yield the CPU. Using sched_yield call requires maintaining - * another implementation for Windows as sched_yield is not - * supported on Windows. - */ - rte_delay_us_sleep(1); - } - - /* Check if the control thread encountered an error */ - if (ctrl_thread_status == CTRL_THREAD_ERROR) { - /* ctrl thread is exiting */ - rte_thread_join((rte_thread_t){(uintptr_t)*thread}, NULL); - } - - ret = params->ret; - free(params); - - return -ret; -} - int rte_thread_create_control(rte_thread_t *thread, const char *name, rte_thread_func start_routine, void *arg) { - struct rte_thread_ctrl_params *params; + struct control_thread_params *params; enum __rte_ctrl_thread_status ctrl_thread_status; int ret; @@ -359,10 +294,10 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, if (params == NULL) return -ENOMEM; - params->u.control_start_routine = start_routine; + params->start_routine = start_routine; params->arg = arg; params->ret = 0; - params->ctrl_thread_status = CTRL_THREAD_LAUNCHING; + params->status = CTRL_THREAD_LAUNCHING; ret = rte_thread_create(thread, NULL, control_thread_start, params); if (ret != 0) { @@ -375,7 +310,7 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, /* Wait for the control thread to initialize successfully */ while ((ctrl_thread_status = - __atomic_load_n(¶ms->ctrl_thread_status, + __atomic_load_n(¶ms->status, __ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) { rte_delay_us_sleep(1); } diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c index ba9b25c2c0..6f97a3c2c1 100644 --- a/lib/eal/freebsd/eal_thread.c +++ b/lib/eal/freebsd/eal_thread.c @@ -42,10 +42,3 @@ void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated); } - -int rte_thread_setname(pthread_t id, const char *name) -{ - /* this BSD function returns no error */ - pthread_set_name_np(id, name); - return 0; -} diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h index 6ce810b876..7deae47af3 100644 --- a/lib/eal/include/rte_lcore.h +++ b/lib/eal/include/rte_lcore.h @@ -385,20 +385,6 @@ void rte_lcore_register_usage_cb(rte_lcore_usage_cb cb); void rte_lcore_dump(FILE *f); -/** - * Set thread names. - * - * @note It fails with glibc < 2.12. - * - * @param id - * Thread id. - * @param name - * Thread name to set. - * @return - * On success, return 0; otherwise return a negative value. - */ -int rte_thread_setname(pthread_t id, const char *name); - /** * Register current non-EAL thread as a lcore. * @@ -421,34 +407,6 @@ rte_thread_register(void); void rte_thread_unregister(void); -/** - * Create a control thread. - * - * Creates a control thread with the given name and attributes. The - * affinity of the new thread is based on the CPU affinity retrieved - * at the time rte_eal_init() was called, the dataplane and service - * lcores are then excluded. If setting the name of the thread fails, - * the error is ignored and a debug message is logged. - * - * @param thread - * Filled with the thread id of the new created thread. - * @param name - * The name of the control thread (max 16 characters including '\0'). - * @param attr - * Attributes for the new thread. - * @param start_routine - * Function to be executed by the new thread. - * @param arg - * Argument passed to start_routine. - * @return - * On success, returns 0; on error, it returns a negative value - * corresponding to the error number. - */ -int -rte_ctrl_thread_create(pthread_t *thread, const char *name, - const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg); - #ifdef __cplusplus } #endif diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c index b9a126f3a8..880070c627 100644 --- a/lib/eal/linux/eal_thread.c +++ b/lib/eal/linux/eal_thread.c @@ -39,19 +39,3 @@ void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) if (ret != 0) RTE_LOG(DEBUG, EAL, "Failed to set thread name\n"); } - -int rte_thread_setname(pthread_t id, const char *name) -{ - int ret = ENOSYS; -#if defined(__GLIBC__) && defined(__GLIBC_PREREQ) -#if __GLIBC_PREREQ(2, 12) - char truncated[16]; - - strlcpy(truncated, name, sizeof(truncated)); - ret = pthread_setname_np(id, truncated); -#endif -#endif - RTE_SET_USED(id); - RTE_SET_USED(name); - return -ret; -} diff --git a/lib/eal/version.map b/lib/eal/version.map index 6d32c19286..915057b325 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -20,7 +20,6 @@ DPDK_24 { rte_cpu_get_flag_enabled; rte_cpu_get_flag_name; rte_cpu_is_supported; # WINDOWS_NO_EXPORT - rte_ctrl_thread_create; rte_cycles_vmware_tsc_map; # WINDOWS_NO_EXPORT rte_delay_us; rte_delay_us_block; @@ -278,7 +277,6 @@ DPDK_24 { rte_thread_set_affinity_by_id; rte_thread_set_name; rte_thread_set_priority; - rte_thread_setname; rte_thread_unregister; rte_thread_value_get; rte_thread_value_set; diff --git a/lib/eal/windows/eal_thread.c b/lib/eal/windows/eal_thread.c index 464d510838..9e3df200b9 100644 --- a/lib/eal/windows/eal_thread.c +++ b/lib/eal/windows/eal_thread.c @@ -76,11 +76,3 @@ rte_sys_gettid(void) { return GetCurrentThreadId(); } - -int -rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name) -{ - /* TODO */ - /* This is a stub, not the expected result */ - return 0; -} -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* [PATCH v3 11/11] lib: remove pthread.h from includes 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon ` (9 preceding siblings ...) 2023-09-13 11:28 ` [PATCH v3 10/11] eal: remove deprecated thread functions Thomas Monjalon @ 2023-09-13 11:28 ` Thomas Monjalon 2023-09-17 12:26 ` [PATCH v3 00/11] rework thread management Konstantin Ananyev 2023-09-22 13:46 ` David Marchand 12 siblings, 0 replies; 60+ messages in thread From: Thomas Monjalon @ 2023-09-13 11:28 UTC (permalink / raw) To: dev Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit, Morten Brørup, Ajit Khaparde, Rosen Xu, Chas Williams, Min Hu (Connor), Matan Azrad, Viacheslav Ovsiienko, Ori Kam, Suanming Mou, Somnath Kotur, Devendra Singh Rawat, Alok Prasad, Tianfei Zhang, Vijay Kumar Srivastava, Jerin Jacob, Sunil Kumar Kori, Anatoly Burakov, Bruce Richardson, Andrew Rybchenko, Naga Harish K S V, Maxime Coquelin, Chenbo Xia The header files should have the minimum embedded includes. The file pthread.h can logically be removed from rte_per_lcore.h and rte_ethdev_core.h files. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com> Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com> Acked-by: Rosen Xu <rosen.xu@intel.com> --- app/test/test_link_bonding.c | 2 ++ drivers/common/mlx5/mlx5_common.c | 1 + drivers/common/mlx5/windows/mlx5_win_ext.h | 2 ++ drivers/net/bnxt/bnxt.h | 1 + drivers/net/qede/base/bcm_osal.h | 1 + drivers/raw/ifpga/base/opae_osdep.h | 1 + drivers/vdpa/sfc/sfc_vdpa.c | 1 + lib/eal/common/eal_common_options.c | 1 + lib/eal/common/eal_common_trace.c | 1 + lib/eal/common/malloc_mp.c | 1 + lib/eal/freebsd/eal_alarm.c | 1 + lib/eal/include/rte_per_lcore.h | 2 -- lib/eal/linux/eal_alarm.c | 1 + lib/ethdev/ethdev_driver.c | 1 + lib/ethdev/ethdev_driver.h | 2 ++ lib/ethdev/rte_ethdev_core.h | 2 -- lib/ethdev/rte_flow.c | 1 + lib/eventdev/rte_event_eth_rx_adapter.c | 1 + lib/vhost/vhost.c | 1 + 19 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/test/test_link_bonding.c b/app/test/test_link_bonding.c index 2f46e4c6ee..d6b6ebc2f2 100644 --- a/app/test/test_link_bonding.c +++ b/app/test/test_link_bonding.c @@ -10,8 +10,10 @@ #include <stdint.h> #include <inttypes.h> #include <errno.h> +#include <pthread.h> #include <sys/queue.h> #include <sys/time.h> + #include <rte_cycles.h> #include <rte_byteorder.h> #include <rte_common.h> diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c index 0ad14a48c7..ca8543e36e 100644 --- a/drivers/common/mlx5/mlx5_common.c +++ b/drivers/common/mlx5/mlx5_common.c @@ -5,6 +5,7 @@ #include <unistd.h> #include <string.h> #include <stdio.h> +#include <pthread.h> #include <rte_errno.h> #include <rte_mempool.h> diff --git a/drivers/common/mlx5/windows/mlx5_win_ext.h b/drivers/common/mlx5/windows/mlx5_win_ext.h index 6f69329a6f..a71c69bff5 100644 --- a/drivers/common/mlx5/windows/mlx5_win_ext.h +++ b/drivers/common/mlx5/windows/mlx5_win_ext.h @@ -5,6 +5,8 @@ #ifndef __MLX5_WIN_ETX_H__ #define __MLX5_WIN_ETX_H__ +#include <pthread.h> + #include "mlx5_prm.h" #include "mlx5devx.h" diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h index ed21ba7f29..0e01b1d4ba 100644 --- a/drivers/net/bnxt/bnxt.h +++ b/drivers/net/bnxt/bnxt.h @@ -8,6 +8,7 @@ #include <inttypes.h> #include <stdbool.h> +#include <pthread.h> #include <sys/queue.h> #include <rte_pci.h> diff --git a/drivers/net/qede/base/bcm_osal.h b/drivers/net/qede/base/bcm_osal.h index 97e261d306..11019b5623 100644 --- a/drivers/net/qede/base/bcm_osal.h +++ b/drivers/net/qede/base/bcm_osal.h @@ -8,6 +8,7 @@ #define __BCM_OSAL_H #include <stdbool.h> +#include <pthread.h> #include <time.h> #include <rte_bitops.h> #include <rte_byteorder.h> diff --git a/drivers/raw/ifpga/base/opae_osdep.h b/drivers/raw/ifpga/base/opae_osdep.h index 033b7e098c..e91205f536 100644 --- a/drivers/raw/ifpga/base/opae_osdep.h +++ b/drivers/raw/ifpga/base/opae_osdep.h @@ -7,6 +7,7 @@ #include <string.h> #include <stdbool.h> +#include <pthread.h> #ifdef RTE_LIB_EAL #include "osdep_rte/osdep_generic.h" diff --git a/drivers/vdpa/sfc/sfc_vdpa.c b/drivers/vdpa/sfc/sfc_vdpa.c index bd6ecde450..9db87fcb7d 100644 --- a/drivers/vdpa/sfc/sfc_vdpa.c +++ b/drivers/vdpa/sfc/sfc_vdpa.c @@ -4,6 +4,7 @@ #include <stdbool.h> #include <stdint.h> +#include <pthread.h> #include <sys/queue.h> #include <rte_common.h> diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index d74b581567..a6d21f1cba 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -5,6 +5,7 @@ #include <stdlib.h> #include <string.h> +#include <pthread.h> #ifndef RTE_EXEC_ENV_WINDOWS #include <syslog.h> #endif diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index cb980af06d..b21e61bf39 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include <fnmatch.h> +#include <pthread.h> #include <sys/queue.h> #include <regex.h> diff --git a/lib/eal/common/malloc_mp.c b/lib/eal/common/malloc_mp.c index 7270c2ec90..4d62397aba 100644 --- a/lib/eal/common/malloc_mp.c +++ b/lib/eal/common/malloc_mp.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include <string.h> +#include <pthread.h> #include <sys/time.h> #include <rte_errno.h> diff --git a/lib/eal/freebsd/eal_alarm.c b/lib/eal/freebsd/eal_alarm.c index acdcf53804..e5b0909a45 100644 --- a/lib/eal/freebsd/eal_alarm.c +++ b/lib/eal/freebsd/eal_alarm.c @@ -4,6 +4,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <pthread.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> diff --git a/lib/eal/include/rte_per_lcore.h b/lib/eal/include/rte_per_lcore.h index 2b846f9337..5a1497631a 100644 --- a/lib/eal/include/rte_per_lcore.h +++ b/lib/eal/include/rte_per_lcore.h @@ -22,8 +22,6 @@ extern "C" { #endif -#include <pthread.h> - #ifdef RTE_TOOLCHAIN_MSVC /** * Macro to define a per lcore variable "var" of type "type", don't diff --git a/lib/eal/linux/eal_alarm.c b/lib/eal/linux/eal_alarm.c index 397f25d7d5..766ba2c251 100644 --- a/lib/eal/linux/eal_alarm.c +++ b/lib/eal/linux/eal_alarm.c @@ -5,6 +5,7 @@ #include <stdint.h> #include <stdlib.h> #include <errno.h> +#include <pthread.h> #include <sys/queue.h> #include <sys/time.h> #include <sys/timerfd.h> diff --git a/lib/ethdev/ethdev_driver.c b/lib/ethdev/ethdev_driver.c index 0be1e8ca04..30db839a77 100644 --- a/lib/ethdev/ethdev_driver.c +++ b/lib/ethdev/ethdev_driver.c @@ -3,6 +3,7 @@ */ #include <stdlib.h> +#include <pthread.h> #include <rte_kvargs.h> #include <rte_malloc.h> diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h index 980f837ab6..3fa8b309c1 100644 --- a/lib/ethdev/ethdev_driver.h +++ b/lib/ethdev/ethdev_driver.h @@ -18,6 +18,8 @@ extern "C" { * use them. */ +#include <pthread.h> + #include <dev_driver.h> #include <rte_compat.h> #include <rte_ethdev.h> diff --git a/lib/ethdev/rte_ethdev_core.h b/lib/ethdev/rte_ethdev_core.h index 46e9721e07..8d260584b4 100644 --- a/lib/ethdev/rte_ethdev_core.h +++ b/lib/ethdev/rte_ethdev_core.h @@ -5,8 +5,6 @@ #ifndef _RTE_ETHDEV_CORE_H_ #define _RTE_ETHDEV_CORE_H_ -#include <pthread.h> - /** * @file * diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c index 271d854f78..0c5aabea45 100644 --- a/lib/ethdev/rte_flow.c +++ b/lib/ethdev/rte_flow.c @@ -6,6 +6,7 @@ #include <errno.h> #include <stddef.h> #include <stdint.h> +#include <pthread.h> #include <rte_common.h> #include <rte_errno.h> diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c index c166ef69a8..2145d803e4 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -4,6 +4,7 @@ */ #include <ctype.h> #include <stdlib.h> +#include <pthread.h> #if defined(LINUX) #include <sys/epoll.h> #endif diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index eb6309b681..c03bb9c6eb 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -6,6 +6,7 @@ #include <linux/virtio_net.h> #include <stdint.h> #include <stdlib.h> +#include <pthread.h> #ifdef RTE_LIBRTE_VHOST_NUMA #include <numa.h> #include <numaif.h> -- 2.42.0 ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH v3 00/11] rework thread management 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon ` (10 preceding siblings ...) 2023-09-13 11:28 ` [PATCH v3 11/11] lib: remove pthread.h from includes Thomas Monjalon @ 2023-09-17 12:26 ` Konstantin Ananyev 2023-09-22 13:46 ` David Marchand 12 siblings, 0 replies; 60+ messages in thread From: Konstantin Ananyev @ 2023-09-17 12:26 UTC (permalink / raw) To: Thomas Monjalon, dev; +Cc: Tyler Retzlaff, David Marchand, Ferruh Yigit 13/09/2023 12:28, Thomas Monjalon пишет: > The main effect of this patch series is to > remove calls to pthread functions except for pthread_cancel and locks. > > The function rte_thread_create_control() does not take thread attributes > settings anymore as it looks a useless complication of the API. > Then the rte_thread API is made stable, > so we can remove the old deprecated functions > rte_thread_setname() and rte_ctrl_thread_create(). > > Some new internal functions are added in rte_thread to make sure > all internal thread names are prefixed with "dpdk-". > > Few other cleanups are done. > > Future work about pthread portability are about: > - cancel > - mutex > > --- > > v2 changes: > - replace (|_) with _? in checkpatch > - simplify thread name size doc > - build time check of internal thread name size > - clean control thread params struct > v3 change: > - fix build (wrong placement of RTE_BUILD_BUG_ON) > note for later: never send a patch during a summit! > > > Thomas Monjalon (11): > devtools: warn when adding some pthread calls > eal: rename thread name length definition > eal: remove attributes from control thread creation > eal: promote thread API as stable > eal: force prefix for internal threads > lib: convert to internal control threads > drivers: convert to internal control threads > examples: convert to normal control threads > test: convert threads creation > eal: remove deprecated thread functions > lib: remove pthread.h from includes > > app/test/process.h | 10 +- > app/test/test_lcores.c | 9 +- > app/test/test_link_bonding.c | 2 + > app/test/test_pdump.c | 6 +- > app/test/test_pdump.h | 2 +- > app/test/test_threads.c | 2 +- > devtools/checkpatches.sh | 16 +++ > .../prog_guide/env_abstraction_layer.rst | 2 +- > doc/guides/rel_notes/deprecation.rst | 5 - > doc/guides/rel_notes/release_23_11.rst | 6 + > drivers/common/cnxk/roc_dev.c | 16 +-- > drivers/common/cnxk/roc_dev_priv.h | 2 +- > drivers/common/cnxk/roc_nix_inl_dev.c | 9 +- > drivers/common/cnxk/roc_nix_inl_priv.h | 2 +- > drivers/common/cnxk/roc_platform.h | 3 +- > drivers/common/mlx5/mlx5_common.c | 1 + > drivers/common/mlx5/windows/mlx5_win_ext.h | 2 + > drivers/dma/skeleton/skeleton_dmadev.c | 8 +- > drivers/event/dlb2/pf/base/dlb2_osdep.h | 14 +- > drivers/event/dlb2/pf/base/dlb2_resource.c | 39 +++--- > drivers/event/dlb2/pf/dlb2_main.h | 1 - > drivers/net/ark/ark_ethdev.c | 11 +- > drivers/net/ark/ark_pktgen.c | 8 +- > drivers/net/ark/ark_pktgen.h | 2 +- > drivers/net/bnxt/bnxt.h | 1 + > drivers/net/iavf/iavf_vchnl.c | 4 +- > drivers/net/ice/ice_dcf_parent.c | 7 +- > drivers/net/ipn3ke/ipn3ke_representor.c | 17 ++- > drivers/net/ixgbe/ixgbe_ethdev.c | 8 +- > drivers/net/mlx5/mlx5.h | 2 +- > drivers/net/mlx5/mlx5_hws_cnt.c | 42 +++--- > drivers/net/qede/base/bcm_osal.h | 1 + > drivers/net/sfc/sfc_mae.h | 2 +- > drivers/net/sfc/sfc_mae_counter.c | 11 +- > drivers/net/txgbe/txgbe_ethdev.c | 6 +- > drivers/raw/ifpga/base/opae_osdep.h | 1 + > drivers/raw/ifpga/ifpga_rawdev.c | 19 ++- > drivers/vdpa/ifc/ifcvf_vdpa.c | 86 ++++++------ > drivers/vdpa/mlx5/mlx5_vdpa.c | 2 +- > drivers/vdpa/mlx5/mlx5_vdpa.h | 10 +- > drivers/vdpa/mlx5/mlx5_vdpa_cthread.c | 70 +++------- > drivers/vdpa/mlx5/mlx5_vdpa_event.c | 64 +++------ > drivers/vdpa/sfc/sfc_vdpa.c | 1 + > drivers/vdpa/sfc/sfc_vdpa_ops.c | 15 +- > drivers/vdpa/sfc/sfc_vdpa_ops.h | 3 +- > examples/vhost/main.c | 9 +- > examples/vhost_blk/vhost_blk.c | 21 +-- > lib/eal/common/eal_common_options.c | 1 + > lib/eal/common/eal_common_proc.c | 15 +- > lib/eal/common/eal_common_thread.c | 131 +++++++----------- > lib/eal/common/eal_common_trace.c | 1 + > lib/eal/common/malloc_mp.c | 1 + > lib/eal/freebsd/eal.c | 2 +- > lib/eal/freebsd/eal_alarm.c | 1 + > lib/eal/freebsd/eal_interrupts.c | 10 +- > lib/eal/freebsd/eal_thread.c | 9 +- > lib/eal/include/rte_eal.h | 3 - > lib/eal/include/rte_lcore.h | 42 ------ > lib/eal/include/rte_per_lcore.h | 2 - > lib/eal/include/rte_thread.h | 131 +++++++++--------- > lib/eal/linux/eal.c | 2 +- > lib/eal/linux/eal_alarm.c | 1 + > lib/eal/linux/eal_interrupts.c | 10 +- > lib/eal/linux/eal_thread.c | 18 +-- > lib/eal/linux/eal_timer.c | 11 +- > lib/eal/unix/rte_thread.c | 2 +- > lib/eal/version.map | 44 +++--- > lib/eal/windows/eal.c | 2 +- > lib/eal/windows/eal_interrupts.c | 2 +- > lib/eal/windows/eal_thread.c | 8 -- > lib/eal/windows/rte_thread.c | 2 +- > lib/ethdev/ethdev_driver.c | 1 + > lib/ethdev/ethdev_driver.h | 2 + > lib/ethdev/rte_ethdev_core.h | 2 - > lib/ethdev/rte_flow.c | 1 + > lib/eventdev/rte_event_eth_rx_adapter.c | 24 ++-- > lib/vhost/fd_man.c | 6 +- > lib/vhost/fd_man.h | 2 +- > lib/vhost/socket.c | 23 ++- > lib/vhost/vduse.c | 5 +- > lib/vhost/vhost.c | 1 + > 81 files changed, 466 insertions(+), 632 deletions(-) > Series-acked-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru> ^ permalink raw reply [flat|nested] 60+ messages in thread
* Re: [PATCH v3 00/11] rework thread management 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon ` (11 preceding siblings ...) 2023-09-17 12:26 ` [PATCH v3 00/11] rework thread management Konstantin Ananyev @ 2023-09-22 13:46 ` David Marchand 12 siblings, 0 replies; 60+ messages in thread From: David Marchand @ 2023-09-22 13:46 UTC (permalink / raw) To: Thomas Monjalon Cc: dev, Tyler Retzlaff, Ferruh Yigit, Morten Brørup, Konstantin Ananyev On Wed, Sep 13, 2023 at 1:45 PM Thomas Monjalon <thomas@monjalon.net> wrote: > > The main effect of this patch series is to > remove calls to pthread functions except for pthread_cancel and locks. > > The function rte_thread_create_control() does not take thread attributes > settings anymore as it looks a useless complication of the API. > Then the rte_thread API is made stable, > so we can remove the old deprecated functions > rte_thread_setname() and rte_ctrl_thread_create(). > > Some new internal functions are added in rte_thread to make sure > all internal thread names are prefixed with "dpdk-". > > Few other cleanups are done. > > Future work about pthread portability are about: > - cancel > - mutex > > --- > > v2 changes: > - replace (|_) with _? in checkpatch > - simplify thread name size doc > - build time check of internal thread name size > - clean control thread params struct > v3 change: > - fix build (wrong placement of RTE_BUILD_BUG_ON) > note for later: never send a patch during a summit! Series applied, thanks. -- David Marchand ^ permalink raw reply [flat|nested] 60+ messages in thread
end of thread, other threads:[~2023-09-22 13:46 UTC | newest] Thread overview: 60+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon 2023-09-06 16:12 ` [PATCH 01/11] devtools: warn when adding some pthread calls Thomas Monjalon 2023-09-07 8:20 ` David Marchand 2023-09-06 16:12 ` [PATCH 02/11] eal: rename thread name length definition Thomas Monjalon 2023-09-08 4:00 ` Tyler Retzlaff 2023-09-06 16:12 ` [PATCH 03/11] eal: remove attributes from control thread creation Thomas Monjalon 2023-09-08 4:02 ` Tyler Retzlaff 2023-09-06 16:12 ` [PATCH 04/11] eal: promote thread API as stable Thomas Monjalon 2023-09-08 4:04 ` Tyler Retzlaff 2023-09-06 16:12 ` [PATCH 05/11] eal: force prefix for internal threads Thomas Monjalon 2023-09-07 8:28 ` David Marchand 2023-09-07 8:50 ` Morten Brørup 2023-09-07 8:53 ` David Marchand 2023-09-07 8:55 ` David Marchand 2023-09-07 11:10 ` Morten Brørup 2023-09-11 16:26 ` Thomas Monjalon 2023-09-11 21:32 ` Morten Brørup 2023-09-06 16:12 ` [PATCH 06/11] lib: convert to internal control threads Thomas Monjalon 2023-09-06 16:12 ` [PATCH 07/11] drivers: " Thomas Monjalon 2023-09-11 13:35 ` Andrew Rybchenko 2023-09-06 16:12 ` [PATCH 08/11] examples: convert to normal " Thomas Monjalon 2023-09-08 4:10 ` Tyler Retzlaff 2023-09-06 16:12 ` [PATCH 09/11] test: convert threads creation Thomas Monjalon 2023-09-08 4:12 ` Tyler Retzlaff 2023-09-06 16:12 ` [PATCH 10/11] eal: remove deprecated thread functions Thomas Monjalon 2023-09-08 4:22 ` Tyler Retzlaff 2023-09-11 16:13 ` Thomas Monjalon 2023-09-12 0:49 ` Tyler Retzlaff 2023-09-06 16:12 ` [PATCH 11/11] lib: remove pthread.h from includes Thomas Monjalon 2023-09-08 4:25 ` Tyler Retzlaff 2023-09-08 4:49 ` Ajit Khaparde 2023-09-10 2:55 ` Xu, Rosen 2023-09-07 8:30 ` [PATCH 00/11] rework thread management Morten Brørup 2023-09-08 4:26 ` Tyler Retzlaff 2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 01/11] devtools: warn when adding some pthread calls Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 02/11] eal: rename thread name length definition Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 03/11] eal: remove attributes from control thread creation Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 04/11] eal: promote thread API as stable Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 05/11] eal: force prefix for internal threads Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 06/11] lib: convert to internal control threads Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 07/11] drivers: " Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 08/11] examples: convert to normal " Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 09/11] test: convert threads creation Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 10/11] eal: remove deprecated thread functions Thomas Monjalon 2023-09-13 10:34 ` [PATCH v2 11/11] lib: remove pthread.h from includes Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 01/11] devtools: warn when adding some pthread calls Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 02/11] eal: rename thread name length definition Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 03/11] eal: remove attributes from control thread creation Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 04/11] eal: promote thread API as stable Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 05/11] eal: force prefix for internal threads Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 06/11] lib: convert to internal control threads Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 07/11] drivers: " Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 08/11] examples: convert to normal " Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 09/11] test: convert threads creation Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 10/11] eal: remove deprecated thread functions Thomas Monjalon 2023-09-13 11:28 ` [PATCH v3 11/11] lib: remove pthread.h from includes Thomas Monjalon 2023-09-17 12:26 ` [PATCH v3 00/11] rework thread management Konstantin Ananyev 2023-09-22 13:46 ` David Marchand
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).