DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [RFC] ring: count and empty optimizations
@ 2020-04-28 13:53 Morten Brørup
  2020-04-29 13:38 ` Olivier Matz
  0 siblings, 1 reply; 6+ messages in thread
From: Morten Brørup @ 2020-04-28 13:53 UTC (permalink / raw)
  To: Olivier Matz; +Cc: dev

Olivier (maintainer of the Ring),

I would like to suggest a couple of minor optimizations to the ring library.


1. Testing if the ring is empty is as simple as comparing the producer and consumer pointers:

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;
}

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().


2. It is not possible to enqueue more elements than the capacity of a ring, so the count function does not need to test if the capacity is exceeded:

static inline unsigned
rte_ring_count(const struct rte_ring *r)
{
	uint32_t prod_tail = r->prod.tail;
	uint32_t cons_tail = r->cons.tail;
	uint32_t count = (prod_tail - cons_tail) & r->mask;
-	return (count > r->capacity) ? r->capacity : count;
+ 	return count;
}

I cannot even come up with a race condition in this function where the count would exceed the capacity. Maybe I missed something?


Med venlig hilsen / kind regards
- Morten Brørup


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-04-30 21:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-28 13:53 [dpdk-dev] [RFC] ring: count and empty optimizations Morten Brørup
2020-04-29 13:38 ` Olivier Matz
2020-04-30  1:12   ` Honnappa Nagarahalli
2020-04-30  9:19     ` Morten Brørup
2020-04-30 15:36       ` Ananyev, Konstantin
2020-04-30 21:38         ` Honnappa Nagarahalli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).