diff options
author | Thomas Huehn <thomas@net.t-labs.tu-berlin.de> | 2013-03-04 17:30:03 -0500 |
---|---|---|
committer | Johannes Berg <johannes.berg@intel.com> | 2013-03-06 10:36:08 -0500 |
commit | 8f15761197c73e1968777e4b4d968ab0fba2cb74 (patch) | |
tree | fbc4072aa6e30a49801b57865f21cc6ede73bee5 | |
parent | c8ca8c2f933a516b5f4586d7dc6055b72107f246 (diff) |
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>
-rw-r--r-- | net/mac80211/rc80211_minstrel.c | 81 | ||||
-rw-r--r-- | net/mac80211/rc80211_minstrel.h | 2 |
2 files changed, 50 insertions, 33 deletions
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c index c9b990237991..152bb0e37865 100644 --- a/net/mac80211/rc80211_minstrel.c +++ b/net/mac80211/rc80211_minstrel.c | |||
@@ -78,7 +78,6 @@ minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi) | |||
78 | u32 usecs; | 78 | u32 usecs; |
79 | int i; | 79 | int i; |
80 | 80 | ||
81 | mi->stats_update = jiffies; | ||
82 | for (i = 0; i < mi->n_rates; i++) { | 81 | for (i = 0; i < mi->n_rates; i++) { |
83 | struct minstrel_rate *mr = &mi->r[i]; | 82 | struct minstrel_rate *mr = &mi->r[i]; |
84 | 83 | ||
@@ -144,6 +143,9 @@ minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi) | |||
144 | mi->max_tp_rate = index_max_tp; | 143 | mi->max_tp_rate = index_max_tp; |
145 | mi->max_tp_rate2 = index_max_tp2; | 144 | mi->max_tp_rate2 = index_max_tp2; |
146 | mi->max_prob_rate = index_max_prob; | 145 | mi->max_prob_rate = index_max_prob; |
146 | |||
147 | /* Reset update timer */ | ||
148 | mi->stats_update = jiffies; | ||
147 | } | 149 | } |
148 | 150 | ||
149 | static void | 151 | static void |
@@ -204,10 +206,10 @@ static int | |||
204 | minstrel_get_next_sample(struct minstrel_sta_info *mi) | 206 | minstrel_get_next_sample(struct minstrel_sta_info *mi) |
205 | { | 207 | { |
206 | unsigned int sample_ndx; | 208 | unsigned int sample_ndx; |
207 | sample_ndx = SAMPLE_TBL(mi, mi->sample_idx, mi->sample_column); | 209 | sample_ndx = SAMPLE_TBL(mi, mi->sample_row, mi->sample_column); |
208 | mi->sample_idx++; | 210 | mi->sample_row++; |
209 | if ((int) mi->sample_idx > (mi->n_rates - 2)) { | 211 | if ((int) mi->sample_row > (mi->n_rates - 2)) { |
210 | mi->sample_idx = 0; | 212 | mi->sample_row = 0; |
211 | mi->sample_column++; | 213 | mi->sample_column++; |
212 | if (mi->sample_column >= SAMPLE_COLUMNS) | 214 | if (mi->sample_column >= SAMPLE_COLUMNS) |
213 | mi->sample_column = 0; | 215 | mi->sample_column = 0; |
@@ -225,31 +227,37 @@ minstrel_get_rate(void *priv, struct ieee80211_sta *sta, | |||
225 | struct minstrel_priv *mp = priv; | 227 | struct minstrel_priv *mp = priv; |
226 | struct ieee80211_tx_rate *ar = info->control.rates; | 228 | struct ieee80211_tx_rate *ar = info->control.rates; |
227 | unsigned int ndx, sample_ndx = 0; | 229 | unsigned int ndx, sample_ndx = 0; |
228 | bool mrr; | 230 | bool mrr_capable; |
229 | bool sample_slower = false; | 231 | bool indirect_rate_sampling = false; |
230 | bool sample = false; | 232 | bool rate_sampling = false; |
231 | int i, delta; | 233 | int i, delta; |
232 | int mrr_ndx[3]; | 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 | if (rate_control_send_low(sta, priv_sta, txrc)) | 238 | if (rate_control_send_low(sta, priv_sta, txrc)) |
236 | return; | 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 | ndx = mi->max_tp_rate; | 251 | ndx = mi->max_tp_rate; |
241 | 252 | ||
242 | if (mrr) | 253 | /* increase sum packet counter */ |
243 | sample_rate = mp->lookaround_rate_mrr; | ||
244 | else | ||
245 | sample_rate = mp->lookaround_rate; | ||
246 | |||
247 | mi->packet_count++; | 254 | mi->packet_count++; |
248 | delta = (mi->packet_count * sample_rate / 100) - | 255 | |
256 | delta = (mi->packet_count * sampling_ratio / 100) - | ||
249 | (mi->sample_count + mi->sample_deferred / 2); | 257 | (mi->sample_count + mi->sample_deferred / 2); |
250 | 258 | ||
251 | /* delta > 0: sampling required */ | 259 | /* delta > 0: sampling required */ |
252 | if ((delta > 0) && (mrr || !mi->prev_sample)) { | 260 | if ((delta > 0) && (mrr_capable || !mi->prev_sample)) { |
253 | struct minstrel_rate *msr; | 261 | struct minstrel_rate *msr; |
254 | if (mi->packet_count >= 10000) { | 262 | if (mi->packet_count >= 10000) { |
255 | mi->sample_deferred = 0; | 263 | mi->sample_deferred = 0; |
@@ -268,21 +276,25 @@ minstrel_get_rate(void *priv, struct ieee80211_sta *sta, | |||
268 | mi->sample_count += (delta - mi->n_rates * 2); | 276 | mi->sample_count += (delta - mi->n_rates * 2); |
269 | } | 277 | } |
270 | 278 | ||
279 | /* get next random rate sample */ | ||
271 | sample_ndx = minstrel_get_next_sample(mi); | 280 | sample_ndx = minstrel_get_next_sample(mi); |
272 | msr = &mi->r[sample_ndx]; | 281 | msr = &mi->r[sample_ndx]; |
273 | sample = true; | 282 | rate_sampling = true; |
274 | sample_slower = mrr && (msr->perfect_tx_time > | ||
275 | mi->r[ndx].perfect_tx_time); | ||
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 | if (msr->sample_limit != 0) { | 291 | if (msr->sample_limit != 0) { |
279 | ndx = sample_ndx; | 292 | ndx = sample_ndx; |
280 | mi->sample_count++; | 293 | mi->sample_count++; |
281 | if (msr->sample_limit > 0) | 294 | if (msr->sample_limit > 0) |
282 | msr->sample_limit--; | 295 | msr->sample_limit--; |
283 | } else { | 296 | } else |
284 | sample = false; | 297 | rate_sampling = false; |
285 | } | ||
286 | } else { | 298 | } else { |
287 | /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark | 299 | /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark |
288 | * packets that have the sampling rate deferred to the | 300 | * packets that have the sampling rate deferred to the |
@@ -294,34 +306,39 @@ minstrel_get_rate(void *priv, struct ieee80211_sta *sta, | |||
294 | mi->sample_deferred++; | 306 | mi->sample_deferred++; |
295 | } | 307 | } |
296 | } | 308 | } |
297 | mi->prev_sample = sample; | 309 | mi->prev_sample = rate_sampling; |
298 | 310 | ||
299 | /* If we're not using MRR and the sampling rate already | 311 | /* If we're not using MRR and the sampling rate already |
300 | * has a probability of >95%, we shouldn't be attempting | 312 | * has a probability of >95%, we shouldn't be attempting |
301 | * to use it, as this only wastes precious airtime */ | 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 | ndx = mi->max_tp_rate; | 316 | ndx = mi->max_tp_rate; |
304 | 317 | ||
318 | /* mrr setup for 1st stage */ | ||
305 | ar[0].idx = mi->r[ndx].rix; | 319 | ar[0].idx = mi->r[ndx].rix; |
306 | ar[0].count = minstrel_get_retry_count(&mi->r[ndx], info); | 320 | ar[0].count = minstrel_get_retry_count(&mi->r[ndx], info); |
307 | 321 | ||
308 | if (!mrr) { | 322 | /* non mrr setup for 2nd stage */ |
309 | if (!sample) | 323 | if (!mrr_capable) { |
324 | if (!rate_sampling) | ||
310 | ar[0].count = mp->max_retry; | 325 | ar[0].count = mp->max_retry; |
311 | ar[1].idx = mi->lowest_rix; | 326 | ar[1].idx = mi->lowest_rix; |
312 | ar[1].count = mp->max_retry; | 327 | ar[1].count = mp->max_retry; |
313 | return; | 328 | return; |
314 | } | 329 | } |
315 | 330 | ||
316 | /* MRR setup */ | 331 | /* mrr setup for 2nd stage */ |
317 | if (sample) { | 332 | if (rate_sampling) { |
318 | if (sample_slower) | 333 | if (indirect_rate_sampling) |
319 | mrr_ndx[0] = sample_ndx; | 334 | mrr_ndx[0] = sample_ndx; |
320 | else | 335 | else |
321 | mrr_ndx[0] = mi->max_tp_rate; | 336 | mrr_ndx[0] = mi->max_tp_rate; |
322 | } else { | 337 | } else { |
323 | mrr_ndx[0] = mi->max_tp_rate2; | 338 | mrr_ndx[0] = mi->max_tp_rate2; |
324 | } | 339 | } |
340 | |||
341 | /* mrr setup for 3rd & 4th stage */ | ||
325 | mrr_ndx[1] = mi->max_prob_rate; | 342 | mrr_ndx[1] = mi->max_prob_rate; |
326 | mrr_ndx[2] = 0; | 343 | mrr_ndx[2] = 0; |
327 | for (i = 1; i < 4; i++) { | 344 | for (i = 1; i < 4; i++) { |
@@ -352,7 +369,7 @@ init_sample_table(struct minstrel_sta_info *mi) | |||
352 | u8 rnd[8]; | 369 | u8 rnd[8]; |
353 | 370 | ||
354 | mi->sample_column = 0; | 371 | mi->sample_column = 0; |
355 | mi->sample_idx = 0; | 372 | mi->sample_row = 0; |
356 | memset(mi->sample_table, 0, SAMPLE_COLUMNS * mi->n_rates); | 373 | memset(mi->sample_table, 0, SAMPLE_COLUMNS * mi->n_rates); |
357 | 374 | ||
358 | for (col = 0; col < SAMPLE_COLUMNS; col++) { | 375 | for (col = 0; col < SAMPLE_COLUMNS; col++) { |
diff --git a/net/mac80211/rc80211_minstrel.h b/net/mac80211/rc80211_minstrel.h index fda4a6154c87..5fb5cb81d0da 100644 --- a/net/mac80211/rc80211_minstrel.h +++ b/net/mac80211/rc80211_minstrel.h | |||
@@ -69,7 +69,7 @@ struct minstrel_sta_info { | |||
69 | unsigned int sample_count; | 69 | unsigned int sample_count; |
70 | int sample_deferred; | 70 | int sample_deferred; |
71 | 71 | ||
72 | unsigned int sample_idx; | 72 | unsigned int sample_row; |
73 | unsigned int sample_column; | 73 | unsigned int sample_column; |
74 | 74 | ||
75 | int n_rates; | 75 | int n_rates; |