ath9k: fix various issues in the airtime-fairness implementation
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / 320-ath9k-clean-up-and-fix-ath_tx_count_airtime.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Sun, 12 Feb 2017 13:13:05 +0100
3 Subject: [PATCH] ath9k: clean up and fix ath_tx_count_airtime
4
5 ath_tx_count_airtime is doing a lot of unnecessary work:
6
7 - Redundant station lookup
8 - Redundant rcu_read_lock/unlock
9 - Useless memcpy of bf->rates
10 - Useless NULL check of bf->bf_mpdu
11 - Redundant lookup of the skb tid
12
13 Additionally, it tries to look up the mac80211 queue index from the txq,
14 which fails if the frame was delivered via the power save queue.
15
16 This patch fixes all of these issues by passing down the right set of
17 pointers instead of doing extra work
18
19 Cc: stable@vger.kernel.org
20 Fixes: 63fefa050477 ("ath9k: Introduce airtime fairness scheduling between stations")
21 Signed-off-by: Felix Fietkau <nbd@nbd.name>
22 ---
23
24 --- a/drivers/net/wireless/ath/ath9k/xmit.c
25 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
26 @@ -723,51 +723,31 @@ static bool bf_is_ampdu_not_probing(stru
27 return bf_isampdu(bf) && !(info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE);
28 }
29
30 -static void ath_tx_count_airtime(struct ath_softc *sc, struct ath_txq *txq,
31 - struct ath_buf *bf, struct ath_tx_status *ts)
32 +static void ath_tx_count_airtime(struct ath_softc *sc, struct ath_node *an,
33 + struct ath_atx_tid *tid, struct ath_buf *bf,
34 + struct ath_tx_status *ts)
35 {
36 - struct ath_node *an;
37 - struct ath_acq *acq = &sc->cur_chan->acq[txq->mac80211_qnum];
38 - struct sk_buff *skb;
39 - struct ieee80211_hdr *hdr;
40 - struct ieee80211_hw *hw = sc->hw;
41 - struct ieee80211_tx_rate rates[4];
42 - struct ieee80211_sta *sta;
43 - int i;
44 + struct ath_txq *txq = tid->txq;
45 u32 airtime = 0;
46 -
47 - skb = bf->bf_mpdu;
48 - if(!skb)
49 - return;
50 -
51 - hdr = (struct ieee80211_hdr *)skb->data;
52 - memcpy(rates, bf->rates, sizeof(rates));
53 -
54 - rcu_read_lock();
55 -
56 - sta = ieee80211_find_sta_by_ifaddr(hw, hdr->addr1, hdr->addr2);
57 - if(!sta)
58 - goto exit;
59 -
60 -
61 - an = (struct ath_node *) sta->drv_priv;
62 + int i;
63
64 airtime += ts->duration * (ts->ts_longretry + 1);
65 + for(i = 0; i < ts->ts_rateindex; i++) {
66 + int rate_dur = ath9k_hw_get_duration(sc->sc_ah, bf->bf_desc, i);
67 + airtime += rate_dur * bf->rates[i].count;
68 + }
69
70 - for(i=0; i < ts->ts_rateindex; i++)
71 - airtime += ath9k_hw_get_duration(sc->sc_ah, bf->bf_desc, i) * rates[i].count;
72 + if (sc->airtime_flags & AIRTIME_USE_TX) {
73 + int q = txq->mac80211_qnum;
74 + struct ath_acq *acq = &sc->cur_chan->acq[q];
75
76 - if (!!(sc->airtime_flags & AIRTIME_USE_TX)) {
77 spin_lock_bh(&acq->lock);
78 - an->airtime_deficit[txq->mac80211_qnum] -= airtime;
79 - if (an->airtime_deficit[txq->mac80211_qnum] <= 0)
80 - __ath_tx_queue_tid(sc, ath_get_skb_tid(sc, an, skb));
81 + an->airtime_deficit[q] -= airtime;
82 + if (an->airtime_deficit[q] <= 0)
83 + __ath_tx_queue_tid(sc, tid);
84 spin_unlock_bh(&acq->lock);
85 }
86 ath_debug_airtime(sc, an, 0, airtime);
87 -
88 -exit:
89 - rcu_read_unlock();
90 }
91
92 static void ath_tx_process_buffer(struct ath_softc *sc, struct ath_txq *txq,
93 @@ -791,13 +771,13 @@ static void ath_tx_process_buffer(struct
94
95 ts->duration = ath9k_hw_get_duration(sc->sc_ah, bf->bf_desc,
96 ts->ts_rateindex);
97 - ath_tx_count_airtime(sc, txq, bf, ts);
98
99 hdr = (struct ieee80211_hdr *) bf->bf_mpdu->data;
100 sta = ieee80211_find_sta_by_ifaddr(hw, hdr->addr1, hdr->addr2);
101 if (sta) {
102 struct ath_node *an = (struct ath_node *)sta->drv_priv;
103 tid = ath_get_skb_tid(sc, an, bf->bf_mpdu);
104 + ath_tx_count_airtime(sc, an, tid, bf, ts);
105 if (ts->ts_status & (ATH9K_TXERR_FILT | ATH9K_TXERR_XRETRY))
106 tid->clear_ps_filter = true;
107 }