Skip to contentSkip to conversation

ice: use better bitmap API

PATCH RESEND Superseded Yury Norov 3 participants 7 messages Feb 25 – Mar 1

Subsystems (7)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yury Norov

author
#0 lore raw

cover ice: use better bitmap API

Use better bitmap API where appropriate.

Original series:

https://lore.kernel.org/all/[email protected]/

RESEND: rebase on top of v7.0-rc1

Yury Norov (3):
bitmap: introduce bitmap_weighted_xor()
ice: use bitmap_weighted_xor() in ice_find_free_recp_res_idx()
ice: use bitmap_empty() in ice_vf_has_no_qs_ena

 drivers/net/ethernet/intel/ice/ice_switch.c |  4 +---
 drivers/net/ethernet/intel/ice/ice_vf_lib.c |  4 ++--
 include/linux/bitmap.h                      | 14 ++++++++++++++
 lib/bitmap.c                                |  7 +++++++
 4 files changed, 24 insertions(+), 5 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH RESEND 1/3 bitmap: introduce bitmap_weighted_xor()

The function helps to XOR bitmaps and calculate Hamming weight of the result in one pass.

---
 include/linux/bitmap.h | 14 ++++++++++++++
 lib/bitmap.c           |  7 +++++++
 2 files changed, 21 insertions(+)
include/linux/bitmap.h +14 -0
index b0395e4ccf90..5485076bb2d0 100644
@@ -168,6 +168,8 @@ void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
 		 const unsigned long *bitmap2, unsigned int nbits);
 unsigned int __bitmap_weighted_or(unsigned long *dst, const unsigned long *bitmap1,
 				  const unsigned long *bitmap2, unsigned int nbits);
+unsigned int __bitmap_weighted_xor(unsigned long *dst, const unsigned long *bitmap1,
+				  const unsigned long *bitmap2, unsigned int nbits);
 void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
 		  const unsigned long *bitmap2, unsigned int nbits);
 bool __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
@@ -352,6 +354,18 @@ unsigned int bitmap_weighted_or(unsigned long *dst, const unsigned long *src1,
 	}
 }
 
+static __always_inline
+unsigned int bitmap_weighted_xor(unsigned long *dst, const unsigned long *src1,
+				const unsigned long *src2, unsigned int nbits)
+{
+	if (small_const_nbits(nbits)) {
+		*dst = *src1 ^ *src2;
+		return hweight_long(*dst & BITMAP_LAST_WORD_MASK(nbits));
+	} else {
+		return __bitmap_weighted_xor(dst, src1, src2, nbits);
+	}
+}
+
 static __always_inline
 void bitmap_xor(unsigned long *dst, const unsigned long *src1,
 		const unsigned long *src2, unsigned int nbits)
lib/bitmap.c +7 -0
index 9dc526507875..a2bcb5b1fe99 100644
@@ -361,6 +361,13 @@ unsigned int __bitmap_weighted_or(unsigned long *dst, const unsigned long *bitma
 	return BITMAP_WEIGHT(({dst[idx] = bitmap1[idx] | bitmap2[idx]; dst[idx]; }), bits);
 }
 
+unsigned int __bitmap_weighted_xor(unsigned long *dst, const unsigned long *bitmap1,
+				  const unsigned long *bitmap2, unsigned int bits)
+{
+	return BITMAP_WEIGHT(({dst[idx] = bitmap1[idx] ^ bitmap2[idx]; dst[idx]; }), bits);
+}
+EXPORT_SYMBOL(__bitmap_weighted_xor);
+
 void __bitmap_set(unsigned long *map, unsigned int start, int len)
 {
 	unsigned long *p = map + BIT_WORD(start);
Signature · 1 line
2.43.0
reviewer
#2 lore raw

Re: [RESEND,1/3] bitmap: introduce bitmap_weighted_xor()

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
bitmap: introduce bitmap_weighted_xor()

The function helps to XOR bitmaps and calculate Hamming weight of the result in one pass.

Quoted 4 lines
include/linux/bitmap.h +0 -0
index b0395e4ccf90..5485076bb2d0 100644

[ ... ]

Quoted 5 lines
include/linux/bitmap.h +1 -0
@@ -352,6 +354,18 @@ unsigned int bitmap_weighted_or(unsigned long *dst, const unsigned long *src1,
 	}
 }
 
+static __always_inline

include/linux/bitmap.h unsigned int bitmap_weighted_or(unsigned long *dst, const unsigned long *src1, · line 367

Quoted 10 lines
include/linux/bitmap.h +10 -0
+unsigned int bitmap_weighted_xor(unsigned long *dst, const unsigned long *src1,
+				const unsigned long *src2, unsigned int nbits)
+{
+	if (small_const_nbits(nbits)) {
+		*dst = *src1 ^ *src2;
+		return hweight_long(*dst & BITMAP_LAST_WORD_MASK(nbits));
+	} else {
+		return __bitmap_weighted_xor(dst, src1, src2, nbits);
+	}
+}

Should bitmap_weighted_xor() be added to the API documentation block near the beginning of this header file? The documentation lists bitmap_weighted_or() at line 48 and bitmap_xor() at line 49. For consistency with the existing pattern, bitmap_weighted_xor() could be documented similarly to:
"bitmap_weighted_xor(dst, src1, src2, nbits) *dst = *src1 ^ *src2. Returns Hamming Weight of dst".

[ ... ]

author
#3 lore raw

PATCH RESEND 2/3 ice: use bitmap_weighted_xor() in ice_find_free_recp_res_idx()

In reply to Yury Norov

Use the right helper and save one bitmaps traverse.

---
 drivers/net/ethernet/intel/ice/ice_switch.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/intel/ice/ice_switch.c +1 -3
index bb0f990fa2c6..6a5875bd9c6b 100644
@@ -4984,10 +4984,8 @@ ice_find_free_recp_res_idx(struct ice_hw *hw, const unsigned long *profiles,
 			  hw->switch_info->recp_list[bit].res_idxs,
 			  ICE_MAX_FV_WORDS);
 
-	bitmap_xor(free_idx, used_idx, possible_idx, ICE_MAX_FV_WORDS);
-
 	/* return number of free indexes */
-	return (u16)bitmap_weight(free_idx, ICE_MAX_FV_WORDS);
+	return (u16)bitmap_weighted_xor(free_idx, used_idx, possible_idx, ICE_MAX_FV_WORDS);
 }
 
 /**
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH RESEND 3/3 ice: use bitmap_empty() in ice_vf_has_no_qs_ena

In reply to Yury Norov

bitmap_empty() is more verbose and efficient, as it stops traversing {r,t}xq_ena as soon as the 1st set bit found.

---
 drivers/net/ethernet/intel/ice/ice_vf_lib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_vf_lib.c +2 -2
index c8bc952f05cd..772f6b07340d 100644
@@ -1210,8 +1210,8 @@ bool ice_is_vf_trusted(struct ice_vf *vf)
  */
 bool ice_vf_has_no_qs_ena(struct ice_vf *vf)
 {
-	return (!bitmap_weight(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF) &&
-		!bitmap_weight(vf->txq_ena, ICE_MAX_RSS_QS_PER_VF));
+	return bitmap_empty(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF) &&
+		bitmap_empty(vf->txq_ena, ICE_MAX_RSS_QS_PER_VF);
 }
 
 /**
Signature · 1 line
2.43.0
maintainer
#5 lore raw
In reply to Yury Norov
Quoted 11 lines · Yury Norov

Use better bitmap API where appropriate.

Original series:

https://lore.kernel.org/all/[email protected]/

RESEND: rebase on top of v7.0-rc1

Yury Norov (3):
bitmap: introduce bitmap_weighted_xor()
ice: use bitmap_weighted_xor() in ice_find_free_recp_res_idx()

Thank you for working on better API.
Do you want this to go through intel, then netdev, tree? Likely that would slow any future user, if you have already one in mind.

Quoted 1 line

ice: use bitmap_empty() in ice_vf_has_no_qs_ena

For unrelated reasons I have one series that will possibly conflict with your patch. Would prefer to not wait/block each other, so will be best if we (Tony) just take this one (in case you will proceed with the first two patches via your tree)

Quoted 7 lines
  drivers/net/ethernet/intel/ice/ice_switch.c |  4 +---
  drivers/net/ethernet/intel/ice/ice_vf_lib.c |  4 ++--
  include/linux/bitmap.h                      | 14 ++++++++++++++
  lib/bitmap.c                                |  7 +++++++
  4 files changed, 24 insertions(+), 5 deletions(-)
author
#6 lore raw
Quoted 17 lines · Przemek Kitszel
Quoted 11 lines · Yury Norov

Use better bitmap API where appropriate.

Original series:

https://lore.kernel.org/all/[email protected]/

RESEND: rebase on top of v7.0-rc1

Yury Norov (3):
bitmap: introduce bitmap_weighted_xor()
ice: use bitmap_weighted_xor() in ice_find_free_recp_res_idx()

Thank you for working on better API.
Do you want this to go through intel, then netdev, tree? Likely that would slow any future user, if you have already one in mind.

Quoted 6 lines
Quoted 1 line

ice: use bitmap_empty() in ice_vf_has_no_qs_ena

For unrelated reasons I have one series that will possibly conflict with your patch. Would prefer to not wait/block each other, so will be best if we (Tony) just take this one (in case you will proceed with the first two patches via your tree)

Another trivial user (recently added) for bitmap_weighted_xx() is xe_pagefault_queue_init() in drivers/gpu/drm/xe/xe_pagefault.c, but it's again the Intel's driver, so it will go with your tree anyways.

I'm not aware of others, so I believe Tony's tree is the best route.

Quoted 5 lines
Quoted 5 lines
  drivers/net/ethernet/intel/ice/ice_switch.c |  4 +---
  drivers/net/ethernet/intel/ice/ice_vf_lib.c |  4 ++--
  include/linux/bitmap.h                      | 14 ++++++++++++++
  lib/bitmap.c                                |  7 +++++++
  4 files changed, 24 insertions(+), 5 deletions(-)

+ Matthew Brost

Attaching a patch for xe_pagefault_queue_init(). Feel free to append it to this series, or let me know if it's better to send it separately.

Thanks,
Yury

From 21804f4ae1674aa166e3566fa898996806ebd3e3 Mon Sep 17 00:00:00 2001
From: Yury Norov <[email protected]>
Date: Wed, 25 Feb 2026 10:02:22 -0500
Subject: [PATCH] drm/xe: switch xe_pagefault_queue_init() to using
bitmap_weighted_or()

The function calls bitmap_or() immediately followed by bitmap_weight(). Switch to using the dedicated bitmap_weighted_or() and save one bitmap traverse.

---
 drivers/gpu/drm/xe/xe_pagefault.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/xe/xe_pagefault.c +1 -2
index 6bee53d6ffc3..c4ce3cfe2164 100644
@@ -285,10 +285,9 @@ static int xe_pagefault_queue_init(struct xe_device *xe,
 		xe_dss_mask_t all_dss;
 		int num_dss, num_eus;
 
-		bitmap_or(all_dss, gt->fuse_topo.g_dss_mask,
+		num_dss = bitmap_weighted_or(all_dss, gt->fuse_topo.g_dss_mask,
 			  gt->fuse_topo.c_dss_mask, XE_MAX_DSS_FUSE_BITS);
 
-		num_dss = bitmap_weight(all_dss, XE_MAX_DSS_FUSE_BITS);
 		num_eus = bitmap_weight(gt->fuse_topo.eu_mask_per_dss,
 					XE_MAX_EU_FUSE_BITS) * num_dss;
 
Signature · 1 line
2.43.0