320-mac80211-Add-TXQ-scheduling-API.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= <toke@toke.dk>
  2. Date: Tue, 18 Dec 2018 17:02:06 -0800
  3. Subject: [PATCH] mac80211: Add TXQ scheduling API
  4. MIME-Version: 1.0
  5. Content-Type: text/plain; charset=UTF-8
  6. Content-Transfer-Encoding: 8bit
  7. This adds an API to mac80211 to handle scheduling of TXQs. The interface
  8. between driver and mac80211 for TXQ handling is changed by adding two new
  9. functions: ieee80211_next_txq(), which will return the next TXQ to schedule
  10. in the current round-robin rotation, and ieee80211_return_txq(), which the
  11. driver uses to indicate that it has finished scheduling a TXQ (which will
  12. then be put back in the scheduling rotation if it isn't empty).
  13. The driver must call ieee80211_txq_schedule_start() at the start of each
  14. scheduling session, and ieee80211_txq_schedule_end() at the end. The API
  15. then guarantees that the same TXQ is not returned twice in the same
  16. session (so a driver can loop on ieee80211_next_txq() without worrying
  17. about breaking the loop.
  18. Usage of the new API is optional, so drivers can be ported one at a time.
  19. In this patch, the actual scheduling performed by mac80211 is simple
  20. round-robin, but a subsequent commit adds airtime fairness awareness to the
  21. scheduler.
  22. Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
  23. [minor kernel-doc fix, propagate sparse locking checks out]
  24. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  25. ---
  26. --- a/include/net/mac80211.h
  27. +++ b/include/net/mac80211.h
  28. @@ -107,9 +107,15 @@
  29. * The driver is expected to initialize its private per-queue data for stations
  30. * and interfaces in the .add_interface and .sta_add ops.
  31. *
  32. - * The driver can't access the queue directly. To dequeue a frame, it calls
  33. - * ieee80211_tx_dequeue(). Whenever mac80211 adds a new frame to a queue, it
  34. - * calls the .wake_tx_queue driver op.
  35. + * The driver can't access the queue directly. To dequeue a frame from a
  36. + * txq, it calls ieee80211_tx_dequeue(). Whenever mac80211 adds a new frame to a
  37. + * queue, it calls the .wake_tx_queue driver op.
  38. + *
  39. + * Drivers can optionally delegate responsibility for scheduling queues to
  40. + * mac80211, to take advantage of airtime fairness accounting. In this case, to
  41. + * obtain the next queue to pull frames from, the driver calls
  42. + * ieee80211_next_txq(). The driver is then expected to return the txq using
  43. + * ieee80211_return_txq().
  44. *
  45. * For AP powersave TIM handling, the driver only needs to indicate if it has
  46. * buffered packets in the driver specific data structures by calling
  47. @@ -5979,7 +5985,8 @@ void ieee80211_unreserve_tid(struct ieee
  48. * ieee80211_tx_dequeue - dequeue a packet from a software tx queue
  49. *
  50. * @hw: pointer as obtained from ieee80211_alloc_hw()
  51. - * @txq: pointer obtained from station or virtual interface
  52. + * @txq: pointer obtained from station or virtual interface, or from
  53. + * ieee80211_next_txq()
  54. *
  55. * Returns the skb if successful, %NULL if no frame was available.
  56. */
  57. @@ -5987,6 +5994,54 @@ struct sk_buff *ieee80211_tx_dequeue(str
  58. struct ieee80211_txq *txq);
  59. /**
  60. + * ieee80211_next_txq - get next tx queue to pull packets from
  61. + *
  62. + * @hw: pointer as obtained from ieee80211_alloc_hw()
  63. + * @ac: AC number to return packets from.
  64. + *
  65. + * Should only be called between calls to ieee80211_txq_schedule_start()
  66. + * and ieee80211_txq_schedule_end().
  67. + * Returns the next txq if successful, %NULL if no queue is eligible. If a txq
  68. + * is returned, it should be returned with ieee80211_return_txq() after the
  69. + * driver has finished scheduling it.
  70. + */
  71. +struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac);
  72. +
  73. +/**
  74. + * ieee80211_return_txq - return a TXQ previously acquired by ieee80211_next_txq()
  75. + *
  76. + * @hw: pointer as obtained from ieee80211_alloc_hw()
  77. + * @txq: pointer obtained from station or virtual interface
  78. + *
  79. + * Should only be called between calls to ieee80211_txq_schedule_start()
  80. + * and ieee80211_txq_schedule_end().
  81. + */
  82. +void ieee80211_return_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq);
  83. +
  84. +/**
  85. + * ieee80211_txq_schedule_start - acquire locks for safe scheduling of an AC
  86. + *
  87. + * @hw: pointer as obtained from ieee80211_alloc_hw()
  88. + * @ac: AC number to acquire locks for
  89. + *
  90. + * Acquire locks needed to schedule TXQs from the given AC. Should be called
  91. + * before ieee80211_next_txq() or ieee80211_return_txq().
  92. + */
  93. +void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac)
  94. + __acquires(txq_lock);
  95. +
  96. +/**
  97. + * ieee80211_txq_schedule_end - release locks for safe scheduling of an AC
  98. + *
  99. + * @hw: pointer as obtained from ieee80211_alloc_hw()
  100. + * @ac: AC number to acquire locks for
  101. + *
  102. + * Release locks previously acquired by ieee80211_txq_schedule_end().
  103. + */
  104. +void ieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac)
  105. + __releases(txq_lock);
  106. +
  107. +/**
  108. * ieee80211_txq_get_depth - get pending frame/byte count of given txq
  109. *
  110. * The values are not guaranteed to be coherent with regard to each other, i.e.
  111. --- a/net/mac80211/agg-tx.c
  112. +++ b/net/mac80211/agg-tx.c
  113. @@ -229,7 +229,7 @@ ieee80211_agg_start_txq(struct sta_info
  114. clear_bit(IEEE80211_TXQ_STOP, &txqi->flags);
  115. local_bh_disable();
  116. rcu_read_lock();
  117. - drv_wake_tx_queue(sta->sdata->local, txqi);
  118. + schedule_and_wake_txq(sta->sdata->local, txqi);
  119. rcu_read_unlock();
  120. local_bh_enable();
  121. }
  122. --- a/net/mac80211/driver-ops.h
  123. +++ b/net/mac80211/driver-ops.h
  124. @@ -1176,6 +1176,15 @@ static inline void drv_wake_tx_queue(str
  125. local->ops->wake_tx_queue(&local->hw, &txq->txq);
  126. }
  127. +static inline void schedule_and_wake_txq(struct ieee80211_local *local,
  128. + struct txq_info *txqi)
  129. +{
  130. + spin_lock_bh(&local->active_txq_lock[txqi->txq.ac]);
  131. + ieee80211_return_txq(&local->hw, &txqi->txq);
  132. + spin_unlock_bh(&local->active_txq_lock[txqi->txq.ac]);
  133. + drv_wake_tx_queue(local, txqi);
  134. +}
  135. +
  136. static inline int drv_start_nan(struct ieee80211_local *local,
  137. struct ieee80211_sub_if_data *sdata,
  138. struct cfg80211_nan_conf *conf)
  139. --- a/net/mac80211/ieee80211_i.h
  140. +++ b/net/mac80211/ieee80211_i.h
  141. @@ -829,6 +829,8 @@ enum txq_info_flags {
  142. * a fq_flow which is already owned by a different tin
  143. * @def_cvars: codel vars for @def_flow
  144. * @frags: used to keep fragments created after dequeue
  145. + * @schedule_order: used with ieee80211_local->active_txqs
  146. + * @schedule_round: counter to prevent infinite loops on TXQ scheduling
  147. */
  148. struct txq_info {
  149. struct fq_tin tin;
  150. @@ -836,6 +838,8 @@ struct txq_info {
  151. struct codel_vars def_cvars;
  152. struct codel_stats cstats;
  153. struct sk_buff_head frags;
  154. + struct list_head schedule_order;
  155. + u16 schedule_round;
  156. unsigned long flags;
  157. /* keep last! */
  158. @@ -1127,6 +1131,11 @@ struct ieee80211_local {
  159. struct codel_vars *cvars;
  160. struct codel_params cparams;
  161. + /* protects active_txqs and txqi->schedule_order */
  162. + spinlock_t active_txq_lock[IEEE80211_NUM_ACS];
  163. + struct list_head active_txqs[IEEE80211_NUM_ACS];
  164. + u16 schedule_round[IEEE80211_NUM_ACS];
  165. +
  166. const struct ieee80211_ops *ops;
  167. /*
  168. --- a/net/mac80211/main.c
  169. +++ b/net/mac80211/main.c
  170. @@ -652,6 +652,11 @@ struct ieee80211_hw *ieee80211_alloc_hw_
  171. spin_lock_init(&local->rx_path_lock);
  172. spin_lock_init(&local->queue_stop_reason_lock);
  173. + for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  174. + INIT_LIST_HEAD(&local->active_txqs[i]);
  175. + spin_lock_init(&local->active_txq_lock[i]);
  176. + }
  177. +
  178. INIT_LIST_HEAD(&local->chanctx_list);
  179. mutex_init(&local->chanctx_mtx);
  180. --- a/net/mac80211/sta_info.c
  181. +++ b/net/mac80211/sta_info.c
  182. @@ -1249,7 +1249,7 @@ void ieee80211_sta_ps_deliver_wakeup(str
  183. if (!txq_has_queue(sta->sta.txq[i]))
  184. continue;
  185. - drv_wake_tx_queue(local, to_txq_info(sta->sta.txq[i]));
  186. + schedule_and_wake_txq(local, to_txq_info(sta->sta.txq[i]));
  187. }
  188. }
  189. --- a/net/mac80211/tx.c
  190. +++ b/net/mac80211/tx.c
  191. @@ -1441,6 +1441,7 @@ void ieee80211_txq_init(struct ieee80211
  192. codel_vars_init(&txqi->def_cvars);
  193. codel_stats_init(&txqi->cstats);
  194. __skb_queue_head_init(&txqi->frags);
  195. + INIT_LIST_HEAD(&txqi->schedule_order);
  196. txqi->txq.vif = &sdata->vif;
  197. @@ -1464,6 +1465,9 @@ void ieee80211_txq_purge(struct ieee8021
  198. fq_tin_reset(fq, tin, fq_skb_free_func);
  199. ieee80211_purge_tx_queue(&local->hw, &txqi->frags);
  200. + spin_lock_bh(&local->active_txq_lock[txqi->txq.ac]);
  201. + list_del_init(&txqi->schedule_order);
  202. + spin_unlock_bh(&local->active_txq_lock[txqi->txq.ac]);
  203. }
  204. void ieee80211_txq_set_params(struct ieee80211_local *local)
  205. @@ -1580,7 +1584,7 @@ static bool ieee80211_queue_skb(struct i
  206. ieee80211_txq_enqueue(local, txqi, skb);
  207. spin_unlock_bh(&fq->lock);
  208. - drv_wake_tx_queue(local, txqi);
  209. + schedule_and_wake_txq(local, txqi);
  210. return true;
  211. }
  212. @@ -3620,6 +3624,60 @@ out:
  213. }
  214. EXPORT_SYMBOL(ieee80211_tx_dequeue);
  215. +struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac)
  216. +{
  217. + struct ieee80211_local *local = hw_to_local(hw);
  218. + struct txq_info *txqi = NULL;
  219. +
  220. + lockdep_assert_held(&local->active_txq_lock[ac]);
  221. +
  222. + txqi = list_first_entry_or_null(&local->active_txqs[ac],
  223. + struct txq_info,
  224. + schedule_order);
  225. +
  226. + if (!txqi || txqi->schedule_round == local->schedule_round[ac])
  227. + return NULL;
  228. +
  229. + list_del_init(&txqi->schedule_order);
  230. + txqi->schedule_round = local->schedule_round[ac];
  231. + return &txqi->txq;
  232. +}
  233. +EXPORT_SYMBOL(ieee80211_next_txq);
  234. +
  235. +void ieee80211_return_txq(struct ieee80211_hw *hw,
  236. + struct ieee80211_txq *txq)
  237. +{
  238. + struct ieee80211_local *local = hw_to_local(hw);
  239. + struct txq_info *txqi = to_txq_info(txq);
  240. +
  241. + lockdep_assert_held(&local->active_txq_lock[txq->ac]);
  242. +
  243. + if (list_empty(&txqi->schedule_order) &&
  244. + (!skb_queue_empty(&txqi->frags) || txqi->tin.backlog_packets))
  245. + list_add_tail(&txqi->schedule_order,
  246. + &local->active_txqs[txq->ac]);
  247. +}
  248. +EXPORT_SYMBOL(ieee80211_return_txq);
  249. +
  250. +void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac)
  251. + __acquires(txq_lock)
  252. +{
  253. + struct ieee80211_local *local = hw_to_local(hw);
  254. +
  255. + spin_lock_bh(&local->active_txq_lock[ac]);
  256. + local->schedule_round[ac]++;
  257. +}
  258. +EXPORT_SYMBOL(ieee80211_txq_schedule_start);
  259. +
  260. +void ieee80211_txq_schedule_end(struct ieee80211_hw *hw, u8 ac)
  261. + __releases(txq_lock)
  262. +{
  263. + struct ieee80211_local *local = hw_to_local(hw);
  264. +
  265. + spin_unlock_bh(&local->active_txq_lock[ac]);
  266. +}
  267. +EXPORT_SYMBOL(ieee80211_txq_schedule_end);
  268. +
  269. void __ieee80211_subif_start_xmit(struct sk_buff *skb,
  270. struct net_device *dev,
  271. u32 info_flags,