Every station starts with the AQL limits of the radio, 5 ms low and 12 ms high, and only debugfs changes them. The driver can know better how much airtime its hardware needs queued for one station. ath11k sees how long each station's PPDUs are and when their completions come back: a station that gets a 1 ms PPDU every 2 ms needs a few milliseconds queued, and every frame queued above that waits in the hardware. Add ieee80211_sta_set_aql_limits(). The limits are capped at the radio's, so a station cannot get past the AQL threshold any more than before, also after a write to the radio's aql_txq_limit file. Limits written to the station's aql file take precedence over the driver's. The writers take active_txq_lock; ieee80211_txq_airtime_check() reads the limits with READ_ONCE(). Signed-off-by: Julius Bairaktaris --- include/net/mac80211.h | 21 +++++++++++++++++++++ net/mac80211/debugfs.c | 19 +++++++++++++++---- net/mac80211/debugfs_sta.c | 8 ++++++-- net/mac80211/sta_info.c | 37 +++++++++++++++++++++++++++++++++++++ net/mac80211/sta_info.h | 7 +++++++ net/mac80211/tx.c | 4 ++-- 6 files changed, 88 insertions(+), 8 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index f768ef9184eba..a224e74b7ac2e 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -6954,6 +6954,27 @@ ieee80211_txq_airtime_check(struct ieee80211_hw *hw, struct ieee80211_txq *txq); u32 ieee80211_txq_aql_pending(struct ieee80211_hw *hw, struct ieee80211_txq *txq); +/** + * ieee80211_sta_set_aql_limits - set the AQL limits of a station + * + * A station starts with the AQL limits of the radio. A driver that knows + * how much airtime its hardware needs queued for a station sets the + * station's own limits for an access category here. They are capped at the + * radio's limits for @ac, and @low_us at @high_us, so the radio's AQL + * threshold keeps its meaning, also when the radio's limits are changed + * through debugfs. Limits written to the station's aql debugfs file take + * precedence over these. + * + * Context: May be called in atomic context. + * + * @pubsta: the station + * @ac: the access category, IEEE80211_AC_* + * @low_us: the low limit, in usec + * @high_us: the high limit, in usec, not 0 + */ +void ieee80211_sta_set_aql_limits(struct ieee80211_sta *pubsta, u8 ac, + u32 low_us, u32 high_us); + /** * ieee80211_iter_keys - iterate keys programmed into the device * @hw: pointer obtained from ieee80211_alloc_hw() diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c index 1a472e9d8cc90..7b28e2a893da9 100644 --- a/net/mac80211/debugfs.c +++ b/net/mac80211/debugfs.c @@ -285,17 +285,28 @@ static ssize_t aql_txq_limit_write(struct file *file, guard(wiphy)(local->hw.wiphy); + spin_lock_bh(&local->active_txq_lock[ac]); local->aql_txq_limit_low[ac] = q_limit_low; local->aql_txq_limit_high[ac] = q_limit_high; list_for_each_entry(sta, &local->sta_list, list) { + struct airtime_info *air_info = &sta->airtime[ac]; + + /* the driver's limits stay within the radio's */ + if (air_info->aql_limit_drv) { + ieee80211_sta_apply_drv_aql_limits(local, air_info, ac); + continue; + } + /* If a sta has customized queue limits, keep it */ - if (sta->airtime[ac].aql_limit_low == q_limit_low_old && - sta->airtime[ac].aql_limit_high == q_limit_high_old) { - sta->airtime[ac].aql_limit_low = q_limit_low; - sta->airtime[ac].aql_limit_high = q_limit_high; + if (!air_info->aql_limit_user && + air_info->aql_limit_low == q_limit_low_old && + air_info->aql_limit_high == q_limit_high_old) { + WRITE_ONCE(air_info->aql_limit_low, q_limit_low); + WRITE_ONCE(air_info->aql_limit_high, q_limit_high); } } + spin_unlock_bh(&local->active_txq_lock[ac]); return count; } diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c index 8d6b4a1bb8d66..5c4b39fe178c2 100644 --- a/net/mac80211/debugfs_sta.c +++ b/net/mac80211/debugfs_sta.c @@ -294,8 +294,12 @@ static ssize_t sta_aql_write(struct file *file, const char __user *userbuf, if (ac >= IEEE80211_NUM_ACS) return -EINVAL; - sta->airtime[ac].aql_limit_low = q_limit_l; - sta->airtime[ac].aql_limit_high = q_limit_h; + spin_lock_bh(&sta->local->active_txq_lock[ac]); + WRITE_ONCE(sta->airtime[ac].aql_limit_low, q_limit_l); + WRITE_ONCE(sta->airtime[ac].aql_limit_high, q_limit_h); + sta->airtime[ac].aql_limit_user = true; + sta->airtime[ac].aql_limit_drv = false; + spin_unlock_bh(&sta->local->active_txq_lock[ac]); return count; } diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index e2ff3a242bb31..91c1ef0ded8f8 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -2625,6 +2625,43 @@ void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid, } EXPORT_SYMBOL(ieee80211_sta_register_airtime); +/* the limits the driver asked for, within the radio's; under active_txq_lock */ +void ieee80211_sta_apply_drv_aql_limits(struct ieee80211_local *local, + struct airtime_info *air_info, u8 ac) +{ + u32 high = min(air_info->aql_drv_high, local->aql_txq_limit_high[ac]); + u32 low = min3(air_info->aql_drv_low, high, + local->aql_txq_limit_low[ac]); + + lockdep_assert_held(&local->active_txq_lock[ac]); + + WRITE_ONCE(air_info->aql_limit_low, low); + WRITE_ONCE(air_info->aql_limit_high, high); +} + +void ieee80211_sta_set_aql_limits(struct ieee80211_sta *pubsta, u8 ac, + u32 low_us, u32 high_us) +{ + struct sta_info *sta = sta_from_pub(pubsta); + struct ieee80211_local *local = sta->local; + struct airtime_info *air_info; + + if (WARN_ON_ONCE(ac >= IEEE80211_NUM_ACS || !high_us)) + return; + + air_info = &sta->airtime[ac]; + + spin_lock_bh(&local->active_txq_lock[ac]); + if (!air_info->aql_limit_user) { + air_info->aql_drv_low = low_us; + air_info->aql_drv_high = high_us; + air_info->aql_limit_drv = true; + ieee80211_sta_apply_drv_aql_limits(local, air_info, ac); + } + spin_unlock_bh(&local->active_txq_lock[ac]); +} +EXPORT_SYMBOL(ieee80211_sta_set_aql_limits); + void __ieee80211_sta_recalc_aggregates(struct sta_info *sta, u16 active_links) { bool first = true; diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h index 5fda4771eee33..1e20b95e2ba49 100644 --- a/net/mac80211/sta_info.h +++ b/net/mac80211/sta_info.h @@ -147,8 +147,15 @@ struct airtime_info { atomic_t aql_tx_pending; /* Estimated airtime for frames pending */ u32 aql_limit_low; u32 aql_limit_high; + u32 aql_drv_low; + u32 aql_drv_high; + bool aql_limit_drv; + bool aql_limit_user; }; +void ieee80211_sta_apply_drv_aql_limits(struct ieee80211_local *local, + struct airtime_info *air_info, u8 ac); + void ieee80211_sta_update_pending_airtime(struct ieee80211_local *local, struct sta_info *sta, u8 ac, u16 tx_airtime, bool tx_completed, diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index cb9ecac25a9cf..671149eaca788 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -4329,13 +4329,13 @@ bool ieee80211_txq_airtime_check(struct ieee80211_hw *hw, sta = sta_from_pub(txq->sta); if (atomic_read(&sta->airtime[txq->ac].aql_tx_pending) < - sta->airtime[txq->ac].aql_limit_low) + READ_ONCE(sta->airtime[txq->ac].aql_limit_low)) return true; if (atomic_read(&local->aql_total_pending_airtime) < local->aql_threshold && atomic_read(&sta->airtime[txq->ac].aql_tx_pending) < - sta->airtime[txq->ac].aql_limit_high) + READ_ONCE(sta->airtime[txq->ac].aql_limit_high)) return true; return false; -- 2.53.0