mac80211: Switch to a virtual time-based airtime scheduler
Subsystems (2)
PATCH 1/4 mac80211: Switch to a virtual time-based airtime scheduler
From: Toke Høiland-Jørgensen <[email protected]>
This switches the airtime scheduler in mac80211 to use a virtual time-based scheduler instead of the round-robin scheduler used before. This has a couple of advantages:
- No need to sync up the round-robin scheduler in firmware/hardware with the round-robin airtime scheduler.
- If several stations are eligible for transmission we can schedule both of them; no need to hard-block the scheduling rotation until the head of the queue has used up its quantum.
- The check of whether a station is eligible for transmission becomes simpler (in ieee80211_txq_may_transmit()).
The drawback is that scheduling becomes slightly more expensive, as we need to maintain an rbtree of TXQs sorted by virtual time. This means that ieee80211_register_airtime() becomes O(logN) in the number of currently scheduled TXQs. However, hopefully this number rarely grows too big (it's only TXQs currently backlogged, not all associated stations), so it shouldn't be too big of an issue.
--- net/mac80211/debugfs.c | 48 +++++++++- net/mac80211/debugfs_sta.c | 16 ++-- net/mac80211/ieee80211_i.h | 14 ++- net/mac80211/main.c | 2 +- net/mac80211/sta_info.c | 19 +++- net/mac80211/sta_info.h | 3 +- net/mac80211/tx.c | 217 +++++++++++++++++++++++++++++---------------- 7 files changed, 223 insertions(+), 96 deletions(-)
net/mac80211/debugfs.c +46 -2
@@ -150,6 +150,46 @@ static ssize_t aqm_write(struct file *file, .llseek = default_llseek, }; +static ssize_t airtime_read (struct file *file, +char __user *user_buf, +size_t count, +loff_t *ppos) +{ +struct ieee80211_local *local = file->private_data; +char buf[200 ]; +u64 v_t[IEEE80211_NUM_ACS ]; +u64 wt[IEEE80211_NUM_ACS ]; +int len =0 , ac; + +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); + v_t[ac] = local->airtime_v_t[ac]; + wt[ac] = local->airtime_weight_sum[ac]; +spin_unlock_bh (&local->active_txq_lock[ac]); + } + len =scnprintf (buf,sizeof (buf), +"\tVO VI BE BK\n" +"Virt-t\t%-10llu %-10llu %-10llu %-10llu\n" +"Weight\t%-10llu %-10llu %-10llu %-10llu\n" , + v_t[0 ], + v_t[1 ], + v_t[2 ], + v_t[3 ], + wt[0 ], + wt[1 ], + wt[2 ], + wt[3 ]); + +return simple_read_from_buffer (user_buf, count, ppos, + buf, len); +} + +static const struct file_operations airtime_ops = { + .read = airtime_read, + .open = simple_open, + .llseek = default_llseek, +}; +#ifdef CONFIG_PM static ssize_t reset_write (struct file *file,const char __user *user_buf,size_t count,loff_t *ppos)
@@ -386,8 +426,12 @@ void debugfs_hw_add(struct ieee80211_local *local)if (local->ops->wake_tx_queue)DEBUGFS_ADD_MODE (aqm,0600 ); -debugfs_create_u16 ("airtime_flags" ,0600 , - phyd, &local->airtime_flags); +if (wiphy_ext_feature_isset (local->hw.wiphy, +NL80211_EXT_FEATURE_AIRTIME_FAIRNESS )) { +DEBUGFS_ADD_MODE (airtime,0600 ); +debugfs_create_u16 ("airtime_flags" ,0600 , + phyd, &local->airtime_flags); + } statsd =debugfs_create_dir ("statistics" , phyd);
net/mac80211/debugfs_sta.c +8 -8
@@ -203,7 +203,7 @@ static ssize_t sta_airtime_read(struct file *file, char __user *userbuf,size_t bufsz =200 ;char *buf =kzalloc (bufsz,GFP_KERNEL ), *p = buf;u64 rx_airtime =0 , tx_airtime =0 ; -s64 deficit[IEEE80211_NUM_ACS ]; +u64 v_t[IEEE80211_NUM_ACS ];ssize_t rv;int ac;
@@ -214,20 +214,20 @@ static ssize_t sta_airtime_read(struct file *file, char __user *userbuf,spin_lock_bh (&local->active_txq_lock[ac]); rx_airtime += sta->airtime[ac].rx_airtime; tx_airtime += sta->airtime[ac].tx_airtime; - deficit[ac] = sta->airtime[ac].deficit; + v_t[ac] = sta->airtime[ac].v_t;spin_unlock_bh (&local->active_txq_lock[ac]); } p +=scnprintf (p, bufsz + buf - p,"RX: %llu us\nTX: %llu us\nWeight: %u\n" -"Deficit: VO: %lld us VI: %lld us BE: %lld us BK: %lld us\n" , +"Virt-T: VO: %lld us VI: %lld us BE: %lld us BK: %lld us\n" , rx_airtime, tx_airtime, sta->airtime_weight, - deficit[0 ], - deficit[1 ], - deficit[2 ], - deficit[3 ]); + v_t[0 ], + v_t[1 ], + v_t[2 ], + v_t[3 ]); rv =simple_read_from_buffer (userbuf, count, ppos, buf, p - buf);kfree (buf);
@@ -245,7 +245,7 @@ static ssize_t sta_airtime_write(struct file *file, const char __user *userbuf,spin_lock_bh (&local->active_txq_lock[ac]); sta->airtime[ac].rx_airtime =0 ; sta->airtime[ac].tx_airtime =0 ; - sta->airtime[ac].deficit = sta->airtime_weight; + sta->airtime[ac].v_t =0 ;spin_unlock_bh (&local->active_txq_lock[ac]); }
net/mac80211/ieee80211_i.h +10 -4
@@ -846,8 +846,7 @@ struct txq_info {struct codel_vars def_cvars;struct codel_stats cstats;struct sk_buff_head frags; -struct list_head schedule_order; -u16 schedule_round; +struct rb_node schedule_order;unsigned long flags;/* keep last! */
@@ -1141,8 +1140,10 @@ struct ieee80211_local {/* protects active_txqs and txqi->schedule_order */ spinlock_t active_txq_lock[IEEE80211_NUM_ACS ]; -struct list_head active_txqs[IEEE80211_NUM_ACS ]; -u16 schedule_round[IEEE80211_NUM_ACS ]; +struct rb_root_cached active_txqs[IEEE80211_NUM_ACS ]; +struct rb_node *schedule_pos[IEEE80211_NUM_ACS ]; +u64 airtime_v_t[IEEE80211_NUM_ACS ]; +u64 airtime_weight_sum[IEEE80211_NUM_ACS ];u16 airtime_flags;
@@ -1779,6 +1780,11 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, const u8 *buf, size_t len, const u8 *dest, __be16 proto, bool unencrypted); +void ieee80211_resort_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq); +void ieee80211_unschedule_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq); +/* HT */ void ieee80211_apply_htcap_overrides (struct ieee80211_sub_if_data *sdata,struct ieee80211_sta_ht_cap *ht_cap);
net/mac80211/main.c +1 -1
@@ -666,7 +666,7 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len,spin_lock_init (&local->queue_stop_reason_lock);for (i =0 ; i <IEEE80211_NUM_ACS ; i++) { -INIT_LIST_HEAD (&local->active_txqs[i]); + local->active_txqs[i] =RB_ROOT_CACHED ;spin_lock_init (&local->active_txq_lock[i]); } local->airtime_flags =AIRTIME_USE_TX |AIRTIME_USE_RX ;
net/mac80211/sta_info.c +16 -3
@@ -389,7 +389,6 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,for (i =0 ; i <IEEE80211_NUM_ACS ; i++) {skb_queue_head_init (&sta->ps_tx_buf[i]);skb_queue_head_init (&sta->tx_filtered[i]); - sta->airtime[i].deficit = sta->airtime_weight; }for (i =0 ; i <IEEE80211_NUM_TIDS ; i++)
@@ -1831,18 +1830,32 @@ void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid, { struct sta_info *sta = container_of(pubsta, struct sta_info, sta);struct ieee80211_local *local = sta->sdata->local; +struct ieee80211_txq *txq = sta->sta.txq[tid];u8 ac =ieee80211_ac_from_tid (tid); -u32 airtime =0 ; +u64 airtime =0 , weight_sum; + +if (!txq) +return ;if (sta->local->airtime_flags &AIRTIME_USE_TX ) airtime += tx_airtime;if (sta->local->airtime_flags &AIRTIME_USE_RX ) airtime += rx_airtime; +/* Weights scale so the unit weight is 256 */ + airtime <<=8 ; +spin_lock_bh (&local->active_txq_lock[ac]); + sta->airtime[ac].tx_airtime += tx_airtime; sta->airtime[ac].rx_airtime += rx_airtime; - sta->airtime[ac].deficit -= airtime; + + weight_sum = local->airtime_weight_sum[ac] ?: sta->airtime_weight; + + local->airtime_v_t[ac] += airtime / weight_sum; + sta->airtime[ac].v_t += airtime / sta->airtime_weight; +ieee80211_resort_txq (&local->hw, txq); +spin_unlock_bh (&local->active_txq_lock[ac]); }EXPORT_SYMBOL (ieee80211_sta_register_airtime);
net/mac80211/sta_info.h +2 -1
@@ -130,11 +130,12 @@ 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_GRACE 500/* usec of grace period before reset */ struct airtime_info {u64 rx_airtime;u64 tx_airtime; -s64 deficit; +u64 v_t; };struct sta_info ;
net/mac80211/tx.c +140 -77
295 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 2/4 mac80211: defer txqs removal from rbtree
In a loop txqs dequeue scenario, if the first txq in the rbtree gets removed from rbtree immediately in the ieee80211_return_txq(), the loop will break soon in the ieee80211_next_txq() due to schedule_pos not leading to the second txq in the rbtree. Thus, defering the removal right before the end of this schedule round.
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)
include/net/mac80211.h +14 -2
@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 +static inline void ieee80211_rate_set_vht (struct ieee80211_tx_rate *rate,u8 mcs,u8 nss) {
@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,* @ac: AC number to return packets from. * * Should only be called between calls to ieee80211_txq_schedule_start() -* and ieee80211_txq_schedule_end(). +* and ieee80211_txq_schedule_end(). If the txq is empty, it will be added +* to a remove list and get removed later. * 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.
@@ -6268,7 +6271,8 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac)* @hw: pointer as obtained from ieee80211_alloc_hw() * @ac: AC number to acquire locks for * -* Release locks previously acquired by ieee80211_txq_schedule_end(). +* Release locks previously acquired by ieee80211_txq_schedule_end(). Check +* and remove the empty txq from rb-tree. */ void ieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac) __releases(txq_lock);
@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq)__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed to transmit * * This function is used to check whether given txq is allowed to transmit by
net/mac80211/ieee80211_i.h +3 -0
@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */
@@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;
net/mac80211/main.c +6 -0
@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len,for (i =0 ; i <IEEE80211_NUM_ACS ; i++) { local->active_txqs[i] =RB_ROOT_CACHED ; +INIT_LIST_HEAD (&local->remove_list[i]);spin_lock_init (&local->active_txq_lock[i]); } local->airtime_flags =AIRTIME_USE_TX |AIRTIME_USE_RX ; +timer_setup (&local->remove_timer, ieee80211_txqs_check,0 ); +mod_timer (&local->remove_timer, + jiffies +msecs_to_jiffies (IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS )); +INIT_LIST_HEAD (&local->chanctx_list);mutex_init (&local->chanctx_mtx);
@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif
net/mac80211/tx.c +60 -3
102 lines not on this page · raw message
Signature · 7 lines
1.9.1 _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 9 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the rbtree gets removed from rbtree immediately in the
ieee80211_return_txq(), the loop will break soon in theieee80211_next_txq()due toschedule_posnot leading to the second txq in the rbtree. Thus, defering the removal right before the end of this schedule round.Co-developed-by Yibo Zhao <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>
I didn't write this patch, so please don't use my sign-off. I'll add ack or review tags as appropriate in reply; but a few comments first:
Quoted 193 lines
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)include/net/mac80211.h +14
-2@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 +static inline void ieee80211_rate_set_vht (struct ieee80211_tx_rate *rate,u8 mcs,u8 nss) {@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,* @ac: AC number to return packets from. * * Should only be called between calls to ieee80211_txq_schedule_start() -* and ieee80211_txq_schedule_end(). +* and ieee80211_txq_schedule_end(). If the txq is empty, it will be added +* to a remove list and get removed later. * 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. @@ -6268,7 +6271,8 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac)* @hw: pointer as obtained from ieee80211_alloc_hw() * @ac: AC number to acquire locks for * -* Release locks previously acquired by ieee80211_txq_schedule_end(). +* Release locks previously acquired by ieee80211_txq_schedule_end(). Check +* and remove the empty txq from rb-tree. */ void ieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac) __releases(txq_lock);@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq)__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed to transmit * * This function is used to check whether given txq is allowed to transmit by net/mac80211/ieee80211_i.h +3
-0@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */ @@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;net/mac80211/main.c +6
-0@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len,for (i =0 ; i <IEEE80211_NUM_ACS ; i++) { local->active_txqs[i] =RB_ROOT_CACHED ; +INIT_LIST_HEAD (&local->remove_list[i]);spin_lock_init (&local->active_txq_lock[i]); } local->airtime_flags =AIRTIME_USE_TX |AIRTIME_USE_RX ; +timer_setup (&local->remove_timer, ieee80211_txqs_check,0 ); +mod_timer (&local->remove_timer, + jiffies +msecs_to_jiffies (IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS )); +INIT_LIST_HEAD (&local->chanctx_list);mutex_init (&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif net/mac80211/tx.c +47
-3@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);RB_CLEAR_NODE (&txqi->schedule_order); +INIT_LIST_HEAD (&txqi->candidate); txqi->txq.vif = &sdata->vif;@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct ieee80211_hw *hw,spin_lock_bh (&local->active_txq_lock[ac]); +if (!list_empty (&txqi->candidate)) +list_del_init (&txqi->candidate); +if (!RB_EMPTY_NODE (&txqi->schedule_order)) goto out;@@ -3783,6 +3787,20 @@ static void __ieee80211_unschedule_txq(struct ieee80211_hw *hw,RB_CLEAR_NODE (&txqi->schedule_order); } +void ieee80211_remove_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct txq_info *txqi =to_txq_info (txq); + +lockdep_assert_held (&local->active_txq_lock[txq->ac]); + +if (!RB_EMPTY_NODE (&txqi->schedule_order)) { +__ieee80211_unschedule_txq (hw, txq); +list_del_init (&txqi->candidate); + } +} + void ieee80211_unschedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq) __acquires(txq_lock) __releases(txq_lock)@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(struct ieee80211_hw *hw,struct ieee80211_local *local =hw_to_local (hw);spin_lock_bh (&local->active_txq_lock[txq->ac]); -__ieee80211_unschedule_txq (hw, txq); +ieee80211_remove_txq (hw, txq);spin_unlock_bh (&local->active_txq_lock[txq->ac]); }@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct ieee80211_hw *hw,lockdep_assert_held (&local->active_txq_lock[txq->ac]);if (!RB_EMPTY_NODE (&txqi->schedule_order) && - (skb_queue_empty (&txqi->frags) && !txqi->tin.backlog_packets)) -__ieee80211_unschedule_txq (hw, txq); + !txq_has_queue (&txqi->txq) && +list_empty (&txqi->candidate)) +list_add_tail (&txqi->candidate, &local->remove_list[txq->ac]); + }EXPORT_SYMBOL (ieee80211_return_txq); +void __ieee80211_check_txqs (struct ieee80211_local *local,int ac) +{ +struct txq_info *iter, *tmp; +struct sta_info *sta; + +lockdep_assert_held (&local->active_txq_lock[ac]); + +list_for_each_entry_safe (iter, tmp, &local->remove_list[ac], + candidate) { + sta = container_of(iter->txq.sta, struct sta_info, sta); + +if (txq_has_queue (&iter->txq)) +list_del_init (&iter->candidate); +else +ieee80211_remove_txq (&local->hw, &iter->txq); + } +} + +void ieee80211_txqs_check (struct timer_list *t) +{ +struct ieee80211_local *local =from_timer (local, t, remove_timer); +struct txq_info *iter, *tmp; +struct sta_info *sta; +int ac;
net/mac80211/tx.c void ieee80211_return_txq(struct ieee80211_hw *hw, · line 3864
Quoted 10 lines
net/mac80211/tx.c +10
-0+ +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +__ieee80211_check_txqs (local, ac); +spin_unlock_bh (&local->active_txq_lock[ac]); + } + +mod_timer (&local->remove_timer, + jiffies +msecs_to_jiffies (IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS )); +}
I'll ask the same as I did last time (where you told me to hold off until this round):
Why do you need the timer and the periodic check? If TXQs are added to the remove list during the scheduling run, and __ieee80211_check_txqs() is run from schedule_end(), isn't that sufficient to clear the list?
-Toke
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 243 lines · Toke Høiland-Jørgensen
Quoted 9 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the rbtree gets removed from rbtree immediately in the
ieee80211_return_txq(), the loop will break soon in theieee80211_next_txq()due toschedule_posnot leading to the second txq in the rbtree. Thus, defering the removal right before the end of this schedule round.Co-developed-by Yibo Zhao <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off. I'll add ack or review tags as appropriate in reply; but a few comments first:
Quoted 214 lines
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)include/net/mac80211.h +2
-0@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 +static inline void ieee80211_rate_set_vht (struct ieee80211_tx_rate *rate,u8 mcs,u8 nss){
include/net/mac80211.h +1
-1@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(structieee80211_hw *hw, * @ac: AC number to return packets from. * * Should only be called between calls toieee80211_txq_schedule_start () - * and ieee80211_txq_schedule_end(). + * and ieee80211_txq_schedule_end(). If the txq is empty, it will beadded
+ * to a remove list and get removed later.
* Returns the next txq if successful, %NULL if no queue is eligible.
If a txq
* is returned, it should be returned withieee80211_return_txq()
after the
* driver has finished scheduling it.include/net/mac80211.h +1
-1@@ -6268,7 +6271,8 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) * @hw: pointer as obtained from ieee80211_alloc_hw() * @ac: AC number to acquire locks for * - * Release locks previously acquired by ieee80211_txq_schedule_end(). + * Release locks previously acquired by ieee80211_txq_schedule_end().Check
+ * and remove the empty txq from rb-tree.
*/
voidieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac)include/net/mac80211.h +8
-0__releases (txq_lock);@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq)__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed to transmit
*
* This function is used to check whether given txq is allowed to
transmit bynet/mac80211/ieee80211_i.h +3
-0@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */ @@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;net/mac80211/main.c +5
-0@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, for (i = 0; i < IEEE80211_NUM_ACS; i++) { local->active_txqs[i] = RB_ROOT_CACHED; + INIT_LIST_HEAD(&local->remove_list[i]); spin_lock_init(&local->active_txq_lock[i]); } local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX; + timer_setup(&local->remove_timer, ieee80211_txqs_check, 0); + mod_timer(&local->remove_timer, + jiffies + msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); + INIT_LIST_HEAD(&local->chanctx_list);net/mac80211/main.c +1
-0mutex_init (&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif
net/mac80211/tx.c +18
-0@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);RB_CLEAR_NODE (&txqi->schedule_order); +INIT_LIST_HEAD (&txqi->candidate); txqi->txq.vif = &sdata->vif;@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct ieee80211_hw *hw,spin_lock_bh (&local->active_txq_lock[ac]); +if (!list_empty (&txqi->candidate)) +list_del_init (&txqi->candidate); +if (!RB_EMPTY_NODE (&txqi->schedule_order)) goto out;@@ -3783,6 +3787,20 @@ static void __ieee80211_unschedule_txq(struct ieee80211_hw *hw,RB_CLEAR_NODE (&txqi->schedule_order); } +void ieee80211_remove_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct txq_info *txqi =to_txq_info (txq); + +lockdep_assert_held (&local->active_txq_lock[txq->ac]); + +if (!RB_EMPTY_NODE (&txqi->schedule_order)) { +__ieee80211_unschedule_txq (hw, txq); +list_del_init (&txqi->candidate); + } +} +void ieee80211_unschedule_txq (struct ieee80211_hw *hw,struct ieee80211_txq *txq)net/mac80211/tx.c +30
-3__acquires (txq_lock)__releases (txq_lock)@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(structieee80211_hw *hw, struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh (&local->active_txq_lock[txq->ac]); -__ieee80211_unschedule_txq (hw, txq); +ieee80211_remove_txq (hw, txq);spin_unlock_bh (&local->active_txq_lock[txq->ac]); }@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct ieee80211_hw *hw,lockdep_assert_held (&local->active_txq_lock[txq->ac]);if (!RB_EMPTY_NODE (&txqi->schedule_order) && - (skb_queue_empty (&txqi->frags) && !txqi->tin.backlog_packets)) -__ieee80211_unschedule_txq (hw, txq); + !txq_has_queue (&txqi->txq) && +list_empty (&txqi->candidate)) +list_add_tail (&txqi->candidate, &local->remove_list[txq->ac]); + }EXPORT_SYMBOL (ieee80211_return_txq); +void __ieee80211_check_txqs (struct ieee80211_local *local,int ac) +{ +struct txq_info *iter, *tmp; +struct sta_info *sta; + +lockdep_assert_held (&local->active_txq_lock[ac]); + +list_for_each_entry_safe (iter, tmp, &local->remove_list[ac], + candidate) { + sta = container_of(iter->txq.sta, struct sta_info, sta); + +if (txq_has_queue (&iter->txq)) +list_del_init (&iter->candidate); +else +ieee80211_remove_txq (&local->hw, &iter->txq); + } +} + +void ieee80211_txqs_check (struct timer_list *t) +{ +struct ieee80211_local *local =from_timer (local, t, remove_timer); +struct txq_info *iter, *tmp; +struct sta_info *sta; +int ac; +net/mac80211/tx.c void ieee80211_return_txq(struct ieee80211_hw · line 3866
Quoted 10 lines
net/mac80211/tx.c +9
-0+for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +__ieee80211_check_txqs (local, ac); +spin_unlock_bh (&local->active_txq_lock[ac]); + } + +mod_timer (&local->remove_timer, + jiffies +msecs_to_jiffies (IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS )); +}I'll ask the same as I did last time (where you told me to hold off until this round):
Quoted 3 lines
Why do you need the timer and the periodic check? If TXQs are added to the remove list during the scheduling run, and
__ieee80211_check_txqs()is run fromschedule_end(), isn't that sufficient to clear the list?
Is it possible that a txq is not added to the remove list but then packets in it are dropped by fq_codel algo? Like the station disconnects without any notification.
Quoted 2 lines
-Toke
Signature · 6 lines
Yibo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 244 lines · Yibo Zhao
Quoted 243 lines · Toke Høiland-Jørgensen
Quoted 9 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the rbtree gets removed from rbtree immediately in the
ieee80211_return_txq(), the loop will break soon in theieee80211_next_txq()due toschedule_posnot leading to the second txq in the rbtree. Thus, defering the removal right before the end of this schedule round.Co-developed-by Yibo Zhao <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off. I'll add ack or review tags as appropriate in reply; but a few comments first:
Quoted 214 lines
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)include/net/mac80211.h +2
-0@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 +static inline void ieee80211_rate_set_vht (struct ieee80211_tx_rate *rate,u8 mcs,u8 nss){
include/net/mac80211.h +1
-1@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(structieee80211_hw *hw, * @ac: AC number to return packets from. * * Should only be called between calls toieee80211_txq_schedule_start () - * and ieee80211_txq_schedule_end(). + * and ieee80211_txq_schedule_end(). If the txq is empty, it will beadded
+ * to a remove list and get removed later.
* Returns the next txq if successful, %NULL if no queue is eligible.
If a txq
* is returned, it should be returned withieee80211_return_txq()
after the
* driver has finished scheduling it.include/net/mac80211.h +1
-1@@ -6268,7 +6271,8 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) * @hw: pointer as obtained from ieee80211_alloc_hw() * @ac: AC number to acquire locks for * - * Release locks previously acquired by ieee80211_txq_schedule_end(). + * Release locks previously acquired by ieee80211_txq_schedule_end().Check
+ * and remove the empty txq from rb-tree.
*/
voidieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac)include/net/mac80211.h +8
-0__releases (txq_lock);@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq)__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed to transmit
*
* This function is used to check whether given txq is allowed to
transmit bynet/mac80211/ieee80211_i.h +3
-0@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */ @@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;net/mac80211/main.c +5
-0@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, for (i = 0; i < IEEE80211_NUM_ACS; i++) { local->active_txqs[i] = RB_ROOT_CACHED; + INIT_LIST_HEAD(&local->remove_list[i]); spin_lock_init(&local->active_txq_lock[i]); } local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX; + timer_setup(&local->remove_timer, ieee80211_txqs_check, 0); + mod_timer(&local->remove_timer, + jiffies + msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); + INIT_LIST_HEAD(&local->chanctx_list);net/mac80211/main.c +1
-0mutex_init (&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif
net/mac80211/tx.c +18
-0@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);RB_CLEAR_NODE (&txqi->schedule_order); +INIT_LIST_HEAD (&txqi->candidate); txqi->txq.vif = &sdata->vif;@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct ieee80211_hw *hw,spin_lock_bh (&local->active_txq_lock[ac]); +if (!list_empty (&txqi->candidate)) +list_del_init (&txqi->candidate); +if (!RB_EMPTY_NODE (&txqi->schedule_order)) goto out;@@ -3783,6 +3787,20 @@ static void __ieee80211_unschedule_txq(struct ieee80211_hw *hw,RB_CLEAR_NODE (&txqi->schedule_order); } +void ieee80211_remove_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct txq_info *txqi =to_txq_info (txq); + +lockdep_assert_held (&local->active_txq_lock[txq->ac]); + +if (!RB_EMPTY_NODE (&txqi->schedule_order)) { +__ieee80211_unschedule_txq (hw, txq); +list_del_init (&txqi->candidate); + } +} +void ieee80211_unschedule_txq (struct ieee80211_hw *hw,struct ieee80211_txq *txq)net/mac80211/tx.c +30
-3__acquires (txq_lock)__releases (txq_lock)@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(structieee80211_hw *hw, struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh (&local->active_txq_lock[txq->ac]); -__ieee80211_unschedule_txq (hw, txq); +ieee80211_remove_txq (hw, txq);spin_unlock_bh (&local->active_txq_lock[txq->ac]); }@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct ieee80211_hw *hw,lockdep_assert_held (&local->active_txq_lock[txq->ac]);if (!RB_EMPTY_NODE (&txqi->schedule_order) && - (skb_queue_empty (&txqi->frags) && !txqi->tin.backlog_packets)) -__ieee80211_unschedule_txq (hw, txq); + !txq_has_queue (&txqi->txq) && +list_empty (&txqi->candidate)) +list_add_tail (&txqi->candidate, &local->remove_list[txq->ac]); + }EXPORT_SYMBOL (ieee80211_return_txq); +void __ieee80211_check_txqs (struct ieee80211_local *local,int ac) +{ +struct txq_info *iter, *tmp; +struct sta_info *sta; + +lockdep_assert_held (&local->active_txq_lock[ac]); + +list_for_each_entry_safe (iter, tmp, &local->remove_list[ac], + candidate) { + sta = container_of(iter->txq.sta, struct sta_info, sta); + +if (txq_has_queue (&iter->txq)) +list_del_init (&iter->candidate); +else +ieee80211_remove_txq (&local->hw, &iter->txq); + } +} + +void ieee80211_txqs_check (struct timer_list *t) +{ +struct ieee80211_local *local =from_timer (local, t, remove_timer); +struct txq_info *iter, *tmp; +struct sta_info *sta; +int ac; +net/mac80211/tx.c void ieee80211_return_txq(struct ieee80211_hw · line 3866
Quoted 10 lines
net/mac80211/tx.c +9
-0+for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +__ieee80211_check_txqs (local, ac); +spin_unlock_bh (&local->active_txq_lock[ac]); + } + +mod_timer (&local->remove_timer, + jiffies +msecs_to_jiffies (IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS )); +}I'll ask the same as I did last time (where you told me to hold off until this round):
Quoted 6 lines
Quoted 3 lines
Why do you need the timer and the periodic check? If TXQs are added to the remove list during the scheduling run, and
__ieee80211_check_txqs()is run fromschedule_end(), isn't that sufficient to clear the list?Is it possible that a txq is not added to the remove list but then packets in it are dropped by
fq_codelalgo? Like the station disconnects without any notification.
Well as long as all the other cleanup paths call directly into __unschedule_txq(), that should remove stations from the scheduler when they disconnect etc.
We only need to defer removal inside a single "scheduling round" (i.e., between a pair of ieee80211_txq_schedule_start/end. So if we just walk the remove list in schedule_end() we should be enough, no?
Hmm, or maybe a simpler way to fix the original issue is just to have unschedule_txq() update the schedule_pos() pointer?
I.e., unschedule_txq checks if the txq being removed is currently being pointed to by schedule_pos[ac], and if it is, it updates schedule_pos to be the rb_next of the current value?
-Toke
_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 258 lines · Toke Høiland-Jørgensen
Quoted 256 lines · Yibo Zhao
Quoted 255 lines · Toke Høiland-Jørgensen
Quoted 9 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the rbtree gets removed from rbtree immediately in the
ieee80211_return_txq(), the loop will break soon in theieee80211_next_txq()due toschedule_posnot leading to the second txq in the rbtree. Thus, defering the removal right before the end of this schedule round.Co-developed-by Yibo Zhao <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off. I'll add ack or review tags as appropriate in reply; but a few comments first:
Quoted 231 lines
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)include/net/mac80211.h +2
-0@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 +static inline void ieee80211_rate_set_vht (struct ieee80211_tx_rate *rate,u8 mcs,u8 nss){
include/net/mac80211.h +1
-1@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(structieee80211_hw *hw, * @ac: AC number to return packets from. * * Should only be called between calls toieee80211_txq_schedule_start () - * and ieee80211_txq_schedule_end(). + * and ieee80211_txq_schedule_end(). If the txq is empty, it willbe
added
+ * to a remove list and get removed later.
* Returns the next txq if successful, %NULL if no queue is
eligible.
If a txq
* is returned, it should be returned withieee80211_return_txq()
after the
* driver has finished scheduling it.include/net/mac80211.h +0
-1@@ -6268,7 +6271,8 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) * @hw: pointer as obtained from ieee80211_alloc_hw() * @ac: AC number to acquire locks for * - * Release locks previously acquired by
ieee80211_txq_schedule_end().
+ * Release locks previously acquired byieee80211_txq_schedule_end().
Check
+ * and remove the empty txq from rb-tree.
*/
voidieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac)include/net/mac80211.h +0
-0__releases (txq_lock);@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw, structieee80211_txq*txq)include/net/mac80211.h +8
-0__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed to transmit
*
* This function is used to check whether given txq is allowed to
transmit bynet/mac80211/ieee80211_i.h +3
-0@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */ @@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;net/mac80211/main.c +5
-0@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, for (i = 0; i < IEEE80211_NUM_ACS; i++) { local->active_txqs[i] = RB_ROOT_CACHED; + INIT_LIST_HEAD(&local->remove_list[i]); spin_lock_init(&local->active_txq_lock[i]); } local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX; + timer_setup(&local->remove_timer, ieee80211_txqs_check, 0); + mod_timer(&local->remove_timer, + jiffies + msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); + INIT_LIST_HEAD(&local->chanctx_list);net/mac80211/main.c +0
-0mutex_init (&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct
ieee80211_hw
*hw)net/mac80211/main.c +1
-0tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif net/mac80211/tx.c +1
-0@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);RB_CLEAR_NODE (&txqi->schedule_order); +INIT_LIST_HEAD (&txqi->candidate); txqi->txq.vif = &sdata->vif;@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +17
-0spin_lock_bh (&local->active_txq_lock[ac]); +if (!list_empty (&txqi->candidate)) +list_del_init (&txqi->candidate); +if (!RB_EMPTY_NODE (&txqi->schedule_order)) goto out;@@ -3783,6 +3787,20 @@ static void __ieee80211_unschedule_txq(struct ieee80211_hw *hw,RB_CLEAR_NODE (&txqi->schedule_order); } +void ieee80211_remove_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct txq_info *txqi =to_txq_info (txq); + +lockdep_assert_held (&local->active_txq_lock[txq->ac]); + +if (!RB_EMPTY_NODE (&txqi->schedule_order)) { +__ieee80211_unschedule_txq (hw, txq); +list_del_init (&txqi->candidate); + } +} +void ieee80211_unschedule_txq (struct ieee80211_hw *hw,struct ieee80211_txq *txq)net/mac80211/tx.c +1
-1__acquires (txq_lock)__releases (txq_lock)@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(structieee80211_hw *hw, struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh (&local->active_txq_lock[txq->ac]); -__ieee80211_unschedule_txq (hw, txq); +ieee80211_remove_txq (hw, txq);spin_unlock_bh (&local->active_txq_lock[txq->ac]); }@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +25
-2lockdep_assert_held (&local->active_txq_lock[txq->ac]);if (!RB_EMPTY_NODE (&txqi->schedule_order) && - (skb_queue_empty (&txqi->frags) && !txqi->tin.backlog_packets)) -__ieee80211_unschedule_txq (hw, txq); + !txq_has_queue (&txqi->txq) && +list_empty (&txqi->candidate)) +list_add_tail (&txqi->candidate, &local->remove_list[txq->ac]); + }EXPORT_SYMBOL (ieee80211_return_txq); +void __ieee80211_check_txqs (struct ieee80211_local *local,int ac) +{ +struct txq_info *iter, *tmp; +struct sta_info *sta; + +lockdep_assert_held (&local->active_txq_lock[ac]); + +list_for_each_entry_safe (iter, tmp, &local->remove_list[ac], + candidate) { + sta = container_of(iter->txq.sta, struct sta_info, sta); + +if (txq_has_queue (&iter->txq)) +list_del_init (&iter->candidate); +else +ieee80211_remove_txq (&local->hw, &iter->txq); + } +} + +void ieee80211_txqs_check (struct timer_list *t) +{ + struct ieee80211_local *local = from_timer(local, t,
remove_timer);net/mac80211/tx.c +12
-0+struct txq_info *iter, *tmp; +struct sta_info *sta; +int ac; + +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +__ieee80211_check_txqs (local, ac); +spin_unlock_bh (&local->active_txq_lock[ac]); + } + + mod_timer(&local->remove_timer, + jiffies +Quoted 2 lines
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); +}I'll ask the same as I did last time (where you told me to hold off until this round):
Why do you need the timer and the periodic check? If TXQs are added to the remove list during the scheduling run, and
__ieee80211_check_txqs()is run fromschedule_end(), isn't that sufficient to clear the list?
Quoted 7 lines
Quoted 3 lines
Is it possible that a txq is not added to the remove list but then packets in it are dropped by
fq_codelalgo? Like the station disconnects without any notification.Well as long as all the other cleanup paths call directly into
__unschedule_txq(), that should remove stations from the scheduler when they disconnect etc.
Yes, the disconnect scenario is a bad example. My concern is, say, we have 10 stations and only one of them is assigned a very small weight compared with that of others. Suppose, after its chance of Tx, it is most likely to be placed in the rightmost(still has some packets in the txq) and no more incoming data for it. The remaining packets in txq will be dropped due to timeout algo in codel(correct me if I am wrong) but this empty txq will stay on the rbtree until other txqs get drained or global vt catch up with its vt. The staying time could be long if weight is extremely small. Then do we need timer to check or any other better solution?
Quoted 11 lines
We only need to defer removal inside a single "scheduling round" (i.e., between a pair of ieee80211_txq_schedule_start/end. So if we just walk the remove list in
schedule_end()we should be enough, no?Hmm, or maybe a simpler way to fix the original issue is just to have
unschedule_txq()update theschedule_pos()pointer?I.e.,
unschedule_txqchecks if the txq being removed is currently being pointed to by schedule_pos[ac], and if it is, it updatesschedule_posto be therb_nextof the current value?
Actually, if schedule_pos is updated to rb_next of the current value, then in the next_txq() where we are going to use rb_next again and finally pick the next node of the node we really want. Is it fine to update schedule_pos to NULL?
Quoted 2 lines
-Toke
Signature · 1 line
Yibo
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 269 lines · Yibo Zhao
Quoted 260 lines · Toke Høiland-Jørgensen
Quoted 258 lines · Yibo Zhao
Quoted 257 lines · Toke Høiland-Jørgensen
Quoted 9 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the rbtree gets removed from rbtree immediately in the
ieee80211_return_txq(), the loop will break soon in theieee80211_next_txq()due toschedule_posnot leading to the second txq in the rbtree. Thus, defering the removal right before the end of this schedule round.Co-developed-by Yibo Zhao <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off. I'll add ack or review tags as appropriate in reply; but a few comments first:
Quoted 231 lines
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)include/net/mac80211.h +2
-0@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 +static inline void ieee80211_rate_set_vht (struct ieee80211_tx_rate *rate,u8 mcs,u8 nss){
include/net/mac80211.h +1
-1@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(structieee80211_hw *hw, * @ac: AC number to return packets from. * * Should only be called between calls toieee80211_txq_schedule_start () - * and ieee80211_txq_schedule_end(). + * and ieee80211_txq_schedule_end(). If the txq is empty, it willbe
added
+ * to a remove list and get removed later.
* Returns the next txq if successful, %NULL if no queue is
eligible.
If a txq
* is returned, it should be returned withieee80211_return_txq()
after the
* driver has finished scheduling it.include/net/mac80211.h +0
-1@@ -6268,7 +6271,8 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) * @hw: pointer as obtained from ieee80211_alloc_hw() * @ac: AC number to acquire locks for * - * Release locks previously acquired by
ieee80211_txq_schedule_end().
+ * Release locks previously acquired byieee80211_txq_schedule_end().
Check
+ * and remove the empty txq from rb-tree.
*/
voidieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac)include/net/mac80211.h +0
-0__releases (txq_lock);@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw, structieee80211_txq*txq)include/net/mac80211.h +8
-0__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed to transmit
*
* This function is used to check whether given txq is allowed to
transmit bynet/mac80211/ieee80211_i.h +3
-0@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */ @@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;net/mac80211/main.c +5
-0@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, for (i = 0; i < IEEE80211_NUM_ACS; i++) { local->active_txqs[i] = RB_ROOT_CACHED; + INIT_LIST_HEAD(&local->remove_list[i]); spin_lock_init(&local->active_txq_lock[i]); } local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX; + timer_setup(&local->remove_timer, ieee80211_txqs_check, 0); + mod_timer(&local->remove_timer, + jiffies + msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); + INIT_LIST_HEAD(&local->chanctx_list);net/mac80211/main.c +0
-0mutex_init (&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct
ieee80211_hw
*hw)net/mac80211/main.c +1
-0tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif net/mac80211/tx.c +1
-0@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);RB_CLEAR_NODE (&txqi->schedule_order); +INIT_LIST_HEAD (&txqi->candidate); txqi->txq.vif = &sdata->vif;@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +17
-0spin_lock_bh (&local->active_txq_lock[ac]); +if (!list_empty (&txqi->candidate)) +list_del_init (&txqi->candidate); +if (!RB_EMPTY_NODE (&txqi->schedule_order)) goto out;@@ -3783,6 +3787,20 @@ static void __ieee80211_unschedule_txq(struct ieee80211_hw *hw,RB_CLEAR_NODE (&txqi->schedule_order); } +void ieee80211_remove_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct txq_info *txqi =to_txq_info (txq); + +lockdep_assert_held (&local->active_txq_lock[txq->ac]); + +if (!RB_EMPTY_NODE (&txqi->schedule_order)) { +__ieee80211_unschedule_txq (hw, txq); +list_del_init (&txqi->candidate); + } +} +void ieee80211_unschedule_txq (struct ieee80211_hw *hw,struct ieee80211_txq *txq)net/mac80211/tx.c +1
-1__acquires (txq_lock)__releases (txq_lock)@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(structieee80211_hw *hw, struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh (&local->active_txq_lock[txq->ac]); -__ieee80211_unschedule_txq (hw, txq); +ieee80211_remove_txq (hw, txq);spin_unlock_bh (&local->active_txq_lock[txq->ac]); }@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +25
-2lockdep_assert_held (&local->active_txq_lock[txq->ac]);if (!RB_EMPTY_NODE (&txqi->schedule_order) && - (skb_queue_empty (&txqi->frags) && !txqi->tin.backlog_packets)) -__ieee80211_unschedule_txq (hw, txq); + !txq_has_queue (&txqi->txq) && +list_empty (&txqi->candidate)) +list_add_tail (&txqi->candidate, &local->remove_list[txq->ac]); + }EXPORT_SYMBOL (ieee80211_return_txq); +void __ieee80211_check_txqs (struct ieee80211_local *local,int ac) +{ +struct txq_info *iter, *tmp; +struct sta_info *sta; + +lockdep_assert_held (&local->active_txq_lock[ac]); + +list_for_each_entry_safe (iter, tmp, &local->remove_list[ac], + candidate) { + sta = container_of(iter->txq.sta, struct sta_info, sta); + +if (txq_has_queue (&iter->txq)) +list_del_init (&iter->candidate); +else +ieee80211_remove_txq (&local->hw, &iter->txq); + } +} + +void ieee80211_txqs_check (struct timer_list *t) +{ + struct ieee80211_local *local = from_timer(local, t,
remove_timer);net/mac80211/tx.c +12
-0+struct txq_info *iter, *tmp; +struct sta_info *sta; +int ac; + +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +__ieee80211_check_txqs (local, ac); +spin_unlock_bh (&local->active_txq_lock[ac]); + } + + mod_timer(&local->remove_timer, + jiffies +Quoted 2 lines
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); +}I'll ask the same as I did last time (where you told me to hold off until this round):
Why do you need the timer and the periodic check? If TXQs are added to
the remove list during the scheduling run, and__ieee80211_check_txqs()
is run fromschedule_end(), isn't that sufficient to clear the list?Quoted 8 lines
Quoted 4 lines
Is it possible that a txq is not added to the remove list but then packets in it are dropped by
fq_codelalgo? Like the station disconnects
without any notification.Well as long as all the other cleanup paths call directly into
__unschedule_txq(), that should remove stations from the scheduler when they disconnect etc.
Quoted 10 lines
Yes, the disconnect scenario is a bad example. My concern is, say, we have 10 stations and only one of them is assigned a very small weight compared with that of others. Suppose, after its chance of Tx, it is most likely to be placed in the rightmost(still has some packets in the txq) and no more incoming data for it. The remaining packets in txq will be dropped due to timeout algo in codel(correct me if I am wrong) but this empty txq will stay on the rbtree until other txqs get drained or global vt catch up with its vt. The staying time could be long if weight is extremely small. Then do we need timer to check or any other better solution?
Ah, I see what you mean. No, I don't think this will be a problem; the scenario you're describing would play out like this:
1. Station ends transmitting, still has a single packet queued, gets moved to the end of the rbtree (and stays there for a while).
2. When we finally get to the point where this station gets another chance to transmit, the CoDel drop timer triggers and the last packet is dropped[0]. This means that the queue will just be empty (and ieee80211_tx_dequeue() will return NULL).
3. Because the queue is empty, ieee80211_return_txq() will not put it back on the rbtree.
Crucially, in 2. the CoDel algorithm doesn't kick in until the point of packet dequeue. But even if an empty queue stays on the rbtree for a while, there is no harm in that: eventually it will get its turn, it will turn out to be empty, and just be skipped over.
The issue we need to be concerned about is the opposite: If we have a queue that *does* have packets queued, but which is *not* scheduled for transmission, that will stall TX.
[0] CoDel in most cases only drops a single packet at a time, so it will not clear out an entire queue with multiple packets in one go. But you are right that it could conceivably drop the last packet in a queue.
Quoted 7 lines
Quoted 7 lines
We only need to defer removal inside a single "scheduling round" (i.e., between a pair of ieee80211_txq_schedule_start/end. So if we just walk the remove list in
schedule_end()we should be enough, no?Hmm, or maybe a simpler way to fix the original issue is just to have
unschedule_txq()update theschedule_pos()pointer?
Quoted 8 lines
Quoted 4 lines
I.e.,
unschedule_txqchecks if the txq being removed is currently being pointed to by schedule_pos[ac], and if it is, it updatesschedule_posto
be therb_nextof the current value?Actually, if
schedule_posis updated torb_nextof the current value, then in thenext_txq()where we are going to userb_nextagain and finally pick the next node of the node we really want. Is it fine to updateschedule_posto NULL?
Hmm, yeah, good point.
If we do end up setting schedule_pos to NULL in the middle of a scheduling round, that will make next_txq() "start over", and do another loop through the whole thing. I guess we may be able hit a case where things can oscillate back and forth between addition and removal resulting in an infinite loop? Not sure, but at least I can't seem to convince myself that this can't happen.
But in that case, we could fix it by just conditionally assigning either rb_next or rb_prev to the schedule_pos in unschedule_txq()? I.e., something like:
local->schedule_pos[ac] = rb_next(node) ?: rb_prev(node);
-Toke
_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 298 lines · Toke Høiland-Jørgensen
Quoted 273 lines · Yibo Zhao
Quoted 264 lines · Toke Høiland-Jørgensen
Quoted 262 lines · Yibo Zhao
Quoted 261 lines · Toke Høiland-Jørgensen
Quoted 9 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the rbtree gets removed from rbtree immediately in the
ieee80211_return_txq(), the loop will break soon in theieee80211_next_txq()due toschedule_posnot leading to the second txq in the rbtree. Thus, defering the removal right before the end of this schedule round.Co-developed-by Yibo Zhao <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off. I'll add ack or review tags as appropriate in reply; but a few comments first:
Quoted 235 lines
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)include/net/mac80211.h +2
-0@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 + static inline void ieee80211_rate_set_vht(struct
ieee80211_tx_rate
*rate,include/net/mac80211.h +1
-1u8 mcs, u8 nss) {@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(structieee80211_hw *hw, * @ac: AC number to return packets from. * * Should only be called between calls toieee80211_txq_schedule_start () - * and ieee80211_txq_schedule_end(). + * and ieee80211_txq_schedule_end(). If the txq is empty, it willbe
added
+ * to a remove list and get removed later.
* Returns the next txq if successful, %NULL if no queue is
eligible.
If a txq
* is returned, it should be returned withieee80211_return_txq()
after the
* driver has finished scheduling it.include/net/mac80211.h +0
-1@@ -6268,7 +6271,8 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) * @hw: pointer as obtained from ieee80211_alloc_hw() * @ac: AC number to acquire locks for * - * Release locks previously acquired by
ieee80211_txq_schedule_end().
+ * Release locks previously acquired byieee80211_txq_schedule_end().
Check
+ * and remove the empty txq from rb-tree.
*/
voidieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac)include/net/mac80211.h +0
-0__releases (txq_lock);@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw, structieee80211_txq*txq)include/net/mac80211.h +8
-0__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed to transmit
*
* This function is used to check whether given txq is allowed to
transmit bynet/mac80211/ieee80211_i.h +3
-0@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */ @@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;net/mac80211/main.c +5
-0@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, for (i = 0; i < IEEE80211_NUM_ACS; i++) { local->active_txqs[i] = RB_ROOT_CACHED; + INIT_LIST_HEAD(&local->remove_list[i]); spin_lock_init(&local->active_txq_lock[i]); } local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX; + timer_setup(&local->remove_timer, ieee80211_txqs_check, 0); + mod_timer(&local->remove_timer, + jiffies + msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); + INIT_LIST_HEAD(&local->chanctx_list);net/mac80211/main.c +0
-0mutex_init (&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct
ieee80211_hw
*hw)net/mac80211/main.c +1
-0tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif net/mac80211/tx.c +1
-0@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);RB_CLEAR_NODE (&txqi->schedule_order); +INIT_LIST_HEAD (&txqi->candidate); txqi->txq.vif = &sdata->vif;@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +3
-0spin_lock_bh (&local->active_txq_lock[ac]); +if (!list_empty (&txqi->candidate)) +list_del_init (&txqi->candidate); +if (!RB_EMPTY_NODE (&txqi->schedule_order)) goto out;@@ -3783,6 +3787,20 @@ static void__ieee80211_unschedule_txq(struct
ieee80211_hw*hw,net/mac80211/tx.c +15
-1RB_CLEAR_NODE (&txqi->schedule_order); } +void ieee80211_remove_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct txq_info *txqi =to_txq_info (txq); + +lockdep_assert_held (&local->active_txq_lock[txq->ac]); + +if (!RB_EMPTY_NODE (&txqi->schedule_order)) { +__ieee80211_unschedule_txq (hw, txq); +list_del_init (&txqi->candidate); + } +} + void ieee80211_unschedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq) __acquires(txq_lock) __releases(txq_lock)@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(structieee80211_hw *hw, struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh (&local->active_txq_lock[txq->ac]); -__ieee80211_unschedule_txq (hw, txq); +ieee80211_remove_txq (hw, txq);spin_unlock_bh (&local->active_txq_lock[txq->ac]); }@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +0
-1lockdep_assert_held (&local->active_txq_lock[txq->ac]); if (!RB_EMPTY_NODE(&txqi->schedule_order) && - (skb_queue_empty(&txqi->frags) &&!txqi->tin.backlog_packets))
net/mac80211/tx.c +5
-1-__ieee80211_unschedule_txq (hw, txq); + !txq_has_queue(&txqi->txq) && + list_empty(&txqi->candidate)) +list_add_tail (&txqi->candidate, &local->remove_list[txq->ac]); + }EXPORT_SYMBOL (ieee80211_return_txq); +void __ieee80211_check_txqs(struct ieee80211_local *local, intac)
net/mac80211/tx.c +20
-0+{ +struct txq_info *iter, *tmp; +struct sta_info *sta; + +lockdep_assert_held (&local->active_txq_lock[ac]); + +list_for_each_entry_safe (iter, tmp, &local->remove_list[ac], + candidate) { + sta = container_of(iter->txq.sta, struct sta_info, sta); + +if (txq_has_queue (&iter->txq)) +list_del_init (&iter->candidate); +else +ieee80211_remove_txq (&local->hw, &iter->txq); + } +} + +void ieee80211_txqs_check (struct timer_list *t) +{ + struct ieee80211_local *local = from_timer(local, t,
remove_timer);net/mac80211/tx.c +12
-0+struct txq_info *iter, *tmp; +struct sta_info *sta; +int ac; + +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +__ieee80211_check_txqs (local, ac); +spin_unlock_bh (&local->active_txq_lock[ac]); + } + + mod_timer(&local->remove_timer, + jiffies +Quoted 2 lines
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); +}I'll ask the same as I did last time (where you told me to hold off until this round):
Why do you need the timer and the periodic check? If TXQs are added to
the remove list during the scheduling run, and__ieee80211_check_txqs()
is run fromschedule_end(), isn't that sufficient to clear the list?Quoted 8 lines
Quoted 4 lines
Is it possible that a txq is not added to the remove list but then packets in it are dropped by
fq_codelalgo? Like the station disconnects
without any notification.Well as long as all the other cleanup paths call directly into
__unschedule_txq(), that should remove stations from the scheduler when they disconnect etc.Quoted 10 lines
Yes, the disconnect scenario is a bad example. My concern is, say, we have 10 stations and only one of them is assigned a very small weight compared with that of others. Suppose, after its chance of Tx, it is most likely to be placed in the rightmost(still has some packets in the txq) and no more incoming data for it. The remaining packets in txq will be dropped due to timeout algo in codel(correct me if I am wrong) but this empty txq will stay on the rbtree until other txqs get drained or global vt catch up with its vt. The staying time could be long if weight is extremely small. Then do we need timer to check or any other better solution?
Ah, I see what you mean. No, I don't think this will be a problem; the scenario you're describing would play out like this:
1. Station ends transmitting, still has a single packet queued, gets moved to the end of the rbtree (and stays there for a while).
2. When we finally get to the point where this station gets another chance to transmit, the CoDel drop timer triggers and the last
packet
is dropped[0]. This means that the queue will just be empty (andieee80211_tx_dequeue()will return NULL).
Quoted 7 lines
3. Because the queue is empty,
ieee80211_return_txq()will not put it back on the rbtree.Crucially, in 2. the CoDel algorithm doesn't kick in until the point of packet dequeue. But even if an empty queue stays on the rbtree for a while, there is no harm in that: eventually it will get its turn, it will turn out to be empty, and just be skipped over.
Then that will be fine. Thanks for the explanation of the dropping part in CoDel algorithm.
Quoted 4 lines
The issue we need to be concerned about is the opposite: If we have a queue that *does* have packets queued, but which is *not* scheduled for transmission, that will stall TX.
Is it by design since its vt is more than global vt, right? The lattency may somehow get impacted though.
Quoted 21 lines
[0] CoDel in most cases only drops a single packet at a time, so it will not clear out an entire queue with multiple packets in one go. But you are right that it could conceivably drop the last packet in a queue.
Quoted 7 lines
Quoted 7 lines
We only need to defer removal inside a single "scheduling round" (i.e., between a pair of ieee80211_txq_schedule_start/end. So if we just walk the remove list in
schedule_end()we should be enough, no?Hmm, or maybe a simpler way to fix the original issue is just to have
unschedule_txq()update theschedule_pos()pointer?Quoted 8 lines
Quoted 4 lines
I.e.,
unschedule_txqchecks if the txq being removed is currently being pointed to by schedule_pos[ac], and if it is, it updatesschedule_posto
be therb_nextof the current value?Actually, if
schedule_posis updated torb_nextof the current value, then in thenext_txq()where we are going to userb_nextagain and finally pick the next node of the node we really want. Is it fine to updateschedule_posto NULL?
Quoted 8 lines
Hmm, yeah, good point.
If we do end up setting
schedule_posto NULL in the middle of a scheduling round, that will makenext_txq()"start over", and do another loop through the whole thing. I guess we may be able hit a case where things can oscillate back and forth between addition and removal resulting in an infinite loop? Not sure, but at least I can't seem to convince myself that this can't happen.
As the loop of next_txq under lock protection as below,
txq_schedule_start();
while(txq=next_txq()){
...return_txq(txq);
}txq_schedule_end();
I do not see any chance of addition, no?
In ath10k, we will usually push packets of first txq as many as we can until it is drained and then move to the next one. So if a txq gets removed in the return_txq, it should always be the leftmost. And during this period, neither vt of any station or global vt can be updated due to lock protection.
Quoted 6 lines
But in that case, we could fix it by just conditionally assigning either
rb_nextorrb_prevto theschedule_posinunschedule_txq()? I.e., something like:local->schedule_pos[ac] =
rb_next(node)?:rb_prev(node);
I am not sure I am getting your point. Still in next_txq, schedule_pos[ac] will lead us to the next node of the one we want.
Quoted 2 lines
-Toke
Signature · 6 lines
Yibo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 312 lines · Yibo Zhao
Quoted 311 lines · Toke Høiland-Jørgensen
Quoted 280 lines · Yibo Zhao
Quoted 275 lines · Toke Høiland-Jørgensen
Quoted 268 lines · Yibo Zhao
Quoted 261 lines · Toke Høiland-Jørgensen
Quoted 11 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the rbtree gets
removed from rbtree immediately in theieee80211_return_txq(), the loop will break soon in theieee80211_next_txq()due toschedule_pos
not leading to the second txq in the rbtree. Thus, defering the removal right before the end of this schedule round.Co-developed-by Yibo Zhao <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off. I'll add
ack or review tags as appropriate in reply; but a few comments first:Quoted 236 lines
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)include/net/mac80211.h +2
-0@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 + static inline void ieee80211_rate_set_vht(struct
ieee80211_tx_rate
*rate,include/net/mac80211.h +1
-1u8 mcs, u8 nss) {@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(structieee80211_hw *hw, * @ac: AC number to return packets from. * * Should only be called between calls toieee80211_txq_schedule_start () - * and ieee80211_txq_schedule_end(). + * and ieee80211_txq_schedule_end(). If the txq is empty, it willbe
added
+ * to a remove list and get removed later.
* Returns the next txq if successful, %NULL if no queue is
eligible.
If a txq
* is returned, it should be returned withieee80211_return_txq()
after the
* driver has finished scheduling it.include/net/mac80211.h +0
-1@@ -6268,7 +6271,8 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) * @hw: pointer as obtained from ieee80211_alloc_hw() * @ac: AC number to acquire locks for * - * Release locks previously acquired by
ieee80211_txq_schedule_end().
+ * Release locks previously acquired byieee80211_txq_schedule_end().
Check
+ * and remove the empty txq from rb-tree.
*/
voidieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac)include/net/mac80211.h +0
-0__releases (txq_lock);@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw, structieee80211_txq*txq)include/net/mac80211.h +8
-0__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed to transmit
*
* This function is used to check whether given txq is allowed to
transmit bynet/mac80211/ieee80211_i.h +3
-0@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */ @@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;net/mac80211/main.c +5
-0@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, for (i = 0; i < IEEE80211_NUM_ACS; i++) { local->active_txqs[i] = RB_ROOT_CACHED; + INIT_LIST_HEAD(&local->remove_list[i]); spin_lock_init(&local->active_txq_lock[i]); } local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX; + timer_setup(&local->remove_timer, ieee80211_txqs_check, 0); + mod_timer(&local->remove_timer, + jiffies + msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); + INIT_LIST_HEAD(&local->chanctx_list);net/mac80211/main.c +0
-0mutex_init (&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct
ieee80211_hw
*hw)net/mac80211/main.c +1
-0tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif net/mac80211/tx.c +1
-0@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);RB_CLEAR_NODE (&txqi->schedule_order); +INIT_LIST_HEAD (&txqi->candidate); txqi->txq.vif = &sdata->vif;@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +3
-0spin_lock_bh (&local->active_txq_lock[ac]); +if (!list_empty (&txqi->candidate)) +list_del_init (&txqi->candidate); +if (!RB_EMPTY_NODE (&txqi->schedule_order)) goto out;@@ -3783,6 +3787,20 @@ static void__ieee80211_unschedule_txq(struct
ieee80211_hw*hw,net/mac80211/tx.c +15
-1RB_CLEAR_NODE (&txqi->schedule_order); } +void ieee80211_remove_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct txq_info *txqi =to_txq_info (txq); + +lockdep_assert_held (&local->active_txq_lock[txq->ac]); + +if (!RB_EMPTY_NODE (&txqi->schedule_order)) { +__ieee80211_unschedule_txq (hw, txq); +list_del_init (&txqi->candidate); + } +} + void ieee80211_unschedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq) __acquires(txq_lock) __releases(txq_lock)@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(structieee80211_hw *hw, struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh (&local->active_txq_lock[txq->ac]); -__ieee80211_unschedule_txq (hw, txq); +ieee80211_remove_txq (hw, txq);spin_unlock_bh (&local->active_txq_lock[txq->ac]); }@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +0
-1lockdep_assert_held (&local->active_txq_lock[txq->ac]); if (!RB_EMPTY_NODE(&txqi->schedule_order) && - (skb_queue_empty(&txqi->frags) &&!txqi->tin.backlog_packets))
net/mac80211/tx.c +5
-1-__ieee80211_unschedule_txq (hw, txq); + !txq_has_queue(&txqi->txq) && + list_empty(&txqi->candidate)) +list_add_tail (&txqi->candidate, &local->remove_list[txq->ac]); + }EXPORT_SYMBOL (ieee80211_return_txq); +void __ieee80211_check_txqs(struct ieee80211_local *local, intac)
net/mac80211/tx.c +20
-0+{ +struct txq_info *iter, *tmp; +struct sta_info *sta; + +lockdep_assert_held (&local->active_txq_lock[ac]); + +list_for_each_entry_safe (iter, tmp, &local->remove_list[ac], + candidate) { + sta = container_of(iter->txq.sta, struct sta_info, sta); + +if (txq_has_queue (&iter->txq)) +list_del_init (&iter->candidate); +else +ieee80211_remove_txq (&local->hw, &iter->txq); + } +} + +void ieee80211_txqs_check (struct timer_list *t) +{ + struct ieee80211_local *local = from_timer(local, t,
remove_timer);net/mac80211/tx.c +12
-0+struct txq_info *iter, *tmp; +struct sta_info *sta; +int ac; + +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +__ieee80211_check_txqs (local, ac); +spin_unlock_bh (&local->active_txq_lock[ac]); + } + + mod_timer(&local->remove_timer, + jiffies +Quoted 2 lines
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); +}I'll ask the same as I did last time (where you told me to hold off until this round):
Quoted 6 lines
Why do you need the timer and the periodic check? If TXQs are added to
the remove list during the scheduling run, and__ieee80211_check_txqs()
is run fromschedule_end(), isn't that sufficient to clear the list?Quoted 4 lines
Is it possible that a txq is not added to the remove list but then packets in it are dropped by
fq_codelalgo? Like the station disconnects
without any notification.Quoted 4 lines
Well as long as all the other cleanup paths call directly into
__unschedule_txq(), that should remove stations from the scheduler when
they disconnect etc.Quoted 13 lines
Yes, the disconnect scenario is a bad example. My concern is, say, we have 10 stations and only one of them is assigned a very small weight compared with that of others. Suppose, after its chance of Tx, it is most likely to be placed in the rightmost(still has some packets in the
txq) and no more incoming data for it. The remaining packets in txq will
be dropped due to timeout algo in codel(correct me if I am wrong) but this empty txq will stay on the rbtree until other txqs get drained or global vt catch up with its vt. The staying time could be long if weight
is extremely small. Then do we need timer to check or any other better solution?Ah, I see what you mean. No, I don't think this will be a problem; the scenario you're describing would play out like this:
1. Station ends transmitting, still has a single packet queued, gets moved to the end of the rbtree (and stays there for a while).
2. When we finally get to the point where this station gets another chance to transmit, the CoDel drop timer triggers and the last
packet
is dropped[0]. This means that the queue will just be empty (andieee80211_tx_dequeue()will return NULL).3. Because the queue is empty,
ieee80211_return_txq()will not put it back on the rbtree.
Quoted 6 lines
Quoted 4 lines
Crucially, in 2. the CoDel algorithm doesn't kick in until the point of packet dequeue. But even if an empty queue stays on the rbtree for a while, there is no harm in that: eventually it will get its turn, it will turn out to be empty, and just be skipped over.
Then that will be fine. Thanks for the explanation of the dropping part in CoDel algorithm.
Yup, think so. And you're welcome :)
Quoted 5 lines
Quoted 3 lines
The issue we need to be concerned about is the opposite: If we have a queue that *does* have packets queued, but which is *not* scheduled for transmission, that will stall TX.
Is it by design since its vt is more than global vt, right? The lattency may somehow get impacted though.
Well, it should still stay on the rbtree as long as it has packets queued. We don't have a check anywhere that reschedules TXQs whose v_t drops below global v_t...
Quoted 36 lines
Quoted 26 lines
[0] CoDel in most cases only drops a single packet at a time, so it will
not clear out an entire queue with multiple packets in one go. But you are right that it could conceivably drop the last packet in a queue.Quoted 14 lines
Quoted 6 lines
We only need to defer removal inside a single "scheduling round" (i.e.,
between a pair of ieee80211_txq_schedule_start/end. So if we just walk
the remove list inschedule_end()we should be enough, no?Quoted 8 lines
Hmm, or maybe a simpler way to fix the original issue is just to have
unschedule_txq()update theschedule_pos()pointer?I.e.,
unschedule_txqchecks if the txq being removed is currently being
pointed to by schedule_pos[ac], and if it is, it updatesschedule_posto
be therb_nextof the current value?Quoted 4 lines
Actually, if
schedule_posis updated torb_nextof the current value, then in thenext_txq()where we are going to userb_nextagain and finally pick the next node of the node we really want. Is it fine to updateschedule_posto NULL?Hmm, yeah, good point.
Quoted 7 lines
If we do end up setting
schedule_posto NULL in the middle of a scheduling round, that will makenext_txq()"start over", and do another
loop through the whole thing. I guess we may be able hit a case where things can oscillate back and forth between addition and removal resulting in an infinite loop? Not sure, but at least I can't seem to convince myself that this can't happen.As the loop of
next_txqunder lock protection as below,
Quoted 8 lines
txq_schedule_start();
while(txq=next_txq()){
...return_txq(txq);
}txq_schedule_end();I do not see any chance of addition, no?
As you noted in your other email, Felix reduced the locking. And yeah, we need to rebase this series to also incorporate that. I figure I can send an updated version of the first patch in the series once we've worked out the remaining issues with your follow-up patches.
Quoted 7 lines
In ath10k, we will usually push packets of first txq as many as we can until it is drained and then move to the next one. So if a txq gets removed in the
return_txq, it should always be the leftmost. And during this period, neither vt of any station or global vt can be updated due to lock protection.Quoted 1 line
Quoted 8 lines
Quoted 6 lines
But in that case, we could fix it by just conditionally assigning either
rb_nextorrb_prevto theschedule_posinunschedule_txq()? I.e., something like:local->schedule_pos[ac] =
rb_next(node)?:rb_prev(node);I am not sure I am getting your point. Still in
next_txq, schedule_pos[ac] will lead us to the next node of the one we want.
The logic in next_txq is different when schedule_pos[ac] is NULL, vs when rb_next(schedule_pos[ac]) is NULL. The former restarts a new scheduling round, while the latter ends the current round.
-Toke
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 381 lines · Toke Høiland-Jørgensen
Quoted 317 lines · Yibo Zhao
Quoted 316 lines · Toke Høiland-Jørgensen
Quoted 285 lines · Yibo Zhao
Quoted 280 lines · Toke Høiland-Jørgensen
Quoted 273 lines · Yibo Zhao
Quoted 266 lines · Toke Høiland-Jørgensen
Quoted 11 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the rbtree gets
removed from rbtree immediately in theieee80211_return_txq(), the loop will break soon in theieee80211_next_txq()due toschedule_pos
not leading to the second txq in the rbtree. Thus, defering the removal right before the end of this schedule round.Co-developed-by Yibo Zhao <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off. I'll add
ack or review tags as appropriate in reply; but a few comments first:Quoted 241 lines
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)include/net/mac80211.h +2
-0@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 + static inline void ieee80211_rate_set_vht(struct
ieee80211_tx_rate
*rate,include/net/mac80211.h +1
-1u8 mcs, u8 nss) {@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, * @ac: AC number to return packets from. * * Should only be called between calls toieee80211_txq_schedule_start () - * and ieee80211_txq_schedule_end(). + * and ieee80211_txq_schedule_end(). If the txq is empty, itwill
be
added
+ * to a remove list and get removed later.
* Returns the next txq if successful, %NULL if no queue is
eligible.
If a txq
* is returned, it should be returned withieee80211_return_txq()
after the
* driver has finished scheduling it.include/net/mac80211.h +0
-1@@ -6268,7 +6271,8 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) * @hw: pointer as obtained from ieee80211_alloc_hw() * @ac: AC number to acquire locks for * - * Release locks previously acquired by
ieee80211_txq_schedule_end().
+ * Release locks previously acquired byieee80211_txq_schedule_end().
Check
+ * and remove the empty txq from rb-tree.
*/
voidieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac)include/net/mac80211.h +0
-0__releases (txq_lock);@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw, structieee80211_txq*txq)include/net/mac80211.h +8
-0__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed to transmit
*
* This function is used to check whether given txq is allowed
to
transmit bynet/mac80211/ieee80211_i.h +3
-0@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */ @@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;net/mac80211/main.c +5
-0@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, for (i = 0; i < IEEE80211_NUM_ACS; i++) { local->active_txqs[i] = RB_ROOT_CACHED; + INIT_LIST_HEAD(&local->remove_list[i]); spin_lock_init(&local->active_txq_lock[i]); } local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX; + timer_setup(&local->remove_timer, ieee80211_txqs_check, 0); + mod_timer(&local->remove_timer, + jiffies + msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); + INIT_LIST_HEAD(&local->chanctx_list);net/mac80211/main.c +0
-0mutex_init (&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct
ieee80211_hw
*hw)net/mac80211/main.c +1
-0tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif net/mac80211/tx.c +1
-0@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);RB_CLEAR_NODE (&txqi->schedule_order); +INIT_LIST_HEAD (&txqi->candidate); txqi->txq.vif = &sdata->vif;@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +3
-0spin_lock_bh (&local->active_txq_lock[ac]); +if (!list_empty (&txqi->candidate)) +list_del_init (&txqi->candidate); +if (!RB_EMPTY_NODE (&txqi->schedule_order)) goto out;@@ -3783,6 +3787,20 @@ static void__ieee80211_unschedule_txq(struct
ieee80211_hw*hw,net/mac80211/tx.c +15
-1RB_CLEAR_NODE (&txqi->schedule_order); } +void ieee80211_remove_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct txq_info *txqi =to_txq_info (txq); + +lockdep_assert_held (&local->active_txq_lock[txq->ac]); + +if (!RB_EMPTY_NODE (&txqi->schedule_order)) { +__ieee80211_unschedule_txq (hw, txq); +list_del_init (&txqi->candidate); + } +} + void ieee80211_unschedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq) __acquires(txq_lock) __releases(txq_lock)@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(structieee80211_hw *hw, struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh (&local->active_txq_lock[txq->ac]); -__ieee80211_unschedule_txq (hw, txq); +ieee80211_remove_txq (hw, txq);spin_unlock_bh (&local->active_txq_lock[txq->ac]); }@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +0
-1lockdep_assert_held (&local->active_txq_lock[txq->ac]); if (!RB_EMPTY_NODE(&txqi->schedule_order) && - (skb_queue_empty(&txqi->frags) &&!txqi->tin.backlog_packets))
net/mac80211/tx.c +3
-1-__ieee80211_unschedule_txq (hw, txq); + !txq_has_queue(&txqi->txq) && + list_empty(&txqi->candidate)) + list_add_tail(&txqi->candidate,&local->remove_list[txq->ac]);
net/mac80211/tx.c +2
-0+ }EXPORT_SYMBOL (ieee80211_return_txq); +void __ieee80211_check_txqs(struct ieee80211_local *local, intac)
net/mac80211/tx.c +20
-0+{ +struct txq_info *iter, *tmp; +struct sta_info *sta; + +lockdep_assert_held (&local->active_txq_lock[ac]); + +list_for_each_entry_safe (iter, tmp, &local->remove_list[ac], + candidate) { + sta = container_of(iter->txq.sta, struct sta_info, sta); + +if (txq_has_queue (&iter->txq)) +list_del_init (&iter->candidate); +else +ieee80211_remove_txq (&local->hw, &iter->txq); + } +} + +void ieee80211_txqs_check (struct timer_list *t) +{ + struct ieee80211_local *local = from_timer(local, t,
remove_timer);net/mac80211/tx.c +12
-0+struct txq_info *iter, *tmp; +struct sta_info *sta; +int ac; + +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +__ieee80211_check_txqs (local, ac); +spin_unlock_bh (&local->active_txq_lock[ac]); + } + + mod_timer(&local->remove_timer, + jiffies +Quoted 2 lines
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); +}I'll ask the same as I did last time (where you told me to hold off until this round):
Quoted 6 lines
Why do you need the timer and the periodic check? If TXQs are added to
the remove list during the scheduling run, and__ieee80211_check_txqs()
is run fromschedule_end(), isn't that sufficient to clear the list?Quoted 4 lines
Is it possible that a txq is not added to the remove list but then packets in it are dropped by
fq_codelalgo? Like the station disconnects
without any notification.Quoted 4 lines
Well as long as all the other cleanup paths call directly into
__unschedule_txq(), that should remove stations from the scheduler when
they disconnect etc.Quoted 13 lines
Yes, the disconnect scenario is a bad example. My concern is, say, we have 10 stations and only one of them is assigned a very small weight compared with that of others. Suppose, after its chance of Tx, it is most likely to be placed in the rightmost(still has some packets in the
txq) and no more incoming data for it. The remaining packets in txq will
be dropped due to timeout algo in codel(correct me if I am wrong) but this empty txq will stay on the rbtree until other txqs get drained or global vt catch up with its vt. The staying time could be long if weight
is extremely small. Then do we need timer to check or any other better solution?Ah, I see what you mean. No, I don't think this will be a problem; the scenario you're describing would play out like this:
1. Station ends transmitting, still has a single packet queued, gets moved to the end of the rbtree (and stays there for a while).
2. When we finally get to the point where this station gets another chance to transmit, the CoDel drop timer triggers and the last
packet
is dropped[0]. This means that the queue will just be empty (andieee80211_tx_dequeue()will return NULL).3. Because the queue is empty,
ieee80211_return_txq()will not put it back on the rbtree.Quoted 6 lines
Quoted 4 lines
Crucially, in 2. the CoDel algorithm doesn't kick in until the point of packet dequeue. But even if an empty queue stays on the rbtree for a while, there is no harm in that: eventually it will get its turn, it will turn out to be empty, and just be skipped over.
Then that will be fine. Thanks for the explanation of the dropping part in CoDel algorithm.
Yup, think so. And you're welcome :)
Quoted 5 lines
Quoted 3 lines
The issue we need to be concerned about is the opposite: If we have a queue that *does* have packets queued, but which is *not* scheduled for transmission, that will stall TX.
Is it by design since its vt is more than global vt, right? The lattency may somehow get impacted though.
Well, it should still stay on the rbtree as long as it has packets queued. We don't have a check anywhere that reschedules TXQs whose
v_tdrops below globalv_t...Quoted 43 lines
Quoted 26 lines
[0] CoDel in most cases only drops a single packet at a time, so it will
not clear out an entire queue with multiple packets in one go. But you are right that it could conceivably drop the last packet in a queue.Quoted 14 lines
Quoted 6 lines
We only need to defer removal inside a single "scheduling round" (i.e.,
between a pair of ieee80211_txq_schedule_start/end. So if we just walk
the remove list inschedule_end()we should be enough, no?Quoted 8 lines
Hmm, or maybe a simpler way to fix the original issue is just to have
unschedule_txq()update theschedule_pos()pointer?I.e.,
unschedule_txqchecks if the txq being removed is currently being
pointed to by schedule_pos[ac], and if it is, it updatesschedule_posto
be therb_nextof the current value?Quoted 4 lines
Actually, if
schedule_posis updated torb_nextof the current value, then in thenext_txq()where we are going to userb_nextagain and finally pick the next node of the node we really want. Is it fine to updateschedule_posto NULL?Hmm, yeah, good point.
Quoted 7 lines
If we do end up setting
schedule_posto NULL in the middle of a scheduling round, that will makenext_txq()"start over", and do another
loop through the whole thing. I guess we may be able hit a case where things can oscillate back and forth between addition and removal resulting in an infinite loop? Not sure, but at least I can't seem to convince myself that this can't happen.As the loop of
next_txqunder lock protection as below,
txq_schedule_start();
while(txq=next_txq()){
...return_txq(txq);
}txq_schedule_end();
Quoted 7 lines
Quoted 1 line
I do not see any chance of addition, no?
As you noted in your other email, Felix reduced the locking. And yeah, we need to rebase this series to also incorporate that. I figure I can send an updated version of the first patch in the series once we've worked out the remaining issues with your follow-up patches.
Oh, I was thinking we were discussing without locking reduced. Yes, I also agree there might be a case causing infinite loop. With locking reduced, the tree can be adjusted between next_txq() and return_txq() in the loop situation. For further discussion, let 's consider,
1) the tree starts like:
A->B->C->D->E
2) then next_txq() returns A for dequeuing
3) driver dequeues A and draines A without any active txq locked meaning the tree could be changed upon Tx compeletion.
4) then in return_txq(), the tree could be,
i A->B->C->D->E (A is empty, and maybe soon be added back
before the loop end)
ii B->C->A->D->E (A is empty, and maybe soon be added back
before the loop end)
iii B->C->D->E->A (A is empty, and maybe soon be added back before the loop end)
with this change:
local->schedule_pos[ac] = rb_next(node) ?: rb_prev(node);
for case i, local->schedule_pos[ac] is rb_next(A) which is B, and in next_txq(), rb_next(B) is what we returns which actually is C and B is skipped, no?
Similiar for case ii, we skip B, C, D.
Also I am wondering if there will be some SMP issues relating with local->schedule_pos[ac].
Quoted 21 lines
Quoted 7 lines
In ath10k, we will usually push packets of first txq as many as we can until it is drained and then move to the next one. So if a txq gets removed in the
return_txq, it should always be the leftmost. And during this period, neither vt of any station or global vt can be updated due to lock protection.Quoted 1 line
Quoted 8 lines
Quoted 6 lines
But in that case, we could fix it by just conditionally assigning either
rb_nextorrb_prevto theschedule_posinunschedule_txq()? I.e., something like:local->schedule_pos[ac] =
rb_next(node)?:rb_prev(node);I am not sure I am getting your point. Still in
next_txq, schedule_pos[ac] will lead us to the next node of the one we want.The logic in
next_txqis different when schedule_pos[ac] is NULL, vs whenrb_next(schedule_pos[ac])is NULL. The former restarts a new scheduling round, while the latter ends the current round.-Toke
Signature · 6 lines
Yibo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 423 lines · Yibo Zhao
Quoted 398 lines · Toke Høiland-Jørgensen
Quoted 326 lines · Yibo Zhao
Quoted 325 lines · Toke Høiland-Jørgensen
Quoted 298 lines · Yibo Zhao
Quoted 283 lines · Toke Høiland-Jørgensen
Quoted 276 lines · Yibo Zhao
Quoted 268 lines · Toke Høiland-Jørgensen
Quoted 9 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the rbtree gets
removed from rbtree immediately in theieee80211_return_txq(), the
loop will break soon in theieee80211_next_txq()due toschedule_pos
not leading to the second txq in the rbtree. Thus, defering the removal right before the end of this schedule round.Quoted 3 lines
Co-developed-by Yibo Zhao <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off. I'll add
ack or review tags as appropriate in reply; but a few comments first:Quoted 241 lines
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)include/net/mac80211.h +2
-0@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 + static inline void ieee80211_rate_set_vht(struct
ieee80211_tx_rate
*rate,include/net/mac80211.h +1
-1u8 mcs, u8 nss) {@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, * @ac: AC number to return packets from. * * Should only be called between calls toieee80211_txq_schedule_start () - * and ieee80211_txq_schedule_end(). + * and ieee80211_txq_schedule_end(). If the txq is empty, itwill
be
added
+ * to a remove list and get removed later.
* Returns the next txq if successful, %NULL if no queue is
eligible.
If a txq
* is returned, it should be returned withieee80211_return_txq()
after the
* driver has finished scheduling it.include/net/mac80211.h +0
-1@@ -6268,7 +6271,8 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) * @hw: pointer as obtained from ieee80211_alloc_hw() * @ac: AC number to acquire locks for * - * Release locks previously acquired by
ieee80211_txq_schedule_end().
+ * Release locks previously acquired byieee80211_txq_schedule_end().
Check
+ * and remove the empty txq from rb-tree.
*/
voidieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac)include/net/mac80211.h +0
-0__releases (txq_lock);@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw, structieee80211_txq*txq)include/net/mac80211.h +8
-0__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed to transmit
*
* This function is used to check whether given txq is allowed
to
transmit bynet/mac80211/ieee80211_i.h +3
-0@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */ @@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;net/mac80211/main.c +5
-0@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, for (i = 0; i < IEEE80211_NUM_ACS; i++) { local->active_txqs[i] = RB_ROOT_CACHED; + INIT_LIST_HEAD(&local->remove_list[i]); spin_lock_init(&local->active_txq_lock[i]); } local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX; + timer_setup(&local->remove_timer, ieee80211_txqs_check, 0); + mod_timer(&local->remove_timer, + jiffies + msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); + INIT_LIST_HEAD(&local->chanctx_list);net/mac80211/main.c +0
-0mutex_init (&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct
ieee80211_hw
*hw)net/mac80211/main.c +1
-0tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif net/mac80211/tx.c +1
-0@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);RB_CLEAR_NODE (&txqi->schedule_order); +INIT_LIST_HEAD (&txqi->candidate); txqi->txq.vif = &sdata->vif;@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +3
-0spin_lock_bh (&local->active_txq_lock[ac]); +if (!list_empty (&txqi->candidate)) +list_del_init (&txqi->candidate); +if (!RB_EMPTY_NODE (&txqi->schedule_order)) goto out;@@ -3783,6 +3787,20 @@ static void__ieee80211_unschedule_txq(struct
ieee80211_hw*hw,net/mac80211/tx.c +15
-1RB_CLEAR_NODE (&txqi->schedule_order); } +void ieee80211_remove_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct txq_info *txqi =to_txq_info (txq); + +lockdep_assert_held (&local->active_txq_lock[txq->ac]); + +if (!RB_EMPTY_NODE (&txqi->schedule_order)) { +__ieee80211_unschedule_txq (hw, txq); +list_del_init (&txqi->candidate); + } +} + void ieee80211_unschedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq) __acquires(txq_lock) __releases(txq_lock)@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(structieee80211_hw *hw, struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh (&local->active_txq_lock[txq->ac]); -__ieee80211_unschedule_txq (hw, txq); +ieee80211_remove_txq (hw, txq);spin_unlock_bh (&local->active_txq_lock[txq->ac]); }@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +0
-1lockdep_assert_held (&local->active_txq_lock[txq->ac]); if (!RB_EMPTY_NODE(&txqi->schedule_order) && - (skb_queue_empty(&txqi->frags) &&!txqi->tin.backlog_packets))
net/mac80211/tx.c +3
-1-__ieee80211_unschedule_txq (hw, txq); + !txq_has_queue(&txqi->txq) && + list_empty(&txqi->candidate)) + list_add_tail(&txqi->candidate,&local->remove_list[txq->ac]);
net/mac80211/tx.c +2
-0+ }EXPORT_SYMBOL (ieee80211_return_txq); +void __ieee80211_check_txqs(struct ieee80211_local *local, intac)
net/mac80211/tx.c +20
-0+{ +struct txq_info *iter, *tmp; +struct sta_info *sta; + +lockdep_assert_held (&local->active_txq_lock[ac]); + +list_for_each_entry_safe (iter, tmp, &local->remove_list[ac], + candidate) { + sta = container_of(iter->txq.sta, struct sta_info, sta); + +if (txq_has_queue (&iter->txq)) +list_del_init (&iter->candidate); +else +ieee80211_remove_txq (&local->hw, &iter->txq); + } +} + +void ieee80211_txqs_check (struct timer_list *t) +{ + struct ieee80211_local *local = from_timer(local, t,
remove_timer);net/mac80211/tx.c +12
-0+struct txq_info *iter, *tmp; +struct sta_info *sta; +int ac; + +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +__ieee80211_check_txqs (local, ac); +spin_unlock_bh (&local->active_txq_lock[ac]); + } + + mod_timer(&local->remove_timer, + jiffies +Quoted 2 lines
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); +}I'll ask the same as I did last time (where you told me to hold off
until this round):Quoted 7 lines
Why do you need the timer and the periodic check? If TXQs are added
to
the remove list during the scheduling run, and__ieee80211_check_txqs()
is run fromschedule_end(), isn't that sufficient to clear the list?Quoted 4 lines
Is it possible that a txq is not added to the remove list but then packets in it are dropped by
fq_codelalgo? Like the station disconnects
without any notification.Quoted 4 lines
Well as long as all the other cleanup paths call directly into
__unschedule_txq(), that should remove stations from the scheduler when
they disconnect etc.Yes, the disconnect scenario is a bad example. My concern is, say, we
have 10 stations and only one of them is assigned a very small weight
compared with that of others. Suppose, after its chance of Tx, it is most likely to be placed in the rightmost(still has some packets in the
txq) and no more incoming data for it. The remaining packets in txq will
be dropped due to timeout algo in codel(correct me if I am wrong)Quoted 8 lines
but
this empty txq will stay on the rbtree until other txqs get drained or
global vt catch up with its vt. The staying time could be long if weight
is extremely small. Then do we need timer to check or any other better
solution?Ah, I see what you mean. No, I don't think this will be a problem; the
scenario you're describing would play out like this:1. Station ends transmitting, still has a single packet queued, gets moved to the end of the rbtree (and stays there for a while).
2. When we finally get to the point where this station gets another chance to transmit, the CoDel drop timer triggers and the last
packet
is dropped[0]. This means that the queue will just be empty (andieee80211_tx_dequeue()will return NULL).3. Because the queue is empty,
ieee80211_return_txq()will not put it back on the rbtree.Quoted 8 lines
Quoted 5 lines
Crucially, in 2. the CoDel algorithm doesn't kick in until the point of
packet dequeue. But even if an empty queue stays on the rbtree for a while, there is no harm in that: eventually it will get its turn, it will turn out to be empty, and just be skipped over.Then that will be fine. Thanks for the explanation of the dropping part
in CoDel algorithm.Yup, think so. And you're welcome :)
Quoted 7 lines
Quoted 4 lines
The issue we need to be concerned about is the opposite: If we have a queue that *does* have packets queued, but which is *not* scheduled for
transmission, that will stall TX.Is it by design since its vt is more than global vt, right? The lattency
may somehow get impacted though.Well, it should still stay on the rbtree as long as it has packets queued. We don't have a check anywhere that reschedules TXQs whose
v_tdrops below globalv_t...Quoted 47 lines
Quoted 30 lines
[0] CoDel in most cases only drops a single packet at a time, so it will
not clear out an entire queue with multiple packets in one go. But you
are right that it could conceivably drop the last packet in a queue.Quoted 16 lines
Quoted 10 lines
We only need to defer removal inside a single "scheduling round" (i.e.,
between a pair of ieee80211_txq_schedule_start/end. So if we just walk
the remove list inschedule_end()we should be enough, no?Hmm, or maybe a simpler way to fix the original issue is just to have
unschedule_txq()update theschedule_pos()pointer?Quoted 6 lines
I.e.,
unschedule_txqchecks if the txq being removed is currently being
pointed to by schedule_pos[ac], and if it is, it updatesschedule_pos
to
be therb_nextof the current value?Quoted 5 lines
Actually, if
schedule_posis updated torb_nextof the current value,
then in thenext_txq()where we are going to userb_nextagain and finally pick the next node of the node we really want. Is it fine to updateschedule_posto NULL?Hmm, yeah, good point.
Quoted 7 lines
If we do end up setting
schedule_posto NULL in the middle of a scheduling round, that will makenext_txq()"start over", and do another
loop through the whole thing. I guess we may be able hit a case where things can oscillate back and forth between addition and removal resulting in an infinite loop? Not sure, but at least I can't seem to convince myself that this can't happen.As the loop of
next_txqunder lock protection as below,
txq_schedule_start();
while(txq=next_txq()){
...return_txq(txq);
}txq_schedule_end();Quoted 7 lines
Quoted 1 line
I do not see any chance of addition, no?
As you noted in your other email, Felix reduced the locking. And yeah, we need to rebase this series to also incorporate that. I figure I can send an updated version of the first patch in the series once we've worked out the remaining issues with your follow-up patches.
Oh, I was thinking we were discussing without locking reduced. Yes, I also agree there might be a case causing infinite loop. With locking reduced, the tree can be adjusted between
next_txq()andreturn_txq()in the loop situation. For further discussion, let 's consider,
1) the tree starts like:A->B->C->D->E2) then
next_txq()returns A for dequeuing
3) driver dequeues A and draines A without any active txq locked meaning the tree could be changed upon Tx compeletion.
4) then inreturn_txq(), the tree could be,i A->B->C->D->E (A is empty, and maybe soon be added back before the loop end) ii B->C->A->D->E (A is empty, and maybe soon be added back before the loop end) iii B->C->D->E->A (A is empty, and maybe soon be added backbefore the loop end)
Quoted 8 lines
with this change:
local->schedule_pos[ac] =rb_next(node)?:rb_prev(node);for case i, local->schedule_pos[ac] is
rb_next(A)which is B, and innext_txq(),rb_next(B)is what we returns which actually is C and B is skipped, no?Similiar for case ii, we skip B, C, D.
Yup, I think you're right. But if we can fix this by making ieee80211_resort_txq() aware of the schedule_pos as well, no? I.e., if resort_txq() acts on the txq that's currently in schedule_pos, it will update schedule pos with the same rb_next(node) ?: rb_prev(node); (optionally after checking that the position of the node is actually going to change).
Quoted 2 lines
Also I am wondering if there will be some SMP issues relating with local->schedule_pos[ac].
Not sure what you mean by this?
Quoted 24 lines
Quoted 21 lines
Quoted 7 lines
In ath10k, we will usually push packets of first txq as many as we can until it is drained and then move to the next one. So if a txq gets removed in the
return_txq, it should always be the leftmost. And during this period, neither vt of any station or global vt can be updated due to lock protection.Quoted 1 line
Quoted 8 lines
Quoted 6 lines
But in that case, we could fix it by just conditionally assigning either
rb_nextorrb_prevto theschedule_posinunschedule_txq()? I.e., something like:local->schedule_pos[ac] =
rb_next(node)?:rb_prev(node);I am not sure I am getting your point. Still in
next_txq, schedule_pos[ac] will lead us to the next node of the one we want.The logic in
next_txqis different when schedule_pos[ac] is NULL, vs whenrb_next(schedule_pos[ac])is NULL. The former restarts a new scheduling round, while the latter ends the current round.-Toke
Signature · 1 line
Yibo
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 474 lines · Toke Høiland-Jørgensen
Quoted 427 lines · Yibo Zhao
Quoted 402 lines · Toke Høiland-Jørgensen
Quoted 330 lines · Yibo Zhao
Quoted 329 lines · Toke Høiland-Jørgensen
Quoted 302 lines · Yibo Zhao
Quoted 287 lines · Toke Høiland-Jørgensen
Quoted 280 lines · Yibo Zhao
Quoted 272 lines · Toke Høiland-Jørgensen
Quoted 9 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the rbtree gets
removed from rbtree immediately in theieee80211_return_txq(), the
loop will break soon in theieee80211_next_txq()due toschedule_pos
not leading to the second txq in the rbtree. Thus, defering the removal right before the end of this schedule round.Quoted 3 lines
Co-developed-by Yibo Zhao <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off. I'll add
ack or review tags as appropriate in reply; but a few comments first:Quoted 245 lines
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)include/net/mac80211.h +2
-0@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 + static inline void ieee80211_rate_set_vht(struct
ieee80211_tx_rate
*rate,include/net/mac80211.h +1
-1u8 mcs, u8 nss) {@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, * @ac: AC number to return packets from. * * Should only be called between calls toieee80211_txq_schedule_start () - * and ieee80211_txq_schedule_end(). + * and ieee80211_txq_schedule_end(). If the txq is empty, itwill
be
added
+ * to a remove list and get removed later.
* Returns the next txq if successful, %NULL if no queue is
eligible.
If a txq
* is returned, it should be returned withieee80211_return_txq()
after the
* driver has finished scheduling it.include/net/mac80211.h +0
-1@@ -6268,7 +6271,8 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) * @hw: pointer as obtained from ieee80211_alloc_hw() * @ac: AC number to acquire locks for * - * Release locks previously acquired by
ieee80211_txq_schedule_end().
+ * Release locks previously acquired byieee80211_txq_schedule_end().
Check
+ * and remove the empty txq from rb-tree.
*/
void ieee80211_txq_schedule_end(structieee80211_hw*hw, u8
ac)include/net/mac80211.h +0
-0__releases (txq_lock);@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw, structieee80211_txq*txq)include/net/mac80211.h +8
-0__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed to
transmit
*
* This function is used to check whether given txq is
allowed
to
transmit bynet/mac80211/ieee80211_i.h +3
-0@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */ @@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;net/mac80211/main.c +5
-0@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, for (i = 0; i < IEEE80211_NUM_ACS; i++) { local->active_txqs[i] = RB_ROOT_CACHED; + INIT_LIST_HEAD(&local->remove_list[i]); spin_lock_init(&local->active_txq_lock[i]); } local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX; + timer_setup(&local->remove_timer, ieee80211_txqs_check, 0); + mod_timer(&local->remove_timer, + jiffies + msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); + INIT_LIST_HEAD(&local->chanctx_list);net/mac80211/main.c +0
-0mutex_init (&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct
ieee80211_hw
*hw)net/mac80211/main.c +1
-0tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif net/mac80211/tx.c +1
-0@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);RB_CLEAR_NODE (&txqi->schedule_order); +INIT_LIST_HEAD (&txqi->candidate); txqi->txq.vif = &sdata->vif;@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +3
-0spin_lock_bh (&local->active_txq_lock[ac]); +if (!list_empty (&txqi->candidate)) +list_del_init (&txqi->candidate); +if (!RB_EMPTY_NODE (&txqi->schedule_order)) goto out;@@ -3783,6 +3787,20 @@ static void__ieee80211_unschedule_txq(struct
ieee80211_hw*hw,net/mac80211/tx.c +15
-1RB_CLEAR_NODE (&txqi->schedule_order); } +void ieee80211_remove_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct txq_info *txqi =to_txq_info (txq); + +lockdep_assert_held (&local->active_txq_lock[txq->ac]); + +if (!RB_EMPTY_NODE (&txqi->schedule_order)) { +__ieee80211_unschedule_txq (hw, txq); +list_del_init (&txqi->candidate); + } +} + void ieee80211_unschedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq) __acquires(txq_lock) __releases(txq_lock)@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(structieee80211_hw *hw, struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh (&local->active_txq_lock[txq->ac]); -__ieee80211_unschedule_txq (hw, txq); +ieee80211_remove_txq (hw, txq);spin_unlock_bh (&local->active_txq_lock[txq->ac]); }@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +0
-1lockdep_assert_held (&local->active_txq_lock[txq->ac]); if (!RB_EMPTY_NODE(&txqi->schedule_order) && - (skb_queue_empty(&txqi->frags) &&!txqi->tin.backlog_packets))
net/mac80211/tx.c +3
-1-__ieee80211_unschedule_txq (hw, txq); + !txq_has_queue(&txqi->txq) && + list_empty(&txqi->candidate)) + list_add_tail(&txqi->candidate,&local->remove_list[txq->ac]);
net/mac80211/tx.c +2
-0+ }EXPORT_SYMBOL (ieee80211_return_txq); +void __ieee80211_check_txqs(struct ieee80211_local *local,int
ac)net/mac80211/tx.c +20
-0+{ +struct txq_info *iter, *tmp; +struct sta_info *sta; + +lockdep_assert_held (&local->active_txq_lock[ac]); + +list_for_each_entry_safe (iter, tmp, &local->remove_list[ac], + candidate) { + sta = container_of(iter->txq.sta, struct sta_info, sta); + +if (txq_has_queue (&iter->txq)) +list_del_init (&iter->candidate); +else +ieee80211_remove_txq (&local->hw, &iter->txq); + } +} + +void ieee80211_txqs_check (struct timer_list *t) +{ + struct ieee80211_local *local = from_timer(local, t,
remove_timer);net/mac80211/tx.c +12
-0+struct txq_info *iter, *tmp; +struct sta_info *sta; +int ac; + +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +__ieee80211_check_txqs (local, ac); +spin_unlock_bh (&local->active_txq_lock[ac]); + } + + mod_timer(&local->remove_timer, + jiffies +Quoted 2 lines
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); +}I'll ask the same as I did last time (where you told me to hold off
until this round):Quoted 7 lines
Why do you need the timer and the periodic check? If TXQs are added
to
the remove list during the scheduling run, and__ieee80211_check_txqs()
is run fromschedule_end(), isn't that sufficient to clear the list?Quoted 4 lines
Is it possible that a txq is not added to the remove list but then packets in it are dropped by
fq_codelalgo? Like the station disconnects
without any notification.Quoted 4 lines
Well as long as all the other cleanup paths call directly into
__unschedule_txq(), that should remove stations from the scheduler when
they disconnect etc.Yes, the disconnect scenario is a bad example. My concern is, say, we
have 10 stations and only one of them is assigned a very small weight
compared with that of others. Suppose, after its chance of Tx, it is most likely to be placed in the rightmost(still has some packets in the
txq) and no more incoming data for it. The remaining packets in txq will
be dropped due to timeout algo in codel(correct me if I am wrong)Quoted 8 lines
but
this empty txq will stay on the rbtree until other txqs get drained or
global vt catch up with its vt. The staying time could be long if weight
is extremely small. Then do we need timer to check or any other better
solution?Ah, I see what you mean. No, I don't think this will be a problem; the
scenario you're describing would play out like this:1. Station ends transmitting, still has a single packet queued, gets moved to the end of the rbtree (and stays there for a while).
2. When we finally get to the point where this station gets another chance to transmit, the CoDel drop timer triggers and the last
packet
is dropped[0]. This means that the queue will just be empty (andieee80211_tx_dequeue()will return NULL).3. Because the queue is empty,
ieee80211_return_txq()will not put it back on the rbtree.Quoted 8 lines
Quoted 5 lines
Crucially, in 2. the CoDel algorithm doesn't kick in until the point of
packet dequeue. But even if an empty queue stays on the rbtree for a while, there is no harm in that: eventually it will get its turn, it will turn out to be empty, and just be skipped over.Then that will be fine. Thanks for the explanation of the dropping part
in CoDel algorithm.Yup, think so. And you're welcome :)
Quoted 7 lines
Quoted 4 lines
The issue we need to be concerned about is the opposite: If we have a queue that *does* have packets queued, but which is *not* scheduled for
transmission, that will stall TX.Is it by design since its vt is more than global vt, right? The lattency
may somehow get impacted though.Well, it should still stay on the rbtree as long as it has packets queued. We don't have a check anywhere that reschedules TXQs whose
v_tdrops below globalv_t...Quoted 47 lines
Quoted 30 lines
[0] CoDel in most cases only drops a single packet at a time, so it will
not clear out an entire queue with multiple packets in one go. But you
are right that it could conceivably drop the last packet in a queue.Quoted 16 lines
Quoted 10 lines
We only need to defer removal inside a single "scheduling round" (i.e.,
between a pair of ieee80211_txq_schedule_start/end. So if we just walk
the remove list inschedule_end()we should be enough, no?Hmm, or maybe a simpler way to fix the original issue is just to have
unschedule_txq()update theschedule_pos()pointer?Quoted 6 lines
I.e.,
unschedule_txqchecks if the txq being removed is currently being
pointed to by schedule_pos[ac], and if it is, it updatesschedule_pos
to
be therb_nextof the current value?Quoted 5 lines
Actually, if
schedule_posis updated torb_nextof the current value,
then in thenext_txq()where we are going to userb_nextagain and finally pick the next node of the node we really want. Is it fine to updateschedule_posto NULL?Hmm, yeah, good point.
Quoted 7 lines
If we do end up setting
schedule_posto NULL in the middle of a scheduling round, that will makenext_txq()"start over", and do another
loop through the whole thing. I guess we may be able hit a case where things can oscillate back and forth between addition and removal resulting in an infinite loop? Not sure, but at least I can't seem to convince myself that this can't happen.As the loop of
next_txqunder lock protection as below,
txq_schedule_start();
while(txq=next_txq()){
...return_txq(txq);
}txq_schedule_end();Quoted 7 lines
Quoted 1 line
I do not see any chance of addition, no?
As you noted in your other email, Felix reduced the locking. And yeah, we need to rebase this series to also incorporate that. I figure I can send an updated version of the first patch in the series once we've worked out the remaining issues with your follow-up patches.
Oh, I was thinking we were discussing without locking reduced. Yes, I also agree there might be a case causing infinite loop. With locking reduced, the tree can be adjusted between
next_txq()andreturn_txq()in the loop situation. For further discussion, let 's consider,
1) the tree starts like:A->B->C->D->E2) then
next_txq()returns A for dequeuing
3) driver dequeues A and draines A without any active txq locked meaning the tree could be changed upon Tx compeletion.
4) then inreturn_txq(), the tree could be,i A->B->C->D->E (A is empty, and maybe soon be added back before the loop end) ii B->C->A->D->E (A is empty, and maybe soon be added back before the loop end) iii B->C->D->E->A (A is empty, and maybe soon be added backbefore the loop end)
Quoted 8 lines
with this change:
local->schedule_pos[ac] =rb_next(node)?:rb_prev(node);for case i, local->schedule_pos[ac] is
rb_next(A)which is B, and innext_txq(),rb_next(B)is what we returns which actually is C and B is skipped, no?Similiar for case ii, we skip B, C, D.
Yup, I think you're right. But if we can fix this by making
ieee80211_resort_txq()aware of theschedule_posas well, no? I.e., ifresort_txq()acts on the txq that's currently inschedule_pos, it will update schedule pos with the samerb_next(node)?:rb_prev(node); (optionally after checking that the position of the node is actually going to change).Quoted 2 lines
Also I am wondering if there will be some SMP issues relating with local->schedule_pos[ac].
Not sure what you mean by this?
Quoted 24 lines
Quoted 13 lines
Quoted 13 lines
In ath10k, we will usually push packets of first txq as many as we can until it is drained and then move to the next one. So if a txq gets removed in the
return_txq, it should always be the leftmost. And during this period, neither vt of any station or global vt can be updated due to lock protection.Quoted 7 lines
But in that case, we could fix it by just conditionally assigning either
rb_nextorrb_prevto theschedule_posinunschedule_txq()? I.e., something like:local->schedule_pos[ac] =
rb_next(node)?:rb_prev(node);Quoted 8 lines
Quoted 2 lines
I am not sure I am getting your point. Still in
next_txq, schedule_pos[ac] will lead us to the next node of the one we want.The logic in
next_txqis different when schedule_pos[ac] is NULL, vs whenrb_next(schedule_pos[ac])is NULL. The former restarts a new scheduling round, while the latter ends the current round.-Toke
--
Yibo
Signature · 6 lines
Yibo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
In reply to Toke Høiland-JørgensenQuoted 436 lines · Toke Høiland-Jørgensen
Quoted 434 lines · Yibo Zhao
Quoted 402 lines · Toke Høiland-Jørgensen
Quoted 330 lines · Yibo Zhao
Quoted 329 lines · Toke Høiland-Jørgensen
Quoted 302 lines · Yibo Zhao
Quoted 287 lines · Toke Høiland-Jørgensen
Quoted 280 lines · Yibo Zhao
Quoted 272 lines · Toke Høiland-Jørgensen
Quoted 9 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the rbtree gets
removed from rbtree immediately in theieee80211_return_txq(), the
loop will break soon in theieee80211_next_txq()due toschedule_pos
not leading to the second txq in the rbtree. Thus, defering the removal right before the end of this schedule round.Quoted 3 lines
Co-developed-by Yibo Zhao <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off. I'll add
ack or review tags as appropriate in reply; but a few comments first:Quoted 245 lines
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)include/net/mac80211.h +2
-0@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 + static inline void ieee80211_rate_set_vht(struct
ieee80211_tx_rate
*rate,include/net/mac80211.h +1
-1u8 mcs, u8 nss) {@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, * @ac: AC number to return packets from. * * Should only be called between calls toieee80211_txq_schedule_start () - * and ieee80211_txq_schedule_end(). + * and ieee80211_txq_schedule_end(). If the txq is empty, itwill
be
added
+ * to a remove list and get removed later.
* Returns the next txq if successful, %NULL if no queue is
eligible.
If a txq
* is returned, it should be returned withieee80211_return_txq()
after the
* driver has finished scheduling it.include/net/mac80211.h +0
-1@@ -6268,7 +6271,8 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) * @hw: pointer as obtained from ieee80211_alloc_hw() * @ac: AC number to acquire locks for * - * Release locks previously acquired by
ieee80211_txq_schedule_end().
+ * Release locks previously acquired byieee80211_txq_schedule_end().
Check
+ * and remove the empty txq from rb-tree.
*/
void ieee80211_txq_schedule_end(structieee80211_hw*hw, u8
ac)include/net/mac80211.h +0
-0__releases (txq_lock);@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw, structieee80211_txq*txq)include/net/mac80211.h +8
-0__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed to
transmit
*
* This function is used to check whether given txq is
allowed
to
transmit bynet/mac80211/ieee80211_i.h +3
-0@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */ @@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;net/mac80211/main.c +5
-0@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, for (i = 0; i < IEEE80211_NUM_ACS; i++) { local->active_txqs[i] = RB_ROOT_CACHED; + INIT_LIST_HEAD(&local->remove_list[i]); spin_lock_init(&local->active_txq_lock[i]); } local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX; + timer_setup(&local->remove_timer, ieee80211_txqs_check, 0); + mod_timer(&local->remove_timer, + jiffies + msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); + INIT_LIST_HEAD(&local->chanctx_list);net/mac80211/main.c +0
-0mutex_init (&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct
ieee80211_hw
*hw)net/mac80211/main.c +1
-0tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif net/mac80211/tx.c +1
-0@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);RB_CLEAR_NODE (&txqi->schedule_order); +INIT_LIST_HEAD (&txqi->candidate); txqi->txq.vif = &sdata->vif;@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +3
-0spin_lock_bh (&local->active_txq_lock[ac]); +if (!list_empty (&txqi->candidate)) +list_del_init (&txqi->candidate); +if (!RB_EMPTY_NODE (&txqi->schedule_order)) goto out;@@ -3783,6 +3787,20 @@ static void__ieee80211_unschedule_txq(struct
ieee80211_hw*hw,net/mac80211/tx.c +15
-1RB_CLEAR_NODE (&txqi->schedule_order); } +void ieee80211_remove_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct txq_info *txqi =to_txq_info (txq); + +lockdep_assert_held (&local->active_txq_lock[txq->ac]); + +if (!RB_EMPTY_NODE (&txqi->schedule_order)) { +__ieee80211_unschedule_txq (hw, txq); +list_del_init (&txqi->candidate); + } +} + void ieee80211_unschedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq) __acquires(txq_lock) __releases(txq_lock)@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(structieee80211_hw *hw, struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh (&local->active_txq_lock[txq->ac]); -__ieee80211_unschedule_txq (hw, txq); +ieee80211_remove_txq (hw, txq);spin_unlock_bh (&local->active_txq_lock[txq->ac]); }@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +0
-1lockdep_assert_held (&local->active_txq_lock[txq->ac]); if (!RB_EMPTY_NODE(&txqi->schedule_order) && - (skb_queue_empty(&txqi->frags) &&!txqi->tin.backlog_packets))
net/mac80211/tx.c +3
-1-__ieee80211_unschedule_txq (hw, txq); + !txq_has_queue(&txqi->txq) && + list_empty(&txqi->candidate)) + list_add_tail(&txqi->candidate,&local->remove_list[txq->ac]);
net/mac80211/tx.c +2
-0+ }EXPORT_SYMBOL (ieee80211_return_txq); +void __ieee80211_check_txqs(struct ieee80211_local *local,int
ac)net/mac80211/tx.c +20
-0+{ +struct txq_info *iter, *tmp; +struct sta_info *sta; + +lockdep_assert_held (&local->active_txq_lock[ac]); + +list_for_each_entry_safe (iter, tmp, &local->remove_list[ac], + candidate) { + sta = container_of(iter->txq.sta, struct sta_info, sta); + +if (txq_has_queue (&iter->txq)) +list_del_init (&iter->candidate); +else +ieee80211_remove_txq (&local->hw, &iter->txq); + } +} + +void ieee80211_txqs_check (struct timer_list *t) +{ + struct ieee80211_local *local = from_timer(local, t,
remove_timer);net/mac80211/tx.c +12
-0+struct txq_info *iter, *tmp; +struct sta_info *sta; +int ac; + +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +__ieee80211_check_txqs (local, ac); +spin_unlock_bh (&local->active_txq_lock[ac]); + } + + mod_timer(&local->remove_timer, + jiffies +Quoted 2 lines
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); +}I'll ask the same as I did last time (where you told me to hold off
until this round):Quoted 7 lines
Why do you need the timer and the periodic check? If TXQs are added
to
the remove list during the scheduling run, and__ieee80211_check_txqs()
is run fromschedule_end(), isn't that sufficient to clear the list?Quoted 4 lines
Is it possible that a txq is not added to the remove list but then packets in it are dropped by
fq_codelalgo? Like the station disconnects
without any notification.Quoted 4 lines
Well as long as all the other cleanup paths call directly into
__unschedule_txq(), that should remove stations from the scheduler when
they disconnect etc.Yes, the disconnect scenario is a bad example. My concern is, say, we
have 10 stations and only one of them is assigned a very small weight
compared with that of others. Suppose, after its chance of Tx, it is most likely to be placed in the rightmost(still has some packets in the
txq) and no more incoming data for it. The remaining packets in txq will
be dropped due to timeout algo in codel(correct me if I am wrong)Quoted 8 lines
but
this empty txq will stay on the rbtree until other txqs get drained or
global vt catch up with its vt. The staying time could be long if weight
is extremely small. Then do we need timer to check or any other better
solution?Ah, I see what you mean. No, I don't think this will be a problem; the
scenario you're describing would play out like this:1. Station ends transmitting, still has a single packet queued, gets moved to the end of the rbtree (and stays there for a while).
2. When we finally get to the point where this station gets another chance to transmit, the CoDel drop timer triggers and the last
packet
is dropped[0]. This means that the queue will just be empty (andieee80211_tx_dequeue()will return NULL).3. Because the queue is empty,
ieee80211_return_txq()will not put it back on the rbtree.Quoted 8 lines
Quoted 5 lines
Crucially, in 2. the CoDel algorithm doesn't kick in until the point of
packet dequeue. But even if an empty queue stays on the rbtree for a while, there is no harm in that: eventually it will get its turn, it will turn out to be empty, and just be skipped over.Then that will be fine. Thanks for the explanation of the dropping part
in CoDel algorithm.Yup, think so. And you're welcome :)
Quoted 7 lines
Quoted 4 lines
The issue we need to be concerned about is the opposite: If we have a queue that *does* have packets queued, but which is *not* scheduled for
transmission, that will stall TX.Is it by design since its vt is more than global vt, right? The lattency
may somehow get impacted though.Well, it should still stay on the rbtree as long as it has packets queued. We don't have a check anywhere that reschedules TXQs whose
v_tdrops below globalv_t...Quoted 47 lines
Quoted 30 lines
[0] CoDel in most cases only drops a single packet at a time, so it will
not clear out an entire queue with multiple packets in one go. But you
are right that it could conceivably drop the last packet in a queue.Quoted 16 lines
Quoted 10 lines
We only need to defer removal inside a single "scheduling round" (i.e.,
between a pair of ieee80211_txq_schedule_start/end. So if we just walk
the remove list inschedule_end()we should be enough, no?Hmm, or maybe a simpler way to fix the original issue is just to have
unschedule_txq()update theschedule_pos()pointer?Quoted 6 lines
I.e.,
unschedule_txqchecks if the txq being removed is currently being
pointed to by schedule_pos[ac], and if it is, it updatesschedule_pos
to
be therb_nextof the current value?Quoted 5 lines
Actually, if
schedule_posis updated torb_nextof the current value,
then in thenext_txq()where we are going to userb_nextagain and finally pick the next node of the node we really want. Is it fine to updateschedule_posto NULL?Hmm, yeah, good point.
Quoted 7 lines
If we do end up setting
schedule_posto NULL in the middle of a scheduling round, that will makenext_txq()"start over", and do another
loop through the whole thing. I guess we may be able hit a case where things can oscillate back and forth between addition and removal resulting in an infinite loop? Not sure, but at least I can't seem to convince myself that this can't happen.As the loop of
next_txqunder lock protection as below,
txq_schedule_start();
while(txq=next_txq()){
...return_txq(txq);
}txq_schedule_end();Quoted 7 lines
Quoted 1 line
I do not see any chance of addition, no?
As you noted in your other email, Felix reduced the locking. And yeah, we need to rebase this series to also incorporate that. I figure I can send an updated version of the first patch in the series once we've worked out the remaining issues with your follow-up patches.
Oh, I was thinking we were discussing without locking reduced. Yes, I also agree there might be a case causing infinite loop. With locking reduced, the tree can be adjusted between
next_txq()andreturn_txq()in the loop situation. For further discussion, let 's consider,
1) the tree starts like:A->B->C->D->E2) then
next_txq()returns A for dequeuing
3) driver dequeues A and draines A without any active txq locked meaning the tree could be changed upon Tx compeletion.
4) then inreturn_txq(), the tree could be,i A->B->C->D->E (A is empty, and maybe soon be added back before the loop end) ii B->C->A->D->E (A is empty, and maybe soon be added back before the loop end) iii B->C->D->E->A (A is empty, and maybe soon be added backbefore the loop end)
with this change:
local->schedule_pos[ac] =rb_next(node)?:rb_prev(node);for case i, local->schedule_pos[ac] is
rb_next(A)which is B, and innext_txq(),rb_next(B)is what we returns which actually is C and B is skipped, no?
Quoted 8 lines
Quoted 1 line
Similiar for case ii, we skip B, C, D.
Yup, I think you're right. But if we can fix this by making
ieee80211_resort_txq()aware of theschedule_posas well, no? I.e., ifresort_txq()acts on the txq that's currently inschedule_pos, it will update schedule pos with the samerb_next(node)?:rb_prev(node); (optionally after checking that the position of the node is actually going to change).
Sorry, please igore last email sent by mistake.
I don't think it makes any difference with that in unschedule_txq(). For case i, it finally picks C as well in next_txq(). For next_txq(), schedule_pos means previous candidate node whereas with your change, it looks like schedule_pos is current candidate node instead.
Quoted 4 lines
Quoted 2 lines
Also I am wondering if there will be some SMP issues relating with local->schedule_pos[ac].
Not sure what you mean by this?
My bad. Please ignore this.
Quoted 25 lines
Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
In ath10k, we will usually push packets of first txq as many as we can until it is drained and then move to the next one. So if a txq gets removed in the
return_txq, it should always be the leftmost. And during this period, neither vt of any station or global vt can be updated due to lock protection.Quoted 7 lines
But in that case, we could fix it by just conditionally assigning either
rb_nextorrb_prevto theschedule_posinunschedule_txq()? I.e., something like:local->schedule_pos[ac] =
rb_next(node)?:rb_prev(node);Quoted 8 lines
Quoted 2 lines
I am not sure I am getting your point. Still in
next_txq, schedule_pos[ac] will lead us to the next node of the one we want.The logic in
next_txqis different when schedule_pos[ac] is NULL, vs whenrb_next(schedule_pos[ac])is NULL. The former restarts a new scheduling round, while the latter ends the current round.-Toke
--
Yibo
Signature · 6 lines
Yibo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 469 lines · Yibo Zhao
Quoted 460 lines · Toke Høiland-Jørgensen
Quoted 458 lines · Yibo Zhao
Quoted 422 lines · Toke Høiland-Jørgensen
Quoted 349 lines · Yibo Zhao
Quoted 340 lines · Toke Høiland-Jørgensen
Quoted 311 lines · Yibo Zhao
Quoted 291 lines · Toke Høiland-Jørgensen
Quoted 283 lines · Yibo Zhao
Quoted 275 lines · Toke Høiland-Jørgensen
Quoted 11 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the rbtree
gets
removed from rbtree immediately in theieee80211_return_txq(), the
loop will break soon in theieee80211_next_txq()due toschedule_pos
not leading to the second txq in the rbtree. Thus, defering the
removal right before the end of this schedule round.Quoted 3 lines
Co-developed-by Yibo Zhao <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off. I'll
add
ack or review tags as appropriate in reply; but a few comments first:Quoted 245 lines
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)include/net/mac80211.h +2
-0@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 + static inline void ieee80211_rate_set_vht(struct
ieee80211_tx_rate
*rate,include/net/mac80211.h +1
-1u8 mcs, u8 nss) {@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, * @ac: AC number to return packets from. * * Should only be called between calls toieee80211_txq_schedule_start () - * and ieee80211_txq_schedule_end(). + * and ieee80211_txq_schedule_end(). If the txq is empty, itwill
be
added
+ * to a remove list and get removed later.
* Returns the next txq if successful, %NULL if no queue is
eligible.
If a txq
* is returned, it should be returned withieee80211_return_txq()
after the
* driver has finished scheduling it.include/net/mac80211.h +0
-1@@ -6268,7 +6271,8 @@ void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) * @hw: pointer as obtained from ieee80211_alloc_hw() * @ac: AC number to acquire locks for * - * Release locks previously acquired by
ieee80211_txq_schedule_end().
+ * Release locks previously acquired byieee80211_txq_schedule_end().
Check
+ * and remove the empty txq from rb-tree.
*/
void ieee80211_txq_schedule_end(structieee80211_hw*hw, u8
ac)include/net/mac80211.h +0
-0__releases (txq_lock);@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw, structieee80211_txq*txq)include/net/mac80211.h +8
-0__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed to
transmit
*
* This function is used to check whether given txq is
allowed
to
transmit bynet/mac80211/ieee80211_i.h +3
-0@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */ @@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;net/mac80211/main.c +5
-0@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, for (i = 0; i < IEEE80211_NUM_ACS; i++) { local->active_txqs[i] = RB_ROOT_CACHED; + INIT_LIST_HEAD(&local->remove_list[i]); spin_lock_init(&local->active_txq_lock[i]); } local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX; + timer_setup(&local->remove_timer, ieee80211_txqs_check, 0); + mod_timer(&local->remove_timer, + jiffies + msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); + INIT_LIST_HEAD(&local->chanctx_list);net/mac80211/main.c +0
-0mutex_init (&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct
ieee80211_hw
*hw)net/mac80211/main.c +1
-0tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif net/mac80211/tx.c +1
-0@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);RB_CLEAR_NODE (&txqi->schedule_order); +INIT_LIST_HEAD (&txqi->candidate); txqi->txq.vif = &sdata->vif;@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +3
-0spin_lock_bh (&local->active_txq_lock[ac]); +if (!list_empty (&txqi->candidate)) +list_del_init (&txqi->candidate); +if (!RB_EMPTY_NODE (&txqi->schedule_order)) goto out;@@ -3783,6 +3787,20 @@ static void__ieee80211_unschedule_txq(struct
ieee80211_hw*hw,net/mac80211/tx.c +15
-1RB_CLEAR_NODE (&txqi->schedule_order); } +void ieee80211_remove_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct txq_info *txqi =to_txq_info (txq); + +lockdep_assert_held (&local->active_txq_lock[txq->ac]); + +if (!RB_EMPTY_NODE (&txqi->schedule_order)) { +__ieee80211_unschedule_txq (hw, txq); +list_del_init (&txqi->candidate); + } +} + void ieee80211_unschedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq) __acquires(txq_lock) __releases(txq_lock)@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(structieee80211_hw *hw, struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh (&local->active_txq_lock[txq->ac]); -__ieee80211_unschedule_txq (hw, txq); +ieee80211_remove_txq (hw, txq);spin_unlock_bh (&local->active_txq_lock[txq->ac]); }@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +0
-1lockdep_assert_held (&local->active_txq_lock[txq->ac]); if (!RB_EMPTY_NODE(&txqi->schedule_order) && - (skb_queue_empty(&txqi->frags) &&!txqi->tin.backlog_packets))
net/mac80211/tx.c +3
-1-__ieee80211_unschedule_txq (hw, txq); + !txq_has_queue(&txqi->txq) && + list_empty(&txqi->candidate)) + list_add_tail(&txqi->candidate,&local->remove_list[txq->ac]);
net/mac80211/tx.c +2
-0+ }EXPORT_SYMBOL (ieee80211_return_txq); +void __ieee80211_check_txqs(struct ieee80211_local *local,int
ac)net/mac80211/tx.c +20
-0+{ +struct txq_info *iter, *tmp; +struct sta_info *sta; + +lockdep_assert_held (&local->active_txq_lock[ac]); + +list_for_each_entry_safe (iter, tmp, &local->remove_list[ac], + candidate) { + sta = container_of(iter->txq.sta, struct sta_info, sta); + +if (txq_has_queue (&iter->txq)) +list_del_init (&iter->candidate); +else +ieee80211_remove_txq (&local->hw, &iter->txq); + } +} + +void ieee80211_txqs_check (struct timer_list *t) +{ + struct ieee80211_local *local = from_timer(local, t,
remove_timer);net/mac80211/tx.c +12
-0+struct txq_info *iter, *tmp; +struct sta_info *sta; +int ac; + +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +__ieee80211_check_txqs (local, ac); +spin_unlock_bh (&local->active_txq_lock[ac]); + } + + mod_timer(&local->remove_timer, + jiffies +Quoted 2 lines
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); +}I'll ask the same as I did last time (where you told me to hold off
until this round):Quoted 7 lines
Why do you need the timer and the periodic check? If TXQs are added
to
the remove list during the scheduling run, and__ieee80211_check_txqs()
is run fromschedule_end(), isn't that sufficient to clear the list?Quoted 5 lines
Is it possible that a txq is not added to the remove list but then
packets in it are dropped byfq_codelalgo? Like the station disconnects
without any notification.Quoted 5 lines
Well as long as all the other cleanup paths call directly into
__unschedule_txq(), that should remove stations from the scheduler
when
they disconnect etc.Yes, the disconnect scenario is a bad example. My concern is, say, we
have 10 stations and only one of them is assigned a very small weight
compared with that of others. Suppose, after its chance of Tx, it is
most likely to be placed in the rightmost(still has some packets in
the
txq) and no more incoming data for it. The remaining packets in txq
will
be dropped due to timeout algo in codel(correct me if I am wrong) butQuoted 8 lines
this empty txq will stay on the rbtree until other txqs get drained
or
global vt catch up with its vt. The staying time could be long if weight
is extremely small. Then do we need timer to check or any other better
solution?Ah, I see what you mean. No, I don't think this will be a problem; the
scenario you're describing would play out like this:1. Station ends transmitting, still has a single packet queued, gets
moved to the end of the rbtree (and stays there for a while).2. When we finally get to the point where this station gets another chance to transmit, the CoDel drop timer triggers and the last
packet
is dropped[0]. This means that the queue will just be empty (andieee80211_tx_dequeue()will return NULL).3. Because the queue is empty,
ieee80211_return_txq()will not put it
back on the rbtree.Quoted 8 lines
Crucially, in 2. the CoDel algorithm doesn't kick in until the point
of
packet dequeue. But even if an empty queue stays on the rbtree for a
while, there is no harm in that: eventually it will get its turn, it
will turn out to be empty, and just be skipped over.Quoted 3 lines
Then that will be fine. Thanks for the explanation of the dropping part
in CoDel algorithm.Yup, think so. And you're welcome :)
Quoted 8 lines
Quoted 5 lines
The issue we need to be concerned about is the opposite: If we have a
queue that *does* have packets queued, but which is *not* scheduled for
transmission, that will stall TX.Is it by design since its vt is more than global vt, right? The lattency
may somehow get impacted though.Well, it should still stay on the rbtree as long as it has packets queued. We don't have a check anywhere that reschedules TXQs whose
v_t
drops below globalv_t...Quoted 51 lines
Quoted 32 lines
[0] CoDel in most cases only drops a single packet at a time, so it will
not clear out an entire queue with multiple packets in one go. But you
are right that it could conceivably drop the last packet in a queue.Quoted 16 lines
Quoted 10 lines
We only need to defer removal inside a single "scheduling round" (i.e.,
between a pair of ieee80211_txq_schedule_start/end. So if we just walk
the remove list inschedule_end()we should be enough, no?Hmm, or maybe a simpler way to fix the original issue is just to have
unschedule_txq()update theschedule_pos()pointer?Quoted 6 lines
I.e.,
unschedule_txqchecks if the txq being removed is currently being
pointed to by schedule_pos[ac], and if it is, it updatesschedule_pos
to
be therb_nextof the current value?Quoted 6 lines
Actually, if
schedule_posis updated torb_nextof the current value,
then in thenext_txq()where we are going to userb_nextagain and finally pick the next node of the node we really want. Is it fine to
updateschedule_posto NULL?Hmm, yeah, good point.
Quoted 9 lines
If we do end up setting
schedule_posto NULL in the middle of a scheduling round, that will makenext_txq()"start over", and do another
loop through the whole thing. I guess we may be able hit a case where
things can oscillate back and forth between addition and removal resulting in an infinite loop? Not sure, but at least I can't seem to
convince myself that this can't happen.As the loop of
next_txqunder lock protection as below,
txq_schedule_start();
while(txq=next_txq()){
...return_txq(txq);
}txq_schedule_end();Quoted 9 lines
Quoted 1 line
I do not see any chance of addition, no?
As you noted in your other email, Felix reduced the locking. And yeah,
we need to rebase this series to also incorporate that. I figure I can
send an updated version of the first patch in the series once we've worked out the remaining issues with your follow-up patches.Oh, I was thinking we were discussing without locking reduced. Yes, I also agree there might be a case causing infinite loop. With locking reduced, the tree can be adjusted between
next_txq()andreturn_txq()in
the loop situation. For further discussion, let 's consider,
1) the tree starts like:A->B->C->D->E2) then
next_txq()returns A for dequeuing
3) driver dequeues A and draines A without any active txq locked meaning
the tree could be changed upon Tx compeletion.
4) then inreturn_txq(), the tree could be,i A->B->C->D->E (A is empty, and maybe soon be added back before the loop end) ii B->C->A->D->E (A is empty, and maybe soon be added back before the loop end) iii B->C->D->E->A (A is empty, and maybe soon be added backbefore the loop end)
with this change:
local->schedule_pos[ac] =rb_next(node)?:rb_prev(node);for case i, local->schedule_pos[ac] is
rb_next(A)which is B, and innext_txq(),rb_next(B)is what we returns which actually is C and B is skipped, no?Quoted 8 lines
Quoted 1 line
Similiar for case ii, we skip B, C, D.
Yup, I think you're right. But if we can fix this by making
ieee80211_resort_txq()aware of theschedule_posas well, no? I.e., ifresort_txq()acts on the txq that's currently inschedule_pos, it will update schedule pos with the samerb_next(node)?:rb_prev(node); (optionally after checking that the position of the node is actually going to change).
Quoted 6 lines
Sorry, please igore last email sent by mistake.
I don't think it makes any difference with that in
unschedule_txq(). For case i, it finally picks C as well innext_txq(). Fornext_txq(),schedule_posmeans previous candidate node whereas with your change, it looks likeschedule_posis current candidate node instead.
Hmm, that was not actually what I was thinking, but yeah I think you're right that it would be easier to just change it so schedule_pos is pointing to the next and not the current txq we want to schedule.
We'd still need a check in resort_txq() then, but it would make it safe to unschedule in return_txq()...
Quoted 36 lines
Quoted 4 lines
Quoted 2 lines
Also I am wondering if there will be some SMP issues relating with local->schedule_pos[ac].
Not sure what you mean by this?
My bad. Please ignore this.
Quoted 26 lines
Quoted 26 lines
Quoted 15 lines
Quoted 15 lines
In ath10k, we will usually push packets of first txq as many as we can
until it is drained and then move to the next one. So if a txq gets removed in thereturn_txq, it should always be the leftmost. And during this period, neither vt of any station or global vt can be updated due to lock protection.Quoted 7 lines
But in that case, we could fix it by just conditionally assigning either
rb_nextorrb_prevto theschedule_posinunschedule_txq()? I.e., something like:local->schedule_pos[ac] =
rb_next(node)?:rb_prev(node);Quoted 8 lines
Quoted 2 lines
I am not sure I am getting your point. Still in
next_txq, schedule_pos[ac] will lead us to the next node of the one we want.The logic in
next_txqis different when schedule_pos[ac] is NULL, vs whenrb_next(schedule_pos[ac])is NULL. The former restarts a new scheduling round, while the latter ends the current round.-Toke
--
YiboSignature · 1 line
Yibo
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 478 lines · Toke Høiland-Jørgensen
Quoted 476 lines · Yibo Zhao
Quoted 465 lines · Toke Høiland-Jørgensen
Quoted 463 lines · Yibo Zhao
Quoted 427 lines · Toke Høiland-Jørgensen
Quoted 354 lines · Yibo Zhao
Quoted 345 lines · Toke Høiland-Jørgensen
Quoted 316 lines · Yibo Zhao
Quoted 296 lines · Toke Høiland-Jørgensen
Quoted 288 lines · Yibo Zhao
Quoted 280 lines · Toke Høiland-Jørgensen
Quoted 11 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the rbtree
gets
removed from rbtree immediately in theieee80211_return_txq(), the
loop will break soon in theieee80211_next_txq()due toschedule_pos
not leading to the second txq in the rbtree. Thus, defering the
removal right before the end of this schedule round.Quoted 3 lines
Co-developed-by Yibo Zhao <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off. I'll
add
ack or review tags as appropriate in reply; but a few comments first:Quoted 250 lines
--- include/net/mac80211.h | 16 ++++++++++-- net/mac80211/ieee80211_i.h | 3 +++ net/mac80211/main.c | 6 +++++ net/mac80211/tx.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-)include/net/mac80211.h +2
-0@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31 +#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100 + static inline void ieee80211_rate_set_vht(struct
ieee80211_tx_rate
*rate,include/net/mac80211.h +1
-1u8 mcs, u8 nss) {@@ -6232,7 +6234,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, * @ac: AC number to return packets from. * * Should only be called between calls to ieee80211_txq_schedule_start() - * and ieee80211_txq_schedule_end(). + * and ieee80211_txq_schedule_end(). If the txq is empty,it
will
be
added
+ * to a remove list and get removed later.
* Returns the next txq if successful, %NULL if no queue is
eligible.
If a txq
* is returned, it should be returned withieee80211_return_txq()
after the
* driver has finished scheduling it.include/net/mac80211.h +0
-0@@ -6268,7 +6271,8 @@ voidieee80211_txq_schedule_start(struct
ieee80211_hw*hw, u8 ac)
* @hw: pointer as obtained fromieee80211_alloc_hw()
* @ac: AC number to acquire locks for
*
- * Release locks previously acquired byieee80211_txq_schedule_end().
+ * Release locks previously acquired byieee80211_txq_schedule_end().
Check
+ * and remove the empty txq from rb-tree.
*/
void ieee80211_txq_schedule_end(structieee80211_hw*hw, u8
ac)include/net/mac80211.h +0
-0__releases (txq_lock);@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw, structieee80211_txq*txq)include/net/mac80211.h +8
-0__acquires (txq_lock)__releases (txq_lock);/** +* ieee80211_txqs_check - Check txqs waiting for removal +* +* @tmr: pointer as obtained from local +* +*/ +void ieee80211_txqs_check (struct timer_list *tmr); + +/** * ieee80211_txq_may_transmit - check whether TXQ is allowed
to
transmit
*
* This function is used to check whether given txq is
allowed
to
transmit bynet/mac80211/ieee80211_i.h +3
-0@@ -847,6 +847,7 @@ struct txq_info {struct codel_stats cstats;struct sk_buff_head frags;struct rb_node schedule_order; +struct list_head candidate;unsigned long flags;/* keep last! */ @@ -1145,6 +1146,8 @@ struct ieee80211_local {u64 airtime_v_t[IEEE80211_NUM_ACS ];u64 airtime_weight_sum[IEEE80211_NUM_ACS ]; +struct list_head remove_list[IEEE80211_NUM_ACS ]; +struct timer_list remove_timer;u16 airtime_flags;const struct ieee80211_ops *ops;net/mac80211/main.c +5
-0@@ -667,10 +667,15 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, for (i = 0; i < IEEE80211_NUM_ACS; i++) { local->active_txqs[i] = RB_ROOT_CACHED; + INIT_LIST_HEAD(&local->remove_list[i]); spin_lock_init(&local->active_txq_lock[i]); } local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX; + timer_setup(&local->remove_timer, ieee80211_txqs_check, 0); +mod_timer (&local->remove_timer, + jiffies + msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); +net/mac80211/main.c +0
-0INIT_LIST_HEAD (&local->chanctx_list);mutex_init (&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct
ieee80211_hw
*hw)net/mac80211/main.c +1
-0tasklet_kill (&local->tx_pending_tasklet);tasklet_kill (&local->tasklet); +del_timer_sync (&local->remove_timer);#ifdef CONFIG_INET unregister_inetaddr_notifier (&local->ifa_notifier);#endif net/mac80211/tx.c +1
-0@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);RB_CLEAR_NODE (&txqi->schedule_order); +INIT_LIST_HEAD (&txqi->candidate); txqi->txq.vif = &sdata->vif;@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +3
-0spin_lock_bh (&local->active_txq_lock[ac]); +if (!list_empty (&txqi->candidate)) +list_del_init (&txqi->candidate); +if (!RB_EMPTY_NODE (&txqi->schedule_order)) goto out;@@ -3783,6 +3787,20 @@ static void__ieee80211_unschedule_txq(struct
ieee80211_hw*hw,net/mac80211/tx.c +15
-1RB_CLEAR_NODE (&txqi->schedule_order); } +void ieee80211_remove_txq (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_local *local =hw_to_local (hw); +struct txq_info *txqi =to_txq_info (txq); + +lockdep_assert_held (&local->active_txq_lock[txq->ac]); + +if (!RB_EMPTY_NODE (&txqi->schedule_order)) { +__ieee80211_unschedule_txq (hw, txq); +list_del_init (&txqi->candidate); + } +} + void ieee80211_unschedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq) __acquires(txq_lock) __releases(txq_lock)@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(structieee80211_hw *hw, struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh (&local->active_txq_lock[txq->ac]); -__ieee80211_unschedule_txq (hw, txq); +ieee80211_remove_txq (hw, txq);spin_unlock_bh (&local->active_txq_lock[txq->ac]); }@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct
ieee80211_hw
*hw,net/mac80211/tx.c +0
-1lockdep_assert_held (&local->active_txq_lock[txq->ac]); if (!RB_EMPTY_NODE(&txqi->schedule_order) && - (skb_queue_empty(&txqi->frags) &&!txqi->tin.backlog_packets))
net/mac80211/tx.c +3
-1-__ieee80211_unschedule_txq (hw, txq); + !txq_has_queue(&txqi->txq) && + list_empty(&txqi->candidate)) + list_add_tail(&txqi->candidate,&local->remove_list[txq->ac]);
net/mac80211/tx.c +2
-0+ }EXPORT_SYMBOL (ieee80211_return_txq); +void __ieee80211_check_txqs(struct ieee80211_local *local,int
ac)net/mac80211/tx.c +7
-0+{ +struct txq_info *iter, *tmp; +struct sta_info *sta; + +lockdep_assert_held (&local->active_txq_lock[ac]); + + list_for_each_entry_safe(iter, tmp,&local->remove_list[ac],
net/mac80211/tx.c +13
-0+ candidate) { + sta = container_of(iter->txq.sta, struct sta_info, sta); + +if (txq_has_queue (&iter->txq)) +list_del_init (&iter->candidate); +else +ieee80211_remove_txq (&local->hw, &iter->txq); + } +} + +void ieee80211_txqs_check (struct timer_list *t) +{ + struct ieee80211_local *local = from_timer(local, t,
remove_timer);net/mac80211/tx.c +12
-0+struct txq_info *iter, *tmp; +struct sta_info *sta; +int ac; + +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +__ieee80211_check_txqs (local, ac); +spin_unlock_bh (&local->active_txq_lock[ac]); + } + + mod_timer(&local->remove_timer, + jiffies +Quoted 2 lines
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS)); +}I'll ask the same as I did last time (where you told me to hold off
until this round):Quoted 7 lines
Why do you need the timer and the periodic check? If TXQs are added
to
the remove list during the scheduling run, and__ieee80211_check_txqs()
is run fromschedule_end(), isn't that sufficient to clear the list?Quoted 5 lines
Is it possible that a txq is not added to the remove list but then
packets in it are dropped byfq_codelalgo? Like the station disconnects
without any notification.Quoted 5 lines
Well as long as all the other cleanup paths call directly into
__unschedule_txq(), that should remove stations from the scheduler
when
they disconnect etc.Yes, the disconnect scenario is a bad example. My concern is, say, we
have 10 stations and only one of them is assigned a very small weight
compared with that of others. Suppose, after its chance of Tx, it is
most likely to be placed in the rightmost(still has some packets in
the
txq) and no more incoming data for it. The remaining packets in txq
will
be dropped due to timeout algo in codel(correct me if I am wrong) butQuoted 8 lines
this empty txq will stay on the rbtree until other txqs get drained
or
global vt catch up with its vt. The staying time could be long if weight
is extremely small. Then do we need timer to check or any other better
solution?Ah, I see what you mean. No, I don't think this will be a problem; the
scenario you're describing would play out like this:1. Station ends transmitting, still has a single packet queued, gets
moved to the end of the rbtree (and stays there for a while).2. When we finally get to the point where this station gets another chance to transmit, the CoDel drop timer triggers and the last
packet
is dropped[0]. This means that the queue will just be empty (andieee80211_tx_dequeue()will return NULL).3. Because the queue is empty,
ieee80211_return_txq()will not put it
back on the rbtree.Quoted 8 lines
Crucially, in 2. the CoDel algorithm doesn't kick in until the point
of
packet dequeue. But even if an empty queue stays on the rbtree for a
while, there is no harm in that: eventually it will get its turn, it
will turn out to be empty, and just be skipped over.Quoted 3 lines
Then that will be fine. Thanks for the explanation of the dropping part
in CoDel algorithm.Yup, think so. And you're welcome :)
Quoted 8 lines
Quoted 5 lines
The issue we need to be concerned about is the opposite: If we have a
queue that *does* have packets queued, but which is *not* scheduled for
transmission, that will stall TX.Is it by design since its vt is more than global vt, right? The lattency
may somehow get impacted though.Well, it should still stay on the rbtree as long as it has packets queued. We don't have a check anywhere that reschedules TXQs whose
v_t
drops below globalv_t...Quoted 51 lines
Quoted 32 lines
[0] CoDel in most cases only drops a single packet at a time, so it will
not clear out an entire queue with multiple packets in one go. But you
are right that it could conceivably drop the last packet in a queue.Quoted 16 lines
Quoted 10 lines
We only need to defer removal inside a single "scheduling round" (i.e.,
between a pair of ieee80211_txq_schedule_start/end. So if we just walk
the remove list inschedule_end()we should be enough, no?Hmm, or maybe a simpler way to fix the original issue is just to have
unschedule_txq()update theschedule_pos()pointer?Quoted 6 lines
I.e.,
unschedule_txqchecks if the txq being removed is currently being
pointed to by schedule_pos[ac], and if it is, it updatesschedule_pos
to
be therb_nextof the current value?Quoted 6 lines
Actually, if
schedule_posis updated torb_nextof the current value,
then in thenext_txq()where we are going to userb_nextagain and finally pick the next node of the node we really want. Is it fine to
updateschedule_posto NULL?Hmm, yeah, good point.
Quoted 9 lines
If we do end up setting
schedule_posto NULL in the middle of a scheduling round, that will makenext_txq()"start over", and do another
loop through the whole thing. I guess we may be able hit a case where
things can oscillate back and forth between addition and removal resulting in an infinite loop? Not sure, but at least I can't seem to
convince myself that this can't happen.As the loop of
next_txqunder lock protection as below,
txq_schedule_start();
while(txq=next_txq()){
...return_txq(txq);
}txq_schedule_end();Quoted 9 lines
Quoted 1 line
I do not see any chance of addition, no?
As you noted in your other email, Felix reduced the locking. And yeah,
we need to rebase this series to also incorporate that. I figure I can
send an updated version of the first patch in the series once we've worked out the remaining issues with your follow-up patches.Oh, I was thinking we were discussing without locking reduced. Yes, I also agree there might be a case causing infinite loop. With locking reduced, the tree can be adjusted between
next_txq()andreturn_txq()in
the loop situation. For further discussion, let 's consider,
1) the tree starts like:A->B->C->D->E2) then
next_txq()returns A for dequeuing
3) driver dequeues A and draines A without any active txq locked meaning
the tree could be changed upon Tx compeletion.
4) then inreturn_txq(), the tree could be,i A->B->C->D->E (A is empty, and maybe soon be added back before the loop end) ii B->C->A->D->E (A is empty, and maybe soon be added back before the loop end) iii B->C->D->E->A (A is empty, and maybe soon be added backbefore the loop end)
with this change:
local->schedule_pos[ac] =rb_next(node)?:rb_prev(node);for case i, local->schedule_pos[ac] is
rb_next(A)which is B, and innext_txq(),rb_next(B)is what we returns which actually is C and B is skipped, no?Quoted 8 lines
Quoted 1 line
Similiar for case ii, we skip B, C, D.
Yup, I think you're right. But if we can fix this by making
ieee80211_resort_txq()aware of theschedule_posas well, no? I.e., ifresort_txq()acts on the txq that's currently inschedule_pos, it will update schedule pos with the samerb_next(node)?:rb_prev(node); (optionally after checking that the position of the node is actually going to change).Sorry, please igore last email sent by mistake.
Quoted 8 lines
Quoted 4 lines
I don't think it makes any difference with that in
unschedule_txq(). For case i, it finally picks C as well innext_txq(). Fornext_txq(),schedule_posmeans previous candidate node whereas with your change, it looks likeschedule_posis current candidate node instead.Hmm, that was not actually what I was thinking, but yeah I think you're right that it would be easier to just change it so
schedule_posis pointing to the next and not the current txq we want to schedule.
So do you mean we can change next_txq like this,
struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8
ac)
{
struct ieee80211_local *local = hw_to_local(hw); struct rb_node *node = local->schedule_pos[ac]; struct txq_info *txqi = NULL; bool first = false;
lockdep_assert_held(&local->active_txq_lock[ac]);
if (!node) {
node = rb_first_cached(&local->active_txqs[ac]);
first = true;- } else
- node = rb_next(node);
+ }
+
if (!node)
return NULL;
Quoted 3 lines
We'd still need a check in
resort_txq()then, but it would make it safe to unschedule inreturn_txq()...
Yes, agree with that.
Quoted 37 lines
Quoted 37 lines
Quoted 5 lines
Quoted 3 lines
Also I am wondering if there will be some SMP issues relating with local->schedule_pos[ac].
Not sure what you mean by this?
My bad. Please ignore this.
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
In ath10k, we will usually push packets of first txq as many as we can
until it is drained and then move to the next one. So if a txq gets removed in thereturn_txq, it should always be the leftmost. And during this period, neither vt of any station or global vt can be updated due to lock protection.Quoted 7 lines
But in that case, we could fix it by just conditionally assigning either
rb_nextorrb_prevto theschedule_posinunschedule_txq()? I.e., something like:local->schedule_pos[ac] =
rb_next(node)?:rb_prev(node);I am not sure I am getting your point. Still in
next_txq, schedule_pos[ac] will lead us to the next node of the one we want.Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
The logic in
next_txqis different when schedule_pos[ac] is NULL, vs whenrb_next(schedule_pos[ac])is NULL. The former restarts a new scheduling round, while the latter ends the current round.-Toke
--
Yibo--
Yibo
Signature · 6 lines
Yibo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 537 lines · Yibo Zhao
Quoted 513 lines · Toke Høiland-Jørgensen
Quoted 502 lines · Yibo Zhao
Quoted 493 lines · Toke Høiland-Jørgensen
Quoted 484 lines · Yibo Zhao
Quoted 450 lines · Toke Høiland-Jørgensen
Quoted 366 lines · Yibo Zhao
Quoted 356 lines · Toke Høiland-Jørgensen
Quoted 324 lines · Yibo Zhao
Quoted 300 lines · Toke Høiland-Jørgensen
Quoted 292 lines · Yibo Zhao
Quoted 283 lines · Toke Høiland-Jørgensen
Quoted 15 lines · Yibo Zhao
In a loop txqs dequeue scenario, if the first txq in the
rbtree
gets
removed from rbtree immediately in the
ieee80211_return_txq(),
the
loop will break soon in the ieee80211_next_txq() due to
schedule_pos
not leading to the second txq in the rbtree. Thus, defering
the
removal right before the end of this schedule round.Co-developed-by: Yibo Zhao <[email protected]>
Signed-off-by: Yibo Zhao <[email protected]>
Signed-off-by: Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off. I'll
add
ack or review tags as appropriate in reply; but a few comments
first:Quoted 252 lines
---
include/net/mac80211.h | 16 ++++++++++--
net/mac80211/ieee80211_i.h | 3 +++
net/mac80211/main.c | 6 +++++
net/mac80211/tx.c | 63
+++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 83 insertions(+), 5 deletions(-)diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index ac2ed8e..ba5a345 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31
+#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100
+
static inline void ieee80211_rate_set_vht(struct
ieee80211_tx_rate
*rate,
u8 mcs, u8 nss)
{
@@ -6232,7 +6234,8 @@ struct sk_buff
*ieee80211_tx_dequeue(struct
ieee80211_hw *hw,
* @ac: AC number to return packets from.
*
* Should only be called between calls to
ieee80211_txq_schedule_start()
- * and ieee80211_txq_schedule_end().
+ * and ieee80211_txq_schedule_end(). If the txq is empty,
it
will
be
added
+ * to a remove list and get removed later.
* 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.
@@ -6268,7 +6271,8 @@ void
ieee80211_txq_schedule_start(struct
ieee80211_hw *hw, u8 ac)
* @hw: pointer as obtained from ieee80211_alloc_hw()
* @ac: AC number to acquire locks for
*
- * Release locks previously acquired by
ieee80211_txq_schedule_end().
+ * Release locks previously acquired by
ieee80211_txq_schedule_end().
Check
+ * and remove the empty txq from rb-tree.
*/
void ieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8
ac)
__releases(txq_lock);
@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw, struct ieee80211_txq *txq)
__acquires(txq_lock) __releases(txq_lock);/**
+ * ieee80211_txqs_check - Check txqs waiting for removal
+ *
+ * @tmr: pointer as obtained from local
+ *
+ */
+void ieee80211_txqs_check(struct timer_list *tmr);
+
+/**
* ieee80211_txq_may_transmit - check whether TXQ is
allowed
to
transmit
*
* This function is used to check whether given txq is
allowed
to
transmit by
diff --git a/net/mac80211/ieee80211_i.h
b/net/mac80211/ieee80211_i.h
index a4556f9..49aa143e 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -847,6 +847,7 @@ struct txq_info {
struct codel_stats cstats;
struct sk_buff_head frags;
struct rb_node schedule_order;
+ struct list_head candidate;
unsigned long flags;/* keep last! */
@@ -1145,6 +1146,8 @@ struct ieee80211_local {
u64 airtime_v_t[IEEE80211_NUM_ACS];
u64 airtime_weight_sum[IEEE80211_NUM_ACS];+ struct list_head remove_list[IEEE80211_NUM_ACS];
+ struct timer_list remove_timer;
u16 airtime_flags;const struct ieee80211_ops *ops;
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index e9ffa8e..78fe24a 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -667,10 +667,15 @@ struct ieee80211_hw
*ieee80211_alloc_hw_nm(size_t priv_data_len,for (i = 0; i < IEEE80211_NUM_ACS; i++) {
local->active_txqs[i] = RB_ROOT_CACHED;
+ INIT_LIST_HEAD(&local->remove_list[i]);
spin_lock_init(&local->active_txq_lock[i]);
}
local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX;+ timer_setup(&local->remove_timer, ieee80211_txqs_check,
0);
+ mod_timer(&local->remove_timer,
+ jiffies +
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS));
+
INIT_LIST_HEAD(&local->chanctx_list);
mutex_init(&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct
ieee80211_hw
*hw)
tasklet_kill(&local->tx_pending_tasklet);
tasklet_kill(&local->tasklet);+ del_timer_sync(&local->remove_timer);
#ifdef CONFIG_INET
unregister_inetaddr_notifier(&local->ifa_notifier);
#endif
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index d00baaa..42ca010 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct
ieee80211_sub_if_data *sdata,
codel_stats_init(&txqi->cstats);
__skb_queue_head_init(&txqi->frags);
RB_CLEAR_NODE(&txqi->schedule_order);
+ INIT_LIST_HEAD(&txqi->candidate);txqi->txq.vif = &sdata->vif;
@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw,spin_lock_bh(&local->active_txq_lock[ac]);
+ if (!list_empty(&txqi->candidate))
+ list_del_init(&txqi->candidate);
+
if (!RB_EMPTY_NODE(&txqi->schedule_order))
goto out;@@ -3783,6 +3787,20 @@ static void
__ieee80211_unschedule_txq(struct
ieee80211_hw *hw,
RB_CLEAR_NODE(&txqi->schedule_order);
}+void ieee80211_remove_txq(struct ieee80211_hw *hw,
+ struct ieee80211_txq *txq)
+{
+ struct ieee80211_local *local = hw_to_local(hw);
+ struct txq_info *txqi = to_txq_info(txq);
+
+ lockdep_assert_held(&local->active_txq_lock[txq->ac]);
+
+ if (!RB_EMPTY_NODE(&txqi->schedule_order)) {
+ __ieee80211_unschedule_txq(hw, txq);
+ list_del_init(&txqi->candidate);
+ }
+}
+
void ieee80211_unschedule_txq(struct ieee80211_hw *hw,
struct ieee80211_txq *txq)
__acquires(txq_lock) __releases(txq_lock)
@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(struct
ieee80211_hw *hw,
struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh(&local->active_txq_lock[txq->ac]);
- __ieee80211_unschedule_txq(hw, txq);
+ ieee80211_remove_txq(hw, txq);
spin_unlock_bh(&local->active_txq_lock[txq->ac]);
}@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct
ieee80211_hw
*hw,
lockdep_assert_held(&local->active_txq_lock[txq->ac]);if (!RB_EMPTY_NODE(&txqi->schedule_order) &&
- (skb_queue_empty(&txqi->frags) &&
!txqi->tin.backlog_packets))
- __ieee80211_unschedule_txq(hw, txq);
+ !txq_has_queue(&txqi->txq) &&
+ list_empty(&txqi->candidate))
+ list_add_tail(&txqi->candidate,
&local->remove_list[txq->ac]);
+
}
EXPORT_SYMBOL(ieee80211_return_txq);+void __ieee80211_check_txqs(struct ieee80211_local *local,
int
ac)
+{
+ struct txq_info *iter, *tmp;
+ struct sta_info *sta;
+
+ lockdep_assert_held(&local->active_txq_lock[ac]);
+
+ list_for_each_entry_safe(iter, tmp,
&local->remove_list[ac],
+ candidate) {
+ sta = container_of(iter->txq.sta, struct sta_info, sta);
+
+ if (txq_has_queue(&iter->txq))
+ list_del_init(&iter->candidate);
+ else
+ ieee80211_remove_txq(&local->hw, &iter->txq);
+ }
+}
+
+void ieee80211_txqs_check(struct timer_list *t)
+{
+ struct ieee80211_local *local = from_timer(local, t,
remove_timer);
+ struct txq_info *iter, *tmp;
+ struct sta_info *sta;
+ int ac;
+
+ for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
+ spin_lock_bh(&local->active_txq_lock[ac]);
+ __ieee80211_check_txqs(local, ac);
+ spin_unlock_bh(&local->active_txq_lock[ac]);
+ }
+
+ mod_timer(&local->remove_timer,
+ jiffies +
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS));
+}I'll ask the same as I did last time (where you told me to hold
off
until this round):Quoted 8 lines
Why do you need the timer and the periodic check? If TXQs are added
to
the remove list during the scheduling run, and__ieee80211_check_txqs()
is run fromschedule_end(), isn't that sufficient to clear the
list?Quoted 5 lines
Is it possible that a txq is not added to the remove list but then
packets in it are dropped byfq_codelalgo? Like the station disconnects
without any notification.Quoted 5 lines
Well as long as all the other cleanup paths call directly into
__unschedule_txq(), that should remove stations from the scheduler
when
they disconnect etc.Yes, the disconnect scenario is a bad example. My concern is, say,
we
have 10 stations and only one of them is assigned a very small weight
compared with that of others. Suppose, after its chance of Tx, it
is
most likely to be placed in the rightmost(still has some packets in
the
txq) and no more incoming data for it. The remaining packets in txq
will
be dropped due to timeout algo in codel(correct me if I am wrong)
but
this empty txq will stay on the rbtree until other txqs getQuoted 8 lines
drained
or
global vt catch up with its vt. The staying time could be long if
weight
is extremely small. Then do we need timer to check or any other better
solution?Ah, I see what you mean. No, I don't think this will be a problem;
the
scenario you're describing would play out like this:1. Station ends transmitting, still has a single packet queued, gets
moved to the end of the rbtree (and stays there for a while).2. When we finally get to the point where this station gets another
chance to transmit, the CoDel drop timer triggers and the last
packet
is dropped[0]. This means that the queue will just be empty (andieee80211_tx_dequeue()will return NULL).3. Because the queue is empty,
ieee80211_return_txq()will not put
it
back on the rbtree.Quoted 9 lines
Crucially, in 2. the CoDel algorithm doesn't kick in until the point
of
packet dequeue. But even if an empty queue stays on the rbtree for
a
while, there is no harm in that: eventually it will get its turn, it
will turn out to be empty, and just be skipped over.Quoted 3 lines
Then that will be fine. Thanks for the explanation of the dropping part
in CoDel algorithm.Yup, think so. And you're welcome :)
Quoted 10 lines
Quoted 7 lines
The issue we need to be concerned about is the opposite: If we have
a
queue that *does* have packets queued, but which is *not* scheduled
for
transmission, that will stall TX.Is it by design since its vt is more than global vt, right? The lattency
may somehow get impacted though.Well, it should still stay on the rbtree as long as it has packets queued. We don't have a check anywhere that reschedules TXQs whose
v_t
drops below globalv_t...Quoted 60 lines
Quoted 40 lines
[0] CoDel in most cases only drops a single packet at a time, so it
will
not clear out an entire queue with multiple packets in one go. But
you
are right that it could conceivably drop the last packet in a queue.Quoted 20 lines
Quoted 13 lines
We only need to defer removal inside a single "scheduling round"
(i.e.,
between a pair of ieee80211_txq_schedule_start/end. So if we just
walk
the remove list inschedule_end()we should be enough, no?Hmm, or maybe a simpler way to fix the original issue is just to
haveunschedule_txq()update theschedule_pos()pointer?Quoted 7 lines
I.e.,
unschedule_txqchecks if the txq being removed is currently
being
pointed to by schedule_pos[ac], and if it is, it updatesschedule_pos
to
be therb_nextof the current value?Quoted 8 lines
Actually, if
schedule_posis updated torb_nextof the current value,
then in thenext_txq()where we are going to userb_nextagain and
finally pick the next node of the node we really want. Is it fine
to
updateschedule_posto NULL?Hmm, yeah, good point.
Quoted 10 lines
If we do end up setting
schedule_posto NULL in the middle of a scheduling round, that will makenext_txq()"start over", and do another
loop through the whole thing. I guess we may be able hit a case where
things can oscillate back and forth between addition and removal resulting in an infinite loop? Not sure, but at least I can't seem
to
convince myself that this can't happen.As the loop of
next_txqunder lock protection as below,
txq_schedule_start();
while(txq=next_txq()){
...return_txq(txq);
}txq_schedule_end();Quoted 9 lines
Quoted 1 line
I do not see any chance of addition, no?
As you noted in your other email, Felix reduced the locking. And yeah,
we need to rebase this series to also incorporate that. I figure I can
send an updated version of the first patch in the series once we've worked out the remaining issues with your follow-up patches.Oh, I was thinking we were discussing without locking reduced. Yes, I
also agree there might be a case causing infinite loop. With locking reduced, the tree can be adjusted betweennext_txq()andreturn_txq()
in
the loop situation. For further discussion, let 's consider,
1) the tree starts like:A->B->C->D->E2) then
next_txq()returns A for dequeuing
3) driver dequeues A and draines A without any active txq locked meaning
the tree could be changed upon Tx compeletion.
4) then inreturn_txq(), the tree could be,i A->B->C->D->E (A is empty, and maybe soon be added back before the loop end) ii B->C->A->D->E (A is empty, and maybe soon be added back before the loop end) iii B->C->D->E->A (A is empty, and maybe soon be added backbefore the loop end)
with this change:
local->schedule_pos[ac] =rb_next(node)?:rb_prev(node);Quoted 6 lines
for case i, local->schedule_pos[ac] is
rb_next(A)which is B, and innext_txq(),rb_next(B)is what we returns which actually is C and B is
skipped, no?Similiar for case ii, we skip B, C, D.
Quoted 8 lines
Yup, I think you're right. But if we can fix this by making
ieee80211_resort_txq()aware of theschedule_posas well, no? I.e., ifresort_txq()acts on the txq that's currently inschedule_pos, it will
update schedule pos with the samerb_next(node)?:rb_prev(node); (optionally after checking that the position of the node is actually going to change).Quoted 8 lines
Sorry, please igore last email sent by mistake.
I don't think it makes any difference with that in
unschedule_txq(). For
case i, it finally picks C as well innext_txq(). Fornext_txq(),schedule_posmeans previous candidate node whereas with your change, it
looks likeschedule_posis current candidate node instead.Quoted 3 lines
Hmm, that was not actually what I was thinking, but yeah I think you're right that it would be easier to just change it so
schedule_posis pointing to the next and not the current txq we want to schedule.So do you mean we can change
next_txqlike this,struct
ieee80211_txq*ieee80211_next_txq(structieee80211_hw*hw, u8
ac)
{struct ieee80211_local *local = hw_to_local(hw); struct rb_node *node = local->schedule_pos[ac]; struct txq_info *txqi = NULL; bool first = false;lockdep_assert_held(&local->active_txq_lock[ac]);if (!node) { node = rb_first_cached(&local->active_txqs[ac]); first = true;(quoted diff) +2
-2- } else - node = rb_next(node); + } +if (!node)
Quoted 1 line
return NULL;
Ah, no, now I remember why this didn't work and I went with the other
approach: If you make this change, you also have to have this at the end:
local->schedule_pos[ac] = rb_next(node);
But this means we can no longer distinguish between having gone through the whole thing (so rb_next() returns NULL), or starting out with nothing.
So, instead we need to keep next_txq() the way it is, and just add
local->schedule_pos[ac] = rb_prev(node);
whenever we remove a node (both in return_txq() and resort_txq()).
Quoted 38 lines
Quoted 3 lines
We'd still need a check in
resort_txq()then, but it would make it safe to unschedule inreturn_txq()...Yes, agree with that.
Quoted 32 lines
Quoted 32 lines
Quoted 5 lines
Quoted 3 lines
Also I am wondering if there will be some SMP issues relating with local->schedule_pos[ac].
Not sure what you mean by this?
My bad. Please ignore this.
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 10 lines
In ath10k, we will usually push packets of first txq as many as we can
until it is drained and then move to the next one. So if a txq gets
removed in thereturn_txq, it should always be the leftmost. And during this period, neither vt of any station or global vt can be updated due to lock protection.Quoted 1 line
Quoted 8 lines
Quoted 6 lines
But in that case, we could fix it by just conditionally assigning either
rb_nextorrb_prevto theschedule_posinunschedule_txq()? I.e., something like:local->schedule_pos[ac] =
rb_next(node)?:rb_prev(node);I am not sure I am getting your point. Still in
next_txq, schedule_pos[ac] will lead us to the next node of the one we want.The logic in
next_txqis different when schedule_pos[ac] is NULL, vs
whenrb_next(schedule_pos[ac])is NULL. The former restarts a new scheduling round, while the latter ends the current round.
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
-Toke
--
Yibo--
YiboSignature · 1 line
Yibo
_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 554 lines · Toke Høiland-Jørgensen
Quoted 546 lines · Yibo Zhao
Quoted 522 lines · Toke Høiland-Jørgensen
Quoted 511 lines · Yibo Zhao
Quoted 502 lines · Toke Høiland-Jørgensen
Quoted 493 lines · Yibo Zhao
Quoted 456 lines · Toke Høiland-Jørgensen
Quoted 372 lines · Yibo Zhao
Quoted 362 lines · Toke Høiland-Jørgensen
Quoted 328 lines · Yibo Zhao
Quoted 304 lines · Toke Høiland-Jørgensen
Quoted 296 lines · Yibo Zhao
Quoted 295 lines · Toke Høiland-Jørgensen
Yibo Zhao <[email protected]> writes:
In a loop txqs dequeue scenario, if the first txq in the
rbtree
gets
removed from rbtree immediately in the
ieee80211_return_txq(),
the
loop will break soon in the ieee80211_next_txq() due to
schedule_pos
not leading to the second txq in the rbtree. Thus, defering
the
removal right before the end of this schedule round.Co-developed-by: Yibo Zhao <[email protected]>
Signed-off-by: Yibo Zhao <[email protected]>
Signed-off-by: Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off.
I'll
add
ack or review tags as appropriate in reply; but a few
comments
first:---
include/net/mac80211.h | 16 ++++++++++--
net/mac80211/ieee80211_i.h | 3 +++
net/mac80211/main.c | 6 +++++
net/mac80211/tx.c | 63
+++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 83 insertions(+), 5 deletions(-)diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index ac2ed8e..ba5a345 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31
+#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100
+
static inline void ieee80211_rate_set_vht(struct
ieee80211_tx_rate
*rate,
u8 mcs, u8 nss)
{
@@ -6232,7 +6234,8 @@ struct sk_buff
*ieee80211_tx_dequeue(struct
ieee80211_hw *hw,
* @ac: AC number to return packets from.
*
* Should only be called between calls to
ieee80211_txq_schedule_start()
- * and ieee80211_txq_schedule_end().
+ * and ieee80211_txq_schedule_end(). If the txq is empty,
it
will
be
added
+ * to a remove list and get removed later.
* 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.
@@ -6268,7 +6271,8 @@ void
ieee80211_txq_schedule_start(struct
ieee80211_hw *hw, u8 ac)
* @hw: pointer as obtained from ieee80211_alloc_hw()
* @ac: AC number to acquire locks for
*
- * Release locks previously acquired by
ieee80211_txq_schedule_end().
+ * Release locks previously acquired by
ieee80211_txq_schedule_end().
Check
+ * and remove the empty txq from rb-tree.
*/
void ieee80211_txq_schedule_end(struct ieee80211_hw *hw,
u8
ac)
__releases(txq_lock);
@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw, struct ieee80211_txq *txq)
__acquires(txq_lock) __releases(txq_lock);/**
+ * ieee80211_txqs_check - Check txqs waiting for removal
+ *
+ * @tmr: pointer as obtained from local
+ *
+ */
+void ieee80211_txqs_check(struct timer_list *tmr);
+
+/**
* ieee80211_txq_may_transmit - check whether TXQ is
allowed
to
transmit
*
* This function is used to check whether given txq is
allowed
to
transmit by
diff --git a/net/mac80211/ieee80211_i.h
b/net/mac80211/ieee80211_i.h
index a4556f9..49aa143e 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -847,6 +847,7 @@ struct txq_info {
struct codel_stats cstats;
struct sk_buff_head frags;
struct rb_node schedule_order;
+ struct list_head candidate;
unsigned long flags;/* keep last! */
@@ -1145,6 +1146,8 @@ struct ieee80211_local {
u64 airtime_v_t[IEEE80211_NUM_ACS];
u64 airtime_weight_sum[IEEE80211_NUM_ACS];+ struct list_head remove_list[IEEE80211_NUM_ACS];
+ struct timer_list remove_timer;
u16 airtime_flags;const struct ieee80211_ops *ops;
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index e9ffa8e..78fe24a 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -667,10 +667,15 @@ struct ieee80211_hw
*ieee80211_alloc_hw_nm(size_t priv_data_len,for (i = 0; i < IEEE80211_NUM_ACS; i++) {
local->active_txqs[i] = RB_ROOT_CACHED;
+ INIT_LIST_HEAD(&local->remove_list[i]);
spin_lock_init(&local->active_txq_lock[i]);
}
local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX;+ timer_setup(&local->remove_timer, ieee80211_txqs_check,
0);
+ mod_timer(&local->remove_timer,
+ jiffies +
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS));
+
INIT_LIST_HEAD(&local->chanctx_list);
mutex_init(&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct
ieee80211_hw
*hw)
tasklet_kill(&local->tx_pending_tasklet);
tasklet_kill(&local->tasklet);+ del_timer_sync(&local->remove_timer);
#ifdef CONFIG_INET
unregister_inetaddr_notifier(&local->ifa_notifier);
#endif
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index d00baaa..42ca010 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct
ieee80211_sub_if_data *sdata,
codel_stats_init(&txqi->cstats);
__skb_queue_head_init(&txqi->frags);
RB_CLEAR_NODE(&txqi->schedule_order);
+ INIT_LIST_HEAD(&txqi->candidate);txqi->txq.vif = &sdata->vif;
@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw,spin_lock_bh(&local->active_txq_lock[ac]);
+ if (!list_empty(&txqi->candidate))
+ list_del_init(&txqi->candidate);
+
if (!RB_EMPTY_NODE(&txqi->schedule_order))
goto out;@@ -3783,6 +3787,20 @@ static void
__ieee80211_unschedule_txq(struct
ieee80211_hw *hw,
RB_CLEAR_NODE(&txqi->schedule_order);
}+void ieee80211_remove_txq(struct ieee80211_hw *hw,
+ struct ieee80211_txq *txq)
+{
+ struct ieee80211_local *local = hw_to_local(hw);
+ struct txq_info *txqi = to_txq_info(txq);
+
+ lockdep_assert_held(&local->active_txq_lock[txq->ac]);
+
+ if (!RB_EMPTY_NODE(&txqi->schedule_order)) {
+ __ieee80211_unschedule_txq(hw, txq);
+ list_del_init(&txqi->candidate);
+ }
+}
+
void ieee80211_unschedule_txq(struct ieee80211_hw *hw,
struct ieee80211_txq *txq)
__acquires(txq_lock) __releases(txq_lock)
@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(struct
ieee80211_hw *hw,
struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh(&local->active_txq_lock[txq->ac]);
- __ieee80211_unschedule_txq(hw, txq);
+ ieee80211_remove_txq(hw, txq);
spin_unlock_bh(&local->active_txq_lock[txq->ac]);
}@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct
ieee80211_hw
*hw,
lockdep_assert_held(&local->active_txq_lock[txq->ac]);if (!RB_EMPTY_NODE(&txqi->schedule_order) &&
- (skb_queue_empty(&txqi->frags) &&
!txqi->tin.backlog_packets))
- __ieee80211_unschedule_txq(hw, txq);
+ !txq_has_queue(&txqi->txq) &&
+ list_empty(&txqi->candidate))
+ list_add_tail(&txqi->candidate,
&local->remove_list[txq->ac]);
+
}
EXPORT_SYMBOL(ieee80211_return_txq);+void __ieee80211_check_txqs(struct ieee80211_local
*local,
int
ac)
+{
+ struct txq_info *iter, *tmp;
+ struct sta_info *sta;
+
+ lockdep_assert_held(&local->active_txq_lock[ac]);
+
+ list_for_each_entry_safe(iter, tmp,
&local->remove_list[ac],
+ candidate) {
+ sta = container_of(iter->txq.sta, struct sta_info,
sta);
+
+ if (txq_has_queue(&iter->txq))
+ list_del_init(&iter->candidate);
+ else
+ ieee80211_remove_txq(&local->hw, &iter->txq);
+ }
+}
+
+void ieee80211_txqs_check(struct timer_list *t)
+{
+ struct ieee80211_local *local = from_timer(local, t,
remove_timer);
+ struct txq_info *iter, *tmp;
+ struct sta_info *sta;
+ int ac;
+
+ for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
+ spin_lock_bh(&local->active_txq_lock[ac]);
+ __ieee80211_check_txqs(local, ac);
+ spin_unlock_bh(&local->active_txq_lock[ac]);
+ }
+
+ mod_timer(&local->remove_timer,
+ jiffies +
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS));
+}I'll ask the same as I did last time (where you told me to
hold
off
until this round):Why do you need the timer and the periodic check? If TXQs are
added
to
the remove list during the scheduling run, and
__ieee80211_check_txqs()
is run from schedule_end(), isn't that sufficient to clear
the
list?Quoted 5 lines
Is it possible that a txq is not added to the remove list but then
packets in it are dropped byfq_codelalgo? Like the station disconnects
without any notification.Quoted 5 lines
Well as long as all the other cleanup paths call directly into
__unschedule_txq(), that should remove stations from the scheduler
when
they disconnect etc.Yes, the disconnect scenario is a bad example. My concern is, say,
we
have 10 stations and only one of them is assigned a very small weight
compared with that of others. Suppose, after its chance of Tx, it
is
most likely to be placed in the rightmost(still has some packets in
the
txq) and no more incoming data for it. The remaining packets in txq
will
be dropped due to timeout algo in codel(correct me if I am wrong)
but
this empty txq will stay on the rbtree until other txqs getQuoted 8 lines
drained
or
global vt catch up with its vt. The staying time could be long if
weight
is extremely small. Then do we need timer to check or any other better
solution?Ah, I see what you mean. No, I don't think this will be a problem;
the
scenario you're describing would play out like this:1. Station ends transmitting, still has a single packet queued, gets
moved to the end of the rbtree (and stays there for a
while).2. When we finally get to the point where this station gets another
chance to transmit, the CoDel drop timer triggers and the
last
packet
is dropped[0]. This means that the queue will just be empty (andieee80211_tx_dequeue()will return NULL).3. Because the queue is empty,
ieee80211_return_txq()will not put
it
back on the rbtree.Quoted 9 lines
Crucially, in 2. the CoDel algorithm doesn't kick in until the point
of
packet dequeue. But even if an empty queue stays on the rbtree for
a
while, there is no harm in that: eventually it will get its turn, it
will turn out to be empty, and just be skipped over.Quoted 3 lines
Then that will be fine. Thanks for the explanation of the dropping part
in CoDel algorithm.Yup, think so. And you're welcome :)
Quoted 10 lines
Quoted 7 lines
The issue we need to be concerned about is the opposite: If we have
a
queue that *does* have packets queued, but which is *not* scheduled
for
transmission, that will stall TX.Is it by design since its vt is more than global vt, right? The lattency
may somehow get impacted though.Well, it should still stay on the rbtree as long as it has packets queued. We don't have a check anywhere that reschedules TXQs whose
v_t
drops below globalv_t...Quoted 60 lines
Quoted 40 lines
[0] CoDel in most cases only drops a single packet at a time, so it
will
not clear out an entire queue with multiple packets in one go. But
you
are right that it could conceivably drop the last packet in a queue.Quoted 20 lines
Quoted 13 lines
We only need to defer removal inside a single "scheduling round"
(i.e.,
between a pair of ieee80211_txq_schedule_start/end. So if we just
walk
the remove list inschedule_end()we should be enough, no?Hmm, or maybe a simpler way to fix the original issue is just to
haveunschedule_txq()update theschedule_pos()pointer?Quoted 7 lines
I.e.,
unschedule_txqchecks if the txq being removed is currently
being
pointed to by schedule_pos[ac], and if it is, it updatesschedule_pos
to
be therb_nextof the current value?Quoted 8 lines
Actually, if
schedule_posis updated torb_nextof the current value,
then in thenext_txq()where we are going to userb_nextagain and
finally pick the next node of the node we really want. Is it fine
to
updateschedule_posto NULL?Hmm, yeah, good point.
Quoted 10 lines
If we do end up setting
schedule_posto NULL in the middle of a scheduling round, that will makenext_txq()"start over", and do another
loop through the whole thing. I guess we may be able hit a case where
things can oscillate back and forth between addition and removal resulting in an infinite loop? Not sure, but at least I can't seem
to
convince myself that this can't happen.As the loop of
next_txqunder lock protection as below,
txq_schedule_start();
while(txq=next_txq()){
...return_txq(txq);
}txq_schedule_end();Quoted 9 lines
Quoted 1 line
I do not see any chance of addition, no?
As you noted in your other email, Felix reduced the locking. And yeah,
we need to rebase this series to also incorporate that. I figure I can
send an updated version of the first patch in the series once we've worked out the remaining issues with your follow-up patches.Oh, I was thinking we were discussing without locking reduced. Yes, I
also agree there might be a case causing infinite loop. With locking reduced, the tree can be adjusted betweennext_txq()andreturn_txq()
in
the loop situation. For further discussion, let 's consider,
1) the tree starts like:A->B->C->D->E2) then
next_txq()returns A for dequeuing
3) driver dequeues A and draines A without any active txq locked meaning
the tree could be changed upon Tx compeletion.
4) then inreturn_txq(), the tree could be,i A->B->C->D->E (A is empty, and maybe soon be added back before the loop end) ii B->C->A->D->E (A is empty, and maybe soon be added back before the loop end) iii B->C->D->E->A (A is empty, and maybe soon be addedback
before the loop end)with this change:
local->schedule_pos[ac] =rb_next(node)?:rb_prev(node);Quoted 6 lines
for case i, local->schedule_pos[ac] is
rb_next(A)which is B, and innext_txq(),rb_next(B)is what we returns which actually is C and B is
skipped, no?Similiar for case ii, we skip B, C, D.
Quoted 8 lines
Yup, I think you're right. But if we can fix this by making
ieee80211_resort_txq()aware of theschedule_posas well, no? I.e., ifresort_txq()acts on the txq that's currently inschedule_pos, it will
update schedule pos with the samerb_next(node)?:rb_prev(node); (optionally after checking that the position of the node is actually going to change).Quoted 8 lines
Sorry, please igore last email sent by mistake.
I don't think it makes any difference with that in
unschedule_txq(). For
case i, it finally picks C as well innext_txq(). Fornext_txq(),schedule_posmeans previous candidate node whereas with your change, it
looks likeschedule_posis current candidate node instead.Quoted 3 lines
Hmm, that was not actually what I was thinking, but yeah I think you're right that it would be easier to just change it so
schedule_posis pointing to the next and not the current txq we want to schedule.So do you mean we can change
next_txqlike this,struct
ieee80211_txq*ieee80211_next_txq(structieee80211_hw*hw, u8
ac)
{struct ieee80211_local *local = hw_to_local(hw); struct rb_node *node = local->schedule_pos[ac]; struct txq_info *txqi = NULL; bool first = false;lockdep_assert_held(&local->active_txq_lock[ac]);if (!node) { node = rb_first_cached(&local->active_txqs[ac]); first = true;(quoted diff) +2
-2- } else - node = rb_next(node); + } +if (!node)Quoted 1 line
return NULL;
Ah, no, now I remember why this didn't work and I went with the other
approach: If you make this change, you also have to have this at the end:
Quoted 8 lines
local->schedule_pos[ac] =
rb_next(node);But this means we can no longer distinguish between having gone through the whole thing (so
rb_next()returns NULL), or starting out with nothing.So, instead we need to keep
next_txq()the way it is, and just add
Right, should keep next_txq() the way it is.
Quoted 4 lines
local->schedule_pos[ac] =
rb_prev(node);whenever we remove a node (both in
return_txq()andresort_txq()).
Agree, and also we may need to consider case like A is removed and soon be added back just the same as ii),
B->C->A->D->E
then B is schedule, removed and soon added back,
C->A->B->D->EA and B will have a second chance to be scheduled and this may happen to others as well leading to the infinite loop as you have mentioned previously, so do we need to maintain a schedule_round like we do in DRR? Like,
- If the node is in the same round, by pass schedule, go torb_next(), either continue loop this round or end this round.
- Increase the schedule_round at the schedule_start() only when theschedule_pos is NULL.
Quoted 49 lines
Quoted 49 lines
Quoted 4 lines
We'd still need a check in
resort_txq()then, but it would make it safe to unschedule inreturn_txq()...Yes, agree with that.
Quoted 32 lines
Quoted 32 lines
Quoted 5 lines
Quoted 3 lines
Also I am wondering if there will be some SMP issues relating with local->schedule_pos[ac].
Not sure what you mean by this?
My bad. Please ignore this.
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 10 lines
In ath10k, we will usually push packets of first txq as many as we can
until it is drained and then move to the next one. So if a txq gets
removed in thereturn_txq, it should always be the leftmost. And during this period, neither vt of any station or global vt can be updated due to lock protection.Quoted 1 line
Quoted 8 lines
Quoted 6 lines
But in that case, we could fix it by just conditionally assigning either
rb_nextorrb_prevto theschedule_posinunschedule_txq()? I.e., something like:local->schedule_pos[ac] =
rb_next(node)?:rb_prev(node);I am not sure I am getting your point. Still in
next_txq, schedule_pos[ac] will lead us to the next node of the one we want.The logic in
next_txqis different when schedule_pos[ac] is NULL, vs
whenrb_next(schedule_pos[ac])is NULL. The former restarts a new scheduling round, while the latter ends the current round.Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
-Toke
--
Yibo--
Yibo--
Yibo
Signature · 6 lines
Yibo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 599 lines · Yibo Zhao
Quoted 577 lines · Toke Høiland-Jørgensen
Quoted 569 lines · Yibo Zhao
Quoted 544 lines · Toke Høiland-Jørgensen
Quoted 533 lines · Yibo Zhao
Quoted 523 lines · Toke Høiland-Jørgensen
Quoted 512 lines · Yibo Zhao
Quoted 473 lines · Toke Høiland-Jørgensen
Quoted 381 lines · Yibo Zhao
Quoted 370 lines · Toke Høiland-Jørgensen
Quoted 336 lines · Yibo Zhao
Quoted 308 lines · Toke Høiland-Jørgensen
Quoted 305 lines · Yibo Zhao
On 2019-09-18 05:10, Toke Høiland-Jørgensen wrote:
Yibo Zhao <[email protected]> writes:In a loop txqs dequeue scenario, if the first txq in the
rbtree
gets
removed from rbtree immediately in the
ieee80211_return_txq(),
the
loop will break soon in the ieee80211_next_txq() due to
schedule_pos
not leading to the second txq in the rbtree. Thus,
defering
the
removal right before the end of this schedule round.Co-developed-by: Yibo Zhao <[email protected]>
Signed-off-by: Yibo Zhao <[email protected]>
Signed-off-by: Toke Høiland-Jørgensen <[email protected]>I didn't write this patch, so please don't use my sign-off.
I'll
add
ack or review tags as appropriate in reply; but a few
comments
first:---
include/net/mac80211.h | 16 ++++++++++--
net/mac80211/ieee80211_i.h | 3 +++
net/mac80211/main.c | 6 +++++
net/mac80211/tx.c | 63
+++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 83 insertions(+), 5 deletions(-)diff --git a/include/net/mac80211.h
b/include/net/mac80211.h
index ac2ed8e..ba5a345 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -925,6 +925,8 @@ struct ieee80211_tx_rate {#define IEEE80211_MAX_TX_RETRY 31
+#define IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS 100
+
static inline void ieee80211_rate_set_vht(struct
ieee80211_tx_rate
*rate,
u8 mcs, u8 nss)
{
@@ -6232,7 +6234,8 @@ struct sk_buff
*ieee80211_tx_dequeue(struct
ieee80211_hw *hw,
* @ac: AC number to return packets from.
*
* Should only be called between calls to
ieee80211_txq_schedule_start()
- * and ieee80211_txq_schedule_end().
+ * and ieee80211_txq_schedule_end(). If the txq is empty,
it
will
be
added
+ * to a remove list and get removed later.
* 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.
@@ -6268,7 +6271,8 @@ void
ieee80211_txq_schedule_start(struct
ieee80211_hw *hw, u8 ac)
* @hw: pointer as obtained from ieee80211_alloc_hw()
* @ac: AC number to acquire locks for
*
- * Release locks previously acquired by
ieee80211_txq_schedule_end().
+ * Release locks previously acquired by
ieee80211_txq_schedule_end().
Check
+ * and remove the empty txq from rb-tree.
*/
void ieee80211_txq_schedule_end(struct ieee80211_hw *hw,
u8
ac)
__releases(txq_lock);
@@ -6287,6 +6291,14 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw, struct ieee80211_txq *txq)
__acquires(txq_lock) __releases(txq_lock);/**
+ * ieee80211_txqs_check - Check txqs waiting for removal
+ *
+ * @tmr: pointer as obtained from local
+ *
+ */
+void ieee80211_txqs_check(struct timer_list *tmr);
+
+/**
* ieee80211_txq_may_transmit - check whether TXQ is
allowed
to
transmit
*
* This function is used to check whether given txq is
allowed
to
transmit by
diff --git a/net/mac80211/ieee80211_i.h
b/net/mac80211/ieee80211_i.h
index a4556f9..49aa143e 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -847,6 +847,7 @@ struct txq_info {
struct codel_stats cstats;
struct sk_buff_head frags;
struct rb_node schedule_order;
+ struct list_head candidate;
unsigned long flags;/* keep last! */
@@ -1145,6 +1146,8 @@ struct ieee80211_local {
u64 airtime_v_t[IEEE80211_NUM_ACS];
u64 airtime_weight_sum[IEEE80211_NUM_ACS];+ struct list_head remove_list[IEEE80211_NUM_ACS];
+ struct timer_list remove_timer;
u16 airtime_flags;const struct ieee80211_ops *ops;
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index e9ffa8e..78fe24a 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -667,10 +667,15 @@ struct ieee80211_hw
*ieee80211_alloc_hw_nm(size_t priv_data_len,for (i = 0; i < IEEE80211_NUM_ACS; i++) {
local->active_txqs[i] = RB_ROOT_CACHED;
+ INIT_LIST_HEAD(&local->remove_list[i]);
spin_lock_init(&local->active_txq_lock[i]);
}
local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX;+ timer_setup(&local->remove_timer, ieee80211_txqs_check,
0);
+ mod_timer(&local->remove_timer,
+ jiffies +
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS));
+
INIT_LIST_HEAD(&local->chanctx_list);
mutex_init(&local->chanctx_mtx);@@ -1305,6 +1310,7 @@ void ieee80211_unregister_hw(struct
ieee80211_hw
*hw)
tasklet_kill(&local->tx_pending_tasklet);
tasklet_kill(&local->tasklet);+ del_timer_sync(&local->remove_timer);
#ifdef CONFIG_INET
unregister_inetaddr_notifier(&local->ifa_notifier);
#endif
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index d00baaa..42ca010 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -1450,6 +1450,7 @@ void ieee80211_txq_init(struct
ieee80211_sub_if_data *sdata,
codel_stats_init(&txqi->cstats);
__skb_queue_head_init(&txqi->frags);
RB_CLEAR_NODE(&txqi->schedule_order);
+ INIT_LIST_HEAD(&txqi->candidate);txqi->txq.vif = &sdata->vif;
@@ -3724,6 +3725,9 @@ void ieee80211_schedule_txq(struct
ieee80211_hw
*hw,spin_lock_bh(&local->active_txq_lock[ac]);
+ if (!list_empty(&txqi->candidate))
+ list_del_init(&txqi->candidate);
+
if (!RB_EMPTY_NODE(&txqi->schedule_order))
goto out;@@ -3783,6 +3787,20 @@ static void
__ieee80211_unschedule_txq(struct
ieee80211_hw *hw,
RB_CLEAR_NODE(&txqi->schedule_order);
}+void ieee80211_remove_txq(struct ieee80211_hw *hw,
+ struct ieee80211_txq *txq)
+{
+ struct ieee80211_local *local = hw_to_local(hw);
+ struct txq_info *txqi = to_txq_info(txq);
+
+ lockdep_assert_held(&local->active_txq_lock[txq->ac]);
+
+ if (!RB_EMPTY_NODE(&txqi->schedule_order)) {
+ __ieee80211_unschedule_txq(hw, txq);
+ list_del_init(&txqi->candidate);
+ }
+}
+
void ieee80211_unschedule_txq(struct ieee80211_hw *hw,
struct ieee80211_txq *txq)
__acquires(txq_lock) __releases(txq_lock)
@@ -3790,7 +3808,7 @@ void ieee80211_unschedule_txq(struct
ieee80211_hw *hw,
struct ieee80211_local *local = hw_to_local(hw);spin_lock_bh(&local->active_txq_lock[txq->ac]);
- __ieee80211_unschedule_txq(hw, txq);
+ ieee80211_remove_txq(hw, txq);
spin_unlock_bh(&local->active_txq_lock[txq->ac]);
}@@ -3803,11 +3821,48 @@ void ieee80211_return_txq(struct
ieee80211_hw
*hw,
lockdep_assert_held(&local->active_txq_lock[txq->ac]);if (!RB_EMPTY_NODE(&txqi->schedule_order) &&
- (skb_queue_empty(&txqi->frags) &&
!txqi->tin.backlog_packets))
- __ieee80211_unschedule_txq(hw, txq);
+ !txq_has_queue(&txqi->txq) &&
+ list_empty(&txqi->candidate))
+ list_add_tail(&txqi->candidate,
&local->remove_list[txq->ac]);
+
}
EXPORT_SYMBOL(ieee80211_return_txq);+void __ieee80211_check_txqs(struct ieee80211_local
*local,
int
ac)
+{
+ struct txq_info *iter, *tmp;
+ struct sta_info *sta;
+
+ lockdep_assert_held(&local->active_txq_lock[ac]);
+
+ list_for_each_entry_safe(iter, tmp,
&local->remove_list[ac],
+ candidate) {
+ sta = container_of(iter->txq.sta, struct sta_info,
sta);
+
+ if (txq_has_queue(&iter->txq))
+ list_del_init(&iter->candidate);
+ else
+ ieee80211_remove_txq(&local->hw, &iter->txq);
+ }
+}
+
+void ieee80211_txqs_check(struct timer_list *t)
+{
+ struct ieee80211_local *local = from_timer(local, t,
remove_timer);
+ struct txq_info *iter, *tmp;
+ struct sta_info *sta;
+ int ac;
+
+ for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
+ spin_lock_bh(&local->active_txq_lock[ac]);
+ __ieee80211_check_txqs(local, ac);
+ spin_unlock_bh(&local->active_txq_lock[ac]);
+ }
+
+ mod_timer(&local->remove_timer,
+ jiffies +
msecs_to_jiffies(IEEE80211_AIRTIME_TXQ_RM_CHK_INTV_IN_MS));
+}I'll ask the same as I did last time (where you told me to
hold
off
until this round):Why do you need the timer and the periodic check? If TXQs
are
added
to
the remove list during the scheduling run, and
__ieee80211_check_txqs()
is run from schedule_end(), isn't that sufficient to clear
the
list?
Is it possible that a txq is not added to the remove list
but
then
packets in it are dropped by fq_codel algo? Like the station
disconnects
without any notification.Quoted 6 lines
Well as long as all the other cleanup paths call directly into
__unschedule_txq(), that should remove stations from the scheduler
when
they disconnect etc.Yes, the disconnect scenario is a bad example. My concern is, say,
we
have 10 stations and only one of them is assigned a very small weight
compared with that of others. Suppose, after its chance of Tx, it
is
most likely to be placed in the rightmost(still has some packets
in
the
txq) and no more incoming data for it. The remaining packets in
txq
will
be dropped due to timeout algo in codel(correct me if I am wrong)
but
this empty txq will stay on the rbtree until other txqs get drainedQuoted 8 lines
or
global vt catch up with its vt. The staying time could be long if
weight
is extremely small. Then do we need timer to check or any other
better
solution?Ah, I see what you mean. No, I don't think this will be a problem;
the
scenario you're describing would play out like this:1. Station ends transmitting, still has a single packet queued, gets
moved to the end of the rbtree (and stays there for a
while).2. When we finally get to the point where this station gets another
chance to transmit, the CoDel drop timer triggers and the
last
packet
is dropped[0]. This means that the queue will just be empty (andieee80211_tx_dequeue()will return NULL).3. Because the queue is empty,
ieee80211_return_txq()will not put
it
back on the rbtree.Quoted 10 lines
Crucially, in 2. the CoDel algorithm doesn't kick in until the point
of
packet dequeue. But even if an empty queue stays on the rbtree for
a
while, there is no harm in that: eventually it will get its turn,
it
will turn out to be empty, and just be skipped over.Quoted 4 lines
Then that will be fine. Thanks for the explanation of the dropping
part
in CoDel algorithm.Yup, think so. And you're welcome :)
Quoted 10 lines
Quoted 7 lines
The issue we need to be concerned about is the opposite: If we have
a
queue that *does* have packets queued, but which is *not* scheduled
for
transmission, that will stall TX.Is it by design since its vt is more than global vt, right? The lattency
may somehow get impacted though.Well, it should still stay on the rbtree as long as it has packets
queued. We don't have a check anywhere that reschedules TXQs whosev_t
drops below globalv_t...Quoted 56 lines
Quoted 41 lines
[0] CoDel in most cases only drops a single packet at a time, so
it
will
not clear out an entire queue with multiple packets in one go. But
you
are right that it could conceivably drop the last packet in a queue.Quoted 20 lines
Quoted 13 lines
We only need to defer removal inside a single "scheduling round"
(i.e.,
between a pair of ieee80211_txq_schedule_start/end. So if we just
walk
the remove list inschedule_end()we should be enough, no?Hmm, or maybe a simpler way to fix the original issue is just to
haveunschedule_txq()update theschedule_pos()pointer?Quoted 7 lines
I.e.,
unschedule_txqchecks if the txq being removed is currently
being
pointed to by schedule_pos[ac], and if it is, it updatesschedule_pos
to
be therb_nextof the current value?Quoted 8 lines
Actually, if
schedule_posis updated torb_nextof the current value,
then in thenext_txq()where we are going to userb_nextagain and
finally pick the next node of the node we really want. Is it fine
to
updateschedule_posto NULL?Hmm, yeah, good point.
Quoted 12 lines
If we do end up setting
schedule_posto NULL in the middle of a scheduling round, that will makenext_txq()"start over", and do
another
loop through the whole thing. I guess we may be able hit a case where
things can oscillate back and forth between addition and removal
resulting in an infinite loop? Not sure, but at least I can't seem
to
convince myself that this can't happen.As the loop of
next_txqunder lock protection as below,Quoted 8 lines
txq_schedule_start();
while(txq=next_txq()){
...return_txq(txq);
}txq_schedule_end();I do not see any chance of addition, no?
Quoted 9 lines
As you noted in your other email, Felix reduced the locking. And yeah,
we need to rebase this series to also incorporate that. I figure I
can
send an updated version of the first patch in the series once we've
worked out the remaining issues with your follow-up patches.Oh, I was thinking we were discussing without locking reduced. Yes,
I
also agree there might be a case causing infinite loop. With locking
reduced, the tree can be adjusted betweennext_txq()andreturn_txq()
in
the loop situation. For further discussion, let 's consider,
1) the tree starts like:A->B->C->D->E2) then
next_txq()returns A for dequeuing
3) driver dequeues A and draines A without any active txq locked meaning
the tree could be changed upon Tx compeletion.
4) then inreturn_txq(), the tree could be,i A->B->C->D->E (A is empty, and maybe soon be added back before the loop end) ii B->C->A->D->E (A is empty, and maybe soon be added back before the loop end) iii B->C->D->E->A (A is empty, and maybe soon be addedback
before the loop end)with this change:
local->schedule_pos[ac] =rb_next(node)?:rb_prev(node);Quoted 8 lines
for case i, local->schedule_pos[ac] is
rb_next(A)which is B, and innext_txq(),rb_next(B)is what we returns which actually is C and B
is
skipped, no?Similiar for case ii, we skip B, C, D.
Quoted 9 lines
Yup, I think you're right. But if we can fix this by making
ieee80211_resort_txq()aware of theschedule_posas well, no? I.e., ifresort_txq()acts on the txq that's currently inschedule_pos, it will
update schedule pos with the samerb_next(node)?:rb_prev(node); (optionally after checking that the position of the node is actually
going to change).Quoted 8 lines
Sorry, please igore last email sent by mistake.
I don't think it makes any difference with that in
unschedule_txq(). For
case i, it finally picks C as well innext_txq(). Fornext_txq(),schedule_posmeans previous candidate node whereas with your change, it
looks likeschedule_posis current candidate node instead.Quoted 4 lines
Hmm, that was not actually what I was thinking, but yeah I think you're
right that it would be easier to just change it soschedule_posis pointing to the next and not the current txq we want to schedule.So do you mean we can change
next_txqlike this,struct
ieee80211_txq*ieee80211_next_txq(structieee80211_hw*hw, u8
ac)
{struct ieee80211_local *local = hw_to_local(hw); struct rb_node *node = local->schedule_pos[ac]; struct txq_info *txqi = NULL; bool first = false;lockdep_assert_held(&local->active_txq_lock[ac]);if (!node) { node = rb_first_cached(&local->active_txqs[ac]); first = true;(quoted diff) +2
-2- } else - node = rb_next(node); + } +if (!node)Quoted 1 line
return NULL;
Ah, no, now I remember why this didn't work and I went with the other
approach: If you make this change, you also have to have this at the end:Quoted 8 lines
local->schedule_pos[ac] =
rb_next(node);But this means we can no longer distinguish between having gone through the whole thing (so
rb_next()returns NULL), or starting out with nothing.So, instead we need to keep
next_txq()the way it is, and just addRight, should keep
next_txq()the way it is.Quoted 4 lines
local->schedule_pos[ac] =
rb_prev(node);whenever we remove a node (both in
return_txq()andresort_txq()).Agree, and also we may need to consider case like A is removed and soon be added back just the same as ii),
B->C->A->D->E then B is schedule, removed and soon added back, C->A->B->D->E
Quoted 8 lines
A and B will have a second chance to be scheduled and this may happen to others as well leading to the infinite loop as you have mentioned previously, so do we need to maintain a
schedule_roundlike we do in DRR? Like,
- If the node is in the same round, by pass schedule, go torb_next(), either continue loop this round or end this round.
- Increase theschedule_roundat theschedule_start()only when theschedule_posis NULL.
Hmm, yeah, I guess we could end up with a loop like that as well. Keeping the schedule_round would be a way to fix it, but I'm not sure we should just skip that station; maybe we should just end the round instead?
Quoted 56 lines
Quoted 53 lines
Quoted 53 lines
Quoted 3 lines
We'd still need a check in
resort_txq()then, but it would make it safe
to unschedule inreturn_txq()...Yes, agree with that.
Quoted 37 lines
Quoted 37 lines
Quoted 5 lines
Quoted 3 lines
Also I am wondering if there will be some SMP issues relating with local->schedule_pos[ac].
Not sure what you mean by this?
My bad. Please ignore this.
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 19 lines
In ath10k, we will usually push packets of first txq as many as we
can
until it is drained and then move to the next one. So if a txq gets
removed in thereturn_txq, it should always be the leftmost. And during this period, neither vt of any station or global vt can be
updated due to lock protection.Quoted 8 lines
But in that case, we could fix it by just conditionally assigning
eitherrb_nextorrb_prevto theschedule_posinunschedule_txq()? I.e.,
something like:Quoted 4 lines
Quoted 1 line
local->schedule_pos[ac] =
rb_next(node)?:rb_prev(node);I am not sure I am getting your point. Still in
next_txq, schedule_pos[ac] will lead us to the next node of the one we want.The logic in
next_txqis different when schedule_pos[ac] is NULL, vs
whenrb_next(schedule_pos[ac])is NULL. The former restarts a new scheduling round, while the latter ends the current round.Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
-Toke
--
Yibo--
Yibo--
YiboSignature · 1 line
Yibo
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 14 lines · Toke Høiland-Jørgensen
Quoted 12 lines · Yibo Zhao
Quoted 11 lines · Toke Høiland-Jørgensen
Quoted 9 lines · Yibo Zhao
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Yibo Zhao
Quoted 5 lines · Toke Høiland-Jørgensen
Quoted 3 lines · Yibo Zhao
Quoted 2 lines · Toke Høiland-Jørgensen
Yibo Zhao <[email protected]> writes:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 7 lines
Quoted 5 lines · Yibo Zhao
Quoted 4 lines · Toke Høiland-Jørgensen
Yibo Zhao <[email protected]> writes:
On 2019-09-18 05:10, Toke Høiland-Jørgensen wrote:
Yibo Zhao <[email protected]> writes:
Guys, PLEASE please consider us poor maintainers drowning in email and edit your quotes :) This style of discussion makes patchwork unusable:
https://patchwork.kernel.org/patch/11147019/
Signature · 6 lines
Kalle Valo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 22 lines · Kalle Valo
Quoted 20 lines · Toke Høiland-Jørgensen
Quoted 18 lines · Yibo Zhao
Quoted 17 lines · Toke Høiland-Jørgensen
Quoted 15 lines · Yibo Zhao
Quoted 14 lines · Toke Høiland-Jørgensen
Quoted 12 lines · Yibo Zhao
Quoted 11 lines · Toke Høiland-Jørgensen
Quoted 9 lines · Yibo Zhao
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Yibo Zhao
Quoted 5 lines · Toke Høiland-Jørgensen
Quoted 3 lines · Yibo Zhao
On 2019-09-18 19:23, Toke Høiland-Jørgensen wrote:
Yibo Zhao <[email protected]> writes:
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
On 2019-09-18 05:10, Toke Høiland-Jørgensen wrote:
Yibo Zhao <[email protected]> writes:Guys, PLEASE please consider us poor maintainers drowning in email and edit your quotes :) This style of discussion makes patchwork unusable:
Heh, oops, didn't realise you were following the discussion from patchwork; sorry, will be sure to cut things in the future.
The quote marks do make a very nice (reverse) christmas tree, though ;)
-Toke
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 27 lines · Toke Høiland-Jørgensen
Quoted 25 lines · Kalle Valo
Quoted 22 lines · Toke Høiland-Jørgensen
Quoted 20 lines · Yibo Zhao
Quoted 19 lines · Toke Høiland-Jørgensen
Quoted 17 lines · Yibo Zhao
Quoted 16 lines · Toke Høiland-Jørgensen
Quoted 14 lines · Yibo Zhao
Quoted 13 lines · Toke Høiland-Jørgensen
Quoted 11 lines · Yibo Zhao
Quoted 10 lines · Toke Høiland-Jørgensen
Quoted 8 lines · Yibo Zhao
Quoted 7 lines · Toke Høiland-Jørgensen
Yibo Zhao <[email protected]> writes:
On 2019-09-18 19:23, Toke Høiland-Jørgensen wrote:
Yibo Zhao <[email protected]> writes:On 2019-09-18 05:10, Toke Høiland-Jørgensen wrote:
Yibo Zhao <[email protected]> writes:
Quoted 7 lines
Quoted 4 lines
Guys, PLEASE please consider us poor maintainers drowning in email and edit your quotes :) This style of discussion makes patchwork unusable:
Heh, oops, didn't realise you were following the discussion from patchwork; sorry, will be sure to cut things in the future.
To be honest, I'm not sure how much Johannes uses patchwork. But I check everything from patchwork 95% of the time and try to keep my email boxes clean.
Quoted 1 line
The quote marks do make a very nice (reverse) christmas tree, though ;)
It did! I had to include that to my rant :)
Signature · 6 lines
Kalle Valo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 32 lines · Kalle Valo
Quoted 30 lines · Toke Høiland-Jørgensen
Quoted 28 lines · Kalle Valo
Quoted 14 lines · Toke Høiland-Jørgensen
Quoted 12 lines · Yibo Zhao
Quoted 11 lines · Toke Høiland-Jørgensen
Quoted 9 lines · Yibo Zhao
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Yibo Zhao
Quoted 5 lines · Toke Høiland-Jørgensen
Quoted 3 lines · Yibo Zhao
Quoted 2 lines · Toke Høiland-Jørgensen
Yibo Zhao <[email protected]> writes:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Toke Høiland-Jørgensen
Yibo Zhao <[email protected]> writes:
On 2019-09-18 19:23, Toke Høiland-Jørgensen wrote:
Yibo Zhao <[email protected]> writes:On 2019-09-18 05:10, Toke Høiland-Jørgensen wrote:
Yibo Zhao <[email protected]> writes:Guys, PLEASE please consider us poor maintainers drowning in email and edit your quotes :) This style of discussion makes patchwork unusable:
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Heh, oops, didn't realise you were following the discussion from patchwork; sorry, will be sure to cut things in the future.
To be honest, I'm not sure how much Johannes uses patchwork. But I check everything from patchwork 95% of the time and try to keep my email boxes clean.
Noted. I'll try to be nice to patchwork, then :)
Quoted 3 lines
Quoted 1 line
The quote marks do make a very nice (reverse) christmas tree, though ;)
It did! I had to include that to my rant :)
:D
-Toke
_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
In reply to Toke Høiland-JørgensenQuoted 25 lines · Toke Høiland-Jørgensen
Quoted 14 lines · Yibo Zhao
Quoted 1 line
So, instead we need to keep
next_txq()the way it is, and just addRight, should keep
next_txq()the way it is.Quoted 4 lines
local->schedule_pos[ac] =
rb_prev(node);whenever we remove a node (both in
return_txq()andresort_txq()).Agree, and also we may need to consider case like A is removed and soon be added back just the same as ii),
B->C->A->D->E then B is schedule, removed and soon added back, C->A->B->D->EQuoted 9 lines
A and B will have a second chance to be scheduled and this may happen to others as well leading to the infinite loop as you have mentioned previously, so do we need to maintain a
schedule_roundlike we do in DRR? Like,
- If the node is in the same round, by pass schedule, go torb_next(), either continue loop this round or end this round.
- Increase theschedule_roundat theschedule_start()only when
theschedule_posis NULL.
Quoted 4 lines
Hmm, yeah, I guess we could end up with a loop like that as well. Keeping the
schedule_roundwould be a way to fix it, but I'm not sure we should just skip that station; maybe we should just end the round instead?
I am not sure. I believe, in some cases, the rest of the nodes which could be most of the nodes in the tree will not have the chance to be scheduled in this round.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
We'd still need a check in
resort_txq()then, but it would make it safe
to unschedule inreturn_txq()...Yes, agree with that.
Signature · 1 line
Yibo
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 8 lines
Quoted 5 lines
Hmm, yeah, I guess we could end up with a loop like that as well. Keeping the
schedule_roundwould be a way to fix it, but I'm not sure we
should just skip that station; maybe we should just end the round instead?I am not sure. I believe, in some cases, the rest of the nodes which could be most of the nodes in the tree will not have the chance to be scheduled in this round.
My guess would be that it doesn't really matter, because in most cases each schedule round will only actually end up queueing packets from one or two stations; as the driver will pull multiple packets from that one station which will often fill up the firmware queues (especially once we start throttling that with the AQL stuff).
So I guess we can just skip TXQs that we've already seen this scheduling round, and let the v_t compare determine transmit eligibility :)
-Toke
_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 9 lines · Toke Høiland-Jørgensen
Quoted 8 lines
Quoted 5 lines
Hmm, yeah, I guess we could end up with a loop like that as well. Keeping the
schedule_roundwould be a way to fix it, but I'm not sure we
should just skip that station; maybe we should just end the round instead?I am not sure. I believe, in some cases, the rest of the nodes which could be most of the nodes in the tree will not have the chance to be scheduled in this round.
Quoted 8 lines
My guess would be that it doesn't really matter, because in most cases each schedule round will only actually end up queueing packets from one or two stations; as the driver will pull multiple packets from that one station which will often fill up the firmware queues (especially once we start throttling that with the AQL stuff).
So I guess we can just skip TXQs that we've already seen this scheduling round, and let the
v_tcompare determine transmit eligibility :)
I am a little confused. So do you mean it is fine for you to skip the TXQs we met in this round before and continue the loop until the end or vt comparison failure?
Quoted 2 lines
-Toke
Signature · 6 lines
Yibo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 2/4] mac80211: defer txqs removal from rbtree
Quoted 17 lines · Yibo Zhao
Quoted 16 lines · Toke Høiland-Jørgensen
Quoted 8 lines
Quoted 5 lines
Hmm, yeah, I guess we could end up with a loop like that as well. Keeping the
schedule_roundwould be a way to fix it, but I'm not sure we
should just skip that station; maybe we should just end the round instead?I am not sure. I believe, in some cases, the rest of the nodes which could be most of the nodes in the tree will not have the chance to be scheduled in this round.
My guess would be that it doesn't really matter, because in most cases each schedule round will only actually end up queueing packets from one or two stations; as the driver will pull multiple packets from that one station which will often fill up the firmware queues (especially once we
start throttling that with the AQL stuff).
Quoted 7 lines
Quoted 3 lines
So I guess we can just skip TXQs that we've already seen this scheduling
round, and let thev_tcompare determine transmit eligibility :)I am a little confused. So do you mean it is fine for you to skip the TXQs we met in this round before and continue the loop until the end or vt comparison failure?
Yeah. In most cases it won't make any difference; but it'll make sure we visit all eligible TXQs in all cases, so we might as well do that if we're tracking the scheduling round anyway.
-Toke
PATCH 3/4 mac80211: fix low throughput in push pull mode
In reply to Yibo ZhaoIf station is ineligible for transmission in ieee80211_txq_may_transmit(), no packet will be delivered to FW. During the tests in push-pull mode with many clients, after several seconds, not a single station is an eligible candidate for transmission since global time is smaller than all the station's virtual airtime. As a consequence, the Tx has been blocked and throughput is quite low.
To avoid this situation to occur in push-pull mode, the new proposal is:
- Increase the airtime grace period a little more to reduce the unexpected sync
- If global virtual time is less than the virtual airtime of any station, sync it to the airtime of first station in the red-black tree
- Round the division result since the process of global virtual time involves the division calculation
--- net/mac80211/sta_info.c | 3 ++- net/mac80211/sta_info.h | 2 +- net/mac80211/tx.c | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-)
net/mac80211/sta_info.c +2 -1
@@ -1852,7 +1852,8 @@ void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid, weight_sum = local->airtime_weight_sum[ac] ?: sta->airtime_weight; - local->airtime_v_t[ac] += airtime / weight_sum; +/* Round the calculation of global vt */ + local->airtime_v_t[ac] += (airtime + (weight_sum >>1 )) / weight_sum; sta->airtime[ac].v_t += airtime / sta->airtime_weight;ieee80211_resort_txq (&local->hw, txq);
net/mac80211/sta_info.h +1 -1
@@ -130,7 +130,7 @@ 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_GRACE 500/* usec of grace period before reset */ +#define AIRTIME_GRACE 2000/* usec of grace period before reset */ struct airtime_info {u64 rx_airtime;
net/mac80211/tx.c +15 -1
@@ -3867,15 +3867,29 @@ bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq) {struct ieee80211_local *local =hw_to_local (hw); -struct txq_info *txqi =to_txq_info (txq); +struct txq_info *first_txqi, *txqi =to_txq_info (txq); +struct rb_node *node =NULL ;struct sta_info *sta;u8 ac = txq->ac; + first_txqi =NULL ;lockdep_assert_held (&local->active_txq_lock[ac]);if (!txqi->txq.sta)return true; + node =rb_first_cached (&local->active_txqs[ac]); +if (node) { + first_txqi = container_of(node, struct txq_info, + schedule_order); +if (first_txqi->txq.sta) { + sta =container_of (first_txqi->txq.sta, + struct sta_info, sta); +if (local->airtime_v_t[ac] < sta->airtime[ac].v_t) + local->airtime_v_t[ac] = sta->airtime[ac].v_t; + } + } + sta = container_of(txqi->txq.sta, struct sta_info, sta);return (sta->airtime[ac].v_t <= local->airtime_v_t[ac]); }
Signature · 7 lines
1.9.1 _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Johannes Berg
maintainerRe: [PATCH 3/4] mac80211: fix low throughput in push pull mode
Without really looking at the code -
Quoted 6 lines
If station is ineligible for transmission in
ieee80211_txq_may_transmit(), no packet will be delivered to FW. During the tests in push-pull mode with many clients, after several seconds, not a single station is an eligible candidate for transmission since global time is smaller than all the station's virtual airtime. As a consequence, the Tx has been blocked and throughput is quite low.
You should rewrite this to be, erm, a bit more understandable in mac80211 context. I assume you're speaking (mostly?) about ath10k, but I have very little context there. "push pull mode"? "firmware"? These things are not something mac80211 knows about.
Quoted 1 line
Co-developed-by Yibo Zhao <[email protected]>
That also seems wrong, should be Toke I guess, unless you intended for a
From: Toke to be present?
johannes
_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 3/4] mac80211: fix low throughput in push pull mode
Quoted 9 lines · Johannes Berg
Without really looking at the code -
Quoted 6 lines
If station is ineligible for transmission in
ieee80211_txq_may_transmit(), no packet will be delivered to FW. During the tests in push-pull mode with many clients, after several seconds, not a single station is an eligible candidate for transmission since global time is smaller than all the station's virtual airtime. As a consequence, the Tx has been blocked and throughput is quite low.
Quoted 4 lines
You should rewrite this to be, erm, a bit more understandable in mac80211 context. I assume you're speaking (mostly?) about ath10k, but I have very little context there. "push pull mode"? "firmware"? These things are not something mac80211 knows about.
Hi Johannes,
Thanks for your kindly reminder. Will rewrite the commit log.
Quoted 5 lines
Quoted 2 lines
Co-developed-by Yibo Zhao <[email protected]>That also seems wrong, should be Toke I guess, unless you intended for a
From: Toke to be present?
Do you mean it should be something like:
Am I understanding right?
Quoted 2 lines
johannes
Signature · 6 lines
Yibo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Johannes Berg
maintainerRe: [PATCH 3/4] mac80211: fix low throughput in push pull mode
Quoted 6 lines · Yibo Zhao
Do you mean it should be something like:
Co-developed-by Toke Høiland-Jørgensen <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>
Yes, I think you mean the right thing. For the record, it seems to me it should be
From: A <...>
[...]
or so.
IOW, I think having the same "From:" (which gets preserved in git as "Author") and "Co-developed-by" makes no sense?
Your "From" line was implied, but I suppose you did mean that From would be yourself (as it was in the patch) and then the above seems right.
Or you can add a "From: Toke ..." to your patch message and leave the "Co-developed-by: yourself" I suppose, the difference is in how git will record it.
johannes
_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 3/4] mac80211: fix low throughput in push pull mode
In reply to Yibo ZhaoQuoted 29 lines · Yibo Zhao
Quoted 13 lines · Johannes Berg
Without really looking at the code -
Quoted 10 lines
If station is ineligible for transmission in
ieee80211_txq_may_transmit(),
no packet will be delivered to FW. During the tests in push-pull mode with
many clients, after several seconds, not a single station is an eligible
candidate for transmission since global time is smaller than all the station's virtual airtime. As a consequence, the Tx has been blocked and
throughput is quite low.Quoted 5 lines
You should rewrite this to be, erm, a bit more understandable in mac80211 context. I assume you're speaking (mostly?) about ath10k, but I
have very little context there. "push pull mode"? "firmware"? These things are not something mac80211 knows about.Hi Johannes,
Thanks for your kindly reminder. Will rewrite the commit log.
Quoted 6 lines
Quoted 2 lines
Co-developed-by Yibo Zhao <[email protected]>That also seems wrong, should be Toke I guess, unless you intended for a
From: Toke to be present?
Quoted 7 lines
Do you mean it should be something like:
Co-developed-by Toke Høiland-Jørgensen <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>Am I understanding right?
I think the right thing here, as with the previous patch, is to just drop my sign-off; you're writing this patch, and I'll add ack/reviews as appropriate. And in that case, well, no need to have co-developed-by yourself when your name is on the patch as author :)
-Toke
Re: [PATCH 3/4] mac80211: fix low throughput in push pull mode
Quoted 37 lines · Toke Høiland-Jørgensen
Quoted 35 lines · Yibo Zhao
Quoted 13 lines · Johannes Berg
Without really looking at the code -
Quoted 10 lines
If station is ineligible for transmission in
ieee80211_txq_may_transmit(),
no packet will be delivered to FW. During the tests in push-pull mode with
many clients, after several seconds, not a single station is an eligible
candidate for transmission since global time is smaller than all the station's virtual airtime. As a consequence, the Tx has been blocked and
throughput is quite low.Quoted 5 lines
You should rewrite this to be, erm, a bit more understandable in mac80211 context. I assume you're speaking (mostly?) about ath10k, but I
have very little context there. "push pull mode"? "firmware"? These things are not something mac80211 knows about.Hi Johannes,
Thanks for your kindly reminder. Will rewrite the commit log.
Quoted 6 lines
Quoted 2 lines
Co-developed-by Yibo Zhao <[email protected]>That also seems wrong, should be Toke I guess, unless you intended for a
From: Toke to be present?Do you mean it should be something like:
Co-developed-by Toke Høiland-Jørgensen <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>
Quoted 8 lines
Quoted 1 line
Am I understanding right?
I think the right thing here, as with the previous patch, is to just drop my sign-off; you're writing this patch, and I'll add ack/reviews as appropriate. And in that case, well, no need to have co-developed-by yourself when your name is on the patch as author :)
-Toke
Sorry, I think I have missed checking your reply, please ignore the wrong signed-off in PATCH-V2.
Signature · 6 lines
Yibo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 3/4] mac80211: fix low throughput in push pull mode
Quoted 49 lines · Yibo Zhao
Quoted 48 lines · Toke Høiland-Jørgensen
Quoted 32 lines · Yibo Zhao
Quoted 14 lines · Johannes Berg
Without really looking at the code -
Quoted 11 lines
If station is ineligible for transmission in
ieee80211_txq_may_transmit(),
no packet will be delivered to FW. During the tests in push-pull mode
with
many clients, after several seconds, not a single station is an eligible
candidate for transmission since global time is smaller than all the station's virtual airtime. As a consequence, the Tx has been blocked and
throughput is quite low.Quoted 6 lines
You should rewrite this to be, erm, a bit more understandable in mac80211 context. I assume you're speaking (mostly?) about ath10k, but
I
have very little context there. "push pull mode"? "firmware"? These things are not something mac80211 knows about.Hi Johannes,
Thanks for your kindly reminder. Will rewrite the commit log.
Quoted 7 lines
Quoted 2 lines
Co-developed-by Yibo Zhao <[email protected]>That also seems wrong, should be Toke I guess, unless you intended for
a
From: Toke to be present?Quoted 7 lines
Do you mean it should be something like:
Co-developed-by Toke Høiland-Jørgensen <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>Am I understanding right?
I think the right thing here, as with the previous patch, is to just drop my sign-off; you're writing this patch, and I'll add ack/reviews as
appropriate. And in that case, well, no need to have co-developed-by yourself when your name is on the patch as author :)
Quoted 3 lines
Quoted 1 line
-Toke
Sorry, I think I have missed checking your reply, please ignore the wrong signed-off in PATCH-V2.
While you're re-spinning, could you please add a changelog for the changes you make? Makes it easier to keep track :)
You can add a cover-letter with a full changelog instead of having a separate changelog for each patch; that's what I usually do...
-Toke
Re: [PATCH 3/4] mac80211: fix low throughput in push pull mode
Quoted 55 lines · Toke Høiland-Jørgensen
Quoted 49 lines · Yibo Zhao
Quoted 48 lines · Toke Høiland-Jørgensen
Quoted 32 lines · Yibo Zhao
Quoted 14 lines · Johannes Berg
Without really looking at the code -
Quoted 11 lines
If station is ineligible for transmission in
ieee80211_txq_may_transmit(),
no packet will be delivered to FW. During the tests in push-pull mode
with
many clients, after several seconds, not a single station is an eligible
candidate for transmission since global time is smaller than all the station's virtual airtime. As a consequence, the Tx has been blocked and
throughput is quite low.Quoted 6 lines
You should rewrite this to be, erm, a bit more understandable in mac80211 context. I assume you're speaking (mostly?) about ath10k, but
I
have very little context there. "push pull mode"? "firmware"? These things are not something mac80211 knows about.Hi Johannes,
Thanks for your kindly reminder. Will rewrite the commit log.
Quoted 7 lines
Quoted 2 lines
Co-developed-by Yibo Zhao <[email protected]>That also seems wrong, should be Toke I guess, unless you intended for
a
From: Toke to be present?Quoted 7 lines
Do you mean it should be something like:
Co-developed-by Toke Høiland-Jørgensen <[email protected]>Signed-off-by Yibo Zhao <[email protected]>Signed-off-by Toke Høiland-Jørgensen <[email protected]>Am I understanding right?
I think the right thing here, as with the previous patch, is to just drop my sign-off; you're writing this patch, and I'll add ack/reviews as
appropriate. And in that case, well, no need to have co-developed-by yourself when your name is on the patch as author :)Quoted 3 lines
Quoted 1 line
-Toke
Sorry, I think I have missed checking your reply, please ignore the wrong signed-off in PATCH-V2.
Quoted 7 lines
While you're re-spinning, could you please add a changelog for the changes you make? Makes it easier to keep track :)
You can add a cover-letter with a full changelog instead of having a separate changelog for each patch; that's what I usually do...
-Toke
Sure, thanks.
Signature · 6 lines
Yibo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
PATCH 4/4 mac80211: Sync airtime weight sum with per AC synced sta airtime weight together
In reply to Yibo ZhaoGlobal airtime weight sum is updated only when txq is added/removed from rbtree. If upper layer configures sta weight during high load, airtime weight sum will not be updated since txq is most likely on the tree. It could a little late for upper layer to reconfigure sta weight when txq is already in the rbtree. And thus, incorrect airtime weight sum will lead to incorrect global virtual time calculation as well as global airtime weight sum overflow of airtime weight sum during txq removed.
Hence, need to update airtime weight sum upon receiving event for configuring sta weight once sta's txq is on the rbtree.
Besides, if airtime weight sum of ACs and sta weight is synced under the same per AC lock protection, there can be a very short window causing incorrct airtime weight sum calculation as below:
active_txq_lock_VO .
VO weight sum is syncd .
sta airtime weight sum is synced .
active_txq_unlock_VO .
. .
active_txq_lock_VI .
VI weight sum is syncd .
sta airtime weight sum active_txq_lock_BE
active_txq_unlock_VI Remove txq and thus sum
. is calculated with synced
. sta airtime weight
. active_txq_unlock_BE
So introduce a per ac synced station airtime weight synced with per AC synced weight sum together. And the per-AC station airtime weight is used to calculate weight sum.
--- net/mac80211/cfg.c | 27 +++++++++++++++++++++++++-- net/mac80211/sta_info.c | 6 ++++-- net/mac80211/sta_info.h | 3 +++ net/mac80211/tx.c | 4 ++-- 4 files changed, 34 insertions(+), 6 deletions(-)
net/mac80211/cfg.c +25 -2
@@ -1284,7 +1284,8 @@ static int sta_apply_parameters(struct ieee80211_local *local,int ret =0 ;struct ieee80211_supported_band *sband;struct ieee80211_sub_if_data *sdata = sta->sdata; -u32 mask, set; +u32 mask, set, tid, ac; +struct txq_info *txqi; sband =ieee80211_get_sband (sdata);if (!sband)
@@ -1452,8 +1453,30 @@ static int sta_apply_parameters(struct ieee80211_local *local,if (ieee80211_vif_is_mesh (&sdata->vif))sta_apply_mesh_params (local, sta, params); -if (params->airtime_weight) +if (params->airtime_weight && + params->airtime_weight != sta->airtime_weight) { +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +for (tid =0 ; tid <IEEE80211_NUM_TIDS +1 ; tid++) { +if (!sta->sta.txq[tid] || + ac !=ieee80211_ac_from_tid (tid)) +continue ; + + sta->airtime_weight_synced[ac] = + params->airtime_weight; + + txqi =to_txq_info (sta->sta.txq[tid]); +if (RB_EMPTY_NODE (&txqi->schedule_order)) +continue ; + + local->airtime_weight_sum[ac] = local->airtime_weight_sum[ac] + + params->airtime_weight - + sta->airtime_weight; + } +spin_unlock_bh (&local->active_txq_lock[ac]); + } sta->airtime_weight = params->airtime_weight; + }/* set the STA state after all sta info from usermode has been set */ if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
net/mac80211/sta_info.c +4 -2
@@ -389,6 +389,7 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,for (i =0 ; i <IEEE80211_NUM_ACS ; i++) {skb_queue_head_init (&sta->ps_tx_buf[i]);skb_queue_head_init (&sta->tx_filtered[i]); + sta->airtime_weight_synced[i] = sta->airtime_weight; }for (i =0 ; i <IEEE80211_NUM_TIDS ; i++)
@@ -1850,11 +1851,12 @@ void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid, sta->airtime[ac].tx_airtime += tx_airtime; sta->airtime[ac].rx_airtime += rx_airtime; - weight_sum = local->airtime_weight_sum[ac] ?: sta->airtime_weight; + weight_sum = local->airtime_weight_sum[ac] ? + : sta->airtime_weight_synced[ac];/* Round the calculation of global vt */ local->airtime_v_t[ac] += (airtime + (weight_sum >>1 )) / weight_sum; - sta->airtime[ac].v_t += airtime / sta->airtime_weight; + sta->airtime[ac].v_t += airtime / sta->airtime_weight_synced[ac];ieee80211_resort_txq (&local->hw, txq);spin_unlock_bh (&local->active_txq_lock[ac]);
net/mac80211/sta_info.h +3 -0
@@ -476,6 +476,8 @@ struct ieee80211_sta_rx_stats {* @tid_seq: per-TID sequence numbers for sending to this STA * @airtime: per-AC struct airtime_info describing airtime statistics for this * station +* @airtime_weight_synced: station per-AC airtime weight for sync and +* calculation * @airtime_weight: station weight for airtime fairness calculation purposes * @ampdu_mlme: A-MPDU state machine state * @mesh: mesh STA information
@@ -602,6 +604,7 @@ struct sta_info {u16 tid_seq[IEEE80211_QOS_CTL_TID_MASK +1 ];struct airtime_info airtime[IEEE80211_NUM_ACS ]; +u16 airtime_weight_synced[IEEE80211_NUM_ACS ];u16 airtime_weight;/*
net/mac80211/tx.c +2 -2
@@ -3735,7 +3735,7 @@ void ieee80211_schedule_txq(struct ieee80211_hw *hw,struct sta_info *sta =container_of (txq->sta, struct sta_info, sta); - local->airtime_weight_sum[ac] += sta->airtime_weight; + local->airtime_weight_sum[ac] += sta->airtime_weight_synced[ac];if (local->airtime_v_t[ac] >AIRTIME_GRACE ) sta->airtime[ac].v_t =max (local->airtime_v_t[ac] -AIRTIME_GRACE , sta->airtime[ac].v_t);
@@ -3779,7 +3779,7 @@ static void __ieee80211_unschedule_txq(struct ieee80211_hw *hw,struct sta_info *sta =container_of (txq->sta, struct sta_info, sta); - local->airtime_weight_sum[ac] -= sta->airtime_weight; + local->airtime_weight_sum[ac] -= sta->airtime_weight_synced[ac]; } rb_erase_cached(&txqi->schedule_order,
Signature · 7 lines
1.9.1 _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Re: [PATCH 4/4] mac80211: Sync airtime weight sum with per AC synced sta airtime weight together
Quoted 72 lines · Yibo Zhao
Global airtime weight sum is updated only when txq is added/removed from rbtree. If upper layer configures sta weight during high load, airtime weight sum will not be updated since txq is most likely on the tree. It could a little late for upper layer to reconfigure sta weight when txq is already in the rbtree. And thus, incorrect airtime weight sum will lead to incorrect global virtual time calculation as well as global airtime weight sum overflow of airtime weight sum during txq removed.
Hence, need to update airtime weight sum upon receiving event for configuring sta weight once sta's txq is on the rbtree.
Besides, if airtime weight sum of ACs and sta weight is synced under the same per AC lock protection, there can be a very short window causing incorrct airtime weight sum calculation as below:
active_txq_lock_VO.
VO weight sum is syncd .
sta airtime weight sum is synced .
active_txq_unlock_VO.
. .
active_txq_lock_VI.
VI weight sum is syncd .
sta airtime weight sumactive_txq_lock_BE
active_txq_unlock_VIRemove txq and thus sum
. is calculated with synced
. sta airtime weight
.active_txq_unlock_BESo introduce a per ac synced station airtime weight synced with per AC synced weight sum together. And the per-AC station airtime weight is used to calculate weight sum.
Signed-off-by Yibo Zhao <[email protected]>--- net/mac80211/cfg.c | 27 +++++++++++++++++++++++++-- net/mac80211/sta_info.c | 6 ++++-- net/mac80211/sta_info.h | 3 +++ net/mac80211/tx.c | 4 ++-- 4 files changed, 34 insertions(+), 6 deletions(-)net/mac80211/cfg.c +15
-2@@ -1284,7 +1284,8 @@ static int sta_apply_parameters(struct ieee80211_local *local,int ret =0 ;struct ieee80211_supported_band *sband;struct ieee80211_sub_if_data *sdata = sta->sdata; -u32 mask, set; +u32 mask, set, tid, ac; +struct txq_info *txqi; sband =ieee80211_get_sband (sdata);if (!sband)@@ -1452,8 +1453,30 @@ static int sta_apply_parameters(struct ieee80211_local *local,if (ieee80211_vif_is_mesh (&sdata->vif))sta_apply_mesh_params (local, sta, params); -if (params->airtime_weight) +if (params->airtime_weight && + params->airtime_weight != sta->airtime_weight) { +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +for (tid =0 ; tid <IEEE80211_NUM_TIDS +1 ; tid++) { +if (!sta->sta.txq[tid] || + ac !=ieee80211_ac_from_tid (tid)) +continue ; + + sta->airtime_weight_synced[ac] = + params->airtime_weight; + + txqi =to_txq_info (sta->sta.txq[tid]);
net/mac80211/cfg.c static int sta_apply_parameters(struct ieee80211_local *local, · line 1478
Quoted 10 lines
net/mac80211/cfg.c +9
-0+if (RB_EMPTY_NODE (&txqi->schedule_order)) +continue ; + + local->airtime_weight_sum[ac] = local->airtime_weight_sum[ac] + + params->airtime_weight - + sta->airtime_weight; + } +spin_unlock_bh (&local->active_txq_lock[ac]); + } sta->airtime_weight = params->airtime_weight;
With this, airtime_weight is basically only used to return to and from userspace, right? I.e., after the above loop has run, it will match the contents of airtime_weight_synced; so why not just turn airtime_weight into a per-ac array? You could just use airtime_weight[0] as the value to return to userspace...
-Toke
Re: [PATCH 4/4] mac80211: Sync airtime weight sum with per AC synced sta airtime weight together
Quoted 84 lines · Toke Høiland-Jørgensen
Quoted 82 lines · Yibo Zhao
Global airtime weight sum is updated only when txq is added/removed from rbtree. If upper layer configures sta weight during high load, airtime weight sum will not be updated since txq is most likely on the tree. It could a little late for upper layer to reconfigure sta weight when txq is already in the rbtree. And thus, incorrect airtime weight sum will lead to incorrect global virtual time calculation as well as global airtime weight sum overflow of airtime weight sum during txq removed.
Hence, need to update airtime weight sum upon receiving event for configuring sta weight once sta's txq is on the rbtree.
Besides, if airtime weight sum of ACs and sta weight is synced under the same per AC lock protection, there can be a very short window causing incorrct airtime weight sum calculation as below:
active_txq_lock_VO.
VO weight sum is syncd .
sta airtime weight sum is synced .
active_txq_unlock_VO.
. .
active_txq_lock_VI.
VI weight sum is syncd .
sta airtime weight sumactive_txq_lock_BE
active_txq_unlock_VIRemove txq and thus sum
. is calculated with synced
. sta airtime weight
.active_txq_unlock_BESo introduce a per ac synced station airtime weight synced with per AC synced weight sum together. And the per-AC station airtime weight is used to calculate weight sum.
Signed-off-by Yibo Zhao <[email protected]>--- net/mac80211/cfg.c | 27 +++++++++++++++++++++++++-- net/mac80211/sta_info.c | 6 ++++-- net/mac80211/sta_info.h | 3 +++ net/mac80211/tx.c | 4 ++-- 4 files changed, 34 insertions(+), 6 deletions(-)net/mac80211/cfg.c +2
-1@@ -1284,7 +1284,8 @@ static int sta_apply_parameters(structieee80211_local *local, int ret = 0;struct ieee80211_supported_band *sband;struct ieee80211_sub_if_data *sdata = sta->sdata; -u32 mask, set; +u32 mask, set, tid, ac; +struct txq_info *txqi; sband =ieee80211_get_sband (sdata);net/mac80211/cfg.c +21
-1if (!sband)@@ -1452,8 +1453,30 @@ static int sta_apply_parameters(struct ieee80211_local *local, if (ieee80211_vif_is_mesh(&sdata->vif))sta_apply_mesh_params (local, sta, params); -if (params->airtime_weight) +if (params->airtime_weight && + params->airtime_weight != sta->airtime_weight) { +for (ac =0 ; ac <IEEE80211_NUM_ACS ; ac++) { +spin_lock_bh (&local->active_txq_lock[ac]); +for (tid =0 ; tid <IEEE80211_NUM_TIDS +1 ; tid++) { +if (!sta->sta.txq[tid] || + ac !=ieee80211_ac_from_tid (tid)) +continue ; + + sta->airtime_weight_synced[ac] = + params->airtime_weight; + + txqi =to_txq_info (sta->sta.txq[tid]); +if (RB_EMPTY_NODE (&txqi->schedule_order)) +continue ; + + local->airtime_weight_sum[ac] = local->airtime_weight_sum[ac] + + params->airtime_weight - + sta->airtime_weight; + } +spin_unlock_bh (&local->active_txq_lock[ac]);
Quoted 8 lines
net/mac80211/cfg.c static int sta_apply_parameters(struct · line 1479
Quoted 2 lines
net/mac80211/cfg.c +1
-0+ } sta->airtime_weight = params->airtime_weight;With this,
airtime_weightis basically only used to return to and from userspace, right? I.e., after the above loop has run, it will match the contents ofairtime_weight_synced; so why not just turnairtime_weightinto a per-ac array? You could just use airtime_weight[0] as the value to return to userspace...
Yes, I also feel it is a little weird to keep both of them. I am fine with suggestion.
Quoted 2 lines
-Toke
Signature · 6 lines
Yibo _______________________________________________ ath10k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath10k
Quoted 5 lines · Yibo Zhao
From: Toke Høiland-Jørgensen <[email protected]>
This switches the airtime scheduler in mac80211 to use a virtual time-based scheduler instead of the round-robin scheduler used before. This has a couple of advantages:
Thank you for keeping at this! I'll take a look at the series in detail tomorrow.
While you're testing things related to this, I've also prototyped a port of the "airtime queue limit" feature from chromeos into mainline. It's currently in my tree here:
https://git.kernel.org/pub/scm/linux/kernel/git/toke/linux.git/log/?h=mac80211-aql-01
If you have time to test it at some point, that would be awesome. I'm planning to submit it as an RFC, but it needs a bit more work first. Also, it's completely untested, but it does compile :)
-Toke
_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
Quoted 16 lines · Yibo Zhao
From: Toke Høiland-Jørgensen <[email protected]>
This switches the airtime scheduler in mac80211 to use a virtual time-based scheduler instead of the round-robin scheduler used before. This has a couple of advantages:
- No need to sync up the round-robin scheduler in
firmware/hardwarewith the round-robin airtime scheduler.- If several stations are eligible for transmission we can schedule both of them; no need to hard-block the scheduling rotation until the head of the queue has used up its quantum.
- The check of whether a station is eligible for transmission becomes simpler (in
ieee80211_txq_may_transmit()).
Quoted 8 lines
The drawback is that scheduling becomes slightly more expensive, as we need to maintain an rbtree of TXQs sorted by virtual time. This means that
ieee80211_register_airtime()becomes O(logN) in the number of currently scheduled TXQs. However, hopefully this number rarely grows too big (it's only TXQs currently backlogged, not all associated stations), so it shouldn't be too big of an issue.Signed-off-by Toke Høiland-Jørgensen <[email protected]>
I'll note that this patch still has the two issues that Felix pointed out when I posted the RFC version. Namely:
- The use of divisions in the fast path. I guess I need to go write some reciprocal-calculation code, since that is also an issue with the AQL patches I linked to before.
- The fact that we don't count the airtime usage of multicast traffic, which with this series means that the vif TXQ will get priority over the others. I think we agreed to fix this by just adding an airtime v_t to the vif as well and use that for scheduling the TXQ. Does ath10k report airtime usage for multicast as well, or only for stations?
-Toke
Quoted 38 lines · Toke Høiland-Jørgensen
Quoted 19 lines · Yibo Zhao
From: Toke Høiland-Jørgensen <[email protected]>
This switches the airtime scheduler in mac80211 to use a virtual time-based scheduler instead of the round-robin scheduler used before. This has a couple of advantages:
- No need to sync up the round-robin scheduler in
firmware/hardwarewith
the round-robin airtime scheduler.- If several stations are eligible for transmission we can schedule both of
them; no need to hard-block the scheduling rotation until the head
of the
queue has used up its quantum.- The check of whether a station is eligible for transmission becomes simpler (in
ieee80211_txq_may_transmit()).Quoted 8 lines
The drawback is that scheduling becomes slightly more expensive, as we need to maintain an rbtree of TXQs sorted by virtual time. This means that
ieee80211_register_airtime()becomes O(logN) in the number of currently scheduled TXQs. However, hopefully this number rarely grows too big (it's only TXQs currently backlogged, not all associated stations), so it shouldn't be too big of an issue.Signed-off-by Toke Høiland-Jørgensen <[email protected]>I'll note that this patch still has the two issues that Felix pointed out when I posted the RFC version. Namely:
- The use of divisions in the fast path. I guess I need to go write some
reciprocal-calculation code, since that is also an issue with the AQL patches I linked to before.
Quoted 8 lines
- The fact that we don't count the airtime usage of multicast traffic, which with this series means that the vif TXQ will get priority over the others. I think we agreed to fix this by just adding an airtime
v_tto the vif as well and use that for scheduling the TXQ. Does ath10k report airtime usage for multicast as well, or only for stations?
I remember we have Felix' patches reducing the time the lock is held in mac80211 for DRR, do we need to integrate it into this version?
Quoted 1 line
-Toke
Signature · 1 line
Yibo