Messages in this thread Patch in this message | | | Subject | Optimisation for smp_num_cpus loop in hotplug | Date | Thu, 20 Jun 2002 19:41:52 -0400 | From | 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
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |