Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Dec 2012 07:29:25 +0000 (UTC)
From:      Luigi Rizzo <luigi@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r244672 - head/tools/tools/netrate/netreceive
Message-ID:  <201212250729.qBP7TPGo010317@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: luigi
Date: Tue Dec 25 07:29:25 2012
New Revision: 244672
URL: http://svnweb.freebsd.org/changeset/base/244672

Log:
  various connections to last commit

Modified:
  head/tools/tools/netrate/netreceive/Makefile
  head/tools/tools/netrate/netreceive/netreceive.c

Modified: head/tools/tools/netrate/netreceive/Makefile
==============================================================================
--- head/tools/tools/netrate/netreceive/Makefile	Tue Dec 25 06:07:34 2012	(r244671)
+++ head/tools/tools/netrate/netreceive/Makefile	Tue Dec 25 07:29:25 2012	(r244672)
@@ -4,5 +4,6 @@
 
 PROG=	netreceive
 NO_MAN=
+LDFLAGS += -lpthread
 
 .include <bsd.prog.mk>

Modified: head/tools/tools/netrate/netreceive/netreceive.c
==============================================================================
--- head/tools/tools/netrate/netreceive/netreceive.c	Tue Dec 25 06:07:34 2012	(r244671)
+++ head/tools/tools/netrate/netreceive/netreceive.c	Tue Dec 25 07:29:25 2012	(r244672)
@@ -59,6 +59,7 @@ static int round_to(int n, int l)
 struct td_desc {
 	pthread_t td_id;
 	uint64_t count;	/* rx counter */
+	uint64_t byte_count;	/* rx byte counter */
 	int fd;
 	char *buf;
 	int buflen;
@@ -116,18 +117,20 @@ rx_body(void *data)
 			if (y < 0)
 				break;
 			t->count++;
+			t->byte_count += y;
 		}
 	}
 	return NULL;
 }
 
-int
-make_threads(struct td_desc **tp, int *s, int nsock, int nthreads)
+static struct td_desc **
+make_threads(int *s, int nsock, int nthreads)
 {
 	int i, si, nt = nsock * nthreads;
 	int lb = round_to(nt * sizeof (struct td_desc *), 64);
 	int td_len = round_to(sizeof(struct td_desc), 64); // cache align
 	char *m = calloc(1, lb + td_len * nt);
+	struct td_desc **tp;
 
 	printf("td len %d -> %d\n", (int)sizeof(struct td_desc) , td_len);
 	/* pointers plus the structs */
@@ -140,6 +143,8 @@ make_threads(struct td_desc **tp, int *s
 	for (si = i = 0; i < nt; i++, m += td_len) {
 		tp[i] = (struct td_desc *)m;
 		tp[i]->fd = s[si];
+		tp[i]->buflen = 65536;
+		tp[i]->buf = calloc(1, tp[i]->buflen);
 		if (++si == nsock)
 			si = 0;
 		if (pthread_create(&tp[i]->td_id, NULL, rx_body, tp[i])) {
@@ -147,27 +152,29 @@ make_threads(struct td_desc **tp, int *s
 			exit(1);
 		}
 	}
+	return tp;
 }
 
-int
+static void
 main_thread(struct td_desc **tp, int nsock, int nthreads)
 {
-	uint64_t c0, c1;
+	uint64_t c0, c1, bc0, bc1;
 	struct timespec now, then, delta;
 	/* now the parent collects and prints results */
-	c0 = c1 = 0;
+	c0 = c1 = bc0 = bc1 = 0;
 	clock_gettime(CLOCK_REALTIME, &then);
 	fprintf(stderr, "start at %ld.%09ld\n", then.tv_sec, then.tv_nsec);
 	while (1) {
 		int i, nt = nsock * nthreads;
 		int64_t dn;
-		uint64_t pps;
+		uint64_t pps, bps;
 
 		if (poll(NULL, 0, 500) < 0) 
 			perror("poll");
-		c0 = 0;
+		c0 = bc0 = 0;
 		for (i = 0; i < nt; i++) {
 			c0 += tp[i]->count;
+			bc0 += tp[i]->byte_count;
 		}
 		dn = c0 - c1;
 		clock_gettime(CLOCK_REALTIME, &now);
@@ -176,9 +183,12 @@ main_thread(struct td_desc **tp, int nso
 		then = now;
 		pps = dn;
 		pps = (pps * 1000000000) / (delta.tv_sec*1000000000 + delta.tv_nsec + 1);
-		fprintf(stderr, "%d pkts in %ld.%09ld ns %ld pps\n",
-			(int)dn, delta.tv_sec, delta.tv_nsec, (long)pps);
+		bps = ((bc0 - bc1) * 8000000000) / (delta.tv_sec*1000000000 + delta.tv_nsec + 1);
+		fprintf(stderr, " %9ld pps %8.3f Mbps", (long)pps, .000001*bps);
+		fprintf(stderr, " - %d pkts in %ld.%09ld ns\n",
+			(int)dn, delta.tv_sec, delta.tv_nsec);
 		c1 = c0;
+		bc1 = bc0;
 	}
 }
 
@@ -256,7 +266,7 @@ main(int argc, char *argv[])
 	printf("netreceive %d sockets x %d threads listening on UDP port %d\n",
 		nsock, nthreads, (u_short)port);
 
-	make_threads(tp, s, nsock, nthreads);
+	tp = make_threads(s, nsock, nthreads);
 	main_thread(tp, nsock, nthreads);
 
 	/*NOTREACHED*/



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