From patchwork Tue May 19 15:27:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Morten_Br=C3=B8rup?= X-Patchwork-Id: 70449 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 A66C4A0093; Tue, 19 May 2020 17:27:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 60CF71D6AF; Tue, 19 May 2020 17:27:41 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by dpdk.org (Postfix) with ESMTP id 72CE41D69E for ; Tue, 19 May 2020 17:27:38 +0200 (CEST) Received: from dkrd2.smartsharesys.local ([192.168.4.12]) by smartserver.smartsharesystems.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 19 May 2020 17:27:37 +0200 From: =?utf-8?q?Morten_Br=C3=B8rup?= To: olivier.matz@6wind.com, konstantin.ananyev@intel.com, Honnappa.Nagarahalli@arm.com, nd@arm.com Cc: dev@dpdk.org, =?utf-8?q?Morten_Br=C3=B8rup?= Date: Tue, 19 May 2020 15:27:25 +0000 Message-Id: <20200519152725.63486-3-mb@smartsharesystems.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200519152725.63486-1-mb@smartsharesystems.com> References: <20200513153111.37063-1-mb@smartsharesystems.com> <20200519152725.63486-1-mb@smartsharesystems.com> MIME-Version: 1.0 X-OriginalArrivalTime: 19 May 2020 15:27:37.0800 (UTC) FILETIME=[07128C80:01D62DF2] Subject: [dpdk-dev] [PATCH 2/2] ring: empty optimization 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" Testing if the ring is empty is as simple as comparing the producer and consumer pointers. In theory, this optimization reduces the number of potential cache misses from 3 to 2 by not having to read r->mask in rte_ring_count(). The modification of this function were also discussed in the RFC here: https://mails.dpdk.org/archives/dev/2020-April/165752.html Signed-off-by: Morten Brørup Acked-by: Konstantin Ananyev --- lib/librte_ring/rte_ring.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h index 9078e7c24..f67141482 100644 --- a/lib/librte_ring/rte_ring.h +++ b/lib/librte_ring/rte_ring.h @@ -733,7 +733,9 @@ rte_ring_full(const struct rte_ring *r) static inline int rte_ring_empty(const struct rte_ring *r) { - return rte_ring_count(r) == 0; + uint32_t prod_tail = r->prod.tail; + uint32_t cons_tail = r->cons.tail; + return cons_tail == prod_tail; } /**