Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Jun 2009 07:44:28 +0000 (UTC)
From:      Kip Macy <kmacy@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r193693 - in user/kmacy/releng_7_2_fcs/sys: net sys
Message-ID:  <200906080744.n587iSVQ019974@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kmacy
Date: Mon Jun  8 07:44:28 2009
New Revision: 193693
URL: http://svn.freebsd.org/changeset/base/193693

Log:
  - add prefetch to single consumer dequeue
  - remove critical section - protected by client lock
  - remove gratuitous memory barrier from buf_ring_peek

Modified:
  user/kmacy/releng_7_2_fcs/sys/net/flowtable.c
  user/kmacy/releng_7_2_fcs/sys/net/if_var.h
  user/kmacy/releng_7_2_fcs/sys/sys/buf_ring.h

Modified: user/kmacy/releng_7_2_fcs/sys/net/flowtable.c
==============================================================================
--- user/kmacy/releng_7_2_fcs/sys/net/flowtable.c	Mon Jun  8 07:42:19 2009	(r193692)
+++ user/kmacy/releng_7_2_fcs/sys/net/flowtable.c	Mon Jun  8 07:44:28 2009	(r193693)
@@ -185,20 +185,6 @@ static struct cv 	flowclean_cv;
 static struct mtx	flowclean_lock;
 static uint64_t		flowclean_cycles;
 
-#if defined(__i386__) || defined(__amd64__)
-static __inline
-void prefetch(void *x) 
-{ 
-        __asm volatile("prefetcht0 %0" :: "m" (*(unsigned long *)x));
-} 
-#else
-static __inline
-void prefetch(void *x) 
-{
-	;
-}
-#endif
-
 /*
  * TODO:
  * - Make flowtable stats per-cpu, aggregated at sysctl call time,

Modified: user/kmacy/releng_7_2_fcs/sys/net/if_var.h
==============================================================================
--- user/kmacy/releng_7_2_fcs/sys/net/if_var.h	Mon Jun  8 07:42:19 2009	(r193692)
+++ user/kmacy/releng_7_2_fcs/sys/net/if_var.h	Mon Jun  8 07:44:28 2009	(r193693)
@@ -561,9 +561,9 @@ drbr_stats_update(struct ifnet *ifp, int
 {
 #ifndef NO_SLOW_STATS
 	ifp->if_obytes += len;
-#endif	
 	if (mflags & M_MCAST)
 		ifp->if_omcasts++;
+#endif	
 }
 
 static __inline int

Modified: user/kmacy/releng_7_2_fcs/sys/sys/buf_ring.h
==============================================================================
--- user/kmacy/releng_7_2_fcs/sys/sys/buf_ring.h	Mon Jun  8 07:42:19 2009	(r193692)
+++ user/kmacy/releng_7_2_fcs/sys/sys/buf_ring.h	Mon Jun  8 07:44:28 2009	(r193693)
@@ -181,24 +181,27 @@ buf_ring_dequeue_mc(struct buf_ring *br)
 static __inline void *
 buf_ring_dequeue_sc(struct buf_ring *br)
 {
-	uint32_t cons_head, cons_next;
+	uint32_t cons_head, cons_next, cons_next_next;
 	uint32_t prod_tail;
 	void *buf;
 	
-	critical_enter();
 	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) {
-		critical_exit();
+	cons_next_next = (cons_head + 2) & br->br_cons_mask;
+	
+	if (cons_head == prod_tail) 
 		return (NULL);
+
+	if (cons_next != prod_tail) {		
+		prefetch(br->br_ring[cons_next]);
+		if (cons_next_next != prod_tail) 
+			prefetch(br->br_ring[cons_next_next]);
 	}
-	
 	br->br_cons_head = cons_next;
 	buf = br->br_ring[cons_head];
-	
+
 #ifdef DEBUG_BUFRING
 	br->br_ring[cons_head] = NULL;
 	if (!mtx_owned(br->br_lock))
@@ -208,7 +211,6 @@ buf_ring_dequeue_sc(struct buf_ring *br)
 		    br->br_cons_tail, cons_head);
 #endif
 	br->br_cons_tail = cons_next;
-	critical_exit();
 	return (buf);
 }
 
@@ -225,7 +227,12 @@ buf_ring_peek(struct buf_ring *br)
 	if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
 		panic("lock not held on single consumer dequeue");
 #endif	
-	wmb();
+	/*
+	 * I believe it is safe to not have a memory barrier
+	 * here because we control cons and tail is worst case
+	 * a lagging indicator so we worst case we might
+	 * return NULL immediately after a buffer has been enqueued
+	 */
 	if (br->br_cons_head == br->br_prod_tail)
 		return (NULL);
 	



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906080744.n587iSVQ019974>