Skip to contentSkip to conversation

Optimisation for smp_num_cpus loop in hotplug

DISCUSSION Pete Zaitcev 2 participants 2 messages Jun 21, 2002 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Review

Quoted 12 lines
	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:

(quoted diff) +5 -0
+#define for_each_cpu(cpu, mask) \
+       for(mask = cpu_online_map; \
+           cpu = __ffs(mask), mask != 0; \
+           mask &= ~(1<<cpu))
+

This is neat, but I'd like to see it work with O(1) as well. Mingo's code uses some long bitmaps.

-- Pete

#2 lore raw
Quoted 2 lines · [email protected] said:

This is neat, but I'd like to see it work with O(1) as well. Mingo's code uses some long bitmaps.

Well, it's strictly only for the cpu bitmap (and it's designed to be different depending on the arch so you can use arch specific CPU enumeration knowlege). The O(1) optimisation for this is easy:

#ifdef CONFIG_SMP

#define for_each_cpu(cpu, mask) \
        for(mask = cpu_online_map; \
            cpu = __ffs(mask), mask != 0; \
            mask &= ~(1<<cpu))

#else
#define for_each_cpu(cpu, mask) cpu = 1;
#endif

because you don't really want to run an SMP kernel on a machine which has only one cpu. Or did you mean you'd like to see it work with the O(1) scheduler, some kind of generic for_each_set_bit?

James