PERFORCE change 131531 for review
Robert Watson
rwatson at FreeBSD.org
Mon Dec 24 09:59:38 PST 2007
http://perforce.freebsd.org/chv.cgi?CH=131531
Change 131531 by rwatson at rwatson_cinnamon on 2007/12/24 17:58:48
First cut at improving behavior of zero-copy BPF buffers on
systems with weaker memory ordering with i386. In certain
cases, it will also help consistency on i386.
Suggested by: jhb
Affected files ...
.. //depot/projects/zcopybpf/src/contrib/libpcap/pcap-bpf.c#15 edit
.. //depot/projects/zcopybpf/src/sys/net/bpf_zerocopy.c#25 edit
Differences ...
==== //depot/projects/zcopybpf/src/contrib/libpcap/pcap-bpf.c#15 (text+ko) ====
@@ -39,6 +39,10 @@
#include <sys/ioctl.h>
#include <sys/utsname.h>
+#ifdef BIOCGETBUFMODE
+#include <machine/atomic.h>
+#endif
+
#include <net/if.h>
#ifdef _AIX
@@ -160,7 +164,8 @@
*/
if (p->zbuffer == p->zbuf2 || p->zbuffer == NULL) {
bzh = (struct bpf_zbuf_header *)p->zbuf1;
- if (bzh->bzh_kernel_gen != bzh->bzh_user_gen) {
+ if (bzh->bzh_user_gen !=
+ atomic_load_acq_int(&bzh->bzh_kernel_gen)) {
p->bzh = bzh;
p->zbuffer = (u_char *)p->zbuf1;
p->buffer = p->zbuffer + sizeof(*bzh);
@@ -169,7 +174,8 @@
}
} else if (p->zbuffer == p->zbuf1) {
bzh = (struct bpf_zbuf_header *)p->zbuf2;
- if (bzh->bzh_kernel_gen != bzh->bzh_user_gen) {
+ if (bzh->bzh_user_gen !=
+ atomic_load_acq_int(&bzh->bzh_kernel_gen)) {
p->bzh = bzh;
p->zbuffer = (u_char *)p->zbuf2;
p->buffer = p->zbuffer + sizeof(*bzh);
@@ -249,9 +255,8 @@
static int
pcap_ack_zbuf(pcap_t *p)
{
- struct bpf_zbuf bz;
- p->bzh->bzh_user_gen = p->bzh->bzh_kernel_gen;
+ atomic_store_rel_int(&p->bzh->bzh_user_gen, p->bzh->bzh_kernel_gen);
p->bzh = NULL;
p->buffer = NULL;
return (0);
==== //depot/projects/zcopybpf/src/sys/net/bpf_zerocopy.c#25 (text+ko) ====
@@ -42,6 +42,8 @@
#include <sys/socket.h>
#include <sys/uio.h>
+#include <machine/atomic.h>
+
#include <net/if.h>
#include <net/bpf.h>
#include <net/bpfdesc.h>
@@ -354,7 +356,7 @@
zb = (struct zbuf *)d->bd_hbuf;
KASSERT(zb != NULL, ("bpf_zerocopy_bufheld: zb == NULL"));
zb->zb_header->bzh_kernel_len = d->bd_hlen;
- zb->zb_header->bzh_kernel_gen++;
+ atomic_add_rel_int(&zb->zb_header->bzh_kernel_gen, 1);
}
/*
@@ -376,7 +378,8 @@
zb = (struct zbuf *)d->bd_hbuf;
if (zb == NULL)
return (0);
- if (zb->zb_header->bzh_kernel_gen == zb->zb_header->bzh_user_gen)
+ if (zb->zb_header->bzh_kernel_gen ==
+ atomic_load_acq_int(&zb->zb_header->bzh_user_gen))
return (1);
return (0);
}
More information about the p4-projects
mailing list