From patchwork Thu Sep 9 23:13:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 508377 Delivered-To: patch@linaro.org Received: by 2002:a02:8629:0:0:0:0:0 with SMTP id e38csp767919jai; Thu, 9 Sep 2021 16:14:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsJoRxbB6twkuiO3eW4KHG558JU+oOWlj0mOfW8wmjAF9/wG1eUqXdgfDfZxGlCEFMveYL X-Received: by 2002:a5d:6392:: with SMTP id p18mr6489335wru.10.1631229247940; Thu, 09 Sep 2021 16:14:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631229247; cv=none; d=google.com; s=arc-20160816; b=sJeWfwt6tPKbJgQAtJVj44qmHv3OIMCoIpfm0cR8SIRmykGdyXpndapXm82oNnaEUV a01094HPzmMoNvKN4kNt01Oz75SEMh96r8cbgVWzNZoEuhH06KJqEM6kDLBEaHN2wrpD YF+U3du950iUzO8ZvoCp0LqyjLhqeFVctoLc7G6ksxmcTVW3t5pe/toqiWFxXp/2Qnki 0QGvXEpnDufg+DHp4+4YYpdvGW1pV6sxbkrXh92WPrC7uWg45t5lleTp3TAInRBbgbBU N6jTffMvCyvkGUBMPnQ/Ih3lnH7pILUeMUYDmvfi3C4ycQQuXAFbAyKs2k4Rk8+WV2Wb /c4A== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:cc:to:from; bh=U2BFRS+OcxDhkbyG2amam6svg3HTnbLIv0EE6F1f+SM=; b=pj+c2yD5BQqfEJdXdIhdhYBmdIfWRjOp0Waz+/Dks9MD7szeaIJsussVnQVnKz3brB xBUOaVsCMuadCqEBs1LbCHqAfF0HWcSr0k2my6yYRd+CU8cJ6J44wcmfDC3qxLUG8BJQ gEmEgi+YFA8EqhOjuYyLfkFbO//jM/t4Dl+SMWDPU/76WqsLw429WeTO0ZqNe1nCqUwz lcN4T+uSM2y7NjmAOm/sFcz/7DSaHM6o8v/Bbee2HjtRI3jx+ZPq6gbhdGXZhelmNwQW PoOunWD/3ZiILhVPQ/EsPP0dGONCdgVnJjlg4V9Y09wUqj7egLZpjXrQWAbCTkkAYyHO rPHw== 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 y6si3081948wrp.91.2021.09.09.16.14.07; Thu, 09 Sep 2021 16:14:07 -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 F16734114F; Fri, 10 Sep 2021 01:13:48 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id AF3A541103 for ; Fri, 10 Sep 2021 01:13:42 +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 23C211063; Thu, 9 Sep 2021 16:13:42 -0700 (PDT) Received: from 2p2660v4-1.austin.arm.com (2p2660v4-1.austin.arm.com [10.118.13.211]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1C7583F766; Thu, 9 Sep 2021 16:13:42 -0700 (PDT) From: Honnappa Nagarahalli To: dev@dpdk.org, honnappa.nagarahalli@arm.com, konstantin.ananyev@intel.com, david.marchand@redhat.com, feifei.wang2@arm.com Cc: ruifeng.wang@arm.com, nd@arm.com, Feifei Wang Date: Thu, 9 Sep 2021 18:13:11 -0500 Message-Id: <20210909231312.2572006-6-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210909231312.2572006-1-honnappa.nagarahalli@arm.com> References: <20210224212018.17576-1-honnappa.nagarahalli@arm.com> <20210909231312.2572006-1-honnappa.nagarahalli@arm.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 5/6] eal: ensure memory operations are visible to main 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" Ensure that the memory operations in worker thread, that happen before it returns the status of the assigned function, are visible to the main thread. Signed-off-by: Honnappa Nagarahalli Reviewed-by: Feifei Wang --- lib/eal/common/eal_common_launch.c | 2 -- lib/eal/freebsd/eal_thread.c | 22 ++++++++++++++++++---- lib/eal/linux/eal_thread.c | 23 ++++++++++++++++++----- lib/eal/windows/eal_thread.c | 21 +++++++++++++++++---- 4 files changed, 53 insertions(+), 15 deletions(-) -- 2.25.1 diff --git a/lib/eal/common/eal_common_launch.c b/lib/eal/common/eal_common_launch.c index 4bc842417a..e95dadffb3 100644 --- a/lib/eal/common/eal_common_launch.c +++ b/lib/eal/common/eal_common_launch.c @@ -27,8 +27,6 @@ rte_eal_wait_lcore(unsigned worker_id) __ATOMIC_ACQUIRE) != WAIT) rte_pause(); - rte_rmb(); - return lcore_config[worker_id].ret; } diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c index e5e3edf79b..3b18030d73 100644 --- a/lib/eal/freebsd/eal_thread.c +++ b/lib/eal/freebsd/eal_thread.c @@ -39,7 +39,11 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned worker_id) int w2m = lcore_config[worker_id].pipe_worker2main[0]; int rc = -EBUSY; - if (lcore_config[worker_id].state != WAIT) + /* Check if the worker is in 'WAIT' state. Use acquire order + * since 'state' variable is used as the guard variable. + */ + if (__atomic_load_n(&lcore_config[worker_id].state, + __ATOMIC_ACQUIRE) != WAIT) goto finish; lcore_config[worker_id].arg = arg; @@ -115,7 +119,11 @@ eal_thread_loop(__rte_unused void *arg) if (n <= 0) rte_panic("cannot read on configuration pipe\n"); - lcore_config[lcore_id].state = RUNNING; + /* Set the state to 'RUNNING'. Use release order + * since 'state' variable is used as the guard variable. + */ + __atomic_store_n(&lcore_config[lcore_id].state, RUNNING, + __ATOMIC_RELEASE); /* send ack */ n = 0; @@ -139,8 +147,14 @@ eal_thread_loop(__rte_unused void *arg) lcore_config[lcore_id].ret = ret; lcore_config[lcore_id].f = NULL; lcore_config[lcore_id].arg = NULL; - rte_wmb(); - lcore_config[lcore_id].state = WAIT; + + /* Store the state with release order to ensure that + * the memory operations from the worker thread + * are completed before the state is updated. + * Use 'state' as the guard variable. + */ + __atomic_store_n(&lcore_config[lcore_id].state, WAIT, + __ATOMIC_RELEASE); } /* never reached */ diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c index c79e09c9ad..c7f0f9b2f7 100644 --- a/lib/eal/linux/eal_thread.c +++ b/lib/eal/linux/eal_thread.c @@ -39,13 +39,17 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned int worker_id) int w2m = lcore_config[worker_id].pipe_worker2main[0]; int rc = -EBUSY; - if (lcore_config[worker_id].state != WAIT) + /* Check if the worker is in 'WAIT' state. Use acquire order + * since 'state' variable is used as the guard variable. + */ + if (__atomic_load_n(&lcore_config[worker_id].state, + __ATOMIC_ACQUIRE) != WAIT) goto finish; lcore_config[worker_id].arg = arg; /* Ensure that all the memory operations are completed * before the worker thread starts running the function. - * Use worker thread function as the guard variable. + * Use worker thread function pointer as the guard variable. */ __atomic_store_n(&lcore_config[worker_id].f, f, __ATOMIC_RELEASE); @@ -115,7 +119,11 @@ eal_thread_loop(__rte_unused void *arg) if (n <= 0) rte_panic("cannot read on configuration pipe\n"); - lcore_config[lcore_id].state = RUNNING; + /* Set the state to 'RUNNING'. Use release order + * since 'state' variable is used as the guard variable. + */ + __atomic_store_n(&lcore_config[lcore_id].state, RUNNING, + __ATOMIC_RELEASE); /* send ack */ n = 0; @@ -139,9 +147,14 @@ eal_thread_loop(__rte_unused void *arg) lcore_config[lcore_id].ret = ret; lcore_config[lcore_id].f = NULL; lcore_config[lcore_id].arg = NULL; - rte_wmb(); - lcore_config[lcore_id].state = WAIT; + /* Store the state with release order to ensure that + * the memory operations from the worker thread + * are completed before the state is updated. + * Use 'state' as the guard variable. + */ + __atomic_store_n(&lcore_config[lcore_id].state, WAIT, + __ATOMIC_RELEASE); } /* never reached */ diff --git a/lib/eal/windows/eal_thread.c b/lib/eal/windows/eal_thread.c index 977911905e..54fa93fa62 100644 --- a/lib/eal/windows/eal_thread.c +++ b/lib/eal/windows/eal_thread.c @@ -29,7 +29,11 @@ rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned int worker_id) int m2w = lcore_config[worker_id].pipe_main2worker[1]; int w2m = lcore_config[worker_id].pipe_worker2main[0]; - if (lcore_config[worker_id].state != WAIT) + /* Check if the worker is in 'WAIT' state. Use acquire order + * since 'state' variable is used as the guard variable. + */ + if (__atomic_load_n(&lcore_config[worker_id].state, + __ATOMIC_ACQUIRE) != WAIT) return -EBUSY; lcore_config[worker_id].arg = arg; @@ -99,7 +103,11 @@ eal_thread_loop(void *arg __rte_unused) if (n <= 0) rte_panic("cannot read on configuration pipe\n"); - lcore_config[lcore_id].state = RUNNING; + /* Set the state to 'RUNNING'. Use release order + * since 'state' variable is used as the guard variable. + */ + __atomic_store_n(&lcore_config[lcore_id].state, RUNNING, + __ATOMIC_RELEASE); /* send ack */ n = 0; @@ -123,9 +131,14 @@ eal_thread_loop(void *arg __rte_unused) lcore_config[lcore_id].ret = ret; lcore_config[lcore_id].f = NULL; lcore_config[lcore_id].arg = NULL; - rte_wmb(); - lcore_config[lcore_id].state = WAIT; + /* Store the state with release order to ensure that + * the memory operations from the worker thread + * are completed before the state is updated. + * Use 'state' as the guard variable. + */ + __atomic_store_n(&lcore_config[lcore_id].state, WAIT, + __ATOMIC_RELEASE); } }