git: 8cb9af94fffc - stable/13 - iflib: emulate counters in netmap mode

Kevin Bowling kbowling at FreeBSD.org
Wed Aug 25 23:52:28 UTC 2021


The branch stable/13 has been updated by kbowling (ports committer):

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

commit 8cb9af94fffc2096d273c0e764dbcdf90774633b
Author:     Stephan de Wit <stephan.dewt at yahoo.co.uk>
AuthorDate: 2021-08-18 07:17:43 +0000
Commit:     Kevin Bowling <kbowling at FreeBSD.org>
CommitDate: 2021-08-25 23:51:42 +0000

    iflib: emulate counters in netmap mode
    
    When iflib devices are in netmap mode the driver
    counters are no longer updated making it look from
    userspace tools that traffic has stopped.
    
    Reported by:    Franco Fichtner <franco at opnsense.org>
    Reviewed by:    vmaffione, iflib (erj, gallatin)
    Obtained from:  OPNsense
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D31550
    
    (cherry picked from commit 66fa12d8fb61485780f32f0226e79d3389567496)
---
 sys/net/iflib.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/sys/net/iflib.c b/sys/net/iflib.c
index a71c48e772e5..046ee31604d3 100644
--- a/sys/net/iflib.c
+++ b/sys/net/iflib.c
@@ -988,6 +988,7 @@ iflib_netmap_txsync(struct netmap_kring *kring, int flags)
 	u_int const lim = kring->nkr_num_slots - 1;
 	u_int const head = kring->rhead;
 	struct if_pkt_info pi;
+	int tx_pkts = 0, tx_bytes = 0;
 
 	/*
 	 * interrupts on every tx packet are expensive so request
@@ -1071,6 +1072,10 @@ iflib_netmap_txsync(struct netmap_kring *kring, int flags)
 				ctx->isc_txd_encap(ctx->ifc_softc, &pi);
 				DBG_COUNTER_INC(tx_encap);
 
+				/* Update transmit counters */
+				tx_bytes += pi.ipi_len;
+				tx_pkts++;
+
 				/* Reinit per-packet info for the next one. */
 				flags = seg_idx = pkt_len = 0;
 				nic_i_start = -1;
@@ -1129,6 +1134,10 @@ iflib_netmap_txsync(struct netmap_kring *kring, int flags)
 			    iflib_netmap_timer, txq,
 			    txq->ift_netmap_timer.c_cpu, 0);
 		}
+
+	if_inc_counter(ifp, IFCOUNTER_OBYTES, tx_bytes);
+	if_inc_counter(ifp, IFCOUNTER_OPACKETS, tx_pkts);
+
 	return (0);
 }
 
@@ -1156,7 +1165,7 @@ iflib_netmap_rxsync(struct netmap_kring *kring, int flags)
 	u_int n;
 	u_int const lim = kring->nkr_num_slots - 1;
 	int force_update = (flags & NAF_FORCE_READ) || kring->nr_kflags & NKR_PENDINTR;
-	int i = 0;
+	int i = 0, rx_bytes = 0, rx_pkts = 0;
 
 	if_ctx_t ctx = ifp->if_softc;
 	if_shared_ctx_t sctx = ctx->ifc_sctx;
@@ -1227,6 +1236,10 @@ iflib_netmap_rxsync(struct netmap_kring *kring, int flags)
 					if (i == (ri.iri_nfrags - 1)) {
 						ring->slot[nm_i].len -= crclen;
 						ring->slot[nm_i].flags = 0;
+
+						/* Update receive counters */
+						rx_bytes += ri.iri_len;
+						rx_pkts++;
 					} else
 						ring->slot[nm_i].flags = NS_MOREFRAG;
 				}
@@ -1264,6 +1277,9 @@ iflib_netmap_rxsync(struct netmap_kring *kring, int flags)
 	 */
 	netmap_fl_refill(rxq, kring, false);
 
+	if_inc_counter(ifp, IFCOUNTER_IBYTES, rx_bytes);
+	if_inc_counter(ifp, IFCOUNTER_IPACKETS, rx_pkts);
+
 	return (0);
 }
 


More information about the dev-commits-src-all mailing list