patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH 19.11] ring: optimize corner case for enqueue/dequeue
@ 2022-03-07 14:14 Andrzej Ostruszka
  0 siblings, 0 replies; only message in thread
From: Andrzej Ostruszka @ 2022-03-07 14:14 UTC (permalink / raw)
  To: stable
  Cc: Andrzej Ostruszka, Olivier Matz, Konstantin Ananyev, Morten Brørup

[ upstream commit 97ed4cb6fb324f4277ee754d4b6f3c7a0d96400b ]

When enqueueing/dequeueing to/from the ring we try to optimize by manual
loop unrolling.  The check for this optimization looks like:

	if (likely(idx + n < size)) {

where 'idx' points to the first usable element (empty slot for enqueue,
data for dequeue).  The correct comparison here should be '<=' instead
of '<'.

This is not a functional error since we fall back to the loop with
correct checks on indexes.  Just a minor suboptimal behaviour for the
case when we want to enqueue/dequeue exactly the number of elements that
we have in the ring before wrapping to its beginning.

Fixes: cc4b218790f6 ("ring: support configurable element size")
Fixes: 286bd05bf70d ("ring: optimisations")

Signed-off-by: Andrzej Ostruszka <amo@semihalf.com>
Reviewed-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
---
 lib/librte_ring/rte_ring.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h
index 2a9f768a1c..e020781336 100644
--- a/lib/librte_ring/rte_ring.h
+++ b/lib/librte_ring/rte_ring.h
@@ -242,7 +242,7 @@ void rte_ring_dump(FILE *f, const struct rte_ring *r);
 	const uint32_t size = (r)->size; \
 	uint32_t idx = prod_head & (r)->mask; \
 	obj_type *ring = (obj_type *)ring_start; \
-	if (likely(idx + n < size)) { \
+	if (likely(idx + n <= size)) { \
 		for (i = 0; i < (n & ((~(unsigned)0x3))); i+=4, idx+=4) { \
 			ring[idx] = obj_table[i]; \
 			ring[idx+1] = obj_table[i+1]; \
@@ -273,7 +273,7 @@ void rte_ring_dump(FILE *f, const struct rte_ring *r);
 	uint32_t idx = cons_head & (r)->mask; \
 	const uint32_t size = (r)->size; \
 	obj_type *ring = (obj_type *)ring_start; \
-	if (likely(idx + n < size)) { \
+	if (likely(idx + n <= size)) { \
 		for (i = 0; i < (n & (~(unsigned)0x3)); i+=4, idx+=4) {\
 			obj_table[i] = ring[idx]; \
 			obj_table[i+1] = ring[idx+1]; \
-- 
2.35.1.616.g0bdcbb4464-goog


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-07 14:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-07 14:14 [PATCH 19.11] ring: optimize corner case for enqueue/dequeue Andrzej Ostruszka

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