Skip to contentSkip to conversation

Implement Airtime-based Queue Limit (AQL)

PATCH Superseded Kan Yan 3 participants 7 messages Oct 10, 2019 – Oct 11, 2019

Subsystems (3)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Kan Yan

author
#0 lore raw

v3 cover Implement Airtime-based Queue Limit (AQL)

This patch series implements Airtime-based Queue Limit (AQL) in the mac80211 and Ath10k driver. It is based on an earlier version from the ChromiumOS tree[0].

This version has been tested with QCA9884 platform with 4.14 kernel. Tests show AQL is able to reduce latency by an order of magnitude in a congested environment without negative impact on the throughput.

[0] https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1703105/7

Kan Yan (2):
mac80211: Implement Airtime-based Queue Limit (AQL)
ath10k: Enable Airtime-based Queue Limit (AQL)

 drivers/net/wireless/ath/ath10k/htt_rx.c |  1 +
 drivers/net/wireless/ath/ath10k/mac.c    |  8 ++-
 drivers/net/wireless/ath/ath10k/txrx.c   | 11 +++-
 include/net/cfg80211.h                   |  7 +++
 include/net/mac80211.h                   | 43 +++++++++++++
 net/mac80211/debugfs.c                   | 78 ++++++++++++++++++++++++
 net/mac80211/debugfs_sta.c               | 43 ++++++++++---
 net/mac80211/ieee80211_i.h               |  4 ++
 net/mac80211/main.c                      |  8 ++-
 net/mac80211/sta_info.c                  | 30 +++++++++
 net/mac80211/sta_info.h                  |  4 ++
 net/mac80211/tx.c                        | 46 +++++++++++++-
 12 files changed, 263 insertions(+), 20 deletions(-)
Signature · 9 lines
Changes from v1:
 - Fix checkpatch error.
 - Keep iterate the list of active_txq until an eligible txq's deficit become non-negative in ieee80211_next_txq(), instead of break the loop after one iteration.
 - Enforce the AQL limit in ath10k's pull mode in ath10k_htt_rx_tx_fetch_ind()

Changes from v2:
 - More coding style fixes.
 - Fixed a bug that txq is not removed from the active_txqs list when txq.sta is null.
 - Removed AQL queue limit check from ieee80211_txq_may_transmit(), so at least one frame will be sent to the firmware when called from ath10k_htt_rx_tx_fetch_ind() in ath10k's poll mode.
author
#1 lore raw

PATCH v3 1/2 mac80211: Implement Airtime-based Queue Limit (AQL)

In order for the Fq_CoDel integrated in mac80211 layer operates effectively to control excessive queueing latency, the CoDel algorithm requires an accurate measure of how long the packets stays in the queue, aka sojourn time. The sojourn time measured at mac80211 layer doesn't include queueing latency in lower layer (firmware/hardware) and CoDel expects lower layer to have a short queue. However, most 802.11ac chipsets offload tasks such TX aggregation to firmware or hardware, thus have a deep lower layer queue. Without a mechanism to control the lower layer queue size, packets only stays in mac80211 layer transiently before being sent to firmware queue. As a result, the sojourn time measured by CoDel in the mac80211 layer is almost always lower than the CoDel latency target, hence CoDel does little to control the latency, even when the lower layer queue causes excessive latency.

Byte Queue limits (BQL) is commonly used to address the similar issue with wired network interface. However, this method cannot be applied directly to the wireless network interface. Byte is not a suitable measure of queue depth in the wireless network, as the data rate can vary dramatically from station to station in the same network, from a few Mbps to over Gbps.

This patch implemented an Airtime-based Queue Limit (AQL) to make CoDel works effectively with wireless drivers that utilized firmware/hardware offloading. AQL only allows each txq to release just enough packets to the lower layer to form 1-2 large aggregations to keep hardware fully utilized and keep the rest of frames in mac80211 layer to be controlled by the CoDel algorithm.

---
 include/net/cfg80211.h     |  7 ++++
 include/net/mac80211.h     | 43 +++++++++++++++++++++
 net/mac80211/debugfs.c     | 78 ++++++++++++++++++++++++++++++++++++++
 net/mac80211/debugfs_sta.c | 43 ++++++++++++++++-----
 net/mac80211/ieee80211_i.h |  4 ++
 net/mac80211/main.c        |  8 +++-
 net/mac80211/sta_info.c    | 30 +++++++++++++++
 net/mac80211/sta_info.h    |  4 ++
 net/mac80211/tx.c          | 46 ++++++++++++++++++++--
 9 files changed, 249 insertions(+), 14 deletions(-)
include/net/cfg80211.h +7 -0
index 26e2ad2c7027..05352eac82ec 100644
@@ -2499,6 +2499,13 @@ enum wiphy_params_flags {
 
 #define IEEE80211_DEFAULT_AIRTIME_WEIGHT	256
 
+/* The per TXQ firmware queue limit in airtime */
+#define IEEE80211_DEFAULT_AQL_TXQ_LIMIT_L	4000
+#define IEEE80211_DEFAULT_AQL_TXQ_LIMIT_H	8000
+
+/* The per interface airtime threshold to switch to lower queue limit */
+#define IEEE80211_AQL_THRESHOLD			24000
+
 /**
  * struct cfg80211_pmksa - PMK Security Association
  *
include/net/mac80211.h +43 -0

49 lines not on this page · raw message

net/mac80211/debugfs.c +78 -0

90 lines not on this page · raw message

net/mac80211/debugfs_sta.c +33 -10

69 lines not on this page · raw message

net/mac80211/ieee80211_i.h +4 -0
index 004e2e3adb88..c7e98ed0710d 100644
@@ -1142,6 +1142,10 @@ struct ieee80211_local {
 	u16 schedule_round[IEEE80211_NUM_ACS];
 
 	u16 airtime_flags;
+	u32 aql_txq_limit_low[IEEE80211_NUM_ACS];
+	u32 aql_txq_limit_high[IEEE80211_NUM_ACS];
+	u32 aql_threshold;
+	s32 aql_total_pending_airtime;
 
 	const struct ieee80211_ops *ops;
 
net/mac80211/main.c +7 -1
index 4c2702f128f3..750d783aae05 100644
@@ -666,8 +666,14 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len,
 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
 		INIT_LIST_HEAD(&local->active_txqs[i]);
 		spin_lock_init(&local->active_txq_lock[i]);
+		local->aql_txq_limit_low[i] = IEEE80211_DEFAULT_AQL_TXQ_LIMIT_L;
+		local->aql_txq_limit_high[i] =
+			IEEE80211_DEFAULT_AQL_TXQ_LIMIT_H;
 	}
-	local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX;
+
+	local->airtime_flags =
+		AIRTIME_USE_TX | AIRTIME_USE_RX | AIRTIME_USE_AQL;
+	local->aql_threshold = IEEE80211_AQL_THRESHOLD;
 
 	INIT_LIST_HEAD(&local->chanctx_list);
 	mutex_init(&local->chanctx_mtx);
net/mac80211/sta_info.c +30 -0
index 95eb8220e2e4..9a3db1e16a9f 100644
@@ -396,6 +396,9 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
 		skb_queue_head_init(&sta->ps_tx_buf[i]);
 		skb_queue_head_init(&sta->tx_filtered[i]);
 		sta->airtime[i].deficit = sta->airtime_weight;
+		sta->airtime[i].aql_tx_pending = 0;
+		sta->airtime[i].aql_limit_low = local->aql_txq_limit_low[i];
+		sta->airtime[i].aql_limit_high = local->aql_txq_limit_high[i];
 	}
 
 	for (i = 0; i < IEEE80211_NUM_TIDS; i++)
@@ -1894,6 +1897,33 @@ void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid,
 }
 EXPORT_SYMBOL(ieee80211_sta_register_airtime);
 
+void ieee80211_sta_update_pending_airtime(struct ieee80211_sta *pubsta, u8 tid,
+					  s32 tx_airtime)
+{
+	u8 ac = ieee80211_ac_from_tid(tid);
+	struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
+	struct ieee80211_local *local = sta->local;
+
+	spin_lock_bh(&local->active_txq_lock[ac]);
+	if (unlikely(sta->airtime[ac].aql_tx_pending + tx_airtime > S32_MAX)) {
+		WARN_ONCE(1, "TXQ pending airtime underflow: %d, %d",
+			  sta->airtime[ac].aql_tx_pending, tx_airtime);
+		sta->airtime[ac].aql_tx_pending = 0;
+	} else {
+		sta->airtime[ac].aql_tx_pending += tx_airtime;
+	}
+
+	if (unlikely(local->aql_total_pending_airtime + tx_airtime > S32_MAX)) {
+		WARN_ONCE(1, "pending airtime underflow: %d, %d",
+			  local->aql_total_pending_airtime, tx_airtime);
+		local->aql_total_pending_airtime = 0;
+	} else {
+		local->aql_total_pending_airtime += tx_airtime;
+	}
+	spin_unlock_bh(&local->active_txq_lock[ac]);
+}
+EXPORT_SYMBOL(ieee80211_sta_update_pending_airtime);
+
 int sta_info_move_state(struct sta_info *sta,
 			enum ieee80211_sta_state new_state)
 {
net/mac80211/sta_info.h +4 -0
index 3260d4234920..6ce252407b19 100644
@@ -127,11 +127,15 @@ enum ieee80211_agg_stop_reason {
 /* Debugfs flags to enable/disable use of RX/TX airtime in scheduler */
 #define AIRTIME_USE_TX		BIT(0)
 #define AIRTIME_USE_RX		BIT(1)
+#define AIRTIME_USE_AQL		BIT(2)
 
 struct airtime_info {
 	u64 rx_airtime;
 	u64 tx_airtime;
 	s64 deficit;
+	u32 aql_tx_pending; /* Estimated airtime for frames pending in queue */
+	u32 aql_limit_low;
+	u32 aql_limit_high;
 };
 
 struct sta_info;
net/mac80211/tx.c +43 -3

69 lines not on this page · raw message

Signature · 1 line
2.23.0.581.g78d2f28ef7-goog
maintainer
#2 lore raw

Re: [PATCH v3 1/2] mac80211: Implement Airtime-based Queue Limit (AQL)

Hi,

A couple of points...

First, I'd like Toke to review & ack this if possible :-)

Second, I probably won't apply this until I return from vacation (will be out next week & the week after).

Third, a couple of more comments on the code:

Quoted 1 line

+/* The per TXQ firmware queue limit in airtime */

I was pretty sure I mentioned it *somewhere*, but I think just calling this "device" or something would be more general. If you don't mind, I can edit that also (unless you have other reasons to resubmit?)

Quoted 8 lines

+/**
+ * ieee80211_sta_update_pending_airtime - update txq's estimated airtime
+ *
+ * Update the estimated total airtime of frames queued in a lower layer queue.
+ *
+ * The estimated airtime is calculated for each frame using the last reported
+ * data rate and stored in the SKB's CB. Once the frame is completed, the same
+ * airtime stored in the CB should be subtracted from a txq's pending airtime

"stored in the CB" should probably be just given as an example "(e.g. stored in the CB)"

Quoted 1 line

+ * count.

"count" is a bit odd for a time value, just remove "count"?

(again, I can fix these)

Quoted 2 lines

+/**
+ * ieee80211_txq_aql_check - check if a txq can send frame to device

I wonder if this really should even be have "aql" in the name? It's also going to return NULL if there's nothing on the TXQ, for example, right?

net/mac80211/debugfs.c static const struct file_operations aqm_ops = { · line 165

Quoted 6 lines
net/mac80211/debugfs.c +6 -0
+	len = scnprintf(buf, sizeof(buf),
+			"AC	AQL limit low	AQL limit high\n"
+			"0	%u		%u\n"
+			"1	%u		%u\n"
+			"2	%u		%u\n"
+			"3	%u		%u\n",

BK/BE/VI/VO instead of 0/1/23?

net/mac80211/debugfs.c static const struct file_operations aqm_ops = { · line 173

Quoted 8 lines
net/mac80211/debugfs.c +8 -0
+			local->aql_txq_limit_low[0],
+			local->aql_txq_limit_high[0],
+			local->aql_txq_limit_low[1],
+			local->aql_txq_limit_high[1],
+			local->aql_txq_limit_low[2],
+			local->aql_txq_limit_high[2],
+			local->aql_txq_limit_low[3],
+			local->aql_txq_limit_high[3]);

but then I guess we have to use the macros to index here too

net/mac80211/main.c struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, · line 675

Quoted 2 lines
net/mac80211/main.c +2 -0
+	local->airtime_flags =
+		AIRTIME_USE_TX | AIRTIME_USE_RX | AIRTIME_USE_AQL;

might be nicer as

airtime_flags = TX |

                 RX |
                 AQL;

but doesn't matter, just in case you have to resend anyway...

net/mac80211/sta_info.c void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid, · line 1910

Quoted 4 lines
net/mac80211/sta_info.c +4 -0
+	spin_lock_bh(&local->active_txq_lock[ac]);
+	if (unlikely(sta->airtime[ac].aql_tx_pending + tx_airtime > S32_MAX)) {
+		WARN_ONCE(1, "TXQ pending airtime underflow: %d, %d",
+			  sta->airtime[ac].aql_tx_pending, tx_airtime);

if (WARN_ONCE(..., "...", ...))

saves you the braces and the extra condition

Also, hmm, doesn't this rely on 2s complement underflow or something?

Maybe that should be

	__signed_add_overflow(aql_tx_pending, tx_airtime,
                              &aql_tx_pending) ||
        aql_tx_pending < 0

or so?

But then again, we don't really care *that* much about overflow or underflow in this code path - it's not going to be security critical.

But it seems that your code there actually can cause UB? That would be nice to avoid.

Actually, that condition can never be true, right? Wait, ok, this one can because integer promotion?

net/mac80211/sta_info.c void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid, · line 1918

Quoted 8 lines
net/mac80211/sta_info.c +8 -0
+		sta->airtime[ac].aql_tx_pending = 0;
+	} else {
+		sta->airtime[ac].aql_tx_pending += tx_airtime;
+	}
+
+	if (unlikely(local->aql_total_pending_airtime + tx_airtime > S32_MAX)) {
+		WARN_ONCE(1, "pending airtime underflow: %d, %d",
+			  local->aql_total_pending_airtime, tx_airtime);

same here

Except aql_total_pending_airtime is still defined as s32 and that causes different behaviour?

All this confuses me ... is it possible to write this more clearly?

Thanks,
johannes

#3 lore raw

Re: [PATCH v3 1/2] mac80211: Implement Airtime-based Queue Limit (AQL)

Quoted 5 lines · Johannes Berg

Hi,

A couple of points...

First, I'd like Toke to review & ack this if possible :-)

Sure, I'll look at it. I'm away the rest of this week, but should hopefully get some more time next week. It may be that it will take the form of another submission that integrates this with the previous patch I sent that put more of the calculation into mac80211 itself...

-Toke

author
#4 lore raw

Re: [PATCH v3 1/2] mac80211: Implement Airtime-based Queue Limit (AQL)

Quoted 5 lines
Quoted 1 line

+/* The per TXQ firmware queue limit in airtime */

I was pretty sure I mentioned it *somewhere*, but I think just calling this "device" or something would be more general. If you don't mind, I can edit that also (unless you have other reasons to resubmit?)

done. I will upload a new version to fix coding style issues according to your comment. Please do help
revise comment as you see fit.

Quoted 3 lines
Quoted 1 line

+ * ieee80211_txq_aql_check - check if a txq can send frame to device

I wonder if this really should even be have "aql" in the name? It's also going to return NULL if there's nothing on the TXQ, for example, right?

Renamed to ieee80211_txq_airtime_check()
This function is not for finding next eligible txq, but return a boolean to indicate if a given txq can send more packets to device. It is also called from ath10k:
static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,

                                   struct ieee80211_txq *txq)
{
       ...
        if (!ieee80211_txq_airtime_check(hw, txq))
                return false;
Quoted 2 lines

if (WARN_ONCE(..., "...", ...))
saves you the braces and the extra condition

done.

Quoted 6 lines

But then again, we don't really care *that* much about overflow or underflow in this code path - it's not going to be security critical. But it seems that your code there actually can cause UB? That would be nice to avoid.
Actually, that condition can never be true, right? Wait, ok, this one can because integer promotion?

I don't think that condition could happen. The WARN_ONCE() was added
per your earlier comment. The older version don't have underflow check and reset pending_airtime part and I didn't find any issues.

Quoted 3 lines

Except aql_total_pending_airtime is still defined as s32 and that causes different behaviour?
All this confuses me ... is it possible to write this more clearly?

I revised it to something similar to the original version, which ieee80211_sta_update_pending_airtime() takes extra parameter to indicate whether it is for a tx completion event.
void ieee80211_sta_update_pending_airtime(struct ieee80211_sta *pubsta, u8 tid,
u32 tx_airtime, bool tx_completed)
This help get rid of the problem that airtime need be signed. Also added the inline function of ieee80211_sta_register/release_pending_airtime() as you suggested.

Quoted 16 lines · Toke Høiland-Jørgensen
Quoted 5 lines · Johannes Berg

Hi,

A couple of points...

First, I'd like Toke to review & ack this if possible :-)

Sure, I'll look at it. I'm away the rest of this week, but should hopefully get some more time next week. It may be that it will take the form of another submission that integrates this with the previous patch I sent that put more of the calculation into mac80211 itself...

-Toke

maintainer
#5 lore raw

Re: [PATCH v3 1/2] mac80211: Implement Airtime-based Queue Limit (AQL)

Quoted 5 lines · Kan Yan
Quoted 3 lines
Quoted 1 line

+ * ieee80211_txq_aql_check - check if a txq can send frame to device

I wonder if this really should even be have "aql" in the name? It's also going to return NULL if there's nothing on the TXQ, for example, right?

Renamed to ieee80211_txq_airtime_check()

:)

Quoted 9 lines

This function is not for finding next eligible txq, but return a boolean to indicate if a given txq can send more packets to device. It is also called from ath10k:
static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,

                                   struct ieee80211_txq *txq)
{
       ...
        if (!ieee80211_txq_airtime_check(hw, txq))
                return false;

Sure, I get that.

I phrased this badly before because I neglected to look at the code of the function closely.

You were documenting it as

+ * Return true if the AQL's airtime limit has not been reached and the txq can
+ * continue to send more packets to the device. Otherwise return false.

but with the current implementation that's not really true. For example, if there are no packets on the TXQ at all, then the function still returns true, even if it's not true that "the txq can continue to send more packets to the device".

So I guess really what I should ask is if the documentation shouldn't be rephrased to say something like

[...] has not been reached and the TXQ is eligible to send packets to the device, regardless of whether or not it currently can or cannot (e.g. if it has no packets, or is stopped, etc.)

to make it more obvious that this really is *only* concerned about the airtime aspects.

Quoted 10 lines
Quoted 6 lines

But then again, we don't really care *that* much about overflow or underflow in this code path - it's not going to be security critical. But it seems that your code there actually can cause UB? That would be nice to avoid.
Actually, that condition can never be true, right? Wait, ok, this one can because integer promotion?

I don't think that condition could happen. The WARN_ONCE() was added
per your earlier comment. The older version don't have underflow check and reset pending_airtime part and I didn't find any issues.

Of course it will never happen with a valid driver :-)

But it seems like a very easy mistake to make - add an estimate, and later subtract the actual airtime, which may be more ...

Quoted 4 lines
Quoted 3 lines

Except aql_total_pending_airtime is still defined as s32 and that causes different behaviour?
All this confuses me ... is it possible to write this more clearly?

Quoted 8 lines

I revised it to something similar to the original version, which ieee80211_sta_update_pending_airtime() takes extra parameter to indicate whether it is for a tx completion event.
void ieee80211_sta_update_pending_airtime(struct ieee80211_sta *pubsta, u8 tid,
u32 tx_airtime, bool tx_completed)
This help get rid of the problem that airtime need be signed. Also added the inline function of ieee80211_sta_register/release_pending_airtime() as you suggested.

ok

johannes

author
#6 lore raw

PATCH v3 2/2 ath10k: Enable Airtime-based Queue Limit (AQL)

In reply to Kan Yan

Calculate the estimated airtime pending in the txqs and apply AQL to prevent excessive amounts of packets being queued in the firmware queue.

---
 drivers/net/wireless/ath/ath10k/htt_rx.c |  1 +
 drivers/net/wireless/ath/ath10k/mac.c    |  8 +++++---
 drivers/net/wireless/ath/ath10k/txrx.c   | 11 ++++++++---
 3 files changed, 14 insertions(+), 6 deletions(-)
drivers/net/wireless/ath/ath10k/htt_rx.c +1 -0
index 83a7fb68fd24..f2115b940964 100644
@@ -3053,6 +3053,7 @@ static void ath10k_htt_rx_tx_fetch_ind(struct ath10k *ar, struct sk_buff *skb)
 
 			num_msdus++;
 			num_bytes += ret;
+			may_tx = ieee80211_txq_aql_check(hw, txq);
 		}
 		ieee80211_return_txq(hw, txq, false);
 		ieee80211_txq_schedule_end(hw, txq->ac);
drivers/net/wireless/ath/ath10k/mac.c +5 -3
index 0606416dc971..b300a3c506b2 100644
@@ -3983,6 +3983,9 @@ static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
 	struct ath10k_txq *artxq = (void *)txq->drv_priv;
 
 	/* No need to get locks */
+	if (!ieee80211_txq_aql_check(hw, txq))
+		return false;
+
 	if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
 		return true;
 
@@ -4009,13 +4012,11 @@ static u16 ath10k_mac_update_airtime(struct ath10k *ar,
 {
 	struct ath10k_sta *arsta;
 	u32 pktlen;
-	u16 airtime = 0;
+	s32 airtime = 0;
 
 	if (!txq || !txq->sta)
 		return airtime;
 
-	if (test_bit(WMI_SERVICE_REPORT_AIRTIME, ar->wmi.svc_map))
-		return airtime;
 
 	spin_lock_bh(&ar->data_lock);
 	arsta = (struct ath10k_sta *)txq->sta->drv_priv;
@@ -4038,6 +4039,7 @@ static u16 ath10k_mac_update_airtime(struct ath10k *ar,
 	}
 	spin_unlock_bh(&ar->data_lock);
 
+	ieee80211_sta_register_pending_airtime(txq->sta, txq->tid, airtime);
 	return airtime;
 }
 
drivers/net/wireless/ath/ath10k/txrx.c +8 -3
index 4102df016931..739046b34d4b 100644
@@ -84,9 +84,14 @@ int ath10k_txrx_tx_unref(struct ath10k_htt *htt,
 		wake_up(&htt->empty_tx_wq);
 	spin_unlock_bh(&htt->tx_lock);
 
-	if (txq && txq->sta && skb_cb->airtime_est)
-		ieee80211_sta_register_airtime(txq->sta, txq->tid,
-					       skb_cb->airtime_est, 0);
+	if (txq && txq->sta && skb_cb->airtime_est) {
+		if (!test_bit(WMI_SERVICE_REPORT_AIRTIME, ar->wmi.svc_map))
+			ieee80211_sta_register_airtime(txq->sta, txq->tid,
+						       skb_cb->airtime_est, 0);
+
+		ieee80211_sta_release_pending_airtime(txq->sta, txq->tid,
+						      skb_cb->airtime_est);
+	}
 
 	if (ar->bus_param.dev_type != ATH10K_DEV_TYPE_HL)
 		dma_unmap_single(dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
Signature · 7 lines
2.23.0.581.g78d2f28ef7-goog


_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k