<div dir="ltr"><span id="gmail-docs-internal-guid-b3a47ab7-7fff-cdd2-90be-1bc5b65dcd1e"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">Hi Toke,</span></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">There is an updated version of AQL in the chromiumos tree implemented in the mac80211 driver, instead in the ath10k driver as the original version:</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href="https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1703105/7" style="text-decoration-line:none"><span style="font-size:11pt;font-family:Arial;background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1703105/7</span></a></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href="https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1703106/6" style="text-decoration-line:none"><span style="font-size:11pt;font-family:Arial;background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1703106/6</span></a></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">It is based on a more recent kernel (4.14) and integrated with the airtime fairness tx scheduler in mac80211. This version has been tested rather extensively. I intended to use it as the basis for my effort to bring AQL upstream, but get sidetracked by other things. I can clean it up and send a patchset next week if you think that is the right path. Sorry for the long delay and slack off on the upstream effort. </span></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">There are some concerns in this thread regarding the accuracy of the estimated airtime using the last reported TX rate. It is indeed a rather crude method and did not include retries in the calculation. Besides, there are lags between firmware changing rate and host driver get the rate update. The 16us IFS overhead is only correct for 5G and it is actually 10us for 2.4 G. However, that hardly matters. The goal of AQL is to prevent the firmware/hardware queue from getting bloated or starved. AQL doesn't control the fine grained TX packet scheduling. It is handled by the airtime fairness scheduler and ultimately firmware. There is a lot of headroom in the queue length limit (8-10 ms) to tolerate inaccuracy in the estimate airtime. </span></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">There are two TX airtimes in the newer version (chromiumos 4.14 kernel): The estimated airtime for frames pending in the queue and the airtime reported by the firmware for the frame transmitted, which should be accurate as firmware supposed to take retries and aggregation into account. The airtime fairness scheduler that does the fine grained packet scheduling should used the "accurate" airtime reported by the firmware. That's the reason why the original implementation in the ChromiumOS tree tries to take aggregation size into account when estimate the airtime overhead and the later version doesn't even bother with that. </span></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">Regards,</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">Kan</span></p></span><br class="gmail-Apple-interchange-newline"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 20, 2019 at 6:32 AM Toke Høiland-Jørgensen <<a href="mailto:toke@redhat.com">toke@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Lorenzo Bianconi <<a href="mailto:lorenzo@kernel.org" target="_blank">lorenzo@kernel.org</a>> writes:<br>
<br>
>> Lorenzo Bianconi <<a href="mailto:lorenzo@kernel.org" target="_blank">lorenzo@kernel.org</a>> writes:<br>
>> <br>
>> >> From: Toke Høiland-Jørgensen <<a href="mailto:toke@redhat.com" target="_blank">toke@redhat.com</a>><br>
>> >> <br>
>> >> Some devices have deep buffers in firmware and/or hardware which prevents<br>
>> >> the FQ structure in mac80211 from effectively limiting bufferbloat on the<br>
>> >> link. For Ethernet devices we have BQL to limit the lower-level queues, but<br>
>> >> this cannot be applied to mac80211 because transmit rates can vary wildly<br>
>> >> between packets depending on which station we are transmitting it to.<br>
>> >> <br>
>> >> To overcome this, we can use airtime-based queue limiting (AQL), where we<br>
>> >> estimate the transmission time for each packet before dequeueing it, and<br>
>> >> use that to limit the amount of data in-flight to the hardware. This idea<br>
>> >> was originally implemented as part of the out-of-tree airtime fairness<br>
>> >> patch to ath10k[0] in chromiumos.<br>
>> >> <br>
>> >> This patch ports that idea over to mac80211. The basic idea is simple<br>
>> >> enough: Whenever we dequeue a packet from the TXQs and send it to the<br>
>> >> driver, we estimate its airtime usage, based on the last recorded TX rate<br>
>> >> of the station that packet is destined for. We keep a running per-AC total<br>
>> >> of airtime queued for the whole device, and when that total climbs above 8<br>
>> >> ms' worth of data (corresponding to two maximum-sized aggregates), we<br>
>> >> simply throttle the queues until it drops down again.<br>
>> >> <br>
>> >> The estimated airtime for each skb is stored in the tx_info, so we can<br>
>> >> subtract the same amount from the running total when the skb is freed or<br>
>> >> recycled. The throttling mechanism relies on this accounting to be<br>
>> >> accurate (i.e., that we are not freeing skbs without subtracting any<br>
>> >> airtime they were accounted for), so we put the subtraction into<br>
>> >> ieee80211_report_used_skb().<br>
>> >> <br>
>> >> This patch does *not* include any mechanism to wake a throttled TXQ again,<br>
>> >> on the assumption that this will happen anyway as a side effect of whatever<br>
>> >> freed the skb (most commonly a TX completion).<br>
>> >> <br>
>> >> The throttling mechanism only kicks in if the queued airtime total goes<br>
>> >> above the limit. Since mac80211 calculates the time based on the reported<br>
>> >> last_tx_time from the driver, the whole throttling mechanism only kicks in<br>
>> >> for drivers that actually report this value. With the exception of<br>
>> >> multicast, where we always calculate an estimated tx time on the assumption<br>
>> >> that multicast is transmitted at the lowest (6 Mbps) rate.<br>
>> >> <br>
>> >> The throttling added in this patch is in addition to any throttling already<br>
>> >> performed by the airtime fairness mechanism, and in principle the two<br>
>> >> mechanisms are orthogonal (and currently also uses two different sources of<br>
>> >> airtime). In the future, we could amend this, using the airtime estimates<br>
>> >> calculated by this mechanism as a fallback input to the airtime fairness<br>
>> >> scheduler, to enable airtime fairness even on drivers that don't have a<br>
>> >> hardware source of airtime usage for each station.<br>
>> >> <br>
>> >> [0] <a href="https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/588190/13/drivers/net/wireless-4.2/ath/ath10k/mac.c#3845" rel="noreferrer" target="_blank">https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/588190/13/drivers/net/wireless-4.2/ath/ath10k/mac.c#3845</a><br>
>> >> <br>
>> >> Signed-off-by: Toke Høiland-Jørgensen <<a href="mailto:toke@redhat.com" target="_blank">toke@redhat.com</a>><br>
>> >> ---<br>
>> >> net/mac80211/debugfs.c | 24 ++++++++++++++++++++++++<br>
>> >> net/mac80211/ieee80211_i.h | 7 +++++++<br>
>> >> net/mac80211/status.c | 22 ++++++++++++++++++++++<br>
>> >> net/mac80211/tx.c | 38 +++++++++++++++++++++++++++++++++++++-<br>
>> >> 4 files changed, 90 insertions(+), 1 deletion(-)<br>
>> ><br>
>> > Hi Toke,<br>
>> ><br>
>> > Thx a lot for working on this. Few comments inline.<br>
>> ><br>
>> > Regards,<br>
>> > Lorenzo<br>
>> ><br>
>> >> <br>
>> >> diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c<br>
>> >> index 568b3b276931..c846c6e7f3e3 100644<br>
>> >> --- a/net/mac80211/debugfs.c<br>
>> >> +++ b/net/mac80211/debugfs.c<br>
>> >> @@ -148,6 +148,29 @@ static const struct file_operations aqm_ops = {<br>
>> >> .llseek = default_llseek,<br>
>> >> };<br>
>> >> <br>
>> ><br>
>> > [...]<br>
>> ><br>
>> >> @@ -3581,8 +3591,19 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,<br>
>> >> tx.skb = skb;<br>
>> >> tx.sdata = vif_to_sdata(info->control.vif);<br>
>> >> <br>
>> >> - if (txq->sta)<br>
>> >> + pktlen = skb->len + 38;<br>
>> >> + if (txq->sta) {<br>
>> >> tx.sta = container_of(txq->sta, struct sta_info, sta);<br>
>> >> + if (tx.sta->last_tx_bitrate) {<br>
>> >> + airtime = (pktlen * 8 * 1000 *<br>
>> >> + tx.sta->last_tx_bitrate_reciprocal) >> IEEE80211_RECIPROCAL_SHIFT;<br>
>> >> + airtime += IEEE80211_AIRTIME_OVERHEAD;<br>
>> ><br>
>> > Here we are not taking into account aggregation burst size (it is done<br>
>> > in a rough way in chromeos implementation) and tx retries. I have not<br>
>> > carried out any tests so far but I think IEEE80211_AIRTIME_OVERHEAD<br>
>> > will led to a significant airtime overestimation. Do you think this<br>
>> > can be improved? (..I agree this is not a perfect world, but .. :))<br>
>> <br>
>> Hmm, yeah, looking at this again, the way I'm going this now, I should<br>
>> probably have used the low 16-us IFS overhead for every packet.<br>
>> <br>
>> I guess we could do something similar to what the chromeos thing is<br>
>> doing. I.e., adding a single "large" overhead value when we think the<br>
>> packet is the first of a burst, and using the smaller value for the<br>
>> rest.<br>
>> <br>
>> One approach could be to couple the switch to the "scheduling rounds" we<br>
>> already have. I.e., first packet after a call to<br>
>> ieee8021_txq_schedule_start() will get the 100-us overhead, and every<br>
>> subsequent one will get the low one. Not sure how this will fit with<br>
>> what the driver actually does, though, so I guess some experimentation<br>
>> is in order.<br>
>> <br>
>> Ultimately, I'm not sure it matters that much whether occasionally add<br>
>> 80 us extra to the estimate. But as you say, adding 100 us to every<br>
>> packet is probably a bit much ;)<br>
><br>
> Would it be possible to use the previous tx airtime reported by the<br>
> driver? (not sure if it is feasible). Some drivers can report airtime<br>
> compute in hw, the issue is it can be no not linked to the given skb<br>
> or aggregation burst, so we should take into account burst size<br>
<br>
That's what we do for the fairness scheduler. And yeah, if the HW can<br>
report after-the-fact airtime usage that is bound to be more accurate,<br>
so I think we should keep using that for fairness.<br>
<br>
But for this AQL thing, we really need it ahead of time. However, I<br>
don't think it's as important that it is super accurate. As long as we<br>
have a reasonable estimate I think we'll be fine. We can solve any<br>
inaccuracies by fiddling with the limit, I think. Similar to what BQL<br>
does; dynamically adjusting it up and down.<br>
<br>
So for a first pass, we can just err on the side of having the limit<br>
higher, and then iterate from there.<br>
<br>
>> > Moreover, can this approach be affected by some interrupt coalescing<br>
>> > implemented by the chipset?<br>
>> <br>
>> Probably? Ultimately we don't really know what exactly the chipset is<br>
>> doing, so we're guessing here, no?<br>
><br>
> Here I mean if the hw relies on a 1:n tx interrupt/packet ratio (I<br>
> guess most driver do), it would probably affect throughput, right?<br>
> (e.g TCP)<br>
<br>
Yeah, this is what I alluded to above: If we set the limit too low, were<br>
are going to kill TCP throughput. Ideally, we want the limit to be as<br>
low as we can get it without hurting TCP (too much), but no lower. Just<br>
doing the conversion to airtime is a way to achieve this: This will<br>
scale the actual queue length with the achievable throughput as long as<br>
the tx rate estimate is reasonably accurate. If needed, we can add<br>
another layer of dynamic tuning on top using the existing BQL logic; but<br>
I'd like to get the basic case working first...<br>
<br>
-Toke<br>
<br>
</blockquote></div>