Re: [PATCH v3] net: stmmac: Improve Tx timer arm logic further

From: Andrew Lunn

Date: Tue Jun 02 2026 - 08:54:25 EST


On Thu, May 28, 2026 at 11:46:59PM -0700, muhammad.nazim.amirul.nazle.asmade@xxxxxxxxxx wrote:
> From: Nazim Amirul <muhammad.nazim.amirul.nazle.asmade@xxxxxxxxxx>
>
> 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@xxxxxxxxxx>
> Tested-by: Maxime Chevallier <maxime.chevallier@xxxxxxxxxxx>
> Reviewed-by: Maxime Chevallier <maxime.chevallier@xxxxxxxxxxx>
> Reviewed-by: Jacob Keller <jacob.e.keller@xxxxxxxxx>
> Signed-off-by: Nazim Amirul <muhammad.nazim.amirul.nazle.asmade@xxxxxxxxxx>

Reviewed-by: Andrew Lunn <andrew@xxxxxxx>

Andrew