From owner-p4-projects@FreeBSD.ORG Thu Mar 8 20:27:49 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 EC63516A401; Thu, 8 Mar 2007 20:27:48 +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 B27EE16A405 for ; Thu, 8 Mar 2007 20:27:48 +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 A251613C494 for ; Thu, 8 Mar 2007 20:27:48 +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 l28KRmFh061963 for ; Thu, 8 Mar 2007 20:27:48 GMT (envelope-from csjp@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id l28KRmBr061960 for perforce@freebsd.org; Thu, 8 Mar 2007 20:27:48 GMT (envelope-from csjp@freebsd.org) Date: Thu, 8 Mar 2007 20:27:48 GMT Message-Id: <200703082027.l28KRmBr061960@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 115548 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: Thu, 08 Mar 2007 20:27:49 -0000 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; } }