From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1732BC433F5 for ; Fri, 11 Feb 2022 10:25:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348884AbiBKKZm (ORCPT ); Fri, 11 Feb 2022 05:25:42 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239028AbiBKKZl (ORCPT ); Fri, 11 Feb 2022 05:25:41 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 62289E5A for ; Fri, 11 Feb 2022 02:25:40 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 04150106F; Fri, 11 Feb 2022 02:25:40 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.87.94]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4C2803F73B; Fri, 11 Feb 2022 02:25:34 -0800 (PST) Date: Fri, 11 Feb 2022 10:25:23 +0000 From: Mark Rutland To: Yury Norov , Will Deacon Cc: Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?utf-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Shaokun Zhang , Qi Liu , Khuong Dinh , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 12/49] perf: replace bitmap_weight with bitmap_empty where appropriate Message-ID: References: <20220210224933.379149-1-yury.norov@gmail.com> <20220210224933.379149-13-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220210224933.379149-13-yury.norov@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 This looks like a nice semantic cleanup to me, so FWIW: Acked-by: Mark Rutland 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 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E06AFC433EF for ; Fri, 11 Feb 2022 10:27:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BtjFpk2c38oxAOB9nE/omWgDbMMLnjSEShNgZWbgQB4=; b=LwPfi2v8JslhG8 XfHVlSEr9yJLJBh7MhIa4Pa84kdZrShxX394fliSifLT+gKaCf4kuH4yxxKoDOnHrhguiSm8rnHTv E0RZ6/zvUr0VMk6AReRqETXx08GCwp7PMUHclkvNb4v/g+wb69MsaH1ht9oh2yoQfCSg4ORZ/ohNw eafPgYE8uPgee/x9h9B8aQdT0rCMfXias0qf2Z645NIhy5T9P+jmuymlneQyJvdg9hF3cLWNvJPYG fqswKdTjaydLMsGE5QMfsIOCpwMHzjh/8dM8OvdHu0VkwtemZU+yeONUY3afmClCbXQ/UFA7e+IFY RIx3SR/ayced0BCdokQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIT7b-006YPQ-Kt; Fri, 11 Feb 2022 10:25:47 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIT7X-006YO8-2g for linux-arm-kernel@lists.infradead.org; Fri, 11 Feb 2022 10:25:45 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 04150106F; Fri, 11 Feb 2022 02:25:40 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.87.94]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4C2803F73B; Fri, 11 Feb 2022 02:25:34 -0800 (PST) Date: Fri, 11 Feb 2022 10:25:23 +0000 From: Mark Rutland To: Yury Norov , Will Deacon Cc: Andy Shevchenko , Rasmus Villemoes , Andrew Morton , =?utf-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Greg Kroah-Hartman , Peter Zijlstra , David Laight , Joe Perches , Dennis Zhou , Emil Renner Berthing , Nicholas Piggin , Matti Vaittinen , Alexey Klimov , linux-kernel@vger.kernel.org, Shaokun Zhang , Qi Liu , Khuong Dinh , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 12/49] perf: replace bitmap_weight with bitmap_empty where appropriate Message-ID: References: <20220210224933.379149-1-yury.norov@gmail.com> <20220210224933.379149-13-yury.norov@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220210224933.379149-13-yury.norov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220211_022543_239036_27632542 X-CRM114-Status: GOOD ( 19.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 This looks like a nice semantic cleanup to me, so FWIW: Acked-by: Mark Rutland 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