ice: use better bitmap API
Subsystems (7)
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
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
@@ -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
@@ -361,6 +361,13 @@ unsigned int __bitmap_weighted_or(unsigned long *dst, const unsigned long *bitmareturn 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
Simon Horman
reviewerRe: [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
[ ... ]
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".
[ ... ]
PATCH RESEND 2/3 ice: use bitmap_weighted_xor() in ice_find_free_recp_res_idx()
In reply to Yury NorovUse 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
@@ -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
PATCH RESEND 3/3 ice: use bitmap_empty() in ice_vf_has_no_qs_ena
In reply to Yury Norovbitmap_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
@@ -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
Przemek Kitszel
maintainerQuoted 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: introducebitmap_weighted_xor()
ice: usebitmap_weighted_xor()inice_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()inice_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(-)
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: introducebitmap_weighted_xor()
ice: usebitmap_weighted_xor()inice_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()inice_vf_has_no_qs_enaFor 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
@@ -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