355a0fa8bb42c561e5f9eccca671349d87ce29c9
[openwrt/openwrt.git] / target / linux / ipq806x / patches-5.15 / 700-Revert-net-stmmac-Use-hrtimer-for-TX-coalescing.patch
1 From 0db3e9ac75b107d2158b227426f58df9bb00529f Mon Sep 17 00:00:00 2001
2 From: Oskari Lemmela <oskari@lemmela.net>
3 Date: Sun, 20 Aug 2023 15:25:09 +0300
4 Subject: [PATCH] Revert "net: stmmac: Use hrtimer for TX coalescing"
5
6 This reverts commit d5a05e69ac6e4c431c380ced2b534c91f7bc3280.
7
8 hrtimer uses raw_spin_lock which causes high CPU usage.
9 ipq806x platform's TCP transmit speed dropped from 950 Mbps to 250 Mbps
10 due to high ksoftirq.
11
12 Signed-off-by: Oskari Lemmela <oskari@lemmela.net>
13 ---
14 drivers/net/ethernet/stmicro/stmmac/stmmac.h | 3 +--
15 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 25 +++++++------------
16 2 files changed, 10 insertions(+), 18 deletions(-)
17
18 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
19 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
20 @@ -13,7 +13,6 @@
21 #define DRV_MODULE_VERSION "Jan_2016"
22
23 #include <linux/clk.h>
24 -#include <linux/hrtimer.h>
25 #include <linux/if_vlan.h>
26 #include <linux/stmmac.h>
27 #include <linux/phylink.h>
28 @@ -59,7 +58,7 @@ struct stmmac_tx_info {
29 struct stmmac_tx_queue {
30 u32 tx_count_frames;
31 int tbs;
32 - struct hrtimer txtimer;
33 + struct timer_list txtimer;
34 u32 queue_index;
35 struct stmmac_priv *priv_data;
36 struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
37 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
38 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
39 @@ -142,7 +142,7 @@ static void stmmac_init_fs(struct net_de
40 static void stmmac_exit_fs(struct net_device *dev);
41 #endif
42
43 -#define STMMAC_COAL_TIMER(x) (ns_to_ktime((x) * NSEC_PER_USEC))
44 +#define STMMAC_COAL_TIMER(x) (jiffies + usecs_to_jiffies(x))
45
46 int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled)
47 {
48 @@ -2726,9 +2726,7 @@ static int stmmac_tx_clean(struct stmmac
49
50 /* We still have pending packets, let's call for a new scheduling */
51 if (tx_q->dirty_tx != tx_q->cur_tx)
52 - hrtimer_start(&tx_q->txtimer,
53 - STMMAC_COAL_TIMER(priv->tx_coal_timer[queue]),
54 - HRTIMER_MODE_REL);
55 + mod_timer(&tx_q->txtimer, STMMAC_COAL_TIMER(priv->tx_coal_timer[queue]));
56
57 __netif_tx_unlock_bh(netdev_get_tx_queue(priv->dev, queue));
58
59 @@ -3020,9 +3018,7 @@ static void stmmac_tx_timer_arm(struct s
60 {
61 struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];
62
63 - hrtimer_start(&tx_q->txtimer,
64 - STMMAC_COAL_TIMER(priv->tx_coal_timer[queue]),
65 - HRTIMER_MODE_REL);
66 + mod_timer(&tx_q->txtimer, STMMAC_COAL_TIMER(priv->tx_coal_timer[queue]));
67 }
68
69 /**
70 @@ -3031,9 +3027,9 @@ static void stmmac_tx_timer_arm(struct s
71 * Description:
72 * This is the timer handler to directly invoke the stmmac_tx_clean.
73 */
74 -static enum hrtimer_restart stmmac_tx_timer(struct hrtimer *t)
75 +static void stmmac_tx_timer(struct timer_list *t)
76 {
77 - struct stmmac_tx_queue *tx_q = container_of(t, struct stmmac_tx_queue, txtimer);
78 + struct stmmac_tx_queue *tx_q = from_timer(tx_q, t, txtimer);
79 struct stmmac_priv *priv = tx_q->priv_data;
80 struct stmmac_channel *ch;
81 struct napi_struct *napi;
82 @@ -3049,8 +3045,6 @@ static enum hrtimer_restart stmmac_tx_ti
83 spin_unlock_irqrestore(&ch->lock, flags);
84 __napi_schedule(napi);
85 }
86 -
87 - return HRTIMER_NORESTART;
88 }
89
90 /**
91 @@ -3073,8 +3067,7 @@ static void stmmac_init_coalesce(struct
92 priv->tx_coal_frames[chan] = STMMAC_TX_FRAMES;
93 priv->tx_coal_timer[chan] = STMMAC_COAL_TX_TIMER;
94
95 - hrtimer_init(&tx_q->txtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
96 - tx_q->txtimer.function = stmmac_tx_timer;
97 + timer_setup(&tx_q->txtimer, stmmac_tx_timer, 0);
98 }
99
100 for (chan = 0; chan < rx_channel_count; chan++)
101 @@ -3904,7 +3897,7 @@ irq_error:
102 phylink_stop(priv->phylink);
103
104 for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++)
105 - hrtimer_cancel(&priv->dma_conf.tx_queue[chan].txtimer);
106 + del_timer_sync(&priv->dma_conf.tx_queue[chan].txtimer);
107
108 stmmac_hw_teardown(dev);
109 init_error:
110 @@ -3960,7 +3953,7 @@ static int stmmac_release(struct net_dev
111 stmmac_disable_all_queues(priv);
112
113 for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++)
114 - hrtimer_cancel(&priv->dma_conf.tx_queue[chan].txtimer);
115 + del_timer_sync(&priv->dma_conf.tx_queue[chan].txtimer);
116
117 netif_tx_disable(dev);
118
119 @@ -6635,7 +6628,7 @@ void stmmac_xdp_release(struct net_devic
120 stmmac_disable_all_queues(priv);
121
122 for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++)
123 - hrtimer_cancel(&priv->dma_conf.tx_queue[chan].txtimer);
124 + del_timer_sync(&priv->dma_conf.tx_queue[chan].txtimer);
125
126 /* Free the IRQ lines */
127 stmmac_free_irq(dev, REQ_IRQ_ERR_ALL, 0);
128 @@ -6730,8 +6723,7 @@ int stmmac_xdp_open(struct net_device *d
129 stmmac_set_tx_tail_ptr(priv, priv->ioaddr,
130 tx_q->tx_tail_addr, chan);
131
132 - hrtimer_init(&tx_q->txtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
133 - tx_q->txtimer.function = stmmac_tx_timer;
134 + timer_setup(&tx_q->txtimer, stmmac_tx_timer, 0);
135 }
136
137 /* Enable the MAC Rx/Tx */
138 @@ -6754,7 +6746,7 @@ int stmmac_xdp_open(struct net_device *d
139
140 irq_error:
141 for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++)
142 - hrtimer_cancel(&priv->dma_conf.tx_queue[chan].txtimer);
143 + del_timer_sync(&priv->dma_conf.tx_queue[chan].txtimer);
144
145 stmmac_hw_teardown(dev);
146 init_error:
147 @@ -7481,7 +7473,7 @@ int stmmac_suspend(struct device *dev)
148 stmmac_disable_all_queues(priv);
149
150 for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++)
151 - hrtimer_cancel(&priv->dma_conf.tx_queue[chan].txtimer);
152 + del_timer_sync(&priv->dma_conf.tx_queue[chan].txtimer);
153
154 if (priv->eee_enabled) {
155 priv->tx_path_in_lpi_mode = false;