[dpdk-dev] Could DPDK ring provide peek interface or any comments for this function?

Yan, Liming (Nokia - CN/Hangzhou) liming.yan at nokia.com
Tue Aug 4 04:20:05 CEST 2015


Hi,
   As we see, DPDK ring has mainly the enqueue/dequeue APIs for SINGLE/MULTI producer/consumer.  I have a requirement in work to take a peek on the top object in the ring. I don't want to consume it, just check the reference of the object.  How could this be supported?   Or any alternative solution for my requirement?  Thanks.
   I wrote my own simple peek interface but it's not MC-safe. I think it's better if DPDK can support it officially.  


 /**
+ * Just take a peek on the top object from a ring but not consume it.
+ * Note: This interface is MC and multi-thread not safe.
+ *       It can only be used for ring with RING_F_SC_DEQ attribute.
+ *
+ * @param r
+ *   A pointer to the ring structure.
+ * @param obj_p
+ *   A pointer to a void * pointer (object) that will be filled.
+ * @return
+ *   - 0: Success, object is peeked.
+ *   - -ENOENT: Not entries in the ring.
+ *   - - EPERM: Operation not permitted/supported
+ */
+static inline int __attribute__((always_inline))
+rte_ring_peek(const struct rte_ring *r, void **obj_p)
+{
+	uint32_t cons_head, prod_tail;
+
+	if (r->cons.sc_dequeue) {
+		cons_head = r->cons.head;
+		prod_tail = r->prod.tail;
+
+		if (prod_tail - cons_head == 0) {
+			return -ENOENT;
+		}
+		*obj_p = r->ring[cons_head & r->prod.mask];
+	} else {
+		return -EPERM;
+	}
+	return 0;
+}
+
+/**


--------^_^--------
Best Regards
Yan Limin




More information about the dev mailing list