1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Mon, 20 Jun 2022 20:52:50 +0200
3 Subject: [PATCH] mac80211: keep recently active tx queues in scheduling
6 This allows proper deficit accounting to ensure that they don't carry their
7 deficit until the next time they become active
9 Signed-off-by: Felix Fietkau <nbd@nbd.name>
12 --- a/net/mac80211/ieee80211_i.h
13 +++ b/net/mac80211/ieee80211_i.h
14 @@ -83,6 +83,13 @@ extern const u8 ieee80211_ac_to_qos_mask
16 #define IEEE80211_MAX_NAN_INSTANCE_ID 255
20 + * Keep a station's queues on the active list for deficit accounting purposes
21 + * if it was active or queued during the last 100ms
23 +#define AIRTIME_ACTIVE_DURATION (HZ / 10)
25 struct ieee80211_bss {
26 u32 device_ts_beacon, device_ts_presp;
28 --- a/net/mac80211/sta_info.h
29 +++ b/net/mac80211/sta_info.h
30 @@ -138,6 +138,7 @@ enum ieee80211_agg_stop_reason {
36 atomic_t aql_tx_pending; /* Estimated airtime for frames pending */
38 --- a/net/mac80211/tx.c
39 +++ b/net/mac80211/tx.c
40 @@ -3824,6 +3824,36 @@ static inline s32 ieee80211_sta_deficit(
41 return air_info->deficit - atomic_read(&air_info->aql_tx_pending);
45 +ieee80211_txq_set_active(struct txq_info *txqi)
47 + struct sta_info *sta;
52 + sta = container_of(txqi->txq.sta, struct sta_info, sta);
53 + sta->airtime[txqi->txq.ac].last_active = (u32)jiffies;
57 +ieee80211_txq_keep_active(struct txq_info *txqi)
59 + struct sta_info *sta;
65 + sta = container_of(txqi->txq.sta, struct sta_info, sta);
66 + if (ieee80211_sta_deficit(sta, txqi->txq.ac) >= 0)
69 + diff = (u32)jiffies - sta->airtime[txqi->txq.ac].last_active;
71 + return diff <= AIRTIME_ACTIVE_DURATION;
74 struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac)
76 struct ieee80211_local *local = hw_to_local(hw);
77 @@ -3870,7 +3900,6 @@ struct ieee80211_txq *ieee80211_next_txq
82 if (txqi->schedule_round == local->schedule_round[ac])
85 @@ -3890,12 +3919,13 @@ void __ieee80211_schedule_txq(struct iee
87 struct ieee80211_local *local = hw_to_local(hw);
88 struct txq_info *txqi = to_txq_info(txq);
91 spin_lock_bh(&local->active_txq_lock[txq->ac]);
93 + has_queue = force || txq_has_queue(txq);
94 if (list_empty(&txqi->schedule_order) &&
95 - (force || !skb_queue_empty(&txqi->frags) ||
96 - txqi->tin.backlog_packets)) {
97 + (has_queue || ieee80211_txq_keep_active(txqi))) {
98 /* If airtime accounting is active, always enqueue STAs at the
99 * head of the list to ensure that they only get moved to the
100 * back by the airtime DRR scheduler once they have a negative
101 @@ -3903,7 +3933,7 @@ void __ieee80211_schedule_txq(struct iee
102 * get immediately moved to the back of the list on the next
103 * call to ieee80211_next_txq().
105 - if (txqi->txq.sta && local->airtime_flags &&
106 + if (txqi->txq.sta && local->airtime_flags && has_queue &&
107 wiphy_ext_feature_isset(local->hw.wiphy,
108 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
109 list_add(&txqi->schedule_order,
110 @@ -3911,6 +3941,8 @@ void __ieee80211_schedule_txq(struct iee
112 list_add_tail(&txqi->schedule_order,
113 &local->active_txqs[txq->ac]);
115 + ieee80211_txq_set_active(txqi);
118 spin_unlock_bh(&local->active_txq_lock[txq->ac]);