Module Name:    src
Committed By:   yamaguchi
Date:           Thu Mar 23 01:58:04 UTC 2023

Modified Files:
        src/sys/dev/pci: if_vioif.c

Log Message:
vioif(4): divide interrupt handler for receiving
into dequeuing and preparing of buffers


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/dev/pci/if_vioif.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_vioif.c
diff -u src/sys/dev/pci/if_vioif.c:1.91 src/sys/dev/pci/if_vioif.c:1.92
--- src/sys/dev/pci/if_vioif.c:1.91	Thu Mar 23 01:52:42 2023
+++ src/sys/dev/pci/if_vioif.c	Thu Mar 23 01:58:04 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vioif.c,v 1.91 2023/03/23 01:52:42 yamaguchi Exp $	*/
+/*	$NetBSD: if_vioif.c,v 1.92 2023/03/23 01:58:04 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.91 2023/03/23 01:52:42 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.92 2023/03/23 01:58:04 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -376,7 +376,7 @@ static void	vioif_populate_rx_mbufs_lock
 		    struct vioif_rxqueue *);
 static void	vioif_rx_queue_clear(struct vioif_rxqueue *);
 static bool	vioif_rx_deq_locked(struct vioif_softc *, struct virtio_softc *,
-		    struct vioif_rxqueue *, u_int);
+		    struct vioif_rxqueue *, u_int, size_t *);
 static int	vioif_rx_intr(void *);
 static void	vioif_rx_handle(void *);
 static void	vioif_rx_sched_handle(struct vioif_softc *,
@@ -1528,9 +1528,6 @@ vioif_populate_rx_mbufs_locked(struct vi
 
 	KASSERT(mutex_owned(rxq->rxq_lock));
 
-	if (rxq->rxq_stopping)
-		return;
-
 	for (i = 0; i < vq->vq_num; i++) {
 		int slot;
 		r = virtio_enqueue_prep(vsc, vq, &slot);
@@ -1600,11 +1597,9 @@ vioif_rx_queue_clear(struct vioif_rxqueu
 	u_int limit = UINT_MAX;
 	bool more;
 
-	KASSERT(rxq->rxq_stopping);
-
 	mutex_enter(rxq->rxq_lock);
 	for (;;) {
-		more = vioif_rx_deq_locked(sc, vsc, rxq, limit);
+		more = vioif_rx_deq_locked(sc, vsc, rxq, limit, NULL);
 		if (more == false)
 			break;
 	}
@@ -1614,21 +1609,25 @@ vioif_rx_queue_clear(struct vioif_rxqueu
 /* dequeue received packets */
 static bool
 vioif_rx_deq_locked(struct vioif_softc *sc, struct virtio_softc *vsc,
-    struct vioif_rxqueue *rxq, u_int limit)
+    struct vioif_rxqueue *rxq, u_int limit, size_t *ndeqp)
 {
 	struct virtqueue *vq = rxq->rxq_vq;
 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
 	struct mbuf *m;
 	int slot, len;
-	bool more = false, dequeued = false;
+	bool more;
+	size_t ndeq;
 
 	KASSERT(mutex_owned(rxq->rxq_lock));
 
+	more = false;
+	ndeq = 0;
+
 	if (virtio_vq_is_enqueued(vsc, vq) == false)
-		return false;
+		goto done;
 
-	for (;;) {
-		if (limit-- == 0) {
+	for (;;ndeq++) {
+		if (ndeq >= limit) {
 			more = true;
 			break;
 		}
@@ -1636,8 +1635,6 @@ vioif_rx_deq_locked(struct vioif_softc *
 		if (virtio_dequeue(vsc, vq, &slot, &len) != 0)
 			break;
 
-		dequeued = true;
-
 		len -= sc->sc_hdr_size;
 		bus_dmamap_sync(virtio_dmat(vsc), rxq->rxq_hdr_dmamaps[slot],
 		    0, sc->sc_hdr_size, BUS_DMASYNC_POSTREAD);
@@ -1654,8 +1651,10 @@ vioif_rx_deq_locked(struct vioif_softc *
 		if_percpuq_enqueue(ifp->if_percpuq, m);
 	}
 
-	if (dequeued)
-		vioif_populate_rx_mbufs_locked(sc, rxq);
+
+done:
+	if (ndeqp != NULL)
+		*ndeqp = ndeq;
 
 	return more;
 }
@@ -1671,11 +1670,15 @@ vioif_rx_handle_locked(void *xrxq, u_int
 	struct vioif_softc *sc = device_private(virtio_child(vsc));
 	bool more;
 	int enqueued;
+	size_t ndeq;
 
 	KASSERT(mutex_owned(rxq->rxq_lock));
 	KASSERT(!rxq->rxq_stopping);
 
-	more = vioif_rx_deq_locked(sc, vsc, rxq, limit);
+	more = vioif_rx_deq_locked(sc, vsc, rxq, limit, &ndeq);
+	if (ndeq > 0)
+		vioif_populate_rx_mbufs_locked(sc, rxq);
+
 	if (more) {
 		vioif_rx_sched_handle(sc, rxq);
 		return;

Reply via email to