Re: [PATCH v6 2/4] mac80211: Import airtime calculation code from mt76

Toke Høiland-Jørgensen
2019-11-08T10:55:44Z

Johannes Berg <johannes@sipsolutions.net> writes:

> On Wed, 2019-10-23 at 11:59 +0200, Toke Høiland-Jørgensen wrote:
>> From: Toke Høiland-Jørgensen <toke@redhat.com>
>>
>> Felix recently added code to calculate airtime of packets to the mt76
>> driver. Import this into mac80211 so we can use it for airtime queue limit
>> calculations later.
>>
>> The airtime.c file is copied verbatim from the mt76 driver, and adjusted to
>> use mac80211 data structures instead (which is fairly straight forward).
>> The per-rate TX rate calculation is split out to its own
>> function (ieee80211_calc_tx_airtime_rate()) so it can be used directly for
>> the AQL calculations added in a subsequent patch.
>
> Any way it could be exposed by mac80211 back to the drivers, perhaps, to
> share it?

Didn't I already export some of the functions? My intention was to do
that, certainly, and to patch mt76 to switch to using them once the
trees have converged...

>> The only thing that it was not possible to port directly was the bit that
>> read the internal driver flags of struct ieee80211_rate to determine
>> whether a rate is using CCK or OFDM encoding. Instead, just look at the
>> rate index, since at least mt76 and ath10k both seem to have the same
>> number of CCK rates (4) in their tables.
>
> This is highly questionable ...
>
>> + switch (status->encoding) {
>> + case RX_ENC_LEGACY:
>> + if (WARN_ON_ONCE(status->band > NL80211_BAND_5GHZ))
>> + return 0;
>> +
>> + sband = hw->wiphy->bands[status->band];
>> + if (!sband || status->rate_idx > sband->n_bitrates)
>> + return 0;
>> +
>> + rate = &sband->bitrates[status->rate_idx];
>> + cck = (status->rate_idx < CCK_NUM_RATES);

Heh, yeah this did feel like a hack to me as well ;)

> Why not
>
> cck = rate->flags & IEEE80211_RATE_MANDATORY_B;
>
> I mean .. we know that IEEE80211_RATE_MANDATORY_B rates are exactly the
> CCK rates, and that's not really going to change?
>
> Alternatively, we could do
>
> cck = sband->band == NL80211_BAND_2GHZ &&
> !(rate->flags & IEEE80211_RATE_ERP_G);
>
> or even
>
> cck = rate->bitrate == 10 || rate->bitrate == 20 ||
> rate->bitrate == 55 || rate->bitrate == 110;

I am fine with either of those; I just wasn't sure what assumptions I
could actually make here. I guess I'll just pick one :)

>> + default:
>> + WARN_ON_ONCE(1);
>
> You can't do that in mac80211 either. That might be fine for mt76, but
> mac80211 already supports HE.

Good point, will fix.

-Toke