perf: replace bitmap_weight with bitmap_empty where appropriate
authorYury Norov <yury.norov@gmail.com>
Thu, 10 Feb 2022 22:48:56 +0000 (14:48 -0800)
committerWill Deacon <will@kernel.org>
Tue, 15 Feb 2022 14:38:57 +0000 (14:38 +0000)
In some places, drivers/perf code calls bitmap_weight() to check if any
bit of a given bitmap is set. It's better to use bitmap_empty() in that
case because bitmap_empty() stops traversing the bitmap as soon as it
finds first set bit, while bitmap_weight() counts all bits unconditionally.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/20220210224933.379149-13-yury.norov@gmail.com
Signed-off-by: Will Deacon <will@kernel.org>
drivers/perf/arm-cci.c
drivers/perf/arm_pmu.c
drivers/perf/hisilicon/hisi_uncore_pmu.c
drivers/perf/xgene_pmu.c

index 54aca3a62814719804e05df7700134bcd2adaaf1..96e09fa4090954f98bb4493610c138ad81c70c60 100644 (file)
@@ -1096,7 +1096,7 @@ static void cci_pmu_enable(struct pmu *pmu)
 {
        struct cci_pmu *cci_pmu = to_cci_pmu(pmu);
        struct cci_pmu_hw_events *hw_events = &cci_pmu->hw_events;
-       int enabled = bitmap_weight(hw_events->used_mask, cci_pmu->num_cntrs);
+       bool enabled = !bitmap_empty(hw_events->used_mask, cci_pmu->num_cntrs);
        unsigned long flags;
 
        if (!enabled)
index 295cc7952d0edf9d622727357d1c3d607ac4aa0b..a31b302b0aded51172a81ba8484724f48bc6426a 100644 (file)
@@ -524,7 +524,7 @@ static void armpmu_enable(struct pmu *pmu)
 {
        struct arm_pmu *armpmu = to_arm_pmu(pmu);
        struct pmu_hw_events *hw_events = this_cpu_ptr(armpmu->hw_events);
-       int enabled = bitmap_weight(hw_events->used_mask, armpmu->num_events);
+       bool enabled = !bitmap_empty(hw_events->used_mask, armpmu->num_events);
 
        /* For task-bound events we may be called on other CPUs */
        if (!cpumask_test_cpu(smp_processor_id(), &armpmu->supported_cpus))
@@ -785,7 +785,7 @@ static int cpu_pm_pmu_notify(struct notifier_block *b, unsigned long cmd,
 {
        struct arm_pmu *armpmu = container_of(b, struct arm_pmu, cpu_pm_nb);
        struct pmu_hw_events *hw_events = this_cpu_ptr(armpmu->hw_events);
-       int enabled = bitmap_weight(hw_events->used_mask, armpmu->num_events);
+       bool enabled = !bitmap_empty(hw_events->used_mask, armpmu->num_events);
 
        if (!cpumask_test_cpu(smp_processor_id(), &armpmu->supported_cpus))
                return NOTIFY_DONE;
index a738aeab5c04985f1fe6b7cf4b21eeb312d50511..358e4e284a62905e64bfba49e58260005afb8761 100644 (file)
@@ -393,7 +393,7 @@ EXPORT_SYMBOL_GPL(hisi_uncore_pmu_read);
 void hisi_uncore_pmu_enable(struct pmu *pmu)
 {
        struct hisi_pmu *hisi_pmu = to_hisi_pmu(pmu);
-       int enabled = bitmap_weight(hisi_pmu->pmu_events.used_mask,
+       bool enabled = !bitmap_empty(hisi_pmu->pmu_events.used_mask,
                                    hisi_pmu->num_counters);
 
        if (!enabled)
index 5283608dc055b0acbeecc545e9e3601263eb10a9..0c32dffc7edefda0e17abb48d5c0dd6907ea1add 100644 (file)
@@ -867,7 +867,7 @@ static void xgene_perf_pmu_enable(struct pmu *pmu)
 {
        struct xgene_pmu_dev *pmu_dev = to_pmu_dev(pmu);
        struct xgene_pmu *xgene_pmu = pmu_dev->parent;
-       int enabled = bitmap_weight(pmu_dev->cntr_assign_mask,
+       bool enabled = !bitmap_empty(pmu_dev->cntr_assign_mask,
                        pmu_dev->max_counters);
 
        if (!enabled)