From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.bufferbloat.net (Postfix) with ESMTPS id 194DF3B29E for ; Fri, 20 Sep 2019 09:32:48 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1568986367; 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=eIMQ42Sw8Hd9uIst5uE+3wtoqBljS/4EHk2QD30OcGw=; b=hr8QRut3H8bc615tVQA6adVax+CBFJr23pUUqQEtT9nPRzTCbk6BpB9HMXcSCa+c6w/3KX ybdLKOXPMl6Su/mYLR2BgXcjtdEBkjLg9Xt7BdAFQjjFKHoi5JQMVUkVA7s8uuKsSFtq9P 3/hivPta83rgE1CJrejfyJl/Z1KxqJU= 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-39-qaXCePmBPimWZg5drmHJBg-1; Fri, 20 Sep 2019 09:32:43 -0400 Received: by mail-ed1-f70.google.com with SMTP id c90so4202349edf.17 for ; Fri, 20 Sep 2019 06:32:42 -0700 (PDT) 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:in-reply-to:references:date :message-id:mime-version:content-transfer-encoding; bh=aw5DtyEyUsPNvcBwktctk1CLPkf90JBH40BC4AU4FLQ=; b=NHDjbR58jEQRxzaGzDc1AD4yF92u047GxjwYhFMM3ImmbEbqqW3ubCMIPx5vYKK33d 6KCebxBEt7rM0nFygVGu7cwguVJYrGpZwU6OcHRm5xOrjgjwef6fKyHPZb+1wsvNe3Is RqmnOOx6KQ4xukt7cyjhc9bz3Awl+KsA0NkGF74rp6Lm21ZF/Ero66DfQwK6aFmTxEaG uv+Qp5dRqGmV+sVvsSunaZA+ASq2rBBsgePM7KC1f+6Hw5gdV4mo7X3cW7DtLQj/LdnD lt0iDqbeWv0XIQYLEN6E8XJArlESiqtO5qkVtSxYO5tOw4XPMPY5YCi0Yrb7GYPd5jwS c/pA== X-Gm-Message-State: APjAAAX8VCXEZp3EQyEJ6kHAo+m8TKqHwq45YfFEfMF/jPSTJ6qXZnZF 57CYhEX+8YmwweRpeGFlddMr4ooAcW/clAqhY1R1uj7Nk4SW7fCOToQI1Wzvic0eaIdb430fg1w eGc3KRGmtSf3ahAZ+w0TCM8SyjxbQ6quetws= X-Received: by 2002:a17:906:fc2:: with SMTP id c2mr3201393ejk.261.1568986361876; Fri, 20 Sep 2019 06:32:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqzX5AKyrhb7CoEjZB4pRdAo+/QHMDTGEsNTNfbXrC4y9p5KyLu/yEqAAYhF89iw5OWcMQw+Ew== X-Received: by 2002:a17:906:fc2:: with SMTP id c2mr3201378ejk.261.1568986361630; Fri, 20 Sep 2019 06:32:41 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a00:7660:6da:443::2]) by smtp.gmail.com with ESMTPSA id n12sm329437edi.1.2019.09.20.06.32.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 06:32:40 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 5B04718063E; Fri, 20 Sep 2019 15:32:40 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Lorenzo Bianconi Cc: Johannes Berg , linux-wireless@vger.kernel.org, make-wifi-fast@lists.bufferbloat.net, John Crispin , Felix Fietkau In-Reply-To: <20190920130604.GB6456@localhost.localdomain> References: <156889576422.191202.5906619710809654631.stgit@alrua-x1> <156889576869.191202.510507546538322707.stgit@alrua-x1> <20190920120639.GA6456@localhost.localdomain> <87k1a39lgt.fsf@toke.dk> <20190920130604.GB6456@localhost.localdomain> X-Clacks-Overhead: GNU Terry Pratchett Date: Fri, 20 Sep 2019 15:32:40 +0200 Message-ID: <87h8579jpj.fsf@toke.dk> MIME-Version: 1.0 X-MC-Unique: qaXCePmBPimWZg5drmHJBg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Make-wifi-fast] [PATCH RFC/RFT 4/4] mac80211: Apply Airtime-based Queue Limit (AQL) on packet dequeue 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: Fri, 20 Sep 2019 13:32:48 -0000 Lorenzo Bianconi writes: >> Lorenzo Bianconi writes: >>=20 >> >> From: Toke H=C3=B8iland-J=C3=B8rgensen >> >>=20 >> >> Some devices have deep buffers in firmware and/or hardware which prev= ents >> >> the FQ structure in mac80211 from effectively limiting bufferbloat on= the >> >> link. For Ethernet devices we have BQL to limit the lower-level queue= s, but >> >> this cannot be applied to mac80211 because transmit rates can vary wi= ldly >> >> between packets depending on which station we are transmitting it to. >> >>=20 >> >> To overcome this, we can use airtime-based queue limiting (AQL), wher= e 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 fairnes= s >> >> patch to ath10k[0] in chromiumos. >> >>=20 >> >> 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 ab= ove 8 >> >> ms' worth of data (corresponding to two maximum-sized aggregates), we >> >> simply throttle the queues until it drops down again. >> >>=20 >> >> The estimated airtime for each skb is stored in the tx_info, so we ca= n >> >> 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(). >> >>=20 >> >> This patch does *not* include any mechanism to wake a throttled TXQ a= gain, >> >> on the assumption that this will happen anyway as a side effect of wh= atever >> >> freed the skb (most commonly a TX completion). >> >>=20 >> >> The throttling mechanism only kicks in if the queued airtime total go= es >> >> above the limit. Since mac80211 calculates the time based on the repo= rted >> >> last_tx_time from the driver, the whole throttling mechanism only kic= ks in >> >> for drivers that actually report this value. With the exception of >> >> multicast, where we always calculate an estimated tx time on the assu= mption >> >> that multicast is transmitted at the lowest (6 Mbps) rate. >> >>=20 >> >> The throttling added in this patch is in addition to any throttling a= lready >> >> performed by the airtime fairness mechanism, and in principle the two >> >> mechanisms are orthogonal (and currently also uses two different sour= ces of >> >> airtime). In the future, we could amend this, using the airtime estim= ates >> >> calculated by this mechanism as a fallback input to the airtime fairn= ess >> >> scheduler, to enable airtime fairness even on drivers that don't have= a >> >> hardware source of airtime usage for each station. >> >>=20 >> >> [0] https://chromium-review.googlesource.com/c/chromiumos/third_party= /kernel/+/588190/13/drivers/net/wireless-4.2/ath/ath10k/mac.c#3845 >> >>=20 >> >> Signed-off-by: Toke H=C3=B8iland-J=C3=B8rgensen >> >> --- >> >> 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(-) >> > >> > Hi Toke, >> > >> > Thx a lot for working on this. Few comments inline. >> > >> > Regards, >> > Lorenzo >> > >> >>=20 >> >> 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 =3D = { >> >> =09.llseek =3D default_llseek, >> >> }; >> >> =20 >> > >> > [...] >> > >> >> @@ -3581,8 +3591,19 @@ struct sk_buff *ieee80211_tx_dequeue(struct ie= ee80211_hw *hw, >> >> =09tx.skb =3D skb; >> >> =09tx.sdata =3D vif_to_sdata(info->control.vif); >> >> =20 >> >> -=09if (txq->sta) >> >> +=09pktlen =3D skb->len + 38; >> >> +=09if (txq->sta) { >> >> =09=09tx.sta =3D container_of(txq->sta, struct sta_info, sta); >> >> +=09=09if (tx.sta->last_tx_bitrate) { >> >> +=09=09=09airtime =3D (pktlen * 8 * 1000 * >> >> +=09=09=09=09 tx.sta->last_tx_bitrate_reciprocal) >> IEEE80211_RECI= PROCAL_SHIFT; >> >> +=09=09=09airtime +=3D IEEE80211_AIRTIME_OVERHEAD; >> > >> > Here we are not taking into account aggregation burst size (it is done >> > in a rough way in chromeos implementation) and tx retries. I have not >> > carried out any tests so far but I think IEEE80211_AIRTIME_OVERHEAD >> > will led to a significant airtime overestimation. Do you think this >> > can be improved? (..I agree this is not a perfect world, but .. :)) >>=20 >> Hmm, yeah, looking at this again, the way I'm going this now, I should >> probably have used the low 16-us IFS overhead for every packet. >>=20 >> I guess we could do something similar to what the chromeos thing is >> doing. I.e., adding a single "large" overhead value when we think the >> packet is the first of a burst, and using the smaller value for the >> rest. >>=20 >> One approach could be to couple the switch to the "scheduling rounds" we >> already have. I.e., first packet after a call to >> ieee8021_txq_schedule_start() will get the 100-us overhead, and every >> subsequent one will get the low one. Not sure how this will fit with >> what the driver actually does, though, so I guess some experimentation >> is in order. >>=20 >> Ultimately, I'm not sure it matters that much whether occasionally add >> 80 us extra to the estimate. But as you say, adding 100 us to every >> packet is probably a bit much ;) > > Would it be possible to use the previous tx airtime reported by the > driver? (not sure if it is feasible). Some drivers can report airtime > compute in hw, the issue is it can be no not linked to the given skb > or aggregation burst, so we should take into account burst size That's what we do for the fairness scheduler. And yeah, if the HW can report after-the-fact airtime usage that is bound to be more accurate, so I think we should keep using that for fairness. But for this AQL thing, we really need it ahead of time. However, I don't think it's as important that it is super accurate. As long as we have a reasonable estimate I think we'll be fine. We can solve any inaccuracies by fiddling with the limit, I think. Similar to what BQL does; dynamically adjusting it up and down. So for a first pass, we can just err on the side of having the limit higher, and then iterate from there. >> > Moreover, can this approach be affected by some interrupt coalescing >> > implemented by the chipset? >>=20 >> Probably? Ultimately we don't really know what exactly the chipset is >> doing, so we're guessing here, no? > > Here I mean if the hw relies on a 1:n tx interrupt/packet ratio (I > guess most driver do), it would probably affect throughput, right? > (e.g TCP) Yeah, this is what I alluded to above: If we set the limit too low, were are going to kill TCP throughput. Ideally, we want the limit to be as low as we can get it without hurting TCP (too much), but no lower. Just doing the conversion to airtime is a way to achieve this: This will scale the actual queue length with the achievable throughput as long as the tx rate estimate is reasonably accurate. If needed, we can add another layer of dynamic tuning on top using the existing BQL logic; but I'd like to get the basic case working first... -Toke