DPDK patches and discussions
 help / color / mirror / Atom feed
From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: Tyler Retzlaff <roretzla@linux.microsoft.com>,
	David Marchand <david.marchand@redhat.com>,
	Ferruh Yigit <ferruh.yigit@amd.com>,
	Maxime Coquelin <maxime.coquelin@redhat.com>,
	Chenbo Xia <chenbo.xia@intel.com>
Subject: [PATCH 08/11] examples: convert to normal control threads
Date: Wed,  6 Sep 2023 18:12:25 +0200	[thread overview]
Message-ID: <20230906162226.1618088-9-thomas@monjalon.net> (raw)
In-Reply-To: <20230906162226.1618088-1-thomas@monjalon.net>

Calls to rte_ctrl_thread_create() are replaced with
rte_thread_create_control().

In vhost_blk, the control thread is not forced
to be scheduled on core 0 anymore.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 examples/vhost/main.c          |  9 +++++----
 examples/vhost_blk/vhost_blk.c | 21 ++++++---------------
 2 files changed, 11 insertions(+), 19 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 9ff2c1f31b..ce5c1efddf 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -28,6 +28,7 @@
 #include <rte_pause.h>
 #include <rte_dmadev.h>
 #include <rte_vhost_async.h>
+#include <rte_thread.h>
 
 #include "main.h"
 
@@ -1807,7 +1808,7 @@ static const struct rte_vhost_device_ops virtio_net_device_ops =
  * This is a thread will wake up after a period to print stats if the user has
  * enabled them.
  */
-static void *
+static uint32_t
 print_stats(__rte_unused void *arg)
 {
 	struct vhost_dev *vdev;
@@ -1852,7 +1853,7 @@ print_stats(__rte_unused void *arg)
 		fflush(stdout);
 	}
 
-	return NULL;
+	return 0;
 }
 
 static void
@@ -1907,7 +1908,7 @@ main(int argc, char *argv[])
 	unsigned nb_ports, valid_num_ports;
 	int ret, i;
 	uint16_t portid;
-	static pthread_t tid;
+	rte_thread_t tid;
 	uint64_t flags = RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS;
 
 	signal(SIGINT, sigint_handler);
@@ -1986,7 +1987,7 @@ main(int argc, char *argv[])
 
 	/* Enable stats if the user option is set. */
 	if (enable_stats) {
-		ret = rte_ctrl_thread_create(&tid, "dpdk-vhost-stat", NULL,
+		ret = rte_thread_create_control(&tid, "dpdk-vhost-stat",
 					print_stats, NULL);
 		if (ret < 0)
 			rte_exit(EXIT_FAILURE,
diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c
index 45699eb0b3..376f7b89a7 100644
--- a/examples/vhost_blk/vhost_blk.c
+++ b/examples/vhost_blk/vhost_blk.c
@@ -5,8 +5,6 @@
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
 #endif
-#include <pthread.h>
-#include <sched.h>
 
 #include <stdint.h>
 #include <stdlib.h>
@@ -529,12 +527,10 @@ process_vq(struct vhost_blk_queue *vq)
 	}
 }
 
-static void *
+static uint32_t
 ctrlr_worker(void *arg)
 {
 	struct vhost_blk_ctrlr *ctrlr = (struct vhost_blk_ctrlr *)arg;
-	cpu_set_t cpuset;
-	pthread_t thread;
 	int i;
 
 	fprintf(stdout, "Ctrlr Worker Thread start\n");
@@ -546,11 +542,6 @@ ctrlr_worker(void *arg)
 		exit(0);
 	}
 
-	thread = pthread_self();
-	CPU_ZERO(&cpuset);
-	CPU_SET(0, &cpuset);
-	pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
-
 	for (i = 0; i < NUM_OF_BLK_QUEUES; i++)
 		submit_inflight_vq(&ctrlr->queues[i]);
 
@@ -560,7 +551,7 @@ ctrlr_worker(void *arg)
 
 	fprintf(stdout, "Ctrlr Worker Thread Exiting\n");
 	sem_post(&exit_sem);
-	return NULL;
+	return 0;
 }
 
 static int
@@ -605,7 +596,7 @@ new_device(int vid)
 	struct vhost_blk_queue *vq;
 	char path[PATH_MAX];
 	uint64_t features, protocol_features;
-	pthread_t tid;
+	rte_thread_t tid;
 	int i, ret;
 	bool packed_ring, inflight_shmfd;
 
@@ -686,15 +677,15 @@ new_device(int vid)
 	/* start polling vring */
 	worker_thread_status = WORKER_STATE_START;
 	fprintf(stdout, "New Device %s, Device ID %d\n", path, vid);
-	if (rte_ctrl_thread_create(&tid, "dpdk-vhost-blk", NULL,
-				   &ctrlr_worker, ctrlr) != 0) {
+	if (rte_thread_create_control(&tid, "dpdk-vhost-blk",
+			&ctrlr_worker, ctrlr) != 0) {
 		fprintf(stderr, "Worker Thread Started Failed\n");
 		return -1;
 	}
 
 	/* device has been started */
 	ctrlr->started = 1;
-	pthread_detach(tid);
+	rte_thread_detach(tid);
 	return 0;
 }
 
-- 
2.42.0


  parent reply	other threads:[~2023-09-06 16:23 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-06 16:12 [PATCH 00/11] rework thread management Thomas Monjalon
2023-09-06 16:12 ` [PATCH 01/11] devtools: warn when adding some pthread calls Thomas Monjalon
2023-09-07  8:20   ` David Marchand
2023-09-06 16:12 ` [PATCH 02/11] eal: rename thread name length definition Thomas Monjalon
2023-09-08  4:00   ` Tyler Retzlaff
2023-09-06 16:12 ` [PATCH 03/11] eal: remove attributes from control thread creation Thomas Monjalon
2023-09-08  4:02   ` Tyler Retzlaff
2023-09-06 16:12 ` [PATCH 04/11] eal: promote thread API as stable Thomas Monjalon
2023-09-08  4:04   ` Tyler Retzlaff
2023-09-06 16:12 ` [PATCH 05/11] eal: force prefix for internal threads Thomas Monjalon
2023-09-07  8:28   ` David Marchand
2023-09-07  8:50     ` Morten Brørup
2023-09-07  8:53       ` David Marchand
2023-09-07  8:55         ` David Marchand
2023-09-07 11:10           ` Morten Brørup
2023-09-11 16:26             ` Thomas Monjalon
2023-09-11 21:32               ` Morten Brørup
2023-09-06 16:12 ` [PATCH 06/11] lib: convert to internal control threads Thomas Monjalon
2023-09-06 16:12 ` [PATCH 07/11] drivers: " Thomas Monjalon
2023-09-11 13:35   ` Andrew Rybchenko
2023-09-06 16:12 ` Thomas Monjalon [this message]
2023-09-08  4:10   ` [PATCH 08/11] examples: convert to normal " Tyler Retzlaff
2023-09-06 16:12 ` [PATCH 09/11] test: convert threads creation Thomas Monjalon
2023-09-08  4:12   ` Tyler Retzlaff
2023-09-06 16:12 ` [PATCH 10/11] eal: remove deprecated thread functions Thomas Monjalon
2023-09-08  4:22   ` Tyler Retzlaff
2023-09-11 16:13     ` Thomas Monjalon
2023-09-12  0:49       ` Tyler Retzlaff
2023-09-06 16:12 ` [PATCH 11/11] lib: remove pthread.h from includes Thomas Monjalon
2023-09-08  4:25   ` Tyler Retzlaff
2023-09-08  4:49     ` Ajit Khaparde
2023-09-10  2:55   ` Xu, Rosen
2023-09-07  8:30 ` [PATCH 00/11] rework thread management Morten Brørup
2023-09-08  4:26   ` Tyler Retzlaff
2023-09-13 10:34 ` [PATCH v2 " Thomas Monjalon
2023-09-13 10:34   ` [PATCH v2 01/11] devtools: warn when adding some pthread calls Thomas Monjalon
2023-09-13 10:34   ` [PATCH v2 02/11] eal: rename thread name length definition Thomas Monjalon
2023-09-13 10:34   ` [PATCH v2 03/11] eal: remove attributes from control thread creation Thomas Monjalon
2023-09-13 10:34   ` [PATCH v2 04/11] eal: promote thread API as stable Thomas Monjalon
2023-09-13 10:34   ` [PATCH v2 05/11] eal: force prefix for internal threads Thomas Monjalon
2023-09-13 10:34   ` [PATCH v2 06/11] lib: convert to internal control threads Thomas Monjalon
2023-09-13 10:34   ` [PATCH v2 07/11] drivers: " Thomas Monjalon
2023-09-13 10:34   ` [PATCH v2 08/11] examples: convert to normal " Thomas Monjalon
2023-09-13 10:34   ` [PATCH v2 09/11] test: convert threads creation Thomas Monjalon
2023-09-13 10:34   ` [PATCH v2 10/11] eal: remove deprecated thread functions Thomas Monjalon
2023-09-13 10:34   ` [PATCH v2 11/11] lib: remove pthread.h from includes Thomas Monjalon
2023-09-13 11:28 ` [PATCH v3 00/11] rework thread management Thomas Monjalon
2023-09-13 11:28   ` [PATCH v3 01/11] devtools: warn when adding some pthread calls Thomas Monjalon
2023-09-13 11:28   ` [PATCH v3 02/11] eal: rename thread name length definition Thomas Monjalon
2023-09-13 11:28   ` [PATCH v3 03/11] eal: remove attributes from control thread creation Thomas Monjalon
2023-09-13 11:28   ` [PATCH v3 04/11] eal: promote thread API as stable Thomas Monjalon
2023-09-13 11:28   ` [PATCH v3 05/11] eal: force prefix for internal threads Thomas Monjalon
2023-09-13 11:28   ` [PATCH v3 06/11] lib: convert to internal control threads Thomas Monjalon
2023-09-13 11:28   ` [PATCH v3 07/11] drivers: " Thomas Monjalon
2023-09-13 11:28   ` [PATCH v3 08/11] examples: convert to normal " Thomas Monjalon
2023-09-13 11:28   ` [PATCH v3 09/11] test: convert threads creation Thomas Monjalon
2023-09-13 11:28   ` [PATCH v3 10/11] eal: remove deprecated thread functions Thomas Monjalon
2023-09-13 11:28   ` [PATCH v3 11/11] lib: remove pthread.h from includes Thomas Monjalon
2023-09-17 12:26   ` [PATCH v3 00/11] rework thread management Konstantin Ananyev
2023-09-22 13:46   ` David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230906162226.1618088-9-thomas@monjalon.net \
    --to=thomas@monjalon.net \
    --cc=chenbo.xia@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=roretzla@linux.microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).