linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 12/49] perf: replace bitmap_weight with bitmap_empty where appropriate
       [not found] <20220210224933.379149-1-yury.norov@gmail.com>
@ 2022-02-10 22:48 ` Yury Norov
  2022-02-11 10:25   ` Mark Rutland
  2022-02-11 17:27   ` Christophe JAILLET
  2022-02-10 22:49 ` [PATCH 17/49] cpufreq: replace cpumask_weight with cpumask_empty " Yury Norov
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 14+ messages in thread
From: Yury Norov @ 2022-02-10 22:48 UTC (permalink / raw)
  To: Yury Norov, Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Will Deacon, Mark Rutland, Shaokun Zhang, Qi Liu, Khuong Dinh,
	linux-arm-kernel

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>
---
 drivers/perf/arm-cci.c                   | 2 +-
 drivers/perf/arm_pmu.c                   | 4 ++--
 drivers/perf/hisilicon/hisi_uncore_pmu.c | 2 +-
 drivers/perf/xgene_pmu.c                 | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c
index 54aca3a62814..96e09fa40909 100644
--- a/drivers/perf/arm-cci.c
+++ b/drivers/perf/arm-cci.c
@@ -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)
diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
index 295cc7952d0e..a31b302b0ade 100644
--- a/drivers/perf/arm_pmu.c
+++ b/drivers/perf/arm_pmu.c
@@ -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;
diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pmu.c
index a738aeab5c04..358e4e284a62 100644
--- a/drivers/perf/hisilicon/hisi_uncore_pmu.c
+++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c
@@ -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)
diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
index 5283608dc055..0c32dffc7ede 100644
--- a/drivers/perf/xgene_pmu.c
+++ b/drivers/perf/xgene_pmu.c
@@ -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)
-- 
2.32.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 17/49] cpufreq: replace cpumask_weight with cpumask_empty where appropriate
       [not found] <20220210224933.379149-1-yury.norov@gmail.com>
  2022-02-10 22:48 ` [PATCH 12/49] perf: replace bitmap_weight with bitmap_empty where appropriate Yury Norov
@ 2022-02-10 22:49 ` Yury Norov
  2022-02-11  4:30   ` Viresh Kumar
  2022-02-10 22:49 ` [PATCH 33/49] perf: replace bitmap_weight with bitmap_weight_eq for ThunderX2 Yury Norov
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Yury Norov @ 2022-02-10 22:49 UTC (permalink / raw)
  To: Yury Norov, Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Andy Gross, Bjorn Andersson, Rafael J. Wysocki, Viresh Kumar,
	Sudeep Holla, Cristian Marussi, linux-arm-msm, linux-pm,
	linux-arm-kernel

drivers/cpufreq calls cpumask_weight() to check if any bit of a given
cpumask is set. We can do it more efficiently with cpumask_empty() because
cpumask_empty() stops traversing the cpumask as soon as it finds first set
bit, while cpumask_weight() counts all bits unconditionally.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> (for SCMI cpufreq driver)
---
 drivers/cpufreq/qcom-cpufreq-hw.c | 2 +-
 drivers/cpufreq/scmi-cpufreq.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c
index 05f3d7876e44..95a0c57ab5bb 100644
--- a/drivers/cpufreq/qcom-cpufreq-hw.c
+++ b/drivers/cpufreq/qcom-cpufreq-hw.c
@@ -482,7 +482,7 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
 	}
 
 	qcom_get_related_cpus(index, policy->cpus);
-	if (!cpumask_weight(policy->cpus)) {
+	if (cpumask_empty(policy->cpus)) {
 		dev_err(dev, "Domain-%d failed to get related CPUs\n", index);
 		ret = -ENOENT;
 		goto error;
diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
index 1e0cd4d165f0..919fa6e3f462 100644
--- a/drivers/cpufreq/scmi-cpufreq.c
+++ b/drivers/cpufreq/scmi-cpufreq.c
@@ -154,7 +154,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 	 * table and opp-shared.
 	 */
 	ret = dev_pm_opp_of_get_sharing_cpus(cpu_dev, priv->opp_shared_cpus);
-	if (ret || !cpumask_weight(priv->opp_shared_cpus)) {
+	if (ret || cpumask_empty(priv->opp_shared_cpus)) {
 		/*
 		 * Either opp-table is not set or no opp-shared was found.
 		 * Use the CPU mask from SCMI to designate CPUs sharing an OPP
-- 
2.32.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 33/49] perf: replace bitmap_weight with bitmap_weight_eq for ThunderX2
       [not found] <20220210224933.379149-1-yury.norov@gmail.com>
  2022-02-10 22:48 ` [PATCH 12/49] perf: replace bitmap_weight with bitmap_empty where appropriate Yury Norov
  2022-02-10 22:49 ` [PATCH 17/49] cpufreq: replace cpumask_weight with cpumask_empty " Yury Norov
@ 2022-02-10 22:49 ` Yury Norov
  2022-02-11 10:30   ` Mark Rutland
  2022-02-10 22:49 ` [PATCH 40/49] firmware: pcsi: replace cpumask_weight with cpumask_weight_eq Yury Norov
  2022-02-10 22:49 ` [PATCH 43/49] soc/qman: replace cpumask_weight with cpumask_weight_lt Yury Norov
  4 siblings, 1 reply; 14+ messages in thread
From: Yury Norov @ 2022-02-10 22:49 UTC (permalink / raw)
  To: Yury Norov, Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Will Deacon, Mark Rutland, linux-arm-kernel

tx2_uncore_event_start() calls bitmap_weight() to compare the weight
of bitmap with a given number. We can do it more efficiently with
bitmap_weight_eq because conditional bitmap_weight may stop traversing
the bitmap earlier, as soon as condition is (or can't be) met.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 drivers/perf/thunderx2_pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/perf/thunderx2_pmu.c b/drivers/perf/thunderx2_pmu.c
index 1edb9c03704f..97d5b39778fa 100644
--- a/drivers/perf/thunderx2_pmu.c
+++ b/drivers/perf/thunderx2_pmu.c
@@ -623,8 +623,8 @@ static void tx2_uncore_event_start(struct perf_event *event, int flags)
 		return;
 
 	/* Start timer for first event */
-	if (bitmap_weight(tx2_pmu->active_counters,
-				tx2_pmu->max_counters) == 1) {
+	if (bitmap_weight_eq(tx2_pmu->active_counters,
+				tx2_pmu->max_counters, 1)) {
 		hrtimer_start(&tx2_pmu->hrtimer,
 			ns_to_ktime(tx2_pmu->hrtimer_interval),
 			HRTIMER_MODE_REL_PINNED);
-- 
2.32.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 40/49] firmware: pcsi: replace cpumask_weight with cpumask_weight_eq
       [not found] <20220210224933.379149-1-yury.norov@gmail.com>
                   ` (2 preceding siblings ...)
  2022-02-10 22:49 ` [PATCH 33/49] perf: replace bitmap_weight with bitmap_weight_eq for ThunderX2 Yury Norov
@ 2022-02-10 22:49 ` Yury Norov
  2022-02-11  9:45   ` Sudeep Holla
  2022-02-11 10:32   ` Mark Rutland
  2022-02-10 22:49 ` [PATCH 43/49] soc/qman: replace cpumask_weight with cpumask_weight_lt Yury Norov
  4 siblings, 2 replies; 14+ messages in thread
From: Yury Norov @ 2022-02-10 22:49 UTC (permalink / raw)
  To: Yury Norov, Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Mark Rutland, Lorenzo Pieralisi, linux-arm-kernel

down_and_up_cpus() calls cpumask_weight() to compare the weight of
cpumask with a given number. We can do it more efficiently with
cpumask_weight_{eq, ...} because conditional cpumask_weight may stop
traversing the cpumask earlier, as soon as condition is (or can't be) met.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 drivers/firmware/psci/psci_checker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firmware/psci/psci_checker.c b/drivers/firmware/psci/psci_checker.c
index 116eb465cdb4..90c9473832a9 100644
--- a/drivers/firmware/psci/psci_checker.c
+++ b/drivers/firmware/psci/psci_checker.c
@@ -90,7 +90,7 @@ static unsigned int down_and_up_cpus(const struct cpumask *cpus,
 		 * cpu_down() checks the number of online CPUs before the TOS
 		 * resident CPU.
 		 */
-		if (cpumask_weight(offlined_cpus) + 1 == nb_available_cpus) {
+		if (cpumask_weight_eq(offlined_cpus, nb_available_cpus - 1)) {
 			if (ret != -EBUSY) {
 				pr_err("Unexpected return code %d while trying "
 				       "to power down last online CPU %d\n",
-- 
2.32.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 43/49] soc/qman: replace cpumask_weight with cpumask_weight_lt
       [not found] <20220210224933.379149-1-yury.norov@gmail.com>
                   ` (3 preceding siblings ...)
  2022-02-10 22:49 ` [PATCH 40/49] firmware: pcsi: replace cpumask_weight with cpumask_weight_eq Yury Norov
@ 2022-02-10 22:49 ` Yury Norov
  4 siblings, 0 replies; 14+ messages in thread
From: Yury Norov @ 2022-02-10 22:49 UTC (permalink / raw)
  To: Yury Norov, Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Li Yang, linuxppc-dev, linux-arm-kernel

qman_test_stash() calls cpumask_weight() to compare the weight of cpumask
with a given number. We can do it more efficiently with cpumask_weight_lt
because conditional cpumask_weight may stop traversing the cpumask earlier,
as soon as condition is (or can't be) met.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 drivers/soc/fsl/qbman/qman_test_stash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/soc/fsl/qbman/qman_test_stash.c b/drivers/soc/fsl/qbman/qman_test_stash.c
index b7e8e5ec884c..28b08568a349 100644
--- a/drivers/soc/fsl/qbman/qman_test_stash.c
+++ b/drivers/soc/fsl/qbman/qman_test_stash.c
@@ -561,7 +561,7 @@ int qman_test_stash(void)
 {
 	int err;
 
-	if (cpumask_weight(cpu_online_mask) < 2) {
+	if (cpumask_weight_lt(cpu_online_mask, 2)) {
 		pr_info("%s(): skip - only 1 CPU\n", __func__);
 		return 0;
 	}
-- 
2.32.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 17/49] cpufreq: replace cpumask_weight with cpumask_empty where appropriate
  2022-02-10 22:49 ` [PATCH 17/49] cpufreq: replace cpumask_weight with cpumask_empty " Yury Norov
@ 2022-02-11  4:30   ` Viresh Kumar
  2022-02-11  5:17     ` Yury Norov
  0 siblings, 1 reply; 14+ messages in thread
From: Viresh Kumar @ 2022-02-11  4:30 UTC (permalink / raw)
  To: Yury Norov
  Cc: Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Andy Gross, Bjorn Andersson, Rafael J. Wysocki, Sudeep Holla,
	Cristian Marussi, linux-arm-msm, linux-pm, linux-arm-kernel

On 10-02-22, 14:49, Yury Norov wrote:
> drivers/cpufreq calls cpumask_weight() to check if any bit of a given
> cpumask is set. We can do it more efficiently with cpumask_empty() because
> cpumask_empty() stops traversing the cpumask as soon as it finds first set
> bit, while cpumask_weight() counts all bits unconditionally.
> 
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
> Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> (for SCMI cpufreq driver)
> ---
>  drivers/cpufreq/qcom-cpufreq-hw.c | 2 +-
>  drivers/cpufreq/scmi-cpufreq.c    | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)

I already applied it yesterday and replied to you as well. Did I miss
something ?

-- 
viresh

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 17/49] cpufreq: replace cpumask_weight with cpumask_empty where appropriate
  2022-02-11  4:30   ` Viresh Kumar
@ 2022-02-11  5:17     ` Yury Norov
  0 siblings, 0 replies; 14+ messages in thread
From: Yury Norov @ 2022-02-11  5:17 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Andy Gross, Bjorn Andersson, Rafael J. Wysocki, Sudeep Holla,
	Cristian Marussi, linux-arm-msm, linux-pm, linux-arm-kernel

On Fri, Feb 11, 2022 at 10:00:57AM +0530, Viresh Kumar wrote:
> On 10-02-22, 14:49, Yury Norov wrote:
> > drivers/cpufreq calls cpumask_weight() to check if any bit of a given
> > cpumask is set. We can do it more efficiently with cpumask_empty() because
> > cpumask_empty() stops traversing the cpumask as soon as it finds first set
> > bit, while cpumask_weight() counts all bits unconditionally.
> > 
> > Signed-off-by: Yury Norov <yury.norov@gmail.com>
> > Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> (for SCMI cpufreq driver)
> > ---
> >  drivers/cpufreq/qcom-cpufreq-hw.c | 2 +-
> >  drivers/cpufreq/scmi-cpufreq.c    | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> I already applied it yesterday and replied to you as well. Did I miss
> something ?

It appeared in next today after I prepared this series, that's why it
slipped through. Sorry for that. Please ignore this patch.

Thanks,
Yury

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 40/49] firmware: pcsi: replace cpumask_weight with cpumask_weight_eq
  2022-02-10 22:49 ` [PATCH 40/49] firmware: pcsi: replace cpumask_weight with cpumask_weight_eq Yury Norov
@ 2022-02-11  9:45   ` Sudeep Holla
  2022-02-11 10:32   ` Mark Rutland
  1 sibling, 0 replies; 14+ messages in thread
From: Sudeep Holla @ 2022-02-11  9:45 UTC (permalink / raw)
  To: Yury Norov
  Cc: Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Sudeep Holla, Joe Perches, Dennis Zhou,
	Emil Renner Berthing, Nicholas Piggin, Matti Vaittinen,
	Alexey Klimov, linux-kernel, Mark Rutland, Lorenzo Pieralisi,
	linux-arm-kernel

On Thu, Feb 10, 2022 at 02:49:24PM -0800, Yury Norov wrote:
> down_and_up_cpus() calls cpumask_weight() to compare the weight of
> cpumask with a given number. We can do it more efficiently with
> cpumask_weight_{eq, ...} because conditional cpumask_weight may stop
> traversing the cpumask earlier, as soon as condition is (or can't be) met.
>

Nit: s/pcsi/psci/ in $subject. With that fixed,

Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>

-- 
Regards,
Sudeep

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 12/49] perf: replace bitmap_weight with bitmap_empty where appropriate
  2022-02-10 22:48 ` [PATCH 12/49] perf: replace bitmap_weight with bitmap_empty where appropriate Yury Norov
@ 2022-02-11 10:25   ` Mark Rutland
  2022-02-11 17:59     ` Yury Norov
  2022-02-11 17:27   ` Christophe JAILLET
  1 sibling, 1 reply; 14+ messages in thread
From: Mark Rutland @ 2022-02-11 10:25 UTC (permalink / raw)
  To: Yury Norov, Will Deacon
  Cc: Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Shaokun Zhang, Qi Liu, Khuong Dinh, linux-arm-kernel

Hi Yury,

On Thu, Feb 10, 2022 at 02:48:56PM -0800, Yury Norov wrote:
> 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>

This looks like a nice semantic cleanup to me, so FWIW:

Acked-by: Mark Rutland <mark.rutland@arm.com>

How are you expecting to queue all of this? Should Will and I pick this patch?

Thanks,
Mark.

> ---
>  drivers/perf/arm-cci.c                   | 2 +-
>  drivers/perf/arm_pmu.c                   | 4 ++--
>  drivers/perf/hisilicon/hisi_uncore_pmu.c | 2 +-
>  drivers/perf/xgene_pmu.c                 | 2 +-
>  4 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c
> index 54aca3a62814..96e09fa40909 100644
> --- a/drivers/perf/arm-cci.c
> +++ b/drivers/perf/arm-cci.c
> @@ -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)
> diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
> index 295cc7952d0e..a31b302b0ade 100644
> --- a/drivers/perf/arm_pmu.c
> +++ b/drivers/perf/arm_pmu.c
> @@ -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;
> diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pmu.c
> index a738aeab5c04..358e4e284a62 100644
> --- a/drivers/perf/hisilicon/hisi_uncore_pmu.c
> +++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c
> @@ -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)
> diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
> index 5283608dc055..0c32dffc7ede 100644
> --- a/drivers/perf/xgene_pmu.c
> +++ b/drivers/perf/xgene_pmu.c
> @@ -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)
> -- 
> 2.32.0
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 33/49] perf: replace bitmap_weight with bitmap_weight_eq for ThunderX2
  2022-02-10 22:49 ` [PATCH 33/49] perf: replace bitmap_weight with bitmap_weight_eq for ThunderX2 Yury Norov
@ 2022-02-11 10:30   ` Mark Rutland
  0 siblings, 0 replies; 14+ messages in thread
From: Mark Rutland @ 2022-02-11 10:30 UTC (permalink / raw)
  To: Yury Norov, Will Deacon
  Cc: Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	linux-arm-kernel

On Thu, Feb 10, 2022 at 02:49:17PM -0800, Yury Norov wrote:
> tx2_uncore_event_start() calls bitmap_weight() to compare the weight
> of bitmap with a given number. We can do it more efficiently with
> bitmap_weight_eq because conditional bitmap_weight may stop traversing
> the bitmap earlier, as soon as condition is (or can't be) met.
> 
> Signed-off-by: Yury Norov <yury.norov@gmail.com>

Given the max counters value is either 4 or 8 I doubt this should matter, but
for consistenct this is fine, so:

Acked-by: Mark Rutland <mark.rutland@arm.com>

I now see bitmap_weight_eq() is introduced within this series, so I assume you
need to queue that and its users together, and will want to take the prior
drivers/perf/ bit together with that.

Thanks,
Mark.

> ---
>  drivers/perf/thunderx2_pmu.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/perf/thunderx2_pmu.c b/drivers/perf/thunderx2_pmu.c
> index 1edb9c03704f..97d5b39778fa 100644
> --- a/drivers/perf/thunderx2_pmu.c
> +++ b/drivers/perf/thunderx2_pmu.c
> @@ -623,8 +623,8 @@ static void tx2_uncore_event_start(struct perf_event *event, int flags)
>  		return;
>  
>  	/* Start timer for first event */
> -	if (bitmap_weight(tx2_pmu->active_counters,
> -				tx2_pmu->max_counters) == 1) {
> +	if (bitmap_weight_eq(tx2_pmu->active_counters,
> +				tx2_pmu->max_counters, 1)) {
>  		hrtimer_start(&tx2_pmu->hrtimer,
>  			ns_to_ktime(tx2_pmu->hrtimer_interval),
>  			HRTIMER_MODE_REL_PINNED);
> -- 
> 2.32.0
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 40/49] firmware: pcsi: replace cpumask_weight with cpumask_weight_eq
  2022-02-10 22:49 ` [PATCH 40/49] firmware: pcsi: replace cpumask_weight with cpumask_weight_eq Yury Norov
  2022-02-11  9:45   ` Sudeep Holla
@ 2022-02-11 10:32   ` Mark Rutland
  1 sibling, 0 replies; 14+ messages in thread
From: Mark Rutland @ 2022-02-11 10:32 UTC (permalink / raw)
  To: Yury Norov
  Cc: Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Lorenzo Pieralisi, linux-arm-kernel

On Thu, Feb 10, 2022 at 02:49:24PM -0800, Yury Norov wrote:
> down_and_up_cpus() calls cpumask_weight() to compare the weight of
> cpumask with a given number. We can do it more efficiently with
> cpumask_weight_{eq, ...} because conditional cpumask_weight may stop
> traversing the cpumask earlier, as soon as condition is (or can't be) met.
> 
> Signed-off-by: Yury Norov <yury.norov@gmail.com>

With the 'pcsi' typo fixed:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  drivers/firmware/psci/psci_checker.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/firmware/psci/psci_checker.c b/drivers/firmware/psci/psci_checker.c
> index 116eb465cdb4..90c9473832a9 100644
> --- a/drivers/firmware/psci/psci_checker.c
> +++ b/drivers/firmware/psci/psci_checker.c
> @@ -90,7 +90,7 @@ static unsigned int down_and_up_cpus(const struct cpumask *cpus,
>  		 * cpu_down() checks the number of online CPUs before the TOS
>  		 * resident CPU.
>  		 */
> -		if (cpumask_weight(offlined_cpus) + 1 == nb_available_cpus) {
> +		if (cpumask_weight_eq(offlined_cpus, nb_available_cpus - 1)) {
>  			if (ret != -EBUSY) {
>  				pr_err("Unexpected return code %d while trying "
>  				       "to power down last online CPU %d\n",
> -- 
> 2.32.0
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 12/49] perf: replace bitmap_weight with bitmap_empty where appropriate
  2022-02-10 22:48 ` [PATCH 12/49] perf: replace bitmap_weight with bitmap_empty where appropriate Yury Norov
  2022-02-11 10:25   ` Mark Rutland
@ 2022-02-11 17:27   ` Christophe JAILLET
  2022-02-11 23:23     ` Yury Norov
  1 sibling, 1 reply; 14+ messages in thread
From: Christophe JAILLET @ 2022-02-11 17:27 UTC (permalink / raw)
  To: Yury Norov, Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Will Deacon, Mark Rutland, Shaokun Zhang, Qi Liu, Khuong Dinh,
	linux-arm-kernel

Le 10/02/2022 à 23:48, Yury Norov a écrit :
> 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>
> ---
>   drivers/perf/arm-cci.c                   | 2 +-
>   drivers/perf/arm_pmu.c                   | 4 ++--
>   drivers/perf/hisilicon/hisi_uncore_pmu.c | 2 +-
>   drivers/perf/xgene_pmu.c                 | 2 +-
>   4 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c
> index 54aca3a62814..96e09fa40909 100644
> --- a/drivers/perf/arm-cci.c
> +++ b/drivers/perf/arm-cci.c
> @@ -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)
> diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
> index 295cc7952d0e..a31b302b0ade 100644
> --- a/drivers/perf/arm_pmu.c
> +++ b/drivers/perf/arm_pmu.c
> @@ -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;
> diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pmu.c
> index a738aeab5c04..358e4e284a62 100644
> --- a/drivers/perf/hisilicon/hisi_uncore_pmu.c
> +++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c
> @@ -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)
> diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
> index 5283608dc055..0c32dffc7ede 100644
> --- a/drivers/perf/xgene_pmu.c
> +++ b/drivers/perf/xgene_pmu.c
> @@ -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);

Would it make sense to call it 'disabled', remove the "!"...

>   
>   	if (!enabled)
... and 'if (disabled)' here?

Just my 2c,

CJ

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 12/49] perf: replace bitmap_weight with bitmap_empty where appropriate
  2022-02-11 10:25   ` Mark Rutland
@ 2022-02-11 17:59     ` Yury Norov
  0 siblings, 0 replies; 14+ messages in thread
From: Yury Norov @ 2022-02-11 17:59 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Will Deacon, Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Shaokun Zhang, Qi Liu, Khuong Dinh, linux-arm-kernel

On Fri, Feb 11, 2022 at 10:25:23AM +0000, Mark Rutland wrote:
> Hi Yury,
> 
> On Thu, Feb 10, 2022 at 02:48:56PM -0800, Yury Norov wrote:
> > 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>
> 
> This looks like a nice semantic cleanup to me, so FWIW:

Thanks :)
 
> Acked-by: Mark Rutland <mark.rutland@arm.com>
> 
> How are you expecting to queue all of this?

I expect maintainers of corresponding subsystems will pick most of the
material. For the rest, I have my own bitmap branch.

> Should Will and I pick this patch?

Yes please.

> Thanks,
> Mark.
> 
> > ---
> >  drivers/perf/arm-cci.c                   | 2 +-
> >  drivers/perf/arm_pmu.c                   | 4 ++--
> >  drivers/perf/hisilicon/hisi_uncore_pmu.c | 2 +-
> >  drivers/perf/xgene_pmu.c                 | 2 +-
> >  4 files changed, 5 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c
> > index 54aca3a62814..96e09fa40909 100644
> > --- a/drivers/perf/arm-cci.c
> > +++ b/drivers/perf/arm-cci.c
> > @@ -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)
> > diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
> > index 295cc7952d0e..a31b302b0ade 100644
> > --- a/drivers/perf/arm_pmu.c
> > +++ b/drivers/perf/arm_pmu.c
> > @@ -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;
> > diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pmu.c
> > index a738aeab5c04..358e4e284a62 100644
> > --- a/drivers/perf/hisilicon/hisi_uncore_pmu.c
> > +++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c
> > @@ -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)
> > diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
> > index 5283608dc055..0c32dffc7ede 100644
> > --- a/drivers/perf/xgene_pmu.c
> > +++ b/drivers/perf/xgene_pmu.c
> > @@ -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)
> > -- 
> > 2.32.0
> > 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 12/49] perf: replace bitmap_weight with bitmap_empty where appropriate
  2022-02-11 17:27   ` Christophe JAILLET
@ 2022-02-11 23:23     ` Yury Norov
  0 siblings, 0 replies; 14+ messages in thread
From: Yury Norov @ 2022-02-11 23:23 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Michał Mirosław, Greg Kroah-Hartman, Peter Zijlstra,
	David Laight, Joe Perches, Dennis Zhou, Emil Renner Berthing,
	Nicholas Piggin, Matti Vaittinen, Alexey Klimov, linux-kernel,
	Will Deacon, Mark Rutland, Shaokun Zhang, Qi Liu, Khuong Dinh,
	linux-arm-kernel

On Fri, Feb 11, 2022 at 06:27:56PM +0100, Christophe JAILLET wrote:
> Le 10/02/2022 à 23:48, Yury Norov a écrit :
> > 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>
> > ---
> >   drivers/perf/arm-cci.c                   | 2 +-
> >   drivers/perf/arm_pmu.c                   | 4 ++--
> >   drivers/perf/hisilicon/hisi_uncore_pmu.c | 2 +-
> >   drivers/perf/xgene_pmu.c                 | 2 +-
> >   4 files changed, 5 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c
> > index 54aca3a62814..96e09fa40909 100644
> > --- a/drivers/perf/arm-cci.c
> > +++ b/drivers/perf/arm-cci.c
> > @@ -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)
> > diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
> > index 295cc7952d0e..a31b302b0ade 100644
> > --- a/drivers/perf/arm_pmu.c
> > +++ b/drivers/perf/arm_pmu.c
> > @@ -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;
> > diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisilicon/hisi_uncore_pmu.c
> > index a738aeab5c04..358e4e284a62 100644
> > --- a/drivers/perf/hisilicon/hisi_uncore_pmu.c
> > +++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c
> > @@ -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)
> > diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
> > index 5283608dc055..0c32dffc7ede 100644
> > --- a/drivers/perf/xgene_pmu.c
> > +++ b/drivers/perf/xgene_pmu.c
> > @@ -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);
> 
> Would it make sense to call it 'disabled', remove the "!"...
> 
> >   	if (!enabled)
> ... and 'if (disabled)' here?

People like positive names (as I do):
        $ git grep bool | grep "= \!" | grep -v "= \!\!" | wc -l
        334

And probably authors chose positive name in this case for a reason.

Replacing 'enabled' with 'disabled' just to avoid negation will add
absolutely nothing to performance, neither to readability. But noise
level of this and other patches will increase - just for nothing.

For me it sounds like total negative commitment.

Thanks,
Yury

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-02-11 23:27 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20220210224933.379149-1-yury.norov@gmail.com>
2022-02-10 22:48 ` [PATCH 12/49] perf: replace bitmap_weight with bitmap_empty where appropriate Yury Norov
2022-02-11 10:25   ` Mark Rutland
2022-02-11 17:59     ` Yury Norov
2022-02-11 17:27   ` Christophe JAILLET
2022-02-11 23:23     ` Yury Norov
2022-02-10 22:49 ` [PATCH 17/49] cpufreq: replace cpumask_weight with cpumask_empty " Yury Norov
2022-02-11  4:30   ` Viresh Kumar
2022-02-11  5:17     ` Yury Norov
2022-02-10 22:49 ` [PATCH 33/49] perf: replace bitmap_weight with bitmap_weight_eq for ThunderX2 Yury Norov
2022-02-11 10:30   ` Mark Rutland
2022-02-10 22:49 ` [PATCH 40/49] firmware: pcsi: replace cpumask_weight with cpumask_weight_eq Yury Norov
2022-02-11  9:45   ` Sudeep Holla
2022-02-11 10:32   ` Mark Rutland
2022-02-10 22:49 ` [PATCH 43/49] soc/qman: replace cpumask_weight with cpumask_weight_lt Yury Norov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).