linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: "Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"David Laight" <David.Laight@ACULAB.COM>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Joe Perches" <joe@perches.com>,
	"Julia Lawall" <Julia.Lawall@inria.fr>,
	"Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Nicolas Palix" <nicolas.palix@imag.fr>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
	"Matti Vaittinen" <Matti.Vaittinen@fi.rohmeurope.com>,
	linux-kernel@vger.kernel.org
Cc: Yury Norov <yury.norov@gmail.com>,
	Balbir Singh <sblbir@amazon.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H . Peter Anvin" <hpa@zytor.com>, Huang Rui <ray.huang@amd.com>,
	Ingo Molnar <mingo@redhat.com>,
	"Paul E . McKenney" <paulmck@kernel.org>,
	"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
	Sean Christopherson <seanjc@google.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	x86@kernel.org
Subject: [PATCH 13/22] x86: smp: move cpumask_weight() out of for-loop in remove_siblinginfo
Date: Tue, 10 May 2022 08:47:41 -0700	[thread overview]
Message-ID: <20220510154750.212913-14-yury.norov@gmail.com> (raw)
In-Reply-To: <20220510154750.212913-1-yury.norov@gmail.com>

Because argument of the function is constant inside for_each_cpu()
loop, the cpumask_weight() does the same work O(NR_CPUS) times, while
it may be calculated only once.

This patch moves cpumask_weight() out of the loop and replaces it
with cpumask_weight_eq(). While here, fix comment format.

CC: Balbir Singh <sblbir@amazon.com>
CC: Boris Ostrovsky <boris.ostrovsky@oracle.com>
CC: Borislav Petkov <bp@alien8.de>
CC: Dave Hansen <dave.hansen@linux.intel.com>
CC: H. Peter Anvin <hpa@zytor.com>
CC: Huang Rui <ray.huang@amd.com>
CC: Ingo Molnar <mingo@redhat.com>
CC: Paul E. McKenney <paulmck@kernel.org>
CC: Peter Zijlstra <peterz@infradead.org>
CC: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
CC: Sean Christopherson <seanjc@google.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Tim Chen <tim.c.chen@linux.intel.com>
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 arch/x86/kernel/smpboot.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 5e7f9532a10d..7d948f79ef31 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1605,13 +1605,14 @@ static void remove_siblinginfo(int cpu)
 {
 	int sibling;
 	struct cpuinfo_x86 *c = &cpu_data(cpu);
+	bool last_thread_sibling = cpumask_weight_eq(topology_sibling_cpumask(cpu), 1);
 
 	for_each_cpu(sibling, topology_core_cpumask(cpu)) {
 		cpumask_clear_cpu(cpu, topology_core_cpumask(sibling));
-		/*/
+		/*
 		 * last thread sibling in this cpu core going down
 		 */
-		if (cpumask_weight(topology_sibling_cpumask(cpu)) == 1)
+		if (last_thread_sibling)
 			cpu_data(sibling).booted_cores--;
 	}
 
-- 
2.32.0


  parent reply	other threads:[~2022-05-10 15:58 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-10 15:47 [PATCH 00/21] add coccinelle scripts for {bitmap,cpumask,nodes}_empty() Yury Norov
2022-05-10 15:47 ` [PATCH 01/22] introduce bitmap.cocci Yury Norov
2022-05-10 15:47 ` [PATCH 02/22] introduce cpumask.cocci Yury Norov
2022-05-10 15:47 ` [PATCH 03/22] introduce nodemask.cocci Yury Norov
2022-05-10 15:47 ` [PATCH 04/22] ice: use bitmap_empty() in ice_vf_has_no_qs_ena() Yury Norov
2022-05-10 15:47 ` [PATCH 05/22] iio: replace bitmap_weight with bitmap_weitght_{eq,le} where appropriate Yury Norov
2022-05-14 15:53   ` Jonathan Cameron
2022-05-14 16:31     ` Joe Perches
2022-05-15 16:40       ` Jonathan Cameron
2022-05-10 15:47 ` [PATCH 06/22] octeontx2: use bitmap_empty() instead of bitmap_weight() Yury Norov
2022-05-10 21:31   ` Jakub Kicinski
2022-05-10 15:47 ` [PATCH 07/22] risc-v: replace bitmap_weight with bitmap_empty in riscv_fill_hwcap() Yury Norov
2022-05-10 16:31   ` Anup Patel
2022-05-10 15:47 ` [PATCH 08/22] bitops: introduce MANY_BITS() macro Yury Norov
2022-05-10 16:50   ` Alexei Starovoitov
2022-05-10 17:54     ` David Laight
2022-05-10 19:11       ` Yury Norov
2022-05-11 10:59         ` Rasmus Villemoes
2022-05-10 17:57   ` Max Filippov
2022-05-10 19:16     ` Yury Norov
2022-05-11  4:55       ` Max Filippov
2022-05-10 15:47 ` [PATCH 09/22] qed: replace bitmap_weight() with MANY_BITS() Yury Norov
2022-05-10 15:47 ` [PATCH 10/22] net/mlx5e: simplify mlx5e_set_fecparam() Yury Norov
2022-05-10 15:47 ` [PATCH 11/22] KVM: x86: hyper-v: replace bitmap_weight() with hweight64() Yury Norov
2022-05-16 13:08   ` Vitaly Kuznetsov
2022-05-22 14:53   ` Guenter Roeck
2022-05-22 17:39     ` Yury Norov
2022-05-10 15:47 ` [PATCH 12/22] ia64: cleanup remove_siblinginfo() Yury Norov
2022-05-10 22:33   ` Andrew Morton
2022-05-10 15:47 ` Yury Norov [this message]
2022-05-11  9:47   ` [PATCH 13/22] x86: smp: move cpumask_weight() out of for-loop in remove_siblinginfo Thomas Gleixner
2022-05-10 15:47 ` [PATCH 14/22] x86: smp: use cpumask_weight_eq() " Yury Norov
2022-05-10 15:47 ` [PATCH 15/22] net/mlx5: use cpumask_weight_gt() in irq_pool_request_irq() Yury Norov
2022-05-10 15:47 ` [PATCH 16/22] x86/tsc: use cpumask_weight_gt() in loop_timeout() Yury Norov
2022-05-10 15:47 ` [PATCH 17/22] sched/core: fix opencoded cpumask_any_but() Yury Norov
2022-05-10 16:37   ` Peter Zijlstra
2022-05-10 17:21     ` Valentin Schneider
2022-05-10 15:47 ` [PATCH 18/22] sched/core: remove unneeded cpumask_weight() in sched_core_cpu_{starting,deactivate} Yury Norov
2022-05-10 15:47 ` [PATCH 19/22] sched/core: replace cpumask_weight() with cpumask_weight_eq() where appropriate Yury Norov
2022-05-10 15:47 ` [PATCH 20/22] sched/topology: " Yury Norov
2022-05-10 15:47 ` [PATCH 21/22] cpufreq: use cpumask_weight_gt() in policy_is_shared() Yury Norov
2022-05-11  3:16   ` Viresh Kumar
2022-05-10 15:47 ` [PATCH 22/22] clockevents: use cpumask_weight_eq() in tick_cleanup_dead_cpu() Yury Norov
2022-05-11  8:18   ` Thomas Gleixner

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=20220510154750.212913-14-yury.norov@gmail.com \
    --to=yury.norov@gmail.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=Julia.Lawall@inria.fr \
    --cc=Matti.Vaittinen@fi.rohmeurope.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mingo@redhat.com \
    --cc=mirq-linux@rere.qmqm.pl \
    --cc=nicolas.palix@imag.fr \
    --cc=npiggin@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=ray.huang@amd.com \
    --cc=sblbir@amazon.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@linux.intel.com \
    --cc=x86@kernel.org \
    /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).