git: b27c5cfc7e76 - stable/15 - e1000: Sample statistics at timer cadence

From: Kevin Bowling <kbowling_at_FreeBSD.org>
Date: Sun, 30 Aug 2026 01:37:56 UTC
The branch stable/15 has been updated by kbowling:

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

commit b27c5cfc7e7673a2d63349261f483a0f3472af4c
Author:     Kevin Bowling <kbowling@FreeBSD.org>
AuthorDate: 2026-07-29 09:11:19 +0000
Commit:     Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2026-08-30 01:36:29 +0000

    e1000: Sample statistics at timer cadence
    
    Mailbox and link interrupts share iflib admin service with the periodic
    timer. Mark timer-driven passes explicitly and run the hardware
    statistics sweep only for those samples instead of repeating 66 PF MMIO
    reads for every VF mailbox message.
    
    DTrace on the I350 DUT measured the PF sweep at about 79 us on average.
    The normal hz/2 timer continues to extend clear-on-read counters
    safely; exported counters may trail hardware by up to 500 ms.
    
    Sponsored by:   BBOX.io
    
    (cherry picked from commit d2cd0b57532ba35fe39744a60d53b90e6f13b5e4)
---
 sys/dev/e1000/if_em.c | 15 ++++++++++++++-
 sys/dev/e1000/if_em.h |  1 +
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/sys/dev/e1000/if_em.c b/sys/dev/e1000/if_em.c
index 7f1da9fb7d3f..b4ca34a0593a 100644
--- a/sys/dev/e1000/if_em.c
+++ b/sys/dev/e1000/if_em.c
@@ -1443,6 +1443,7 @@ em_if_attach_post(if_ctx_t ctx)
 		sc->ustats.stats = (struct e1000_hw_stats){};
 
 	em_update_stats_counters(sc);
+	atomic_readandclear_32(&sc->stats_pending);
 	hw->mac.get_link_status = 1;
 	em_if_update_admin_status(ctx);
 	em_add_hw_stats(sc);
@@ -2910,9 +2911,13 @@ em_if_multi_set(if_ctx_t ctx)
 static void
 em_if_timer(if_ctx_t ctx, uint16_t qid)
 {
+	struct e1000_softc *sc;
+
 	if (qid != 0)
 		return;
 
+	sc = iflib_get_softc(ctx);
+	atomic_set_32(&sc->stats_pending, 1);
 	iflib_admin_intr_deferred(ctx);
 }
 
@@ -3041,7 +3046,15 @@ em_if_update_admin_status(if_ctx_t ctx)
 		if (link_was_published)
 			iflib_link_state_change(ctx, LINK_STATE_DOWN, 0);
 	}
-	em_update_stats_counters(sc);
+	/*
+	 * Mailbox, link, and timer events share this admin task.  The PF
+	 * statistics sweep performs 66 MMIO reads, so run it only when the
+	 * ordinary iflib timer requests a sample rather than once per mailbox
+	 * message.  Exported counters can consequently trail hardware by the
+	 * timer interval (normally 500 ms).
+	 */
+	if (atomic_readandclear_32(&sc->stats_pending) != 0)
+		em_update_stats_counters(sc);
 
 	/* Reset LAA into RAR[0] on 82571 */
 	if (hw->mac.type == e1000_82571 && e1000_get_laa_state_82571(hw))
diff --git a/sys/dev/e1000/if_em.h b/sys/dev/e1000/if_em.h
index 62e783307b59..5beb3e09fcad 100644
--- a/sys/dev/e1000/if_em.h
+++ b/sys/dev/e1000/if_em.h
@@ -618,6 +618,7 @@ struct e1000_softc {
 	u32			pba;
 	int			link_mask;
 	int			tso_automasked;
+	u32			stats_pending;
 	u32			fatal_error_state;
 	u32			fatal_error_icr;
 	u32			fatal_error_pbeccsts;