DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v2] ring: check for zero objects mc dequeue / mp enqueue
@ 2016-03-17 15:49 Lazaros Koromilas
  2016-03-17 16:09 ` Mauricio Vásquez
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Lazaros Koromilas @ 2016-03-17 15:49 UTC (permalink / raw)
  To: dev

Issuing a zero objects dequeue with a single consumer has no effect.
Doing so with multiple consumers, can get more than one thread to succeed
the compare-and-set operation and observe starvation or even deadlock in
the while loop that checks for preceding dequeues.  The problematic piece
of code when n = 0:

    cons_next = cons_head + n;
    success = rte_atomic32_cmpset(&r->cons.head, cons_head, cons_next);

The same is possible on the enqueue path.

Signed-off-by: Lazaros Koromilas <l@nofutznetworks.com>
---
 lib/librte_ring/rte_ring.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h
index 943c97c..eb45e41 100644
--- a/lib/librte_ring/rte_ring.h
+++ b/lib/librte_ring/rte_ring.h
@@ -431,6 +431,11 @@ __rte_ring_mp_do_enqueue(struct rte_ring *r, void * const *obj_table,
 	uint32_t mask = r->prod.mask;
 	int ret;
 
+	/* Avoid the unnecessary cmpset operation below, which is also
+	 * potentially harmful when n equals 0. */
+	if (n == 0)
+		return 0;
+
 	/* move prod.head atomically */
 	do {
 		/* Reset n to the initial burst count */
@@ -618,6 +623,11 @@ __rte_ring_mc_do_dequeue(struct rte_ring *r, void **obj_table,
 	unsigned i, rep = 0;
 	uint32_t mask = r->prod.mask;
 
+	/* Avoid the unnecessary cmpset operation below, which is also
+	 * potentially harmful when n equals 0. */
+	if (n == 0)
+		return 0;
+
 	/* move cons.head atomically */
 	do {
 		/* Restore n as it may change every loop */
-- 
1.9.1

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

end of thread, other threads:[~2016-03-29 17:35 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-17 15:49 [dpdk-dev] [PATCH v2] ring: check for zero objects mc dequeue / mp enqueue Lazaros Koromilas
2016-03-17 16:09 ` Mauricio Vásquez
2016-03-18 10:18   ` Bruce Richardson
2016-03-18 10:27     ` Olivier Matz
2016-03-18 10:35       ` Bruce Richardson
2016-03-18 10:35       ` Thomas Monjalon
2016-03-18 12:47         ` Mauricio Vásquez
2016-03-18 14:16           ` Bruce Richardson
2016-03-21 17:47             ` Xie, Huawei
2016-03-22 10:13               ` Bruce Richardson
2016-03-22 14:38                 ` Xie, Huawei
2016-03-21 12:23 ` Olivier Matz
2016-03-22 16:49   ` Thomas Monjalon
2016-03-25 11:15 ` Olivier Matz
2016-03-28 15:48   ` Lazaros Koromilas
2016-03-29  8:54     ` Bruce Richardson
2016-03-29 15:29       ` Olivier MATZ
2016-03-29 16:04         ` Bruce Richardson
2016-03-29 17:35           ` Lazaros Koromilas

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