a0548d9d057aaed80611834656248b1a2673af73
[oweals/openwrt.git] /
1 From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= <toke@redhat.com>
2 Date: Mon, 18 Nov 2019 22:06:10 -0800
3 Subject: [PATCH] mac80211: Use Airtime-based Queue Limits (AQL) on packet
4  dequeue
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 The previous commit added the ability to throttle stations when they queue
10 too much airtime in the hardware. This commit enables the functionality by
11 calculating the expected airtime usage of each packet that is dequeued from
12 the TXQs in mac80211, and accounting that as pending airtime.
13
14 The estimated airtime for each skb is stored in the tx_info, so we can
15 subtract the same amount from the running total when the skb is freed or
16 recycled. The throttling mechanism relies on this accounting to be
17 accurate (i.e., that we are not freeing skbs without subtracting any
18 airtime they were accounted for), so we put the subtraction into
19 ieee80211_report_used_skb(). As an optimisation, we also subtract the
20 airtime on regular TX completion, zeroing out the value stored in the
21 packet afterwards, to avoid having to do an expensive lookup of the station
22 from the packet data on every packet.
23
24 This patch does *not* include any mechanism to wake a throttled TXQ again,
25 on the assumption that this will happen anyway as a side effect of whatever
26 freed the skb (most commonly a TX completion).
27
28 Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
29 Link: https://lore.kernel.org/r/20191119060610.76681-5-kyan@google.com
30 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
31 ---
32
33 --- a/include/net/mac80211.h
34 +++ b/include/net/mac80211.h
35 @@ -1060,6 +1060,22 @@ struct ieee80211_tx_info {
36         };
37  };
38  
39 +static inline u16
40 +ieee80211_info_set_tx_time_est(struct ieee80211_tx_info *info, u16 tx_time_est)
41 +{
42 +       /* We only have 10 bits in tx_time_est, so store airtime
43 +        * in increments of 4us and clamp the maximum to 2**12-1
44 +        */
45 +       info->tx_time_est = min_t(u16, tx_time_est, 4095) >> 2;
46 +       return info->tx_time_est << 2;
47 +}
48 +
49 +static inline u16
50 +ieee80211_info_get_tx_time_est(struct ieee80211_tx_info *info)
51 +{
52 +       return info->tx_time_est << 2;
53 +}
54 +
55  /**
56   * struct ieee80211_tx_status - extended tx staus info for rate control
57   *
58 --- a/net/mac80211/status.c
59 +++ b/net/mac80211/status.c
60 @@ -670,12 +670,26 @@ static void ieee80211_report_used_skb(st
61                                       struct sk_buff *skb, bool dropped)
62  {
63         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
64 +       u16 tx_time_est = ieee80211_info_get_tx_time_est(info);
65         struct ieee80211_hdr *hdr = (void *)skb->data;
66         bool acked = info->flags & IEEE80211_TX_STAT_ACK;
67  
68         if (dropped)
69                 acked = false;
70  
71 +       if (tx_time_est) {
72 +               struct sta_info *sta;
73 +
74 +               rcu_read_lock();
75 +
76 +               sta = sta_info_get_by_addrs(local, hdr->addr1, hdr->addr2);
77 +               ieee80211_sta_update_pending_airtime(local, sta,
78 +                                                    skb_get_queue_mapping(skb),
79 +                                                    tx_time_est,
80 +                                                    true);
81 +               rcu_read_unlock();
82 +       }
83 +
84         if (info->flags & IEEE80211_TX_INTFL_MLME_CONN_TX) {
85                 struct ieee80211_sub_if_data *sdata;
86  
87 @@ -885,6 +899,7 @@ static void __ieee80211_tx_status(struct
88         struct ieee80211_bar *bar;
89         int shift = 0;
90         int tid = IEEE80211_NUM_TIDS;
91 +       u16 tx_time_est;
92  
93         rates_idx = ieee80211_tx_get_rates(hw, info, &retry_count);
94  
95 @@ -996,6 +1011,17 @@ static void __ieee80211_tx_status(struct
96                         ieee80211_sta_register_airtime(&sta->sta, tid,
97                                                        info->status.tx_time, 0);
98  
99 +               if ((tx_time_est = ieee80211_info_get_tx_time_est(info)) > 0) {
100 +                       /* Do this here to avoid the expensive lookup of the sta
101 +                        * in ieee80211_report_used_skb().
102 +                        */
103 +                       ieee80211_sta_update_pending_airtime(local, sta,
104 +                                                            skb_get_queue_mapping(skb),
105 +                                                            tx_time_est,
106 +                                                            true);
107 +                       ieee80211_info_set_tx_time_est(info, 0);
108 +               }
109 +
110                 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
111                         if (acked) {
112                                 if (sta->status_stats.lost_packets)
113 --- a/net/mac80211/tx.c
114 +++ b/net/mac80211/tx.c
115 @@ -3559,6 +3559,9 @@ struct sk_buff *ieee80211_tx_dequeue(str
116  
117         WARN_ON_ONCE(softirq_count() == 0);
118  
119 +       if (!ieee80211_txq_airtime_check(hw, txq))
120 +               return NULL;
121 +
122  begin:
123         spin_lock_bh(&fq->lock);
124  
125 @@ -3687,6 +3690,21 @@ begin:
126         }
127  
128         IEEE80211_SKB_CB(skb)->control.vif = vif;
129 +
130 +       if (local->airtime_flags & AIRTIME_USE_AQL) {
131 +               u32 airtime;
132 +
133 +               airtime = ieee80211_calc_expected_tx_airtime(hw, vif, txq->sta,
134 +                                                            skb->len);
135 +               if (airtime) {
136 +                       airtime = ieee80211_info_set_tx_time_est(info, airtime);
137 +                       ieee80211_sta_update_pending_airtime(local, tx.sta,
138 +                                                            txq->ac,
139 +                                                            airtime,
140 +                                                            false);
141 +               }
142 +       }
143 +
144         return skb;
145  
146  out: