linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: Johannes Berg <johannes@sipsolutions.net>,
	linux-wireless@vger.kernel.org,
	make-wifi-fast@lists.bufferbloat.net,
	John Crispin <john@phrozen.org>, Felix Fietkau <nbd@nbd.name>
Subject: Re: [PATCH RFC/RFT 4/4] mac80211: Apply Airtime-based Queue Limit (AQL) on packet dequeue
Date: Fri, 20 Sep 2019 15:32:40 +0200	[thread overview]
Message-ID: <87h8579jpj.fsf@toke.dk> (raw)
In-Reply-To: <20190920130604.GB6456@localhost.localdomain>

Lorenzo Bianconi <lorenzo@kernel.org> writes:

>> Lorenzo Bianconi <lorenzo@kernel.org> writes:
>> 
>> >> From: Toke Høiland-Jørgensen <toke@redhat.com>
>> >> 
>> >> 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 <toke@redhat.com>
>> >> ---
>> >>  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
>> >
>> >> 
>> >> 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,
>> >>  };
>> >>  
>> >
>> > [...]
>> >
>> >> @@ -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;
>> >
>> > 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 .. :))
>> 
>> 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.
>> 
>> 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.
>> 
>> 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.
>> 
>> 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?
>> 
>> 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


  reply	other threads:[~2019-09-20 13:32 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-19 12:22 [PATCH RFC/RFT 0/4] Add Airtime Queue Limits (AQL) to mac80211 Toke Høiland-Jørgensen
2019-09-19 12:22 ` [PATCH RFC/RFT 1/4] mac80211: Rearrange ieee80211_tx_info to make room for tx_time_est Toke Høiland-Jørgensen
2019-10-01  8:44   ` Johannes Berg
2019-10-01  9:08     ` Toke Høiland-Jørgensen
2019-10-01  9:12       ` Johannes Berg
2019-10-01  9:39         ` Toke Høiland-Jørgensen
2019-09-19 12:22 ` [PATCH RFC/RFT 2/4] mac80211: Add API function to set the last TX bitrate for a station Toke Høiland-Jørgensen
2019-10-01  8:46   ` Johannes Berg
2019-10-01  9:09     ` Toke Høiland-Jørgensen
2019-09-19 12:22 ` [PATCH RFC/RFT 3/4] ath10k: Pass last TX bitrate up to mac80211 Toke Høiland-Jørgensen
2019-09-19 12:22 ` [PATCH RFC/RFT 4/4] mac80211: Apply Airtime-based Queue Limit (AQL) on packet dequeue Toke Høiland-Jørgensen
2019-09-19 17:44   ` Peter Oh
2019-09-19 17:46     ` Ben Greear
2019-09-19 17:54       ` Peter Oh
2019-09-19 18:03         ` Peter Oh
2019-09-19 18:18           ` [Make-wifi-fast] " Dave Taht
2019-09-19 20:09             ` John Yates
2019-09-19 20:15               ` Toke Høiland-Jørgensen
2019-09-19 18:03         ` Toke Høiland-Jørgensen
2019-09-20 12:06   ` Lorenzo Bianconi
2019-09-20 12:54     ` Toke Høiland-Jørgensen
2019-09-20 13:06       ` Lorenzo Bianconi
2019-09-20 13:32         ` Toke Høiland-Jørgensen [this message]
2019-09-20 22:55           ` Kan Yan
2019-09-21 12:11             ` Toke Høiland-Jørgensen
2019-09-25  7:37   ` Yibo Zhao
2019-09-25  8:11     ` Toke Høiland-Jørgensen
2019-09-25 11:54       ` Yibo Zhao
2019-09-25 12:52         ` Toke Høiland-Jørgensen
2019-09-26  0:27           ` Kan Yan
2019-09-26  0:34             ` Kan Yan
2019-09-26  5:57               ` Toke Høiland-Jørgensen
2019-09-26  6:04             ` Toke Høiland-Jørgensen
2019-09-26 12:53   ` Felix Fietkau
2019-09-26 13:17     ` Toke Høiland-Jørgensen
2019-09-26 13:47       ` Felix Fietkau
2019-09-26 15:19         ` Toke Høiland-Jørgensen
2019-09-27  2:42           ` Kan Yan
2019-09-27  6:12             ` Toke Høiland-Jørgensen
2019-09-27  9:20               ` Yibo Zhao
2019-09-28 20:24                 ` Kan Yan
2019-09-29 19:18                   ` Toke Høiland-Jørgensen
2019-10-01  4:47                     ` Kan Yan
2019-10-01  6:57                       ` Toke Høiland-Jørgensen
2019-09-19 14:12 ` [PATCH RFC/RFT 0/4] Add Airtime Queue Limits (AQL) to mac80211 Toke Høiland-Jørgensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h8579jpj.fsf@toke.dk \
    --to=toke@redhat.com \
    --cc=johannes@sipsolutions.net \
    --cc=john@phrozen.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=make-wifi-fast@lists.bufferbloat.net \
    --cc=nbd@nbd.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).