diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2015-11-20 03:35:24 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2015-11-20 03:35:24 +0000 |
commit | 93d7f55b038092ded0514b3f745fd014c1845492 (patch) | |
tree | da8fbd80cf246b5a4ebcdf952d9bb7b92cbe5e19 /sys/dev/pci/if_nge.c | |
parent | d3a33e8102f3bbde40bab36e7fc5067836baf064 (diff) |
shuffle struct ifqueue so in flight mbufs are protected by a mutex.
the code is refactored so the IFQ macros call newly implemented ifq
functions. the ifq code is split so each discipline (priq and hfsc
in our case) is an opaque set of operations that the common ifq
code can call. the common code does the locking, accounting (ifq_len
manipulation), and freeing of the mbuf if the disciplines enqueue
function rejects it. theyre kind of like bufqs in the block layer
with their fifo and nscan disciplines.
the new api also supports atomic switching of disciplines at runtime.
the hfsc setup in pf_ioctl.c has been tweaked to build a complete
hfsc_if structure which it attaches to the send queue in a single
operation, rather than attaching to the interface up front and
building up a list of queues.
the send queue is now mutexed, which raises the expectation that
packets can be enqueued or purged on one cpu while another cpu is
dequeueing them in a driver for transmission. a lot of drivers use
IFQ_POLL to peek at an mbuf and attempt to fit it on the ring before
committing to it with a later IFQ_DEQUEUE operation. if the mbuf
gets freed in between the POLL and DEQUEUE operations, fireworks
will ensue.
to avoid this, the ifq api introduces ifq_deq_begin, ifq_deq_rollback,
and ifq_deq_commit. ifq_deq_begin allows a driver to take the ifq
mutex and get a reference to the mbuf they wish to try and tx. if
there's space, they can ifq_deq_commit it to remove the mbuf and
release the mutex. if there's no space, ifq_deq_rollback simply
releases the mutex. this api was developed to make updating the
drivers using IFQ_POLL easy, instead of having to do significant
semantic changes to avoid POLL that we cannot test on all the
hardware.
the common code has been tested pretty hard, and all the driver
modifications are straightforward except for de(4). if that breaks
it can be dealt with later.
ok mpi@ jmatthew@
Diffstat (limited to 'sys/dev/pci/if_nge.c')
-rw-r--r-- | sys/dev/pci/if_nge.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/sys/dev/pci/if_nge.c b/sys/dev/pci/if_nge.c index d573d5955df..f1c89ec918e 100644 --- a/sys/dev/pci/if_nge.c +++ b/sys/dev/pci/if_nge.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_nge.c,v 1.87 2015/11/14 17:54:57 mpi Exp $ */ +/* $OpenBSD: if_nge.c,v 1.88 2015/11/20 03:35:23 dlg Exp $ */ /* * Copyright (c) 2001 Wind River Systems * Copyright (c) 1997, 1998, 1999, 2000, 2001 @@ -1408,17 +1408,18 @@ nge_start(struct ifnet *ifp) return; while(sc->nge_ldata->nge_tx_list[idx].nge_mbuf == NULL) { - IFQ_POLL(&ifp->if_snd, m_head); + m_head = ifq_deq_begin(&ifp->if_snd); if (m_head == NULL) break; if (nge_encap(sc, m_head, &idx)) { + ifq_deq_rollback(&ifp->if_snd, m_head); ifp->if_flags |= IFF_OACTIVE; break; } /* now we are committed to transmit the packet */ - IFQ_DEQUEUE(&ifp->if_snd, m_head); + ifq_deq_commit(&ifp->if_snd, m_head); pkts++; #if NBPFILTER > 0 |