bcm27xx-utils: update to latest version
[openwrt/openwrt.git] / target / linux / generic / backport-6.6 / 771-v6.7-01-net-stmmac-improve-TX-timer-arm-logic.patch
1 From 2d1a42cf7f77cda54dbbee18d00b1200e7bc22aa Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Wed, 18 Oct 2023 14:35:48 +0200
4 Subject: [PATCH 1/3] net: stmmac: improve TX timer arm logic
5
6 There is currently a problem with the TX timer getting armed multiple
7 unnecessary times causing big performance regression on some device that
8 suffer from heavy handling of hrtimer rearm.
9
10 The use of the TX timer is an old implementation that predates the napi
11 implementation and the interrupt enable/disable handling.
12
13 Due to stmmac being a very old code, the TX timer was never evaluated
14 again with this new implementation and was kept there causing
15 performance regression. The performance regression started to appear
16 with kernel version 4.19 with 8fce33317023 ("net: stmmac: Rework coalesce
17 timer and fix multi-queue races") where the timer was reduced to 1ms
18 causing it to be armed 40 times more than before.
19
20 Decreasing the timer made the problem more present and caused the
21 regression in the other of 600-700mbps on some device (regression where
22 this was notice is ipq806x).
23
24 The problem is in the fact that handling the hrtimer on some target is
25 expensive and recent kernel made the timer armed much more times.
26 A solution that was proposed was reverting the hrtimer change and use
27 mod_timer but such solution would still hide the real problem in the
28 current implementation.
29
30 To fix the regression, apply some additional logic and skip arming the
31 timer when not needed.
32
33 Arm the timer ONLY if a napi is not already scheduled. Running the timer
34 is redundant since the same function (stmmac_tx_clean) will run in the
35 napi TX poll. Also try to cancel any timer if a napi is scheduled to
36 prevent redundant run of TX call.
37
38 With the following new logic the original performance are restored while
39 keeping using the hrtimer.
40
41 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
42 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
43 ---
44 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 18 +++++++++++++++---
45 1 file changed, 15 insertions(+), 3 deletions(-)
46
47 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
48 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
49 @@ -3003,13 +3003,25 @@ static void stmmac_tx_timer_arm(struct s
50 {
51 struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];
52 u32 tx_coal_timer = priv->tx_coal_timer[queue];
53 + struct stmmac_channel *ch;
54 + struct napi_struct *napi;
55
56 if (!tx_coal_timer)
57 return;
58
59 - hrtimer_start(&tx_q->txtimer,
60 - STMMAC_COAL_TIMER(tx_coal_timer),
61 - HRTIMER_MODE_REL);
62 + ch = &priv->channel[tx_q->queue_index];
63 + napi = tx_q->xsk_pool ? &ch->rxtx_napi : &ch->tx_napi;
64 +
65 + /* Arm timer only if napi is not already scheduled.
66 + * Try to cancel any timer if napi is scheduled, timer will be armed
67 + * again in the next scheduled napi.
68 + */
69 + if (unlikely(!napi_is_scheduled(napi)))
70 + hrtimer_start(&tx_q->txtimer,
71 + STMMAC_COAL_TIMER(tx_coal_timer),
72 + HRTIMER_MODE_REL);
73 + else
74 + hrtimer_try_to_cancel(&tx_q->txtimer);
75 }
76
77 /**