From: Steve Wahl <steve.wahl@hpe.com>
To: Yury Norov <yury.norov@gmail.com>
Cc: "Emil Renner Berthing" <kernel@esmil.dk>,
"Russ Anderson" <russ.anderson@hpe.com>,
"Steve Wahl" <steve.wahl@hpe.com>,
"Peter Zijlstra" <peterz@infradead.org>,
nouveau@lists.freedesktop.org,
"Dave Hansen" <dave.hansen@linux.intel.com>,
"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
"H. Peter Anvin" <hpa@zytor.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
x86@kernel.org, "Mike Travis" <mike.travis@hpe.com>,
"Ingo Molnar" <mingo@redhat.com>,
"Dennis Zhou" <dennis@kernel.org>,
platform-driver-x86@vger.kernel.org,
"Fenghua Yu" <fenghua.yu@intel.com>,
"Alexey Klimov" <aklimov@redhat.com>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
"Pekka Paalanen" <ppaalanen@gmail.com>,
"Borislav Petkov" <bp@alien8.de>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Andy Lutomirski" <luto@kernel.org>,
"Darren Hart" <dvhart@infradead.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Reinette Chatre" <reinette.chatre@intel.com>,
"Dimitri Sivanich" <dimitri.sivanich@hpe.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Matti Vaittinen" <matti.vaittinen@fi.rohmeurope.com>,
linux-kernel@vger.kernel.org,
"David Laight" <David.Laight@aculab.com>,
"Joe Perches" <joe@perches.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Andy Shevchenko" <andy@infradead.org>
Subject: Re: [Nouveau] [PATCH 15/54] arch/x86: replace cpumask_weight with cpumask_empty where appropriate
Date: Thu, 27 Jan 2022 11:20:33 -0600 [thread overview]
Message-ID: <YfLUYSh8Qyv6wEHd@swahl-home.5wahls.com> (raw)
In-Reply-To: <20220123183925.1052919-16-yury.norov@gmail.com>
Reviewed-by: Steve Wahl <steve.wahl@hpe.com>
On Sun, Jan 23, 2022 at 10:38:46AM -0800, Yury Norov wrote:
> In some cases, arch/x86 code 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>
> ---
> arch/x86/kernel/cpu/resctrl/rdtgroup.c | 14 +++++++-------
> arch/x86/mm/mmio-mod.c | 2 +-
> arch/x86/platform/uv/uv_nmi.c | 2 +-
> 3 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> index b57b3db9a6a7..e23ff03290b8 100644
> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
> @@ -341,14 +341,14 @@ static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
>
> /* Check whether cpus belong to parent ctrl group */
> cpumask_andnot(tmpmask, newmask, &prgrp->cpu_mask);
> - if (cpumask_weight(tmpmask)) {
> + if (!cpumask_empty(tmpmask)) {
> rdt_last_cmd_puts("Can only add CPUs to mongroup that belong to parent\n");
> return -EINVAL;
> }
>
> /* Check whether cpus are dropped from this group */
> cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
> - if (cpumask_weight(tmpmask)) {
> + if (!cpumask_empty(tmpmask)) {
> /* Give any dropped cpus to parent rdtgroup */
> cpumask_or(&prgrp->cpu_mask, &prgrp->cpu_mask, tmpmask);
> update_closid_rmid(tmpmask, prgrp);
> @@ -359,7 +359,7 @@ static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
> * and update per-cpu rmid
> */
> cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
> - if (cpumask_weight(tmpmask)) {
> + if (!cpumask_empty(tmpmask)) {
> head = &prgrp->mon.crdtgrp_list;
> list_for_each_entry(crgrp, head, mon.crdtgrp_list) {
> if (crgrp == rdtgrp)
> @@ -394,7 +394,7 @@ static int cpus_ctrl_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
>
> /* Check whether cpus are dropped from this group */
> cpumask_andnot(tmpmask, &rdtgrp->cpu_mask, newmask);
> - if (cpumask_weight(tmpmask)) {
> + if (!cpumask_empty(tmpmask)) {
> /* Can't drop from default group */
> if (rdtgrp == &rdtgroup_default) {
> rdt_last_cmd_puts("Can't drop CPUs from default group\n");
> @@ -413,12 +413,12 @@ static int cpus_ctrl_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
> * and update per-cpu closid/rmid.
> */
> cpumask_andnot(tmpmask, newmask, &rdtgrp->cpu_mask);
> - if (cpumask_weight(tmpmask)) {
> + if (!cpumask_empty(tmpmask)) {
> list_for_each_entry(r, &rdt_all_groups, rdtgroup_list) {
> if (r == rdtgrp)
> continue;
> cpumask_and(tmpmask1, &r->cpu_mask, tmpmask);
> - if (cpumask_weight(tmpmask1))
> + if (!cpumask_empty(tmpmask1))
> cpumask_rdtgrp_clear(r, tmpmask1);
> }
> update_closid_rmid(tmpmask, rdtgrp);
> @@ -488,7 +488,7 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
>
> /* check that user didn't specify any offline cpus */
> cpumask_andnot(tmpmask, newmask, cpu_online_mask);
> - if (cpumask_weight(tmpmask)) {
> + if (!cpumask_empty(tmpmask)) {
> ret = -EINVAL;
> rdt_last_cmd_puts("Can only assign online CPUs\n");
> goto unlock;
> diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
> index 933a2ebad471..c3317f0650d8 100644
> --- a/arch/x86/mm/mmio-mod.c
> +++ b/arch/x86/mm/mmio-mod.c
> @@ -400,7 +400,7 @@ static void leave_uniprocessor(void)
> int cpu;
> int err;
>
> - if (!cpumask_available(downed_cpus) || cpumask_weight(downed_cpus) == 0)
> + if (!cpumask_available(downed_cpus) || cpumask_empty(downed_cpus))
> return;
> pr_notice("Re-enabling CPUs...\n");
> for_each_cpu(cpu, downed_cpus) {
> diff --git a/arch/x86/platform/uv/uv_nmi.c b/arch/x86/platform/uv/uv_nmi.c
> index 1e9ff28bc2e0..ea277fc08357 100644
> --- a/arch/x86/platform/uv/uv_nmi.c
> +++ b/arch/x86/platform/uv/uv_nmi.c
> @@ -985,7 +985,7 @@ static int uv_handle_nmi(unsigned int reason, struct pt_regs *regs)
>
> /* Clear global flags */
> if (master) {
> - if (cpumask_weight(uv_nmi_cpu_mask))
> + if (!cpumask_empty(uv_nmi_cpu_mask))
> uv_nmi_cleanup_mask();
> atomic_set(&uv_nmi_cpus_in_nmi, -1);
> atomic_set(&uv_nmi_cpu, -1);
> --
> 2.30.2
>
--
Steve Wahl, Hewlett Packard Enterprise
prev parent reply other threads:[~2022-01-27 19:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220123183925.1052919-1-yury.norov@gmail.com>
2022-01-23 18:38 ` [Nouveau] [PATCH 15/54] arch/x86: replace cpumask_weight with cpumask_empty where appropriate Yury Norov
2022-01-27 17:20 ` Steve Wahl [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YfLUYSh8Qyv6wEHd@swahl-home.5wahls.com \
--to=steve.wahl@hpe.com \
--cc=David.Laight@aculab.com \
--cc=aklimov@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andy@infradead.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dennis@kernel.org \
--cc=dimitri.sivanich@hpe.com \
--cc=dvhart@infradead.org \
--cc=fenghua.yu@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=joe@perches.com \
--cc=kernel@esmil.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=luto@kernel.org \
--cc=matti.vaittinen@fi.rohmeurope.com \
--cc=mike.travis@hpe.com \
--cc=mingo@redhat.com \
--cc=mirq-linux@rere.qmqm.pl \
--cc=nouveau@lists.freedesktop.org \
--cc=npiggin@gmail.com \
--cc=peterz@infradead.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=ppaalanen@gmail.com \
--cc=reinette.chatre@intel.com \
--cc=rostedt@goodmis.org \
--cc=russ.anderson@hpe.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).