From patchwork Fri Sep 25 17:43:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Lariau X-Patchwork-Id: 78865 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 83BA6A04C0; Fri, 25 Sep 2020 19:45:50 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 43AFC1EA16; Fri, 25 Sep 2020 19:44:31 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id E2FEE1E9F5 for ; Fri, 25 Sep 2020 19:44:18 +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 CBB9A1396; Fri, 25 Sep 2020 10:44:16 -0700 (PDT) Received: from localhost.localdomain (unknown [10.57.54.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EEBCA3F718; Fri, 25 Sep 2020 10:44:15 -0700 (PDT) From: Steven Lariau To: Gage Eads , Olivier Matz Cc: dev@dpdk.org, nd@arm.com, Steven Lariau Date: Fri, 25 Sep 2020 18:43:39 +0100 Message-Id: <20200925174340.10014-6-steven.lariau@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200925174340.10014-1-steven.lariau@arm.com> References: <20200911152938.8019-1-steven.lariau@arm.com> <20200925174340.10014-1-steven.lariau@arm.com> Subject: [dpdk-dev] [PATCH v2 5/5] lib/stack: remove pop cas release ordering 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" Replace the store-release by relaxed for the CAS success at the end of pop. Release isn't needed, because there is not write to data that need to be synchronized. The only preceding write is when the length is decreased, but the length CAS loop already ensures the right synchronization. The situation to avoid is when a thread sees the old length but the new list, that doesn't have enough items for pop to success. But the CAS success on length before the pop loop ensures any core reads and updates the latest length, preventing this situation. The store-release is also used to make sure that the items are read before the head is updated, in order to prevent a core in pop to read an incorrect value because another core rewrites it with push. But this isn't needed, because items are read only when removed from the used list. Right after this, they are pushed to the free list, and the store-release in push makes sure the items are read before they are visible in the free list. Signed-off-by: Steven Lariau Reviewed-by: Dharmik Thakkar Reviewed-by: Ruifeng Wang Acked-by: Gage Eads --- lib/librte_stack/rte_stack_lf_c11.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/librte_stack/rte_stack_lf_c11.h b/lib/librte_stack/rte_stack_lf_c11.h index adb9f590d..8403196d5 100644 --- a/lib/librte_stack/rte_stack_lf_c11.h +++ b/lib/librte_stack/rte_stack_lf_c11.h @@ -141,11 +141,25 @@ __rte_stack_lf_pop_elems(struct rte_stack_lf_list *list, new_head.top = tmp; new_head.cnt = old_head.cnt + 1; + /* + * The CAS should have release semantics to ensure that + * items are read before the head is updated. + * But this function is internal, and items are read + * only when __rte_stack_lf_pop calls this function to + * pop items from used list. + * Then, those items are pushed to the free list. + * Push uses a CAS store-release on head, which makes + * sure that items are read before they are pushed to + * the free list, without need for a CAS release here. + * This CAS could also be used to ensure that the new + * length is visible before the head update, but + * acquire semantics on the length update is enough. + */ success = rte_atomic128_cmp_exchange( (rte_int128_t *)&list->head, (rte_int128_t *)&old_head, (rte_int128_t *)&new_head, - 0, __ATOMIC_RELEASE, + 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED); } while (success == 0);