From patchwork Wed Feb 24 21:20:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 386879 Delivered-To: patch@linaro.org Received: by 2002:a02:290e:0:0:0:0:0 with SMTP id p14csp697917jap; Wed, 24 Feb 2021 13:21:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4sappw+uGbOdryAW7bQb51VDS+0Ly+tCRlFd8iGZ/BB6tKMXNLSX8ehGUBe3RmWIFtfqs X-Received: by 2002:a17:906:8a5c:: with SMTP id gx28mr25516237ejc.51.1614201660161; Wed, 24 Feb 2021 13:21:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614201660; cv=none; d=google.com; s=arc-20160816; b=cwtNs4Q29Ze0dcogLu9EXSS6DFE7KoT64V5xeAxVxBQI6yt3BP8pVJm8c54QrwQJIi ZJJuSC3uv5LV9NFld2NrsZoRElk/KtcW+jjy5uJY9dZtncnBOrrON+PyyElwgOVEG5YA Ti4m7XXyc3CmXhiDlF8XG8M0OMcRAmIdInmILbeyCauEhIIjrmlFmiE/rtjBTUMMlMe+ rHl1G7up4O/zXI3BDdTsisfcvC21Chd6jm2dVhogXpIlfPGYUdSFDgMPDUNzCV28RIDb 4YcxMR5yWszu7GWzy5fBwwNR0WBNuVIkdzXq/X4vLn2EsA2drYM9Z9c8FxfuvxIb3Ro4 Hasg== 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:references:in-reply-to :message-id:date:cc:to:from; bh=01kzJnM7ENLR4aCpRWXTHLFM49N1F1jQtJaGPHAvmLY=; b=NaOT1RJk5kL1vZCQGAnLTg16MmIs2pM5XR9uC78YMZ8VzC6ZFDXY2ZQNrmYkp45dMv J0/ukkAEGbFqE/sP5Nn6MPqZa+9pgyIals4MQ4/p+oYPlE/QWKaLv3WhXrSpXgyylorl TqKjmwwr9t1Zq6p/KpOFbg7wzBqIBoyOjBq6up1s+cRE3OAhqyk/kqVZjpwAFBqd24Vg VndZTQw9pdhi0cNAH2pvRJXioaaOJ/FgNomQw72bgHAMC7YE5nmcGAqhcEB36NhvpvzT SQDS0DSKLvsPXDVP+Wu9SX4z/dmo3DQt/9VbQpd4U+ui+I0M/HWnJw2f6b45MEljioNy Z4Wg== 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 m6si2075018edp.192.2021.02.24.13.20.59; Wed, 24 Feb 2021 13:21:00 -0800 (PST) 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 C5300160778; Wed, 24 Feb 2021 22:20:50 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id 1665D160774 for ; Wed, 24 Feb 2021 22:20:49 +0100 (CET) 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 88CB8ED1; Wed, 24 Feb 2021 13:20:48 -0800 (PST) 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 7BFE33F73D; Wed, 24 Feb 2021 13:20:48 -0800 (PST) From: Honnappa Nagarahalli To: Bruce Richardson , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Cc: dev@dpdk.org, honnappa.nagarahalli@arm.com, ruifeng.wang@arm.com, feifei.wang@arm.com, nd@arm.com Date: Wed, 24 Feb 2021 15:20:17 -0600 Message-Id: <20210224212018.17576-5-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210224212018.17576-1-honnappa.nagarahalli@arm.com> References: <20210224212018.17576-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [RFC 4/5] 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 --- lib/librte_eal/common/eal_common_launch.c | 8 ++++---- lib/librte_eal/freebsd/eal_thread.c | 10 ++++++++-- lib/librte_eal/linux/eal_thread.c | 17 ++++++++++++----- lib/librte_eal/windows/eal_thread.c | 9 +++++++-- 4 files changed, 31 insertions(+), 13 deletions(-) -- 2.17.1 diff --git a/lib/librte_eal/common/eal_common_launch.c b/lib/librte_eal/common/eal_common_launch.c index 78fd94026..9cc71801a 100644 --- a/lib/librte_eal/common/eal_common_launch.c +++ b/lib/librte_eal/common/eal_common_launch.c @@ -23,14 +23,14 @@ int rte_eal_wait_lcore(unsigned worker_id) { - if (lcore_config[worker_id].state == WAIT) + if (__atomic_load_n(&lcore_config[worker_id].state, + __ATOMIC_ACQUIRE) == WAIT) return 0; - while (lcore_config[worker_id].state != WAIT) + while (__atomic_load_n(&lcore_config[worker_id].state, + __ATOMIC_ACQUIRE) != WAIT) rte_pause(); - rte_rmb(); - return lcore_config[worker_id].ret; } diff --git a/lib/librte_eal/freebsd/eal_thread.c b/lib/librte_eal/freebsd/eal_thread.c index 6d6f1e2fd..58c8502de 100644 --- a/lib/librte_eal/freebsd/eal_thread.c +++ b/lib/librte_eal/freebsd/eal_thread.c @@ -139,8 +139,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/librte_eal/linux/eal_thread.c b/lib/librte_eal/linux/eal_thread.c index 7b9463df3..eab6fa652 100644 --- a/lib/librte_eal/linux/eal_thread.c +++ b/lib/librte_eal/linux/eal_thread.c @@ -39,13 +39,14 @@ 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) + 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 +116,8 @@ eal_thread_loop(__rte_unused void *arg) if (n <= 0) rte_panic("cannot read on configuration pipe\n"); - lcore_config[lcore_id].state = RUNNING; + __atomic_store_n(&lcore_config[lcore_id].state, RUNNING, + __ATOMIC_RELEASE); /* send ack */ n = 0; @@ -139,9 +141,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/librte_eal/windows/eal_thread.c b/lib/librte_eal/windows/eal_thread.c index 35d059a30..fb1ec4b4f 100644 --- a/lib/librte_eal/windows/eal_thread.c +++ b/lib/librte_eal/windows/eal_thread.c @@ -123,9 +123,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); } }