]> git.hungrycats.org Git - linux/commitdiff
[PATCH] Make for_each_cpu() Iterator More Friendly
authorAndrew Morton <akpm@osdl.org>
Mon, 19 Jan 2004 02:30:46 +0000 (18:30 -0800)
committerLinus Torvalds <torvalds@home.osdl.org>
Mon, 19 Jan 2004 02:30:46 +0000 (18:30 -0800)
From: Rusty Russell <rusty@rustcorp.com.au>

Anton: breaks PPC64, as it needs cpu_possible_mask, but fix is already
in Ameslab tree.

The for_each_cpu() and for_each_online_cpu() iterators take a mask, and
noone uses them that way (except for arch/i386/mach-voyager, which uses
for_each_cpu(cpu_online_mask).  Make them more usable iterators, by
dropping the "mask" arg.

This requires that archs provide a cpu_possible_mask: most do, but PPC64
doesn't, so it is broken by this patch.  The other archs use a #define to
define it in asm/smp.h.

Most places doing loops over cpus testing for cpu_online() should use
for_each_cpu: it is synonymous at the moment, but with the CPU hotplug
patch the difference becomes important.

Followup patches will convert users.

14 files changed:
arch/i386/mach-voyager/voyager_smp.c
include/asm-alpha/smp.h
include/asm-i386/smp.h
include/asm-ia64/smp.h
include/asm-mips/smp.h
include/asm-parisc/smp.h
include/asm-ppc/smp.h
include/asm-s390/smp.h
include/asm-sh/smp.h
include/asm-sparc64/smp.h
include/asm-um/smp.h
include/asm-x86_64/smp.h
include/linux/cpumask.h
include/linux/smp.h

index 1401aa9130d3835e9a8cbb1c34c7a73e94f5d9d0..1f1af175b6f63675a7c3eedf56634a3c28e7ecf0 100644 (file)
@@ -130,7 +130,7 @@ send_QIC_CPI(__u32 cpuset, __u8 cpi)
 {
        int cpu;
 
-       for_each_cpu(cpu, cpu_online_map) {
+       for_each_online_cpu(cpu) {
                if(cpuset & (1<<cpu)) {
 #ifdef VOYAGER_DEBUG
                        if(!cpu_isset(cpu, cpu_online_map))
@@ -1465,7 +1465,7 @@ send_CPI(__u32 cpuset, __u8 cpi)
        cpuset &= 0xff;         /* only first 8 CPUs vaild for VIC CPI */
        if(cpuset == 0)
                return;
-       for_each_cpu(cpu, cpu_online_map) {
+       for_each_online_cpu(cpu) {
                if(cpuset & (1<<cpu))
                        set_bit(cpi, &vic_cpi_mailbox[cpu]);
        }
@@ -1579,7 +1579,7 @@ enable_vic_irq(unsigned int irq)
        VDEBUG(("VOYAGER: enable_vic_irq(%d) CPU%d affinity 0x%lx\n",
                irq, cpu, cpu_irq_affinity[cpu]));
        spin_lock_irqsave(&vic_irq_lock, flags);
-       for_each_cpu(real_cpu, cpu_online_map) {
+       for_each_online_cpu(real_cpu) {
                if(!(voyager_extended_vic_processors & (1<<real_cpu)))
                        continue;
                if(!(cpu_irq_affinity[real_cpu] & mask)) {
@@ -1720,7 +1720,7 @@ after_handle_vic_irq(unsigned int irq)
                        int i;
                        __u8 cpu = smp_processor_id();
                        __u8 real_cpu;
-                       int mask;
+                       int mask; /* Um... initialize me??? --RR */
 
                        printk("VOYAGER SMP: CPU%d lost interrupt %d\n",
                               cpu, irq);
@@ -1809,7 +1809,7 @@ set_vic_irq_affinity(unsigned int irq, cpumask_t mask)
                 * bus) */
                return;
 
-       for_each_cpu(cpu, cpu_online_map) {
+       for_each_online_cpu(cpu) {
                unsigned long cpu_mask = 1 << cpu;
                
                if(cpu_mask & real_mask) {
@@ -1875,7 +1875,7 @@ voyager_smp_dump()
        int old_cpu = smp_processor_id(), cpu;
 
        /* dump the interrupt masks of each processor */
-       for_each_cpu(cpu, cpu_online_map) {
+       for_each_online_cpu(cpu) {
                __u16 imr, isr, irr;
                unsigned long flags;
 
index 0283901c468c880eff9c8a3ec6710b03ed77a48d..d342a017ceb6ea2d1fcebae718bdc8218fb4479b 100644 (file)
@@ -48,8 +48,8 @@ extern struct cpuinfo_alpha cpu_data[NR_CPUS];
 extern cpumask_t cpu_present_mask;
 extern cpumask_t cpu_online_map;
 extern int smp_num_cpus;
+#define cpu_possible_map       cpu_present_mask
 
-#define cpu_possible(cpu)      cpu_isset(cpu, cpu_present_mask)
 #define cpu_online(cpu)                cpu_isset(cpu, cpu_online_map)
 
 extern int smp_call_function_on_cpu(void (*func) (void *info), void *info,int retry, int wait, unsigned long cpu);
index 7736931c188300fdd250dadfe9be81ddc56035ce..edbf16ce86ab5d4e7ef5b40e33a3b3fda16d6f10 100644 (file)
@@ -53,8 +53,7 @@ extern void zap_low_mappings (void);
 #define smp_processor_id() (current_thread_info()->cpu)
 
 extern cpumask_t cpu_callout_map;
-
-#define cpu_possible(cpu) cpu_isset(cpu, cpu_callout_map)
+#define cpu_possible_map cpu_callout_map
 
 /* We don't mark CPUs online until __cpu_up(), so we need another measure */
 static inline int num_booting_cpus(void)
index adb4716f352cbb9fa23251092b316edb32198a1b..deeccd4f8f35b327e07c4c27db81aef6a792a579 100644 (file)
@@ -48,7 +48,7 @@ extern volatile int ia64_cpu_to_sapicid[];
 
 extern unsigned long ap_wakeup_vector;
 
-#define cpu_possible(cpu)      cpu_isset(cpu, phys_cpu_present_map)
+#define cpu_possible_map phys_cpu_present_map
 
 /*
  * Function to map hard smp processor id to logical id.  Slow, so don't use this in
index 1c7e4eea094d4058c8c2e604ffc5f07765636368..c8d1ed35c1cc7325196dbe26bb7ed3777c83c55b 100644 (file)
@@ -48,8 +48,8 @@ extern struct call_data_struct *call_data;
 
 extern cpumask_t phys_cpu_present_map;
 extern cpumask_t cpu_online_map;
+#define cpu_possible_map       phys_cpu_present_map
 
-#define cpu_possible(cpu)      cpu_isset(cpu, phys_cpu_present_map)
 #define cpu_online(cpu)                cpu_isset(cpu, cpu_online_map)
 
 static inline unsigned int num_online_cpus(void)
index 0877e8c9bbf7b021f5530eadbe8cb58034ef3fc1..83e720f79a6e59bdf8056d3621ca5082e572e5d6 100644 (file)
@@ -54,7 +54,7 @@ extern unsigned long cpu_present_mask;
 #define smp_processor_id()     (current_thread_info()->cpu)
 #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map)
 
-#define cpu_possible(cpu)       cpu_isset(cpu, cpu_present_mask)
+#define cpu_possible_map       cpu_present_map
 
 #endif /* CONFIG_SMP */
 
index 8d27f08eeb6e7027478420d401139461a7bbc7a3..803fdb5833487b1888be9f72412ca009a9c3d007 100644 (file)
@@ -48,7 +48,6 @@ extern void smp_local_timer_interrupt(struct pt_regs *);
 #define smp_processor_id() (current_thread_info()->cpu)
 
 #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map)
-#define cpu_possible(cpu) cpu_isset(cpu, cpu_possible_map)
 
 extern int __cpu_up(unsigned int cpu);
 
index 8ce65892de97b0acd16b2a6e988a7a3de34e4c6e..1b9e99a994ee58b848612aca40ad19b5aca305d1 100644 (file)
@@ -49,7 +49,6 @@ extern cpumask_t cpu_possible_map;
 #define smp_processor_id() (S390_lowcore.cpu_data.cpu_nr)
 
 #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map)
-#define cpu_possible(cpu) cpu_isset(cpu, cpu_possible_map)
 
 extern __inline__ __u16 hard_smp_processor_id(void)
 {
index ebb034453b200d827d0c04b1aa32e6cbb52cb09d..38b54469d7d1a1557715f2196f703094a6c93cb1 100644 (file)
@@ -24,7 +24,6 @@ extern cpumask_t cpu_online_map;
 extern cpumask_t cpu_possible_map;
 
 #define cpu_online(cpu)                cpu_isset(cpu, cpu_online_map)
-#define cpu_possible(cpu)      cpu_isset(cpu, cpu_possible_map)
 
 #define smp_processor_id()     (current_thread_info()->cpu)
 
index 7d8378846e559f9e39a4b07966d0f4b0bc029f86..1ad4911ef0de33fa3e339b10c1d3bf690be054c8 100644 (file)
@@ -33,7 +33,7 @@
 extern unsigned char boot_cpu_id;
 
 extern cpumask_t phys_cpu_present_map;
-#define cpu_possible(cpu)      cpu_isset(cpu, phys_cpu_present_map)
+#define cpu_possible_map phys_cpu_present_map
 
 #define cpu_online(cpu)                cpu_isset(cpu, cpu_online_map)
 
index 846461275b2983a4fd41c5a64b5a90c0083faf58..4629de8666a45bd2c2fee84fe328e654b5dc5920 100644 (file)
@@ -20,7 +20,7 @@ extern int hard_smp_processor_id(void);
 #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map)
 
 extern int ncpus;
-#define cpu_possible(cpu) (cpu < ncpus)
+
 
 extern inline void smp_cpus_done(unsigned int maxcpus)
 {
index 28c6f28fa54b31996ced2fa70a2a178765519fa8..41484cb03424f0122a451a5837142c34d4e2f319 100644 (file)
@@ -57,8 +57,7 @@ void smp_stop_cpu(void);
  */
 
 extern cpumask_t cpu_callout_map;
-
-#define cpu_possible(cpu) cpu_isset(cpu, cpu_callout_map)
+#define cpu_possible_map cpu_callout_map
 #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map)
 
 static inline int num_booting_cpus(void)
index 6aa67b15b76fa1ef05ff49d645c59d895a6a1e2d..6fa750a5b26ee8f259bc4748c659f1a9f7fcf9e0 100644 (file)
@@ -8,32 +8,28 @@
 #ifdef CONFIG_SMP
 
 extern cpumask_t cpu_online_map;
+extern cpumask_t cpu_possible_map;
 
 #define num_online_cpus()              cpus_weight(cpu_online_map)
 #define cpu_online(cpu)                        cpu_isset(cpu, cpu_online_map)
+#define cpu_possible(cpu)              cpu_isset(cpu, cpu_possible_map)
+
+#define for_each_cpu_mask(cpu, mask)                                   \
+       for (cpu = first_cpu_const(mk_cpumask_const(mask));             \
+               cpu < NR_CPUS;                                          \
+               cpu = next_cpu_const(cpu, mk_cpumask_const(mask)))
+
+#define for_each_cpu(cpu) for_each_cpu_mask(cpu, cpu_possible_map)
+#define for_each_online_cpu(cpu) for_each_cpu_mask(cpu, cpu_online_map)
 #else
 #define        cpu_online_map                  cpumask_of_cpu(0)
 #define num_online_cpus()              1
 #define cpu_online(cpu)                        ({ BUG_ON((cpu) != 0); 1; })
-#endif
-
-static inline int next_online_cpu(int cpu, cpumask_t map)
-{
-       do
-               cpu = next_cpu_const(cpu, mk_cpumask_const(map));
-       while (cpu < NR_CPUS && !cpu_online(cpu));
-       return cpu;
-}
+#define cpu_possible(cpu)              ({ BUG_ON((cpu) != 0); 1; })
 
-#define for_each_cpu(cpu, map)                                         \
-       for (cpu = first_cpu_const(mk_cpumask_const(map));              \
-               cpu < NR_CPUS;                                          \
-               cpu = next_cpu_const(cpu,mk_cpumask_const(map)))
-
-#define for_each_online_cpu(cpu, map)                                  \
-       for (cpu = first_cpu_const(mk_cpumask_const(map));              \
-               cpu < NR_CPUS;                                          \
-               cpu = next_online_cpu(cpu,map))
+#define for_each_cpu(cpu) for (cpu = 0; cpu < 1; cpu++)
+#define for_each_online_cpu(cpu) for (cpu = 0; cpu < 1; cpu++)
+#endif
 
 extern int __mask_snprintf_len(char *buf, unsigned int buflen,
                const unsigned long *maskp, unsigned int maskbytes);
index c1a74b2345bc24a73ff8a8d26db6d64a1baf8048..9f7feff3ee9e53df3048c17d325217b3a10a27b7 100644 (file)
@@ -103,7 +103,6 @@ void smp_prepare_boot_cpu(void);
 #define on_each_cpu(func,info,retry,wait)      ({ func(info); 0; })
 static inline void smp_send_reschedule(int cpu) { }
 #define num_booting_cpus()                     1
-#define cpu_possible(cpu)                      ({ BUG_ON((cpu) != 0); 1; })
 #define smp_prepare_boot_cpu()                 do {} while (0)
 
 #endif /* !SMP */