From patchwork Thu Sep 19 12:22:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 11152253 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F6A8112B for ; Thu, 19 Sep 2019 12:22:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 246AE2196F for ; Thu, 19 Sep 2019 12:22:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IA0hlO1Z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390287AbfISMWu (ORCPT ); Thu, 19 Sep 2019 08:22:50 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:55553 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390189AbfISMWu (ORCPT ); Thu, 19 Sep 2019 08:22:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1568895769; 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: in-reply-to:in-reply-to:references:references; bh=d8iED3oiyhLzJJZ30CyP3ZO6eui10EgrPm/9G6wov3s=; b=IA0hlO1ZMmyc6Dv/cxAsQAtE4tH8mrusOlc7WMHDyKm+Em0zRN0KmsW7zwwhvVWkhGaL4c rtbdtMhSYYoVggR3xHWcdAIlBY4MkH5N8Po5VRbV4aNdTp3++wjDQF0GNo5Dp6V6KYMhCJ ABZuhuTwaMZJNurQSTP27jnSJ/dksZc= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-121-SJva4J_mO7mVhw80i6swsQ-1; Thu, 19 Sep 2019 08:22:47 -0400 Received: by mail-ed1-f71.google.com with SMTP id n12so1818917edr.22 for ; Thu, 19 Sep 2019 05:22:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=EXEr1sMDPH/aWfRInXJqvE5yL3ewAcgVs45LnZ9+8dU=; b=CHS/YmGkjiUZs09Q73CxyZjRqbnGKkEUOhWFZbNNP0Q3NTI6sE0X6DXpyQJg2UT/Un 92/L7GpAmqKPxuAmmAzPBVpmY1PyRBWzCjQEfLswF5jZ+POn/ObcarRL920l8kDnkLRE UpYhVVhClOU9hoDriK9X+STSgqvQ5wiCJMuR8o5Xm6XO7uswO/EkugyQHO15MpIe19J+ Dy55C+R9/1lDocpRZqb0b54CCQ1qbHLpN20kcAAOP84fOYKyU2bmus5Iayfbe6Yz0A67 mArRJeBACA3/dUNzgq4eIspab8VlpLGIJTfGQ55D34/1+yUrIaIGSZpkdJ2V4ZVcjBz2 k0tQ== X-Gm-Message-State: APjAAAVDicP7NTUA2tsUlhvajDNGm/cYulz6oZJbu+bZsNPK+IHkin5x UYCFHcZR6ghgphn58n1IoHVblFI9sCPFglcwvM7LqedTjKiVE7ipYADi0/j0+xgkem0mIyaiU89 KCY9AfViLdCZCDxuMsHhibWBN1k4= X-Received: by 2002:a17:906:1304:: with SMTP id w4mr13641522ejb.6.1568895766662; Thu, 19 Sep 2019 05:22:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJa6db6yYOyoT/D8diru8N8y2vYw5ZdUdScxxTHkNz9Av5ARCqssZ6G+qM8bwIdBfM3wU51g== X-Received: by 2002:a17:906:1304:: with SMTP id w4mr13641508ejb.6.1568895766453; Thu, 19 Sep 2019 05:22:46 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a00:7660:6da:443::2]) by smtp.gmail.com with ESMTPSA id l11sm1018778eje.67.2019.09.19.05.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2019 05:22:45 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 7082518063F; Thu, 19 Sep 2019 14:22:45 +0200 (CEST) Subject: [PATCH RFC/RFT 1/4] mac80211: Rearrange ieee80211_tx_info to make room for tx_time_est From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Johannes Berg Cc: linux-wireless@vger.kernel.org, make-wifi-fast@lists.bufferbloat.net, John Crispin , Lorenzo Bianconi , Felix Fietkau Date: Thu, 19 Sep 2019 14:22:45 +0200 Message-ID: <156889576534.191202.17686228416284995279.stgit@alrua-x1> In-Reply-To: <156889576422.191202.5906619710809654631.stgit@alrua-x1> References: <156889576422.191202.5906619710809654631.stgit@alrua-x1> User-Agent: StGit/0.19-dirty MIME-Version: 1.0 X-MC-Unique: SJva4J_mO7mVhw80i6swsQ-1 X-Mimecast-Spam-Score: 0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Toke Høiland-Jørgensen To implement airtime queue limiting, we need to keep a running account of the estimated airtime of all skbs queued into the device. Do to this correctly, we need to store the airtime estimate into the skb so we can decrease the outstanding balance when the skb is freed. This means that the time estimate must be stored somewhere that will survive for the lifetime of the skb. Fortunately, we had a couple of bytes left in the 'status' field in the ieee80211_tx_info; and since we only plan to calculate the airtime estimate after the skb is dequeued from the FQ structure, on the control side we can share the space with the codel enqueue time. And by rearranging the order of elements it is possible to have the position of the new tx_time_est line up between the control and status structs, so the value will survive from when mac80211 hands the packet to the driver, and until the driver either frees it, or hands it back through TX status. Signed-off-by: Toke Høiland-Jørgensen --- include/net/mac80211.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 523c6a09e1c8..b12d378621b0 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -975,20 +975,22 @@ ieee80211_rate_get_vht_nss(const struct ieee80211_tx_rate *rate) * @control.short_preamble: use short preamble (CCK only) * @control.skip_table: skip externally configured rate table * @control.jiffies: timestamp for expiry on powersave clients + * @control.enqueue_time: enqueue time (for iTXQs) + * @control.tx_time_est: estimated airtime usage (shared with @status) + * @control.flags: control flags, see &enum mac80211_tx_control_flags * @control.vif: virtual interface (may be NULL) * @control.hw_key: key to encrypt with (may be NULL) - * @control.flags: control flags, see &enum mac80211_tx_control_flags - * @control.enqueue_time: enqueue time (for iTXQs) * @driver_rates: alias to @control.rates to reserve space * @pad: padding * @rate_driver_data: driver use area if driver needs @control.rates * @status: union part for status data * @status.rates: attempted rates * @status.ack_signal: ACK signal + * @status.tx_time_est: estimated airtime of skb (shared with @control) + * @status.tx_time: actual airtime consumed for transmission * @status.ampdu_ack_len: AMPDU ack length * @status.ampdu_len: AMPDU length * @status.antenna: (legacy, kept only for iwlegacy) - * @status.tx_time: airtime consumed for transmission * @status.is_valid_ack_signal: ACK signal is valid * @status.status_driver_data: driver use area * @ack: union part for pure ACK data @@ -1026,11 +1028,14 @@ struct ieee80211_tx_info { /* only needed before rate control */ unsigned long jiffies; }; + union { + codel_time_t enqueue_time; + u16 tx_time_est; /* shared with status */ + }; + u32 flags; /* NB: vif can be NULL for injected frames */ struct ieee80211_vif *vif; struct ieee80211_key_conf *hw_key; - u32 flags; - codel_time_t enqueue_time; } control; struct { u64 cookie; @@ -1038,12 +1043,13 @@ struct ieee80211_tx_info { struct { struct ieee80211_tx_rate rates[IEEE80211_TX_MAX_RATES]; s32 ack_signal; + u16 tx_time_est; /* shared with control */ + u16 tx_time; u8 ampdu_ack_len; u8 ampdu_len; u8 antenna; - u16 tx_time; bool is_valid_ack_signal; - void *status_driver_data[19 / sizeof(void *)]; + void *status_driver_data[16 / sizeof(void *)]; } status; struct { struct ieee80211_tx_rate driver_rates[ @@ -1126,6 +1132,8 @@ ieee80211_tx_info_clear_status(struct ieee80211_tx_info *info) offsetof(struct ieee80211_tx_info, control.rates)); BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, status.rates) != offsetof(struct ieee80211_tx_info, driver_rates)); + BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, control.tx_time_est) != + offsetof(struct ieee80211_tx_info, status.tx_time_est)); BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, status.rates) != 8); /* clear the rate counts */ for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) From patchwork Thu Sep 19 12:22:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 11152255 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 092E316B1 for ; Thu, 19 Sep 2019 12:22:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC6C22196F for ; Thu, 19 Sep 2019 12:22:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TpFrmwPq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390289AbfISMWx (ORCPT ); Thu, 19 Sep 2019 08:22:53 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:55359 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390189AbfISMWx (ORCPT ); Thu, 19 Sep 2019 08:22:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1568895770; 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: in-reply-to:in-reply-to:references:references; bh=0TjYALoQnRgIrNe7Jpy6h0CAGnfDVH/rvpH+SgQd3Yw=; b=TpFrmwPqm6+1DOFlLqCABatFPDPTt5iwWfhqB1ZT99gd4LQGqcrUvm8Rr+NI1h6Gu0Zg8k jMrAVDp2PvVIltRGeEOF0sKEtPDVJlrq7BIbm91TQnnur2cvs7k2tqh9kOkrW+SytvSK4H DHQD6NQ+s9uworfiR7v/LN+/eUoj2gE= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-16-gcFSpKOIP0Gx7-oRn-NNDA-1; Thu, 19 Sep 2019 08:22:49 -0400 Received: by mail-ed1-f70.google.com with SMTP id c16so991731eds.10 for ; Thu, 19 Sep 2019 05:22:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=KjFprYlVcjHNButAUZ7w0c0tzBKf1DOqVFXKr1K22dc=; b=tgqjRYH4uplYsxJYGYoy9POmu2wZdN6j/SFWtNmDQyP//cp5giDwgfjHTepi0uMWqD v1gGThU6YqUeNmr2iNLGeL6hlM2Yup9L0GgRT9g3P2x2cfUn4KZPZUohUbo/6oWS2uQ0 IfjJmhBKgMh6H0/kQzKbh5mBiO6OZxwBp8BcpnVqjmVDlh8uZ1VwbeXzJC2uY9R1/fNf kZLQtredt9Gs40mnR0DAatkZulG65YmSvqGiJXj7IJrMonwiGHBPATM9pRcs99R5n8gm MwspoD9bsPdOY4teS5pCNP/q7SW9BQH4NGsOfuxlz4BCw3bKwcZleTkcPGDC3Th55LBQ jzsw== X-Gm-Message-State: APjAAAXA7CI37Z/LoHQCZ/+ImwpoAhtAq8aSsTPM/zb5OilRx8cbP7M1 8Nml+dbQTb7hQnxewfsPwcC3VT2oUqr/gDNqmfh2LpxKtc55fQ/vaDvoJvWwRmViI2VMUpkHsqu CZVJgM6B91pC4omId6rALeMj5Sf4= X-Received: by 2002:a17:906:4a51:: with SMTP id a17mr13838839ejv.279.1568895768183; Thu, 19 Sep 2019 05:22:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1JrZikJXVhvU4P8naQE9WjBTVHMbuP067O/imjHriv11OeWSxV/xIvPwxrqVVaAtNp5t6Ow== X-Received: by 2002:a17:906:4a51:: with SMTP id a17mr13838819ejv.279.1568895767985; Thu, 19 Sep 2019 05:22:47 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk (borgediget.toke.dk. [85.204.121.218]) by smtp.gmail.com with ESMTPSA id c22sm1619170edc.9.2019.09.19.05.22.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2019 05:22:47 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 8EC2E18063E; Thu, 19 Sep 2019 14:22:46 +0200 (CEST) Subject: [PATCH RFC/RFT 2/4] mac80211: Add API function to set the last TX bitrate for a station From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Johannes Berg Cc: linux-wireless@vger.kernel.org, make-wifi-fast@lists.bufferbloat.net, John Crispin , Lorenzo Bianconi , Felix Fietkau Date: Thu, 19 Sep 2019 14:22:46 +0200 Message-ID: <156889576646.191202.14461472477971784776.stgit@alrua-x1> In-Reply-To: <156889576422.191202.5906619710809654631.stgit@alrua-x1> References: <156889576422.191202.5906619710809654631.stgit@alrua-x1> User-Agent: StGit/0.19-dirty MIME-Version: 1.0 X-MC-Unique: gcFSpKOIP0Gx7-oRn-NNDA-1 X-Mimecast-Spam-Score: 0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Toke Høiland-Jørgensen To implement airtime queue limits, we need an estimate of the transmission rate a station is currently transmitting at. The ath10k driver already keeps this internally, so add an API function to pass this up to mac80211. We also keep a pre-calculated 64-bit reciprocal that will be used in the actual calculations, to avoid a division operation in the fast path. Signed-off-by: Toke Høiland-Jørgensen --- include/net/mac80211.h | 10 ++++++++++ net/mac80211/ieee80211_i.h | 4 ++++ net/mac80211/sta_info.c | 9 +++++++++ net/mac80211/sta_info.h | 2 ++ 4 files changed, 25 insertions(+) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index b12d378621b0..1b7f4a370122 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -4529,6 +4529,16 @@ void ieee80211_get_tx_rates(struct ieee80211_vif *vif, void ieee80211_sta_set_expected_throughput(struct ieee80211_sta *pubsta, u32 thr); +/** + * ieee80211_sta_set_last_tx_bitrate - set last tx rate for station + * + * This sets the last TX bitrate for a given station. + * + * @sta: Pointer to the station + * @bitrate: Bitrate in kbps + */ +void ieee80211_sta_set_last_tx_bitrate(struct ieee80211_sta *sta, u32 bitrate); + /** * ieee80211_tx_rate_update - transmit rate update callback * diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 05406e9c05b3..9de5390411ba 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -59,6 +59,10 @@ struct ieee80211_local; /* power level hasn't been configured (or set to automatic) */ #define IEEE80211_UNSET_POWER_LEVEL INT_MIN +/* constants for calculating reciprocals to avoid division in fast path */ +#define IEEE80211_RECIPROCAL_DIVISOR 0x100000000ULL +#define IEEE80211_RECIPROCAL_SHIFT 32 + /* * Some APs experience problems when working with U-APSD. Decreasing the * probability of that happening by using legacy mode for all ACs but VO isn't diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index df553070206c..aae878ffe94c 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -2481,3 +2481,12 @@ void ieee80211_sta_set_expected_throughput(struct ieee80211_sta *pubsta, sta_update_codel_params(sta, thr); } + +void ieee80211_sta_set_last_tx_bitrate(struct ieee80211_sta *pubsta, + u32 rate) +{ + struct sta_info *sta = container_of(pubsta, struct sta_info, sta); + + sta->last_tx_bitrate = rate; + sta->last_tx_bitrate_reciprocal = ((u64)IEEE80211_RECIPROCAL_DIVISOR / rate); +} diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h index 369c2dddce52..dd1a0b87f234 100644 --- a/net/mac80211/sta_info.h +++ b/net/mac80211/sta_info.h @@ -617,6 +617,8 @@ struct sta_info { const struct ieee80211_cipher_scheme *cipher_scheme; struct codel_params cparams; + u32 last_tx_bitrate; + u64 last_tx_bitrate_reciprocal; u8 reserved_tid; From patchwork Thu Sep 19 12:22:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 11152257 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E2FB16B1 for ; Thu, 19 Sep 2019 12:22:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E1A9E2196F for ; Thu, 19 Sep 2019 12:22:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GnebpjRJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390293AbfISMWy (ORCPT ); Thu, 19 Sep 2019 08:22:54 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:21163 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390237AbfISMWx (ORCPT ); Thu, 19 Sep 2019 08:22:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1568895772; 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: in-reply-to:in-reply-to:references:references; bh=IwctswRgBDzjQDKiFZhMpOyHVX95Z8fvqsdkOkPRGjY=; b=GnebpjRJiwbpVJsA5Bq2u0e21OH6HMfbS98bfuTy0DEkgCoDqTOBDAkmgob4ac8oTGHWgU FNcbekxZfa7YJ+VcZNjYTyglsTZL6mVwXlYA0LLLSjiyhwxtVCSfzd1i3dxIHuzrjHfSd/ jufWuyqlSSZACtAT3P9ADlr8Lr5zOn4= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-225-AI3e1DeJPOWBJTiijeC5AQ-1; Thu, 19 Sep 2019 08:22:50 -0400 Received: by mail-ed1-f71.google.com with SMTP id 38so1859468edr.4 for ; Thu, 19 Sep 2019 05:22:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=Oen7CzFZmELv1d4/EePaKSFIocxA1ziuIjtlPtY3KYI=; b=iMSMClzadhdaHa2mxJU/x7FV9n8zQzSQeBdLhHBjkVVIWAf5uQ7sIFVwvp4rgrOWsa yD9VdS4qWdmzxSTCzWSUX+BhD4gQERwfrKxgYRmhUeN3s3Fh2YsydeyAXE7fWSxgxvur uN3tB6IBAR9nNY8iFootJaTd/hmY1ajIWN8k6sEvkriMrmRDm/X1zZoO9/aqz7/Yrkp5 qFmTbugZgWPLAuGIL1cX2pcGcLSH9HrB2xgfcMBUiNKwoyYdVSc4TFrE7h2ahdfgNWc9 nZgJ3YF7jIfe//w3A5mddgW8u6hI2/XKx68aXai8QeG0UKSu7NjjlRWN/2s1cAdzm0zr F1vg== X-Gm-Message-State: APjAAAX2R5zRNw2i8jNOSqY8Cjs/eaAGvarcJ1Ve0vuXnQ2g72vIPM1z ymYnloKtxac1VyjdZFP9wV3bfqwOIL8mqXoJeBKJ01Gc2fC6Eg2s2DGy0QSLWrsOHeyAqOppP5T EsvNx6W6BeTAFHiRrUdiBLJq7aIM= X-Received: by 2002:aa7:c657:: with SMTP id z23mr13862895edr.234.1568895769632; Thu, 19 Sep 2019 05:22:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4Wrq6mkotnQ/ffGvhibRAOH/IoFNreUVCNsD+HOZ36Lv4908di3XQf+c6ZEgDxc1uJSdeYQ== X-Received: by 2002:aa7:c657:: with SMTP id z23mr13862793edr.234.1568895768591; Thu, 19 Sep 2019 05:22:48 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a00:7660:6da:443::2]) by smtp.gmail.com with ESMTPSA id y5sm994249ejj.35.2019.09.19.05.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2019 05:22:48 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id A8A9E18063F; Thu, 19 Sep 2019 14:22:47 +0200 (CEST) Subject: [PATCH RFC/RFT 3/4] ath10k: Pass last TX bitrate up to mac80211 From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Johannes Berg Cc: linux-wireless@vger.kernel.org, make-wifi-fast@lists.bufferbloat.net, John Crispin , Lorenzo Bianconi , Felix Fietkau Date: Thu, 19 Sep 2019 14:22:47 +0200 Message-ID: <156889576758.191202.2981673914345691512.stgit@alrua-x1> In-Reply-To: <156889576422.191202.5906619710809654631.stgit@alrua-x1> References: <156889576422.191202.5906619710809654631.stgit@alrua-x1> User-Agent: StGit/0.19-dirty MIME-Version: 1.0 X-MC-Unique: AI3e1DeJPOWBJTiijeC5AQ-1 X-Mimecast-Spam-Score: 0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Toke Høiland-Jørgensen Use the newly added API to pass the last_tx_bitrate up to mac80211. The multiplication is because ath10k keeps it internally as units of 100kbps, whereas for mac80211 we just use kbps as the variable unit. Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/wireless/ath/ath10k/htt_rx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/ath/ath10k/htt_rx.c b/drivers/net/wireless/ath/ath10k/htt_rx.c index 83a7fb68fd24..0617341eb70c 100644 --- a/drivers/net/wireless/ath/ath10k/htt_rx.c +++ b/drivers/net/wireless/ath/ath10k/htt_rx.c @@ -3454,6 +3454,7 @@ ath10k_update_per_peer_tx_stats(struct ath10k *ar, arsta->txrate.nss = txrate.nss; arsta->txrate.bw = ath10k_bw_to_mac80211_bw(txrate.bw); arsta->last_tx_bitrate = cfg80211_calculate_bitrate(&arsta->txrate); + ieee80211_sta_set_last_tx_bitrate(sta, arsta->last_tx_bitrate * 100); if (sgi) arsta->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; From patchwork Thu Sep 19 12:22:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 11152259 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8EB3A112B for ; Thu, 19 Sep 2019 12:22:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 503E42196F for ; Thu, 19 Sep 2019 12:22:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ajs9ilOE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390295AbfISMWy (ORCPT ); Thu, 19 Sep 2019 08:22:54 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:60627 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390189AbfISMWy (ORCPT ); Thu, 19 Sep 2019 08:22:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1568895773; 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: in-reply-to:in-reply-to:references:references; bh=ff9ylqKsll/m6vnHoApO6eRc/A7utDvshVP4ma2pnKU=; b=Ajs9ilOE8L6DPBCA5t/aJzUhuPLUbUDaclpZMd1F1WJEGJlP5d7Tu3KhIjCtcBLEDFNWSg bw9k9BuWpixME4jDx7sY1HYVuOfd6yHMS/7kUjcIFQOdTGPON/WQa1/TdueEHe2+LzXHKJ KqwXwiKRPf9gk+o6lsJKSk0TjEfakwA= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-325-y7iWZFWjMVuporVpOIUXPA-1; Thu, 19 Sep 2019 08:22:52 -0400 Received: by mail-ed1-f70.google.com with SMTP id n14so1271590edt.3 for ; Thu, 19 Sep 2019 05:22:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=eHyKNNOoJTEEPAtKDeF5btinM/54CahoHWM77ag+nRY=; b=Xry4I/oUrg4ZVDIsPHEQk7X/yU7muhgJhJZZwvytLkNerAEB7kQL6DxvpZw0lmKNpE WLjlsbSgV9lrGsAggiG5v8YKb8m6U8C/UKgC7DkPFErbZ81TFxtym3AIZsGBuqtHEWf1 nd4xPYVUYteGNA/7Pu9+rr7VHJ9J5c0J+8cYZK7Wjb8HzN9g438TbH30c7qYzi0+P/vg tO9nhwi/ykNzYxcZy/vY64MLJjvxGFbRRullabuqv34b7DerQUpd/4XE3TwhoAHPeMNb sl+visD8O2m7FuKKcuOpRoBXPLJUoCOwxSbUnfWo7A2F14hZrCqrJHQcP4K/yv8sQARL Hezg== X-Gm-Message-State: APjAAAUF1SpP7y+6sy+RoqeHns7o+8L7E84sQP1ZLUAIQS5GGIKvVM4I fLgJ9U279+twRK+SkZP+xcdzpyAhiF9SExGacyBWO5UhVl+HMjBZRjWTpO56LYHaRHNFLItpP3B BHXGBh6YF7s0I0X0ghfJc8nCoLJE= X-Received: by 2002:a50:8b26:: with SMTP id l35mr15920931edl.244.1568895770508; Thu, 19 Sep 2019 05:22:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpRDXS7YRcyFJE0zqCq6U/gxCU2Vj0UW0AMOYHXKIpUIVfIAAujHDKKgzl49Gu4sHOlYNaEg== X-Received: by 2002:a50:8b26:: with SMTP id l35mr15920903edl.244.1568895770212; Thu, 19 Sep 2019 05:22:50 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a00:7660:6da:443::2]) by smtp.gmail.com with ESMTPSA id i63sm1614169edi.65.2019.09.19.05.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2019 05:22:49 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id C473618063E; Thu, 19 Sep 2019 14:22:48 +0200 (CEST) Subject: [PATCH RFC/RFT 4/4] mac80211: Apply Airtime-based Queue Limit (AQL) on packet dequeue From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Johannes Berg Cc: linux-wireless@vger.kernel.org, make-wifi-fast@lists.bufferbloat.net, John Crispin , Lorenzo Bianconi , Felix Fietkau Date: Thu, 19 Sep 2019 14:22:48 +0200 Message-ID: <156889576869.191202.510507546538322707.stgit@alrua-x1> In-Reply-To: <156889576422.191202.5906619710809654631.stgit@alrua-x1> References: <156889576422.191202.5906619710809654631.stgit@alrua-x1> User-Agent: StGit/0.19-dirty MIME-Version: 1.0 X-MC-Unique: y7iWZFWjMVuporVpOIUXPA-1 X-Mimecast-Spam-Score: 0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Toke Høiland-Jørgensen Some devices have deep buffers in firmware and/or hardware which prevents the FQ structure in mac80211 from effectively limiting bufferbloat on the link. For Ethernet devices we have BQL to limit the lower-level queues, but this cannot be applied to mac80211 because transmit rates can vary wildly between packets depending on which station we are transmitting it to. To overcome this, we can use airtime-based queue limiting (AQL), where we estimate the transmission time for each packet before dequeueing it, and use that to limit the amount of data in-flight to the hardware. This idea was originally implemented as part of the out-of-tree airtime fairness patch to ath10k[0] in chromiumos. This patch ports that idea over to mac80211. The basic idea is simple enough: Whenever we dequeue a packet from the TXQs and send it to the driver, we estimate its airtime usage, based on the last recorded TX rate of the station that packet is destined for. We keep a running per-AC total of airtime queued for the whole device, and when that total climbs above 8 ms' worth of data (corresponding to two maximum-sized aggregates), we simply throttle the queues until it drops down again. The estimated airtime for each skb is stored in the tx_info, so we can subtract the same amount from the running total when the skb is freed or recycled. The throttling mechanism relies on this accounting to be accurate (i.e., that we are not freeing skbs without subtracting any airtime they were accounted for), so we put the subtraction into ieee80211_report_used_skb(). This patch does *not* include any mechanism to wake a throttled TXQ again, on the assumption that this will happen anyway as a side effect of whatever freed the skb (most commonly a TX completion). The throttling mechanism only kicks in if the queued airtime total goes above the limit. Since mac80211 calculates the time based on the reported last_tx_time from the driver, the whole throttling mechanism only kicks in for drivers that actually report this value. With the exception of multicast, where we always calculate an estimated tx time on the assumption that multicast is transmitted at the lowest (6 Mbps) rate. The throttling added in this patch is in addition to any throttling already performed by the airtime fairness mechanism, and in principle the two mechanisms are orthogonal (and currently also uses two different sources of airtime). In the future, we could amend this, using the airtime estimates calculated by this mechanism as a fallback input to the airtime fairness scheduler, to enable airtime fairness even on drivers that don't have a hardware source of airtime usage for each station. [0] https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/588190/13/drivers/net/wireless-4.2/ath/ath10k/mac.c#3845 Signed-off-by: Toke Høiland-Jørgensen --- net/mac80211/debugfs.c | 24 ++++++++++++++++++++++++ net/mac80211/ieee80211_i.h | 7 +++++++ net/mac80211/status.c | 22 ++++++++++++++++++++++ net/mac80211/tx.c | 38 +++++++++++++++++++++++++++++++++++++- 4 files changed, 90 insertions(+), 1 deletion(-) diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c index 568b3b276931..c846c6e7f3e3 100644 --- a/net/mac80211/debugfs.c +++ b/net/mac80211/debugfs.c @@ -148,6 +148,29 @@ static const struct file_operations aqm_ops = { .llseek = default_llseek, }; +static ssize_t airtime_queued_read(struct file *file, + char __user *user_buf, + size_t count, + loff_t *ppos) +{ + struct ieee80211_local *local = file->private_data; + char buf[32 * IEEE80211_NUM_ACS], *p = buf; + u8 ac; + + for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) + p += scnprintf(p, sizeof(buf)+buf-p, "AC%u: %u\n", ac, + local->airtime_queued[ac]); + + return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf); + +} + +static const struct file_operations airtime_queued_ops = { + .read = airtime_queued_read, + .open = simple_open, + .llseek = default_llseek, +}; + static ssize_t force_tx_status_read(struct file *file, char __user *user_buf, size_t count, @@ -440,6 +463,7 @@ void debugfs_hw_add(struct ieee80211_local *local) debugfs_create_u16("airtime_flags", 0600, phyd, &local->airtime_flags); + DEBUGFS_ADD(airtime_queued); statsd = debugfs_create_dir("statistics", phyd); diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 9de5390411ba..6bebfe80ed29 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -63,6 +63,12 @@ struct ieee80211_local; #define IEEE80211_RECIPROCAL_DIVISOR 0x100000000ULL #define IEEE80211_RECIPROCAL_SHIFT 32 +/* constants used for airtime queue limit */ +#define IEEE80211_AIRTIME_QUEUE_LIMIT 8000 /* 8 ms */ +#define IEEE80211_AIRTIME_OVERHEAD 100 +#define IEEE80211_AIRTIME_OVERHEAD_IFS 16 +#define IEEE80211_AIRTIME_MINRATE_RECIPROCAL (IEEE80211_RECIPROCAL_DIVISOR / 6000) + /* * Some APs experience problems when working with U-APSD. Decreasing the * probability of that happening by using legacy mode for all ACs but VO isn't @@ -1144,6 +1150,7 @@ struct ieee80211_local { spinlock_t active_txq_lock[IEEE80211_NUM_ACS]; struct list_head active_txqs[IEEE80211_NUM_ACS]; u16 schedule_round[IEEE80211_NUM_ACS]; + u32 airtime_queued[IEEE80211_NUM_ACS]; u16 airtime_flags; diff --git a/net/mac80211/status.c b/net/mac80211/status.c index ab8ba5835ca0..e63a70657050 100644 --- a/net/mac80211/status.c +++ b/net/mac80211/status.c @@ -711,6 +711,28 @@ static void ieee80211_report_used_skb(struct ieee80211_local *local, skb->wifi_acked = acked; } + if (info->control.tx_time_est) { + u8 *qc, ac; + int tid; + + if (ieee80211_is_data_qos(hdr->frame_control)) { + qc = ieee80211_get_qos_ctl(hdr); + tid = qc[0] & 0xf; + ac = ieee80211_ac_from_tid(tid); + } else { + ac = IEEE80211_AC_BE; + } + + spin_lock_bh(&local->active_txq_lock[ac]); + /* sanity check to make sure we don't underflow */ + if (WARN_ON_ONCE(info->control.tx_time_est > local->airtime_queued[ac])) + local->airtime_queued[ac] = 0; + else + local->airtime_queued[ac] -= info->control.tx_time_est; + spin_unlock_bh(&local->active_txq_lock[ac]); + + } + ieee80211_led_tx(local); if (skb_has_frag_list(skb)) { diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 1fa422782905..2b8564621ecf 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -3546,9 +3546,19 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, struct ieee80211_tx_data tx; ieee80211_tx_result r; struct ieee80211_vif *vif = txq->vif; + u32 airtime = 0, airtime_queued; + u8 ac = txq->ac; + u32 pktlen; WARN_ON_ONCE(softirq_count() == 0); + spin_lock_bh(&local->active_txq_lock[ac]); + airtime_queued = local->airtime_queued[ac]; + spin_unlock_bh(&local->active_txq_lock[ac]); + + if (airtime_queued > IEEE80211_AIRTIME_QUEUE_LIMIT) + return NULL; + begin: spin_lock_bh(&fq->lock); @@ -3581,8 +3591,19 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, tx.skb = skb; tx.sdata = vif_to_sdata(info->control.vif); - if (txq->sta) + pktlen = skb->len + 38; + if (txq->sta) { tx.sta = container_of(txq->sta, struct sta_info, sta); + if (tx.sta->last_tx_bitrate) { + airtime = (pktlen * 8 * 1000 * + tx.sta->last_tx_bitrate_reciprocal) >> IEEE80211_RECIPROCAL_SHIFT; + airtime += IEEE80211_AIRTIME_OVERHEAD; + } + } else { + airtime = (pktlen * 8 * 1000 * + IEEE80211_AIRTIME_MINRATE_RECIPROCAL) >> IEEE80211_RECIPROCAL_SHIFT; + airtime += IEEE80211_AIRTIME_OVERHEAD; + } /* * The key can be removed while the packet was queued, so need to call @@ -3659,6 +3680,15 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, } IEEE80211_SKB_CB(skb)->control.vif = vif; + + if (airtime) { + info->control.tx_time_est = airtime; + + spin_lock_bh(&local->active_txq_lock[ac]); + local->airtime_queued[ac] += airtime; + spin_unlock_bh(&local->active_txq_lock[ac]); + } + return skb; out: @@ -3676,6 +3706,9 @@ struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac) spin_lock_bh(&local->active_txq_lock[ac]); + if (local->airtime_queued[ac] > IEEE80211_AIRTIME_QUEUE_LIMIT) + goto out; + begin: txqi = list_first_entry_or_null(&local->active_txqs[ac], struct txq_info, @@ -3753,6 +3786,9 @@ bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw, spin_lock_bh(&local->active_txq_lock[ac]); + if (local->airtime_queued[ac] > IEEE80211_AIRTIME_QUEUE_LIMIT) + goto out; + if (!txqi->txq.sta) goto out;