Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 Jan 2021 11:38:52 GMT
From:      Lutz Donnerhacke <donner@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: ebc61c86b556 - main - netgraph/ng_source: Switch queuing framework
Message-ID:  <202101291138.10TBcqVV068939@gitrepo.freebsd.org>

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

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

commit ebc61c86b5567f2e5a3c5f452e86879b558b376b
Author:     Lutz Donnerhacke <donner@FreeBSD.org>
AuthorDate: 2021-01-29 11:03:17 +0000
Commit:     Lutz Donnerhacke <donner@FreeBSD.org>
CommitDate: 2021-01-29 11:34:53 +0000

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

diff --git a/sys/netgraph/ng_source.c b/sys/netgraph/ng_source.c
index 4bde62e5898a..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;
+	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);
@@ -568,11 +568,11 @@ ng_source_rcvdata(hook_p hook, item_p item)
 	KASSERT(hook == sc->input, ("%s: no hook!", __func__));
 
 	/* Enqueue packet if the queue isn't full. */
-	if (_IF_QFULL(&sc->snd_queue)) {
+	error = mbufq_enqueue(&sc->snd_queue, m);
+	if (error) {
 		NG_FREE_M(m);
-		return (ENOBUFS);
+		return (error);
 	}
-	_IF_ENQUEUE(&sc->snd_queue, m);
 	sc->queueOctets += m->m_pkthdr.len;
 	sc->last_packet = m;
 
@@ -671,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);
@@ -744,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;
@@ -788,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;
 
@@ -796,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?202101291138.10TBcqVV068939>