From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.bufferbloat.net (Postfix) with ESMTPS id 73AF13B29D for ; Sun, 22 Dec 2019 12:25:01 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577035500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Gt0Paw+OLCtPOX226jq6XLEC6u2LRuV7/cQ/9LEuYrw=; b=fmQUtYHmrYCCTEuYJh8uTBmZnhYSogWHQgdcAluh83e93EPbE7vlX1szfMnNj/C/kN4Kat SU95/K6lWjI9jo3IXiIS3ezWsGl+oV0mxWnxs63iYyElBsfwjYMufzlpOdp2Gd78f/TDGG DC/2o/zo8bovbcDNrGWRN3q+i788UWM= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-205-9AvzxK0wPD2dU8bdasIQDQ-1; Sun, 22 Dec 2019 12:24:58 -0500 Received: by mail-lf1-f69.google.com with SMTP id h7so2034969lfp.20 for ; Sun, 22 Dec 2019 09:24:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=V6kWaCSmmH3ZHsWUhH6jdUYKwkQn9Eo3jAjEgUnGAIM=; b=fNR/Wzx/pkzbjXptv2JMHH/24thTnol4KwScP3torN+gPeImwDouoMx7TgiCs9vTna YFExXAqDiiEnv6XL1i2Trr6x5p9QEd+80jnBBpf1ezMVY4S7JCgw+h3lyU3MG0EcVSo9 82k6PvAE3BDKvDzIhkhLXwrKEUpZAljLSAlMq7ACvAjWShS1HaADG/QERg8FLGKNWZJt CZasbNRJScALMrfhAJBPbyAgae2Pn8NHtO6IkElGvPsrSH36eq/mFxptiQVRvfbwijLi CqRp9pQEOmVHazL61hoJ/YjD5Up5eiqiCsuMyMVJ9uRpXMyIoth18BAmhBRqh1Af00Qc teaw== X-Gm-Message-State: APjAAAVTwPEw8sk8BqGF2NRhDIAh/xveIjZS/wq19RFexvJA4l8cmSjr W897mdrdl2P6UvOR4HukgYCHQpNjupPIwak1g8NSDTVFaI+NKs8n4dA80rb8EW3tjKblJYYf1EA D+lRSMD/fQe3VZ7/f79xU+kRhS5nIPIaAUMQ= X-Received: by 2002:ac2:4553:: with SMTP id j19mr15161760lfm.142.1577035496696; Sun, 22 Dec 2019 09:24:56 -0800 (PST) X-Google-Smtp-Source: APXvYqxL16QDaCrfcTfEF7bZttd1NTKunostnLbWnG7YytJ/yx3QTTPHCho0ycZ7DyqVP3jiLw8qxw== X-Received: by 2002:ac2:4553:: with SMTP id j19mr15161744lfm.142.1577035495910; Sun, 22 Dec 2019 09:24:55 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id t81sm6892667lff.25.2019.12.22.09.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Dec 2019 09:24:55 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id E4391180979; Sun, 22 Dec 2019 18:24:48 +0100 (CET) From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= To: linux-wireless@vger.kernel.org Cc: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Felix Fietkau , Rajkumar Manoharan , Kan Yan , make-wifi-fast@lists.bufferbloat.net, Yibo Zhao Date: Sun, 22 Dec 2019 18:24:23 +0100 Message-Id: <20191222172423.131033-1-toke@redhat.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-MC-Unique: 9AvzxK0wPD2dU8bdasIQDQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Make-wifi-fast] [PATCH v5] mac80211: Switch to a virtual time-based airtime scheduler X-BeenThere: make-wifi-fast@lists.bufferbloat.net X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Dec 2019 17:25:01 -0000 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. Co-developed-by: Yibo Zhao Signed-off-by: Yibo Zhao Signed-off-by: Toke H=C3=B8iland-J=C3=B8rgensen --- This version resolves the two outstanding issues Felix pointed out back at the RFC: The risk that the vif TXQ will always be scheduled first, and the division in the fast path. This means that as far as I'm concerned, this patch is now "feature complete". Didn't have a chance to do anything other than compile-test it yet, but wanted to get it out before the holidays (which I almost managed, since technically my holiday started two days ago)... Full changelog: Changes since v4: Rebase on latest mac80211-next. Squash everything into a single patch again, and add back Yibo's co-developed-by tag and signoff. Move all the per-ac airtime-related data into separate structs. Use pre-calculated reciprocals to avoid divisions in the fast path. Record airtime usage for the vif TXQ to avoid it always being scheduled first. Changes since v3: Change schedule_pos to previous node once it has chance to be moved/remov= ed from current position in the tree in loop scenario and bring back schedul= e_round in case that same node is to be scheduled again in the mean time. Increase airtime grace period to 2000 us in the first patch. Put per-AC station weight checking in its lock during configuration from = application. Changes since v2: Changes station airtime weight to be per-AC based to avoid sync issue Remove Co-developed-by and Toke's sign-off as Toke suggested Changes since v1: Modify the author of Co-developed-by as Johannes suggested include/net/mac80211.h | 17 +-- net/mac80211/cfg.c | 30 +++- net/mac80211/debugfs.c | 72 +++++++-- net/mac80211/debugfs_sta.c | 24 +-- net/mac80211/ieee80211_i.h | 73 ++++++++- net/mac80211/iface.c | 3 + net/mac80211/main.c | 10 +- net/mac80211/rx.c | 6 +- net/mac80211/sta_info.c | 69 ++++++--- net/mac80211/sta_info.h | 13 +- net/mac80211/status.c | 17 +++ net/mac80211/tx.c | 296 +++++++++++++++++++++++-------------- 12 files changed, 438 insertions(+), 192 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 682fd2f4431b..4e9ef0fe294f 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -6362,9 +6362,6 @@ static inline void ieee80211_txq_schedule_end(struct = ieee80211_hw *hw, u8 ac) { } =20 -void __ieee80211_schedule_txq(struct ieee80211_hw *hw, -=09=09=09 struct ieee80211_txq *txq, bool force); - /** * ieee80211_schedule_txq - schedule a TXQ for transmission * @@ -6377,11 +6374,7 @@ void __ieee80211_schedule_txq(struct ieee80211_hw *h= w, * The driver may call this function if it has buffered packets for * this TXQ internally. */ -static inline void -ieee80211_schedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq) -{ -=09__ieee80211_schedule_txq(hw, txq, true); -} +void ieee80211_schedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq = *txq); =20 /** * ieee80211_return_txq - return a TXQ previously acquired by ieee80211_ne= xt_txq() @@ -6393,12 +6386,8 @@ ieee80211_schedule_txq(struct ieee80211_hw *hw, stru= ct ieee80211_txq *txq) * The driver may set force=3Dtrue if it has buffered packets for this TXQ * internally. */ -static inline void -ieee80211_return_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq, -=09=09 bool force) -{ -=09__ieee80211_schedule_txq(hw, txq, force); -} +void ieee80211_return_txq(struct ieee80211_hw *hw, struct ieee80211_txq *t= xq, +=09=09=09 bool force); =20 /** * ieee80211_txq_may_transmit - check whether TXQ is allowed to transmit diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 4fb7f1f12109..9ce05740bcf0 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -1333,7 +1333,8 @@ static int sta_apply_parameters(struct ieee80211_loca= l *local, =09int ret =3D 0; =09struct ieee80211_supported_band *sband; =09struct ieee80211_sub_if_data *sdata =3D sta->sdata; -=09u32 mask, set; +=09u32 mask, set, tid, ac, old_weight; +=09struct txq_info *txqi; =20 =09sband =3D ieee80211_get_sband(sdata); =09if (!sband) @@ -1510,8 +1511,31 @@ static int sta_apply_parameters(struct ieee80211_loc= al *local, =09if (ieee80211_vif_is_mesh(&sdata->vif)) =09=09sta_apply_mesh_params(local, sta, params); =20 -=09if (params->airtime_weight) -=09=09sta->airtime_weight =3D params->airtime_weight; +=09if (params->airtime_weight) { +=09=09for (ac =3D 0; ac < IEEE80211_NUM_ACS; ac++) { +=09=09=09struct airtime_sched_info *air_sched =3D &local->airtime[ac]; +=09=09=09struct airtime_info *air_info =3D &sta->airtime[ac]; + +=09=09=09spin_lock_bh(&air_sched->lock); +=09=09=09for (tid =3D 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { +=09=09=09=09if (air_info->weight =3D=3D params->airtime_weight || +=09=09=09=09 !sta->sta.txq[tid] || +=09=09=09=09 ac !=3D ieee80211_ac_from_tid(tid)) +=09=09=09=09=09continue; + +=09=09=09=09old_weight =3D air_info->weight; +=09=09=09=09airtime_weight_set(air_info, params->airtime_weight); + +=09=09=09=09txqi =3D to_txq_info(sta->sta.txq[tid]); +=09=09=09=09if (RB_EMPTY_NODE(&txqi->schedule_order)) +=09=09=09=09=09continue; + +=09=09=09=09airtime_weight_add(air_sched, +=09=09=09=09=09=09 params->airtime_weight - old_weight); +=09=09=09} +=09=09=09spin_unlock_bh(&air_sched->lock); +=09=09} +=09} =20 =09/* set the STA state after all sta info from usermode has been set */ =09if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) || diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c index ad41d74530c6..7c55d12466c4 100644 --- a/net/mac80211/debugfs.c +++ b/net/mac80211/debugfs.c @@ -165,14 +165,14 @@ static ssize_t aql_txq_limit_read(struct file *file, =09=09=09"VI=09%u=09=09%u\n" =09=09=09"BE=09%u=09=09%u\n" =09=09=09"BK=09%u=09=09%u\n", -=09=09=09local->aql_txq_limit_low[IEEE80211_AC_VO], -=09=09=09local->aql_txq_limit_high[IEEE80211_AC_VO], -=09=09=09local->aql_txq_limit_low[IEEE80211_AC_VI], -=09=09=09local->aql_txq_limit_high[IEEE80211_AC_VI], -=09=09=09local->aql_txq_limit_low[IEEE80211_AC_BE], -=09=09=09local->aql_txq_limit_high[IEEE80211_AC_BE], -=09=09=09local->aql_txq_limit_low[IEEE80211_AC_BK], -=09=09=09local->aql_txq_limit_high[IEEE80211_AC_BK]); +=09=09=09local->airtime[IEEE80211_AC_VO].aql_txq_limit_low, +=09=09=09local->airtime[IEEE80211_AC_VO].aql_txq_limit_high, +=09=09=09local->airtime[IEEE80211_AC_VI].aql_txq_limit_low, +=09=09=09local->airtime[IEEE80211_AC_VI].aql_txq_limit_high, +=09=09=09local->airtime[IEEE80211_AC_BE].aql_txq_limit_low, +=09=09=09local->airtime[IEEE80211_AC_BE].aql_txq_limit_high, +=09=09=09local->airtime[IEEE80211_AC_BK].aql_txq_limit_low, +=09=09=09local->airtime[IEEE80211_AC_BK].aql_txq_limit_high); =09return simple_read_from_buffer(user_buf, count, ppos, =09=09=09=09 buf, len); } @@ -205,11 +205,11 @@ static ssize_t aql_txq_limit_write(struct file *file, =09if (ac >=3D IEEE80211_NUM_ACS) =09=09return -EINVAL; =20 -=09q_limit_low_old =3D local->aql_txq_limit_low[ac]; -=09q_limit_high_old =3D local->aql_txq_limit_high[ac]; +=09q_limit_low_old =3D local->airtime[ac].aql_txq_limit_low; +=09q_limit_high_old =3D local->airtime[ac].aql_txq_limit_high; =20 -=09local->aql_txq_limit_low[ac] =3D q_limit_low; -=09local->aql_txq_limit_high[ac] =3D q_limit_high; +=09local->airtime[ac].aql_txq_limit_low =3D q_limit_low; +=09local->airtime[ac].aql_txq_limit_high =3D q_limit_high; =20 =09mutex_lock(&local->sta_mtx); =09list_for_each_entry(sta, &local->sta_list, list) { @@ -283,6 +283,46 @@ static const struct file_operations force_tx_status_op= s =3D { =09.llseek =3D default_llseek, }; =20 +static ssize_t airtime_read(struct file *file, +=09=09=09 char __user *user_buf, +=09=09=09 size_t count, +=09=09=09 loff_t *ppos) +{ +=09struct ieee80211_local *local =3D file->private_data; +=09char buf[200]; +=09u64 v_t[IEEE80211_NUM_ACS]; +=09u64 wt[IEEE80211_NUM_ACS]; +=09int len =3D 0, ac; + +=09for (ac =3D 0; ac < IEEE80211_NUM_ACS; ac++) { +=09=09spin_lock_bh(&local->airtime[ac].lock); +=09=09v_t[ac] =3D local->airtime[ac].v_t; +=09=09wt[ac] =3D local->airtime[ac].weight_sum; +=09=09spin_unlock_bh(&local->airtime[ac].lock); +=09} +=09len =3D scnprintf(buf, sizeof(buf), +=09=09=09"\tVO VI BE BK\n" +=09=09=09"Virt-t\t%-10llu %-10llu %-10llu %-10llu\n" +=09=09=09"Weight\t%-10llu %-10llu %-10llu %-10llu\n", +=09=09=09v_t[0], +=09=09=09v_t[1], +=09=09=09v_t[2], +=09=09=09v_t[3], +=09=09=09wt[0], +=09=09=09wt[1], +=09=09=09wt[2], +=09=09=09wt[3]); + +=09return simple_read_from_buffer(user_buf, count, ppos, +=09=09=09=09 buf, len); +} + +static const struct file_operations airtime_ops =3D { +=09.read =3D airtime_read, +=09.open =3D simple_open, +=09.llseek =3D default_llseek, +}; + #ifdef CONFIG_PM static ssize_t reset_write(struct file *file, const char __user *user_buf, =09=09=09 size_t count, loff_t *ppos) @@ -522,8 +562,12 @@ void debugfs_hw_add(struct ieee80211_local *local) =09if (local->ops->wake_tx_queue) =09=09DEBUGFS_ADD_MODE(aqm, 0600); =20 -=09debugfs_create_u16("airtime_flags", 0600, -=09=09=09 phyd, &local->airtime_flags); +=09if (wiphy_ext_feature_isset(local->hw.wiphy, +=09=09=09=09 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) { +=09=09DEBUGFS_ADD_MODE(airtime, 0600); +=09=09debugfs_create_u16("airtime_flags", 0600, +=09=09=09=09 phyd, &local->airtime_flags); +=09} =20 =09DEBUGFS_ADD(aql_txq_limit); =09debugfs_create_u32("aql_threshold", 0600, diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c index 266d63819415..40df93b32c66 100644 --- a/net/mac80211/debugfs_sta.c +++ b/net/mac80211/debugfs_sta.c @@ -200,7 +200,7 @@ static ssize_t sta_airtime_read(struct file *file, char= __user *userbuf, =09size_t bufsz =3D 400; =09char *buf =3D kzalloc(bufsz, GFP_KERNEL), *p =3D buf; =09u64 rx_airtime =3D 0, tx_airtime =3D 0; -=09s64 deficit[IEEE80211_NUM_ACS]; +=09u64 v_t[IEEE80211_NUM_ACS]; =09ssize_t rv; =09int ac; =20 @@ -208,18 +208,18 @@ static ssize_t sta_airtime_read(struct file *file, ch= ar __user *userbuf, =09=09return -ENOMEM; =20 =09for (ac =3D 0; ac < IEEE80211_NUM_ACS; ac++) { -=09=09spin_lock_bh(&local->active_txq_lock[ac]); +=09=09spin_lock_bh(&local->airtime[ac].lock); =09=09rx_airtime +=3D sta->airtime[ac].rx_airtime; =09=09tx_airtime +=3D sta->airtime[ac].tx_airtime; -=09=09deficit[ac] =3D sta->airtime[ac].deficit; -=09=09spin_unlock_bh(&local->active_txq_lock[ac]); +=09=09v_t[ac] =3D sta->airtime[ac].v_t; +=09=09spin_unlock_bh(&local->airtime[ac].lock); =09} =20 =09p +=3D scnprintf(p, bufsz + buf - p, =09=09"RX: %llu us\nTX: %llu us\nWeight: %u\n" -=09=09"Deficit: VO: %lld us VI: %lld us BE: %lld us BK: %lld us\n", -=09=09rx_airtime, tx_airtime, sta->airtime_weight, -=09=09deficit[0], deficit[1], deficit[2], deficit[3]); +=09=09"Virt-T: VO: %lld us VI: %lld us BE: %lld us BK: %lld us\n", +=09=09rx_airtime, tx_airtime, sta->airtime[0].weight, +=09=09v_t[0], v_t[1], v_t[2], v_t[3]); =20 =09rv =3D simple_read_from_buffer(userbuf, count, ppos, buf, p - buf); =09kfree(buf); @@ -234,11 +234,11 @@ static ssize_t sta_airtime_write(struct file *file, c= onst char __user *userbuf, =09int ac; =20 =09for (ac =3D 0; ac < IEEE80211_NUM_ACS; ac++) { -=09=09spin_lock_bh(&local->active_txq_lock[ac]); +=09=09spin_lock_bh(&local->airtime[ac].lock); =09=09sta->airtime[ac].rx_airtime =3D 0; =09=09sta->airtime[ac].tx_airtime =3D 0; -=09=09sta->airtime[ac].deficit =3D sta->airtime_weight; -=09=09spin_unlock_bh(&local->active_txq_lock[ac]); +=09=09sta->airtime[ac].v_t =3D 0; +=09=09spin_unlock_bh(&local->airtime[ac].lock); =09} =20 =09return count; @@ -261,10 +261,10 @@ static ssize_t sta_aql_read(struct file *file, char _= _user *userbuf, =09=09return -ENOMEM; =20 =09for (ac =3D 0; ac < IEEE80211_NUM_ACS; ac++) { -=09=09spin_lock_bh(&local->active_txq_lock[ac]); +=09=09spin_lock_bh(&local->airtime[ac].lock); =09=09q_limit_l[ac] =3D sta->airtime[ac].aql_limit_low; =09=09q_limit_h[ac] =3D sta->airtime[ac].aql_limit_high; -=09=09spin_unlock_bh(&local->active_txq_lock[ac]); +=09=09spin_unlock_bh(&local->airtime[ac].lock); =09=09q_depth[ac] =3D atomic_read(&sta->airtime[ac].aql_tx_pending); =09} =20 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index e3cf24cb4615..db15f6100c2d 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -843,7 +843,7 @@ struct txq_info { =09struct codel_vars def_cvars; =09struct codel_stats cstats; =09struct sk_buff_head frags; -=09struct list_head schedule_order; +=09struct rb_node schedule_order; =09u16 schedule_round; =09unsigned long flags; =20 @@ -919,6 +919,8 @@ struct ieee80211_sub_if_data { =09struct ieee80211_tx_queue_params tx_conf[IEEE80211_NUM_ACS]; =09struct mac80211_qos_map __rcu *qos_map; =20 +=09struct airtime_info airtime[IEEE80211_NUM_ACS]; + =09struct work_struct csa_finalize_work; =09bool csa_block_tx; /* write-protected by sdata_lock and local->mtx */ =09struct cfg80211_chan_def csa_chandef; @@ -1128,6 +1130,18 @@ enum mac80211_scan_state { =09SCAN_ABORT, }; =20 +struct airtime_sched_info { +=09spinlock_t lock; +=09struct rb_root_cached active_txqs; +=09struct rb_node *schedule_pos; +=09u64 v_t; +=09u64 weight_sum; +=09u64 weight_sum_reciprocal; +=09u32 aql_txq_limit_low; +=09u32 aql_txq_limit_high; +=09u16 schedule_round; +}; + struct ieee80211_local { =09/* embed the driver visible part. =09 * don't cast (use the static inlines below), but we keep @@ -1139,13 +1153,8 @@ struct ieee80211_local { =09struct codel_params cparams; =20 =09/* protects active_txqs and txqi->schedule_order */ -=09spinlock_t active_txq_lock[IEEE80211_NUM_ACS]; -=09struct list_head active_txqs[IEEE80211_NUM_ACS]; -=09u16 schedule_round[IEEE80211_NUM_ACS]; - +=09struct airtime_sched_info airtime[IEEE80211_NUM_ACS]; =09u16 airtime_flags; -=09u32 aql_txq_limit_low[IEEE80211_NUM_ACS]; -=09u32 aql_txq_limit_high[IEEE80211_NUM_ACS]; =09u32 aql_threshold; =09atomic_t aql_total_pending_airtime; =20 @@ -1556,6 +1565,52 @@ static inline bool txq_has_queue(struct ieee80211_tx= q *txq) =09return !(skb_queue_empty(&txqi->frags) && !txqi->tin.backlog_packets); } =20 +static inline struct airtime_info *to_airtime_info(struct ieee80211_txq *t= xq) +{ +=09struct ieee80211_sub_if_data *sdata; +=09struct sta_info *sta; + +=09if (txq->sta) { +=09=09sta =3D container_of(txq->sta, struct sta_info, sta); +=09=09return &sta->airtime[txq->ac]; +=09} + +=09sdata =3D vif_to_sdata(txq->vif); +=09return &sdata->airtime[txq->ac]; +} + +static inline void airtime_weight_set(struct airtime_info *air_info, u16 w= eight) +{ +=09air_info->weight =3D weight; +=09if (weight) { +=09=09air_info->weight_reciprocal =3D IEEE80211_RECIPROCAL_DIVISOR; +=09=09do_div(air_info->weight_reciprocal, weight); +=09} else { +=09=09air_info->weight_reciprocal =3D 0; +=09} +} + +static inline void airtime_weight_add(struct airtime_sched_info *air_sched= , +=09=09=09=09 int weight) +{ +=09air_sched->weight_sum +=3D weight; +=09if (air_sched->weight_sum) { +=09=09air_sched->weight_sum_reciprocal =3D IEEE80211_RECIPROCAL_DIVISOR; +=09=09do_div(air_sched->weight_sum_reciprocal, air_sched->weight_sum); +=09} else { +=09=09air_sched->weight_sum_reciprocal =3D 0; +=09} +} + +static inline void init_airtime_info(struct airtime_info *air_info, +=09=09=09=09 struct airtime_sched_info *air_sched) +{ +=09atomic_set(&air_info->aql_tx_pending, 0); +=09air_info->aql_limit_low =3D air_sched->aql_txq_limit_low; +=09air_info->aql_limit_high =3D air_sched->aql_txq_limit_high; +=09airtime_weight_set(air_info, IEEE80211_DEFAULT_AIRTIME_WEIGHT); +} + static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr) { =09return ether_addr_equal(raddr, addr) || @@ -1789,6 +1844,10 @@ int ieee80211_tx_control_port(struct wiphy *wiphy, s= truct net_device *dev, =09=09=09 const u8 *dest, __be16 proto, bool unencrypted); int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev, =09=09=09 const u8 *buf, size_t len); +void ieee80211_resort_txq(struct ieee80211_hw *hw, +=09=09=09 struct ieee80211_txq *txq); +void ieee80211_unschedule_txq(struct ieee80211_hw *hw, +=09=09=09 struct ieee80211_txq *txq); =20 /* HT */ void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata, diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index 9b833e170c20..a0481ea59212 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -1922,6 +1922,9 @@ int ieee80211_if_add(struct ieee80211_local *local, c= onst char *name, =09=09} =09} =20 +=09for (i =3D 0; i < IEEE80211_NUM_ACS; i++) +=09=09init_airtime_info(&sdata->airtime[i], &local->airtime[i]); + =09ieee80211_set_default_queues(sdata); =20 =09sdata->ap_power_level =3D IEEE80211_UNSET_POWER_LEVEL; diff --git a/net/mac80211/main.c b/net/mac80211/main.c index 4c2b5ba3ac09..cf2e6be21b98 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -665,10 +665,12 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t pri= v_data_len, =09spin_lock_init(&local->queue_stop_reason_lock); =20 =09for (i =3D 0; i < IEEE80211_NUM_ACS; i++) { -=09=09INIT_LIST_HEAD(&local->active_txqs[i]); -=09=09spin_lock_init(&local->active_txq_lock[i]); -=09=09local->aql_txq_limit_low[i] =3D IEEE80211_DEFAULT_AQL_TXQ_LIMIT_L; -=09=09local->aql_txq_limit_high[i] =3D +=09=09struct airtime_sched_info *air_sched =3D &local->airtime[i]; + +=09=09air_sched->active_txqs =3D RB_ROOT_CACHED; +=09=09spin_lock_init(&air_sched->lock); +=09=09air_sched->aql_txq_limit_low =3D IEEE80211_DEFAULT_AQL_TXQ_LIMIT_L; +=09=09air_sched->aql_txq_limit_high =3D =09=09=09IEEE80211_DEFAULT_AQL_TXQ_LIMIT_H; =09} =20 diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 0e05ff037672..eafdd7492aba 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -1586,12 +1586,8 @@ static void sta_ps_start(struct sta_info *sta) =20 =09for (tid =3D 0; tid < IEEE80211_NUM_TIDS; tid++) { =09=09struct ieee80211_txq *txq =3D sta->sta.txq[tid]; -=09=09struct txq_info *txqi =3D to_txq_info(txq); =20 -=09=09spin_lock(&local->active_txq_lock[txq->ac]); -=09=09if (!list_empty(&txqi->schedule_order)) -=09=09=09list_del_init(&txqi->schedule_order); -=09=09spin_unlock(&local->active_txq_lock[txq->ac]); +=09=09ieee80211_unschedule_txq(&local->hw, txq); =20 =09=09if (txq_has_queue(txq)) =09=09=09set_bit(tid, &sta->txq_buffered_tids); diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index 0f5f40678885..c1d925096b02 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -404,15 +404,11 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_= if_data *sdata, =09if (sta_prepare_rate_control(local, sta, gfp)) =09=09goto free_txq; =20 -=09sta->airtime_weight =3D IEEE80211_DEFAULT_AIRTIME_WEIGHT; =20 =09for (i =3D 0; i < IEEE80211_NUM_ACS; i++) { =09=09skb_queue_head_init(&sta->ps_tx_buf[i]); =09=09skb_queue_head_init(&sta->tx_filtered[i]); -=09=09sta->airtime[i].deficit =3D sta->airtime_weight; -=09=09atomic_set(&sta->airtime[i].aql_tx_pending, 0); -=09=09sta->airtime[i].aql_limit_low =3D local->aql_txq_limit_low[i]; -=09=09sta->airtime[i].aql_limit_high =3D local->aql_txq_limit_high[i]; +=09=09init_airtime_info(&sta->airtime[i], &local->airtime[i]); =09} =20 =09for (i =3D 0; i < IEEE80211_NUM_TIDS; i++) @@ -1889,24 +1885,58 @@ void ieee80211_sta_set_buffered(struct ieee80211_st= a *pubsta, } EXPORT_SYMBOL(ieee80211_sta_set_buffered); =20 -void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid, -=09=09=09=09 u32 tx_airtime, u32 rx_airtime) +void ieee80211_register_airtime(struct ieee80211_txq *txq, +=09=09=09=09u32 tx_airtime, u32 rx_airtime) { -=09struct sta_info *sta =3D container_of(pubsta, struct sta_info, sta); -=09struct ieee80211_local *local =3D sta->sdata->local; -=09u8 ac =3D ieee80211_ac_from_tid(tid); -=09u32 airtime =3D 0; +=09struct ieee80211_sub_if_data *sdata =3D vif_to_sdata(txq->vif); +=09u64 airtime =3D 0, weight_sum, weight_sum_reciprocal; +=09struct ieee80211_local *local =3D sdata->local; +=09struct airtime_sched_info *air_sched; +=09struct airtime_info *air_info; + +=09air_sched =3D &local->airtime[txq->ac]; +=09air_info =3D to_airtime_info(txq); =20 -=09if (sta->local->airtime_flags & AIRTIME_USE_TX) +=09if (local->airtime_flags & AIRTIME_USE_TX) =09=09airtime +=3D tx_airtime; -=09if (sta->local->airtime_flags & AIRTIME_USE_RX) +=09if (local->airtime_flags & AIRTIME_USE_RX) =09=09airtime +=3D rx_airtime; =20 -=09spin_lock_bh(&local->active_txq_lock[ac]); -=09sta->airtime[ac].tx_airtime +=3D tx_airtime; -=09sta->airtime[ac].rx_airtime +=3D rx_airtime; -=09sta->airtime[ac].deficit -=3D airtime; -=09spin_unlock_bh(&local->active_txq_lock[ac]); +=09/* Weights scale so the unit weight is 256 */ +=09airtime <<=3D 8; + +=09spin_lock_bh(&air_sched->lock); + +=09air_info->tx_airtime +=3D tx_airtime; +=09air_info->rx_airtime +=3D rx_airtime; + +=09if (air_sched->weight_sum) { +=09=09weight_sum =3D air_sched->weight_sum; +=09=09weight_sum_reciprocal =3D air_sched->weight_sum_reciprocal; +=09} else { +=09=09weight_sum =3D air_info->weight; +=09=09weight_sum_reciprocal =3D air_info->weight_reciprocal; +=09} + +=09/* Round the calculation of global vt */ +=09air_sched->v_t +=3D ((airtime + (weight_sum >> 1)) * +=09=09=09 weight_sum_reciprocal) >> IEEE80211_RECIPROCAL_SHIFT; +=09air_info->v_t +=3D (airtime * air_info->weight_reciprocal) >> +=09=09IEEE80211_RECIPROCAL_SHIFT; +=09ieee80211_resort_txq(&local->hw, txq); + +=09spin_unlock_bh(&air_sched->lock); +} + +void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid, +=09=09=09=09 u32 tx_airtime, u32 rx_airtime) +{ +=09struct ieee80211_txq *txq =3D pubsta->txq[tid]; + +=09if (!txq) +=09=09return; + +=09ieee80211_register_airtime(txq, tx_airtime, rx_airtime); } EXPORT_SYMBOL(ieee80211_sta_register_airtime); =20 @@ -1948,6 +1978,7 @@ void ieee80211_sta_update_pending_airtime(struct ieee= 80211_local *local, =09=09=09 tx_pending, 0); } =20 + int sta_info_move_state(struct sta_info *sta, =09=09=09enum ieee80211_sta_state new_state) { @@ -2330,7 +2361,7 @@ void sta_set_sinfo(struct sta_info *sta, struct stati= on_info *sinfo, =09} =20 =09if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT))) { -=09=09sinfo->airtime_weight =3D sta->airtime_weight; +=09=09sinfo->airtime_weight =3D sta->airtime[0].weight; =09=09sinfo->filled |=3D BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT); =09} =20 diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h index c00e28585f9d..1cdecca28b3d 100644 --- a/net/mac80211/sta_info.h +++ b/net/mac80211/sta_info.h @@ -127,19 +127,27 @@ enum ieee80211_agg_stop_reason { /* Debugfs flags to enable/disable use of RX/TX airtime in scheduler */ #define AIRTIME_USE_TX=09=09BIT(0) #define AIRTIME_USE_RX=09=09BIT(1) +#define AIRTIME_GRACE 2000 /* usec of grace period before reset */ + +#define IEEE80211_RECIPROCAL_DIVISOR 0x100000000ULL +#define IEEE80211_RECIPROCAL_SHIFT 32 =20 struct airtime_info { =09u64 rx_airtime; =09u64 tx_airtime; -=09s64 deficit; +=09u64 v_t; =09atomic_t aql_tx_pending; /* Estimated airtime for frames pending */ =09u32 aql_limit_low; =09u32 aql_limit_high; +=09u64 weight_reciprocal; +=09u16 weight; }; =20 void ieee80211_sta_update_pending_airtime(struct ieee80211_local *local, =09=09=09=09=09 struct sta_info *sta, u8 ac, =09=09=09=09=09 u16 tx_airtime, bool tx_completed); +void ieee80211_register_airtime(struct ieee80211_txq *txq, +=09=09=09=09u32 tx_airtime, u32 rx_airtime); =20 struct sta_info; =20 @@ -480,7 +488,6 @@ 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 *=09station - * @airtime_weight: station weight for airtime fairness calculation purpos= es * @ampdu_mlme: A-MPDU state machine state * @mesh: mesh STA information * @debugfs_dir: debug filesystem directory dentry @@ -525,6 +532,7 @@ struct ieee80211_sta_rx_stats { * @status_stats.ack_signal_filled: last ACK signal validity * @status_stats.avg_ack_signal: average ACK signal */ + struct sta_info { =09/* General information, mostly static */ =09struct list_head list, free_list; @@ -607,7 +615,6 @@ struct sta_info { =09u16 tid_seq[IEEE80211_QOS_CTL_TID_MASK + 1]; =20 =09struct airtime_info airtime[IEEE80211_NUM_ACS]; -=09u16 airtime_weight; =20 =09/* =09 * Aggregation information, locked with lock. diff --git a/net/mac80211/status.c b/net/mac80211/status.c index 0344b82a34f5..e2f660addc9f 100644 --- a/net/mac80211/status.c +++ b/net/mac80211/status.c @@ -1025,6 +1025,23 @@ static void __ieee80211_tx_status(struct ieee80211_h= w *hw, =09=09=09=09ieee80211_lost_packet(sta, info); =09=09=09} =09=09} +=09} else if (wiphy_ext_feature_isset(local->hw.wiphy, +=09=09=09=09=09 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) { +=09=09struct ieee80211_sub_if_data *sdata; +=09=09struct ieee80211_txq *txq; +=09=09u32 airtime; + +=09=09sdata =3D ieee80211_sdata_from_skb(local, skb); + +=09=09if (sdata && (txq =3D sdata->vif.txq)) { +=09=09=09airtime =3D info->status.tx_time ?: +=09=09=09=09ieee80211_calc_expected_tx_airtime(hw, +=09=09=09=09=09=09=09=09 &sdata->vif, +=09=09=09=09=09=09=09=09 NULL, +=09=09=09=09=09=09=09=09 skb->len); + +=09=09=09ieee80211_register_airtime(txq, airtime, 0); +=09=09} =09} =20 =09/* SNMP counters diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 302cc7c83a4f..d63145f86c39 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -1451,7 +1451,7 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data = *sdata, =09codel_vars_init(&txqi->def_cvars); =09codel_stats_init(&txqi->cstats); =09__skb_queue_head_init(&txqi->frags); -=09INIT_LIST_HEAD(&txqi->schedule_order); +=09RB_CLEAR_NODE(&txqi->schedule_order); =20 =09txqi->txq.vif =3D &sdata->vif; =20 @@ -1495,9 +1495,7 @@ void ieee80211_txq_purge(struct ieee80211_local *loca= l, =09ieee80211_purge_tx_queue(&local->hw, &txqi->frags); =09spin_unlock_bh(&fq->lock); =20 -=09spin_lock_bh(&local->active_txq_lock[txqi->txq.ac]); -=09list_del_init(&txqi->schedule_order); -=09spin_unlock_bh(&local->active_txq_lock[txqi->txq.ac]); +=09ieee80211_unschedule_txq(&local->hw, &txqi->txq); } =20 void ieee80211_txq_set_params(struct ieee80211_local *local) @@ -3699,100 +3697,194 @@ EXPORT_SYMBOL(ieee80211_tx_dequeue); struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac) { =09struct ieee80211_local *local =3D hw_to_local(hw); +=09struct airtime_sched_info *air_sched; =09struct ieee80211_txq *ret =3D NULL; -=09struct txq_info *txqi =3D NULL, *head =3D NULL; -=09bool found_eligible_txq =3D false; +=09struct txq_info *txqi =3D NULL; +=09struct airtime_info *air_info; +=09struct rb_node *node; +=09bool first =3D false; =20 -=09spin_lock_bh(&local->active_txq_lock[ac]); +=09air_sched =3D &local->airtime[ac]; +=09spin_lock_bh(&air_sched->lock); =20 - begin: -=09txqi =3D list_first_entry_or_null(&local->active_txqs[ac], -=09=09=09=09=09struct txq_info, -=09=09=09=09=09schedule_order); -=09if (!txqi) +=09node =3D air_sched->schedule_pos; + +begin: +=09if (!node) { +=09=09node =3D rb_first_cached(&air_sched->active_txqs); +=09=09first =3D true; +=09} else { +=09=09node =3D rb_next(node); +=09} + +=09if (!node) =09=09goto out; =20 -=09if (txqi =3D=3D head) { -=09=09if (!found_eligible_txq) -=09=09=09goto out; +=09txqi =3D container_of(node, struct txq_info, schedule_order); +=09air_info =3D to_airtime_info(&txqi->txq); + +=09if (air_info->v_t > air_sched->v_t) { +=09=09if (first) +=09=09=09air_sched->v_t =3D air_sched->v_t; =09=09else -=09=09=09found_eligible_txq =3D false; +=09=09=09goto out; =09} =20 -=09if (!head) -=09=09head =3D txqi; - -=09if (txqi->txq.sta) { -=09=09struct sta_info *sta =3D container_of(txqi->txq.sta, -=09=09=09=09=09=09 struct sta_info, sta); -=09=09bool aql_check =3D ieee80211_txq_airtime_check(hw, &txqi->txq); -=09=09s64 deficit =3D sta->airtime[txqi->txq.ac].deficit; +=09if (!ieee80211_txq_airtime_check(hw, &txqi->txq)) { +=09=09first =3D false; +=09=09goto begin; +=09} =20 -=09=09if (aql_check) -=09=09=09found_eligible_txq =3D true; +=09if (txqi->schedule_round =3D=3D air_sched->schedule_round) +=09=09goto begin; =20 -=09=09if (deficit < 0) -=09=09=09sta->airtime[txqi->txq.ac].deficit +=3D -=09=09=09=09sta->airtime_weight; +=09txqi->schedule_round =3D air_sched->schedule_round; +=09air_sched->schedule_pos =3D node; +=09ret =3D &txqi->txq; +out: +=09spin_unlock_bh(&air_sched->lock); +=09return ret; +} +EXPORT_SYMBOL(ieee80211_next_txq); =20 -=09=09if (deficit < 0 || !aql_check) { -=09=09=09list_move_tail(&txqi->schedule_order, -=09=09=09=09 &local->active_txqs[txqi->txq.ac]); -=09=09=09goto begin; +static void __ieee80211_insert_txq(struct rb_root_cached *root, +=09=09=09=09 struct txq_info *txqi) +{ +=09struct rb_node **new =3D &root->rb_root.rb_node; +=09struct airtime_info *old_air, *new_air; +=09struct rb_node *parent =3D NULL; +=09struct txq_info *__txqi; +=09bool leftmost =3D true; + +=09while (*new) { +=09=09parent =3D *new; +=09=09__txqi =3D rb_entry(parent, struct txq_info, schedule_order); +=09=09old_air =3D to_airtime_info(&__txqi->txq); +=09=09new_air =3D to_airtime_info(&txqi->txq); + +=09=09if (new_air->v_t <=3D old_air->v_t) { +=09=09=09/* new txqi has no sta - insert to the left */ +=09=09=09new =3D &parent->rb_left; +=09=09} else { +=09=09=09/* existing txqi has no sta - insert to the right */ +=09=09=09new =3D &parent->rb_right; +=09=09=09leftmost =3D false; =09=09} =09} =20 +=09rb_link_node(&txqi->schedule_order, parent, new); +=09rb_insert_color_cached(&txqi->schedule_order, root, leftmost); +} =20 -=09if (txqi->schedule_round =3D=3D local->schedule_round[ac]) +void ieee80211_resort_txq(struct ieee80211_hw *hw, +=09=09=09 struct ieee80211_txq *txq) +{ +=09struct ieee80211_local *local =3D hw_to_local(hw); +=09struct txq_info *txqi =3D to_txq_info(txq); +=09struct airtime_sched_info *air_sched; + +=09air_sched =3D &local->airtime[txq->ac]; + +=09lockdep_assert_held(&air_sched->lock); + +=09if (!RB_EMPTY_NODE(&txqi->schedule_order)) { +=09=09if (air_sched->schedule_pos =3D=3D &txqi->schedule_order) +=09=09=09air_sched->schedule_pos =3D rb_prev(&txqi->schedule_order); + +=09=09rb_erase_cached(&txqi->schedule_order, +=09=09=09=09&air_sched->active_txqs); +=09=09RB_CLEAR_NODE(&txqi->schedule_order); +=09=09__ieee80211_insert_txq(&air_sched->active_txqs, txqi); +=09} +} + +void ieee80211_schedule_txq(struct ieee80211_hw *hw, +=09=09=09 struct ieee80211_txq *txq) +=09__acquires(txq_lock) __releases(txq_lock) +{ +=09struct ieee80211_local *local =3D hw_to_local(hw); +=09struct txq_info *txqi =3D to_txq_info(txq); +=09struct airtime_sched_info *air_sched; +=09struct airtime_info *air_info; +=09u8 ac =3D txq->ac; + +=09air_sched =3D &local->airtime[ac]; +=09air_info =3D to_airtime_info(txq); + +=09spin_lock_bh(&air_sched->lock); + +=09if (!RB_EMPTY_NODE(&txqi->schedule_order)) =09=09goto out; =20 -=09list_del_init(&txqi->schedule_order); -=09txqi->schedule_round =3D local->schedule_round[ac]; -=09ret =3D &txqi->txq; +=09airtime_weight_add(air_sched, air_info->weight); +=09if (air_sched->v_t > AIRTIME_GRACE) +=09=09air_info->v_t =3D max(air_sched->v_t - AIRTIME_GRACE, +=09=09=09=09 air_info->v_t); + +=09__ieee80211_insert_txq(&air_sched->active_txqs, txqi); =20 out: -=09spin_unlock_bh(&local->active_txq_lock[ac]); -=09return ret; +=09spin_unlock_bh(&air_sched->lock); } -EXPORT_SYMBOL(ieee80211_next_txq); +EXPORT_SYMBOL(ieee80211_schedule_txq); =20 -void __ieee80211_schedule_txq(struct ieee80211_hw *hw, -=09=09=09 struct ieee80211_txq *txq, -=09=09=09 bool force) +static void __ieee80211_unschedule_txq(struct ieee80211_hw *hw, +=09=09=09=09 struct ieee80211_txq *txq) { =09struct ieee80211_local *local =3D hw_to_local(hw); =09struct txq_info *txqi =3D to_txq_info(txq); +=09struct airtime_sched_info *air_sched; +=09struct airtime_info *air_info; =20 -=09spin_lock_bh(&local->active_txq_lock[txq->ac]); - -=09if (list_empty(&txqi->schedule_order) && -=09 (force || !skb_queue_empty(&txqi->frags) || -=09 txqi->tin.backlog_packets)) { -=09=09/* If airtime accounting is active, always enqueue STAs at the -=09=09 * head of the list to ensure that they only get moved to the -=09=09 * back by the airtime DRR scheduler once they have a negative -=09=09 * deficit. A station that already has a negative deficit will -=09=09 * get immediately moved to the back of the list on the next -=09=09 * call to ieee80211_next_txq(). -=09=09 */ -=09=09if (txqi->txq.sta && -=09=09 wiphy_ext_feature_isset(local->hw.wiphy, -=09=09=09=09=09 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) -=09=09=09list_add(&txqi->schedule_order, -=09=09=09=09 &local->active_txqs[txq->ac]); -=09=09else -=09=09=09list_add_tail(&txqi->schedule_order, -=09=09=09=09 &local->active_txqs[txq->ac]); -=09} +=09air_sched =3D &local->airtime[txq->ac]; +=09air_info =3D to_airtime_info(&txqi->txq); + +=09lockdep_assert_held(&air_sched->lock); + +=09if (RB_EMPTY_NODE(&txqi->schedule_order)) +=09=09return; + +=09if (air_sched->schedule_pos =3D=3D &txqi->schedule_order) +=09=09air_sched->schedule_pos =3D rb_prev(&txqi->schedule_order); + +=09airtime_weight_add(air_sched, -air_info->weight); + +=09rb_erase_cached(&txqi->schedule_order, +=09=09=09&air_sched->active_txqs); +=09RB_CLEAR_NODE(&txqi->schedule_order); +} + +void ieee80211_unschedule_txq(struct ieee80211_hw *hw, +=09=09=09 struct ieee80211_txq *txq) +=09__acquires(txq_lock) __releases(txq_lock) +{ +=09struct ieee80211_local *local =3D hw_to_local(hw); + +=09spin_lock_bh(&local->airtime[txq->ac].lock); +=09__ieee80211_unschedule_txq(hw, txq); +=09spin_unlock_bh(&local->airtime[txq->ac].lock); +} + +void ieee80211_return_txq(struct ieee80211_hw *hw, +=09=09=09 struct ieee80211_txq *txq, bool force) +{ +=09struct ieee80211_local *local =3D hw_to_local(hw); +=09struct txq_info *txqi =3D to_txq_info(txq); + +=09spin_lock_bh(&local->airtime[txq->ac].lock); + +=09if (!RB_EMPTY_NODE(&txqi->schedule_order) && !force && +=09 !txq_has_queue(txq)) +=09=09__ieee80211_unschedule_txq(hw, txq); =20 -=09spin_unlock_bh(&local->active_txq_lock[txq->ac]); +=09spin_unlock_bh(&local->airtime[txq->ac].lock); } -EXPORT_SYMBOL(__ieee80211_schedule_txq); +EXPORT_SYMBOL(ieee80211_return_txq); =20 bool ieee80211_txq_airtime_check(struct ieee80211_hw *hw, =09=09=09=09 struct ieee80211_txq *txq) { -=09struct sta_info *sta; +=09struct airtime_info *air_info =3D to_airtime_info(txq); =09struct ieee80211_local *local =3D hw_to_local(hw); =20 =09if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) @@ -3801,15 +3893,12 @@ bool ieee80211_txq_airtime_check(struct ieee80211_h= w *hw, =09if (!txq->sta) =09=09return true; =20 -=09sta =3D container_of(txq->sta, struct sta_info, sta); -=09if (atomic_read(&sta->airtime[txq->ac].aql_tx_pending) < -=09 sta->airtime[txq->ac].aql_limit_low) +=09if (atomic_read(&air_info->aql_tx_pending) < air_info->aql_limit_low) =09=09return true; =20 =09if (atomic_read(&local->aql_total_pending_airtime) < =09 local->aql_threshold && -=09 atomic_read(&sta->airtime[txq->ac].aql_tx_pending) < -=09 sta->airtime[txq->ac].aql_limit_high) +=09 atomic_read(&air_info->aql_tx_pending) < air_info->aql_limit_high) =09=09return true; =20 =09return false; @@ -3819,60 +3908,45 @@ EXPORT_SYMBOL(ieee80211_txq_airtime_check); bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw, =09=09=09=09struct ieee80211_txq *txq) { +=09struct txq_info *first_txqi =3D NULL, *txqi =3D to_txq_info(txq); =09struct ieee80211_local *local =3D hw_to_local(hw); -=09struct txq_info *iter, *tmp, *txqi =3D to_txq_info(txq); -=09struct sta_info *sta; -=09u8 ac =3D txq->ac; +=09struct airtime_sched_info *air_sched; +=09struct airtime_info *air_info; +=09struct rb_node *node =3D NULL; +=09bool ret; =20 -=09spin_lock_bh(&local->active_txq_lock[ac]); +=09if (!ieee80211_txq_airtime_check(hw, txq)) +=09=09return false; =20 -=09if (!txqi->txq.sta) -=09=09goto out; +=09air_sched =3D &local->airtime[txq->ac]; +=09spin_lock_bh(&air_sched->lock); =20 -=09if (list_empty(&txqi->schedule_order)) -=09=09goto out; +=09node =3D rb_first_cached(&air_sched->active_txqs); +=09if (node) { +=09=09first_txqi =3D container_of(node, struct txq_info, +=09=09=09=09=09 schedule_order); +=09=09air_info =3D to_airtime_info(&first_txqi->txq); =20 -=09list_for_each_entry_safe(iter, tmp, &local->active_txqs[ac], -=09=09=09=09 schedule_order) { -=09=09if (iter =3D=3D txqi) -=09=09=09break; - -=09=09if (!iter->txq.sta) { -=09=09=09list_move_tail(&iter->schedule_order, -=09=09=09=09 &local->active_txqs[ac]); -=09=09=09continue; -=09=09} -=09=09sta =3D container_of(iter->txq.sta, struct sta_info, sta); -=09=09if (sta->airtime[ac].deficit < 0) -=09=09=09sta->airtime[ac].deficit +=3D sta->airtime_weight; -=09=09list_move_tail(&iter->schedule_order, &local->active_txqs[ac]); +=09=09if (air_sched->v_t < air_info->v_t) +=09=09=09air_sched->v_t =3D air_info->v_t; =09} =20 -=09sta =3D container_of(txqi->txq.sta, struct sta_info, sta); -=09if (sta->airtime[ac].deficit >=3D 0) -=09=09goto out; - -=09sta->airtime[ac].deficit +=3D sta->airtime_weight; -=09list_move_tail(&txqi->schedule_order, &local->active_txqs[ac]); -=09spin_unlock_bh(&local->active_txq_lock[ac]); +=09air_info =3D to_airtime_info(&txqi->txq); +=09ret =3D (air_info->v_t <=3D air_sched->v_t); =20 -=09return false; -out: -=09if (!list_empty(&txqi->schedule_order)) -=09=09list_del_init(&txqi->schedule_order); -=09spin_unlock_bh(&local->active_txq_lock[ac]); - -=09return true; +=09spin_unlock_bh(&air_sched->lock); +=09return ret; } EXPORT_SYMBOL(ieee80211_txq_may_transmit); =20 void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) { =09struct ieee80211_local *local =3D hw_to_local(hw); +=09struct airtime_sched_info *air_sched =3D &local->airtime[ac]; =20 -=09spin_lock_bh(&local->active_txq_lock[ac]); -=09local->schedule_round[ac]++; -=09spin_unlock_bh(&local->active_txq_lock[ac]); +=09spin_lock_bh(&air_sched->lock); +=09air_sched->schedule_round++; +=09spin_unlock_bh(&air_sched->lock); } EXPORT_SYMBOL(ieee80211_txq_schedule_start); =20 --=20 2.24.1