PERFORCE change 113925 for review
Christian S.J. Peron
csjp at FreeBSD.org
Fri Feb 2 23:09:01 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=113925
Change 113925 by csjp at 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 <signal.h>
#include <err.h>
#include <pcap.h>
+#include <assert.h>
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;
More information about the p4-projects
mailing list