[Midnightbsd-cvs] src [6554] trunk/sys/sys/buf_ring.h: add putback.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Dec 28 09:25:10 EST 2013


Revision: 6554
          http://svnweb.midnightbsd.org/src/?rev=6554
Author:   laffer1
Date:     2013-12-28 09:25:10 -0500 (Sat, 28 Dec 2013)
Log Message:
-----------
add putback. Obtained From: FreeBSD

Modified Paths:
--------------
    trunk/sys/sys/buf_ring.h

Modified: trunk/sys/sys/buf_ring.h
===================================================================
--- trunk/sys/sys/buf_ring.h	2013-12-28 14:24:33 UTC (rev 6553)
+++ trunk/sys/sys/buf_ring.h	2013-12-28 14:25:10 UTC (rev 6554)
@@ -48,7 +48,6 @@
 	int              	br_prod_mask;
 	uint64_t		br_drops;
 	uint64_t		br_prod_bufs;
-	uint64_t		br_prod_bytes;
 	/*
 	 * Pad out to next L2 cache line
 	 */
@@ -74,7 +73,7 @@
  *
  */
 static __inline int
-buf_ring_enqueue_bytes(struct buf_ring *br, void *buf, int nbytes)
+buf_ring_enqueue(struct buf_ring *br, void *buf)
 {
 	uint32_t prod_head, prod_next;
 	uint32_t cons_tail;
@@ -95,6 +94,7 @@
 		prod_next = (prod_head + 1) & br->br_prod_mask;
 		
 		if (prod_next == cons_tail) {
+			br->br_drops++;
 			critical_exit();
 			return (ENOBUFS);
 		}
@@ -117,19 +117,11 @@
 	while (br->br_prod_tail != prod_head)
 		cpu_spinwait();
 	br->br_prod_bufs++;
-	br->br_prod_bytes += nbytes;
 	br->br_prod_tail = prod_next;
 	critical_exit();
 	return (0);
 }
 
-static __inline int
-buf_ring_enqueue(struct buf_ring *br, void *buf)
-{
-
-	return (buf_ring_enqueue_bytes(br, buf, 0));
-}
-
 /*
  * multi-consumer safe dequeue 
  *
@@ -222,6 +214,54 @@
 }
 
 /*
+ * single-consumer advance after a peek
+ * use where it is protected by a lock
+ * e.g. a network driver's tx queue lock
+ */
+static __inline void
+buf_ring_advance_sc(struct buf_ring *br)
+{
+	uint32_t cons_head, cons_next;
+	uint32_t prod_tail;
+	
+	cons_head = br->br_cons_head;
+	prod_tail = br->br_prod_tail;
+	
+	cons_next = (cons_head + 1) & br->br_cons_mask;
+	if (cons_head == prod_tail) 
+		return;
+	br->br_cons_head = cons_next;
+#ifdef DEBUG_BUFRING
+	br->br_ring[cons_head] = NULL;
+#endif
+	br->br_cons_tail = cons_next;
+}
+
+/*
+ * Used to return a buffer (most likely already there)
+ * to the top od the ring. The caller should *not*
+ * have used any dequeue to pull it out of the ring
+ * but instead should have used the peek() function.
+ * This is normally used where the transmit queue
+ * of a driver is full, and an mubf must be returned.
+ * Most likely whats in the ring-buffer is what
+ * is being put back (since it was not removed), but
+ * sometimes the lower transmit function may have
+ * done a pullup or other function that will have
+ * changed it. As an optimzation we always put it
+ * back (since jhb says the store is probably cheaper),
+ * if we have to do a multi-queue version we will need
+ * the compare and an atomic.
+ */
+static __inline void
+buf_ring_putback_sc(struct buf_ring *br, void *new)
+{
+	KASSERT(br->br_cons_head != br->br_prod_tail, 
+		("Buf-Ring has none in putback")) ;
+	br->br_ring[br->br_cons_head] = new;
+}
+
+/*
  * return a pointer to the first entry in the ring
  * without modifying it, or NULL if the ring is empty
  * race-prone if not protected by a lock



More information about the Midnightbsd-cvs mailing list