public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Optimisation for smp_num_cpus loop in hotplug
@ 2002-06-20 23:41 James Bottomley
  2002-06-21 15:14 ` Rusty Russell
  0 siblings, 1 reply; 6+ messages in thread
From: James Bottomley @ 2002-06-20 23:41 UTC (permalink / raw)
  To: Rusty Russell; +Cc: linux-kernel, James.Bottomley

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;

Since the cpu online map is probably going to be quite sparse, could I suggest 
this alternative, which doesn't have to loop 32 times:

===== smp.h 1.11 vs edited =====
--- 1.11/include/asm-i386/smp.h Thu Jun 20 14:04:21 2002
+++ edited/smp.h        Thu Jun 20 12:39:33 2002
@@ -95,6 +95,11 @@
 
 #define cpu_online(cpu) (cpu_online_map & (1<<(cpu)))
 
+#define for_each_cpu(cpu, mask) \
+       for(mask = cpu_online_map; \
+           cpu = __ffs(mask), mask != 0; \
+           mask &= ~(1<<cpu))
+
 extern inline unsigned int num_online_cpus(void)
 {
        return hweight32(cpu_online_map);

I've implemented this for my voyager system (8 cpus, but still a sparse online 
bitmap), mainly because (for historical reasons), I have to do this loop in 
time critical IPI code.

James 



^ permalink raw reply	[flat|nested] 6+ messages in thread
[parent not found: <mailman.1024617156.25656.linux-kernel2news@redhat.com>]

end of thread, other threads:[~2002-06-21 19:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-20 23:41 Optimisation for smp_num_cpus loop in hotplug James Bottomley
2002-06-21 15:14 ` Rusty Russell
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox