public inbox for linux-wireless@vger.kernel.org
 help / color / mirror / Atom feed
From: Pablo MARTIN-GOMEZ <pmartin-gomez@freebox.fr>
To: Felix Fietkau <nbd@nbd.name>, linux-wireless@vger.kernel.org
Cc: johannes@sipsolutions.net
Subject: Re: [PATCH 1/4] wifi: mac80211: factor out part of ieee80211_calc_expected_tx_airtime
Date: Mon, 23 Mar 2026 17:00:32 +0100	[thread overview]
Message-ID: <900aa78e-b0ca-43de-adae-4053bde4d328@freebox.fr> (raw)
In-Reply-To: <20260323101954.874299-1-nbd@nbd.name>

Hello,

On 23/03/2026 11:19, Felix Fietkau wrote:
> Create ieee80211_rate_expected_tx_airtime helper function, which returns
> the expected tx airtime for a given rate and packet length in units of
> 1024 usec, for more accuracy.
> 
> Signed-off-by: Felix Fietkau <nbd@nbd.name>
> ---
>  net/mac80211/airtime.c     | 87 ++++++++++++++++++++++----------------
>  net/mac80211/ieee80211_i.h |  5 +++
>  2 files changed, 56 insertions(+), 36 deletions(-)
> 
> diff --git a/net/mac80211/airtime.c b/net/mac80211/airtime.c
> index c61df637232a..0c54cdbd753c 100644
> --- a/net/mac80211/airtime.c
> +++ b/net/mac80211/airtime.c
> @@ -685,7 +685,7 @@ static int ieee80211_fill_rx_status(struct ieee80211_rx_status *stat,
>  	if (ieee80211_fill_rate_info(hw, stat, band, ri))
>  		return 0;
>  
> -	if (!ieee80211_rate_valid(rate))
> +	if (!rate || !ieee80211_rate_valid(rate))
>  		return -1;
>  
>  	if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
> @@ -753,6 +753,53 @@ u32 ieee80211_calc_tx_airtime(struct ieee80211_hw *hw,
>  }
>  EXPORT_SYMBOL_GPL(ieee80211_calc_tx_airtime);
>  
> +u32 ieee80211_rate_expected_tx_airtime(struct ieee80211_hw *hw,
> +				       struct ieee80211_tx_rate *tx_rate,
> +				       struct rate_info *ri,
> +				       enum nl80211_band band,
> +				       bool ampdu, int len)
> +{
> +	struct ieee80211_rx_status stat;
> +	u32 duration, overhead;
> +	u8 agg_shift;
> +
> +	if (ieee80211_fill_rx_status(&stat, hw, tx_rate, ri, band, len))
> +		return 0;
> +
> +	if (stat.encoding == RX_ENC_LEGACY || !ampdu)
> +		return ieee80211_calc_rx_airtime(hw, &stat, len) * 1024;
> +
> +	duration = ieee80211_get_rate_duration(hw, &stat, &overhead);
> +
> +	/*
> +	 * Assume that HT/VHT transmission on any AC except VO will
> +	 * use aggregation. Since we don't have reliable reporting
> +	 * of aggregation length, assume an average size based on the
> +	 * tx rate.
> +	 * This will not be very accurate, but much better than simply
> +	 * assuming un-aggregated tx in all cases.
> +	 */
> +	if (duration > 400 * 1024) /* <= VHT20 MCS2 1S */
> +		agg_shift = 1;
> +	else if (duration > 250 * 1024) /* <= VHT20 MCS3 1S or MCS1 2S */
> +		agg_shift = 2;
> +	else if (duration > 150 * 1024) /* <= VHT20 MCS5 1S or MCS2 2S */
> +		agg_shift = 3;
> +	else if (duration > 70 * 1024) /* <= VHT20 MCS5 2S */
> +		agg_shift = 4;
> +	else if (stat.encoding != RX_ENC_HE ||
> +		 duration > 20 * 1024) /* <= HE40 MCS6 2S */
> +		agg_shift = 5;
> +	else
> +		agg_shift = 6;
> +
> +	duration *= len;
> +	duration /= AVG_PKT_SIZE;
> +	duration += (overhead * 1024 >> agg_shift);
I know this patch is just a refactoring, but I think this moved code is
bugged. If (and it's a big if) I understood correctly the chain of
macros and the comments, `ieee80211_get_rate_duration` return the
`duration` in 1024 µs of an average packet (which would imply
1f38b8c564b8 is wrong) and the (PHY) `overhead` in µs for a (average)
packet. So I believe the code should be:
```c
	duration = ieee80211_get_rate_duration(hw, &stat, &overhead);
	duration *= 1024;  /* now duration is in µs */
	/* the agg_shift calculation has to be fixed */
	duration += (overhead >> agg_shift);  /* for one packet, we "assign" a
fraction of the overhead */
	duration *= len/AVG_PKT_SIZE;  /* we multiply by the number of packets */
	duration /= 1024;  /* we go back to a duration in 1024 µs*/

	return duration;
```

If this is correct, then `ieee80211_calc_rx_airtime` is also bugged
likewise.
> +
> +	return duration;
> +}
> +
>  u32 ieee80211_calc_expected_tx_airtime(struct ieee80211_hw *hw,
>  				       struct ieee80211_vif *vif,
>  				       struct ieee80211_sta *pubsta,
Pablo MG

  parent reply	other threads:[~2026-03-23 16:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 10:19 [PATCH 1/4] wifi: mac80211: factor out part of ieee80211_calc_expected_tx_airtime Felix Fietkau
2026-03-23 10:19 ` [PATCH 2/4] wifi: mac80211: estimate expected throughput if not provided by driver/rc Felix Fietkau
2026-03-23 10:35   ` Johannes Berg
2026-03-23 10:19 ` [PATCH 3/4] wifi: mac80211: add AQL support for broadcast packets Felix Fietkau
2026-03-23 10:38   ` Johannes Berg
2026-03-23 10:19 ` [PATCH 4/4] wifi: mac80211: add ieee80211_txq_aql_pending() Felix Fietkau
2026-03-23 10:39   ` Johannes Berg
2026-03-23 10:43     ` Felix Fietkau
2026-03-23 10:55   ` Johannes Berg
2026-03-23 16:00 ` Pablo MARTIN-GOMEZ [this message]
2026-03-25  3:58   ` [PATCH 1/4] wifi: mac80211: factor out part of ieee80211_calc_expected_tx_airtime Felix Fietkau
2026-03-25 11:21     ` Pablo MARTIN-GOMEZ
2026-03-25 11:41       ` Felix Fietkau
2026-03-25 13:05         ` Pablo MARTIN-GOMEZ

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=900aa78e-b0ca-43de-adae-4053bde4d328@freebox.fr \
    --to=pmartin-gomez@freebox.fr \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    --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