Skip to content

Commit 6a27b2c

Browse files
thuehnjmberg-intel
authored andcommitted
mac80211: restructure per-rate throughput calculation into function
This patch moves Minstrels and Minstrel-HTs per-rate throughput calculation (EWMA(thr)) into a dedicated function to be called. Therefore the variable "unsigned int cur_tp" within struct "minstrel_rate_stats" becomes obsolete. and is removed to free up its space. Signed-off-by: Thomas Huehn <[email protected]> Acked-by: Felix Fietkau <[email protected]> Signed-off-by: Johannes Berg <[email protected]>
1 parent 9134073 commit 6a27b2c

File tree

6 files changed

+88
-61
lines changed

6 files changed

+88
-61
lines changed

net/mac80211/rc80211_minstrel.c

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,32 @@ rix_to_ndx(struct minstrel_sta_info *mi, int rix)
6969
return i;
7070
}
7171

72+
/* return current EMWA throughput */
73+
int minstrel_get_tp_avg(struct minstrel_rate *mr)
74+
{
75+
int usecs;
76+
77+
usecs = mr->perfect_tx_time;
78+
if (!usecs)
79+
usecs = 1000000;
80+
81+
/* reset thr. below 10% success */
82+
if (mr->stats.prob_ewma < MINSTREL_FRAC(10, 100))
83+
return 0;
84+
else
85+
return MINSTREL_TRUNC(mr->stats.prob_ewma * (100000 / usecs));
86+
}
87+
7288
/* find & sort topmost throughput rates */
7389
static inline void
7490
minstrel_sort_best_tp_rates(struct minstrel_sta_info *mi, int i, u8 *tp_list)
7591
{
7692
int j = MAX_THR_RATES;
7793

78-
while (j > 0 && mi->r[i].stats.cur_tp > mi->r[tp_list[j - 1]].stats.cur_tp)
94+
while (j > 0 && (minstrel_get_tp_avg(&mi->r[i]) >
95+
minstrel_get_tp_avg(&mi->r[tp_list[j - 1]])))
7996
j--;
97+
8098
if (j < MAX_THR_RATES - 1)
8199
memmove(&tp_list[j + 1], &tp_list[j], MAX_THR_RATES - (j + 1));
82100
if (j < MAX_THR_RATES)
@@ -158,8 +176,7 @@ minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
158176
{
159177
u8 tmp_tp_rate[MAX_THR_RATES];
160178
u8 tmp_prob_rate = 0;
161-
u32 usecs;
162-
int i;
179+
int i, tmp_cur_tp, tmp_prob_tp;
163180

164181
for (i = 0; i < MAX_THR_RATES; i++)
165182
tmp_tp_rate[i] = 0;
@@ -168,19 +185,9 @@ minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
168185
struct minstrel_rate *mr = &mi->r[i];
169186
struct minstrel_rate_stats *mrs = &mi->r[i].stats;
170187

171-
usecs = mr->perfect_tx_time;
172-
if (!usecs)
173-
usecs = 1000000;
174-
175188
/* Update success probabilities per rate */
176189
minstrel_calc_rate_stats(mrs);
177190

178-
/* Update throughput per rate, reset thr. below 10% success */
179-
if (mrs->prob_ewma < MINSTREL_FRAC(10, 100))
180-
mrs->cur_tp = 0;
181-
else
182-
mrs->cur_tp = mrs->prob_ewma * (1000000 / usecs);
183-
184191
/* Sample less often below the 10% chance of success.
185192
* Sample less often above the 95% chance of success. */
186193
if (mrs->prob_ewma > MINSTREL_FRAC(95, 100) ||
@@ -205,7 +212,9 @@ minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
205212
* (2) if all success probabilities < 95%, the rate with
206213
* highest success probability is chosen as max_prob_rate */
207214
if (mrs->prob_ewma >= MINSTREL_FRAC(95, 100)) {
208-
if (mrs->cur_tp >= mi->r[tmp_prob_rate].stats.cur_tp)
215+
tmp_cur_tp = minstrel_get_tp_avg(mr);
216+
tmp_prob_tp = minstrel_get_tp_avg(&mi->r[tmp_prob_rate]);
217+
if (tmp_cur_tp >= tmp_prob_tp)
209218
tmp_prob_rate = i;
210219
} else {
211220
if (mrs->prob_ewma >= mi->r[tmp_prob_rate].stats.prob_ewma)
@@ -676,11 +685,15 @@ static u32 minstrel_get_expected_throughput(void *priv_sta)
676685
{
677686
struct minstrel_sta_info *mi = priv_sta;
678687
int idx = mi->max_tp_rate[0];
688+
int tmp_cur_tp;
679689

680690
/* convert pkt per sec in kbps (1200 is the average pkt size used for
681691
* computing cur_tp
682692
*/
683-
return MINSTREL_TRUNC(mi->r[idx].stats.cur_tp) * 1200 * 8 / 1024;
693+
tmp_cur_tp = minstrel_get_tp_avg(&mi->r[idx]);
694+
tmp_cur_tp = tmp_cur_tp * 1200 * 8 / 1024;
695+
696+
return tmp_cur_tp;
684697
}
685698

686699
const struct rate_control_ops mac80211_minstrel = {

net/mac80211/rc80211_minstrel.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ struct minstrel_rate_stats {
3838
/* total attempts/success counters */
3939
u64 att_hist, succ_hist;
4040

41-
/* current EWMA of rate throughput */
42-
unsigned int cur_tp;
43-
4441
/* statistis of packet delivery probability
4542
* cur_prob - current prob within last update intervall
4643
* prob_ewma - exponential weighted moving average of prob */
@@ -137,6 +134,7 @@ void minstrel_remove_sta_debugfs(void *priv, void *priv_sta);
137134

138135
/* Recalculate success probabilities and counters for a given rate using EWMA */
139136
void minstrel_calc_rate_stats(struct minstrel_rate_stats *mrs);
137+
int minstrel_get_tp_avg(struct minstrel_rate *mr);
140138

141139
/* debugfs */
142140
int minstrel_stats_open(struct inode *inode, struct file *file);

net/mac80211/rc80211_minstrel_debugfs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ minstrel_stats_open(struct inode *inode, struct file *file)
7575
{
7676
struct minstrel_sta_info *mi = inode->i_private;
7777
struct minstrel_debugfs_info *ms;
78-
unsigned int i, tp, prob, eprob;
78+
unsigned int i, tp_avg, prob, eprob;
7979
char *p;
8080

8181
ms = kmalloc(2048, GFP_KERNEL);
@@ -105,13 +105,13 @@ minstrel_stats_open(struct inode *inode, struct file *file)
105105
p += sprintf(p, "%3u ", i);
106106
p += sprintf(p, "%6u ", mr->perfect_tx_time);
107107

108-
tp = MINSTREL_TRUNC(mrs->cur_tp / 10);
108+
tp_avg = minstrel_get_tp_avg(mr);
109109
prob = MINSTREL_TRUNC(mrs->cur_prob * 1000);
110110
eprob = MINSTREL_TRUNC(mrs->prob_ewma * 1000);
111111

112112
p += sprintf(p, " %4u.%1u %3u.%1u %3u.%1u %3u"
113113
" %3u %-3u %9llu %-9llu\n",
114-
tp / 10, tp % 10,
114+
tp_avg / 10, tp_avg % 10,
115115
eprob / 10, eprob % 10,
116116
prob / 10, prob % 10,
117117
mrs->retry_count,
@@ -144,7 +144,7 @@ minstrel_stats_csv_open(struct inode *inode, struct file *file)
144144
{
145145
struct minstrel_sta_info *mi = inode->i_private;
146146
struct minstrel_debugfs_info *ms;
147-
unsigned int i, tp, prob, eprob;
147+
unsigned int i, tp_avg, prob, eprob;
148148
char *p;
149149

150150
ms = kmalloc(2048, GFP_KERNEL);
@@ -169,13 +169,13 @@ minstrel_stats_csv_open(struct inode *inode, struct file *file)
169169
p += sprintf(p, "%u,", i);
170170
p += sprintf(p, "%u,",mr->perfect_tx_time);
171171

172-
tp = MINSTREL_TRUNC(mrs->cur_tp / 10);
172+
tp_avg = minstrel_get_tp_avg(mr);
173173
prob = MINSTREL_TRUNC(mrs->cur_prob * 1000);
174174
eprob = MINSTREL_TRUNC(mrs->prob_ewma * 1000);
175175

176176
p += sprintf(p, "%u.%u,%u.%u,%u.%u,%u,%u,%u,"
177177
"%llu,%llu,%d,%d\n",
178-
tp / 10, tp % 10,
178+
tp_avg / 10, tp_avg % 10,
179179
eprob / 10, eprob % 10,
180180
prob / 10, prob % 10,
181181
mrs->retry_count,

net/mac80211/rc80211_minstrel_ht.c

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,11 @@ minstrel_get_ratestats(struct minstrel_ht_sta *mi, int index)
314314
}
315315

316316
/*
317-
* Calculate throughput based on the average A-MPDU length, taking into account
318-
* the expected number of retransmissions and their expected length
317+
* Return current throughput based on the average A-MPDU length, taking into
318+
* account the expected number of retransmissions and their expected length
319319
*/
320-
static void
321-
minstrel_ht_calc_tp(struct minstrel_ht_sta *mi, int group, int rate)
320+
int
321+
minstrel_ht_get_tp_avg(struct minstrel_ht_sta *mi, int group, int rate)
322322
{
323323
struct minstrel_rate_stats *mrs;
324324
unsigned int nsecs = 0;
@@ -328,10 +328,8 @@ minstrel_ht_calc_tp(struct minstrel_ht_sta *mi, int group, int rate)
328328
tmp_prob_ewma = mrs->prob_ewma;
329329

330330
/* do not account throughput if sucess prob is below 10% */
331-
if (mrs->prob_ewma < MINSTREL_FRAC(10, 100)) {
332-
mrs->cur_tp = 0;
333-
return;
334-
}
331+
if (mrs->prob_ewma < MINSTREL_FRAC(10, 100))
332+
return 0;
335333

336334
/*
337335
* For the throughput calculation, limit the probability value to 90% to
@@ -346,7 +344,7 @@ minstrel_ht_calc_tp(struct minstrel_ht_sta *mi, int group, int rate)
346344
nsecs += minstrel_mcs_groups[group].duration[rate];
347345

348346
/* prob is scaled - see MINSTREL_FRAC above */
349-
mrs->cur_tp = MINSTREL_TRUNC(1000000 * ((tmp_prob_ewma * 1000) / nsecs));
347+
return MINSTREL_TRUNC(100000 * ((tmp_prob_ewma * 1000) / nsecs));
350348
}
351349

352350
/*
@@ -360,22 +358,22 @@ static void
360358
minstrel_ht_sort_best_tp_rates(struct minstrel_ht_sta *mi, u16 index,
361359
u16 *tp_list)
362360
{
363-
int cur_group, cur_idx, cur_thr, cur_prob;
364-
int tmp_group, tmp_idx, tmp_thr, tmp_prob;
361+
int cur_group, cur_idx, cur_tp_avg, cur_prob;
362+
int tmp_group, tmp_idx, tmp_tp_avg, tmp_prob;
365363
int j = MAX_THR_RATES;
366364

367365
cur_group = index / MCS_GROUP_RATES;
368366
cur_idx = index % MCS_GROUP_RATES;
369-
cur_thr = mi->groups[cur_group].rates[cur_idx].cur_tp;
367+
cur_tp_avg = minstrel_ht_get_tp_avg(mi, cur_group, cur_idx);
370368
cur_prob = mi->groups[cur_group].rates[cur_idx].prob_ewma;
371369

372370
do {
373371
tmp_group = tp_list[j - 1] / MCS_GROUP_RATES;
374372
tmp_idx = tp_list[j - 1] % MCS_GROUP_RATES;
375-
tmp_thr = mi->groups[tmp_group].rates[tmp_idx].cur_tp;
373+
tmp_tp_avg = minstrel_ht_get_tp_avg(mi, tmp_group, tmp_idx);
376374
tmp_prob = mi->groups[tmp_group].rates[tmp_idx].prob_ewma;
377-
if (cur_thr < tmp_thr ||
378-
(cur_thr == tmp_thr && cur_prob <= tmp_prob))
375+
if (cur_tp_avg < tmp_tp_avg ||
376+
(cur_tp_avg == tmp_tp_avg && cur_prob <= tmp_prob))
379377
break;
380378
j--;
381379
} while (j > 0);
@@ -396,14 +394,19 @@ minstrel_ht_set_best_prob_rate(struct minstrel_ht_sta *mi, u16 index)
396394
{
397395
struct minstrel_mcs_group_data *mg;
398396
struct minstrel_rate_stats *mrs;
399-
int tmp_group, tmp_idx, tmp_tp, tmp_prob, max_tp_group;
397+
int tmp_group, tmp_idx, tmp_tp_avg, tmp_prob;
398+
int max_tp_group, cur_tp_avg, cur_group, cur_idx;
399+
int max_group_prob_rate_group, max_group_prob_rate_idx;
400+
int max_group_prob_rate_tp_avg;
400401

402+
cur_group = index / MCS_GROUP_RATES;
403+
cur_idx = index % MCS_GROUP_RATES;
401404
mg = &mi->groups[index / MCS_GROUP_RATES];
402405
mrs = &mg->rates[index % MCS_GROUP_RATES];
403406

404407
tmp_group = mi->max_prob_rate / MCS_GROUP_RATES;
405408
tmp_idx = mi->max_prob_rate % MCS_GROUP_RATES;
406-
tmp_tp = mi->groups[tmp_group].rates[tmp_idx].cur_tp;
409+
tmp_tp_avg = minstrel_ht_get_tp_avg(mi, tmp_group, tmp_idx);
407410
tmp_prob = mi->groups[tmp_group].rates[tmp_idx].prob_ewma;
408411

409412
/* if max_tp_rate[0] is from MCS_GROUP max_prob_rate get selected from
@@ -414,9 +417,18 @@ minstrel_ht_set_best_prob_rate(struct minstrel_ht_sta *mi, u16 index)
414417
return;
415418

416419
if (mrs->prob_ewma > MINSTREL_FRAC(75, 100)) {
417-
if (mrs->cur_tp > tmp_tp)
420+
cur_tp_avg = minstrel_ht_get_tp_avg(mi, cur_group, cur_idx);
421+
if (cur_tp_avg > tmp_tp_avg)
418422
mi->max_prob_rate = index;
419-
if (mrs->cur_tp > mg->rates[mg->max_group_prob_rate].cur_tp)
423+
424+
max_group_prob_rate_group = mg->max_group_prob_rate /
425+
MCS_GROUP_RATES;
426+
max_group_prob_rate_idx = mg->max_group_prob_rate %
427+
MCS_GROUP_RATES;
428+
max_group_prob_rate_tp_avg = minstrel_ht_get_tp_avg(mi,
429+
max_group_prob_rate_group,
430+
max_group_prob_rate_idx);
431+
if (cur_tp_avg > max_group_prob_rate_tp_avg)
420432
mg->max_group_prob_rate = index;
421433
} else {
422434
if (mrs->prob_ewma > tmp_prob)
@@ -443,11 +455,11 @@ minstrel_ht_assign_best_tp_rates(struct minstrel_ht_sta *mi,
443455

444456
tmp_group = tmp_cck_tp_rate[0] / MCS_GROUP_RATES;
445457
tmp_idx = tmp_cck_tp_rate[0] % MCS_GROUP_RATES;
446-
tmp_cck_tp = mi->groups[tmp_group].rates[tmp_idx].cur_tp;
458+
tmp_cck_tp = minstrel_ht_get_tp_avg(mi, tmp_group, tmp_idx);
447459

448460
tmp_group = tmp_mcs_tp_rate[0] / MCS_GROUP_RATES;
449461
tmp_idx = tmp_mcs_tp_rate[0] % MCS_GROUP_RATES;
450-
tmp_mcs_tp = mi->groups[tmp_group].rates[tmp_idx].cur_tp;
462+
tmp_mcs_tp = minstrel_ht_get_tp_avg(mi, tmp_group, tmp_idx);
451463

452464
if (tmp_cck_tp > tmp_mcs_tp) {
453465
for(i = 0; i < MAX_THR_RATES; i++) {
@@ -466,8 +478,7 @@ static inline void
466478
minstrel_ht_prob_rate_reduce_streams(struct minstrel_ht_sta *mi)
467479
{
468480
struct minstrel_mcs_group_data *mg;
469-
struct minstrel_rate_stats *mrs;
470-
int tmp_max_streams, group;
481+
int tmp_max_streams, group, tmp_idx;
471482
int tmp_tp = 0;
472483

473484
tmp_max_streams = minstrel_mcs_groups[mi->max_tp_rate[0] /
@@ -476,11 +487,14 @@ minstrel_ht_prob_rate_reduce_streams(struct minstrel_ht_sta *mi)
476487
mg = &mi->groups[group];
477488
if (!mg->supported || group == MINSTREL_CCK_GROUP)
478489
continue;
479-
mrs = minstrel_get_ratestats(mi, mg->max_group_prob_rate);
480-
if (tmp_tp < mrs->cur_tp &&
490+
491+
tmp_idx = mg->max_group_prob_rate % MCS_GROUP_RATES;
492+
493+
if (tmp_tp < minstrel_ht_get_tp_avg(mi, group, tmp_idx) &&
481494
(minstrel_mcs_groups[group].streams < tmp_max_streams)) {
482495
mi->max_prob_rate = mg->max_group_prob_rate;
483-
tmp_tp = mrs->cur_tp;
496+
tmp_tp = minstrel_ht_get_tp_avg(mi, group,
497+
tmp_idx);
484498
}
485499
}
486500
}
@@ -541,9 +555,8 @@ minstrel_ht_update_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
541555
mrs = &mg->rates[i];
542556
mrs->retry_updated = false;
543557
minstrel_calc_rate_stats(mrs);
544-
minstrel_ht_calc_tp(mi, group, i);
545558

546-
if (!mrs->cur_tp)
559+
if (minstrel_ht_get_tp_avg(mi, group, i) == 0)
547560
continue;
548561

549562
/* Find max throughput rate set */
@@ -1302,16 +1315,18 @@ static u32 minstrel_ht_get_expected_throughput(void *priv_sta)
13021315
{
13031316
struct minstrel_ht_sta_priv *msp = priv_sta;
13041317
struct minstrel_ht_sta *mi = &msp->ht;
1305-
int i, j;
1318+
int i, j, tp_avg;
13061319

13071320
if (!msp->is_ht)
13081321
return mac80211_minstrel.get_expected_throughput(priv_sta);
13091322

13101323
i = mi->max_tp_rate[0] / MCS_GROUP_RATES;
13111324
j = mi->max_tp_rate[0] % MCS_GROUP_RATES;
13121325

1313-
/* convert cur_tp from pkt per second in kbps */
1314-
return mi->groups[i].rates[j].cur_tp * AVG_PKT_SIZE * 8 / 1024;
1326+
/* convert tp_avg from pkt per second in kbps */
1327+
tp_avg = minstrel_ht_get_tp_avg(mi, i, j) * AVG_PKT_SIZE * 8 / 1024;
1328+
1329+
return tp_avg;
13151330
}
13161331

13171332
static const struct rate_control_ops mac80211_minstrel_ht = {

net/mac80211/rc80211_minstrel_ht.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,6 @@ struct minstrel_ht_sta_priv {
121121

122122
void minstrel_ht_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir);
123123
void minstrel_ht_remove_sta_debugfs(void *priv, void *priv_sta);
124+
int minstrel_ht_get_tp_avg(struct minstrel_ht_sta *mi, int group, int rate);
124125

125126
#endif

0 commit comments

Comments
 (0)