PERFORCE change 113762 for review
Robert Watson
rwatson at FreeBSD.org
Wed Jan 31 14:51:03 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=113762
Change 113762 by rwatson at 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;
More information about the p4-projects
mailing list