Skip to contentSkip to conversation

rework thread management

PATCH Superseded Thomas Monjalon 8 participants 60 messages Sep 6, 2023 – Sep 22, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover rework thread management

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(-)
Signature · 1 line
2.42.0
#1 lore raw

PATCH 1/11 devtools: warn when adding some pthread calls

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.

---
 devtools/checkpatches.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
devtools/checkpatches.sh +8 -0
index 55fabc5458..131ffbcebe 100755
@@ -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\\>' \
Signature · 1 line
2.42.0
#2 lore raw

Re: [PATCH 01/11] devtools: warn when adding some pthread calls

Hello Thomas,

Quoted 24 lines · Thomas Monjalon

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.

---
 devtools/checkpatches.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
devtools/checkpatches.sh +0 -0
index 55fabc5458..131ffbcebe 100755

devtools/checkpatches.sh check_forbidden_additions() { # <patch> · line 124

Quoted 6 lines
devtools/checkpatches.sh +3 -0
@@ -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 _?

Quoted 11 lines
devtools/checkpatches.sh +5 -1
+               -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

Signature · 1 line
David Marchand
#3 lore raw

PATCH 2/11 eal: rename thread name length definition

In reply to Thomas Monjalon

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.

---
 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(-)
lib/eal/freebsd/eal.c +1 -1
index 9e1e267955..39a2868523 100644
@@ -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();
lib/eal/freebsd/eal_thread.c +1 -1
index 3227d9b8a2..ba9b25c2c0 100644
@@ -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)
lib/eal/include/rte_eal.h +0 -3
index 53c4a5519e..cd318ee141 100644
@@ -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
  */
lib/eal/include/rte_thread.h +7 -2
index 369e2375f6..6233142322 100644
@@ -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
lib/eal/linux/eal.c +1 -1
index a26822f667..5f4b2fb005 100644
@@ -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 =
lib/eal/linux/eal_thread.c +1 -1
index c07ad9d8a4..b9a126f3a8 100644
@@ -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)
lib/eal/windows/eal.c +1 -1
index 16c1ba1596..7ec2152211 100644
@@ -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);
 
lib/eal/windows/rte_thread.c +1 -1
index e528ac9991..acf648456c 100644
@@ -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;
Signature · 1 line
2.42.0
Acked-by on v1 2/11
#4 lore raw

Re: [PATCH 02/11] eal: rename thread name length definition

Quoted 10 lines · Thomas Monjalon

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.

---

lgtm

#5 lore raw

PATCH 3/11 eal: remove attributes from control thread creation

In reply to Thomas Monjalon

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.

---
 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(-)
app/test/test_threads.c +1 -1
index 8c27e2bae1..4ac3f2671a 100644
@@ -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)
doc/guides/rel_notes/release_23_11.rst +3 -0
index 333e1d95a2..d3d500f294 100644
@@ -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
 -----------
drivers/dma/skeleton/skeleton_dmadev.c +1 -2
index 493224542f..4fc2319668 100644
@@ -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;
drivers/net/iavf/iavf_vchnl.c +1 -1
index c31a6d5c98..6baa6d5955 100644
@@ -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;
 	}
drivers/net/ice/ice_dcf_parent.c +1 -1
index ad98a531de..d3bb65874f 100644
@@ -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");
drivers/net/ixgbe/ixgbe_ethdev.c +0 -1
index 7eac05ee60..64e7e5d7d6 100644
@@ -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,
drivers/net/txgbe/txgbe_ethdev.c +1 -1
index 6f2f5a1841..198fac8318 100644
@@ -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);
lib/eal/common/eal_common_thread.c +2 -3
index 6605bd017e..07ac721da1 100644
@@ -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;
lib/eal/include/rte_thread.h +1 -4
index 6233142322..28cc5220a4 100644
@@ -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
lib/eal/windows/eal_interrupts.c +1 -1
index b1b1228c2b..66a49c844a 100644
@@ -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;
Signature · 1 line
2.42.0
Acked-by on v1 3/11
#6 lore raw

Re: [PATCH 03/11] eal: remove attributes from control thread creation

Quoted 10 lines · Thomas Monjalon

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.

---

#7 lore raw

PATCH 4/11 eal: promote thread API as stable

In reply to Thomas Monjalon

The rte_thread API must be used to ease OS porting. One step of this process is to mark the necessary API as stable.

---
 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(-)
doc/guides/rel_notes/release_23_11.rst +1 -0
index d3d500f294..d7562fd646 100644
@@ -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
lib/eal/include/rte_thread.h +0 -64

240 lines not on this page · raw message

lib/eal/version.map +19 -21
index 7940431e5a..33b853d7be 100644
@@ -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
Signature · 1 line
2.42.0
#9 lore raw

PATCH 5/11 eal: force prefix for internal threads

In reply to Thomas Monjalon

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.

---
 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(-)
devtools/checkpatches.sh +8 -0
index 131ffbcebe..18ad6fbb7f 100755
@@ -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' \
lib/eal/common/eal_common_thread.c +30 -0
index 07ac721da1..31c37e3102 100644
@@ -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)
 {
lib/eal/include/rte_thread.h +56 -1

87 lines not on this page · raw message

lib/eal/version.map +2 -0
index 33b853d7be..6d32c19286 100644
@@ -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;
 };
Signature · 1 line
2.42.0
#10 lore raw

Re: [PATCH 05/11] eal: force prefix for internal threads

Quoted 46 lines · Thomas Monjalon

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.

---
 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(-)
devtools/checkpatches.sh +8 -0
index 131ffbcebe..18ad6fbb7f 100755
@@ -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' \
lib/eal/common/eal_common_thread.c +0 -0
index 07ac721da1..31c37e3102 100644

lib/eal/common/eal_common_thread.c rte_thread_create_control(rte_thread_t *thread, const char *name, · line 398

Quoted 7 lines
lib/eal/common/eal_common_thread.c +4 -0
@@ -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?

Quoted 53 lines
lib/eal/common/eal_common_thread.c +26 -0
+       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)
 {
lib/eal/include/rte_thread.h +4 -1
index dd1f62523f..4b1135df4f 100644
@@ -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.

lib/eal/include/rte_thread.h int · line 130

Quoted 7 lines
lib/eal/include/rte_thread.h +4 -0
@@ -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.

lib/eal/include/rte_thread.h int · line 140

Quoted 10 lines
lib/eal/include/rte_thread.h +10 -0
+ * 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.

Quoted 69 lines
lib/eal/include/rte_thread.h +38 -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.
  *
lib/eal/version.map +2 -1
index 33b853d7be..6d32c19286 100644
@@ -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

Signature · 1 line
David Marchand
#11 lore raw

RE: [PATCH 05/11] eal: force prefix for internal threads

Quoted 121 lines

From: David Marchand [mailto:[email protected]]
Sent: Thursday, 7 September 2023 10.28

Quoted 27 lines · Thomas Monjalon

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.

---
 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(-)
devtools/checkpatches.sh +0 -0
index 131ffbcebe..18ad6fbb7f 100755

devtools/checkpatches.sh check_forbidden_additions() { # <patch> · line 166

Quoted 8 lines
devtools/checkpatches.sh +5 -0
@@ -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' \

Review

Quoted 7 lines
devtools/checkpatches.sh +3 -0
+               -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' \
(quoted diff) +0 -0

b/lib/eal/common/eal_common_thread.c

lib/eal/common/eal_common_thread.c rte_thread_create_control(rte_thread_t *thread, const

Quoted 4 lines

index 07ac721da1..31c37e3102 100644

lib/eal/common/eal_common_thread.c +0 -0
@@ -392,6 +392,36 @@ rte_thread_create_control(rte_thread_t *thread, const

char *name,

lib/eal/common/eal_common_thread.c rte_thread_create_control(rte_thread_t *thread, const char *name, · line 398

Quoted 7 lines
lib/eal/common/eal_common_thread.c +4 -0
        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?

Quoted 56 lines
lib/eal/common/eal_common_thread.c +26 -0
+       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)
 {
lib/eal/include/rte_thread.h +4 -1
index dd1f62523f..4b1135df4f 100644
@@ -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);
 
Quoted 8 lines

lib/eal/include/rte_thread.h int · line 130

Quoted 4 lines
lib/eal/include/rte_thread.h +4 -0
+/**
+ * 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)

Quoted 15 lines

lib/eal/include/rte_thread.h int · line 131

Quoted 3 lines
lib/eal/include/rte_thread.h +1 -0
+ * If setting the name of the thread fails, the error is ignored and

logged.

lib/eal/include/rte_thread.h int

Quoted 3 lines
lib/eal/include/rte_thread.h +3 -0
+ *
+ * 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.

lib/eal/include/rte_thread.h int · line 140

Quoted 6 lines
lib/eal/include/rte_thread.h +6 -0
+ *
+ * @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').
Quoted 3 lines

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.");
Quoted 75 lines
Quoted 69 lines
lib/eal/include/rte_thread.h +38 -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.
  *
lib/eal/version.map +2 -1
index 33b853d7be..6d32c19286 100644
@@ -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;
 };
--
Quoted 2 lines

2.42.0

--
David Marchand

#12 lore raw

Re: [PATCH 05/11] eal: force prefix for internal threads

Quoted 6 lines · Morten Brørup
Quoted 3 lines

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.

Quoted 7 lines

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 ?

Signature · 1 line
David Marchand
#13 lore raw

Re: [PATCH 05/11] eal: force prefix for internal threads

Quoted 10 lines · David Marchand
Quoted 8 lines · Morten Brørup
Quoted 3 lines

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.

Quoted 7 lines
Quoted 5 lines

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.

Signature · 1 line
David Marchand
#14 lore raw

RE: [PATCH 05/11] eal: force prefix for internal threads

Quoted 19 lines

From: David Marchand [mailto:[email protected]]
Sent: Thursday, 7 September 2023 10.55

Quoted 2 lines · David Marchand

On Thu, Sep 7, 2023 at 10:50 AM Morten Brørup <[email protected]>

Quoted 7 lines · wrote:
Quoted 7 lines
Quoted 3 lines

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.

Quoted 3 lines
Quoted 3 lines

For the best of both worlds, you can add something like this nearby:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

_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".

#15 lore raw

Re: [PATCH 05/11] eal: force prefix for internal threads

07/09/2023 13:10, Morten Brørup:

Quoted 28 lines
Quoted 19 lines

From: David Marchand [mailto:[email protected]]
Sent: Thursday, 7 September 2023 10.55

Quoted 2 lines · David Marchand

On Thu, Sep 7, 2023 at 10:50 AM Morten Brørup <[email protected]>

Quoted 7 lines · wrote:
Quoted 7 lines
Quoted 3 lines

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.

Quoted 3 lines
Quoted 3 lines

For the best of both worlds, you can add something like this nearby:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

_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.

Quoted 7 lines

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.

#16 lore raw

RE: [PATCH 05/11] eal: force prefix for internal threads

Quoted 50 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Monday, 11 September 2023 17.26

07/09/2023 13:10, Morten Brørup:

Quoted 7 lines
Quoted 7 lines

From: David Marchand [mailto:[email protected]]
Sent: Thursday, 7 September 2023 10.55

Quoted 2 lines · David Marchand

On Thu, Sep 7, 2023 at 10:50 AM Morten Brørup

<[email protected]>

Quoted 2 lines
Quoted 2 lines
Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line

This 10 value in the comment is easy to miss if some change

with the

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

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

Quoted 3 lines
Quoted 3 lines

mentioned.

Quoted 2 lines
Quoted 2 lines

For the best of both worlds, you can add something like this

nearby:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

_Static_assert(sizeof(RTE_THREAD_NAME_PREFIX) == sizeof("dpdk-

"),

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

"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

Quoted 3 lines
Quoted 1 line

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.

Quoted 2 lines

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.)

Quoted 2 lines

Also, the failure message could be improved to include help about what

to look for.

Quoted 2 lines

PS: The reference to RTE_THREAD_INTERNAL_NAME_SIZE should remain in

Quoted 8 lines

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.

#17 lore raw

PATCH 6/11 lib: convert to internal control threads

In reply to Thomas Monjalon

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.

---
 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(-)
lib/eal/common/eal_common_proc.c +8 -7
index 26e6b78f8f..f20a348ede 100644
@@ -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);
 }
 
lib/eal/freebsd/eal_interrupts.c +5 -5
index 68cdb9deb3..2b31dfb099 100644
@@ -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());
 }
lib/eal/linux/eal_interrupts.c +5 -5
index 19b36787b8..24fff3d3c2 100644
@@ -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());
 }
lib/eal/linux/eal_timer.c +6 -5
index 1898709700..3a30284e3a 100644
@@ -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;
lib/eal/unix/rte_thread.c +1 -1
index f4076122a4..36a21ab2f9 100644
@@ -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)
lib/eal/windows/eal_interrupts.c +1 -1
index 66a49c844a..49efdc098c 100644
@@ -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;
lib/eventdev/rte_event_eth_rx_adapter.c +12 -11
index 3ebfa5366d..c166ef69a8 100644
@@ -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);
 
lib/vhost/fd_man.c +3 -3
index 1876fada33..134414fb4b 100644
@@ -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
lib/vhost/fd_man.h +1 -1
index 6f4499bdfa..6315904c8e 100644
@@ -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);
 
lib/vhost/socket.c +11 -12
index 12095b0e1a..5882e44176 100644
@@ -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);
lib/vhost/vduse.c +3 -2
index 7770259f37..e342f53b81 100644
@@ -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");
Signature · 1 line
2.42.0
#18 lore raw

PATCH 7/11 drivers: convert to internal control threads

In reply to Thomas Monjalon

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.

---
 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(-)
drivers/common/cnxk/roc_dev.c +8 -8
index 13d3eece47..08fd13f741 100644
@@ -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);
 	}
drivers/common/cnxk/roc_dev_priv.h +1 -1
index 1f84f74ff3..c1a37aa4f0 100644
@@ -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;
 };
drivers/common/cnxk/roc_nix_inl_dev.c +4 -5
index d76158e30d..7400069309 100644
@@ -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);
drivers/common/cnxk/roc_nix_inl_priv.h +1 -1
index b0a8976c6b..b2b89227b1 100644
@@ -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;
drivers/common/cnxk/roc_platform.h +2 -1
index 08f83aba12..d8f2707a6e 100644
@@ -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
drivers/dma/skeleton/skeleton_dmadev.c +4 -3
index 4fc2319668..eabe88fada 100644
@@ -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;
drivers/event/dlb2/pf/base/dlb2_osdep.h +5 -9
index 75860cca4d..06d69f39b1 100644
@@ -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",
drivers/event/dlb2/pf/base/dlb2_resource.c +21 -18
index dd8390a013..7ce3e3531c 100644
@@ -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;
drivers/event/dlb2/pf/dlb2_main.h +0 -1
index 4c64d72e9c..12912a2dec 100644
@@ -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;
 };
drivers/net/ark/ark_ethdev.c +5 -6
index 30814650bf..3ddcc9b461 100644
@@ -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;
drivers/net/ark/ark_pktgen.c +4 -4
index cd2d3adc51..69ff7072b2 100644
@@ -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;
 }
drivers/net/ark/ark_pktgen.h +1 -1
index 7147fe1bd4..925058367c 100644
@@ -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
drivers/net/iavf/iavf_vchnl.c +1 -1
index 6baa6d5955..b3e106b41f 100644
@@ -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;
drivers/net/ice/ice_dcf_parent.c +3 -4
index d3bb65874f..173ed9f81d 100644
@@ -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");
drivers/net/ipn3ke/ipn3ke_representor.c +8 -9
index c82f8b5333..57ec7a19bc 100644
@@ -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");
 
drivers/net/ixgbe/ixgbe_ethdev.c +3 -4
index 64e7e5d7d6..cd4a85b3a7 100644
@@ -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 */
drivers/net/mlx5/mlx5.h +1 -1
index 3785103308..c587e13c63 100644
@@ -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;
 };
drivers/net/mlx5/mlx5_hws_cnt.c +22 -20

78 lines not on this page · raw message

drivers/net/sfc/sfc_mae.h +1 -1
index 646d055ac1..7988424449 100644
@@ -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;
drivers/net/sfc/sfc_mae_counter.c +5 -6
index 631b54afeb..ba17295719 100644
@@ -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;
 }
drivers/net/txgbe/txgbe_ethdev.c +3 -3
index 198fac8318..15911a3621 100644
@@ -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);
 				}
drivers/raw/ifpga/ifpga_rawdev.c +9 -10
index a7b18299de..f89bd3f9e2 100644
@@ -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");
 
drivers/vdpa/ifc/ifcvf_vdpa.c +40 -46

218 lines not on this page · raw message

drivers/vdpa/mlx5/mlx5_vdpa.c +1 -1
index f1737f82a8..01a5877d08 100644
@@ -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);
drivers/vdpa/mlx5/mlx5_vdpa.h +4 -6
index dc4dfba5ed..7b37c98e74 100644
@@ -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
drivers/vdpa/mlx5/mlx5_vdpa_cthread.c +17 -53

129 lines not on this page · raw message

drivers/vdpa/mlx5/mlx5_vdpa_event.c +20 -44

116 lines not on this page · raw message

drivers/vdpa/sfc/sfc_vdpa_ops.c +7 -8
index f63af7d478..00f9a4b04c 100644
@@ -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",
drivers/vdpa/sfc/sfc_vdpa_ops.h +2 -1
index 5c8e352de3..10ea239434 100644
@@ -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;
Signature · 1 line
2.42.0
Acked-by on v1 7/11
#19 lore raw

Re: [PATCH 07/11] drivers: convert to internal control threads

Quoted 10 lines · Thomas Monjalon

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.

Quoted 5 lines

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.

For net/sfc

#20 lore raw

PATCH 8/11 examples: convert to normal control threads

In reply to Thomas Monjalon

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.

---
 examples/vhost/main.c          |  9 +++++----
 examples/vhost_blk/vhost_blk.c | 21 ++++++---------------
 2 files changed, 11 insertions(+), 19 deletions(-)
examples/vhost/main.c +5 -4
index 9ff2c1f31b..ce5c1efddf 100644
@@ -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,
examples/vhost_blk/vhost_blk.c +6 -15
index 45699eb0b3..376f7b89a7 100644
@@ -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;
 }
 
Signature · 1 line
2.42.0
#22 lore raw

PATCH 9/11 test: convert threads creation

In reply to Thomas Monjalon

Calls to pthread for thread creation are replaced with the rte_thread API.

---
 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(-)
app/test/process.h +5 -5
index 1f073b9c5c..af7bc3e0de 100644
@@ -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
app/test/test_lcores.c +4 -5
index 0c96faa4cb..22225a9fd3 100644
@@ -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.
app/test/test_pdump.c +3 -3
index ea03056b47..adf49f0b54 100644
@@ -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;
 }
 
 /*
app/test/test_pdump.h +1 -1
index abef9a85ec..8746d61269 100644
@@ -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);
Signature · 1 line
2.42.0
#24 lore raw

PATCH 10/11 eal: remove deprecated thread functions

In reply to Thomas Monjalon

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()

---
 .../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(-)
doc/guides/prog_guide/env_abstraction_layer.rst +1 -1
index 89014789de..6debf54efb 100644
@@ -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.
 
doc/guides/rel_notes/deprecation.rst +0 -5
index 3e48908b51..8c8873006d 100644
@@ -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.
 
doc/guides/rel_notes/release_23_11.rst +3 -1
index d7562fd646..9746809a66 100644
@@ -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
lib/eal/common/eal_common_thread.c +2 -64

89 lines not on this page · raw message

lib/eal/freebsd/eal_thread.c +0 -7
index ba9b25c2c0..6f97a3c2c1 100644
@@ -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;
-}
lib/eal/include/rte_lcore.h +0 -42

54 lines not on this page · raw message

lib/eal/linux/eal_thread.c +0 -16
index b9a126f3a8..880070c627 100644
@@ -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;
-}
lib/eal/version.map +0 -2
index 6d32c19286..915057b325 100644
@@ -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;
lib/eal/windows/eal_thread.c +0 -8
index 464d510838..9e3df200b9 100644
@@ -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;
-}
Signature · 1 line
2.42.0
Acked-by on v1 10/11
#25 lore raw

Re: [PATCH 10/11] eal: remove deprecated thread functions

Quoted 8 lines · Thomas Monjalon

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()

Quoted 7 lines

rte_ctrl_thread_create()
can be replaced with
rte_thread_create_control()
or rte_thread_create_internal_control()

---

with suggestions.

...

lib/eal/common/eal_common_thread.c struct rte_thread_ctrl_params { · line 249

Quoted 8 lines

ABI Changes

lib/eal/common/eal_common_thread.c +0 -0
index 31c37e3102..78f643af73 100644
@@ -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.

Quoted 9 lines
lib/eal/common/eal_common_thread.c +1 -1
-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;
 }
#26 lore raw

Re: [PATCH 10/11] eal: remove deprecated thread functions

08/09/2023 06:22, Tyler Retzlaff:

Quoted 9 lines · Thomas Monjalon

lib/eal/common/eal_common_thread.c struct rte_thread_ctrl_params { · line 249

Quoted 5 lines
lib/eal/common/eal_common_thread.c +0 -0
@@ -248,7 +248,7 @@ struct rte_thread_ctrl_params {
 	enum __rte_ctrl_thread_status ctrl_thread_status;
 };

the code above here

Quoted 4 lines

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.

#27 lore raw

Re: [PATCH 10/11] eal: remove deprecated thread functions

Quoted 10 lines · Thomas Monjalon

08/09/2023 06:22, Tyler Retzlaff:

Quoted 9 lines · Thomas Monjalon

lib/eal/common/eal_common_thread.c struct rte_thread_ctrl_params { · line 249

Quoted 5 lines
lib/eal/common/eal_common_thread.c +0 -0
@@ -248,7 +248,7 @@ struct rte_thread_ctrl_params {
 	enum __rte_ctrl_thread_status ctrl_thread_status;
 };

the code above here

Quoted 8 lines
Quoted 4 lines

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.

Quoted 1 line
#28 lore raw

PATCH 11/11 lib: remove pthread.h from includes

In reply to Thomas Monjalon

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.

---
 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(-)
app/test/test_link_bonding.c +2 -0
index 2f46e4c6ee..d6b6ebc2f2 100644
@@ -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>
drivers/common/mlx5/mlx5_common.c +1 -0
index 0ad14a48c7..ca8543e36e 100644
@@ -5,6 +5,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <stdio.h>
+#include <pthread.h>
 
 #include <rte_errno.h>
 #include <rte_mempool.h>
drivers/common/mlx5/windows/mlx5_win_ext.h +2 -0
index 6f69329a6f..a71c69bff5 100644
@@ -5,6 +5,8 @@
 #ifndef __MLX5_WIN_ETX_H__
 #define __MLX5_WIN_ETX_H__
 
+#include <pthread.h>
+
 #include "mlx5_prm.h"
 #include "mlx5devx.h"
 
drivers/net/bnxt/bnxt.h +1 -0
index ed21ba7f29..0e01b1d4ba 100644
@@ -8,6 +8,7 @@
 
 #include <inttypes.h>
 #include <stdbool.h>
+#include <pthread.h>
 #include <sys/queue.h>
 
 #include <rte_pci.h>
drivers/net/qede/base/bcm_osal.h +1 -0
index 97e261d306..11019b5623 100644
@@ -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>
drivers/raw/ifpga/base/opae_osdep.h +1 -0
index 033b7e098c..e91205f536 100644
@@ -7,6 +7,7 @@
 
 #include <string.h>
 #include <stdbool.h>
+#include <pthread.h>
 
 #ifdef RTE_LIB_EAL
 #include "osdep_rte/osdep_generic.h"
drivers/vdpa/sfc/sfc_vdpa.c +1 -0
index bd6ecde450..9db87fcb7d 100644
@@ -4,6 +4,7 @@
 
 #include <stdbool.h>
 #include <stdint.h>
+#include <pthread.h>
 #include <sys/queue.h>
 
 #include <rte_common.h>
lib/eal/common/eal_common_options.c +1 -0
index d74b581567..a6d21f1cba 100644
@@ -5,6 +5,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <pthread.h>
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include <syslog.h>
 #endif
lib/eal/common/eal_common_trace.c +1 -0
index cb980af06d..b21e61bf39 100644
@@ -4,6 +4,7 @@
 
 #include <stdlib.h>
 #include <fnmatch.h>
+#include <pthread.h>
 #include <sys/queue.h>
 #include <regex.h>
 
lib/eal/common/malloc_mp.c +1 -0
index 7270c2ec90..4d62397aba 100644
@@ -4,6 +4,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <pthread.h>
 #include <sys/time.h>
 
 #include <rte_errno.h>
lib/eal/freebsd/eal_alarm.c +1 -0
index acdcf53804..e5b0909a45 100644
@@ -4,6 +4,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <pthread.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
lib/eal/include/rte_per_lcore.h +0 -2
index 2b846f9337..5a1497631a 100644
@@ -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
lib/eal/linux/eal_alarm.c +1 -0
index 397f25d7d5..766ba2c251 100644
@@ -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>
lib/ethdev/ethdev_driver.c +1 -0
index 0be1e8ca04..30db839a77 100644
@@ -3,6 +3,7 @@
  */
 
 #include <stdlib.h>
+#include <pthread.h>
 
 #include <rte_kvargs.h>
 #include <rte_malloc.h>
lib/ethdev/ethdev_driver.h +2 -0
index 980f837ab6..3fa8b309c1 100644
@@ -18,6 +18,8 @@ extern "C" {
  * use them.
  */
 
+#include <pthread.h>
+
 #include <dev_driver.h>
 #include <rte_compat.h>
 #include <rte_ethdev.h>
lib/ethdev/rte_ethdev_core.h +0 -2
index 46e9721e07..8d260584b4 100644
@@ -5,8 +5,6 @@
 #ifndef _RTE_ETHDEV_CORE_H_
 #define _RTE_ETHDEV_CORE_H_
 
-#include <pthread.h>
-
 /**
  * @file
  *
lib/ethdev/rte_flow.c +1 -0
index 271d854f78..0c5aabea45 100644
@@ -6,6 +6,7 @@
 #include <errno.h>
 #include <stddef.h>
 #include <stdint.h>
+#include <pthread.h>
 
 #include <rte_common.h>
 #include <rte_errno.h>
lib/eventdev/rte_event_eth_rx_adapter.c +1 -0
index c166ef69a8..2145d803e4 100644
@@ -4,6 +4,7 @@
  */
 #include <ctype.h>
 #include <stdlib.h>
+#include <pthread.h>
 #if defined(LINUX)
 #include <sys/epoll.h>
 #endif
lib/vhost/vhost.c +1 -0
index eb6309b681..c03bb9c6eb 100644
@@ -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>
Signature · 1 line
2.42.0
Acked-by on v1 11/11
#31 lore raw

RE: [PATCH 11/11] lib: remove pthread.h from includes

In reply to Thomas Monjalon

Hi,

Quoted 22 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Thursday, September 7, 2023 12:12 AM
To: [email protected]
Cc: Tyler Retzlaff <[email protected]>; David Marchand <[email protected]>; Ferruh Yigit <[email protected]>; Chas Williams <[email protected]>; Min Hu (Connor) <[email protected]>; Matan Azrad <[email protected]>; Viacheslav Ovsiienko <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Ajit Khaparde <[email protected]>; Somnath Kotur <[email protected]>; Devendra Singh Rawat <[email protected]>; Alok Prasad <[email protected]>; Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>; Vijay Kumar Srivastava <[email protected]>; Jerin Jacob <[email protected]>; Sunil Kumar Kori <[email protected]>; Burakov, Anatoly <[email protected]>; Richardson, Bruce <[email protected]>; Andrew Rybchenko <[email protected]>; Naga Harish K, S V <[email protected]>; Maxime Coquelin <[email protected]>; Xia, Chenbo <[email protected]>
Subject: [PATCH 11/11] lib: remove pthread.h from includes

Quoted 7 lines

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.

---
 drivers/raw/ifpga/base/opae_osdep.h        | 1 +
#32 lore raw
In reply to Thomas Monjalon
Quoted 8 lines

From: Thomas Monjalon [mailto:[email protected]]
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.

Quoted 14 lines

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

Quoted 12 lines

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.

#33 lore raw
Quoted 38 lines · Morten Brørup
Quoted 8 lines

From: Thomas Monjalon [mailto:[email protected]]
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.

Quoted 14 lines

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

Quoted 12 lines

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

Quoted 3 lines

Thank you for cleaning all this up, Thomas.

+1

thank you very much, this has been on my todo list it's really appreciated!

#34 lore raw

v2 cover rework thread management

In reply to 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

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(-)
Signature · 1 line
2.42.0
#35 lore raw

PATCH v2 1/11 devtools: warn when adding some pthread calls

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.

---
v2: replace (|_) with _?

---
 devtools/checkpatches.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
devtools/checkpatches.sh +8 -0
index 55fabc5458..ec9d232393 100755
@@ -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\\>' \
Signature · 1 line
2.42.0
#36 lore raw

PATCH v2 2/11 eal: rename thread name length definition

In reply to Thomas Monjalon

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.

---
 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(-)
lib/eal/freebsd/eal.c +1 -1
index 9e1e267955..39a2868523 100644
@@ -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();
lib/eal/freebsd/eal_thread.c +1 -1
index 3227d9b8a2..ba9b25c2c0 100644
@@ -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)
lib/eal/include/rte_eal.h +0 -3
index 53c4a5519e..cd318ee141 100644
@@ -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
  */
lib/eal/include/rte_thread.h +7 -2
index 369e2375f6..6233142322 100644
@@ -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
lib/eal/linux/eal.c +1 -1
index a26822f667..5f4b2fb005 100644
@@ -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 =
lib/eal/linux/eal_thread.c +1 -1
index c07ad9d8a4..b9a126f3a8 100644
@@ -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)
lib/eal/windows/eal.c +1 -1
index 16c1ba1596..7ec2152211 100644
@@ -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);
 
lib/eal/windows/rte_thread.c +1 -1
index e528ac9991..acf648456c 100644
@@ -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;
Signature · 1 line
2.42.0
#37 lore raw

PATCH v2 3/11 eal: remove attributes from control thread creation

In reply to Thomas Monjalon

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.

---
 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(-)
app/test/test_threads.c +1 -1
index 8c27e2bae1..4ac3f2671a 100644
@@ -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)
doc/guides/rel_notes/release_23_11.rst +3 -0
index 333e1d95a2..d3d500f294 100644
@@ -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
 -----------
drivers/dma/skeleton/skeleton_dmadev.c +1 -2
index 493224542f..4fc2319668 100644
@@ -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;
drivers/net/iavf/iavf_vchnl.c +1 -1
index c31a6d5c98..6baa6d5955 100644
@@ -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;
 	}
drivers/net/ice/ice_dcf_parent.c +1 -1
index ad98a531de..d3bb65874f 100644
@@ -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");
drivers/net/ixgbe/ixgbe_ethdev.c +0 -1
index 7eac05ee60..64e7e5d7d6 100644
@@ -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,
drivers/net/txgbe/txgbe_ethdev.c +1 -1
index 6f2f5a1841..198fac8318 100644
@@ -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);
lib/eal/common/eal_common_thread.c +2 -3
index 6605bd017e..07ac721da1 100644
@@ -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;
lib/eal/include/rte_thread.h +1 -4
index 6233142322..28cc5220a4 100644
@@ -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
lib/eal/windows/eal_interrupts.c +1 -1
index b1b1228c2b..66a49c844a 100644
@@ -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;
Signature · 1 line
2.42.0
#38 lore raw

PATCH v2 4/11 eal: promote thread API as stable

In reply to Thomas Monjalon

The rte_thread API must be used to ease OS porting. One step of this process is to mark the necessary API as stable.

---
 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(-)
doc/guides/rel_notes/release_23_11.rst +1 -0
index d3d500f294..d7562fd646 100644
@@ -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
lib/eal/include/rte_thread.h +0 -64

240 lines not on this page · raw message

lib/eal/version.map +19 -21
index 7940431e5a..33b853d7be 100644
@@ -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
Signature · 1 line
2.42.0
#39 lore raw

PATCH v2 5/11 eal: force prefix for internal threads

In reply to Thomas Monjalon

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.

---
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(-)
devtools/checkpatches.sh +8 -0
index ec9d232393..e97811192a 100755
@@ -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' \
lib/eal/common/eal_common_thread.c +29 -0
index 07ac721da1..cd6e00fe8a 100644
@@ -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)
 {
lib/eal/include/rte_thread.h +58 -1

89 lines not on this page · raw message

lib/eal/version.map +2 -0
index 33b853d7be..6d32c19286 100644
@@ -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;
 };
Signature · 1 line
2.42.0
#40 lore raw

PATCH v2 6/11 lib: convert to internal control threads

In reply to Thomas Monjalon

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.

---
 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(-)
lib/eal/common/eal_common_proc.c +8 -7
index 26e6b78f8f..f20a348ede 100644
@@ -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);
 }
 
lib/eal/freebsd/eal_interrupts.c +5 -5
index 68cdb9deb3..2b31dfb099 100644
@@ -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());
 }
lib/eal/linux/eal_interrupts.c +5 -5
index 19b36787b8..24fff3d3c2 100644
@@ -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());
 }
lib/eal/linux/eal_timer.c +6 -5
index 1898709700..3a30284e3a 100644
@@ -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;
lib/eal/unix/rte_thread.c +1 -1
index f4076122a4..36a21ab2f9 100644
@@ -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)
lib/eal/windows/eal_interrupts.c +1 -1
index 66a49c844a..49efdc098c 100644
@@ -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;
lib/eventdev/rte_event_eth_rx_adapter.c +12 -11
index 3ebfa5366d..c166ef69a8 100644
@@ -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);
 
lib/vhost/fd_man.c +3 -3
index 1876fada33..134414fb4b 100644
@@ -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
lib/vhost/fd_man.h +1 -1
index 6f4499bdfa..6315904c8e 100644
@@ -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);
 
lib/vhost/socket.c +11 -12
index 12095b0e1a..5882e44176 100644
@@ -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);
lib/vhost/vduse.c +3 -2
index 7770259f37..e342f53b81 100644
@@ -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");
Signature · 1 line
2.42.0
#41 lore raw

PATCH v2 7/11 drivers: convert to internal control threads

In reply to Thomas Monjalon

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.

---
 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(-)
drivers/common/cnxk/roc_dev.c +8 -8
index 13d3eece47..08fd13f741 100644
@@ -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);
 	}
drivers/common/cnxk/roc_dev_priv.h +1 -1
index 1f84f74ff3..c1a37aa4f0 100644
@@ -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;
 };
drivers/common/cnxk/roc_nix_inl_dev.c +4 -5
index d76158e30d..7400069309 100644
@@ -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);
drivers/common/cnxk/roc_nix_inl_priv.h +1 -1
index b0a8976c6b..b2b89227b1 100644
@@ -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;
drivers/common/cnxk/roc_platform.h +2 -1
index 08f83aba12..d8f2707a6e 100644
@@ -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
drivers/dma/skeleton/skeleton_dmadev.c +4 -3
index 4fc2319668..eabe88fada 100644
@@ -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;
drivers/event/dlb2/pf/base/dlb2_osdep.h +5 -9
index 75860cca4d..06d69f39b1 100644
@@ -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",
drivers/event/dlb2/pf/base/dlb2_resource.c +21 -18
index dd8390a013..7ce3e3531c 100644
@@ -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;
drivers/event/dlb2/pf/dlb2_main.h +0 -1
index 4c64d72e9c..12912a2dec 100644
@@ -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;
 };
drivers/net/ark/ark_ethdev.c +5 -6
index 30814650bf..3ddcc9b461 100644
@@ -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;
drivers/net/ark/ark_pktgen.c +4 -4
index cd2d3adc51..69ff7072b2 100644
@@ -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;
 }
drivers/net/ark/ark_pktgen.h +1 -1
index 7147fe1bd4..925058367c 100644
@@ -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
drivers/net/iavf/iavf_vchnl.c +1 -1
index 6baa6d5955..b3e106b41f 100644
@@ -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;
drivers/net/ice/ice_dcf_parent.c +3 -4
index d3bb65874f..173ed9f81d 100644
@@ -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");
drivers/net/ipn3ke/ipn3ke_representor.c +8 -9
index c82f8b5333..57ec7a19bc 100644
@@ -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");
 
drivers/net/ixgbe/ixgbe_ethdev.c +3 -4
index 64e7e5d7d6..cd4a85b3a7 100644
@@ -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 */
drivers/net/mlx5/mlx5.h +1 -1
index 3785103308..c587e13c63 100644
@@ -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;
 };
drivers/net/mlx5/mlx5_hws_cnt.c +22 -20

78 lines not on this page · raw message

drivers/net/sfc/sfc_mae.h +1 -1
index 646d055ac1..7988424449 100644
@@ -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;
drivers/net/sfc/sfc_mae_counter.c +5 -6
index 631b54afeb..ba17295719 100644
@@ -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;
 }
drivers/net/txgbe/txgbe_ethdev.c +3 -3
index 198fac8318..15911a3621 100644
@@ -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);
 				}
drivers/raw/ifpga/ifpga_rawdev.c +9 -10
index a7b18299de..f89bd3f9e2 100644
@@ -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");
 
drivers/vdpa/ifc/ifcvf_vdpa.c +40 -46

218 lines not on this page · raw message

drivers/vdpa/mlx5/mlx5_vdpa.c +1 -1
index f1737f82a8..01a5877d08 100644
@@ -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);
drivers/vdpa/mlx5/mlx5_vdpa.h +4 -6
index dc4dfba5ed..7b37c98e74 100644
@@ -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
drivers/vdpa/mlx5/mlx5_vdpa_cthread.c +17 -53

129 lines not on this page · raw message

drivers/vdpa/mlx5/mlx5_vdpa_event.c +20 -44

116 lines not on this page · raw message

drivers/vdpa/sfc/sfc_vdpa_ops.c +7 -8
index f63af7d478..00f9a4b04c 100644
@@ -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",
drivers/vdpa/sfc/sfc_vdpa_ops.h +2 -1
index 5c8e352de3..10ea239434 100644
@@ -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;
Signature · 1 line
2.42.0
#42 lore raw

PATCH v2 8/11 examples: convert to normal control threads

In reply to Thomas Monjalon

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.

---
 examples/vhost/main.c          |  9 +++++----
 examples/vhost_blk/vhost_blk.c | 21 ++++++---------------
 2 files changed, 11 insertions(+), 19 deletions(-)
examples/vhost/main.c +5 -4
index 9ff2c1f31b..ce5c1efddf 100644
@@ -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,
examples/vhost_blk/vhost_blk.c +6 -15
index 45699eb0b3..376f7b89a7 100644
@@ -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;
 }
 
Signature · 1 line
2.42.0
#43 lore raw

PATCH v2 9/11 test: convert threads creation

In reply to Thomas Monjalon

Calls to pthread for thread creation are replaced with the rte_thread API.

---
 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(-)
app/test/process.h +5 -5
index 1f073b9c5c..af7bc3e0de 100644
@@ -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
app/test/test_lcores.c +4 -5
index 0c96faa4cb..22225a9fd3 100644
@@ -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.
app/test/test_pdump.c +3 -3
index ea03056b47..adf49f0b54 100644
@@ -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;
 }
 
 /*
app/test/test_pdump.h +1 -1
index abef9a85ec..8746d61269 100644
@@ -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);
Signature · 1 line
2.42.0
#44 lore raw

PATCH v2 10/11 eal: remove deprecated thread functions

In reply to Thomas Monjalon

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()

---
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(-)
doc/guides/prog_guide/env_abstraction_layer.rst +1 -1
index 89014789de..6debf54efb 100644
@@ -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.
 
doc/guides/rel_notes/deprecation.rst +0 -5
index 3e48908b51..8c8873006d 100644
@@ -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.
 
doc/guides/rel_notes/release_23_11.rst +3 -1
index d7562fd646..9746809a66 100644
@@ -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
lib/eal/common/eal_common_thread.c +14 -79

152 lines not on this page · raw message

lib/eal/freebsd/eal_thread.c +0 -7
index ba9b25c2c0..6f97a3c2c1 100644
@@ -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;
-}
lib/eal/include/rte_lcore.h +0 -42

54 lines not on this page · raw message

lib/eal/linux/eal_thread.c +0 -16
index b9a126f3a8..880070c627 100644
@@ -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;
-}
lib/eal/version.map +0 -2
index 6d32c19286..915057b325 100644
@@ -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;
lib/eal/windows/eal_thread.c +0 -8
index 464d510838..9e3df200b9 100644
@@ -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;
-}
Signature · 1 line
2.42.0
#45 lore raw

PATCH v2 11/11 lib: remove pthread.h from includes

In reply to Thomas Monjalon

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.

---
 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(-)
app/test/test_link_bonding.c +2 -0
index 2f46e4c6ee..d6b6ebc2f2 100644
@@ -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>
drivers/common/mlx5/mlx5_common.c +1 -0
index 0ad14a48c7..ca8543e36e 100644
@@ -5,6 +5,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <stdio.h>
+#include <pthread.h>
 
 #include <rte_errno.h>
 #include <rte_mempool.h>
drivers/common/mlx5/windows/mlx5_win_ext.h +2 -0
index 6f69329a6f..a71c69bff5 100644
@@ -5,6 +5,8 @@
 #ifndef __MLX5_WIN_ETX_H__
 #define __MLX5_WIN_ETX_H__
 
+#include <pthread.h>
+
 #include "mlx5_prm.h"
 #include "mlx5devx.h"
 
drivers/net/bnxt/bnxt.h +1 -0
index ed21ba7f29..0e01b1d4ba 100644
@@ -8,6 +8,7 @@
 
 #include <inttypes.h>
 #include <stdbool.h>
+#include <pthread.h>
 #include <sys/queue.h>
 
 #include <rte_pci.h>
drivers/net/qede/base/bcm_osal.h +1 -0
index 97e261d306..11019b5623 100644
@@ -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>
drivers/raw/ifpga/base/opae_osdep.h +1 -0
index 033b7e098c..e91205f536 100644
@@ -7,6 +7,7 @@
 
 #include <string.h>
 #include <stdbool.h>
+#include <pthread.h>
 
 #ifdef RTE_LIB_EAL
 #include "osdep_rte/osdep_generic.h"
drivers/vdpa/sfc/sfc_vdpa.c +1 -0
index bd6ecde450..9db87fcb7d 100644
@@ -4,6 +4,7 @@
 
 #include <stdbool.h>
 #include <stdint.h>
+#include <pthread.h>
 #include <sys/queue.h>
 
 #include <rte_common.h>
lib/eal/common/eal_common_options.c +1 -0
index d74b581567..a6d21f1cba 100644
@@ -5,6 +5,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <pthread.h>
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include <syslog.h>
 #endif
lib/eal/common/eal_common_trace.c +1 -0
index cb980af06d..b21e61bf39 100644
@@ -4,6 +4,7 @@
 
 #include <stdlib.h>
 #include <fnmatch.h>
+#include <pthread.h>
 #include <sys/queue.h>
 #include <regex.h>
 
lib/eal/common/malloc_mp.c +1 -0
index 7270c2ec90..4d62397aba 100644
@@ -4,6 +4,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <pthread.h>
 #include <sys/time.h>
 
 #include <rte_errno.h>
lib/eal/freebsd/eal_alarm.c +1 -0
index acdcf53804..e5b0909a45 100644
@@ -4,6 +4,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <pthread.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
lib/eal/include/rte_per_lcore.h +0 -2
index 2b846f9337..5a1497631a 100644
@@ -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
lib/eal/linux/eal_alarm.c +1 -0
index 397f25d7d5..766ba2c251 100644
@@ -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>
lib/ethdev/ethdev_driver.c +1 -0
index 0be1e8ca04..30db839a77 100644
@@ -3,6 +3,7 @@
  */
 
 #include <stdlib.h>
+#include <pthread.h>
 
 #include <rte_kvargs.h>
 #include <rte_malloc.h>
lib/ethdev/ethdev_driver.h +2 -0
index 980f837ab6..3fa8b309c1 100644
@@ -18,6 +18,8 @@ extern "C" {
  * use them.
  */
 
+#include <pthread.h>
+
 #include <dev_driver.h>
 #include <rte_compat.h>
 #include <rte_ethdev.h>
lib/ethdev/rte_ethdev_core.h +0 -2
index 46e9721e07..8d260584b4 100644
@@ -5,8 +5,6 @@
 #ifndef _RTE_ETHDEV_CORE_H_
 #define _RTE_ETHDEV_CORE_H_
 
-#include <pthread.h>
-
 /**
  * @file
  *
lib/ethdev/rte_flow.c +1 -0
index 271d854f78..0c5aabea45 100644
@@ -6,6 +6,7 @@
 #include <errno.h>
 #include <stddef.h>
 #include <stdint.h>
+#include <pthread.h>
 
 #include <rte_common.h>
 #include <rte_errno.h>
lib/eventdev/rte_event_eth_rx_adapter.c +1 -0
index c166ef69a8..2145d803e4 100644
@@ -4,6 +4,7 @@
  */
 #include <ctype.h>
 #include <stdlib.h>
+#include <pthread.h>
 #if defined(LINUX)
 #include <sys/epoll.h>
 #endif
lib/vhost/vhost.c +1 -0
index eb6309b681..c03bb9c6eb 100644
@@ -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>
Signature · 1 line
2.42.0
#46 lore raw

v3 cover rework thread management

In reply to 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(-)
Signature · 1 line
2.42.0
#47 lore raw

PATCH v3 1/11 devtools: warn when adding some pthread calls

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.

---
v2: replace (|_) with _?

---
 devtools/checkpatches.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
devtools/checkpatches.sh +8 -0
index 55fabc5458..ec9d232393 100755
@@ -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\\>' \
Signature · 1 line
2.42.0
#48 lore raw

PATCH v3 2/11 eal: rename thread name length definition

In reply to Thomas Monjalon

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.

---
 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(-)
lib/eal/freebsd/eal.c +1 -1
index 9e1e267955..39a2868523 100644
@@ -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();
lib/eal/freebsd/eal_thread.c +1 -1
index 3227d9b8a2..ba9b25c2c0 100644
@@ -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)
lib/eal/include/rte_eal.h +0 -3
index 53c4a5519e..cd318ee141 100644
@@ -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
  */
lib/eal/include/rte_thread.h +7 -2
index 369e2375f6..6233142322 100644
@@ -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
lib/eal/linux/eal.c +1 -1
index a26822f667..5f4b2fb005 100644
@@ -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 =
lib/eal/linux/eal_thread.c +1 -1
index c07ad9d8a4..b9a126f3a8 100644
@@ -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)
lib/eal/windows/eal.c +1 -1
index 16c1ba1596..7ec2152211 100644
@@ -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);
 
lib/eal/windows/rte_thread.c +1 -1
index e528ac9991..acf648456c 100644
@@ -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;
Signature · 1 line
2.42.0
#49 lore raw

PATCH v3 3/11 eal: remove attributes from control thread creation

In reply to Thomas Monjalon

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.

---
 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(-)
app/test/test_threads.c +1 -1
index 8c27e2bae1..4ac3f2671a 100644
@@ -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)
doc/guides/rel_notes/release_23_11.rst +3 -0
index 333e1d95a2..d3d500f294 100644
@@ -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
 -----------
drivers/dma/skeleton/skeleton_dmadev.c +1 -2
index 493224542f..4fc2319668 100644
@@ -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;
drivers/net/iavf/iavf_vchnl.c +1 -1
index c31a6d5c98..6baa6d5955 100644
@@ -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;
 	}
drivers/net/ice/ice_dcf_parent.c +1 -1
index ad98a531de..d3bb65874f 100644
@@ -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");
drivers/net/ixgbe/ixgbe_ethdev.c +0 -1
index 7eac05ee60..64e7e5d7d6 100644
@@ -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,
drivers/net/txgbe/txgbe_ethdev.c +1 -1
index 6f2f5a1841..198fac8318 100644
@@ -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);
lib/eal/common/eal_common_thread.c +2 -3
index 6605bd017e..07ac721da1 100644
@@ -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;
lib/eal/include/rte_thread.h +1 -4
index 6233142322..28cc5220a4 100644
@@ -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
lib/eal/windows/eal_interrupts.c +1 -1
index b1b1228c2b..66a49c844a 100644
@@ -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;
Signature · 1 line
2.42.0
#50 lore raw

PATCH v3 4/11 eal: promote thread API as stable

In reply to Thomas Monjalon

The rte_thread API must be used to ease OS porting. One step of this process is to mark the necessary API as stable.

---
 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(-)
doc/guides/rel_notes/release_23_11.rst +1 -0
index d3d500f294..d7562fd646 100644
@@ -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
lib/eal/include/rte_thread.h +0 -64

240 lines not on this page · raw message

lib/eal/version.map +19 -21
index 7940431e5a..33b853d7be 100644
@@ -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
Signature · 1 line
2.42.0
#51 lore raw

PATCH v3 5/11 eal: force prefix for internal threads

In reply to Thomas Monjalon

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.

---
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(-)
devtools/checkpatches.sh +8 -0
index ec9d232393..e97811192a 100755
@@ -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' \
lib/eal/common/eal_common_thread.c +33 -0
index 07ac721da1..830273813f 100644
@@ -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)
 {
lib/eal/include/rte_thread.h +56 -1

87 lines not on this page · raw message

lib/eal/version.map +2 -0
index 33b853d7be..6d32c19286 100644
@@ -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;
 };
Signature · 1 line
2.42.0
#52 lore raw

PATCH v3 6/11 lib: convert to internal control threads

In reply to Thomas Monjalon

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.

---
 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(-)
lib/eal/common/eal_common_proc.c +8 -7
index 26e6b78f8f..f20a348ede 100644
@@ -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);
 }
 
lib/eal/freebsd/eal_interrupts.c +5 -5
index 68cdb9deb3..2b31dfb099 100644
@@ -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());
 }
lib/eal/linux/eal_interrupts.c +5 -5
index 19b36787b8..24fff3d3c2 100644
@@ -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());
 }
lib/eal/linux/eal_timer.c +6 -5
index 1898709700..3a30284e3a 100644
@@ -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;
lib/eal/unix/rte_thread.c +1 -1
index f4076122a4..36a21ab2f9 100644
@@ -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)
lib/eal/windows/eal_interrupts.c +1 -1
index 66a49c844a..49efdc098c 100644
@@ -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;
lib/eventdev/rte_event_eth_rx_adapter.c +12 -11
index 3ebfa5366d..c166ef69a8 100644
@@ -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);
 
lib/vhost/fd_man.c +3 -3
index 1876fada33..134414fb4b 100644
@@ -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
lib/vhost/fd_man.h +1 -1
index 6f4499bdfa..6315904c8e 100644
@@ -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);
 
lib/vhost/socket.c +11 -12
index 12095b0e1a..5882e44176 100644
@@ -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);
lib/vhost/vduse.c +3 -2
index 7770259f37..e342f53b81 100644
@@ -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");
Signature · 1 line
2.42.0
#53 lore raw

PATCH v3 7/11 drivers: convert to internal control threads

In reply to Thomas Monjalon

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.

---
 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(-)
drivers/common/cnxk/roc_dev.c +8 -8
index 13d3eece47..08fd13f741 100644
@@ -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);
 	}
drivers/common/cnxk/roc_dev_priv.h +1 -1
index 1f84f74ff3..c1a37aa4f0 100644
@@ -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;
 };
drivers/common/cnxk/roc_nix_inl_dev.c +4 -5
index d76158e30d..7400069309 100644
@@ -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);
drivers/common/cnxk/roc_nix_inl_priv.h +1 -1
index b0a8976c6b..b2b89227b1 100644
@@ -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;
drivers/common/cnxk/roc_platform.h +2 -1
index 08f83aba12..d8f2707a6e 100644
@@ -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
drivers/dma/skeleton/skeleton_dmadev.c +4 -3
index 4fc2319668..eabe88fada 100644
@@ -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;
drivers/event/dlb2/pf/base/dlb2_osdep.h +5 -9
index 75860cca4d..06d69f39b1 100644
@@ -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",
drivers/event/dlb2/pf/base/dlb2_resource.c +21 -18
index dd8390a013..7ce3e3531c 100644
@@ -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;
drivers/event/dlb2/pf/dlb2_main.h +0 -1
index 4c64d72e9c..12912a2dec 100644
@@ -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;
 };
drivers/net/ark/ark_ethdev.c +5 -6
index 30814650bf..3ddcc9b461 100644
@@ -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;
drivers/net/ark/ark_pktgen.c +4 -4
index cd2d3adc51..69ff7072b2 100644
@@ -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;
 }
drivers/net/ark/ark_pktgen.h +1 -1
index 7147fe1bd4..925058367c 100644
@@ -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
drivers/net/iavf/iavf_vchnl.c +1 -1
index 6baa6d5955..b3e106b41f 100644
@@ -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;
drivers/net/ice/ice_dcf_parent.c +3 -4
index d3bb65874f..173ed9f81d 100644
@@ -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");
drivers/net/ipn3ke/ipn3ke_representor.c +8 -9
index c82f8b5333..57ec7a19bc 100644
@@ -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");
 
drivers/net/ixgbe/ixgbe_ethdev.c +3 -4
index 64e7e5d7d6..cd4a85b3a7 100644
@@ -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 */
drivers/net/mlx5/mlx5.h +1 -1
index 3785103308..c587e13c63 100644
@@ -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;
 };
drivers/net/mlx5/mlx5_hws_cnt.c +22 -20

78 lines not on this page · raw message

drivers/net/sfc/sfc_mae.h +1 -1
index 646d055ac1..7988424449 100644
@@ -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;
drivers/net/sfc/sfc_mae_counter.c +5 -6
index 631b54afeb..ba17295719 100644
@@ -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;
 }
drivers/net/txgbe/txgbe_ethdev.c +3 -3
index 198fac8318..15911a3621 100644
@@ -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);
 				}
drivers/raw/ifpga/ifpga_rawdev.c +9 -10
index a7b18299de..f89bd3f9e2 100644
@@ -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");
 
drivers/vdpa/ifc/ifcvf_vdpa.c +40 -46

218 lines not on this page · raw message

drivers/vdpa/mlx5/mlx5_vdpa.c +1 -1
index f1737f82a8..01a5877d08 100644
@@ -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);
drivers/vdpa/mlx5/mlx5_vdpa.h +4 -6
index dc4dfba5ed..7b37c98e74 100644
@@ -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
drivers/vdpa/mlx5/mlx5_vdpa_cthread.c +17 -53

129 lines not on this page · raw message

drivers/vdpa/mlx5/mlx5_vdpa_event.c +20 -44

116 lines not on this page · raw message

drivers/vdpa/sfc/sfc_vdpa_ops.c +7 -8
index f63af7d478..00f9a4b04c 100644
@@ -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",
drivers/vdpa/sfc/sfc_vdpa_ops.h +2 -1
index 5c8e352de3..10ea239434 100644
@@ -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;
Signature · 1 line
2.42.0
#54 lore raw

PATCH v3 8/11 examples: convert to normal control threads

In reply to Thomas Monjalon

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.

---
 examples/vhost/main.c          |  9 +++++----
 examples/vhost_blk/vhost_blk.c | 21 ++++++---------------
 2 files changed, 11 insertions(+), 19 deletions(-)
examples/vhost/main.c +5 -4
index 9ff2c1f31b..ce5c1efddf 100644
@@ -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,
examples/vhost_blk/vhost_blk.c +6 -15
index 45699eb0b3..376f7b89a7 100644
@@ -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;
 }
 
Signature · 1 line
2.42.0
#55 lore raw

PATCH v3 9/11 test: convert threads creation

In reply to Thomas Monjalon

Calls to pthread for thread creation are replaced with the rte_thread API.

---
 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(-)
app/test/process.h +5 -5
index 1f073b9c5c..af7bc3e0de 100644
@@ -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
app/test/test_lcores.c +4 -5
index 0c96faa4cb..22225a9fd3 100644
@@ -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.
app/test/test_pdump.c +3 -3
index ea03056b47..adf49f0b54 100644
@@ -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;
 }
 
 /*
app/test/test_pdump.h +1 -1
index abef9a85ec..8746d61269 100644
@@ -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);
Signature · 1 line
2.42.0
#56 lore raw

PATCH v3 10/11 eal: remove deprecated thread functions

In reply to Thomas Monjalon

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()

---
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(-)
doc/guides/prog_guide/env_abstraction_layer.rst +1 -1
index 89014789de..6debf54efb 100644
@@ -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.
 
doc/guides/rel_notes/deprecation.rst +0 -5
index 3e48908b51..8c8873006d 100644
@@ -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.
 
doc/guides/rel_notes/release_23_11.rst +3 -1
index d7562fd646..9746809a66 100644
@@ -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
lib/eal/common/eal_common_thread.c +14 -79

152 lines not on this page · raw message

lib/eal/freebsd/eal_thread.c +0 -7
index ba9b25c2c0..6f97a3c2c1 100644
@@ -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;
-}
lib/eal/include/rte_lcore.h +0 -42

54 lines not on this page · raw message

lib/eal/linux/eal_thread.c +0 -16
index b9a126f3a8..880070c627 100644
@@ -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;
-}
lib/eal/version.map +0 -2
index 6d32c19286..915057b325 100644
@@ -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;
lib/eal/windows/eal_thread.c +0 -8
index 464d510838..9e3df200b9 100644
@@ -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;
-}
Signature · 1 line
2.42.0
#57 lore raw

PATCH v3 11/11 lib: remove pthread.h from includes

In reply to Thomas Monjalon

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.

---
 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(-)
app/test/test_link_bonding.c +2 -0
index 2f46e4c6ee..d6b6ebc2f2 100644
@@ -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>
drivers/common/mlx5/mlx5_common.c +1 -0
index 0ad14a48c7..ca8543e36e 100644
@@ -5,6 +5,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <stdio.h>
+#include <pthread.h>
 
 #include <rte_errno.h>
 #include <rte_mempool.h>
drivers/common/mlx5/windows/mlx5_win_ext.h +2 -0
index 6f69329a6f..a71c69bff5 100644
@@ -5,6 +5,8 @@
 #ifndef __MLX5_WIN_ETX_H__
 #define __MLX5_WIN_ETX_H__
 
+#include <pthread.h>
+
 #include "mlx5_prm.h"
 #include "mlx5devx.h"
 
drivers/net/bnxt/bnxt.h +1 -0
index ed21ba7f29..0e01b1d4ba 100644
@@ -8,6 +8,7 @@
 
 #include <inttypes.h>
 #include <stdbool.h>
+#include <pthread.h>
 #include <sys/queue.h>
 
 #include <rte_pci.h>
drivers/net/qede/base/bcm_osal.h +1 -0
index 97e261d306..11019b5623 100644
@@ -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>
drivers/raw/ifpga/base/opae_osdep.h +1 -0
index 033b7e098c..e91205f536 100644
@@ -7,6 +7,7 @@
 
 #include <string.h>
 #include <stdbool.h>
+#include <pthread.h>
 
 #ifdef RTE_LIB_EAL
 #include "osdep_rte/osdep_generic.h"
drivers/vdpa/sfc/sfc_vdpa.c +1 -0
index bd6ecde450..9db87fcb7d 100644
@@ -4,6 +4,7 @@
 
 #include <stdbool.h>
 #include <stdint.h>
+#include <pthread.h>
 #include <sys/queue.h>
 
 #include <rte_common.h>
lib/eal/common/eal_common_options.c +1 -0
index d74b581567..a6d21f1cba 100644
@@ -5,6 +5,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <pthread.h>
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include <syslog.h>
 #endif
lib/eal/common/eal_common_trace.c +1 -0
index cb980af06d..b21e61bf39 100644
@@ -4,6 +4,7 @@
 
 #include <stdlib.h>
 #include <fnmatch.h>
+#include <pthread.h>
 #include <sys/queue.h>
 #include <regex.h>
 
lib/eal/common/malloc_mp.c +1 -0
index 7270c2ec90..4d62397aba 100644
@@ -4,6 +4,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <pthread.h>
 #include <sys/time.h>
 
 #include <rte_errno.h>
lib/eal/freebsd/eal_alarm.c +1 -0
index acdcf53804..e5b0909a45 100644
@@ -4,6 +4,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <pthread.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
lib/eal/include/rte_per_lcore.h +0 -2
index 2b846f9337..5a1497631a 100644
@@ -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
lib/eal/linux/eal_alarm.c +1 -0
index 397f25d7d5..766ba2c251 100644
@@ -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>
lib/ethdev/ethdev_driver.c +1 -0
index 0be1e8ca04..30db839a77 100644
@@ -3,6 +3,7 @@
  */
 
 #include <stdlib.h>
+#include <pthread.h>
 
 #include <rte_kvargs.h>
 #include <rte_malloc.h>
lib/ethdev/ethdev_driver.h +2 -0
index 980f837ab6..3fa8b309c1 100644
@@ -18,6 +18,8 @@ extern "C" {
  * use them.
  */
 
+#include <pthread.h>
+
 #include <dev_driver.h>
 #include <rte_compat.h>
 #include <rte_ethdev.h>
lib/ethdev/rte_ethdev_core.h +0 -2
index 46e9721e07..8d260584b4 100644
@@ -5,8 +5,6 @@
 #ifndef _RTE_ETHDEV_CORE_H_
 #define _RTE_ETHDEV_CORE_H_
 
-#include <pthread.h>
-
 /**
  * @file
  *
lib/ethdev/rte_flow.c +1 -0
index 271d854f78..0c5aabea45 100644
@@ -6,6 +6,7 @@
 #include <errno.h>
 #include <stddef.h>
 #include <stdint.h>
+#include <pthread.h>
 
 #include <rte_common.h>
 #include <rte_errno.h>
lib/eventdev/rte_event_eth_rx_adapter.c +1 -0
index c166ef69a8..2145d803e4 100644
@@ -4,6 +4,7 @@
  */
 #include <ctype.h>
 #include <stdlib.h>
+#include <pthread.h>
 #if defined(LINUX)
 #include <sys/epoll.h>
 #endif
lib/vhost/vhost.c +1 -0
index eb6309b681..c03bb9c6eb 100644
@@ -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>
Signature · 1 line
2.42.0
#58 lore raw
In reply to Thomas Monjalon

13/09/2023 12:28, Thomas Monjalon пишет:

Quoted 117 lines

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 -
Quoted 9 lines
  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(-)
#59 lore raw
In reply to Thomas Monjalon
Quoted 21 lines · 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

---

Quoted 8 lines

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.

Signature · 1 line
David Marchand