64bd59b852cac2f65d76a6a5e51f5019e947a07e
[openwrt/staging/hauke.git] /
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Sat, 23 Jan 2021 07:18:26 +0100
3 Subject: [PATCH] mac80211: minstrel_ht: remove sample rate switching code for
4 constrained devices
5
6 This was added to mitigate the effects of too much sampling on devices that
7 use a static global fallback table instead of configurable multi-rate retry.
8 Now that the sampling algorithm is improved, this code path no longer performs
9 any better than the standard probing on affected devices.
10
11 Signed-off-by: Felix Fietkau <nbd@nbd.name>
12 ---
13
14 --- a/net/mac80211/rc80211_minstrel_ht.c
15 +++ b/net/mac80211/rc80211_minstrel_ht.c
16 @@ -648,27 +648,6 @@ __minstrel_ht_get_sample_rate(struct min
17 return 0;
18 }
19
20 -static void
21 -minstrel_ht_rate_sample_switch(struct minstrel_priv *mp,
22 - struct minstrel_ht_sta *mi)
23 -{
24 - u16 rate;
25 -
26 - /*
27 - * Use rate switching instead of probing packets for devices with
28 - * little control over retry fallback behavior
29 - */
30 - if (mp->hw->max_rates > 1)
31 - return;
32 -
33 - rate = __minstrel_ht_get_sample_rate(mi, MINSTREL_SAMPLE_TYPE_INC);
34 - if (!rate)
35 - return;
36 -
37 - mi->sample_rate = rate;
38 - mi->sample_mode = MINSTREL_SAMPLE_ACTIVE;
39 -}
40 -
41 static inline int
42 minstrel_ewma(int old, int new, int weight)
43 {
44 @@ -1012,8 +991,7 @@ minstrel_ht_refill_sample_rates(struct m
45 * higher throughput rates, even if the probablity is a bit lower
46 */
47 static void
48 -minstrel_ht_update_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
49 - bool sample)
50 +minstrel_ht_update_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
51 {
52 struct minstrel_mcs_group_data *mg;
53 struct minstrel_rate_stats *mrs;
54 @@ -1023,18 +1001,6 @@ minstrel_ht_update_stats(struct minstrel
55 u16 index;
56 bool ht_supported = mi->sta->ht_cap.ht_supported;
57
58 - mi->sample_mode = MINSTREL_SAMPLE_IDLE;
59 -
60 - if (sample) {
61 - mi->total_packets_cur = mi->total_packets -
62 - mi->total_packets_last;
63 - mi->total_packets_last = mi->total_packets;
64 - }
65 - if (!mp->sample_switch)
66 - sample = false;
67 - if (mi->total_packets_cur < SAMPLE_SWITCH_THR && mp->sample_switch != 1)
68 - sample = false;
69 -
70 if (mi->ampdu_packets > 0) {
71 if (!ieee80211_hw_check(mp->hw, TX_STATUS_NO_AMPDU_LEN))
72 mi->avg_ampdu_len = minstrel_ewma(mi->avg_ampdu_len,
73 @@ -1149,16 +1115,12 @@ minstrel_ht_update_stats(struct minstrel
74 minstrel_ht_prob_rate_reduce_streams(mi);
75 minstrel_ht_refill_sample_rates(mi);
76
77 - if (sample)
78 - minstrel_ht_rate_sample_switch(mp, mi);
79 -
80 #ifdef CPTCFG_MAC80211_DEBUGFS
81 /* use fixed index if set */
82 if (mp->fixed_rate_idx != -1) {
83 for (i = 0; i < 4; i++)
84 mi->max_tp_rate[i] = mp->fixed_rate_idx;
85 mi->max_prob_rate = mp->fixed_rate_idx;
86 - mi->sample_mode = MINSTREL_SAMPLE_IDLE;
87 }
88 #endif
89
90 @@ -1248,11 +1210,10 @@ minstrel_ht_tx_status(void *priv, struct
91 struct ieee80211_tx_info *info = st->info;
92 struct minstrel_ht_sta *mi = priv_sta;
93 struct ieee80211_tx_rate *ar = info->status.rates;
94 - struct minstrel_rate_stats *rate, *rate2, *rate_sample = NULL;
95 + struct minstrel_rate_stats *rate, *rate2;
96 struct minstrel_priv *mp = priv;
97 u32 update_interval = mp->update_interval;
98 bool last, update = false;
99 - bool sample_status = false;
100 int i;
101
102 /* This packet was aggregated but doesn't carry status info */
103 @@ -1279,49 +1240,18 @@ minstrel_ht_tx_status(void *priv, struct
104 mi->ampdu_packets++;
105 mi->ampdu_len += info->status.ampdu_len;
106
107 - if (mi->sample_mode != MINSTREL_SAMPLE_IDLE)
108 - rate_sample = minstrel_get_ratestats(mi, mi->sample_rate);
109 -
110 last = !minstrel_ht_txstat_valid(mp, mi, &ar[0]);
111 for (i = 0; !last; i++) {
112 last = (i == IEEE80211_TX_MAX_RATES - 1) ||
113 !minstrel_ht_txstat_valid(mp, mi, &ar[i + 1]);
114
115 rate = minstrel_ht_get_stats(mp, mi, &ar[i]);
116 - if (rate == rate_sample)
117 - sample_status = true;
118 -
119 if (last)
120 rate->success += info->status.ampdu_ack_len;
121
122 rate->attempts += ar[i].count * info->status.ampdu_len;
123 }
124
125 - switch (mi->sample_mode) {
126 - case MINSTREL_SAMPLE_IDLE:
127 - if (mp->hw->max_rates > 1 ||
128 - mi->total_packets_cur < SAMPLE_SWITCH_THR)
129 - update_interval /= 2;
130 - break;
131 -
132 - case MINSTREL_SAMPLE_ACTIVE:
133 - if (!sample_status)
134 - break;
135 -
136 - mi->sample_mode = MINSTREL_SAMPLE_PENDING;
137 - update = true;
138 - break;
139 -
140 - case MINSTREL_SAMPLE_PENDING:
141 - if (sample_status)
142 - break;
143 -
144 - update = true;
145 - minstrel_ht_update_stats(mp, mi, false);
146 - break;
147 - }
148 -
149 -
150 if (mp->hw->max_rates > 1) {
151 /*
152 * check for sudden death of spatial multiplexing,
153 @@ -1344,7 +1274,7 @@ minstrel_ht_tx_status(void *priv, struct
154
155 if (time_after(jiffies, mi->last_stats_update + update_interval)) {
156 update = true;
157 - minstrel_ht_update_stats(mp, mi, true);
158 + minstrel_ht_update_stats(mp, mi);
159 }
160
161 if (update)
162 @@ -1523,18 +1453,14 @@ static void
163 minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
164 {
165 struct ieee80211_sta_rates *rates;
166 - u16 first_rate = mi->max_tp_rate[0];
167 int i = 0;
168
169 - if (mi->sample_mode == MINSTREL_SAMPLE_ACTIVE)
170 - first_rate = mi->sample_rate;
171 -
172 rates = kzalloc(sizeof(*rates), GFP_ATOMIC);
173 if (!rates)
174 return;
175
176 /* Start with max_tp_rate[0] */
177 - minstrel_ht_set_rate(mp, mi, rates, i++, first_rate);
178 + minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_tp_rate[0]);
179
180 if (mp->hw->max_rates >= 3) {
181 /* At least 3 tx rates supported, use max_tp_rate[1] next */
182 @@ -1593,11 +1519,6 @@ minstrel_ht_get_rate(void *priv, struct
183 (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO))
184 return;
185
186 - if (mp->hw->max_rates == 1 && mp->sample_switch &&
187 - (mi->total_packets_cur >= SAMPLE_SWITCH_THR ||
188 - mp->sample_switch == 1))
189 - return;
190 -
191 if (time_is_before_jiffies(mi->sample_time))
192 return;
193
194 @@ -1811,7 +1732,7 @@ minstrel_ht_update_caps(void *priv, stru
195 minstrel_ht_update_ofdm(mp, mi, sband, sta);
196
197 /* create an initial rate table with the lowest supported rates */
198 - minstrel_ht_update_stats(mp, mi, true);
199 + minstrel_ht_update_stats(mp, mi);
200 minstrel_ht_update_rates(mp, mi);
201 }
202
203 @@ -1927,8 +1848,6 @@ minstrel_ht_alloc(struct ieee80211_hw *h
204 if (!mp)
205 return NULL;
206
207 - mp->sample_switch = -1;
208 -
209 /* contention window settings
210 * Just an approximation. Using the per-queue values would complicate
211 * the calculations and is probably unnecessary */
212 @@ -1948,7 +1867,7 @@ minstrel_ht_alloc(struct ieee80211_hw *h
213 mp->has_mrr = true;
214
215 mp->hw = hw;
216 - mp->update_interval = HZ / 10;
217 + mp->update_interval = HZ / 20;
218
219 minstrel_ht_init_cck_rates(mp);
220 for (i = 0; i < ARRAY_SIZE(mp->hw->wiphy->bands); i++)
221 @@ -1966,8 +1885,6 @@ static void minstrel_ht_add_debugfs(stru
222 mp->fixed_rate_idx = (u32) -1;
223 debugfs_create_u32("fixed_rate_idx", S_IRUGO | S_IWUGO, debugfsdir,
224 &mp->fixed_rate_idx);
225 - debugfs_create_u32("sample_switch", S_IRUGO | S_IWUSR, debugfsdir,
226 - &mp->sample_switch);
227 }
228 #endif
229
230 --- a/net/mac80211/rc80211_minstrel_ht.h
231 +++ b/net/mac80211/rc80211_minstrel_ht.h
232 @@ -75,7 +75,6 @@
233 struct minstrel_priv {
234 struct ieee80211_hw *hw;
235 bool has_mrr;
236 - u32 sample_switch;
237 unsigned int cw_min;
238 unsigned int cw_max;
239 unsigned int max_retry;
240 @@ -147,12 +146,6 @@ struct minstrel_mcs_group_data {
241 struct minstrel_rate_stats rates[MCS_GROUP_RATES];
242 };
243
244 -enum minstrel_sample_mode {
245 - MINSTREL_SAMPLE_IDLE,
246 - MINSTREL_SAMPLE_ACTIVE,
247 - MINSTREL_SAMPLE_PENDING,
248 -};
249 -
250 struct minstrel_sample_category {
251 u8 sample_group;
252 u16 sample_rates[MINSTREL_SAMPLE_RATES];
253 @@ -182,23 +175,19 @@ struct minstrel_ht_sta {
254 unsigned int overhead_legacy;
255 unsigned int overhead_legacy_rtscts;
256
257 - unsigned int total_packets_last;
258 - unsigned int total_packets_cur;
259 unsigned int total_packets;
260 unsigned int sample_packets;
261
262 /* tx flags to add for frames for this sta */
263 u32 tx_flags;
264
265 - unsigned long sample_time;
266 - struct minstrel_sample_category sample[__MINSTREL_SAMPLE_TYPE_MAX];
267 + u8 band;
268
269 u8 sample_seq;
270 -
271 - enum minstrel_sample_mode sample_mode;
272 u16 sample_rate;
273
274 - u8 band;
275 + unsigned long sample_time;
276 + struct minstrel_sample_category sample[__MINSTREL_SAMPLE_TYPE_MAX];
277
278 /* Bitfield of supported MCS rates of all groups */
279 u16 supported[MINSTREL_GROUPS_NB];