Date: Fri, 21 Nov 2008 04:37:38 +0000 (UTC) From: Kip Macy <kmacy@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r185141 - user/kmacy/HEAD_fast_multi_xmit/sys/sys Message-ID: <200811210437.mAL4bcnF073889@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kmacy Date: Fri Nov 21 04:37:38 2008 New Revision: 185141 URL: http://svn.freebsd.org/changeset/base/185141 Log: add sanity checking of buf ring functions under DEBUG_BUFRING Modified: user/kmacy/HEAD_fast_multi_xmit/sys/sys/buf_ring.h Modified: user/kmacy/HEAD_fast_multi_xmit/sys/sys/buf_ring.h ============================================================================== --- user/kmacy/HEAD_fast_multi_xmit/sys/sys/buf_ring.h Fri Nov 21 03:03:57 2008 (r185140) +++ user/kmacy/HEAD_fast_multi_xmit/sys/sys/buf_ring.h Fri Nov 21 04:37:38 2008 (r185141) @@ -56,6 +56,15 @@ #error "unknown compiler" #endif +#if defined(INVARIANTS) && !defined(DEBUG_BUFRING) +#define DEBUG_BUFRING 1 +#endif + +#ifdef DEBUG_BUFRING +#include <sys/lock.h> +#include <sys/mutex.h> +#endif + struct buf_ring { volatile uint32_t br_prod_head; volatile uint32_t br_prod_tail; @@ -70,11 +79,14 @@ struct buf_ring { volatile uint32_t br_cons_tail; int br_cons_size; int br_cons_mask; - + /* * Pad out to next L2 cache line */ uint64_t _pad1[14]; +#ifdef DEBUG_BUFRING + struct mtx *br_lock; +#endif void *br_ring[0]; }; @@ -85,7 +97,14 @@ buf_ring_enqueue(struct buf_ring *br, vo uint32_t prod_head, prod_next; uint32_t cons_tail; int success; - +#ifdef DEBUG_BUFRING + int i; + for (i = br->br_cons_head; i != br->br_prod_head; + i = ((i + 1) & br->br_cons_mask)) + if(br->br_ring[i] == buf) + panic("buf=%p already enqueue at %d prod=%d cons=%d", + buf, i, br->br_prod_tail, br->br_cons_tail); +#endif critical_enter(); do { prod_head = br->br_prod_head; @@ -101,9 +120,10 @@ buf_ring_enqueue(struct buf_ring *br, vo success = atomic_cmpset_int(&br->br_prod_head, prod_head, prod_next); } while (success == 0); - - KASSERT(br->br_ring[prod_head] == NULL, ("dangling value in enqueue")); - +#ifdef DEBUG_BUFRING + if (br->br_ring[prod_head] != NULL) + panic("dangling value in enqueue"); +#endif br->br_ring[prod_head] = buf; wmb(); @@ -115,6 +135,7 @@ buf_ring_enqueue(struct buf_ring *br, vo while (br->br_prod_tail != prod_head) cpu_spinwait(); br->br_prod_tail = prod_next; + mb(); critical_exit(); return (0); } @@ -148,7 +169,7 @@ buf_ring_dequeue_mc(struct buf_ring *br) } while (success == 0); buf = br->br_ring[cons_head]; -#ifdef INVARIANTS +#ifdef DEBUG_BUFRING br->br_ring[cons_head] = NULL; #endif mb(); @@ -192,14 +213,16 @@ buf_ring_dequeue_sc(struct buf_ring *br) br->br_cons_head = cons_next; buf = br->br_ring[cons_head]; -#ifdef INVARIANTS + mb(); + +#ifdef DEBUG_BUFRING br->br_ring[cons_head] = NULL; + if (!mtx_owned(br->br_lock)) + panic("lock not held on single consumer dequeue"); + if (br->br_cons_tail != cons_head) + panic("inconsistent list cons_tail=%d cons_head=%d", + br->br_cons_tail, cons_head); #endif - mb(); - KASSERT(br->br_cons_tail == cons_head, - ("inconsistent list cons_tail=%d cons_head=%d", - br->br_cons_tail, cons_head)); - br->br_cons_tail = cons_next; mb(); critical_exit(); @@ -235,7 +258,8 @@ buf_ring_count(struct buf_ring *br) & br->br_prod_mask); } -struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags); +struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags, + struct mtx *); void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200811210437.mAL4bcnF073889>