diff mbox series

wifi: carl9170: micro-optimize carl9170_tx_shift_bm()

Message ID 20250326155200.39895-1-yury.norov@gmail.com (mailing list archive)
State New
Delegated to: Jeff Johnson
Headers show
Series wifi: carl9170: micro-optimize carl9170_tx_shift_bm() | expand

Checks

Context Check Description
wifibot/fixes_present success Fixes tag not required for -next series
wifibot/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
wifibot/tree_selection success Guessed tree name to be wireless-next
wifibot/ynl success Generated files up to date; no warnings/errors; no diff in generated;
wifibot/build_32bit success Errors and warnings before: 0 this patch: 0
wifibot/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
wifibot/build_clang success Errors and warnings before: 0 this patch: 0
wifibot/build_clang_rust success No Rust files in patch. Skipping build
wifibot/build_tools success No tools touched, skip
wifibot/check_selftest success No net selftest shell script
wifibot/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
wifibot/deprecated_api success None detected
wifibot/header_inline success No static functions without inline keyword in header files
wifibot/kdoc success Errors and warnings before: 0 this patch: 0
wifibot/source_inline success Was 0 now: 0
wifibot/verify_fixes success No Fixes tag
wifibot/verify_signedoff success Signed-off-by tag matches author and committer

Commit Message

Yury Norov March 26, 2025, 3:51 p.m. UTC
The function calls bitmap_empty() just before find_first_bit(). Both
functions are O(N). Because find_first_bit() returns >= nbits in case of
empty bitmap, the bitmap_empty() test may be avoided.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 drivers/net/wireless/ath/carl9170/tx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Christian Lamparter March 26, 2025, 8 p.m. UTC | #1
Hi,

On Wed, Mar 26, 2025 at 4:52 PM Yury Norov <yury.norov@gmail.com> wrote:
>
> The function calls bitmap_empty() just before find_first_bit(). Both
> functions are O(N). Because find_first_bit() returns >= nbits in case of
> empty bitmap, the bitmap_empty() test may be avoided.
>

I looked up bitmap_empty():
<https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/bitmap.h#n423>

apart from the small_const_nbits stuff (which carl9170 likely does not qualify
for since from what I remember it's a 128bits bitmap) the function just does:

|   return find_first_bit(src, nbits) == nbits;

so yes, find_first_bit runs twice with same parameters... Unless the
compiler is smart
enough to detect this and (re-)use the intermediate result later. But
I haven't check
if this is the case with any current, old or future compilers. Has anyone?

Anyway, Sure.

> Signed-off-by: Yury Norov <yury.norov@gmail.com>

Acked-by: Christian Lamparter <chunkeey@gmail.com>

> ---
>  drivers/net/wireless/ath/carl9170/tx.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/net/wireless/ath/carl9170/tx.c b/drivers/net/wireless/ath/carl9170/tx.c
> index 0226c31a6cae..b7717f9e1e9b 100644
> --- a/drivers/net/wireless/ath/carl9170/tx.c
> +++ b/drivers/net/wireless/ath/carl9170/tx.c
> @@ -366,8 +366,7 @@ static void carl9170_tx_shift_bm(struct ar9170 *ar,
>         if (WARN_ON_ONCE(off >= CARL9170_BAW_BITS))
>                 return;
>
> -       if (!bitmap_empty(tid_info->bitmap, off))
> -               off = find_first_bit(tid_info->bitmap, off);
> +       off = min(off, find_first_bit(tid_info->bitmap, off));
>
>         tid_info->bsn += off;
>         tid_info->bsn &= 0x0fff;
> --
> 2.43.0
>
diff mbox series

Patch

diff --git a/drivers/net/wireless/ath/carl9170/tx.c b/drivers/net/wireless/ath/carl9170/tx.c
index 0226c31a6cae..b7717f9e1e9b 100644
--- a/drivers/net/wireless/ath/carl9170/tx.c
+++ b/drivers/net/wireless/ath/carl9170/tx.c
@@ -366,8 +366,7 @@  static void carl9170_tx_shift_bm(struct ar9170 *ar,
 	if (WARN_ON_ONCE(off >= CARL9170_BAW_BITS))
 		return;
 
-	if (!bitmap_empty(tid_info->bitmap, off))
-		off = find_first_bit(tid_info->bitmap, off);
+	off = min(off, find_first_bit(tid_info->bitmap, off));
 
 	tid_info->bsn += off;
 	tid_info->bsn &= 0x0fff;