blob: 1df5dec0394f4eb01b5ef8d44e76d027d98737eb [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From: Felix Fietkau <nbd@nbd.name>
2Date: Fri, 15 Jan 2021 12:15:06 +0100
3Subject: [PATCH] mac80211: minstrel_ht: fix rounding error in throughput
4 calculation
5
6On lower data rates, the throughput calculation has a significant rounding
7error, causing rates like 48M and 54M OFDM to share the same throughput
8value with >= 90% success probablity.
9
10This is because the result of the division (prob_avg * 1000) / nsecs
11is really small (8 in this example).
12
13Improve accuracy by moving over some zeroes, making better use of the full
14range of u32 before the division.
15
16Signed-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 /*