Skip to content

Commit

Permalink
mac80211: minstrel_ht: fix rounding error in throughput calculation
Browse files Browse the repository at this point in the history
On lower data rates, the throughput calculation has a significant rounding
error, causing rates like 48M and 54M OFDM to share the same throughput
value with >= 90% success probablity.

This is because the result of the division (prob_avg * 1000) / nsecs
is really small (8 in this example).

Improve accuracy by moving over some zeroes, making better use of the full
range of u32 before the division.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Link: https://lore.kernel.org/r/20210115120242.89616-10-nbd@nbd.name
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  • Loading branch information
nbd168 authored and jmberg-intel committed Jan 22, 2021
1 parent 7e2123a commit 347c298
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions net/mac80211/rc80211_minstrel_ht.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,9 @@ minstrel_ht_get_tp_avg(struct minstrel_ht_sta *mi, int group, int rate,
* (prob is scaled - see MINSTREL_FRAC above)
*/
if (prob_avg > MINSTREL_FRAC(90, 100))
return MINSTREL_TRUNC(100000 * ((MINSTREL_FRAC(90, 100) * 1000)
/ nsecs));
else
return MINSTREL_TRUNC(100000 * ((prob_avg * 1000) / nsecs));
prob_avg = MINSTREL_FRAC(90, 100);

return MINSTREL_TRUNC(100 * ((prob_avg * 1000000) / nsecs));
}

/*
Expand Down

0 comments on commit 347c298

Please sign in to comment.