git: 812a6ee0d3cb - stable/15 - iflib: don't update the admin status in if_media_status()

From: Kevin Bowling <kbowling_at_FreeBSD.org>
Date: Thu, 29 Oct 2026 04:58:20 UTC
The branch stable/15 has been updated by kbowling:

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

commit 812a6ee0d3cb5b15af60c029a35751e405980341
Author:     Andrew Gallatin <gallatin@FreeBSD.org>
AuthorDate: 2026-08-31 21:13:47 +0000
Commit:     Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2026-10-29 04:57:24 +0000

    iflib: don't update the admin status in if_media_status()
    
    When _task_fn_admin() is active, it will regularly call
    IFDI_UPDATE_ADMIN_STATUS(). So there is no need to do it in
    iflib_media_status. This can be fairly expensive on some drivers (long
    DELAY busywait loops waiting for a NIC command), and there is no need
    to pause a userspace app in this DELAY() if it is happening
    asynchronously anyway.
    
    Note the logic to detect if _task_fn_admin() is regularly calling
    IFDI_UPDATE_ADMIN_STATUS() was copied from that function.
    
    Reviewed by: erj, kbowling
    Sponsored by: Netflix
    Differential Revision:  https://reviews.freebsd.org/D54096
    
    (cherry picked from commit ebb93ce6d86e6c6abd9d9fada21a3b107099db8f)
---
 sys/net/iflib.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/sys/net/iflib.c b/sys/net/iflib.c
index 8f1e8c30e374..c62bf10370f2 100644
--- a/sys/net/iflib.c
+++ b/sys/net/iflib.c
@@ -2602,9 +2602,23 @@ static void
 iflib_media_status(if_t ifp, struct ifmediareq *ifmr)
 {
 	if_ctx_t ctx = if_getsoftc(ifp);
+	bool oactive, running;
+
+	STATE_LOCK(ctx);
+	running = (if_getdrvflags(ctx->ifc_ifp) & IFF_DRV_RUNNING);
+	oactive = (if_getdrvflags(ctx->ifc_ifp) & IFF_DRV_OACTIVE);
+	STATE_UNLOCK(ctx);
 
 	CTX_LOCK(ctx);
-	IFDI_UPDATE_ADMIN_STATUS(ctx);
+	/*
+	 * There is no need to update the admin status when it is done regularly by
+	 * _task_fn_admin(), so only do it if that's not running. That can be quite
+	 * expensive on some drivers.
+	 */
+	if ((!running && !oactive) &&
+	    !(ctx->ifc_sctx->isc_flags & IFLIB_ADMIN_ALWAYS_RUN)) {
+		IFDI_UPDATE_ADMIN_STATUS(ctx);
+	}
 	IFDI_MEDIA_STATUS(ctx, ifmr);
 	CTX_UNLOCK(ctx);
 }