summaryrefslogtreecommitdiff
path: root/sys/net/bpf.c
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2021-01-02 07:25:43 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2021-01-02 07:25:43 +0000
commite18690509326b195997629df0771e8e405f8ed0e (patch)
tree115cb188143803d6b2a2a66e5fe8bab8e4970ce4 /sys/net/bpf.c
parentafcb8a9a1c1c5b05bac15590fb8c7327e7264d61 (diff)
optimise bpf_catchpacket and bpf_wakeup.
bpf_catchpacket had a chunk to deal with reader timeouts, but that has largely been moved to bpfread. the vestigal code that was left still tried to wake up a reader when a buffer got full, but there already is a chunk of code that wakes up readers when the buffer gets full. bpf_wakeup now checks for readers before calling wakeup directly, rather than pushing the wakeup to a task and calling it unconditionally. the task_add is now only done when the bpfdesc actually has something that needs it. ok visa@
Diffstat (limited to 'sys/net/bpf.c')
-rw-r--r--sys/net/bpf.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index fe7ca2e6a01..6c9e386ab7d 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.200 2021/01/02 02:46:06 cheloha Exp $ */
+/* $OpenBSD: bpf.c,v 1.201 2021/01/02 07:25:42 dlg Exp $ */
/* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */
/*
@@ -571,7 +571,6 @@ out:
return (error);
}
-
/*
* If there are processes sleeping on this descriptor, wake them up.
*/
@@ -580,14 +579,20 @@ bpf_wakeup(struct bpf_d *d)
{
MUTEX_ASSERT_LOCKED(&d->bd_mtx);
+ if (d->bd_nreaders)
+ wakeup(d);
+
/*
* As long as pgsigio() and selwakeup() need to be protected
* by the KERNEL_LOCK() we have to delay the wakeup to
* another context to keep the hot path KERNEL_LOCK()-free.
*/
- bpf_get(d);
- if (!task_add(systq, &d->bd_wake_task))
- bpf_put(d);
+ if ((d->bd_async && d->bd_sig) ||
+ (!klist_empty(&d->bd_sel.si_note) || d->bd_sel.si_seltid != 0)) {
+ bpf_get(d);
+ if (!task_add(systq, &d->bd_wake_task))
+ bpf_put(d);
+ }
}
void
@@ -595,7 +600,6 @@ bpf_wakeup_cb(void *xd)
{
struct bpf_d *d = xd;
- wakeup(d);
if (d->bd_async && d->bd_sig)
pgsigio(&d->bd_sigio, d->bd_sig, 0);
@@ -1553,17 +1557,6 @@ bpf_catchpacket(struct bpf_d *d, u_char *pkt, size_t pktlen, size_t snaplen,
do_wakeup = 1;
}
- if (d->bd_nreaders > 0) {
- /*
- * We have one or more threads sleeping in bpfread().
- * We got a packet, so wake up all readers.
- */
- if (d->bd_fbuf != NULL) {
- ROTATE_BUFFERS(d);
- do_wakeup = 1;
- }
- }
-
if (do_wakeup)
bpf_wakeup(d);
}