From: Rusty Russell <rusty@rustcorp.com.au>
To: James Bottomley <James.Bottomley@steeleye.com>
Cc: linux-kernel@vger.kernel.org, mingo@redhat.com
Subject: Re: Optimisation for smp_num_cpus loop in hotplug
Date: Sat, 22 Jun 2002 01:14:46 +1000 [thread overview]
Message-ID: <E17LQ7b-0000Iz-00@wagner.rustcorp.com.au> (raw)
In-Reply-To: Your message of "Thu, 20 Jun 2002 19:41:52 -0400." <200206202341.g5KNfqU07377@localhost.localdomain>
In message <200206202341.g5KNfqU07377@localhost.localdomain> you write:
> The hotplug CPU patch introduces this to replace the loop over all active CPUs
> abstraction:
>
> for (i = 0; i < NR_CPUS; i++) {
> if (!cpu_online(i))
> continue;
Yeah, it's simple, and none of the current ones are really critical.
But I think we're better off with:
for (i = first_cpu(); i < NR_CPUS; i = next_cpu(i)) {
Which is simple enough not to need an iterator macro, and also has the
bonus of giving irq-balancing et al. an efficient, portable way of
looking for the "next" cpu.
Cheers!
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Name: CPU iterator patch
Author: Rusty Russell
Status: Trivial
D: This patch adds first_cpu() & next_cpu(cpu) for more efficient cpu
D: iteration.
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.24/include/asm-i386/smp.h working-2.5.24-cpu-iter/include/asm-i386/smp.h
--- linux-2.5.24/include/asm-i386/smp.h Thu Jun 20 01:28:51 2002
+++ working-2.5.24-cpu-iter/include/asm-i386/smp.h Sat Jun 22 00:55:46 2002
@@ -107,6 +107,18 @@
return -1;
}
+/* x86 is always linear, ie. cpu_online(0) always true at the moment. */
+static inline unsigned int first_cpu(void)
+{
+ return 0;
+}
+
+/* Return "next" online cpu. Returns NR_CPUS on end. */
+static inline unsigned int next_cpu(unsigned int cpu)
+{
+ return find_next_bit(&cpu_online_map, NR_CPUS, cpu+1);
+}
+
static __inline int hard_smp_processor_id(void)
{
/* we don't want to mark this access volatile - bad code generation */
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.24/include/asm-ia64/smp.h working-2.5.24-cpu-iter/include/asm-ia64/smp.h
--- linux-2.5.24/include/asm-ia64/smp.h Thu Jun 20 01:28:51 2002
+++ working-2.5.24-cpu-iter/include/asm-ia64/smp.h Sat Jun 22 00:59:34 2002
@@ -45,6 +45,17 @@
extern unsigned long ap_wakeup_vector;
+static inline unsigned int first_cpu(void)
+{
+ return __ffs(cpu_online_map);
+}
+
+/* Return "next" online cpu. Returns NR_CPUS on end. */
+static inline unsigned int next_cpu(unsigned int cpu)
+{
+ return find_next_bit(&cpu_online_map, NR_CPUS, cpu+1);
+}
+
#define cpu_online(cpu) (cpu_online_map & (1<<(cpu)))
extern inline unsigned int num_online_cpus(void)
{
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.24/include/asm-ppc/smp.h working-2.5.24-cpu-iter/include/asm-ppc/smp.h
--- linux-2.5.24/include/asm-ppc/smp.h Thu Jun 20 01:28:51 2002
+++ working-2.5.24-cpu-iter/include/asm-ppc/smp.h Sat Jun 22 00:58:37 2002
@@ -47,6 +47,17 @@
#define smp_processor_id() (current_thread_info()->cpu)
+static inline unsigned int first_cpu(void)
+{
+ return __ffs(cpu_online_map);
+}
+
+/* Return "next" online cpu. Returns NR_CPUS on end. */
+static inline unsigned int next_cpu(unsigned int cpu)
+{
+ return find_next_bit(&cpu_online_map, NR_CPUS, cpu+1);
+}
+
#define cpu_online(cpu) (cpu_online_map & (1<<(cpu)))
extern inline unsigned int num_online_cpus(void)
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.24/include/asm-sparc64/smp.h working-2.5.24-cpu-iter/include/asm-sparc64/smp.h
--- linux-2.5.24/include/asm-sparc64/smp.h Fri Jun 21 09:41:55 2002
+++ working-2.5.24-cpu-iter/include/asm-sparc64/smp.h Sat Jun 22 01:06:58 2002
@@ -77,6 +77,17 @@
return -1;
}
+static inline unsigned int first_cpu(void)
+{
+ return __ffs(cpu_online_map);
+}
+
+/* Return "next" online cpu. Returns NR_CPUS on end. */
+static inline unsigned int next_cpu(unsigned int cpu)
+{
+ return find_next_bit(&cpu_online_map, NR_CPUS, cpu+1);
+}
+
/*
* General functions that each host system must provide.
*/
next prev parent reply other threads:[~2002-06-21 15:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-20 23:41 Optimisation for smp_num_cpus loop in hotplug James Bottomley
2002-06-21 15:14 ` Rusty Russell [this message]
2002-06-21 15:31 ` James Bottomley
2002-06-21 19:17 ` Rusty Russell
[not found] <mailman.1024617156.25656.linux-kernel2news@redhat.com>
2002-06-21 4:16 ` Pete Zaitcev
2002-06-21 13:10 ` James Bottomley
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=E17LQ7b-0000Iz-00@wagner.rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=James.Bottomley@steeleye.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.