Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Mar 2007 20:27:48 GMT
From:      "Christian S.J. Peron" <csjp@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 115548 for review
Message-ID:  <200703082027.l28KRmBr061960@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=115548

Change 115548 by csjp@csjp_rnd01 on 2007/03/08 20:27:30

	Introduce more cycle counters to measure the various aspects of the
	new bpf zero copy system:
	
	(1) Measure the number of cycles spent waiting for system calls to
	    finish while processing packet data.  This will allow us to
	    measure the overhead associated with reads in "regular copy mode".
	    As well as allows us to see how many manual buffer rotations we
	    have done in zero copy mode.
	
	(2) Measure the number of cycles spent NOT sleeping. So, this allows us
	    to measure the number of cycles spent from the time select(2) wakes
	    us up, to the time we potentially go back to sleep (or call select(2)
	    again.
	
	(3) Measure the number of cycles spent from the time select(2) wakes us
	    up, to the time we signal to the kernel we are done. In the read case,
	    the kernel is notified after the uiomove completes. In the zerocopy
	    case, the kernel is notified when the user generation number is incremented
	    and a packet comes in.
	
	(4) Also, add a counter which tells the us how many packets we have indexed in
	    total. This allows us to cross reference between packet generation engines.

Affected files ...

.. //depot/projects/zcopybpf/utils/bpfnull/bpfnull.c#17 edit

Differences ...

==== //depot/projects/zcopybpf/utils/bpfnull/bpfnull.c#17 (text+ko) ====

@@ -52,7 +52,10 @@
 
 int		bpf_open(void);
 void		usage(void);
-u_int64_t sum;
+u_int64_t	sum;	/* cycles spent processing packet data */
+u_int64_t	rsum;	/* cycles spent in syscalls after wakeup */
+u_int64_t	ssum;	/* cycles spent not sleep in event  loop */
+u_int64_t	psum;	/* cycles spent before buffer can be reclaimed */
 
 static struct ifreq	 ifr;
 static pcap_dumper_t	*dp;
@@ -69,14 +72,18 @@
 static int		 pflag;
 static int		 Pflag;
 
-/* XXX we need an option to put the interface into promisc mode */
 static u_char		*bufa, *bufb;
 static unsigned long		 packet_count;
 static int
 handle_int(int sig __unused)
 {
 
+	putchar('\n');
 	printf("%lu cycles spent processing packets\n", sum);
+	printf("%lu cycles spent in a syscall after wakeup\n", rsum);
+	printf("%lu cycles spent not sleeping\n", ssum);
+	printf("%lu cycles spent before buffer reclaims\n", psum);
+	printf("%lu packets processed\n", packet_count);
 	exit(0);
 }
 
@@ -156,11 +163,11 @@
 	fd_set s_set, r_set;
 	struct bpf_zbuf bz;
 	char *pbuf;
-	int processed_data, n;
+	int n;
 	struct bpf_zbuf_header *bzha, *bzhb;
 	struct timeval tv;
 	void *prev2, *prev;
-	u_int64_t b, a;
+	u_int64_t b, a, c, d, e, f;
 
 	prev2 = prev = NULL;
 	pbuf = malloc(bflag + 1);
@@ -172,6 +179,7 @@
         for (;;) {
 		r_set = s_set;
 		n = select(fd + 1, &r_set, NULL, NULL, &tv);
+		e = rdtsc();
 		if (n < 0) {
 			fprintf(stderr,"owned by select\n");
 			err(1, "select failed");
@@ -181,9 +189,13 @@
 		if (n != 0 && !FD_ISSET(fd, &r_set) && vflag)
 			printf("No timeout and fd is not ready!\n");
 		if (zflag == 0) {
+			c = rdtsc();
 			n = read(fd, pbuf, bflag);
+			d = rdtsc();
 			if (n < 0)
 				err(1, "read failed");
+			psum += d - e;
+			rsum += d - c;
 			bz.bz_bufa = pbuf;
 			bz.bz_buflen = n;
 			b = rdtsc();
@@ -191,19 +203,23 @@
 			a = rdtsc();
 			sum += a - b;
 		} else {
-			processed_data = 0;
 			bzha = (struct bpf_zbuf_header *)bufa;
 			bzhb = (struct bpf_zbuf_header *)bufb;
 
 			if (n == 0) {
+				c = rdtsc();
 				if (ioctl(fd, BIOCROTZBUF, &bz) < 0)
 					err(1, "ioctl");
+				d = rdtsc();
+				rsum += d - c;
 				if (bz.bz_bufa == NULL) {
 					if (vflag)
 					printf("timeout no data\n");
 					continue;
 				}
 			}
+			assert(bzha->bzh_kernel_gen > bzha->bzh_user_gen ||
+			    bzhb->bzh_kernel_gen > bzhb->bzh_user_gen);
 			if (bzha->bzh_kernel_gen > bzha->bzh_user_gen) {
 				bz.bz_bufa = bufa;
 				bz.bz_bufa += sizeof(struct bpf_zbuf_header);
@@ -212,8 +228,8 @@
 				bpf_process_packets(&bz, "A");
 				a = rdtsc();
 				sum += a - b;
+				psum += a - e;
 				bzha->bzh_user_gen++;
-				processed_data++;
 			} else if (bzhb->bzh_kernel_gen > bzhb->bzh_user_gen) {
 				bz.bz_bufa = bufb;
 				bz.bz_bufa += sizeof(struct bpf_zbuf_header);
@@ -222,11 +238,12 @@
 				bpf_process_packets(&bz, "B");
 				a = rdtsc();
 				sum += a - b;
+				psum += a - e;
 				bzhb->bzh_user_gen++;
-				processed_data++;
 			}
-			assert(processed_data != 0);
 		}
+		f = rdtsc();
+		ssum += f - e;
         }
 }
 



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