From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from nbd.name (nbd.name [46.4.11.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CA2A2DCF72 for ; Wed, 25 Mar 2026 03:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.4.11.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774411107; cv=none; b=X69WPQhuDAYbKW8Updl12BnVJP1CEZQZVJuXI/CF2I9VcI6xbKRcWPzvqYSRJuXZNyFC7d2hOWtd8UVk/d8ri9vcHMfBQrZ/BWNDJjOivCq1ERUsYbcCzNl1/sAZn2VlyRJOHGHxtou5quwnisy7nhdtvZtteEotD8DkxhlH26A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774411107; c=relaxed/simple; bh=iE3xjGVJ/6eu6GxRtQOyXtaGtJ7EZSG44jZWzVYoqrQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=WWU9E88ktVsVhaxlTGpe4KttubBZqJ5gRHd/mGllmKzbPOAG1JhkCIp2+85LvKTs0MGfEijoMvt5134c5mlF5yPHDYp5e1ZGOrC3RIlA8PT7O1j2XJrNNDG5ERHpySUla5CWiO2T5JfpSnWL/94aIRYeRPjbg3UsMAY0T6tSDU8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nbd.name; spf=pass smtp.mailfrom=nbd.name; dkim=pass (1024-bit key) header.d=nbd.name header.i=@nbd.name header.b=hmQkn1zw; arc=none smtp.client-ip=46.4.11.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nbd.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nbd.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nbd.name header.i=@nbd.name header.b="hmQkn1zw" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=v9Ex7hD80hBVTRRmfINP5eftE39Fv+TMGzzOpyC6G5U=; b=hmQkn1zw8vzE0CE5Ery/OUnYR/ FqYs40TWNc8dJ4kZ5R/D0s35vT2JFCLnzrfOBcWyhgGAaL7jlWUEgU8uQxM9EU6FMDxKa403NdcPw MF1crHpdqjXoWA7/WDlINxxoPjTWFeghgOCpgFKhD7y6Y11eSbiGea2kTKcaM3WWakUY=; Received: from p200300cadf082f0005b2d20964363def.dip0.t-ipconnect.de ([2003:ca:df08:2f00:5b2:d209:6436:3def] helo=nf.local) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1w5FNw-00BrXb-0L; Wed, 25 Mar 2026 04:58:24 +0100 Message-ID: <0f56f76d-7820-4392-88f7-78f24b9ff421@nbd.name> Date: Wed, 25 Mar 2026 04:58:23 +0100 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/4] wifi: mac80211: factor out part of ieee80211_calc_expected_tx_airtime To: Pablo MARTIN-GOMEZ , linux-wireless@vger.kernel.org Cc: johannes@sipsolutions.net References: <20260323101954.874299-1-nbd@nbd.name> <900aa78e-b0ca-43de-adae-4053bde4d328@freebox.fr> Content-Language: en-US From: Felix Fietkau Autocrypt: addr=nbd@nbd.name; keydata= xsDiBE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Sj7qFFQcD4laADVsabTpNNpaV4wAgVTRHKV/kC9luItzwDnUcsZUPdQ f3MueRJ3jIHU0UmRBG3uQftqbZJj3ikhnfvyLmkCNe+/hXhPu9sGvXyi2D4vszICvc1KL4RD aLSrOsROx22eZ26KqcW4ny7+va2FnvjsZgI8h4sDmaLzKczVRIiLITiMpLFEU/VoSv0m1F4B FtRgoiyjFzigWG0MsTdAN6FJzGh4mWWGIlE7o5JraNhnTd+yTUIPtw3ym6l8P+gbvfoZida0 TspgwBWLnXQvP5EDvlZnNaKa/3oBes6z0QdaSOwZCRA3QSLHBwtgUsrT6RxRSweLrcabwkkE GBECAAkFAkah5FQCGwwACgkQ130UHQKnbvW2GgCeMncXpbbWNT2AtoAYICrKyX5R3iMAoMhw cL98efvrjdstUfTCP2pfetyN In-Reply-To: <900aa78e-b0ca-43de-adae-4053bde4d328@freebox.fr> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 23.03.26 17:00, Pablo MARTIN-GOMEZ wrote: > 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 >> --- >> 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; > ``` The overhead (preamble, signal field, etc.) is a fixed per-frame PHY cost that doesn't depend on how many data bytes are in the frame. In the aggregated case, agg_shift amortizes that fixed cost across the estimated number of subframes in the aggregate. So the correct order is: scale the data duration to the actual packet size, then add the amortized overhead once. This is the same pattern used in ieee80211_calc_rx_airtime: duration *= len; duration /= AVG_PKT_SIZE; duration /= 1024; return duration + overhead; Your proposed rewrite would multiply the overhead by len / AVG_PKT_SIZE, making it proportional to packet size, which is incorrect, because a 512-byte frame and a 1500-byte frame have the same PHY preamble duration. - Felix