Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Mar 2007 17:47:14 GMT
From:      "Christian S.J. Peron" <csjp@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 115349 for review
Message-ID:  <200703051747.l25HlEvI002939@repoman.freebsd.org>

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

Change 115349 by csjp@csjp_rnd01 on 2007/03/05 17:46:43

	- Introduce -P to put the card into promiscuous mode. I've been
	  setting it manually up until now
	- Get rid of -t, it was redundant and will now be the default
	  action
	- Add a comment that the prefetch method really needs to be looked
	  at by somebody with more CPU architecture fu

Affected files ...

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

Differences ...

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

@@ -52,28 +52,43 @@
 
 int		bpf_open(void);
 void		usage(void);
+u_int64_t sum;
 
 static struct ifreq	 ifr;
 static pcap_dumper_t	*dp;
 static pcap_t		*p;
 static char		*fflag = "-";
+static unsigned long	 cflag;
 static int		 Iflag;
 static char		*iflag;
 static int		 bflag = 32768;
 static int		 wflag;
 static int		 vflag;
 static int		 zflag;
-static int		 tflag;
 static int		 Tflag;
 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)
 {
+
+	printf("%lu cycles spent processing packets\n", sum);
 	exit(0);
 }
 
+u_int64_t
+rdtsc(void)
+{
+	u_int32_t high, low;
+
+	__asm __volatile("rdtsc" : "=a" (low), "=d" (high));
+	return (low | ((u_int64_t) high << 32));
+}
+
 static void
 bpf_init_dumpfile(void)
 {
@@ -98,13 +113,19 @@
 	u_char *b,*bp, *ep, *p, by;
 #define bhp ((struct bpf_hdr *)bp)
 
-	if (!wflag && !tflag && !Tflag)
-		return;
 	b = bp = bz->bz_bufa;
 	p = ep = bp + bz->bz_buflen;
 	while (bp < ep) {
-		if (pflag)
+		packet_count++;
+		if (cflag > 0 && packet_count > cflag)
+			exit(0);
+		if (pflag) {
+			/*
+			 * XXXCSJP this prefetch method needs to be
+			 * re-visted
+			 */
 			__builtin_prefetch(bp + bhp->bh_datalen, 0, 3);
+		}
 		clen = bhp->bh_caplen;
 		hlen = bhp->bh_hdrlen;
 		p = (u_char *)bp + hlen;
@@ -117,10 +138,6 @@
 			bp += BPF_WORDALIGN(clen + hlen);
 			continue;
 		}
-		if (tflag) {
-			bp += BPF_WORDALIGN(clen + hlen);
-			continue;
-		}
 		if (wflag) {
 			pcap_dump((u_char *)dp, &phd, p);
 			if (ferror((FILE *)dp)) {
@@ -128,8 +145,8 @@
 				exit(1);
 			}
 			fflush((FILE *)dp);
-			bp += BPF_WORDALIGN(clen + hlen);
 		}
+		bp += BPF_WORDALIGN(clen + hlen);
 	}
 }
 
@@ -143,6 +160,7 @@
 	struct bpf_zbuf_header *bzha, *bzhb;
 	struct timeval tv;
 	void *prev2, *prev;
+	u_int64_t b, a;
 
 	prev2 = prev = NULL;
 	pbuf = malloc(bflag + 1);
@@ -153,14 +171,14 @@
 	FD_SET(fd, &s_set);
         for (;;) {
 		r_set = s_set;
-		n = select(fd + 1, &r_set, NULL, NULL, NULL);
+		n = select(fd + 1, &r_set, NULL, NULL, &tv);
 		if (n < 0) {
 			fprintf(stderr,"owned by select\n");
 			err(1, "select failed");
 		}
 		if (vflag)
 			(void) fprintf(stderr, "select wakeup\n");
-		if (n != 0 && !FD_ISSET(fd, &r_set))
+		if (n != 0 && !FD_ISSET(fd, &r_set) && vflag)
 			printf("No timeout and fd is not ready!\n");
 		if (zflag == 0) {
 			n = read(fd, pbuf, bflag);
@@ -168,7 +186,10 @@
 				err(1, "read failed");
 			bz.bz_bufa = pbuf;
 			bz.bz_buflen = n;
+			b = rdtsc();
 			bpf_process_packets(&bz, "W");
+			a = rdtsc();
+			sum += a - b;
 		} else {
 			processed_data = 0;
 			bzha = (struct bpf_zbuf_header *)bufa;
@@ -178,6 +199,7 @@
 				if (ioctl(fd, BIOCROTZBUF, &bz) < 0)
 					err(1, "ioctl");
 				if (bz.bz_bufa == NULL) {
+					if (vflag)
 					printf("timeout no data\n");
 					continue;
 				}
@@ -186,14 +208,20 @@
 				bz.bz_bufa = bufa;
 				bz.bz_bufa += sizeof(struct bpf_zbuf_header);
 				bz.bz_buflen = bzha->bzh_kernel_len;
+				b = rdtsc();
 				bpf_process_packets(&bz, "A");
+				a = rdtsc();
+				sum += a - b;
 				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);
 				bz.bz_buflen = bzhb->bzh_kernel_len;
+				b = rdtsc();
 				bpf_process_packets(&bz, "B");
+				a = rdtsc();
+				sum += a - b;
 				bzhb->bzh_user_gen++;
 				processed_data++;
 			}
@@ -283,11 +311,17 @@
 	char ch;
 
 	signal(SIGINT, (void *)handle_int);
-	while ((ch = getopt(argc, argv, "b:f:hIi:ptTwvz")) != -1) {
+	while ((ch = getopt(argc, argv, "b:c:f:hIi:pPTwvz")) != -1) {
 		switch (ch) {
 		case 'b':
 			bflag = atoi(optarg);
 			break;
+		case 'c':
+			{
+				char *r;
+			cflag = strtoul(optarg, &r, 10);
+			}
+			break;
 		case 'f':
 			fflag = optarg;
 			wflag = 1;
@@ -301,8 +335,8 @@
 		case 'p':
 			pflag = 1;
 			break;
-		case 't':
-			tflag = 1;
+		case 'P':
+			Pflag = 1;
 			break;
 		case 'T':
 			Tflag = 1;
@@ -357,6 +391,14 @@
 		if (ioctl(in, BIOCIMMEDIATE, &opt) < 0)
 			err(1, "BIOCIMMEDIATE");
 	}
+	if (Pflag) {
+		if (vflag)
+			(void) fprintf(stderr,
+			    "DEBUG: putting card into promiscuous "
+			    "mode\n");
+		if (ioctl(in, BIOCPROMISC, NULL) < 0)
+			err(1, "BIOCPROMISC");
+	}
 	if (vflag)
 		(void) fprintf(stderr,
 		    "DEBUG: attaching to %s\n", iflag);



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