diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-11-06 16:20:21 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-11-11 10:08:08 +0100 |
commit | 66659ff1ad6831b0ea7425fa6ecd8a8687523658 (patch) | |
tree | 48e22b475fa8854128e0861a33fed6f78c8094b5 /freebsd/sys/sys/buf_ring.h | |
parent | Define __GLOBL1() and __GLOBL() (diff) | |
download | rtems-libbsd-66659ff1ad6831b0ea7425fa6ecd8a8687523658.tar.bz2 |
Update to FreeBSD 9.2
Diffstat (limited to 'freebsd/sys/sys/buf_ring.h')
-rw-r--r-- | freebsd/sys/sys/buf_ring.h | 60 |
1 files changed, 50 insertions, 10 deletions
diff --git a/freebsd/sys/sys/buf_ring.h b/freebsd/sys/sys/buf_ring.h index 59853e42..59e74cf7 100644 --- a/freebsd/sys/sys/buf_ring.h +++ b/freebsd/sys/sys/buf_ring.h @@ -48,7 +48,6 @@ struct buf_ring { 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 @@ struct buf_ring { * */ 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 @@ buf_ring_enqueue_bytes(struct buf_ring *br, void *buf, int nbytes) 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 @@ buf_ring_enqueue_bytes(struct buf_ring *br, void *buf, int nbytes) 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 @@ buf_ring_dequeue_sc(struct buf_ring *br) } /* + * 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 |