From 4b7284a71f64f69a55692a2c2018f5c60c49b226 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Morten=20Br=C3=B8rup?= Date: Tue, 19 May 2020 15:27:25 +0000 Subject: [PATCH] ring: optimize empty test MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 9078e7c24a..f671414822 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; } /** -- 2.20.1