mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julius Bairaktaris <julius@bairaktaris.de>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-wireless@vger.kernel.org,
	"Jeff Johnson" <jjohnson@kernel.org>,
	"Baochen Qiang" <baochen.qiang@oss.qualcomm.com>,
	"Felix Fietkau" <nbd@nbd.name>,
	"Toke Høiland-Jørgensen" <toke@toke.dk>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	ath11k@lists.infradead.org, ath12k@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH wireless-next v2 1/7] wifi: mac80211: compute the airtime estimate in 64 bits
Date: Sat, 28 Nov 2026 17:03:29 +0100	[thread overview]
Message-ID: <20261128160335.1815537-2-julius@bairaktaris.de> (raw)
In-Reply-To: <20261128160335.1815537-1-julius@bairaktaris.de>

ieee80211_calc_rx_airtime() and ieee80211_rate_expected_tx_airtime()
multiply the duration of an AVG_PKT_SIZE frame, in 1/1024 us, by the
frame length in a u32. The product is the airtime in us times 2^20, so
it wraps once the airtime reaches 4096 us. At HT MCS0 a 4096 byte
A-MPDU comes out as 945 us instead of 5041 us.

mt76x0, mt76x2 and mt7603 compute RX airtime in software and pass the
length of a whole A-MPDU to ieee80211_calc_rx_airtime(), so a station
that sends at a low rate is charged a fraction of its airtime.

Do the multiplication in 64 bits. Where it did not wrap, the result is
the same.

Found by the hosted Sashiko review of v1.

Fixes: db3e1c40cf2f ("mac80211: Import airtime calculation code from mt76")
Fixes: f01cfbaf9b29 ("mac80211: improve AQL aggregation estimation for low data rates")
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
v2:
- New. The GSO estimate of v1 1/4 wrapped here.

 net/mac80211/airtime.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/net/mac80211/airtime.c b/net/mac80211/airtime.c
index ee5dc524347c..55bc451d4a9d 100644
--- a/net/mac80211/airtime.c
+++ b/net/mac80211/airtime.c
@@ -616,9 +616,7 @@ u32 ieee80211_calc_rx_airtime(struct ieee80211_hw *hw,
 	if (!duration)
 		return 0;
 
-	duration *= len;
-	duration /= AVG_PKT_SIZE;
-	duration /= 1024;
+	duration = div_u64(mul_u32_u32(duration, len), AVG_PKT_SIZE * 1024);
 
 	return duration + overhead;
 }
@@ -813,8 +811,7 @@ u32 ieee80211_rate_expected_tx_airtime(struct ieee80211_hw *hw,
 	else
 		agg_shift = 6;
 
-	duration *= len;
-	duration /= AVG_PKT_SIZE;
+	duration = div_u64(mul_u32_u32(duration, len), AVG_PKT_SIZE);
 	duration += (overhead * 1024 >> agg_shift);
 
 	return duration;
-- 
2.53.0


  reply	other threads:[~2026-11-28 16:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 16:03 [PATCH wireless-next v2 0/7] wifi: mac80211: TSO and SG for encap offload, and the TID of 802.3 RX frames Julius Bairaktaris
2026-11-28 16:03 ` Julius Bairaktaris [this message]
2026-11-28 16:03 ` [PATCH wireless-next v2 2/7] wifi: mac80211: use the ampdu argument of ieee80211_calc_expected_tx_airtime() Julius Bairaktaris
2026-11-28 16:03 ` [PATCH wireless-next v2 3/7] wifi: mac80211: clamp the AQL airtime estimate before narrowing it Julius Bairaktaris
2026-11-28 16:03 ` [PATCH wireless-next v2 4/7] wifi: mac80211: advertise TSO and SG for encap offloaded frames Julius Bairaktaris
2026-11-28 16:03 ` [PATCH wireless-next v2 5/7] wifi: mac80211: take the TID of an 802.3 frame from the driver Julius Bairaktaris
2026-11-28 16:03 ` [PATCH wireless-next v2 6/7] wifi: ath11k: pass the TID of a received 802.3 frame to mac80211 Julius Bairaktaris
2026-11-28 16:03 ` [PATCH wireless-next v2 7/7] wifi: ath12k: " Julius Bairaktaris

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=20261128160335.1815537-2-julius@bairaktaris.de \
    --to=julius@bairaktaris.de \
    --cc=ath11k@lists.infradead.org \
    --cc=ath12k@lists.infradead.org \
    --cc=baochen.qiang@oss.qualcomm.com \
    --cc=jjohnson@kernel.org \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=nbd@nbd.name \
    --cc=toke@redhat.com \
    --cc=toke@toke.dk \
    /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

all inboxes | Powered by JetHome®