Re: [PATCH 3/9] all: replace bitmap_weigth() with bitmap_{empty,full,eq,gt,le}

2021-11-28 Thread Greg Kroah-Hartman
On Sat, Nov 27, 2021 at 07:56:58PM -0800, Yury Norov wrote:
> bitmap_weight() counts all set bits in the bitmap unconditionally.
> However in some cases we can traverse a part of bitmap when we
> only need to check if number of set bits is greater, less or equal
> to some number.
> 
> This patch replaces bitmap_weight() with one of
> bitmap_{empty,full,eq,gt,le), as appropriate.
> 
> In some places driver code has been optimized further, where it's
> trivial.
> 
> Signed-off-by: Yury Norov 
> ---
>  arch/nds32/kernel/perf_event_cpu.c |  4 +---
>  arch/x86/kernel/cpu/resctrl/rdtgroup.c |  4 ++--
>  arch/x86/kvm/hyperv.c  |  8 
>  drivers/crypto/ccp/ccp-dev-v5.c|  5 +
>  drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c   |  2 +-
>  drivers/iio/adc/mxs-lradc-adc.c|  3 +--
>  drivers/iio/dummy/iio_simple_dummy_buffer.c|  4 ++--
>  drivers/iio/industrialio-buffer.c  |  2 +-
>  drivers/iio/industrialio-trigger.c |  2 +-
>  drivers/memstick/core/ms_block.c   |  4 ++--
>  drivers/net/dsa/b53/b53_common.c   |  2 +-
>  drivers/net/ethernet/broadcom/bcmsysport.c |  6 +-
>  drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c   |  4 ++--
>  drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c |  2 +-
>  .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c  |  2 +-
>  .../ethernet/marvell/octeontx2/nic/otx2_flows.c|  8 
>  .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |  2 +-
>  drivers/net/ethernet/mellanox/mlx4/cmd.c   | 10 +++---
>  drivers/net/ethernet/mellanox/mlx4/eq.c|  4 ++--
>  drivers/net/ethernet/mellanox/mlx4/main.c  |  2 +-
>  .../net/ethernet/mellanox/mlx5/core/en_ethtool.c   |  2 +-
>  drivers/net/ethernet/qlogic/qed/qed_dev.c  |  3 +--
>  drivers/net/ethernet/qlogic/qed/qed_rdma.c |  4 ++--
>  drivers/net/ethernet/qlogic/qed/qed_roce.c |  2 +-
>  drivers/perf/arm-cci.c |  2 +-
>  drivers/perf/arm_pmu.c |  4 ++--
>  drivers/perf/hisilicon/hisi_uncore_pmu.c   |  2 +-
>  drivers/perf/thunderx2_pmu.c   |  3 +--
>  drivers/perf/xgene_pmu.c   |  2 +-
>  drivers/pwm/pwm-pca9685.c  |  2 +-
>  drivers/staging/media/tegra-video/vi.c |  2 +-
>  drivers/thermal/intel/intel_powerclamp.c   | 10 --
>  fs/ocfs2/cluster/heartbeat.c   | 14 +++---
>  33 files changed, 57 insertions(+), 75 deletions(-)

After you get the new functions added to the kernel tree, this patch
should be broken up into one-patch-per-subsystem and submitted through
the various subsystem trees.

thanks,

greg k-h


[PATCH 3/9] all: replace bitmap_weigth() with bitmap_{empty, full, eq, gt, le}

2021-11-27 Thread Yury Norov
bitmap_weight() counts all set bits in the bitmap unconditionally.
However in some cases we can traverse a part of bitmap when we
only need to check if number of set bits is greater, less or equal
to some number.

This patch replaces bitmap_weight() with one of
bitmap_{empty,full,eq,gt,le), as appropriate.

In some places driver code has been optimized further, where it's
trivial.

Signed-off-by: Yury Norov 
---
 arch/nds32/kernel/perf_event_cpu.c |  4 +---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c |  4 ++--
 arch/x86/kvm/hyperv.c  |  8 
 drivers/crypto/ccp/ccp-dev-v5.c|  5 +
 drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c   |  2 +-
 drivers/iio/adc/mxs-lradc-adc.c|  3 +--
 drivers/iio/dummy/iio_simple_dummy_buffer.c|  4 ++--
 drivers/iio/industrialio-buffer.c  |  2 +-
 drivers/iio/industrialio-trigger.c |  2 +-
 drivers/memstick/core/ms_block.c   |  4 ++--
 drivers/net/dsa/b53/b53_common.c   |  2 +-
 drivers/net/ethernet/broadcom/bcmsysport.c |  6 +-
 drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c   |  4 ++--
 drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c |  2 +-
 .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c  |  2 +-
 .../ethernet/marvell/octeontx2/nic/otx2_flows.c|  8 
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |  2 +-
 drivers/net/ethernet/mellanox/mlx4/cmd.c   | 10 +++---
 drivers/net/ethernet/mellanox/mlx4/eq.c|  4 ++--
 drivers/net/ethernet/mellanox/mlx4/main.c  |  2 +-
 .../net/ethernet/mellanox/mlx5/core/en_ethtool.c   |  2 +-
 drivers/net/ethernet/qlogic/qed/qed_dev.c  |  3 +--
 drivers/net/ethernet/qlogic/qed/qed_rdma.c |  4 ++--
 drivers/net/ethernet/qlogic/qed/qed_roce.c |  2 +-
 drivers/perf/arm-cci.c |  2 +-
 drivers/perf/arm_pmu.c |  4 ++--
 drivers/perf/hisilicon/hisi_uncore_pmu.c   |  2 +-
 drivers/perf/thunderx2_pmu.c   |  3 +--
 drivers/perf/xgene_pmu.c   |  2 +-
 drivers/pwm/pwm-pca9685.c  |  2 +-
 drivers/staging/media/tegra-video/vi.c |  2 +-
 drivers/thermal/intel/intel_powerclamp.c   | 10 --
 fs/ocfs2/cluster/heartbeat.c   | 14 +++---
 33 files changed, 57 insertions(+), 75 deletions(-)

diff --git a/arch/nds32/kernel/perf_event_cpu.c 
b/arch/nds32/kernel/perf_event_cpu.c
index a78a879e7ef1..05a1cd258356 100644
--- a/arch/nds32/kernel/perf_event_cpu.c
+++ b/arch/nds32/kernel/perf_event_cpu.c
@@ -695,10 +695,8 @@ static void nds32_pmu_enable(struct pmu *pmu)
 {
struct nds32_pmu *nds32_pmu = to_nds32_pmu(pmu);
struct pmu_hw_events *hw_events = nds32_pmu->get_hw_events();
-   int enabled = bitmap_weight(hw_events->used_mask,
-   nds32_pmu->num_events);
 
-   if (enabled)
+   if (!bitmap_empty(hw_events->used_mask, nds32_pmu->num_events))
nds32_pmu->start(nds32_pmu);
 }
 
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c 
b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index b57b3db9a6a7..94e7e6b420e4 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -2749,10 +2749,10 @@ static int __init_one_rdt_domain(struct rdt_domain *d, 
struct resctrl_schema *s,
cfg->new_ctrl = cbm_ensure_valid(cfg->new_ctrl, r);
/*
 * Assign the u32 CBM to an unsigned long to ensure that
-* bitmap_weight() does not access out-of-bound memory.
+* bitmap_weight_le() does not access out-of-bound memory.
 */
tmp_cbm = cfg->new_ctrl;
-   if (bitmap_weight(_cbm, r->cache.cbm_len) < r->cache.min_cbm_bits) {
+   if (bitmap_weight_le(_cbm, r->cache.cbm_len, r->cache.min_cbm_bits) 
{
rdt_last_cmd_printf("No space on %s:%d\n", s->name, d->id);
return -ENOSPC;
}
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 5e19e6e4c2ce..8b72c896e0f1 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -90,7 +90,7 @@ static void synic_update_vector(struct kvm_vcpu_hv_synic 
*synic,
 {
struct kvm_vcpu *vcpu = hv_synic_to_vcpu(synic);
struct kvm_hv *hv = to_kvm_hv(vcpu->kvm);
-   int auto_eoi_old, auto_eoi_new;
+   bool auto_eoi_old, auto_eoi_new;
 
if (vector < HV_SYNIC_FIRST_VALID_VECTOR)
return;
@@ -100,16 +100,16 @@ static void synic_update_vector(struct kvm_vcpu_hv_synic 
*synic,
else
__clear_bit(vector, synic->vec_bitmap);
 
-   auto_eoi_old = bitmap_weight(synic->auto_eoi_bitmap, 256);
+   auto_eoi_old = bitmap_empty(synic->auto_eoi_bitmap, 256);
 
if (synic_has_vector_auto_eoi(synic, vector))
__set_bit(vector,