From patchwork Fri Jul 30 21:37:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 489342 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:1185:0:0:0:0 with SMTP id f5csp3532870jas; Fri, 30 Jul 2021 14:37:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzu5OgCbNMbtBtUqcVJ0EGkfOso9XF8sv4L+EapqP2lZx4XYg39l8rmJ/kIBzFsq2IIZmoR X-Received: by 2002:a17:906:2813:: with SMTP id r19mr4711331ejc.150.1627681055177; Fri, 30 Jul 2021 14:37:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627681055; cv=none; d=google.com; s=arc-20160816; b=ac6nUQzZ8Sx7sXMt9NW8l2LJqxxeJE1ukfiP/KOdpYzyAKGb2d4g7+LpDcm4DvWrT4 AI3f2Krb/KvjTb/Tj1aq/4WwoZAUx1wJT5PsssewVIMWkz5xuoB9tPOP9NlAyApftfbK 6BJS4rvNyd9sBkgiX+Bkdao/75Zwx6ClGLRbF8x24BIzxguPbeHgqiSwOgRFHGP5rTDJ DhThd04v5xxHD+sIGRrE9DPiCCkusqukAuq6fX9WBDBeq2Nn0m/P83Uf2qlyxGI0g6kJ 8SmKKWGb1ZD2qDazfAUtBf9HbCPC9Wmm9XQHfT+2JtvQ+rzEuF09HHkg0GnnKMpTLsOJ 7GnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:message-id:date:cc:to :from; bh=hW3WJMN0LRle+0+kQ8Cpkdjs64+LJ9bBgnbLB/Ol6hs=; b=vH52+q9NtiQYc92lIiMWBU8HTbIleeIIfOfJ6F9UYf52OzEeriMsQf/Onsv9y88Tg+ L+3POe4EuJn8jEhjqF5IHgMr84C+lrc8PLLT2OXaSa8ZJ0H59Z3IblZ0M6ilk/gxzs1U 0RH8/AMU4cWmlTZSBh0OdLMsok0Inx3t5ns80KKKryLYu5BXHEURskI+Ahvfmn+Yxqyi lYk7ykaxIhnP+bs5/cvoB7rw1UxycKVX8SyWl+1dqo486qIKzzN5vGRbmkMh+QYAqqpA z14NwronpLqSR9wHmN3xdwg7W2STpqhTYTPEJcSG4oByo1BAJC9rBkLkxdNIfFKCRFcl 8Y9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from mails.dpdk.org (mails.dpdk.org. [217.70.189.124]) by mx.google.com with ESMTP id z5si2193159edb.235.2021.07.30.14.37.34; Fri, 30 Jul 2021 14:37:35 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) client-ip=217.70.189.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 217.70.189.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5E64B40040; Fri, 30 Jul 2021 23:37:34 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id 1A29E4003F for ; Fri, 30 Jul 2021 23:37:33 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6448711B3; Fri, 30 Jul 2021 14:37:32 -0700 (PDT) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.12.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4E4493F70D; Fri, 30 Jul 2021 14:37:32 -0700 (PDT) From: Honnappa Nagarahalli To: dev@dpdk.org, honnappa.nagarahalli@arm.com, olivier.matz@6wind.com, lucp.at.work@gmail.com, david.marchand@redhat.com Cc: ruifeng.wang@arm.com, nd@arm.com Date: Fri, 30 Jul 2021 16:37:09 -0500 Message-Id: <20210730213709.19400-1-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [RFC] eal: simplify the implementation of rte_ctrl_thread_create 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 Sender: "dev" The current described behaviour of rte_ctrl_thread_create is rigid which makes the implementation of the function complex. The behavior is abstracted to allow for simplified implementation. Signed-off-by: Honnappa Nagarahalli --- lib/eal/common/eal_common_thread.c | 65 +++++++++++++----------------- lib/eal/include/rte_lcore.h | 8 ++-- 2 files changed, 32 insertions(+), 41 deletions(-) -- 2.17.1 Reviewed-by: Olivier Matz Reviewed-by: Olivier Matz diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 1a52f42a2b..86cacd840c 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -169,35 +169,35 @@ __rte_thread_uninit(void) struct rte_thread_ctrl_params { void *(*start_routine)(void *); void *arg; - pthread_barrier_t configured; - unsigned int refcnt; + int ret; + /* Synchronization variable between the control thread + * and the thread calling rte_ctrl_thread_create function. + * 0 - Initialized + * 1 - Control thread is running successfully + * 2 - Control thread encountered an error. 'ret' has the + * error code. + */ + unsigned int sync; }; -static void ctrl_params_free(struct rte_thread_ctrl_params *params) -{ - if (__atomic_sub_fetch(¶ms->refcnt, 1, __ATOMIC_ACQ_REL) == 0) { - (void)pthread_barrier_destroy(¶ms->configured); - free(params); - } -} - static void *ctrl_thread_init(void *arg) { struct internal_config *internal_conf = eal_get_internal_configuration(); rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset; struct rte_thread_ctrl_params *params = arg; - void *(*start_routine)(void *); + void *(*start_routine)(void *) = params->start_routine; void *routine_arg = params->arg; __rte_thread_init(rte_lcore_id(), cpuset); - - pthread_barrier_wait(¶ms->configured); - start_routine = params->start_routine; - ctrl_params_free(params); - - if (start_routine == NULL) + params->ret = pthread_setaffinity_np(pthread_self(), + sizeof(*cpuset), cpuset); + if (params->ret != 0) { + params->sync = 2; return NULL; + } + + params->sync = 1; return start_routine(routine_arg); } @@ -207,9 +207,6 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) { - struct internal_config *internal_conf = - eal_get_internal_configuration(); - rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset; struct rte_thread_ctrl_params *params; int ret; @@ -219,15 +216,12 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, params->start_routine = start_routine; params->arg = arg; - params->refcnt = 2; - - ret = pthread_barrier_init(¶ms->configured, NULL, 2); - if (ret != 0) - goto fail_no_barrier; + params->ret = 0; + params->sync = 0; ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params); if (ret != 0) - goto fail_with_barrier; + goto thread_create_failed; if (name != NULL) { ret = rte_thread_setname(*thread, name); @@ -236,24 +230,21 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, "Cannot set name for ctrl thread\n"); } - ret = pthread_setaffinity_np(*thread, sizeof(*cpuset), cpuset); - if (ret != 0) - params->start_routine = NULL; + /* Wait for the control thread to initialize successfully */ + while (!params->sync) + rte_pause(); + ret = params->ret; - pthread_barrier_wait(¶ms->configured); - ctrl_params_free(params); + free(params); - if (ret != 0) - /* start_routine has been set to NULL above; */ - /* ctrl thread will exit immediately */ + if (params->sync != 1) + /* ctrl thread is exiting */ pthread_join(*thread, NULL); return -ret; -fail_with_barrier: - (void)pthread_barrier_destroy(¶ms->configured); +thread_create_failed: -fail_no_barrier: free(params); return -ret; diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h index 1550b75da0..f1cc5e38dc 100644 --- a/lib/eal/include/rte_lcore.h +++ b/lib/eal/include/rte_lcore.h @@ -420,10 +420,10 @@ rte_thread_unregister(void); /** * Create a control thread. * - * Wrapper to pthread_create(), pthread_setname_np() and - * pthread_setaffinity_np(). The affinity of the new thread is based - * on the CPU affinity retrieved at the time rte_eal_init() was called, - * the dataplane and service lcores are then excluded. + * Creates a control thread with the given name and attributes. The + * affinity of the new thread is based on the CPU affinity retrieved + * at the time rte_eal_init() was called, the dataplane and service + * lcores are then excluded. * * @param thread * Filled with the thread id of the new created thread.