Commit 8f15761197c73e1968777e4b4d968ab0fba2cb74
Committed by
Johannes Berg
1 parent
c8ca8c2f93
Exists in
smarc_imx_lf-5.15.y
and in
37 other branches
mac80211: add documentation and verbose variable names in
Add documentation and more verbose variable names to minstrel's multi-rate-retry setup within function minstrel_get_rate() to increase the readability of the algorithm. Acked-by: Felix Fietkau <nbd@openwrt.org> Signed-off-by: Thomas Huehn <thomas@net.t-labs.tu-berlin.de> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Showing 2 changed files with 50 additions and 33 deletions Side-by-side Diff
net/mac80211/rc80211_minstrel.c
... | ... | @@ -78,7 +78,6 @@ |
78 | 78 | u32 usecs; |
79 | 79 | int i; |
80 | 80 | |
81 | - mi->stats_update = jiffies; | |
82 | 81 | for (i = 0; i < mi->n_rates; i++) { |
83 | 82 | struct minstrel_rate *mr = &mi->r[i]; |
84 | 83 | |
... | ... | @@ -144,6 +143,9 @@ |
144 | 143 | mi->max_tp_rate = index_max_tp; |
145 | 144 | mi->max_tp_rate2 = index_max_tp2; |
146 | 145 | mi->max_prob_rate = index_max_prob; |
146 | + | |
147 | + /* Reset update timer */ | |
148 | + mi->stats_update = jiffies; | |
147 | 149 | } |
148 | 150 | |
149 | 151 | static void |
... | ... | @@ -204,10 +206,10 @@ |
204 | 206 | minstrel_get_next_sample(struct minstrel_sta_info *mi) |
205 | 207 | { |
206 | 208 | unsigned int sample_ndx; |
207 | - sample_ndx = SAMPLE_TBL(mi, mi->sample_idx, mi->sample_column); | |
208 | - mi->sample_idx++; | |
209 | - if ((int) mi->sample_idx > (mi->n_rates - 2)) { | |
210 | - mi->sample_idx = 0; | |
209 | + sample_ndx = SAMPLE_TBL(mi, mi->sample_row, mi->sample_column); | |
210 | + mi->sample_row++; | |
211 | + if ((int) mi->sample_row > (mi->n_rates - 2)) { | |
212 | + mi->sample_row = 0; | |
211 | 213 | mi->sample_column++; |
212 | 214 | if (mi->sample_column >= SAMPLE_COLUMNS) |
213 | 215 | mi->sample_column = 0; |
214 | 216 | |
215 | 217 | |
216 | 218 | |
217 | 219 | |
218 | 220 | |
219 | 221 | |
220 | 222 | |
... | ... | @@ -225,31 +227,37 @@ |
225 | 227 | struct minstrel_priv *mp = priv; |
226 | 228 | struct ieee80211_tx_rate *ar = info->control.rates; |
227 | 229 | unsigned int ndx, sample_ndx = 0; |
228 | - bool mrr; | |
229 | - bool sample_slower = false; | |
230 | - bool sample = false; | |
230 | + bool mrr_capable; | |
231 | + bool indirect_rate_sampling = false; | |
232 | + bool rate_sampling = false; | |
231 | 233 | int i, delta; |
232 | 234 | int mrr_ndx[3]; |
233 | - int sample_rate; | |
235 | + int sampling_ratio; | |
234 | 236 | |
237 | + /* management/no-ack frames do not use rate control */ | |
235 | 238 | if (rate_control_send_low(sta, priv_sta, txrc)) |
236 | 239 | return; |
237 | 240 | |
238 | - mrr = mp->has_mrr && !txrc->rts && !txrc->bss_conf->use_cts_prot; | |
241 | + /* check multi-rate-retry capabilities & adjust lookaround_rate */ | |
242 | + mrr_capable = mp->has_mrr && | |
243 | + !txrc->rts && | |
244 | + !txrc->bss_conf->use_cts_prot; | |
245 | + if (mrr_capable) | |
246 | + sampling_ratio = mp->lookaround_rate_mrr; | |
247 | + else | |
248 | + sampling_ratio = mp->lookaround_rate; | |
239 | 249 | |
250 | + /* init rateindex [ndx] with max throughput rate */ | |
240 | 251 | ndx = mi->max_tp_rate; |
241 | 252 | |
242 | - if (mrr) | |
243 | - sample_rate = mp->lookaround_rate_mrr; | |
244 | - else | |
245 | - sample_rate = mp->lookaround_rate; | |
246 | - | |
253 | + /* increase sum packet counter */ | |
247 | 254 | mi->packet_count++; |
248 | - delta = (mi->packet_count * sample_rate / 100) - | |
255 | + | |
256 | + delta = (mi->packet_count * sampling_ratio / 100) - | |
249 | 257 | (mi->sample_count + mi->sample_deferred / 2); |
250 | 258 | |
251 | 259 | /* delta > 0: sampling required */ |
252 | - if ((delta > 0) && (mrr || !mi->prev_sample)) { | |
260 | + if ((delta > 0) && (mrr_capable || !mi->prev_sample)) { | |
253 | 261 | struct minstrel_rate *msr; |
254 | 262 | if (mi->packet_count >= 10000) { |
255 | 263 | mi->sample_deferred = 0; |
256 | 264 | |
257 | 265 | |
258 | 266 | |
... | ... | @@ -268,21 +276,25 @@ |
268 | 276 | mi->sample_count += (delta - mi->n_rates * 2); |
269 | 277 | } |
270 | 278 | |
279 | + /* get next random rate sample */ | |
271 | 280 | sample_ndx = minstrel_get_next_sample(mi); |
272 | 281 | msr = &mi->r[sample_ndx]; |
273 | - sample = true; | |
274 | - sample_slower = mrr && (msr->perfect_tx_time > | |
275 | - mi->r[ndx].perfect_tx_time); | |
282 | + rate_sampling = true; | |
276 | 283 | |
277 | - if (!sample_slower) { | |
284 | + /* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage) | |
285 | + * rate sampling method should be used */ | |
286 | + if (mrr_capable && | |
287 | + msr->perfect_tx_time > mi->r[ndx].perfect_tx_time) | |
288 | + indirect_rate_sampling = true; | |
289 | + | |
290 | + if (!indirect_rate_sampling) { | |
278 | 291 | if (msr->sample_limit != 0) { |
279 | 292 | ndx = sample_ndx; |
280 | 293 | mi->sample_count++; |
281 | 294 | if (msr->sample_limit > 0) |
282 | 295 | msr->sample_limit--; |
283 | - } else { | |
284 | - sample = false; | |
285 | - } | |
296 | + } else | |
297 | + rate_sampling = false; | |
286 | 298 | } else { |
287 | 299 | /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark |
288 | 300 | * packets that have the sampling rate deferred to the |
289 | 301 | |
290 | 302 | |
291 | 303 | |
292 | 304 | |
293 | 305 | |
... | ... | @@ -294,34 +306,39 @@ |
294 | 306 | mi->sample_deferred++; |
295 | 307 | } |
296 | 308 | } |
297 | - mi->prev_sample = sample; | |
309 | + mi->prev_sample = rate_sampling; | |
298 | 310 | |
299 | 311 | /* If we're not using MRR and the sampling rate already |
300 | 312 | * has a probability of >95%, we shouldn't be attempting |
301 | 313 | * to use it, as this only wastes precious airtime */ |
302 | - if (!mrr && sample && (mi->r[ndx].probability > MINSTREL_FRAC(95, 100))) | |
314 | + if (!mrr_capable && rate_sampling && | |
315 | + (mi->r[ndx].probability > MINSTREL_FRAC(95, 100))) | |
303 | 316 | ndx = mi->max_tp_rate; |
304 | 317 | |
318 | + /* mrr setup for 1st stage */ | |
305 | 319 | ar[0].idx = mi->r[ndx].rix; |
306 | 320 | ar[0].count = minstrel_get_retry_count(&mi->r[ndx], info); |
307 | 321 | |
308 | - if (!mrr) { | |
309 | - if (!sample) | |
322 | + /* non mrr setup for 2nd stage */ | |
323 | + if (!mrr_capable) { | |
324 | + if (!rate_sampling) | |
310 | 325 | ar[0].count = mp->max_retry; |
311 | 326 | ar[1].idx = mi->lowest_rix; |
312 | 327 | ar[1].count = mp->max_retry; |
313 | 328 | return; |
314 | 329 | } |
315 | 330 | |
316 | - /* MRR setup */ | |
317 | - if (sample) { | |
318 | - if (sample_slower) | |
331 | + /* mrr setup for 2nd stage */ | |
332 | + if (rate_sampling) { | |
333 | + if (indirect_rate_sampling) | |
319 | 334 | mrr_ndx[0] = sample_ndx; |
320 | 335 | else |
321 | 336 | mrr_ndx[0] = mi->max_tp_rate; |
322 | 337 | } else { |
323 | 338 | mrr_ndx[0] = mi->max_tp_rate2; |
324 | 339 | } |
340 | + | |
341 | + /* mrr setup for 3rd & 4th stage */ | |
325 | 342 | mrr_ndx[1] = mi->max_prob_rate; |
326 | 343 | mrr_ndx[2] = 0; |
327 | 344 | for (i = 1; i < 4; i++) { |
... | ... | @@ -352,7 +369,7 @@ |
352 | 369 | u8 rnd[8]; |
353 | 370 | |
354 | 371 | mi->sample_column = 0; |
355 | - mi->sample_idx = 0; | |
372 | + mi->sample_row = 0; | |
356 | 373 | memset(mi->sample_table, 0, SAMPLE_COLUMNS * mi->n_rates); |
357 | 374 | |
358 | 375 | for (col = 0; col < SAMPLE_COLUMNS; col++) { |