From owner-p4-projects@FreeBSD.ORG Fri Feb 2 23:09:01 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9E97416A403; Fri, 2 Feb 2007 23:09:01 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7AFAD16A401 for ; Fri, 2 Feb 2007 23:09:01 +0000 (UTC) (envelope-from csjp@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 69D0013C481 for ; Fri, 2 Feb 2007 23:09:01 +0000 (UTC) (envelope-from csjp@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id l12N91tl041153 for ; Fri, 2 Feb 2007 23:09:01 GMT (envelope-from csjp@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id l12N91B1041150 for perforce@freebsd.org; Fri, 2 Feb 2007 23:09:01 GMT (envelope-from csjp@freebsd.org) Date: Fri, 2 Feb 2007 23:09:01 GMT Message-Id: <200702022309.l12N91B1041150@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to csjp@freebsd.org using -f From: "Christian S.J. Peron" To: Perforce Change Reviews Cc: Subject: PERFORCE change 113925 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Feb 2007 23:09:01 -0000 http://perforce.freebsd.org/chv.cgi?CH=113925 Change 113925 by csjp@csjp_rnd01 on 2007/02/02 23:08:41 Import testing for new zero copy model Affected files ... .. //depot/projects/zcopybpf/utils/bpfnull/bpfnull.c#6 edit Differences ... ==== //depot/projects/zcopybpf/utils/bpfnull/bpfnull.c#6 (text+ko) ==== @@ -23,6 +23,7 @@ #include #include #include +#include int bpf_open(void); void usage(void); @@ -37,7 +38,14 @@ static int wflag; static int vflag; static int zflag; +static u_char *bufa, *bufb; +static int +handle_int(int sig __unused) +{ + exit(0); +} + static void bpf_init_dumpfile(void) { @@ -53,16 +61,22 @@ } static void -bpf_process_packets(struct bpf_zbuf *bz) +bpf_process_packets(struct bpf_zbuf *bz, char *bufname) { struct pcap_pkthdr phd; int clen, hlen; - u_char *bp, *ep, *p; + u_char *b,*bp, *ep, *p; + int i; #define bhp ((struct bpf_hdr *)bp) - bp = bz->bz_bufa; + b = bp = bz->bz_bufa; ep = bp + bz->bz_buflen; + i = 0; while (bp < ep) { + i++; + if (vflag) + fprintf(stderr, "%s %d clen=%i hlen=%d dlen=%d bp=%lu pd=%lu ep=%lu %lu bytes away from eob %lu bytes into buffer\n", + bufname, i, clen, hlen, bhp->bh_datalen, bp, (u_char *)bp + hlen, ep, ep - bp, bp - b); clen = bhp->bh_caplen; hlen = bhp->bh_hdrlen; p = (u_char *)bp + hlen; @@ -85,6 +99,8 @@ struct bpf_zbuf bz; char *pbuf; int n; + struct bpf_zbuf_header *bzha, *bzhb; + int d; pbuf = malloc(bflag + 1); if (pbuf == NULL) @@ -93,10 +109,14 @@ for (;;) { r_set = s_set; n = select(fd + 1, &r_set, NULL, NULL, NULL); - if (n < 0) + if (n < 0) { + fprintf(stderr,"owned by select\n"); err(1, "select failed"); - if (!FD_ISSET(fd, &r_set)) + } + if (!FD_ISSET(fd, &r_set)) { + fprintf(stderr, "FD is NOT set\n"); continue; + } if (vflag) (void) fprintf(stderr, "DEBUG: wokeup and bpf is ready to read from\n"); @@ -106,25 +126,31 @@ err(1, "read failed"); bz.bz_bufa = pbuf; bz.bz_buflen = n; - } else - if (ioctl(fd, BIOCGETZNEXT, &bz) < 0) - err(1, "ioctl(BIOCGETZNEXT)"); - if (wflag) - bpf_process_packets(&bz); - if (zflag == 0) - continue; - if (ioctl(fd, BIOCACKZBUF, &bz) < 0) - err(1, "ioctl(BIOCACKZBUF)"); + if (wflag) + bpf_process_packets(&bz, "W"); + } else { + bzha = (struct bpf_zbuf_header *)bufa; + bzhb = (struct bpf_zbuf_header *)bufb; + if (bzha->bzh_kernel_gen > bzha->bzh_user_gen) { + bz.bz_bufa = bufa; + bz.bz_bufa += sizeof(struct bpf_zbuf_header); + bz.bz_buflen = bzha->bzh_kernel_len; + if (wflag) + bpf_process_packets(&bz, "A"); + bzha->bzh_user_gen++; + } + 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; + if (wflag) + bpf_process_packets(&bz, "B"); + bzhb->bzh_user_gen++; + } + } } } -void * -handle_int(int sig __unused) -{ - - exit(0); -} - int bpf_open(void) { @@ -154,7 +180,6 @@ static int bpf_zbuf_init(int fd, struct bpf_zbuf *bz) { - u_char *bufa, *bufb; int bmode; if ((bflag % getpagesize()) != 0) @@ -166,7 +191,7 @@ err(1, "mmap(bufa)"); bufb = mmap(NULL, bz->bz_buflen, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); - if (bufa == MAP_FAILED) + if (bufb == MAP_FAILED) err(1, "mmap(bufb)"); bz->bz_bufa = bufa; bz->bz_bufb = bufb;