]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: stmmac: Improve Tx timer arm logic further
authorNazim Amirul <muhammad.nazim.amirul.nazle.asmade@altera.com>
Fri, 29 May 2026 06:46:59 +0000 (23:46 -0700)
committerJakub Kicinski <kuba@kernel.org>
Wed, 3 Jun 2026 02:20:48 +0000 (19:20 -0700)
Calling hrtimer_start() on an already-active txtimer is unnecessary
and expensive. Skip the restart if the timer is already active by
adding an hrtimer_active() check before hrtimer_start().

Previously, each packet reset the timer to tx_coal_timer in the future,
acting as a sliding window that delayed NAPI under burst traffic. With
this change, an already-active timer is left to fire sooner, scheduling
NAPI within tx_coal_timer of the first packet and freeing TX descriptors
earlier.

There is no race concern: hrtimer_start() is internally serialized and
safe to call on an active timer. In the event of a race between
hrtimer_active() and hrtimer_start(), the worst case is calling
hrtimer_start() on an already-active timer, which is identical to the
pre-patch behaviour.

Performance on Cyclone V with dwmac-socfpga (iperf3 -u -b 0 -l 64):
  Before: ~45200 pps
  After:  ~52300 pps (~15% improvement)

Additionally, ~10% improvement in UDP throughput observed on Agilex5,
with hrtimer CPU usage reduced from ~8% to ~0.6%.

Signed-off-by: Rohan G Thomas <rohan.g.thomas@altera.com>
Tested-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Nazim Amirul <muhammad.nazim.amirul.nazle.asmade@altera.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20260529064659.32287-1-muhammad.nazim.amirul.nazle.asmade@altera.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

index 3591755ea30be5a64fa947bc351879a1b151499f..35da51c26248448c4ff8feff70a7516959c3ad83 100644 (file)
@@ -3341,12 +3341,14 @@ static void stmmac_tx_timer_arm(struct stmmac_priv *priv, u32 queue)
         * Try to cancel any timer if napi is scheduled, timer will be armed
         * again in the next scheduled napi.
         */
-       if (unlikely(!napi_is_scheduled(napi)))
-               hrtimer_start(&tx_q->txtimer,
-                             STMMAC_COAL_TIMER(tx_coal_timer),
-                             HRTIMER_MODE_REL);
-       else
+       if (unlikely(!napi_is_scheduled(napi))) {
+               if (unlikely(!(hrtimer_active(&tx_q->txtimer))))
+                       hrtimer_start(&tx_q->txtimer,
+                                     STMMAC_COAL_TIMER(tx_coal_timer),
+                                     HRTIMER_MODE_REL);
+       } else {
                hrtimer_try_to_cancel(&tx_q->txtimer);
+       }
 }
 
 /**