From patchwork Thu Sep 9 23:13:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 508374 Delivered-To: patch@linaro.org Received: by 2002:a02:8629:0:0:0:0:0 with SMTP id e38csp767730jai; Thu, 9 Sep 2021 16:13:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzW99DA9o8p4GM8+JvPmxsRvqaO+93SWGOLB63CsMNk1itWZK26YJ6aXFlJjtAMg8LyQS5J X-Received: by 2002:a05:600c:3790:: with SMTP id o16mr5397796wmr.157.1631229232489; Thu, 09 Sep 2021 16:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631229232; cv=none; d=google.com; s=arc-20160816; b=XQp26fTM2qAgcndCDRdZ9UCxx6gAH2h/N1tenmMrTBTgPZsGmHBEVG8qVrkCjGoMJI dTlp3jwljMnlgs2GGS579+1mNGa9HiRMVyMx51JpYAZHjj9HjIUIIMlEZ109zbxD1Qnz 6MNA6zZz9+rWLRB+Ju9FqCaY42yOAp9qD/O/LcYmzAB87vSB5SQozWDxz9QD52dWQSHu LB3Tw9hk3K4XWnNQMiGju+bIzm+iaVCpHG0ZyvPKB2qrAzTQnDx3GinCryTbXWxDS9Ge ZraN9w24Kr3LWIZhXF2Srv4MUYmqlatzPKg9jGHrgkuvIZGO8oFAaA/lqf4t6y7Fike4 PLQA== 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=HF9bVxswE+JWzdLpvQLHiXnF3FxJiHkrE5rOpSPZIdA=; b=QezOcjtQCNPI41C2BnoP5Gmx+sWsu878bxGp5lLaXsVAIHt/6081LGVMzUMZtRHk5H LFyQD8QqTmkxMyHbe3kLZcmGjKWw66KEYnEsFjXlG4tStXqUfO2kALiXEDNboGW1GKoR 8yrrNa2RmBe4ZhzhliQm7+giwiE6BSUca2rSMFf4YkTlz9xedaX1zrpINQMoWO8u7gET Bp95LZfkRFUkmPXB6T58Q8bzIYsI+L1zitqv75dozJIdz158VfGdGZJ1Nylkw8VV18rV 2n2PRzVkBfYd5dIXKxatoR4vgYucm0EYVKj6sCzpSgCtV95CZqzCYRBaDMvT57gvyv89 z/gQ== 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 n26si3297949wmk.27.2021.09.09.16.13.52; Thu, 09 Sep 2021 16:13:52 -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 843094112E; Fri, 10 Sep 2021 01:13:45 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id A1EFA410FE 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 13D3D31B; 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 0C1DD3F73D; 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, Ola Liljedahl , Feifei Wang Date: Thu, 9 Sep 2021 18:13:08 -0500 Message-Id: <20210909231312.2572006-3-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 2/6] eal: ensure memory operations are visible to worker 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 before the call to rte_eal_remote_launch are visible to the worker thread. Use the function pointer to execute in worker thread as the guard variable. Signed-off-by: Honnappa Nagarahalli Reviewed-by: Ola Liljedahl Reviewed-by: Feifei Wang --- lib/eal/freebsd/eal_thread.c | 19 +++++++++++++++---- lib/eal/linux/eal_thread.c | 19 +++++++++++++++---- lib/eal/windows/eal_thread.c | 19 +++++++++++++++---- 3 files changed, 45 insertions(+), 12 deletions(-) -- 2.25.1 diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c index bbc3a8e985..17b8f39966 100644 --- a/lib/eal/freebsd/eal_thread.c +++ b/lib/eal/freebsd/eal_thread.c @@ -42,8 +42,12 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned worker_id) if (lcore_config[worker_id].state != WAIT) goto finish; - lcore_config[worker_id].f = f; 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. + */ + __atomic_store_n(&lcore_config[worker_id].f, f, __ATOMIC_RELEASE); /* send message */ n = 0; @@ -100,6 +104,7 @@ eal_thread_loop(__rte_unused void *arg) /* read on our pipe to get commands */ while (1) { + lcore_function_t *f; void *fct_arg; /* wait command */ @@ -119,12 +124,18 @@ eal_thread_loop(__rte_unused void *arg) if (n < 0) rte_panic("cannot write on configuration pipe\n"); - if (lcore_config[lcore_id].f == NULL) - rte_panic("NULL function pointer\n"); + /* Load 'f' with acquire order to ensure that + * the memory operations from the main thread + * are accessed only after update to 'f' is visible. + * Wait till the update to 'f' is visible to the worker. + */ + while ((f = __atomic_load_n(&lcore_config[lcore_id].f, + __ATOMIC_ACQUIRE)) == NULL) + rte_pause(); /* call the function and store the return value */ fct_arg = lcore_config[lcore_id].arg; - ret = lcore_config[lcore_id].f(fct_arg); + ret = f(fct_arg); lcore_config[lcore_id].ret = ret; lcore_config[lcore_id].f = NULL; lcore_config[lcore_id].arg = NULL; diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c index 8f3c0dafd6..a0a0091040 100644 --- a/lib/eal/linux/eal_thread.c +++ b/lib/eal/linux/eal_thread.c @@ -42,8 +42,12 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned int worker_id) if (lcore_config[worker_id].state != WAIT) goto finish; - lcore_config[worker_id].f = f; 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. + */ + __atomic_store_n(&lcore_config[worker_id].f, f, __ATOMIC_RELEASE); /* send message */ n = 0; @@ -100,6 +104,7 @@ eal_thread_loop(__rte_unused void *arg) /* read on our pipe to get commands */ while (1) { + lcore_function_t *f; void *fct_arg; /* wait command */ @@ -119,12 +124,18 @@ eal_thread_loop(__rte_unused void *arg) if (n < 0) rte_panic("cannot write on configuration pipe\n"); - if (lcore_config[lcore_id].f == NULL) - rte_panic("NULL function pointer\n"); + /* Load 'f' with acquire order to ensure that + * the memory operations from the main thread + * are accessed only after update to 'f' is visible. + * Wait till the update to 'f' is visible to the worker. + */ + while ((f = __atomic_load_n(&lcore_config[lcore_id].f, + __ATOMIC_ACQUIRE)) == NULL) + rte_pause(); /* call the function and store the return value */ fct_arg = lcore_config[lcore_id].arg; - ret = lcore_config[lcore_id].f(fct_arg); + ret = f(fct_arg); lcore_config[lcore_id].ret = ret; lcore_config[lcore_id].f = NULL; lcore_config[lcore_id].arg = NULL; diff --git a/lib/eal/windows/eal_thread.c b/lib/eal/windows/eal_thread.c index df1df5d02c..e08abcf21f 100644 --- a/lib/eal/windows/eal_thread.c +++ b/lib/eal/windows/eal_thread.c @@ -32,8 +32,12 @@ rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned int worker_id) if (lcore_config[worker_id].state != WAIT) return -EBUSY; - lcore_config[worker_id].f = f; 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. + */ + __atomic_store_n(&lcore_config[worker_id].f, f, __ATOMIC_RELEASE); /* send message */ n = 0; @@ -84,6 +88,7 @@ eal_thread_loop(void *arg __rte_unused) /* read on our pipe to get commands */ while (1) { + lcore_function_t *f; void *fct_arg; /* wait command */ @@ -103,12 +108,18 @@ eal_thread_loop(void *arg __rte_unused) if (n < 0) rte_panic("cannot write on configuration pipe\n"); - if (lcore_config[lcore_id].f == NULL) - rte_panic("NULL function pointer\n"); + /* Load 'f' with acquire order to ensure that + * the memory operations from the main thread + * are accessed only after update to 'f' is visible. + * Wait till the update to 'f' is visible to the worker. + */ + while ((f = __atomic_load_n(&lcore_config[lcore_id].f, + __ATOMIC_ACQUIRE)) == NULL) + rte_pause(); /* call the function and store the return value */ fct_arg = lcore_config[lcore_id].arg; - ret = lcore_config[lcore_id].f(fct_arg); + ret = f(fct_arg); lcore_config[lcore_id].ret = ret; lcore_config[lcore_id].f = NULL; lcore_config[lcore_id].arg = NULL;