From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3092442529; Wed, 6 Sep 2023 18:23:35 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DE882402CF; Wed, 6 Sep 2023 18:23:32 +0200 (CEST) Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by mails.dpdk.org (Postfix) with ESMTP id CB595402CF for ; Wed, 6 Sep 2023 18:23:31 +0200 (CEST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id ABE3A3200961; Wed, 6 Sep 2023 12:23:29 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 06 Sep 2023 12:23:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1694017409; x= 1694103809; bh=igwCenGrRZHCYI88j+lV8THyohyOAN1qiFsN5MB8Jrw=; b=b gVKEIk+lkEznGI/WPKvoHBo2z+O5JLqtRtPKG42jojruck3efrVIpfOqfl4NW8gM JBkGpoICe2raRkOxXqf2VoAynCGQLiVERxdVnZlG92SFVg0cXzmwWbb2mkmVnY+d 1+HAumX8e9aYmCncNiKr4r4/tji4zu/xvAhkxeBh8llQ2xIRSCyzHTn5gEB7Fgkp hH2uH+6EWrXkwd1W8UrPKYj57BNGvd3uHykzAQoXm7biMg15yx/Yas+w8yQSEXaB 3NB6dp/WOLs+8EuFiEodpbwG9k33mgpFaLB0j1lpua0VVgX+e01JkfScNN9v6Mh1 tRchmc3ucOBSfHmcMAonA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1694017409; x= 1694103809; bh=igwCenGrRZHCYI88j+lV8THyohyOAN1qiFsN5MB8Jrw=; b=m 9+PxmCnRiaLqd2bWeA8XYdYVVcr6hdPxh33DZOawEBvUe+jIaKgisHfZz9Gb7y4Y Zc632X06JE+OimeqNkkQxB4ah0icUNL7Y04d8giHeVg4+5M4P0gAeLxgxRwM281b 4iuDXKQm3B/UcFdFrrOc9hbgUxs0ijM4c8nCoZD0CuB1tplRkGCGA2/osoRUA/7y Nt9390HRceFnpmHs1ELVAJAM8+hrn0Z4hcTwtfUXFWjhhrqWNtNzBMwHs/W40bAK eHZkutkP2B7ldexvlbc6PIbOoSy9+9MTYJCBJVBb04il//eY+p4fdADOJr1rVx80 RsGIaOOp/Lw2Iehw1p7Kg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudehfedgleelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhm rghsucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenuc ggtffrrghtthgvrhhnpedvjefhudeghedvtdeijeeigeetuedugfejueekieeltdfhteev keehhfeilefhtdenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfh hrohhmpehthhhomhgrshesmhhonhhjrghlohhnrdhnvght X-ME-Proxy: Feedback-ID: i47234305:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 6 Sep 2023 12:23:26 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: Tyler Retzlaff , David Marchand , Ferruh Yigit , Anatoly Burakov , Harman Kalra , Bruce Richardson , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam , Naga Harish K S V , Jerin Jacob , Maxime Coquelin , Chenbo Xia Subject: [PATCH 06/11] lib: convert to internal control threads Date: Wed, 6 Sep 2023 18:12:23 +0200 Message-ID: <20230906162226.1618088-7-thomas@monjalon.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230906162226.1618088-1-thomas@monjalon.net> References: <20230906162226.1618088-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Calls to rte_ctrl_thread_create() are replaced with rte_thread_create_internal_control(). Other pthread-related functions are replaced with the rte_thread API. Only pthread_cancel() has no replacement. Signed-off-by: Thomas Monjalon --- lib/eal/common/eal_common_proc.c | 15 ++++++++------- lib/eal/freebsd/eal_interrupts.c | 10 +++++----- lib/eal/linux/eal_interrupts.c | 10 +++++----- lib/eal/linux/eal_timer.c | 11 ++++++----- lib/eal/unix/rte_thread.c | 2 +- lib/eal/windows/eal_interrupts.c | 2 +- lib/eventdev/rte_event_eth_rx_adapter.c | 23 ++++++++++++----------- lib/vhost/fd_man.c | 6 +++--- lib/vhost/fd_man.h | 2 +- lib/vhost/socket.c | 23 +++++++++++------------ lib/vhost/vduse.c | 5 +++-- 11 files changed, 56 insertions(+), 53 deletions(-) diff --git a/lib/eal/common/eal_common_proc.c b/lib/eal/common/eal_common_proc.c index 26e6b78f8f..f20a348ede 100644 --- a/lib/eal/common/eal_common_proc.c +++ b/lib/eal/common/eal_common_proc.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "eal_memcfg.h" #include "eal_private.h" @@ -33,7 +34,7 @@ #include "eal_internal_cfg.h" static int mp_fd = -1; -static pthread_t mp_handle_tid; +static rte_thread_t mp_handle_tid; static char mp_filter[PATH_MAX]; /* Filter for secondary process sockets */ static char mp_dir_path[PATH_MAX]; /* The directory path for all mp sockets */ static pthread_mutex_t mp_mutex_action = PTHREAD_MUTEX_INITIALIZER; @@ -396,7 +397,7 @@ process_msg(struct mp_msg_internal *m, struct sockaddr_un *s) } } -static void * +static uint32_t mp_handle(void *arg __rte_unused) { struct mp_msg_internal msg; @@ -413,7 +414,7 @@ mp_handle(void *arg __rte_unused) process_msg(&msg, &sa); } - return NULL; + return 0; } static int @@ -646,8 +647,8 @@ rte_mp_channel_init(void) return -1; } - if (rte_ctrl_thread_create(&mp_handle_tid, "dpdk-mp-msg", - NULL, mp_handle, NULL) < 0) { + if (rte_thread_create_internal_control(&mp_handle_tid, "mp-msg", + mp_handle, NULL) < 0) { RTE_LOG(ERR, EAL, "failed to create mp thread: %s\n", strerror(errno)); close(dir_fd); @@ -671,8 +672,8 @@ rte_mp_channel_cleanup(void) if (fd < 0) return; - pthread_cancel(mp_handle_tid); - pthread_join(mp_handle_tid, NULL); + pthread_cancel((pthread_t)mp_handle_tid.opaque_id); + rte_thread_join(mp_handle_tid, NULL); close_socket_fd(fd); } diff --git a/lib/eal/freebsd/eal_interrupts.c b/lib/eal/freebsd/eal_interrupts.c index 68cdb9deb3..2b31dfb099 100644 --- a/lib/eal/freebsd/eal_interrupts.c +++ b/lib/eal/freebsd/eal_interrupts.c @@ -52,7 +52,7 @@ static rte_spinlock_t intr_lock = RTE_SPINLOCK_INITIALIZER; static struct rte_intr_source_list intr_sources; /* interrupt handling thread */ -static pthread_t intr_thread; +static rte_thread_t intr_thread; static volatile int kq = -1; @@ -591,7 +591,7 @@ eal_intr_process_interrupts(struct kevent *events, int nfds) } } -static void * +static uint32_t eal_intr_thread_main(void *arg __rte_unused) { struct kevent events[MAX_INTR_EVENTS]; @@ -619,7 +619,7 @@ eal_intr_thread_main(void *arg __rte_unused) } close(kq); kq = -1; - return NULL; + return 0; } int @@ -637,7 +637,7 @@ rte_eal_intr_init(void) } /* create the host thread to wait/handle the interrupt */ - ret = rte_ctrl_thread_create(&intr_thread, "dpdk-intr", NULL, + ret = rte_thread_create_internal_control(&intr_thread, "intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; @@ -746,5 +746,5 @@ rte_intr_free_epoll_fd(struct rte_intr_handle *intr_handle) int rte_thread_is_intr(void) { - return pthread_equal(intr_thread, pthread_self()); + return rte_thread_equal(intr_thread, rte_thread_self()); } diff --git a/lib/eal/linux/eal_interrupts.c b/lib/eal/linux/eal_interrupts.c index 19b36787b8..24fff3d3c2 100644 --- a/lib/eal/linux/eal_interrupts.c +++ b/lib/eal/linux/eal_interrupts.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -19,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -89,7 +89,7 @@ static union intr_pipefds intr_pipe; static struct rte_intr_source_list intr_sources; /* interrupt handling thread */ -static pthread_t intr_thread; +static rte_thread_t intr_thread; /* VFIO interrupts */ #ifdef VFIO_PRESENT @@ -1103,7 +1103,7 @@ eal_intr_handle_interrupts(int pfd, unsigned totalfds) * @return * never return; */ -static __rte_noreturn void * +static __rte_noreturn uint32_t eal_intr_thread_main(__rte_unused void *arg) { /* host thread, never break out */ @@ -1188,7 +1188,7 @@ rte_eal_intr_init(void) } /* create the host thread to wait/handle the interrupt */ - ret = rte_ctrl_thread_create(&intr_thread, "dpdk-intr", NULL, + ret = rte_thread_create_internal_control(&intr_thread, "intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; @@ -1601,5 +1601,5 @@ rte_intr_cap_multiple(struct rte_intr_handle *intr_handle) int rte_thread_is_intr(void) { - return pthread_equal(intr_thread, pthread_self()); + return rte_thread_equal(intr_thread, rte_thread_self()); } diff --git a/lib/eal/linux/eal_timer.c b/lib/eal/linux/eal_timer.c index 1898709700..3a30284e3a 100644 --- a/lib/eal/linux/eal_timer.c +++ b/lib/eal/linux/eal_timer.c @@ -14,6 +14,7 @@ #include #include +#include #include "eal_private.h" @@ -71,14 +72,14 @@ static uint64_t eal_hpet_resolution_hz = 0; /* Incremented 4 times during one 32bits hpet full count */ static uint32_t eal_hpet_msb; -static pthread_t msb_inc_thread_id; +static rte_thread_t msb_inc_thread_id; /* * This function runs on a specific thread to update a global variable * containing used to process MSB of the HPET (unfortunately, we need * this because hpet is 32 bits by default under linux). */ -static void * +static uint32_t hpet_msb_inc(__rte_unused void *arg) { uint32_t t; @@ -89,7 +90,7 @@ hpet_msb_inc(__rte_unused void *arg) eal_hpet_msb ++; sleep(10); } - return NULL; + return 0; } uint64_t @@ -176,8 +177,8 @@ rte_eal_hpet_init(int make_default) /* create a thread that will increment a global variable for * msb (hpet is 32 bits by default under linux) */ - ret = rte_ctrl_thread_create(&msb_inc_thread_id, "dpdk-hpet-msb", NULL, - hpet_msb_inc, NULL); + ret = rte_thread_create_internal_control(&msb_inc_thread_id, "hpet-msb", + hpet_msb_inc, NULL); if (ret != 0) { RTE_LOG(ERR, EAL, "ERROR: Cannot create HPET timer thread!\n"); internal_conf->no_hpet = 1; diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c index f4076122a4..36a21ab2f9 100644 --- a/lib/eal/unix/rte_thread.c +++ b/lib/eal/unix/rte_thread.c @@ -190,7 +190,7 @@ rte_thread_create(rte_thread_t *thread_id, pthread_mutex_unlock(&ctx.wrapper_mutex); if (ret != 0) - pthread_join((pthread_t)thread_id->opaque_id, NULL); + rte_thread_join(*thread_id, NULL); cleanup: if (attrp != NULL) diff --git a/lib/eal/windows/eal_interrupts.c b/lib/eal/windows/eal_interrupts.c index 66a49c844a..49efdc098c 100644 --- a/lib/eal/windows/eal_interrupts.c +++ b/lib/eal/windows/eal_interrupts.c @@ -98,7 +98,7 @@ rte_eal_intr_init(void) return -1; } - ret = rte_thread_create_control(&intr_thread, "dpdk-intr", + ret = rte_thread_create_internal_control(&intr_thread, "intr", eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c index 3ebfa5366d..c166ef69a8 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -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 from interrupt ring and enqueue received @@ -1595,7 +1596,7 @@ static int rxa_create_intr_thread(struct event_eth_rx_adapter *rx_adapter) { int err; - char thread_name[RTE_MAX_THREAD_NAME_LEN]; + char thread_name[RTE_THREAD_INTERNAL_NAME_SIZE]; if (rx_adapter->intr_ring) return 0; @@ -1618,11 +1619,11 @@ rxa_create_intr_thread(struct event_eth_rx_adapter *rx_adapter) rte_spinlock_init(&rx_adapter->intr_ring_lock); - snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, - "dpdk-evt-rx%d", rx_adapter->id); + snprintf(thread_name, sizeof(thread_name), + "evt-rx%d", rx_adapter->id); - err = rte_ctrl_thread_create(&rx_adapter->rx_intr_thread, thread_name, - NULL, rxa_intr_thread, rx_adapter); + err = rte_thread_create_internal_control(&rx_adapter->rx_intr_thread, + thread_name, rxa_intr_thread, rx_adapter); if (!err) return 0; @@ -1640,12 +1641,12 @@ rxa_destroy_intr_thread(struct event_eth_rx_adapter *rx_adapter) { int err; - err = pthread_cancel(rx_adapter->rx_intr_thread); + err = pthread_cancel((pthread_t)rx_adapter->rx_intr_thread.opaque_id); if (err) RTE_EDEV_LOG_ERR("Can't cancel interrupt thread err = %d\n", err); - err = pthread_join(rx_adapter->rx_intr_thread, NULL); + err = rte_thread_join(rx_adapter->rx_intr_thread, NULL); if (err) RTE_EDEV_LOG_ERR("Can't join interrupt thread err = %d\n", err); diff --git a/lib/vhost/fd_man.c b/lib/vhost/fd_man.c index 1876fada33..134414fb4b 100644 --- a/lib/vhost/fd_man.c +++ b/lib/vhost/fd_man.c @@ -212,7 +212,7 @@ fdset_try_del(struct fdset *pfdset, int fd) * will wait until the flag is reset to zero(which indicates the callback is * finished), then it could free the context after fdset_del. */ -void * +uint32_t fdset_event_dispatch(void *arg) { int i; @@ -227,7 +227,7 @@ fdset_event_dispatch(void *arg) int val; if (pfdset == NULL) - return NULL; + return 0; while (1) { @@ -303,7 +303,7 @@ fdset_event_dispatch(void *arg) fdset_shrink(pfdset); } - return NULL; + return 0; } static void diff --git a/lib/vhost/fd_man.h b/lib/vhost/fd_man.h index 6f4499bdfa..6315904c8e 100644 --- a/lib/vhost/fd_man.h +++ b/lib/vhost/fd_man.h @@ -46,7 +46,7 @@ int fdset_add(struct fdset *pfdset, int fd, void *fdset_del(struct fdset *pfdset, int fd); int fdset_try_del(struct fdset *pfdset, int fd); -void *fdset_event_dispatch(void *arg); +uint32_t fdset_event_dispatch(void *arg); int fdset_pipe_init(struct fdset *fdset); diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c index 12095b0e1a..5882e44176 100644 --- a/lib/vhost/socket.c +++ b/lib/vhost/socket.c @@ -13,8 +13,8 @@ #include #include #include -#include +#include #include #include "fd_man.h" @@ -431,7 +431,7 @@ struct vhost_user_reconnect_list { }; static struct vhost_user_reconnect_list reconn_list; -static pthread_t reconn_tid; +static rte_thread_t reconn_tid; static int vhost_user_connect_nonblock(char *path, int fd, struct sockaddr *un, size_t sz) @@ -455,7 +455,7 @@ vhost_user_connect_nonblock(char *path, int fd, struct sockaddr *un, size_t sz) return 0; } -static void * +static uint32_t vhost_user_client_reconnect(void *arg __rte_unused) { int ret; @@ -496,7 +496,7 @@ vhost_user_client_reconnect(void *arg __rte_unused) sleep(1); } - return NULL; + return 0; } static int @@ -511,8 +511,8 @@ vhost_user_reconnect_init(void) } TAILQ_INIT(&reconn_list.head); - ret = rte_ctrl_thread_create(&reconn_tid, "dpdk-vhost-reco", NULL, - vhost_user_client_reconnect, NULL); + ret = rte_thread_create_internal_control(&reconn_tid, "vhost-reco", + vhost_user_client_reconnect, NULL); if (ret != 0) { VHOST_LOG_CONFIG("thread", ERR, "failed to create reconnect thread\n"); if (pthread_mutex_destroy(&reconn_list.mutex)) @@ -1004,7 +1004,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags) if (!vsocket->is_vduse) { if ((flags & RTE_VHOST_USER_CLIENT) != 0) { vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT); - if (vsocket->reconnect && reconn_tid == 0) { + if (vsocket->reconnect && reconn_tid.opaque_id == 0) { if (vhost_user_reconnect_init() != 0) goto out_mutex; } @@ -1174,7 +1174,7 @@ int rte_vhost_driver_start(const char *path) { struct vhost_user_socket *vsocket; - static pthread_t fdset_tid; + static rte_thread_t fdset_tid; pthread_mutex_lock(&vhost_user.mutex); vsocket = find_vhost_user_socket(path); @@ -1186,7 +1186,7 @@ rte_vhost_driver_start(const char *path) if (vsocket->is_vduse) return vduse_device_create(path, vsocket->net_compliant_ol_flags); - if (fdset_tid == 0) { + if (fdset_tid.opaque_id == 0) { /** * create a pipe which will be waited by poll and notified to * rebuild the wait list of poll. @@ -1196,9 +1196,8 @@ rte_vhost_driver_start(const char *path) return -1; } - int ret = rte_ctrl_thread_create(&fdset_tid, - "dpdk-vhost-evt", NULL, fdset_event_dispatch, - &vhost_user.fdset); + int ret = rte_thread_create_internal_control(&fdset_tid, + "vhost-evt", fdset_event_dispatch, &vhost_user.fdset); if (ret != 0) { VHOST_LOG_CONFIG(path, ERR, "failed to create fdset handling thread\n"); fdset_pipe_uninit(&vhost_user.fdset); diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index 7770259f37..e342f53b81 100644 --- a/lib/vhost/vduse.c +++ b/lib/vhost/vduse.c @@ -16,6 +16,7 @@ #include #include +#include #include "fd_man.h" #include "iotlb.h" @@ -415,7 +416,7 @@ int vduse_device_create(const char *path, bool compliant_ol_flags) { int control_fd, dev_fd, vid, ret; - pthread_t fdset_tid; + rte_thread_t fdset_tid; uint32_t i, max_queue_pairs, total_queues; struct virtio_net *dev; struct virtio_net_config vnet_config = {{ 0 }}; @@ -435,7 +436,7 @@ vduse_device_create(const char *path, bool compliant_ol_flags) return -1; } - ret = rte_ctrl_thread_create(&fdset_tid, "dpdk-vduse-evt", NULL, + ret = rte_thread_create_internal_control(&fdset_tid, "vduse-evt", fdset_event_dispatch, &vduse.fdset); if (ret != 0) { VHOST_LOG_CONFIG(path, ERR, "failed to create vduse fdset handling thread\n"); -- 2.42.0