From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id 69E6E343F for ; Tue, 24 Apr 2018 16:47:13 +0200 (CEST) Received: from glumotte.dev.6wind.com. (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id 6C980168A51; Tue, 24 Apr 2018 16:45:08 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Cc: Anatoly Burakov Date: Tue, 24 Apr 2018 16:46:48 +0200 Message-Id: <20180424144651.13145-3-olivier.matz@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180424144651.13145-1-olivier.matz@6wind.com> References: <20180403130439.11151-1-olivier.matz@6wind.com> <20180424144651.13145-1-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH v3 2/5] eal: new function to create control threads X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Apr 2018 14:47:13 -0000 Many parts of dpdk use their own management threads. Introduce a new wrapper for thread creation that will be extended in next commits to set the name and affinity. To be consistent with other DPDK APIs, the return value is negative in case of error, which was not the case for pthread_create(). Signed-off-by: Olivier Matz Reviewed-by: Anatoly Burakov --- drivers/net/kni/Makefile | 1 + drivers/net/kni/rte_eth_kni.c | 2 +- lib/librte_eal/common/eal_common_proc.c | 4 ++-- lib/librte_eal/common/eal_common_thread.c | 8 ++++++++ lib/librte_eal/common/include/rte_lcore.h | 21 +++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 6 +++--- lib/librte_eal/linuxapp/eal/eal_timer.c | 2 +- lib/librte_eal/rte_eal_version.map | 1 + lib/librte_vhost/socket.c | 6 +++--- 9 files changed, 41 insertions(+), 10 deletions(-) diff --git a/drivers/net/kni/Makefile b/drivers/net/kni/Makefile index 01eaef056..562e8d2da 100644 --- a/drivers/net/kni/Makefile +++ b/drivers/net/kni/Makefile @@ -10,6 +10,7 @@ LIB = librte_pmd_kni.a CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API LDLIBS += -lpthread LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs -lrte_kni diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c index 08fc6a35e..fdd592554 100644 --- a/drivers/net/kni/rte_eth_kni.c +++ b/drivers/net/kni/rte_eth_kni.c @@ -149,7 +149,7 @@ eth_kni_dev_start(struct rte_eth_dev *dev) } if (internals->no_request_thread == 0) { - ret = pthread_create(&internals->thread, NULL, + ret = rte_ctrl_thread_create(&internals->thread, NULL, kni_handle_request, internals); if (ret) { RTE_LOG(ERR, PMD, diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c index c450c848f..abaa085c4 100644 --- a/lib/librte_eal/common/eal_common_proc.c +++ b/lib/librte_eal/common/eal_common_proc.c @@ -662,7 +662,7 @@ rte_mp_channel_init(void) return -1; } - if (pthread_create(&mp_handle_tid, NULL, mp_handle, NULL) < 0) { + if (rte_ctrl_thread_create(&mp_handle_tid, NULL, mp_handle, NULL) < 0) { RTE_LOG(ERR, EAL, "failed to create mp thead: %s\n", strerror(errno)); close(mp_fd); @@ -671,7 +671,7 @@ rte_mp_channel_init(void) return -1; } - if (pthread_create(&async_reply_handle_tid, NULL, + if (rte_ctrl_thread_create(&async_reply_handle_tid, NULL, async_reply_handle, NULL) < 0) { RTE_LOG(ERR, EAL, "failed to create mp thead: %s\n", strerror(errno)); diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c index 40902e49b..efbccddbc 100644 --- a/lib/librte_eal/common/eal_common_thread.c +++ b/lib/librte_eal/common/eal_common_thread.c @@ -140,3 +140,11 @@ eal_thread_dump_affinity(char *str, unsigned size) return ret; } + +__rte_experimental int +rte_ctrl_thread_create(pthread_t *thread, + const pthread_attr_t *attr, + void *(*start_routine)(void *), void *arg) +{ + return pthread_create(thread, attr, start_routine, arg); +} diff --git a/lib/librte_eal/common/include/rte_lcore.h b/lib/librte_eal/common/include/rte_lcore.h index 731297574..30749d0ab 100644 --- a/lib/librte_eal/common/include/rte_lcore.h +++ b/lib/librte_eal/common/include/rte_lcore.h @@ -277,6 +277,27 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp); int rte_thread_setname(pthread_t id, const char *name); /** + * Create a control thread. + * + * Wrapper to pthread_create(). + * + * @param thread + * Filled with the thread id of the new created thread. + * @param attr + * Attributes for the new thread. + * @param start_routine + * Function to be executed by the new thread. + * @param arg + * Argument passed to start_routine. + * @return + * On success, returns 0; on error, it returns a negative value + * corresponding to the error number. + */ +__rte_experimental int +rte_ctrl_thread_create(pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine)(void *), void *arg); + +/** * Test if the core supplied has a specific role * * @param lcore_id diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c index b5bcfc59a..9a49ae6a5 100644 --- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c +++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c @@ -869,10 +869,10 @@ rte_eal_intr_init(void) } /* create the host thread to wait/handle the interrupt */ - ret = pthread_create(&intr_thread, NULL, + ret = rte_ctrl_thread_create(&intr_thread, NULL, eal_intr_thread_main, NULL); if (ret != 0) { - rte_errno = ret; + rte_errno = -ret; RTE_LOG(ERR, EAL, "Failed to create thread for interrupt handling\n"); } else { @@ -885,7 +885,7 @@ rte_eal_intr_init(void) "Failed to set thread name for interrupt handling\n"); } - return -ret; + return ret; } static void diff --git a/lib/librte_eal/linuxapp/eal/eal_timer.c b/lib/librte_eal/linuxapp/eal/eal_timer.c index 098e22a65..6f5d9fee6 100644 --- a/lib/librte_eal/linuxapp/eal/eal_timer.c +++ b/lib/librte_eal/linuxapp/eal/eal_timer.c @@ -178,7 +178,7 @@ 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 = pthread_create(&msb_inc_thread_id, NULL, + ret = rte_ctrl_thread_create(&msb_inc_thread_id, NULL, (void *(*)(void *))hpet_msb_inc, NULL); if (ret != 0) { RTE_LOG(ERR, EAL, "ERROR: Cannot create HPET timer thread!\n"); diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index d02d80b8a..bc3c02dcc 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -213,6 +213,7 @@ DPDK_18.02 { EXPERIMENTAL { global: + rte_ctrl_thread_create; rte_dev_event_callback_register; rte_dev_event_callback_unregister; rte_dev_event_monitor_start; diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index 6eec427e4..db9be6a99 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -476,7 +476,7 @@ vhost_user_reconnect_init(void) } TAILQ_INIT(&reconn_list.head); - ret = pthread_create(&reconn_tid, NULL, + ret = rte_ctrl_thread_create(&reconn_tid, NULL, vhost_user_client_reconnect, NULL); if (ret != 0) { RTE_LOG(ERR, VHOST_CONFIG, "failed to create reconnect thread"); @@ -1020,8 +1020,8 @@ rte_vhost_driver_start(const char *path) return -1; } - int ret = pthread_create(&fdset_tid, NULL, fdset_event_dispatch, - &vhost_user.fdset); + int ret = rte_ctrl_thread_create(&fdset_tid, NULL, + fdset_event_dispatch, &vhost_user.fdset); if (ret != 0) { RTE_LOG(ERR, VHOST_CONFIG, "failed to create fdset handling thread"); -- 2.11.0