Date: Thu, 4 Aug 2011 16:43:27 GMT From: Takuya ASADA <syuu@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 197191 for review Message-ID: <201108041643.p74GhRP2094498@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@197191?ac=10 Change 197191 by syuu@kikurage on 2011/08/04 16:43:15 Bugfix Affected files ... .. //depot/projects/soc2011/mq_bpf/src/tools/regression/bpf/mq_bpf/test_mqbpf/Makefile#2 edit .. //depot/projects/soc2011/mq_bpf/src/tools/regression/bpf/mq_bpf/test_mqbpf/test_mqbpf.c#3 edit .. //depot/projects/soc2011/mq_bpf/src/tools/regression/bpf/mq_bpf/test_sqbpf/test_sqbpf.c#3 edit Differences ... ==== //depot/projects/soc2011/mq_bpf/src/tools/regression/bpf/mq_bpf/test_mqbpf/Makefile#2 (text+ko) ==== @@ -1,6 +1,7 @@ PROG= test_mqbpf SRCS+= test_mqbpf.c +DPADD= ${LIBPCAP} ${LIBPTHREAD} +LDADD= -lpcap -lpthread NO_MAN= -CFLAGS= -lpthread .include <bsd.prog.mk> ==== //depot/projects/soc2011/mq_bpf/src/tools/regression/bpf/mq_bpf/test_mqbpf/test_mqbpf.c#3 (text+ko) ==== @@ -49,6 +49,7 @@ #include <errno.h> #include <signal.h> #include <err.h> +#include <pcap.h> #include <assert.h> #include <pthread.h> @@ -67,19 +68,26 @@ u_char *bufa, *bufb; unsigned long count; unsigned long wrote; + pcap_dumper_t *dp; + pcap_t *p; }; static char *ifname = NULL; static struct bpf_thread_instance *instances; -static int rxqlen, txqlen; +static int rxqlen, txqlen, maxcpus; int bpf_open(void); void usage(void); static struct ifreq ifr; +static char *fflag; +#if 0 +static unsigned long cflag; +#endif static int Iflag; static char *iflag; static int bflag = 32768; +static int wflag; static int vflag; static int zflag; static int Tflag; @@ -111,26 +119,28 @@ u_int64_t ssum = 0; /* cycles spent not sleep in event loop */ u_int64_t psum = 0; /* cycles spent before buffer can be reclaimed */ unsigned long count = 0; -#if 0 u_int recv = 0; u_int drop = 0; -#endif - for (i = 0; i < (rxqlen + txqlen + 1); i++) { - pthread_cancel(instances[i].thread); - pthread_join(instances[i].thread, NULL); - wrote += (double)instances[i].wrote / (double)(1024 * 1024); + for (i = 0; i < maxcpus; i++) { + if (pthread_cancel(instances[i].thread) < 0) { + perror("pthread_cancel"); + exit(-1); + } + if (pthread_join(instances[i].thread, NULL) < 0) { + perror("pthread_join"); + exit(-1); + } + wrote += instances[i].wrote; sum += instances[i].sum; rsum += instances[i].rsum; ssum += instances[i].ssum; psum += instances[i].psum; count += instances[i].count; -#if 0 if (ioctl(instances[i].bpffd, BIOCGSTATS, &bs) < 0) err(-1, "BIOCGSTATS"); recv += bs.bs_recv; drop += bs.bs_drop; -#endif } putchar('\n'); @@ -139,14 +149,12 @@ printf("%lu cycles spent not sleeping\n", ssum); printf("%lu cycles spent before buffer reclaims\n", psum); printf("%lu packets processed\n", count); + wrote /= (double)(1024 * 1024); throughput = (wrote * 8) / 60; printf("wrote:%f MB throughput:%f Mbps\n", wrote, throughput); - -#if 0 printf("%u packets received (BPF)\n", recv); printf("%u packets dropped (BPF)\n", drop); -#endif exit(0); } @@ -160,13 +168,27 @@ return (low | ((u_int64_t) high << 32)); } -/* -#define CACHE_LINE_SIZE 32 -*/ +static void +bpf_init_dumpfile(struct bpf_thread_instance *instance) +{ + char filename[strlen(fflag) + 4]; + + if (wflag == 0) + return; + + snprintf(filename, strlen(fflag) + 4, "%s.%x", fflag, instance->cpu); + instance->p = pcap_open_dead(DLT_EN10MB, 0xffffU); + instance->dp = pcap_dump_open(instance->p, filename); + if (instance->dp == NULL) { + pcap_perror(instance->p, filename); + exit(-1); + } +} static void bpf_process_packets(struct bpf_thread_instance *instance, struct bpf_zbuf *bz, char *bufname) { + struct pcap_pkthdr phd; int clen, hlen, i; u_char *b,*bp, *ep, *p, by; #define bhp ((struct bpf_hdr *)bp) @@ -175,6 +197,10 @@ ep = bp + bz->bz_buflen; while (bp < ep) { instance->count++; +#if 0 + if (cflag > 0 && packet_count > cflag) + exit(0); +#endif if (pflag) { /* * XXXCSJP this prefetch method needs to be @@ -184,12 +210,24 @@ } clen = bhp->bh_caplen; hlen = bhp->bh_hdrlen; + p = (u_char *)bp + hlen; + phd.ts.tv_sec = bhp->bh_tstamp.tv_sec; + phd.ts.tv_usec = bhp->bh_tstamp.tv_usec; + phd.caplen = phd.len = bhp->bh_datalen; if (Tflag) { for (i = 0; i < bhp->bh_datalen; i++) by = p[i]; bp += BPF_WORDALIGN(clen + hlen); continue; } + if (wflag) { + pcap_dump((u_char *)instance->dp, &phd, p); + if (ferror((FILE *)instance->dp)) { + perror("dump.pcap"); + exit(-1); + } + fflush((FILE *)instance->dp); + } instance->wrote += bhp->bh_caplen; bp += BPF_WORDALIGN(clen + hlen); } @@ -233,8 +271,7 @@ n = read(instance->bpffd, pbuf, bflag); d = rdtsc(); if (n < 0) -// err(1, "read failed"); - fprintf(stderr, "read failed"); + err(1, "read failed"); instance->psum += d - e; instance->rsum += d - c; bz.bz_bufa = pbuf; @@ -383,19 +420,24 @@ CPU_ZERO(&instance->cpuset); CPU_SET(instance->cpu, &instance->cpuset); - cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, - sizeof(cpuset_t), &instance->cpuset); + if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, + sizeof(cpuset_t), &instance->cpuset) < 0) { + perror("cpuset_setaffinity"); + exit(-1); + } bzero(&ifr, sizeof(ifr)); strlcpy(ifr.ifr_name, iflag, sizeof(ifr.ifr_name)); instance->bpffd = bpf_open(); - if (instance->bpffd == -1) { + if (instance->bpffd < 0) { (void) fprintf(stderr, "bpfnull: no bpf device available\n"); - exit(1); + exit(-1); } if (vflag) (void) fprintf(stderr, "DEBUG: obtained bpf fd=%d\n", instance->bpffd); + if (fflag) + bpf_init_dumpfile(instance); #ifdef BPF_BUFMODE_ZBUF if (zflag) { if (vflag) @@ -470,7 +512,7 @@ main(int argc, char *argv[]) { char ch; - int i, s, maxcpus; + int i, s; struct sigaction action = { .sa_handler = (void (*)(int))handle_int, .sa_flags = 0 @@ -501,6 +543,18 @@ case 'b': bflag = atoi(optarg); break; +#if 0 + case 'c': + { + char *r; + cflag = strtoul(optarg, &r, 10); + } + break; +#endif + case 'f': + fflag = optarg; + wflag = 1; + break;; case 'i': iflag = optarg; break; @@ -516,6 +570,9 @@ case 'T': Tflag = 1; break; + case 'w': + wflag = 1; + break; case 'v': vflag++; break; @@ -578,12 +635,20 @@ instances[0].other = 1; - for (i = 0; i < maxcpus; i++) - pthread_create(&instances[i].thread, NULL, - (void *(*)(void *))bpf_thread, &instances[i]); + for (i = 0; i < maxcpus; i++) { + if (pthread_create(&instances[i].thread, NULL, + (void *(*)(void *))bpf_thread, &instances[i]) < 0) { + perror("pthread_create"); + return -1; + } + } - for (i = 0; i < maxcpus; i++) - pthread_join(instances[i].thread, NULL); + for (i = 0; i < maxcpus; i++) { + if (pthread_join(instances[i].thread, NULL) < 0) { + perror("pthread_join"); + return -1; + } + } return (0); } ==== //depot/projects/soc2011/mq_bpf/src/tools/regression/bpf/mq_bpf/test_sqbpf/test_sqbpf.c#3 (text+ko) ==== @@ -329,11 +329,6 @@ bmode = BPF_BUFMODE_ZBUF; if (ioctl(bpffd, BIOCSETBUFMODE, &bmode) < 0) err(1, "ioctl(BIOCGSETBUFMODE)"); - u_int zbufmax; - if (ioctl(bpffd, BIOCGETZMAX, (caddr_t)&zbufmax) < 0) { - err(1, "ioctl(BIOCGETZMAX)"); - } - printf("zbufmax:%d\n", zbufmax); if (ioctl(bpffd, BIOCSETZBUF, bz) < 0) err(1, "ioctl(BIOCSETZBUF)"); if (vflag)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108041643.p74GhRP2094498>