Home | History | Annotate | Line # | Download | only in net
pktqueue.c revision 1.12
      1  1.12  riastrad /*	$NetBSD: pktqueue.c,v 1.12 2020/09/11 14:29:00 riastradh Exp $	*/
      2   1.1     rmind 
      3   1.1     rmind /*-
      4   1.1     rmind  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5   1.1     rmind  * All rights reserved.
      6   1.1     rmind  *
      7   1.1     rmind  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1     rmind  * by Mindaugas Rasiukevicius.
      9   1.1     rmind  *
     10   1.1     rmind  * Redistribution and use in source and binary forms, with or without
     11   1.1     rmind  * modification, are permitted provided that the following conditions
     12   1.1     rmind  * are met:
     13   1.1     rmind  * 1. Redistributions of source code must retain the above copyright
     14   1.1     rmind  *    notice, this list of conditions and the following disclaimer.
     15   1.1     rmind  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1     rmind  *    notice, this list of conditions and the following disclaimer in the
     17   1.1     rmind  *    documentation and/or other materials provided with the distribution.
     18   1.1     rmind  *
     19   1.1     rmind  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1     rmind  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1     rmind  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1     rmind  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1     rmind  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1     rmind  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1     rmind  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1     rmind  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1     rmind  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1     rmind  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1     rmind  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1     rmind  */
     31   1.1     rmind 
     32   1.4     rmind /*
     33   1.4     rmind  * The packet queue (pktqueue) interface is a lockless IP input queue
     34   1.4     rmind  * which also abstracts and handles network ISR scheduling.  It provides
     35   1.4     rmind  * a mechanism to enable receiver-side packet steering (RPS).
     36   1.4     rmind  */
     37   1.4     rmind 
     38   1.1     rmind #include <sys/cdefs.h>
     39  1.12  riastrad __KERNEL_RCSID(0, "$NetBSD: pktqueue.c,v 1.12 2020/09/11 14:29:00 riastradh Exp $");
     40   1.1     rmind 
     41   1.1     rmind #include <sys/param.h>
     42   1.1     rmind #include <sys/types.h>
     43   1.1     rmind 
     44   1.1     rmind #include <sys/atomic.h>
     45   1.1     rmind #include <sys/cpu.h>
     46   1.1     rmind #include <sys/pcq.h>
     47   1.1     rmind #include <sys/intr.h>
     48   1.1     rmind #include <sys/mbuf.h>
     49   1.1     rmind #include <sys/proc.h>
     50   1.1     rmind #include <sys/percpu.h>
     51  1.11   thorpej #include <sys/xcall.h>
     52   1.1     rmind 
     53   1.1     rmind #include <net/pktqueue.h>
     54   1.1     rmind 
     55   1.1     rmind /*
     56   1.1     rmind  * WARNING: update this if struct pktqueue changes.
     57   1.1     rmind  */
     58   1.1     rmind #define	PKTQ_CLPAD	\
     59   1.1     rmind     MAX(COHERENCY_UNIT, COHERENCY_UNIT - sizeof(kmutex_t) - sizeof(u_int))
     60   1.1     rmind 
     61   1.1     rmind struct pktqueue {
     62   1.1     rmind 	/*
     63   1.1     rmind 	 * The lock used for a barrier mechanism.  The barrier counter,
     64   1.1     rmind 	 * as well as the drop counter, are managed atomically though.
     65   1.1     rmind 	 * Ensure this group is in a separate cache line.
     66   1.1     rmind 	 */
     67   1.1     rmind 	kmutex_t	pq_lock;
     68   1.1     rmind 	volatile u_int	pq_barrier;
     69   1.1     rmind 	uint8_t		_pad[PKTQ_CLPAD];
     70   1.1     rmind 
     71   1.1     rmind 	/* The size of the queue, counters and the interrupt handler. */
     72   1.1     rmind 	u_int		pq_maxlen;
     73   1.1     rmind 	percpu_t *	pq_counters;
     74   1.1     rmind 	void *		pq_sih;
     75   1.1     rmind 
     76   1.1     rmind 	/* Finally, per-CPU queues. */
     77  1.12  riastrad 	struct percpu *	pq_pcq;	/* struct pcq * */
     78   1.1     rmind };
     79   1.1     rmind 
     80   1.1     rmind /* The counters of the packet queue. */
     81   1.1     rmind #define	PQCNT_ENQUEUE	0
     82   1.1     rmind #define	PQCNT_DEQUEUE	1
     83   1.1     rmind #define	PQCNT_DROP	2
     84   1.1     rmind #define	PQCNT_NCOUNTERS	3
     85   1.1     rmind 
     86   1.1     rmind typedef struct {
     87   1.1     rmind 	uint64_t	count[PQCNT_NCOUNTERS];
     88   1.1     rmind } pktq_counters_t;
     89   1.1     rmind 
     90   1.1     rmind /* Special marker value used by pktq_barrier() mechanism. */
     91   1.1     rmind #define	PKTQ_MARKER	((void *)(~0ULL))
     92   1.1     rmind 
     93  1.12  riastrad static void
     94  1.12  riastrad pktq_init_cpu(void *vqp, void *vpq, struct cpu_info *ci)
     95  1.12  riastrad {
     96  1.12  riastrad 	struct pcq **qp = vqp;
     97  1.12  riastrad 	struct pktqueue *pq = vpq;
     98  1.12  riastrad 
     99  1.12  riastrad 	*qp = pcq_create(pq->pq_maxlen, KM_SLEEP);
    100  1.12  riastrad }
    101  1.12  riastrad 
    102  1.12  riastrad static void
    103  1.12  riastrad pktq_fini_cpu(void *vqp, void *vpq, struct cpu_info *ci)
    104  1.12  riastrad {
    105  1.12  riastrad 	struct pcq **qp = vqp, *q = *qp;
    106  1.12  riastrad 
    107  1.12  riastrad 	KASSERT(pcq_peek(q) == NULL);
    108  1.12  riastrad 	pcq_destroy(q);
    109  1.12  riastrad 	*qp = NULL;		/* paranoia */
    110  1.12  riastrad }
    111  1.12  riastrad 
    112  1.12  riastrad static struct pcq *
    113  1.12  riastrad pktq_pcq(struct pktqueue *pq, struct cpu_info *ci)
    114  1.12  riastrad {
    115  1.12  riastrad 	struct pcq **qp, *q;
    116  1.12  riastrad 
    117  1.12  riastrad 	/*
    118  1.12  riastrad 	 * As long as preemption is disabled, the xcall to swap percpu
    119  1.12  riastrad 	 * buffers can't complete, so it is safe to read the pointer.
    120  1.12  riastrad 	 */
    121  1.12  riastrad 	KASSERT(kpreempt_disabled());
    122  1.12  riastrad 
    123  1.12  riastrad 	qp = percpu_getptr_remote(pq->pq_pcq, ci);
    124  1.12  riastrad 	q = *qp;
    125  1.12  riastrad 
    126  1.12  riastrad 	return q;
    127  1.12  riastrad }
    128   1.1     rmind 
    129   1.1     rmind pktqueue_t *
    130   1.5     ozaki pktq_create(size_t maxlen, void (*intrh)(void *), void *sc)
    131   1.1     rmind {
    132   1.1     rmind 	const u_int sflags = SOFTINT_NET | SOFTINT_MPSAFE | SOFTINT_RCPU;
    133   1.1     rmind 	pktqueue_t *pq;
    134   1.1     rmind 	percpu_t *pc;
    135   1.1     rmind 	void *sih;
    136   1.1     rmind 
    137   1.9       chs 	pc = percpu_alloc(sizeof(pktq_counters_t));
    138   1.5     ozaki 	if ((sih = softint_establish(sflags, intrh, sc)) == NULL) {
    139   1.1     rmind 		percpu_free(pc, sizeof(pktq_counters_t));
    140   1.1     rmind 		return NULL;
    141   1.1     rmind 	}
    142   1.1     rmind 
    143  1.12  riastrad 	pq = kmem_zalloc(sizeof(*pq), KM_SLEEP);
    144   1.1     rmind 	mutex_init(&pq->pq_lock, MUTEX_DEFAULT, IPL_NONE);
    145   1.1     rmind 	pq->pq_maxlen = maxlen;
    146   1.1     rmind 	pq->pq_counters = pc;
    147   1.1     rmind 	pq->pq_sih = sih;
    148  1.12  riastrad 	pq->pq_pcq = percpu_create(sizeof(struct pcq *),
    149  1.12  riastrad 	    pktq_init_cpu, pktq_fini_cpu, pq);
    150   1.1     rmind 
    151   1.1     rmind 	return pq;
    152   1.1     rmind }
    153   1.1     rmind 
    154   1.1     rmind void
    155   1.1     rmind pktq_destroy(pktqueue_t *pq)
    156   1.1     rmind {
    157   1.1     rmind 
    158  1.12  riastrad 	percpu_free(pq->pq_pcq, sizeof(struct pcq *));
    159   1.1     rmind 	percpu_free(pq->pq_counters, sizeof(pktq_counters_t));
    160   1.1     rmind 	softint_disestablish(pq->pq_sih);
    161   1.1     rmind 	mutex_destroy(&pq->pq_lock);
    162  1.12  riastrad 	kmem_free(pq, sizeof(*pq));
    163   1.1     rmind }
    164   1.1     rmind 
    165   1.1     rmind /*
    166   1.1     rmind  * - pktq_inc_counter: increment the counter given an ID.
    167   1.1     rmind  * - pktq_collect_counts: handler to sum up the counts from each CPU.
    168   1.1     rmind  * - pktq_getcount: return the effective count given an ID.
    169   1.1     rmind  */
    170   1.1     rmind 
    171   1.1     rmind static inline void
    172   1.1     rmind pktq_inc_count(pktqueue_t *pq, u_int i)
    173   1.1     rmind {
    174   1.1     rmind 	percpu_t *pc = pq->pq_counters;
    175   1.1     rmind 	pktq_counters_t *c;
    176   1.1     rmind 
    177   1.1     rmind 	c = percpu_getref(pc);
    178   1.1     rmind 	c->count[i]++;
    179   1.1     rmind 	percpu_putref(pc);
    180   1.1     rmind }
    181   1.1     rmind 
    182   1.1     rmind static void
    183   1.1     rmind pktq_collect_counts(void *mem, void *arg, struct cpu_info *ci)
    184   1.1     rmind {
    185   1.1     rmind 	const pktq_counters_t *c = mem;
    186   1.1     rmind 	pktq_counters_t *sum = arg;
    187   1.1     rmind 
    188  1.11   thorpej 	int s = splnet();
    189  1.11   thorpej 
    190   1.1     rmind 	for (u_int i = 0; i < PQCNT_NCOUNTERS; i++) {
    191   1.1     rmind 		sum->count[i] += c->count[i];
    192   1.1     rmind 	}
    193  1.11   thorpej 
    194  1.11   thorpej 	splx(s);
    195   1.1     rmind }
    196   1.1     rmind 
    197   1.1     rmind uint64_t
    198   1.1     rmind pktq_get_count(pktqueue_t *pq, pktq_count_t c)
    199   1.1     rmind {
    200   1.1     rmind 	pktq_counters_t sum;
    201   1.1     rmind 
    202   1.1     rmind 	if (c != PKTQ_MAXLEN) {
    203   1.1     rmind 		memset(&sum, 0, sizeof(sum));
    204  1.11   thorpej 		percpu_foreach_xcall(pq->pq_counters,
    205  1.11   thorpej 		    XC_HIGHPRI_IPL(IPL_SOFTNET), pktq_collect_counts, &sum);
    206   1.1     rmind 	}
    207   1.1     rmind 	switch (c) {
    208   1.1     rmind 	case PKTQ_NITEMS:
    209   1.1     rmind 		return sum.count[PQCNT_ENQUEUE] - sum.count[PQCNT_DEQUEUE];
    210   1.1     rmind 	case PKTQ_DROPS:
    211   1.1     rmind 		return sum.count[PQCNT_DROP];
    212   1.1     rmind 	case PKTQ_MAXLEN:
    213   1.1     rmind 		return pq->pq_maxlen;
    214   1.1     rmind 	}
    215   1.1     rmind 	return 0;
    216   1.1     rmind }
    217   1.1     rmind 
    218   1.1     rmind uint32_t
    219   1.1     rmind pktq_rps_hash(const struct mbuf *m __unused)
    220   1.1     rmind {
    221   1.1     rmind 	/*
    222   1.1     rmind 	 * XXX: No distribution yet; the softnet_lock contention
    223   1.1     rmind 	 * XXX: must be eliminated first.
    224   1.1     rmind 	 */
    225   1.1     rmind 	return 0;
    226   1.1     rmind }
    227   1.1     rmind 
    228   1.1     rmind /*
    229   1.1     rmind  * pktq_enqueue: inject the packet into the end of the queue.
    230   1.1     rmind  *
    231   1.1     rmind  * => Must be called from the interrupt or with the preemption disabled.
    232   1.1     rmind  * => Consumes the packet and returns true on success.
    233   1.1     rmind  * => Returns false on failure; caller is responsible to free the packet.
    234   1.1     rmind  */
    235   1.1     rmind bool
    236   1.3     rmind pktq_enqueue(pktqueue_t *pq, struct mbuf *m, const u_int hash __unused)
    237   1.1     rmind {
    238   1.8     ozaki #if defined(_RUMPKERNEL) || defined(_RUMP_NATIVE_ABI)
    239  1.12  riastrad 	struct cpu_info *ci = curcpu();
    240   1.7     ozaki #else
    241  1.12  riastrad 	struct cpu_info *ci = cpu_lookup(hash % ncpu);
    242   1.7     ozaki #endif
    243   1.1     rmind 
    244   1.1     rmind 	KASSERT(kpreempt_disabled());
    245   1.1     rmind 
    246  1.12  riastrad 	if (__predict_false(!pcq_put(pktq_pcq(pq, ci), m))) {
    247   1.1     rmind 		pktq_inc_count(pq, PQCNT_DROP);
    248   1.1     rmind 		return false;
    249   1.1     rmind 	}
    250  1.12  riastrad 	softint_schedule_cpu(pq->pq_sih, ci);
    251   1.1     rmind 	pktq_inc_count(pq, PQCNT_ENQUEUE);
    252   1.1     rmind 	return true;
    253   1.1     rmind }
    254   1.1     rmind 
    255   1.1     rmind /*
    256   1.1     rmind  * pktq_dequeue: take a packet from the queue.
    257   1.1     rmind  *
    258   1.1     rmind  * => Must be called with preemption disabled.
    259   1.1     rmind  * => Must ensure there are not concurrent dequeue calls.
    260   1.1     rmind  */
    261   1.1     rmind struct mbuf *
    262   1.1     rmind pktq_dequeue(pktqueue_t *pq)
    263   1.1     rmind {
    264  1.12  riastrad 	struct cpu_info *ci = curcpu();
    265   1.1     rmind 	struct mbuf *m;
    266   1.1     rmind 
    267  1.12  riastrad 	KASSERT(kpreempt_disabled());
    268  1.12  riastrad 
    269  1.12  riastrad 	m = pcq_get(pktq_pcq(pq, ci));
    270   1.1     rmind 	if (__predict_false(m == PKTQ_MARKER)) {
    271   1.1     rmind 		/* Note the marker entry. */
    272   1.1     rmind 		atomic_inc_uint(&pq->pq_barrier);
    273   1.1     rmind 		return NULL;
    274   1.1     rmind 	}
    275   1.1     rmind 	if (__predict_true(m != NULL)) {
    276   1.1     rmind 		pktq_inc_count(pq, PQCNT_DEQUEUE);
    277   1.1     rmind 	}
    278   1.1     rmind 	return m;
    279   1.1     rmind }
    280   1.1     rmind 
    281   1.1     rmind /*
    282   1.1     rmind  * pktq_barrier: waits for a grace period when all packets enqueued at
    283   1.1     rmind  * the moment of calling this routine will be processed.  This is used
    284   1.1     rmind  * to ensure that e.g. packets referencing some interface were drained.
    285   1.1     rmind  */
    286   1.1     rmind void
    287   1.1     rmind pktq_barrier(pktqueue_t *pq)
    288   1.1     rmind {
    289  1.12  riastrad 	CPU_INFO_ITERATOR cii;
    290  1.12  riastrad 	struct cpu_info *ci;
    291   1.1     rmind 	u_int pending = 0;
    292   1.1     rmind 
    293   1.1     rmind 	mutex_enter(&pq->pq_lock);
    294   1.1     rmind 	KASSERT(pq->pq_barrier == 0);
    295   1.1     rmind 
    296  1.12  riastrad 	for (CPU_INFO_FOREACH(cii, ci)) {
    297  1.12  riastrad 		struct pcq *q;
    298  1.12  riastrad 
    299  1.12  riastrad 		kpreempt_disable();
    300  1.12  riastrad 		q = pktq_pcq(pq, ci);
    301  1.12  riastrad 		kpreempt_enable();
    302   1.1     rmind 
    303   1.1     rmind 		/* If the queue is empty - nothing to do. */
    304   1.1     rmind 		if (pcq_peek(q) == NULL) {
    305   1.1     rmind 			continue;
    306   1.1     rmind 		}
    307   1.1     rmind 		/* Otherwise, put the marker and entry. */
    308   1.1     rmind 		while (!pcq_put(q, PKTQ_MARKER)) {
    309   1.1     rmind 			kpause("pktqsync", false, 1, NULL);
    310   1.1     rmind 		}
    311   1.1     rmind 		kpreempt_disable();
    312  1.12  riastrad 		softint_schedule_cpu(pq->pq_sih, ci);
    313   1.1     rmind 		kpreempt_enable();
    314   1.1     rmind 		pending++;
    315   1.1     rmind 	}
    316   1.1     rmind 
    317   1.1     rmind 	/* Wait for each queue to process the markers. */
    318   1.1     rmind 	while (pq->pq_barrier != pending) {
    319   1.1     rmind 		kpause("pktqsync", false, 1, NULL);
    320   1.1     rmind 	}
    321   1.1     rmind 	pq->pq_barrier = 0;
    322   1.1     rmind 	mutex_exit(&pq->pq_lock);
    323   1.1     rmind }
    324   1.1     rmind 
    325   1.1     rmind /*
    326   1.1     rmind  * pktq_flush: free mbufs in all queues.
    327   1.1     rmind  *
    328   1.4     rmind  * => The caller must ensure there are no concurrent writers or flush calls.
    329   1.1     rmind  */
    330   1.1     rmind void
    331   1.1     rmind pktq_flush(pktqueue_t *pq)
    332   1.1     rmind {
    333  1.12  riastrad 	CPU_INFO_ITERATOR cii;
    334  1.12  riastrad 	struct cpu_info *ci;
    335   1.1     rmind 	struct mbuf *m;
    336   1.1     rmind 
    337  1.12  riastrad 	for (CPU_INFO_FOREACH(cii, ci)) {
    338  1.12  riastrad 		struct pcq *q;
    339  1.12  riastrad 
    340  1.12  riastrad 		kpreempt_disable();
    341  1.12  riastrad 		q = pktq_pcq(pq, ci);
    342  1.12  riastrad 		kpreempt_enable();
    343  1.12  riastrad 
    344  1.12  riastrad 		/*
    345  1.12  riastrad 		 * XXX This can't be right -- if the softint is running
    346  1.12  riastrad 		 * then pcq_get isn't safe here.
    347  1.12  riastrad 		 */
    348  1.12  riastrad 		while ((m = pcq_get(q)) != NULL) {
    349   1.1     rmind 			pktq_inc_count(pq, PQCNT_DEQUEUE);
    350   1.1     rmind 			m_freem(m);
    351   1.1     rmind 		}
    352   1.1     rmind 	}
    353   1.1     rmind }
    354   1.2     rmind 
    355  1.12  riastrad static void
    356  1.12  riastrad pktq_set_maxlen_cpu(void *vpq, void *vqs)
    357  1.12  riastrad {
    358  1.12  riastrad 	struct pktqueue *pq = vpq;
    359  1.12  riastrad 	struct pcq **qp, *q, **qs = vqs;
    360  1.12  riastrad 	unsigned i = cpu_index(curcpu());
    361  1.12  riastrad 	int s;
    362  1.12  riastrad 
    363  1.12  riastrad 	s = splnet();
    364  1.12  riastrad 	qp = percpu_getref(pq->pq_pcq);
    365  1.12  riastrad 	q = *qp;
    366  1.12  riastrad 	*qp = qs[i];
    367  1.12  riastrad 	qs[i] = q;
    368  1.12  riastrad 	percpu_putref(pq->pq_pcq);
    369  1.12  riastrad 	splx(s);
    370  1.12  riastrad }
    371  1.12  riastrad 
    372   1.2     rmind /*
    373   1.2     rmind  * pktq_set_maxlen: create per-CPU queues using a new size and replace
    374   1.2     rmind  * the existing queues without losing any packets.
    375  1.12  riastrad  *
    376  1.12  riastrad  * XXX ncpu must remain stable throughout.
    377   1.2     rmind  */
    378   1.2     rmind int
    379   1.2     rmind pktq_set_maxlen(pktqueue_t *pq, size_t maxlen)
    380   1.2     rmind {
    381   1.2     rmind 	const u_int slotbytes = ncpu * sizeof(pcq_t *);
    382   1.2     rmind 	pcq_t **qs;
    383   1.2     rmind 
    384   1.2     rmind 	if (!maxlen || maxlen > PCQ_MAXLEN)
    385   1.2     rmind 		return EINVAL;
    386   1.2     rmind 	if (pq->pq_maxlen == maxlen)
    387   1.2     rmind 		return 0;
    388   1.2     rmind 
    389  1.12  riastrad 	/* First, allocate the new queues. */
    390   1.2     rmind 	qs = kmem_zalloc(slotbytes, KM_SLEEP);
    391   1.2     rmind 	for (u_int i = 0; i < ncpu; i++) {
    392   1.2     rmind 		qs[i] = pcq_create(maxlen, KM_SLEEP);
    393   1.2     rmind 	}
    394  1.12  riastrad 
    395  1.12  riastrad 	/*
    396  1.12  riastrad 	 * Issue an xcall to replace the queue pointers on each CPU.
    397  1.12  riastrad 	 * This implies all the necessary memory barriers.
    398  1.12  riastrad 	 */
    399   1.2     rmind 	mutex_enter(&pq->pq_lock);
    400  1.12  riastrad 	xc_wait(xc_broadcast(XC_HIGHPRI, pktq_set_maxlen_cpu, pq, qs));
    401   1.2     rmind 	pq->pq_maxlen = maxlen;
    402   1.2     rmind 	mutex_exit(&pq->pq_lock);
    403   1.2     rmind 
    404   1.2     rmind 	/*
    405   1.2     rmind 	 * At this point, the new packets are flowing into the new
    406   1.4     rmind 	 * queues.  However, the old queues may have some packets
    407   1.4     rmind 	 * present which are no longer being processed.  We are going
    408   1.2     rmind 	 * to re-enqueue them.  This may change the order of packet
    409   1.2     rmind 	 * arrival, but it is not considered an issue.
    410   1.2     rmind 	 *
    411   1.4     rmind 	 * There may be in-flight interrupts calling pktq_dequeue()
    412   1.2     rmind 	 * which reference the old queues.  Issue a barrier to ensure
    413   1.2     rmind 	 * that we are going to be the only pcq_get() callers on the
    414   1.2     rmind 	 * old queues.
    415   1.2     rmind 	 */
    416   1.2     rmind 	pktq_barrier(pq);
    417   1.2     rmind 
    418   1.2     rmind 	for (u_int i = 0; i < ncpu; i++) {
    419  1.12  riastrad 		struct pcq *q;
    420   1.2     rmind 		struct mbuf *m;
    421   1.2     rmind 
    422  1.12  riastrad 		kpreempt_disable();
    423  1.12  riastrad 		q = pktq_pcq(pq, cpu_lookup(i));
    424  1.12  riastrad 		kpreempt_enable();
    425  1.12  riastrad 
    426   1.2     rmind 		while ((m = pcq_get(qs[i])) != NULL) {
    427  1.12  riastrad 			while (!pcq_put(q, m)) {
    428   1.2     rmind 				kpause("pktqrenq", false, 1, NULL);
    429   1.2     rmind 			}
    430   1.2     rmind 		}
    431   1.2     rmind 		pcq_destroy(qs[i]);
    432   1.2     rmind 	}
    433   1.2     rmind 
    434   1.2     rmind 	/* Well, that was fun. */
    435   1.2     rmind 	kmem_free(qs, slotbytes);
    436   1.2     rmind 	return 0;
    437   1.2     rmind }
    438   1.6     ozaki 
    439   1.6     ozaki int
    440   1.6     ozaki sysctl_pktq_maxlen(SYSCTLFN_ARGS, pktqueue_t *pq)
    441   1.6     ozaki {
    442   1.6     ozaki 	u_int nmaxlen = pktq_get_count(pq, PKTQ_MAXLEN);
    443   1.6     ozaki 	struct sysctlnode node = *rnode;
    444   1.6     ozaki 	int error;
    445   1.6     ozaki 
    446   1.6     ozaki 	node.sysctl_data = &nmaxlen;
    447   1.6     ozaki 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    448   1.6     ozaki 	if (error || newp == NULL)
    449   1.6     ozaki 		return error;
    450   1.6     ozaki 	return pktq_set_maxlen(pq, nmaxlen);
    451   1.6     ozaki }
    452   1.6     ozaki 
    453   1.6     ozaki int
    454   1.6     ozaki sysctl_pktq_count(SYSCTLFN_ARGS, pktqueue_t *pq, u_int count_id)
    455   1.6     ozaki {
    456  1.10   msaitoh 	uint64_t count = pktq_get_count(pq, count_id);
    457   1.6     ozaki 	struct sysctlnode node = *rnode;
    458  1.10   msaitoh 
    459   1.6     ozaki 	node.sysctl_data = &count;
    460   1.6     ozaki 	return sysctl_lookup(SYSCTLFN_CALL(&node));
    461   1.6     ozaki }
    462