[PATCH ath-next 2/3] wifi: ath11k: keep a lone low-rate PPDU from the rate given to mac80211
From: Julius Bairaktaris
Date: Sun Nov 29 2026 - 09:42:43 EST
mac80211 estimates the airtime of each frame it dequeues from the rate
of the station's last TX status, and AQL charges the station that
estimate. ath11k reports the rate of the station's last PPDU, so one
PPDU sent at a basic rate makes every frame dequeued until the next
PPDU statistics cost tens of times its airtime, and AQL holds the
station back for that time. On an IPQ8074 AP, 0.14 % of the data PPDUs
to a station receiving 89 Mbit/s went out at 6 Mbit/s, about 11 a
second.
Keep a running average of the station's PPDU rates, and do not report
a rate more than four times below it unless eight PPDUs in a row have
one, so that a real drop of the rate still reaches mac80211 after eight
PPDUs. The station's statistics still show the rate of each PPDU.
Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1
Signed-off-by: Julius Bairaktaris <julius@xxxxxxxxxxxxxx>
---
drivers/net/wireless/ath/ath11k/core.h | 5 ++++
drivers/net/wireless/ath/ath11k/dp_rx.c | 2 +-
drivers/net/wireless/ath/ath11k/dp_tx.c | 2 +-
drivers/net/wireless/ath/ath11k/mac.c | 37 +++++++++++++++++++++++++
drivers/net/wireless/ath/ath11k/mac.h | 2 ++
5 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/ath/ath11k/core.h b/drivers/net/wireless/ath/ath11k/core.h
index d28e0c043f5ed..16bea4c4d9bc9 100644
--- a/drivers/net/wireless/ath/ath11k/core.h
+++ b/drivers/net/wireless/ath/ath11k/core.h
@@ -533,6 +533,8 @@ struct ath11k_per_ppdu_tx_stats {
};
DECLARE_EWMA(avg_rssi, 10, 8)
+/* a bitrate in 100 kbit/s, over about the last 16 PPDUs */
+DECLARE_EWMA(txrate, 4, 16)
struct ath11k_per_peer_cfr_capture {
enum ath11k_cfr_capture_method cfr_method;
@@ -555,7 +557,10 @@ struct ath11k_sta {
struct work_struct set_4addr_wk;
struct rate_info txrate;
u32 peer_nss;
+ /* the rate given to mac80211, ath11k_mac_sta_report_txrate() */
struct rate_info last_txrate;
+ struct ewma_txrate txrate_avg;
+ u8 txrate_low;
u64 rx_duration;
u64 tx_duration;
u8 rssi_comb;
diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index 1e4080caaa80d..2c80bd8066fed 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -1511,7 +1511,7 @@ ath11k_update_per_peer_tx_stats(struct ath11k *ar,
if (tx_duration)
ieee80211_sta_register_airtime(sta, airtime_tid, tx_duration, 0);
- memcpy(&arsta->last_txrate, &arsta->txrate, sizeof(struct rate_info));
+ ath11k_mac_sta_report_txrate(arsta);
/* PPDU stats reported for mgmt packet doesn't have valid tx bytes.
* So skip peer stats update for mgmt packets.
diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.c b/drivers/net/wireless/ath/ath11k/dp_tx.c
index fc3e3cb8f8b29..db1ece088bbe4 100644
--- a/drivers/net/wireless/ath/ath11k/dp_tx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_tx.c
@@ -692,7 +692,7 @@ void ath11k_dp_tx_update_txcompl(struct ath11k *ar, struct hal_tx_status *ts)
* mac80211, which estimates airtime from it.
*/
if (ab->hw_params.single_pdev_only)
- arsta->last_txrate = arsta->txrate;
+ ath11k_mac_sta_report_txrate(arsta);
if (ath11k_debugfs_is_extd_tx_stats_enabled(ar))
ath11k_debugfs_sta_add_tx_stats(arsta, peer_stats, rate_idx);
diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
index e82efca9ac8d7..b7b9ebfacf3ec 100644
--- a/drivers/net/wireless/ath/ath11k/mac.c
+++ b/drivers/net/wireless/ath/ath11k/mac.c
@@ -6637,6 +6637,43 @@ static void ath11k_mac_wait_reconfigure(struct ath11k_base *ab)
ATH11K_RECONFIGURE_TIMEOUT_HZ);
}
+/* A PPDU rate this many times below the average is an outlier, and this many
+ * outliers in a row are the station's rate.
+ */
+#define ATH11K_TXRATE_OUTLIER_DIV 4
+#define ATH11K_TXRATE_OUTLIER_RUN 8
+
+/**
+ * ath11k_mac_sta_report_txrate() - set the rate given to mac80211
+ * @arsta: the station, with the rate of its last PPDU in txrate
+ *
+ * mac80211 estimates the airtime of each frame it hands to the driver from
+ * the rate of the last TX status, and AQL charges the station that
+ * estimate. A single PPDU sent at a rate far below the station's usual
+ * one, a basic rate for example, would multiply the charge of every frame
+ * dequeued until the next PPDU is reported. Keep such a rate from the
+ * reported one, unless ATH11K_TXRATE_OUTLIER_RUN PPDUs in a row have it.
+ *
+ * Context: holds ab->base_lock.
+ */
+void ath11k_mac_sta_report_txrate(struct ath11k_sta *arsta)
+{
+ unsigned long avg = ewma_txrate_read(&arsta->txrate_avg);
+ u32 rate = cfg80211_calculate_bitrate(&arsta->txrate);
+
+ if (!rate)
+ return;
+
+ ewma_txrate_add(&arsta->txrate_avg, rate);
+
+ if ((unsigned long)rate * ATH11K_TXRATE_OUTLIER_DIV < avg &&
+ ++arsta->txrate_low < ATH11K_TXRATE_OUTLIER_RUN)
+ return;
+
+ arsta->txrate_low = 0;
+ arsta->last_txrate = arsta->txrate;
+}
+
static int ath11k_mac_op_start(struct ieee80211_hw *hw)
{
struct ath11k *ar = hw->priv;
diff --git a/drivers/net/wireless/ath/ath11k/mac.h b/drivers/net/wireless/ath/ath11k/mac.h
index b78a357b5472e..4e9fd2efca308 100644
--- a/drivers/net/wireless/ath/ath11k/mac.h
+++ b/drivers/net/wireless/ath/ath11k/mac.h
@@ -13,6 +13,7 @@
struct ath11k;
struct ath11k_base;
+struct ath11k_sta;
struct ath11k_generic_iter {
struct ath11k *ar;
@@ -161,6 +162,7 @@ struct ath11k *ath11k_mac_get_ar_by_vdev_id(struct ath11k_base *ab, u32 vdev_id)
struct ath11k *ath11k_mac_get_ar_by_pdev_id(struct ath11k_base *ab, u32 pdev_id);
void ath11k_mac_drain_tx(struct ath11k *ar);
+void ath11k_mac_sta_report_txrate(struct ath11k_sta *arsta);
void ath11k_mac_tx_push_pending(struct ath11k *ar, u8 ac);
void ath11k_mac_peer_cleanup_all(struct ath11k *ar);
void ath11k_mac_tx_mgmt_pending_free(struct ath11k *ar);
--
2.53.0