From owner-p4-projects@FreeBSD.ORG Wed Jan 31 14:51:03 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 E97BE16A407; Wed, 31 Jan 2007 14:51:02 +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 82DE316A406 for ; Wed, 31 Jan 2007 14:51:02 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 718A813C4D3 for ; Wed, 31 Jan 2007 14:51:02 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id l0VEp22S096886 for ; Wed, 31 Jan 2007 14:51:02 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id l0VEp2tH096880 for perforce@freebsd.org; Wed, 31 Jan 2007 14:51:02 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Wed, 31 Jan 2007 14:51:02 GMT Message-Id: <200701311451.l0VEp2tH096880@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Cc: Subject: PERFORCE change 113762 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: Wed, 31 Jan 2007 14:51:03 -0000 http://perforce.freebsd.org/chv.cgi?CH=113762 Change 113762 by rwatson@rwatson_cinnamon on 2007/01/31 14:50:13 When in BPF immediate mode, modify getznext to rotate the buffers if there is data in the stored buffer but not the held buffer: this is effectively the same behavior found in bpfread(), and causes a BPF buffer rotation if it can satisfy the request for a buffer immediately by doing so. Move the BPF rotation logic [back] into the global include file so that bpf_zerocopy.c can use it. Affected files ... .. //depot/projects/zcopybpf/src/sys/net/bpf.c#8 edit .. //depot/projects/zcopybpf/src/sys/net/bpf.h#4 edit .. //depot/projects/zcopybpf/src/sys/net/bpf_zerocopy.c#7 edit Differences ... ==== //depot/projects/zcopybpf/src/sys/net/bpf.c#8 (text+ko) ==== @@ -613,19 +613,6 @@ } /* - * Rotate the packet buffers in descriptor d. Move the store buffer into - * the hold slot, and the free buffer ino the store slot. Zero the length of - * the new store buffer. Descriptor lock should be held. - */ -#define ROTATE_BUFFERS(d) do { \ - (d)->bd_hbuf = (d)->bd_sbuf; \ - (d)->bd_hlen = (d)->bd_slen; \ - (d)->bd_sbuf = (d)->bd_fbuf; \ - (d)->bd_slen = 0; \ - (d)->bd_fbuf = NULL; \ -} while (0) - -/* * bpfread - read next chunk of packets from buffers */ static int ==== //depot/projects/zcopybpf/src/sys/net/bpf.h#4 (text+ko) ==== @@ -663,6 +663,19 @@ #endif /* + * Rotate the packet buffers in descriptor d. Move the store buffer into the + * hold slot, and the free buffer ino the store slot. Zero the length of the + * new store buffer. Descriptor lock should be held. + */ +#define ROTATE_BUFFERS(d) do { \ + (d)->bd_hbuf = (d)->bd_sbuf; \ + (d)->bd_hlen = (d)->bd_slen; \ + (d)->bd_sbuf = (d)->bd_fbuf; \ + (d)->bd_slen = 0; \ + (d)->bd_fbuf = NULL; \ +} while (0) + +/* * Descriptor associated with each attached hardware interface. */ struct bpf_if { ==== //depot/projects/zcopybpf/src/sys/net/bpf_zerocopy.c#7 (text+ko) ==== @@ -480,9 +480,10 @@ } /* - * Ioctl to return the next completed buffer to read, if any. Only the first - * pointer/length in the zbuf are used, since at most one buffer is in the - * hold position on the descriptor. + * Ioctl to return the next completed buffer to read, if any. In immediate + * mode, this may force a buffer rotation if there is stored data but no held + * data, in similar style to calling bpfread() on an immediate mode + * descriptor. */ int bpf_zerocopy_ioctl_getznext(struct thread *td, struct bpf_d *d, @@ -496,7 +497,14 @@ // printf("bpf_zerocopy_ioctl_getznext(td: %p, pid: %d, d: %p)\n", td, // td->td_proc->p_pid, d); + /* + * If in immediate mode, there's no holder buffer, but there is + * stored packet data, rotate so that the stored buffer is now the + * held buffer. + */ BPFD_LOCK(d); + if (d->bd_immediate && d->bd_hbuf == NULL && d->bd_slen != 0) + ROTATE_BUFFERS(d); bzero(bz, sizeof(*bz)); if (d->bd_hbuf != NULL) { zb = (struct zbuf *)d->bd_hbuf;