Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 12 Feb 2021 08:07:56 GMT
From:      Lutz Donnerhacke <donner@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: dd8f4fcd270d - stable/13 - netgraph/ng_source: Switch queuing framework
Message-ID:  <202102120807.11C87uRh020767@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by donner:

URL: https://cgit.FreeBSD.org/src/commit/?id=dd8f4fcd270d1b7191591d040f54dcaa78a1d609

commit dd8f4fcd270d1b7191591d040f54dcaa78a1d609
Author:     Lutz Donnerhacke <donner@FreeBSD.org>
AuthorDate: 2021-01-29 11:03:17 +0000
Commit:     Lutz Donnerhacke <donner@FreeBSD.org>
CommitDate: 2021-02-12 08:05:19 +0000

    netgraph/ng_source: Switch queuing framework
    
    Change the queuing framework from ifq to mbufq.
    
    Reported by:    glebius
    Reviewed by:    glebius, kp
    Differential Revision: https://reviews.freebsd.org/D28407
---
 sys/netgraph/ng_source.c | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/sys/netgraph/ng_source.c b/sys/netgraph/ng_source.c
index 401548da65d0..0eee9ceb25c5 100644
--- a/sys/netgraph/ng_source.c
+++ b/sys/netgraph/ng_source.c
@@ -85,7 +85,7 @@ struct privdata {
 	hook_p				input;
 	hook_p				output;
 	struct ng_source_stats		stats;
-	struct ifqueue			snd_queue;	/* packets to send */
+	struct mbufq			snd_queue;	/* packets to send */
 	struct mbuf			*last_packet;	/* last pkt in queue */
 	struct ifnet			*output_ifp;
 	struct callout			intr_ch;
@@ -284,7 +284,7 @@ ng_source_constructor(node_p node)
 
 	NG_NODE_SET_PRIVATE(node, sc);
 	sc->node = node;
-	sc->snd_queue.ifq_maxlen = 2048;	/* XXX not checked */
+	mbufq_init(&sc->snd_queue, 2048);
 	ng_callout_init(&sc->intr_ch);
 
 	return (0);
@@ -374,7 +374,7 @@ ng_source_rcvmsg(node_p node, item_p item, hook_p lasthook)
 					goto done;
 				}
 				sc->stats.queueOctets = sc->queueOctets;
-				sc->stats.queueFrames = sc->snd_queue.ifq_len;
+				sc->stats.queueFrames = mbufq_len(&sc->snd_queue);
 				if ((sc->node->nd_flags & NG_SOURCE_ACTIVE)
 				    && !timevalisset(&sc->stats.endTime)) {
 					getmicrotime(&sc->stats.elapsedTime);
@@ -567,9 +567,12 @@ ng_source_rcvdata(hook_p hook, item_p item)
 	}
 	KASSERT(hook == sc->input, ("%s: no hook!", __func__));
 
-	/* Enqueue packet. */
-	/* XXX should we check IF_QFULL() ? */
-	_IF_ENQUEUE(&sc->snd_queue, m);
+	/* Enqueue packet if the queue isn't full. */
+	error = mbufq_enqueue(&sc->snd_queue, m);
+	if (error) {
+		NG_FREE_M(m);
+		return (error);
+	}
 	sc->queueOctets += m->m_pkthdr.len;
 	sc->last_packet = m;
 
@@ -668,7 +671,7 @@ ng_source_clr_data (sc_p sc)
 	struct mbuf *m;
 
 	for (;;) {
-		_IF_DEQUEUE(&sc->snd_queue, m);
+		m =  mbufq_dequeue(&sc->snd_queue);
 		if (m == NULL)
 			break;
 		NG_FREE_M(m);
@@ -741,7 +744,7 @@ ng_source_intr(node_p node, hook_p hook, void *arg1, int arg2)
 		ifq = (struct ifqueue *)&sc->output_ifp->if_snd;
 		packets = ifq->ifq_maxlen - ifq->ifq_len;
 	} else
-		packets = sc->snd_queue.ifq_len;
+		packets = mbufq_len(&sc->snd_queue);
 
 	if (sc->stats.maxPps != 0) {
 		struct timeval	now, elapsed;
@@ -785,7 +788,7 @@ ng_source_send(sc_p sc, int tosend, int *sent_p)
 
 	/* Go through the queue sending packets one by one. */
 	for (sent = 0; error == 0 && sent < tosend; ++sent) {
-		_IF_DEQUEUE(&sc->snd_queue, m);
+		m = mbufq_dequeue(&sc->snd_queue);
 		if (m == NULL)
 			break;
 
@@ -793,14 +796,20 @@ ng_source_send(sc_p sc, int tosend, int *sent_p)
 		error = ng_source_dup_mod(sc, m, &m2);
 		if (error) {
 			if (error == ENOBUFS)
-				_IF_PREPEND(&sc->snd_queue, m);
+				mbufq_prepend(&sc->snd_queue, m);
 			else
-				_IF_ENQUEUE(&sc->snd_queue, m);
+				(void)mbufq_enqueue(&sc->snd_queue, m);
 			break;
 		}
 
-		/* Re-enqueue the original packet for us. */
-		_IF_ENQUEUE(&sc->snd_queue, m);
+		/*
+		 * Re-enqueue the original packet for us.  The queue
+		 * has a free slot, because we dequeued the packet
+		 * above and this callout function runs under WRITER
+		 * lock.
+		 */
+		error = mbufq_enqueue(&sc->snd_queue, m);
+		KASSERT(error == 0, ("%s: re-enqueue packet failed", __func__));
 
 		sc->stats.outFrames++;
 		sc->stats.outOctets += m2->m_pkthdr.len;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202102120807.11C87uRh020767>