Skip to content

Commit 484a54c

Browse files
tohojojmberg-intel
authored andcommitted
mac80211: Dynamically set CoDel parameters per station
CoDel can be too aggressive if a station sends at a very low rate, leading reduced throughput. This gets worse the more stations are present, as each station gets more bursty the longer the round-robin scheduling between stations takes. This adds dynamic adjustment of CoDel parameters per station. It uses the rate selection information to estimate throughput and sets more lenient CoDel parameters if the estimated throughput is below a threshold (modified by the number of active stations). A new callback is added that drivers can use to notify mac80211 about changes in expected throughput, so the same adjustment can be made for cards that implement rate control in firmware. Drivers that don't use this will just get the default parameters. Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk> [remove currently unnecessary EXPORT_SYMBOL, fix kernel-doc, remove inline annotation] Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent ca8fe25 commit 484a54c

6 files changed

Lines changed: 73 additions & 2 deletions

File tree

‎include/net/mac80211.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4204,6 +4204,22 @@ void ieee80211_get_tx_rates(struct ieee80211_vif *vif,
42044204
struct ieee80211_tx_rate *dest,
42054205
int max_rates);
42064206

4207+
/**
4208+
* ieee80211_sta_set_expected_throughput - set the expected tpt for a station
4209+
*
4210+
* Call this function to notify mac80211 about a change in expected throughput
4211+
* to a station. A driver for a device that does rate control in firmware can
4212+
* call this function when the expected throughput estimate towards a station
4213+
* changes. The information is used to tune the CoDel AQM applied to traffic
4214+
* going towards that station (which can otherwise be too aggressive and cause
4215+
* slow stations to starve).
4216+
*
4217+
* @pubsta: the station to set throughput for.
4218+
* @thr: the current expected throughput in kbps.
4219+
*/
4220+
void ieee80211_sta_set_expected_throughput(struct ieee80211_sta *pubsta,
4221+
u32 thr);
4222+
42074223
/**
42084224
* ieee80211_tx_status - transmit status callback
42094225
*

‎net/mac80211/debugfs_sta.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ static ssize_t sta_aqm_read(struct file *file, char __user *userbuf,
152152
spin_lock_bh(&local->fq.lock);
153153
rcu_read_lock();
154154

155+
p += scnprintf(p,
156+
bufsz+buf-p,
157+
"target %uus interval %uus ecn %s\n",
158+
codel_time_to_us(sta->cparams.target),
159+
codel_time_to_us(sta->cparams.interval),
160+
sta->cparams.ecn ? "yes" : "no");
155161
p += scnprintf(p,
156162
bufsz+buf-p,
157163
"tid ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n");

‎net/mac80211/rate.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,8 @@ int rate_control_set_rates(struct ieee80211_hw *hw,
943943

944944
drv_sta_rate_tbl_update(hw_to_local(hw), sta->sdata, pubsta);
945945

946+
ieee80211_sta_set_expected_throughput(pubsta, sta_get_expected_throughput(sta));
947+
946948
return 0;
947949
}
948950
EXPORT_SYMBOL(rate_control_set_rates);
@@ -991,4 +993,3 @@ void rate_control_deinitialize(struct ieee80211_local *local)
991993
local->rate_ctrl = NULL;
992994
rate_control_free(local, ref);
993995
}
994-

‎net/mac80211/sta_info.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/timer.h>
2121
#include <linux/rtnetlink.h>
2222

23+
#include <net/codel.h>
2324
#include <net/mac80211.h>
2425
#include "ieee80211_i.h"
2526
#include "driver-ops.h"
@@ -425,6 +426,11 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
425426

426427
sta->sta.max_rc_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_BA;
427428

429+
sta->cparams.ce_threshold = CODEL_DISABLED_THRESHOLD;
430+
sta->cparams.target = MS2TIME(20);
431+
sta->cparams.interval = MS2TIME(100);
432+
sta->cparams.ecn = true;
433+
428434
sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
429435

430436
return sta;
@@ -2310,3 +2316,27 @@ unsigned long ieee80211_sta_last_active(struct sta_info *sta)
23102316
return stats->last_rx;
23112317
return sta->status_stats.last_ack;
23122318
}
2319+
2320+
static void sta_update_codel_params(struct sta_info *sta, u32 thr)
2321+
{
2322+
if (!sta->sdata->local->ops->wake_tx_queue)
2323+
return;
2324+
2325+
if (thr && thr < STA_SLOW_THRESHOLD * sta->local->num_sta) {
2326+
sta->cparams.target = MS2TIME(50);
2327+
sta->cparams.interval = MS2TIME(300);
2328+
sta->cparams.ecn = false;
2329+
} else {
2330+
sta->cparams.target = MS2TIME(20);
2331+
sta->cparams.interval = MS2TIME(100);
2332+
sta->cparams.ecn = true;
2333+
}
2334+
}
2335+
2336+
void ieee80211_sta_set_expected_throughput(struct ieee80211_sta *pubsta,
2337+
u32 thr)
2338+
{
2339+
struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2340+
2341+
sta_update_codel_params(sta, thr);
2342+
}

‎net/mac80211/sta_info.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,14 @@ struct ieee80211_sta_rx_stats {
393393
u64 msdu[IEEE80211_NUM_TIDS + 1];
394394
};
395395

396+
/**
397+
* The bandwidth threshold below which the per-station CoDel parameters will be
398+
* scaled to be more lenient (to prevent starvation of slow stations). This
399+
* value will be scaled by the number of active stations when it is being
400+
* applied.
401+
*/
402+
#define STA_SLOW_THRESHOLD 6000 /* 6 Mbps */
403+
396404
/**
397405
* struct sta_info - STA information
398406
*
@@ -446,6 +454,7 @@ struct ieee80211_sta_rx_stats {
446454
* @known_smps_mode: the smps_mode the client thinks we are in. Relevant for
447455
* AP only.
448456
* @cipher_scheme: optional cipher scheme for this station
457+
* @cparams: CoDel parameters for this station.
449458
* @reserved_tid: reserved TID (if any, otherwise IEEE80211_TID_UNRESERVED)
450459
* @fast_tx: TX fastpath information
451460
* @fast_rx: RX fastpath information
@@ -549,6 +558,8 @@ struct sta_info {
549558
enum ieee80211_smps_mode known_smps_mode;
550559
const struct ieee80211_cipher_scheme *cipher_scheme;
551560

561+
struct codel_params cparams;
562+
552563
u8 reserved_tid;
553564

554565
struct cfg80211_chan_def tdls_chandef;

‎net/mac80211/tx.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,9 +1340,16 @@ static struct sk_buff *fq_tin_dequeue_func(struct fq *fq,
13401340

13411341
local = container_of(fq, struct ieee80211_local, fq);
13421342
txqi = container_of(tin, struct txq_info, tin);
1343-
cparams = &local->cparams;
13441343
cstats = &txqi->cstats;
13451344

1345+
if (txqi->txq.sta) {
1346+
struct sta_info *sta = container_of(txqi->txq.sta,
1347+
struct sta_info, sta);
1348+
cparams = &sta->cparams;
1349+
} else {
1350+
cparams = &local->cparams;
1351+
}
1352+
13461353
if (flow == &txqi->def_flow)
13471354
cvars = &txqi->def_cvars;
13481355
else

0 commit comments

Comments
 (0)