From 339341e8e126a34381861b7347a8ad4ffb9cb293 Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Wed, 29 Nov 2017 10:57:10 +0100 Subject: [PATCH] eal: new function to create control threads Many parts of dpdk use their own management threads. Introduce a new wrapper for thread creation that will be extended in next commit 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 --- lib/librte_eal/common/eal_common_thread.c | 7 +++++++ lib/librte_eal/common/include/rte_lcore.h | 20 +++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 6 +++--- lib/librte_eal/linuxapp/eal/eal_timer.c | 2 +- .../linuxapp/eal/eal_vfio_mp_sync.c | 2 +- lib/librte_eal/rte_eal_version.map | 1 + lib/librte_pdump/rte_pdump.c | 5 +++-- lib/librte_vhost/socket.c | 6 +++--- 8 files changed, 39 insertions(+), 10 deletions(-) diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c index 55e96963b8..f1a88f85e5 100644 --- a/lib/librte_eal/common/eal_common_thread.c +++ b/lib/librte_eal/common/eal_common_thread.c @@ -169,3 +169,10 @@ exit: return ret; } + +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 c89e6bab14..11f481c525 100644 --- a/lib/librte_eal/common/include/rte_lcore.h +++ b/lib/librte_eal/common/include/rte_lcore.h @@ -262,6 +262,26 @@ 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. + */ +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 * diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c index 1c20693d9e..8fee317e55 100644 --- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c +++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c @@ -889,10 +889,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 { @@ -905,7 +905,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 a616928bed..1766f93535 100644 --- a/lib/librte_eal/linuxapp/eal/eal_timer.c +++ b/lib/librte_eal/linuxapp/eal/eal_timer.c @@ -207,7 +207,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/linuxapp/eal/eal_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c index b53ed7eb36..d104f89200 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c @@ -403,7 +403,7 @@ vfio_mp_sync_setup(void) return -1; } - ret = pthread_create(&socket_thread, NULL, + ret = rte_ctrl_thread_create(&socket_thread, NULL, vfio_mp_sync_thread, NULL); if (ret) { RTE_LOG(ERR, EAL, diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index f4f46c1be8..49b02aa082 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -203,6 +203,7 @@ DPDK_17.11 { EXPERIMENTAL { global: + rte_ctrl_thread_create; rte_eal_devargs_insert; rte_eal_devargs_parse; rte_eal_devargs_remove; diff --git a/lib/librte_pdump/rte_pdump.c b/lib/librte_pdump/rte_pdump.c index 44dcc9531f..70de0c48bf 100644 --- a/lib/librte_pdump/rte_pdump.c +++ b/lib/librte_pdump/rte_pdump.c @@ -577,11 +577,12 @@ rte_pdump_init(const char *path) } /* create the host thread to wait/handle pdump requests */ - ret = pthread_create(&pdump_thread, NULL, pdump_thread_main, NULL); + ret = rte_ctrl_thread_create(&pdump_thread, NULL, + pdump_thread_main, NULL); if (ret != 0) { RTE_LOG(ERR, PDUMP, "Failed to create the pdump thread:%s, %s:%d\n", - strerror(ret), __func__, __LINE__); + strerror(-ret), __func__, __LINE__); return -1; } /* Set thread_name for aid in debugging. */ diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index 811e6bf160..905d040a4b 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -470,7 +470,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"); @@ -834,8 +834,8 @@ rte_vhost_driver_start(const char *path) return -1; if (fdset_tid == 0) { - 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.20.1