From patchwork Fri Dec 8 10:26:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Matz X-Patchwork-Id: 32034 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D24171B161; Fri, 8 Dec 2017 11:27:30 +0100 (CET) Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id E9349199B4 for ; Fri, 8 Dec 2017 11:27:23 +0100 (CET) Received: from glumotte.dev.6wind.com (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id BD48C110164 for ; Fri, 8 Dec 2017 11:19:16 +0100 (CET) From: Olivier Matz To: dev@dpdk.org Date: Fri, 8 Dec 2017 11:26:56 +0100 Message-Id: <20171208102657.2699-4-olivier.matz@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171208102657.2699-1-olivier.matz@6wind.com> References: <20171208102657.2699-1-olivier.matz@6wind.com> Subject: [dpdk-dev] [RFC 3/4] eal: set name when creating a control thread 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" To avoid code duplication, add a parameter to rte_ctrl_thread_create() to specify the name of the thread. This requires to add a wrapper for the thread start routine in rte_thread_init(), which will first wait that the thread is configured. Signed-off-by: Olivier Matz --- lib/librte_eal/common/eal_common_thread.c | 53 +++++++++++++++++++++++++- lib/librte_eal/common/include/rte_lcore.h | 7 +++- lib/librte_eal/linuxapp/eal/eal_interrupts.c | 13 ++----- lib/librte_eal/linuxapp/eal/eal_timer.c | 12 +----- lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c | 10 +---- lib/librte_pdump/rte_pdump.c | 10 +---- lib/librte_vhost/socket.c | 7 ++-- 7 files changed, 69 insertions(+), 43 deletions(-) diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c index f1a88f85e..b4335e04e 100644 --- a/lib/librte_eal/common/eal_common_thread.c +++ b/lib/librte_eal/common/eal_common_thread.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -170,9 +171,57 @@ eal_thread_dump_affinity(char *str, unsigned size) return ret; } -int rte_ctrl_thread_create(pthread_t *thread, + +struct rte_thread_ctrl_params { + void *(*start_routine)(void *); + void *arg; + pthread_barrier_t launched; + pthread_barrier_t configured; +}; + +static void *rte_thread_init(void *arg) +{ + struct rte_thread_ctrl_params *params = arg; + void *(*start_routine)(void *) = params->start_routine; + void *routine_arg = params->arg; + + pthread_barrier_wait(¶ms->launched); + pthread_barrier_wait(¶ms->configured); + + return start_routine(routine_arg); +} + +int rte_ctrl_thread_create(pthread_t *thread, const char *name, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) { - return pthread_create(thread, attr, start_routine, arg); + struct rte_thread_ctrl_params params = { + .start_routine = start_routine, + .arg = arg, + }; + int ret; + + pthread_barrier_init(¶ms.launched, NULL, 2); + pthread_barrier_init(¶ms.configured, NULL, 2); + + ret = pthread_create(thread, attr, rte_thread_init, (void *)¶ms); + if (ret != 0) + return ret; + + pthread_barrier_wait(¶ms.launched); + + if (name != NULL) { + ret = rte_thread_setname(*thread, name); + if (ret < 0) + goto fail; + } + + pthread_barrier_wait(¶ms.configured); + + return 0; + +fail: + pthread_kill(*thread, SIGTERM); + pthread_join(*thread, NULL); + return ret; } diff --git a/lib/librte_eal/common/include/rte_lcore.h b/lib/librte_eal/common/include/rte_lcore.h index 11f481c52..f7f67868c 100644 --- a/lib/librte_eal/common/include/rte_lcore.h +++ b/lib/librte_eal/common/include/rte_lcore.h @@ -265,10 +265,12 @@ int rte_thread_setname(pthread_t id, const char *name); /** * Create a control thread. * - * Wrapper to pthread_create(). + * Wrapper to pthread_create() and pthread_setname_np(). * * @param thread * Filled with the thread id of the new created thread. + * @param name + * The name of the control thread (max 16 characters including '\0'). * @param attr * Attributes for the new thread. * @param start_routine @@ -279,7 +281,8 @@ int rte_thread_setname(pthread_t id, const char *name); * 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, +int rte_ctrl_thread_create(pthread_t *thread, const char *name, + const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); /** diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c index 8fee317e5..4b5e6da31 100644 --- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c +++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c @@ -873,7 +873,7 @@ eal_intr_thread_main(__rte_unused void *arg) int rte_eal_intr_init(void) { - int ret = 0, ret_1 = 0; + int ret = 0; char thread_name[RTE_MAX_THREAD_NAME_LEN]; /* init the global interrupt source head */ @@ -889,20 +889,13 @@ rte_eal_intr_init(void) } /* create the host thread to wait/handle the interrupt */ - ret = rte_ctrl_thread_create(&intr_thread, NULL, + snprintf(thread_name, sizeof(thread_name), "eal-intr-thread"); + ret = rte_ctrl_thread_create(&intr_thread, thread_name, NULL, eal_intr_thread_main, NULL); if (ret != 0) { rte_errno = -ret; RTE_LOG(ERR, EAL, "Failed to create thread for interrupt handling\n"); - } else { - /* Set thread_name for aid in debugging. */ - snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, - "eal-intr-thread"); - ret_1 = rte_thread_setname(intr_thread, thread_name); - if (ret_1 != 0) - RTE_LOG(DEBUG, EAL, - "Failed to set thread name for interrupt handling\n"); } return ret; diff --git a/lib/librte_eal/linuxapp/eal/eal_timer.c b/lib/librte_eal/linuxapp/eal/eal_timer.c index 1766f9353..669dc9ceb 100644 --- a/lib/librte_eal/linuxapp/eal/eal_timer.c +++ b/lib/librte_eal/linuxapp/eal/eal_timer.c @@ -207,7 +207,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, NULL, + snprintf(thread_name, sizeof(thread_name), "hpet-msb-inc"); + ret = rte_ctrl_thread_create(&msb_inc_thread_id, thread_name, NULL, (void *(*)(void *))hpet_msb_inc, NULL); if (ret != 0) { RTE_LOG(ERR, EAL, "ERROR: Cannot create HPET timer thread!\n"); @@ -215,15 +216,6 @@ rte_eal_hpet_init(int make_default) return -1; } - /* - * Set thread_name for aid in debugging. - */ - snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "hpet-msb-inc"); - ret = rte_thread_setname(msb_inc_thread_id, thread_name); - if (ret != 0) - RTE_LOG(DEBUG, EAL, - "Cannot set HPET timer thread name!\n"); - if (make_default) eal_timer_source = EAL_TIMER_HPET; return 0; 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 d104f8920..a20fb8691 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,8 @@ vfio_mp_sync_setup(void) return -1; } - ret = rte_ctrl_thread_create(&socket_thread, NULL, + snprintf(thread_name, sizeof(thread_name), "vfio-sync"); + ret = rte_ctrl_thread_create(&socket_thread, thread_name, NULL, vfio_mp_sync_thread, NULL); if (ret) { RTE_LOG(ERR, EAL, @@ -412,13 +413,6 @@ vfio_mp_sync_setup(void) return -1; } - /* Set thread_name for aid in debugging. */ - snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "vfio-sync"); - ret = rte_thread_setname(socket_thread, thread_name); - if (ret) - RTE_LOG(DEBUG, EAL, - "Failed to set thread name for secondary processes!\n"); - return 0; } diff --git a/lib/librte_pdump/rte_pdump.c b/lib/librte_pdump/rte_pdump.c index 70de0c48b..061263236 100644 --- a/lib/librte_pdump/rte_pdump.c +++ b/lib/librte_pdump/rte_pdump.c @@ -577,7 +577,8 @@ rte_pdump_init(const char *path) } /* create the host thread to wait/handle pdump requests */ - ret = rte_ctrl_thread_create(&pdump_thread, NULL, + snprintf(thread_name, sizeof(thread_name), "pdump-thread"); + ret = rte_ctrl_thread_create(&pdump_thread, thread_name, NULL, pdump_thread_main, NULL); if (ret != 0) { RTE_LOG(ERR, PDUMP, @@ -585,13 +586,6 @@ rte_pdump_init(const char *path) strerror(-ret), __func__, __LINE__); return -1; } - /* Set thread_name for aid in debugging. */ - snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "pdump-thread"); - ret = rte_thread_setname(pdump_thread, thread_name); - if (ret != 0) { - RTE_LOG(DEBUG, PDUMP, - "Failed to set thread name for pdump handling\n"); - } return 0; } diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index 905d040a4..43d699ef7 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 = rte_ctrl_thread_create(&reconn_tid, NULL, + ret = rte_ctrl_thread_create(&reconn_tid, "vhost_reconnect", NULL, vhost_user_client_reconnect, NULL); if (ret != 0) { RTE_LOG(ERR, VHOST_CONFIG, "failed to create reconnect thread"); @@ -834,8 +834,9 @@ rte_vhost_driver_start(const char *path) return -1; if (fdset_tid == 0) { - int ret = rte_ctrl_thread_create(&fdset_tid, NULL, - fdset_event_dispatch, &vhost_user.fdset); + int ret = rte_ctrl_thread_create(&fdset_tid, + "vhost_dispatch", NULL, fdset_event_dispatch, + &vhost_user.fdset); if (ret != 0) RTE_LOG(ERR, VHOST_CONFIG, "failed to create fdset handling thread");