1df5dec0394f4eb01b5ef8d44e76d027d98737eb
[openwrt/staging/ansuel.git] /
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Fri, 15 Jan 2021 12:15:06 +0100
3 Subject: [PATCH] mac80211: minstrel_ht: fix rounding error in throughput
4 calculation
5
6 On lower data rates, the throughput calculation has a significant rounding
7 error, causing rates like 48M and 54M OFDM to share the same throughput
8 value with >= 90% success probablity.
9
10 This is because the result of the division (prob_avg * 1000) / nsecs
11 is really small (8 in this example).
12
13 Improve accuracy by moving over some zeroes, making better use of the full
14 range of u32 before the division.
15
16 Signed-off-by: Felix Fietkau <nbd@nbd.name>
17 ---
18
19 --- a/net/mac80211/rc80211_minstrel_ht.c
20 +++ b/net/mac80211/rc80211_minstrel_ht.c
21 @@ -445,10 +445,9 @@ minstrel_ht_get_tp_avg(struct minstrel_h
22 * (prob is scaled - see MINSTREL_FRAC above)
23 */
24 if (prob_avg > MINSTREL_FRAC(90, 100))
25 - return MINSTREL_TRUNC(100000 * ((MINSTREL_FRAC(90, 100) * 1000)
26 - / nsecs));
27 - else
28 - return MINSTREL_TRUNC(100000 * ((prob_avg * 1000) / nsecs));
29 + prob_avg = MINSTREL_FRAC(90, 100);
30 +
31 + return MINSTREL_TRUNC(100 * ((prob_avg * 1000000) / nsecs));
32 }
33
34 /*