565d9bec436b6b547cc6d1c7437aa13a5139f64f
[openwrt/.git] /
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Wed, 12 Aug 2020 17:07:10 +0200
3 Subject: [PATCH] mac80211: improve AQL aggregation estimation for low data
4  rates
5
6 Links with low data rates use much smaller aggregates and are much more
7 sensitive to latency added by bufferbloat.
8 Tune the assumed aggregation length based on the tx rate duration.
9
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 ---
12
13 --- a/net/mac80211/airtime.c
14 +++ b/net/mac80211/airtime.c
15 @@ -646,27 +646,40 @@ u32 ieee80211_calc_expected_tx_airtime(s
16         if (pubsta) {
17                 struct sta_info *sta = container_of(pubsta, struct sta_info,
18                                                     sta);
19 +               struct ieee80211_rx_status stat;
20                 struct ieee80211_tx_rate *rate = &sta->tx_stats.last_rate;
21                 struct rate_info *ri = &sta->tx_stats.last_rate_info;
22 -               u32 airtime;
23 +               u32 duration, overhead;
24 +               u8 agg_shift;
25  
26 -               if (!(rate->flags & (IEEE80211_TX_RC_VHT_MCS |
27 -                                    IEEE80211_TX_RC_MCS)))
28 -                       ampdu = false;
29 +               ieee80211_fill_rx_status(&stat, hw, rate, ri, band, len);
30 +
31 +               if (stat.encoding == RX_ENC_LEGACY || !ampdu)
32 +                       return ieee80211_calc_rx_airtime(hw, &stat, len);
33  
34 +               duration = ieee80211_get_rate_duration(hw, &stat, &overhead);
35                 /*
36                  * Assume that HT/VHT transmission on any AC except VO will
37                  * use aggregation. Since we don't have reliable reporting
38 -                * of aggregation length, assume an average of 16.
39 +                * of aggregation length, assume an average size based on the
40 +                * tx rate.
41                  * This will not be very accurate, but much better than simply
42 -                * assuming un-aggregated tx.
43 +                * assuming un-aggregated tx in all cases.
44                  */
45 -               airtime = ieee80211_calc_tx_airtime_rate(hw, rate, ri, band,
46 -                                                        ampdu ? len * 16 : len);
47 -               if (ampdu)
48 -                       airtime /= 16;
49 +               if (duration > 400) /* <= VHT20 MCS2 1S */
50 +                       agg_shift = 1;
51 +               else if (duration > 250) /* <= VHT20 MCS3 1S or MCS1 2S */
52 +                       agg_shift = 2;
53 +               else if (duration > 150) /* <= VHT20 MCS5 1S or MCS3 2S */
54 +                       agg_shift = 3;
55 +               else
56 +                       agg_shift = 4;
57  
58 -               return airtime;
59 +               duration *= len;
60 +               duration /= AVG_PKT_SIZE;
61 +               duration /= 1024;
62 +
63 +               return duration + (overhead >> agg_shift);
64         }
65  
66         if (!conf)