Skip to content

Commit f62838b

Browse files
thuehnjmberg-intel
authored andcommitted
mac80211: unify Minstrel & Minstrel-HTs calculation of rate statistics
This patch unifies the calculation of Minstrels and Minstrel-HTs per-rate statistic. The new common function minstrel_calc_rate_stats() is called when a statistic update is performed. Signed-off-by: Thomas Huehn <[email protected]> Acked-by: Felix Fietkau <[email protected]> Signed-off-by: Johannes Berg <[email protected]>
1 parent 2cae0b6 commit f62838b

File tree

3 files changed

+32
-43
lines changed

3 files changed

+32
-43
lines changed

net/mac80211/rc80211_minstrel.c

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,32 @@ minstrel_update_rates(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
127127
rate_control_set_rates(mp->hw, mi->sta, ratetbl);
128128
}
129129

130+
/*
131+
* Recalculate success probabilities and counters for a given rate using EWMA
132+
*/
133+
void
134+
minstrel_calc_rate_stats(struct minstrel_rate_stats *mrs)
135+
{
136+
if (unlikely(mrs->attempts > 0)) {
137+
mrs->sample_skipped = 0;
138+
mrs->cur_prob = MINSTREL_FRAC(mrs->success, mrs->attempts);
139+
if (unlikely(!mrs->att_hist))
140+
mrs->probability = mrs->cur_prob;
141+
else
142+
mrs->probability = minstrel_ewma(mrs->probability,
143+
mrs->cur_prob, EWMA_LEVEL);
144+
mrs->att_hist += mrs->attempts;
145+
mrs->succ_hist += mrs->success;
146+
} else {
147+
mrs->sample_skipped++;
148+
}
149+
150+
mrs->last_success = mrs->success;
151+
mrs->last_attempts = mrs->attempts;
152+
mrs->success = 0;
153+
mrs->attempts = 0;
154+
}
155+
130156
static void
131157
minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
132158
{
@@ -146,22 +172,8 @@ minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
146172
if (!usecs)
147173
usecs = 1000000;
148174

149-
if (unlikely(mrs->attempts > 0)) {
150-
mrs->sample_skipped = 0;
151-
mrs->cur_prob = MINSTREL_FRAC(mrs->success,
152-
mrs->attempts);
153-
mrs->succ_hist += mrs->success;
154-
mrs->att_hist += mrs->attempts;
155-
mrs->probability = minstrel_ewma(mrs->probability,
156-
mrs->cur_prob,
157-
EWMA_LEVEL);
158-
} else
159-
mrs->sample_skipped++;
160-
161-
mrs->last_success = mrs->success;
162-
mrs->last_attempts = mrs->attempts;
163-
mrs->success = 0;
164-
mrs->attempts = 0;
175+
/* Update success probabilities per rate */
176+
minstrel_calc_rate_stats(mrs);
165177

166178
/* Update throughput per rate, reset thr. below 10% success */
167179
if (mrs->probability < MINSTREL_FRAC(10, 100))

net/mac80211/rc80211_minstrel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ extern const struct rate_control_ops mac80211_minstrel;
132132
void minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir);
133133
void minstrel_remove_sta_debugfs(void *priv, void *priv_sta);
134134

135+
/* Recalculate success probabilities and counters for a given rate using EWMA */
136+
void minstrel_calc_rate_stats(struct minstrel_rate_stats *mr);
137+
135138
/* debugfs */
136139
int minstrel_stats_open(struct inode *inode, struct file *file);
137140
int minstrel_stats_csv_open(struct inode *inode, struct file *file);

net/mac80211/rc80211_minstrel_ht.c

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -313,32 +313,6 @@ minstrel_get_ratestats(struct minstrel_ht_sta *mi, int index)
313313
return &mi->groups[index / MCS_GROUP_RATES].rates[index % MCS_GROUP_RATES];
314314
}
315315

316-
317-
/*
318-
* Recalculate success probabilities and counters for a rate using EWMA
319-
*/
320-
static void
321-
minstrel_calc_rate_ewma(struct minstrel_rate_stats *mr)
322-
{
323-
if (unlikely(mr->attempts > 0)) {
324-
mr->sample_skipped = 0;
325-
mr->cur_prob = MINSTREL_FRAC(mr->success, mr->attempts);
326-
if (!mr->att_hist)
327-
mr->probability = mr->cur_prob;
328-
else
329-
mr->probability = minstrel_ewma(mr->probability,
330-
mr->cur_prob, EWMA_LEVEL);
331-
mr->att_hist += mr->attempts;
332-
mr->succ_hist += mr->success;
333-
} else {
334-
mr->sample_skipped++;
335-
}
336-
mr->last_success = mr->success;
337-
mr->last_attempts = mr->attempts;
338-
mr->success = 0;
339-
mr->attempts = 0;
340-
}
341-
342316
/*
343317
* Calculate throughput based on the average A-MPDU length, taking into account
344318
* the expected number of retransmissions and their expected length
@@ -567,7 +541,7 @@ minstrel_ht_update_stats(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
567541

568542
mr = &mg->rates[i];
569543
mr->retry_updated = false;
570-
minstrel_calc_rate_ewma(mr);
544+
minstrel_calc_rate_stats(mr);
571545
minstrel_ht_calc_tp(mi, group, i);
572546

573547
if (!mr->cur_tp)

0 commit comments

Comments
 (0)