Skip to contentSkip to conversation

mac80211: rework locking for txq scheduling / airtime fairness

RFC In review Felix Fietkau 2 participants 4 messages Mar 13, 2019 – Mar 14, 2019 mac80211

lore
Share & tools
lore
#0 lore raw

RFC 1/1 mac80211: rework locking for txq scheduling / airtime fairness

Holding the lock around the entire duration of tx scheduling can create some nasty lock contention, especially when processing airtime information from the tx status or the rx path.
Improve locking by only holding the active_txq_lock for lookups / scheduling list modifications.

---
 include/net/mac80211.h | 48 ++++++++++++++++--------------------------
 net/mac80211/tx.c      | 44 ++++++++++++++------------------------
 2 files changed, 34 insertions(+), 58 deletions(-)
include/net/mac80211.h +18 -30
index 3771625b7a9d..40fbd15e6c8c 100644
@@ -6269,8 +6269,6 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
  * @hw: pointer as obtained from ieee80211_alloc_hw()
  * @ac: AC number to return packets from.
  *
- * Should only be called between calls to ieee80211_txq_schedule_start()
- * and ieee80211_txq_schedule_end().
  * Returns the next txq if successful, %NULL if no queue is eligible. If a txq
  * is returned, it should be returned with ieee80211_return_txq() after the
  * driver has finished scheduling it.
@@ -6278,51 +6276,41 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
 struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac);
 
 /**
- * ieee80211_return_txq - return a TXQ previously acquired by ieee80211_next_txq()
- *
- * @hw: pointer as obtained from ieee80211_alloc_hw()
- * @txq: pointer obtained from station or virtual interface
- *
- * Should only be called between calls to ieee80211_txq_schedule_start()
- * and ieee80211_txq_schedule_end().
- */
-void ieee80211_return_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq);
-
-/**
- * ieee80211_txq_schedule_start - acquire locks for safe scheduling of an AC
+ * ieee80211_txq_schedule_start - start new scheduling round for TXQs
  *
  * @hw: pointer as obtained from ieee80211_alloc_hw()
  * @ac: AC number to acquire locks for
  *
- * Acquire locks needed to schedule TXQs from the given AC. Should be called
- * before ieee80211_next_txq() or ieee80211_return_txq().
+ * Should be called before ieee80211_next_txq() or ieee80211_return_txq().
  */
-void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac)
-	__acquires(txq_lock);
+void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac);
+
+/* (deprecated) */
+static inline void ieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac)
+{
+}
 
 /**
- * ieee80211_txq_schedule_end - release locks for safe scheduling of an AC
+ * ieee80211_schedule_txq - schedule a TXQ for transmission
  *
  * @hw: pointer as obtained from ieee80211_alloc_hw()
- * @ac: AC number to acquire locks for
+ * @txq: pointer obtained from station or virtual interface
  *
- * Release locks previously acquired by ieee80211_txq_schedule_end().
+ * Schedules a TXQ for transmission if it is not already scheduled.
  */
-void ieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac)
-	__releases(txq_lock);
+void ieee80211_schedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
 
 /**
- * ieee80211_schedule_txq - schedule a TXQ for transmission
+ * ieee80211_return_txq - return a TXQ previously acquired by ieee80211_next_txq()
  *
  * @hw: pointer as obtained from ieee80211_alloc_hw()
  * @txq: pointer obtained from station or virtual interface
- *
- * Schedules a TXQ for transmission if it is not already scheduled. Takes a
- * lock, which means it must *not* be called between
- * ieee80211_txq_schedule_start() and ieee80211_txq_schedule_end()
  */
-void ieee80211_schedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
-	__acquires(txq_lock) __releases(txq_lock);
+static inline void
+ieee80211_return_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
+{
+	ieee80211_schedule_txq(hw, txq);
+}
 
 /**
  * ieee80211_txq_may_transmit - check whether TXQ is allowed to transmit
net/mac80211/tx.c +16 -28

111 lines not on this page · raw message

Signature · 1 line
2.17.0
#1 lore raw
Quoted 3 lines · Felix Fietkau

Holding the lock around the entire duration of tx scheduling can create some nasty lock contention, especially when processing airtime information from the tx status or the rx path.

Right, I can see how that could become an issue at higher loads than what I tested with :)

Quoted 2 lines

Improve locking by only holding the active_txq_lock for lookups / scheduling list modifications.

So the (potential) issue I see with this modification is that it requires the driver to ensure that it will not interleave two different scheduling rounds for the same acno. I.e., another call to schedule_start() will reset the round counter and something needs to guarantee that this doesn't happen until the driver has actually finished the previous round.

I am not sure to what extent this would *actually* be a problem. For ath9k, for instance, there's already the in-driver chan_lock (although the call to ieee80211_txq_schedule_start() would then have to be moved into the section covered by that lock). But it does introduce an implicit dependency in the API, which should at least be documented.

If memory serves, avoiding this implicit dependency was the original reason I had for adding the full lock around everything. I can't think of any other reason right now, but if I do think of something I'll be sure to let you know :)

-Toke

#2 lore raw
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 3 lines · Felix Fietkau

Holding the lock around the entire duration of tx scheduling can create some nasty lock contention, especially when processing airtime information from the tx status or the rx path.

Right, I can see how that could become an issue at higher loads than what I tested with :)

I stumbled onto this when I was doing perf runs with mt76 (before even adding support for this API) and I noticed that a visible amount of lock contention was caused by mac80211 tx calls being blocked by mt76 tx scheduling.
I wanted to fix these issues by switching to the mac80211 txq scheduling API, but when reading the code I noticed that using this API had the very same issue I was trying to fix. That's why I made this patch :)

Quoted 10 lines
Quoted 2 lines

Improve locking by only holding the active_txq_lock for lookups / scheduling list modifications.

So the (potential) issue I see with this modification is that it requires the driver to ensure that it will not interleave two different scheduling rounds for the same acno. I.e., another call to schedule_start() will reset the round counter and something needs to guarantee that this doesn't happen until the driver has actually finished the previous round.

Quoted 5 lines

I am not sure to what extent this would *actually* be a problem. For ath9k, for instance, there's already the in-driver chan_lock (although the call to ieee80211_txq_schedule_start() would then have to be moved into the section covered by that lock). But it does introduce an implicit dependency in the API, which should at least be documented.

With ath9k it's also protected by the per-txq lock.
With ath10k it's protected by having scheduling calls come from the NAPI poll function.

Quoted 4 lines

If memory serves, avoiding this implicit dependency was the original reason I had for adding the full lock around everything. I can't think of any other reason right now, but if I do think of something I'll be sure to let you know :)

I'll change the patch to make this more explicit and resubmit. Thanks for your comments.

- Felix

#3 lore raw
Quoted 9 lines · Felix Fietkau
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 3 lines · Felix Fietkau

Holding the lock around the entire duration of tx scheduling can create some nasty lock contention, especially when processing airtime information from the tx status or the rx path.

Right, I can see how that could become an issue at higher loads than what I tested with :)

Quoted 7 lines

I stumbled onto this when I was doing perf runs with mt76 (before even adding support for this API) and I noticed that a visible amount of lock contention was caused by mac80211 tx calls being blocked by mt76 tx scheduling.
I wanted to fix these issues by switching to the mac80211 txq scheduling API, but when reading the code I noticed that using this API had the very same issue I was trying to fix. That's why I made this patch :)

Ah, I see. Well I applaud you making fixing this and switching over mt76 your solution :)

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines

Improve locking by only holding the active_txq_lock for lookups / scheduling list modifications.

So the (potential) issue I see with this modification is that it requires the driver to ensure that it will not interleave two different scheduling rounds for the same acno. I.e., another call to schedule_start() will reset the round counter and something needs to guarantee that this doesn't happen until the driver has actually finished the previous round.

Quoted 6 lines
Quoted 5 lines

I am not sure to what extent this would *actually* be a problem. For ath9k, for instance, there's already the in-driver chan_lock (although the call to ieee80211_txq_schedule_start() would then have to be moved into the section covered by that lock). But it does introduce an implicit dependency in the API, which should at least be documented.

With ath9k it's also protected by the per-txq lock.

Ah, right, that was just moved not removed entirely. Great!

Quoted 2 lines

With ath10k it's protected by having scheduling calls come from the NAPI poll function.

Cool.

Quoted 6 lines
Quoted 4 lines

If memory serves, avoiding this implicit dependency was the original reason I had for adding the full lock around everything. I can't think of any other reason right now, but if I do think of something I'll be sure to let you know :)

I'll change the patch to make this more explicit and resubmit. Thanks for your comments.

Sounds good!

-Toke