mac80211: add AQL support for broadcast/multicast packets
[openwrt/staging/jow.git] / package / kernel / mac80211 / patches / subsys / 330-mac80211-add-AQL-support-for-broadcast-packets.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Fri, 9 Feb 2024 19:43:40 +0100
3 Subject: [PATCH] mac80211: add AQL support for broadcast packets
4
5 Excessive broadcast traffic with little competing unicast traffic can easily
6 flood hardware queues, leading to throughput issues. Additionally, filling
7 the hardware queues with too many packets breaks FQ for broadcast data.
8 Fix this by enabling AQL for broadcast packets.
9
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 ---
12
13 --- a/include/net/cfg80211.h
14 +++ b/include/net/cfg80211.h
15 @@ -3324,6 +3324,7 @@ enum wiphy_params_flags {
16 /* The per TXQ device queue limit in airtime */
17 #define IEEE80211_DEFAULT_AQL_TXQ_LIMIT_L 5000
18 #define IEEE80211_DEFAULT_AQL_TXQ_LIMIT_H 12000
19 +#define IEEE80211_DEFAULT_AQL_TXQ_LIMIT_BC 50000
20
21 /* The per interface airtime threshold to switch to lower queue limit */
22 #define IEEE80211_AQL_THRESHOLD 24000
23 --- a/net/mac80211/debugfs.c
24 +++ b/net/mac80211/debugfs.c
25 @@ -215,11 +215,13 @@ static ssize_t aql_pending_read(struct f
26 "VI %u us\n"
27 "BE %u us\n"
28 "BK %u us\n"
29 + "BC/MC %u us\n"
30 "total %u us\n",
31 atomic_read(&local->aql_ac_pending_airtime[IEEE80211_AC_VO]),
32 atomic_read(&local->aql_ac_pending_airtime[IEEE80211_AC_VI]),
33 atomic_read(&local->aql_ac_pending_airtime[IEEE80211_AC_BE]),
34 atomic_read(&local->aql_ac_pending_airtime[IEEE80211_AC_BK]),
35 + atomic_read(&local->aql_bc_pending_airtime),
36 atomic_read(&local->aql_total_pending_airtime));
37 return simple_read_from_buffer(user_buf, count, ppos,
38 buf, len);
39 @@ -245,7 +247,8 @@ static ssize_t aql_txq_limit_read(struct
40 "VO %u %u\n"
41 "VI %u %u\n"
42 "BE %u %u\n"
43 - "BK %u %u\n",
44 + "BK %u %u\n"
45 + "BC/MC %u\n",
46 local->aql_txq_limit_low[IEEE80211_AC_VO],
47 local->aql_txq_limit_high[IEEE80211_AC_VO],
48 local->aql_txq_limit_low[IEEE80211_AC_VI],
49 @@ -253,7 +256,8 @@ static ssize_t aql_txq_limit_read(struct
50 local->aql_txq_limit_low[IEEE80211_AC_BE],
51 local->aql_txq_limit_high[IEEE80211_AC_BE],
52 local->aql_txq_limit_low[IEEE80211_AC_BK],
53 - local->aql_txq_limit_high[IEEE80211_AC_BK]);
54 + local->aql_txq_limit_high[IEEE80211_AC_BK],
55 + local->aql_txq_limit_bc);
56 return simple_read_from_buffer(user_buf, count, ppos,
57 buf, len);
58 }
59 @@ -279,6 +283,11 @@ static ssize_t aql_txq_limit_write(struc
60 else
61 buf[count] = '\0';
62
63 + if (sscanf(buf, "mcast %u", &q_limit_low) == 1) {
64 + local->aql_txq_limit_bc = q_limit_low;
65 + return count;
66 + }
67 +
68 if (sscanf(buf, "%u %u %u", &ac, &q_limit_low, &q_limit_high) != 3)
69 return -EINVAL;
70
71 --- a/net/mac80211/ieee80211_i.h
72 +++ b/net/mac80211/ieee80211_i.h
73 @@ -1328,10 +1328,12 @@ struct ieee80211_local {
74 spinlock_t handle_wake_tx_queue_lock;
75
76 u16 airtime_flags;
77 + u32 aql_txq_limit_bc;
78 u32 aql_txq_limit_low[IEEE80211_NUM_ACS];
79 u32 aql_txq_limit_high[IEEE80211_NUM_ACS];
80 u32 aql_threshold;
81 atomic_t aql_total_pending_airtime;
82 + atomic_t aql_bc_pending_airtime;
83 atomic_t aql_ac_pending_airtime[IEEE80211_NUM_ACS];
84
85 const struct ieee80211_ops *ops;
86 --- a/net/mac80211/main.c
87 +++ b/net/mac80211/main.c
88 @@ -788,6 +788,7 @@ struct ieee80211_hw *ieee80211_alloc_hw_
89 spin_lock_init(&local->rx_path_lock);
90 spin_lock_init(&local->queue_stop_reason_lock);
91
92 + local->aql_txq_limit_bc = IEEE80211_DEFAULT_AQL_TXQ_LIMIT_BC;
93 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
94 INIT_LIST_HEAD(&local->active_txqs[i]);
95 spin_lock_init(&local->active_txq_lock[i]);
96 --- a/net/mac80211/sta_info.c
97 +++ b/net/mac80211/sta_info.c
98 @@ -2341,28 +2341,27 @@ void ieee80211_sta_update_pending_airtim
99 struct sta_info *sta, u8 ac,
100 u16 tx_airtime, bool tx_completed)
101 {
102 + atomic_t *counter;
103 int tx_pending;
104
105 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
106 return;
107
108 - if (!tx_completed) {
109 - if (sta)
110 - atomic_add(tx_airtime,
111 - &sta->airtime[ac].aql_tx_pending);
112 + if (sta)
113 + counter = &sta->airtime[ac].aql_tx_pending;
114 + else
115 + counter = &local->aql_bc_pending_airtime;
116
117 + if (!tx_completed) {
118 + atomic_add(tx_airtime, counter);
119 atomic_add(tx_airtime, &local->aql_total_pending_airtime);
120 atomic_add(tx_airtime, &local->aql_ac_pending_airtime[ac]);
121 return;
122 }
123
124 - if (sta) {
125 - tx_pending = atomic_sub_return(tx_airtime,
126 - &sta->airtime[ac].aql_tx_pending);
127 - if (tx_pending < 0)
128 - atomic_cmpxchg(&sta->airtime[ac].aql_tx_pending,
129 - tx_pending, 0);
130 - }
131 + tx_pending = atomic_sub_return(tx_airtime, counter);
132 + if (tx_pending < 0)
133 + atomic_cmpxchg(counter, tx_pending, 0);
134
135 atomic_sub(tx_airtime, &local->aql_total_pending_airtime);
136 tx_pending = atomic_sub_return(tx_airtime,
137 --- a/net/mac80211/tx.c
138 +++ b/net/mac80211/tx.c
139 @@ -3958,9 +3958,8 @@ begin:
140 encap_out:
141 IEEE80211_SKB_CB(skb)->control.vif = vif;
142
143 - if (tx.sta &&
144 - wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) {
145 - bool ampdu = txq->ac != IEEE80211_AC_VO;
146 + if (wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) {
147 + bool ampdu = txq->sta && txq->ac != IEEE80211_AC_VO;
148 u32 airtime;
149
150 airtime = ieee80211_calc_expected_tx_airtime(hw, vif, txq->sta,
151 @@ -4026,6 +4025,7 @@ struct ieee80211_txq *ieee80211_next_txq
152 struct ieee80211_txq *ret = NULL;
153 struct txq_info *txqi = NULL, *head = NULL;
154 bool found_eligible_txq = false;
155 + bool aql_check;
156
157 spin_lock_bh(&local->active_txq_lock[ac]);
158
159 @@ -4049,26 +4049,26 @@ struct ieee80211_txq *ieee80211_next_txq
160 if (!head)
161 head = txqi;
162
163 + aql_check = ieee80211_txq_airtime_check(hw, &txqi->txq);
164 + if (aql_check)
165 + found_eligible_txq = true;
166 +
167 if (txqi->txq.sta) {
168 struct sta_info *sta = container_of(txqi->txq.sta,
169 struct sta_info, sta);
170 - bool aql_check = ieee80211_txq_airtime_check(hw, &txqi->txq);
171 - s32 deficit = ieee80211_sta_deficit(sta, txqi->txq.ac);
172 -
173 - if (aql_check)
174 - found_eligible_txq = true;
175 -
176 - if (deficit < 0)
177 + if (ieee80211_sta_deficit(sta, txqi->txq.ac) < 0) {
178 sta->airtime[txqi->txq.ac].deficit +=
179 sta->airtime_weight << AIRTIME_QUANTUM_SHIFT;
180 -
181 - if (deficit < 0 || !aql_check) {
182 - list_move_tail(&txqi->schedule_order,
183 - &local->active_txqs[txqi->txq.ac]);
184 - goto begin;
185 + aql_check = false;
186 }
187 }
188
189 + if (!aql_check) {
190 + list_move_tail(&txqi->schedule_order,
191 + &local->active_txqs[txqi->txq.ac]);
192 + goto begin;
193 + }
194 +
195 if (txqi->schedule_round == local->schedule_round[ac])
196 goto out;
197
198 @@ -4133,7 +4133,8 @@ bool ieee80211_txq_airtime_check(struct
199 return true;
200
201 if (!txq->sta)
202 - return true;
203 + return atomic_read(&local->aql_bc_pending_airtime) <
204 + local->aql_txq_limit_bc;
205
206 if (unlikely(txq->tid == IEEE80211_NUM_TIDS))
207 return true;
208 @@ -4182,15 +4183,15 @@ bool ieee80211_txq_may_transmit(struct i
209
210 spin_lock_bh(&local->active_txq_lock[ac]);
211
212 - if (!txqi->txq.sta)
213 - goto out;
214 -
215 if (list_empty(&txqi->schedule_order))
216 goto out;
217
218 if (!ieee80211_txq_schedule_airtime_check(local, ac))
219 goto out;
220
221 + if (!txqi->txq.sta)
222 + goto out;
223 +
224 list_for_each_entry_safe(iter, tmp, &local->active_txqs[ac],
225 schedule_order) {
226 if (iter == txqi)