ring: optimize empty test

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 <mb@smartsharesystems.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
This commit is contained in:
Morten Brørup 2020-05-19 15:27:25 +00:00 committed by David Marchand
parent 36e3cfbbef
commit 4b7284a71f

View File

@ -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;
}
/**