[PATCH] more for_each_cpu() conversions
authorAndrew Morton <akpm@osdl.org>
Thu, 23 Mar 2006 11:01:05 +0000 (03:01 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Thu, 23 Mar 2006 15:38:17 +0000 (07:38 -0800)
When we stop allocating percpu memory for not-possible CPUs we must not touch
the percpu data for not-possible CPUs at all.  The correct way of doing this
is to test cpu_possible() or to use for_each_cpu().

This patch is a kernel-wide sweep of all instances of NR_CPUS.  I found very
few instances of this bug, if any.  But the patch converts lots of open-coded
test to use the preferred helper macros.

Cc: Mikael Starvik <starvik@axis.com>
Cc: David Howells <dhowells@redhat.com>
Acked-by: Kyle McMartin <kyle@parisc-linux.org>
Cc: Anton Blanchard <anton@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: William Lee Irwin III <wli@holomorphy.com>
Cc: Andi Kleen <ak@muc.de>
Cc: Christian Zankel <chris@zankel.net>
Cc: Philippe Elie <phil.el@wanadoo.fr>
Cc: Nathan Scott <nathans@sgi.com>
Cc: Jens Axboe <axboe@suse.de>
Cc: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
42 files changed:
arch/cris/kernel/irq.c
arch/frv/kernel/irq.c
arch/i386/kernel/cpu/cpufreq/powernow-k8.c
arch/i386/kernel/io_apic.c
arch/i386/kernel/nmi.c
arch/i386/oprofile/nmi_int.c
arch/m32r/kernel/irq.c
arch/mips/kernel/irq.c
arch/mips/kernel/smp.c
arch/mips/sgi-ip27/ip27-irq.c
arch/parisc/kernel/smp.c
arch/powerpc/kernel/irq.c
arch/powerpc/kernel/setup-common.c
arch/powerpc/kernel/setup_32.c
arch/powerpc/platforms/powermac/smp.c
arch/ppc/kernel/setup.c
arch/s390/kernel/smp.c
arch/sh/kernel/irq.c
arch/sh/kernel/setup.c
arch/sh64/kernel/irq.c
arch/sparc/kernel/irq.c
arch/sparc/kernel/smp.c
arch/sparc/kernel/sun4d_irq.c
arch/sparc/kernel/sun4d_smp.c
arch/sparc/kernel/sun4m_smp.c
arch/sparc64/kernel/irq.c
arch/sparc64/kernel/smp.c
arch/x86_64/kernel/irq.c
arch/x86_64/kernel/nmi.c
arch/xtensa/kernel/irq.c
drivers/net/loopback.c
drivers/oprofile/cpu_buffer.c
fs/xfs/linux-2.6/xfs_stats.c
fs/xfs/linux-2.6/xfs_sysctl.c
include/asm-alpha/mmu_context.h
include/asm-alpha/topology.h
include/asm-generic/percpu.h
include/asm-powerpc/percpu.h
include/asm-s390/percpu.h
include/asm-sparc64/percpu.h
include/asm-x86_64/percpu.h
include/linux/genhd.h

index 30deaf1b728a0c3cac3084821d84bbd2a48eb503..b504def3e346944cc65fad1a5b55cc391f145eb1 100644 (file)
@@ -52,9 +52,8 @@ int show_interrupts(struct seq_file *p, void *v)
 
        if (i == 0) {
                seq_printf(p, "           ");
-               for (j=0; j<NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "CPU%d       ",j);
+               for_each_online_cpu(j)
+                       seq_printf(p, "CPU%d       ",j);
                seq_putc(p, '\n');
        }
 
@@ -67,9 +66,8 @@ int show_interrupts(struct seq_file *p, void *v)
 #ifndef CONFIG_SMP
                seq_printf(p, "%10u ", kstat_irqs(i));
 #else
-               for (j = 0; j < NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
+               for_each_online_cpu(j)
+                       seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
 #endif
                seq_printf(p, " %14s", irq_desc[i].handler->typename);
                seq_printf(p, "  %s", action->name);
index 27ab4c30aac677396a6cd975e8fb1d99f904e6e5..11fa326a8f62e76bca30559b913314e3083cded2 100644 (file)
@@ -75,9 +75,8 @@ int show_interrupts(struct seq_file *p, void *v)
        switch (i) {
        case 0:
                seq_printf(p, "           ");
-               for (j = 0; j < NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "CPU%d       ",j);
+               for_each_online_cpu(j)
+                       seq_printf(p, "CPU%d       ",j);
 
                seq_putc(p, '\n');
                break;
@@ -100,9 +99,8 @@ int show_interrupts(struct seq_file *p, void *v)
 #ifndef CONFIG_SMP
                seq_printf(p, "%10u ", kstat_irqs(i));
 #else
-               for (j = 0; j < NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "%10u ", kstat_cpu(j).irqs[i - 1]);
+               for_each_online_cpu(j)
+                       seq_printf(p, "%10u ", kstat_cpu(j).irqs[i - 1]);
 #endif
 
                level = group->sources[ix]->level - frv_irq_levels;
index e11a09207ec89cc74c236ed7efa2fbd5059da8ca..3d5110b65cc3bee0f0baa75c39ada5dbbf42bd4c 100644 (file)
@@ -1145,9 +1145,7 @@ static int __cpuinit powernowk8_init(void)
 {
        unsigned int i, supported_cpus = 0;
 
-       for (i=0; i<NR_CPUS; i++) {
-               if (!cpu_online(i))
-                       continue;
+       for_each_cpu(i) {
                if (check_supported_cpu(i))
                        supported_cpus++;
        }
index fd1c60cfd29455f377352d47b3318da5f6ed3378..311b4e7266f16f891c86c9687af267953bd28c68 100644 (file)
@@ -351,8 +351,8 @@ static inline void rotate_irqs_among_cpus(unsigned long useful_load_threshold)
 {
        int i, j;
        Dprintk("Rotating IRQs among CPUs.\n");
-       for (i = 0; i < NR_CPUS; i++) {
-               for (j = 0; cpu_online(i) && (j < NR_IRQS); j++) {
+       for_each_online_cpu(i) {
+               for (j = 0; j < NR_IRQS; j++) {
                        if (!irq_desc[j].action)
                                continue;
                        /* Is it a significant load ?  */
@@ -381,7 +381,7 @@ static void do_irq_balance(void)
        unsigned long imbalance = 0;
        cpumask_t allowed_mask, target_cpu_mask, tmp;
 
-       for (i = 0; i < NR_CPUS; i++) {
+       for_each_cpu(i) {
                int package_index;
                CPU_IRQ(i) = 0;
                if (!cpu_online(i))
@@ -422,9 +422,7 @@ static void do_irq_balance(void)
                }
        }
        /* Find the least loaded processor package */
-       for (i = 0; i < NR_CPUS; i++) {
-               if (!cpu_online(i))
-                       continue;
+       for_each_online_cpu(i) {
                if (i != CPU_TO_PACKAGEINDEX(i))
                        continue;
                if (min_cpu_irq > CPU_IRQ(i)) {
@@ -441,9 +439,7 @@ tryanothercpu:
         */
        tmp_cpu_irq = 0;
        tmp_loaded = -1;
-       for (i = 0; i < NR_CPUS; i++) {
-               if (!cpu_online(i))
-                       continue;
+       for_each_online_cpu(i) {
                if (i != CPU_TO_PACKAGEINDEX(i))
                        continue;
                if (max_cpu_irq <= CPU_IRQ(i)) 
@@ -619,9 +615,7 @@ static int __init balanced_irq_init(void)
        if (smp_num_siblings > 1 && !cpus_empty(tmp))
                physical_balance = 1;
 
-       for (i = 0; i < NR_CPUS; i++) {
-               if (!cpu_online(i))
-                       continue;
+       for_each_online_cpu(i) {
                irq_cpu_data[i].irq_delta = kmalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
                irq_cpu_data[i].last_irq = kmalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
                if (irq_cpu_data[i].irq_delta == NULL || irq_cpu_data[i].last_irq == NULL) {
@@ -638,9 +632,11 @@ static int __init balanced_irq_init(void)
        else 
                printk(KERN_ERR "balanced_irq_init: failed to spawn balanced_irq");
 failed:
-       for (i = 0; i < NR_CPUS; i++) {
+       for_each_cpu(i) {
                kfree(irq_cpu_data[i].irq_delta);
+               irq_cpu_data[i].irq_delta = NULL;
                kfree(irq_cpu_data[i].last_irq);
+               irq_cpu_data[i].last_irq = NULL;
        }
        return 0;
 }
index 1db34effdd8d3357e545c081b0f1aa3ce749a638..9074818b9473face4d96ead8b36987d61c81a53e 100644 (file)
@@ -143,7 +143,7 @@ static int __init check_nmi_watchdog(void)
        local_irq_enable();
        mdelay((10*1000)/nmi_hz); // wait 10 ticks
 
-       for (cpu = 0; cpu < NR_CPUS; cpu++) {
+       for_each_cpu(cpu) {
 #ifdef CONFIG_SMP
                /* Check cpu_callin_map here because that is set
                   after the timer is started. */
@@ -510,7 +510,7 @@ void touch_nmi_watchdog (void)
         * Just reset the alert counters, (other CPUs might be
         * spinning on locks we hold):
         */
-       for (i = 0; i < NR_CPUS; i++)
+       for_each_cpu(i)
                alert_counter[i] = 0;
 
        /*
index 0493e8b8ec49266618b155fb3490f02854dc70db..1accce50c2c7ddaf1f3b534a5aeab0d92c88b393 100644 (file)
@@ -122,7 +122,7 @@ static void nmi_save_registers(void * dummy)
 static void free_msrs(void)
 {
        int i;
-       for (i = 0; i < NR_CPUS; ++i) {
+       for_each_cpu(i) {
                kfree(cpu_msrs[i].counters);
                cpu_msrs[i].counters = NULL;
                kfree(cpu_msrs[i].controls);
@@ -138,10 +138,7 @@ static int allocate_msrs(void)
        size_t counters_size = sizeof(struct op_msr) * model->num_counters;
 
        int i;
-       for (i = 0; i < NR_CPUS; ++i) {
-               if (!cpu_online(i))
-                       continue;
-
+       for_each_online_cpu(i) {
                cpu_msrs[i].counters = kmalloc(counters_size, GFP_KERNEL);
                if (!cpu_msrs[i].counters) {
                        success = 0;
index 1ce63926a3c02d22d16d4690d28582d9dd819022..a4634b06f67554ffeb3f9c84f33bb213ca493b7b 100644 (file)
@@ -37,9 +37,8 @@ int show_interrupts(struct seq_file *p, void *v)
 
        if (i == 0) {
                seq_printf(p, "           ");
-               for (j=0; j<NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "CPU%d       ",j);
+               for_each_online_cpu(j)
+                       seq_printf(p, "CPU%d       ",j);
                seq_putc(p, '\n');
        }
 
@@ -52,9 +51,8 @@ int show_interrupts(struct seq_file *p, void *v)
 #ifndef CONFIG_SMP
                seq_printf(p, "%10u ", kstat_irqs(i));
 #else
-               for (j = 0; j < NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
+               for_each_online_cpu(j)
+                       seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
 #endif
                seq_printf(p, " %14s", irq_desc[i].handler->typename);
                seq_printf(p, "  %s", action->name);
index 7d93992e462c847deb025a798943b7f6f6eef78e..3dd76b3d296778c1f81596a8888da5bf96fc4ab3 100644 (file)
@@ -68,9 +68,8 @@ int show_interrupts(struct seq_file *p, void *v)
 
        if (i == 0) {
                seq_printf(p, "           ");
-               for (j=0; j<NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "CPU%d       ",j);
+               for_each_online_cpu(j)
+                       seq_printf(p, "CPU%d       ",j);
                seq_putc(p, '\n');
        }
 
@@ -83,9 +82,8 @@ int show_interrupts(struct seq_file *p, void *v)
 #ifndef CONFIG_SMP
                seq_printf(p, "%10u ", kstat_irqs(i));
 #else
-               for (j = 0; j < NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
+               for_each_online_cpu(j)
+                       seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
 #endif
                seq_printf(p, " %14s", irq_desc[i].handler->typename);
                seq_printf(p, "  %s", action->name);
index 06ed907524249fed2c3b1a70ee490c5a6031b523..78d171bfa331cbbbdd024746ba49c8e61267e846 100644 (file)
@@ -167,8 +167,8 @@ int smp_call_function (void (*func) (void *info), void *info, int retry,
        mb();
 
        /* Send a message to all other CPUs and wait for them to respond */
-       for (i = 0; i < NR_CPUS; i++)
-               if (cpu_online(i) && i != cpu)
+       for_each_online_cpu(i)
+               if (i != cpu)
                        core_send_ipi(i, SMP_CALL_FUNCTION);
 
        /* Wait for response */
index 73e5e52781d8c96aa3107c33e46b5c1cf805959f..2854ac4c9be13e0d75430de1f99eaef2ff070edb 100644 (file)
@@ -88,12 +88,9 @@ static inline int find_level(cpuid_t *cpunum, int irq)
 {
        int cpu, i;
 
-       for (cpu = 0; cpu <= NR_CPUS; cpu++) {
+       for_each_online_cpu(cpu) {
                struct slice_data *si = cpu_data[cpu].data;
 
-               if (!cpu_online(cpu))
-                       continue;
-
                for (i = BASE_PCI_IRQ; i < LEVELS_PER_SLICE; i++)
                        if (si->level_to_irq[i] == irq) {
                                *cpunum = cpu;
index 25564b7ca6bbc084f60a25978431c20b5e163f90..d6ac1c60a4713bf2f0266f99ca84c416016558e7 100644 (file)
@@ -298,8 +298,8 @@ send_IPI_allbutself(enum ipi_message_type op)
 {
        int i;
        
-       for (i = 0; i < NR_CPUS; i++) {
-               if (cpu_online(i) && i != smp_processor_id())
+       for_each_online_cpu(i) {
+               if (i != smp_processor_id())
                        send_IPI_single(i, op);
        }
 }
@@ -643,14 +643,13 @@ int sys_cpus(int argc, char **argv)
        if ( argc == 1 ){
        
 #ifdef DUMP_MORE_STATE
-               for(i=0; i<NR_CPUS; i++) {
+               for_each_online_cpu(i) {
                        int cpus_per_line = 4;
-                       if(cpu_online(i)) {
-                               if (j++ % cpus_per_line)
-                                       printk(" %3d",i);
-                               else
-                                       printk("\n %3d",i);
-                       }
+
+                       if (j++ % cpus_per_line)
+                               printk(" %3d",i);
+                       else
+                               printk("\n %3d",i);
                }
                printk("\n"); 
 #else
@@ -659,9 +658,7 @@ int sys_cpus(int argc, char **argv)
        } else if((argc==2) && !(strcmp(argv[1],"-l"))) {
                printk("\nCPUSTATE  TASK CPUNUM CPUID HARDCPU(HPA)\n");
 #ifdef DUMP_MORE_STATE
-               for(i=0;i<NR_CPUS;i++) {
-                       if (!cpu_online(i))
-                               continue;
+               for_each_online_cpu(i) {
                        if (cpu_data[i].cpuid != NO_PROC_ID) {
                                switch(cpu_data[i].state) {
                                        case STATE_RENDEZVOUS:
@@ -695,9 +692,7 @@ int sys_cpus(int argc, char **argv)
        } else if ((argc==2) && !(strcmp(argv[1],"-s"))) { 
 #ifdef DUMP_MORE_STATE
                printk("\nCPUSTATE   CPUID\n");
-               for (i=0;i<NR_CPUS;i++) {
-                       if (!cpu_online(i))
-                               continue;
+               for_each_online_cpu(i) {
                        if (cpu_data[i].cpuid != NO_PROC_ID) {
                                switch(cpu_data[i].state) {
                                        case STATE_RENDEZVOUS:
index 24dc8117b822e5228098438711c2b1f6ae420025..771a59cbd213168219f42e71f529511298ca163e 100644 (file)
@@ -135,9 +135,8 @@ skip:
 #ifdef CONFIG_TAU_INT
                if (tau_initialized){
                        seq_puts(p, "TAU: ");
-                       for (j = 0; j < NR_CPUS; j++)
-                               if (cpu_online(j))
-                                       seq_printf(p, "%10u ", tau_interrupts(j));
+                       for_each_online_cpu(j)
+                               seq_printf(p, "%10u ", tau_interrupts(j));
                        seq_puts(p, "  PowerPC             Thermal Assist (cpu temp)\n");
                }
 #endif
index be12041c0fc5404ab8b811050f45de883c225631..c1d62bf11f299ce427fb1043bf37fa9360143f0d 100644 (file)
@@ -162,9 +162,8 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 #if defined(CONFIG_SMP) && defined(CONFIG_PPC32)
                unsigned long bogosum = 0;
                int i;
-               for (i = 0; i < NR_CPUS; ++i)
-                       if (cpu_online(i))
-                               bogosum += loops_per_jiffy;
+               for_each_online_cpu(i)
+                       bogosum += loops_per_jiffy;
                seq_printf(m, "total bogomips\t: %lu.%02lu\n",
                           bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
 #endif /* CONFIG_SMP && CONFIG_PPC32 */
index db72a92943bf63e4cb9f1c1e583f027a6be06698..dc2770df25b3585da267f696e74865f51f95ccd8 100644 (file)
@@ -272,9 +272,8 @@ int __init ppc_init(void)
        if ( ppc_md.progress ) ppc_md.progress("             ", 0xffff);
 
        /* register CPU devices */
-       for (i = 0; i < NR_CPUS; i++)
-               if (cpu_possible(i))
-                       register_cpu(&cpu_devices[i], i, NULL);
+       for_each_cpu(i)
+               register_cpu(&cpu_devices[i], i, NULL);
 
        /* call platform init */
        if (ppc_md.init != NULL) {
index 6d64a9bf3474db8a29decd772667aafd6f03a8ea..1065d87fc27904f63b182f696f7f8fd8f8e9059b 100644 (file)
@@ -191,9 +191,7 @@ static void smp_psurge_message_pass(int target, int msg)
        if (num_online_cpus() < 2)
                return;
 
-       for (i = 0; i < NR_CPUS; i++) {
-               if (!cpu_online(i))
-                       continue;
+       for_each_online_cpu(i) {
                if (target == MSG_ALL
                    || (target == MSG_ALL_BUT_SELF && i != smp_processor_id())
                    || target == i) {
index c08ab432e95891b32e51d1e5bf31fc6f26eb22df..53e9deacee824884fd43cf8eab392cfa64b597ce 100644 (file)
@@ -168,9 +168,8 @@ int show_cpuinfo(struct seq_file *m, void *v)
                /* Show summary information */
 #ifdef CONFIG_SMP
                unsigned long bogosum = 0;
-               for (i = 0; i < NR_CPUS; ++i)
-                       if (cpu_online(i))
-                               bogosum += cpu_data[i].loops_per_jiffy;
+               for_each_online_cpu(i)
+                       bogosum += cpu_data[i].loops_per_jiffy;
                seq_printf(m, "total bogomips\t: %lu.%02lu\n",
                           bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
 #endif /* CONFIG_SMP */
@@ -712,9 +711,8 @@ int __init ppc_init(void)
        if ( ppc_md.progress ) ppc_md.progress("             ", 0xffff);
 
        /* register CPU devices */
-       for (i = 0; i < NR_CPUS; i++)
-               if (cpu_possible(i))
-                       register_cpu(&cpu_devices[i], i, NULL);
+       for_each_cpu(i)
+               register_cpu(&cpu_devices[i], i, NULL);
 
        /* call platform init */
        if (ppc_md.init != NULL) {
index 7dbe00c76c6bcf2274a2168ec7c01b0de31375d3..d52d6d211d9f6d644b2f2f7115b90dedf5dde34d 100644 (file)
@@ -799,9 +799,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
          */
        print_cpu_info(&S390_lowcore.cpu_data);
 
-        for(i = 0; i < NR_CPUS; i++) {
-               if (!cpu_possible(i))
-                       continue;
+        for_each_cpu(i) {
                lowcore_ptr[i] = (struct _lowcore *)
                        __get_free_pages(GFP_KERNEL|GFP_DMA, 
                                        sizeof(void*) == 8 ? 1 : 0);
index 6883c00728cbb116e2f104e2b302c17c7d1a0aeb..b56e79632f241aaa28fb91935ef3dace2c69924c 100644 (file)
@@ -35,9 +35,8 @@ int show_interrupts(struct seq_file *p, void *v)
 
        if (i == 0) {
                seq_puts(p, "           ");
-               for (j=0; j<NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "CPU%d       ",j);
+               for_each_online_cpu(j)
+                       seq_printf(p, "CPU%d       ",j);
                seq_putc(p, '\n');
        }
 
index a067a34e0b64fe2e6cd23573b2cbecd975cf5a1a..c0e79843f580437ef9e3d15ec33148dbf8d2415d 100644 (file)
@@ -404,9 +404,8 @@ static int __init topology_init(void)
 {
        int cpu_id;
 
-       for (cpu_id = 0; cpu_id < NR_CPUS; cpu_id++)
-               if (cpu_possible(cpu_id))
-                       register_cpu(&cpu[cpu_id], cpu_id, NULL);
+       for_each_cpu(cpu_id)
+               register_cpu(&cpu[cpu_id], cpu_id, NULL);
 
        return 0;
 }
index 9fc2b71dbd84be191ddef033a43ce637562b3bfc..d69879c0e063dc7ed39f890fd5020345f830a268 100644 (file)
@@ -53,9 +53,8 @@ int show_interrupts(struct seq_file *p, void *v)
 
        if (i == 0) {
                seq_puts(p, "           ");
-               for (j=0; j<NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "CPU%d       ",j);
+               for_each_online_cpu(j)
+                       seq_printf(p, "CPU%d       ",j);
                seq_putc(p, '\n');
        }
 
index 410b9a72aba97439c042eac98208e6da0ffd3203..4c60a6ef54a9157e0ae0d42770ea3acde6ded729 100644 (file)
@@ -184,9 +184,8 @@ int show_interrupts(struct seq_file *p, void *v)
 #ifndef CONFIG_SMP
                seq_printf(p, "%10u ", kstat_irqs(i));
 #else
-               for (j = 0; j < NR_CPUS; j++) {
-                       if (cpu_online(j))
-                               seq_printf(p, "%10u ",
+               for_each_online_cpu(j) {
+                       seq_printf(p, "%10u ",
                                    kstat_cpu(cpu_logical_map(j)).irqs[i]);
                }
 #endif
index c6e721d8f4772850652034d9a97ad136fe830f38..ea5682ce70319c99ee3ae994685287d54413a357 100644 (file)
@@ -243,9 +243,8 @@ int setup_profiling_timer(unsigned int multiplier)
                return -EINVAL;
 
        spin_lock_irqsave(&prof_setup_lock, flags);
-       for(i = 0; i < NR_CPUS; i++) {
-               if (cpu_possible(i))
-                       load_profile_irq(i, lvl14_resolution / multiplier);
+       for_each_cpu(i) {
+               load_profile_irq(i, lvl14_resolution / multiplier);
                prof_multiplier(i) = multiplier;
        }
        spin_unlock_irqrestore(&prof_setup_lock, flags);
@@ -273,13 +272,12 @@ void smp_bogo(struct seq_file *m)
 {
        int i;
        
-       for (i = 0; i < NR_CPUS; i++) {
-               if (cpu_online(i))
-                       seq_printf(m,
-                                  "Cpu%dBogo\t: %lu.%02lu\n", 
-                                  i,
-                                  cpu_data(i).udelay_val/(500000/HZ),
-                                  (cpu_data(i).udelay_val/(5000/HZ))%100);
+       for_each_online_cpu(i) {
+               seq_printf(m,
+                          "Cpu%dBogo\t: %lu.%02lu\n",
+                          i,
+                          cpu_data(i).udelay_val/(500000/HZ),
+                          (cpu_data(i).udelay_val/(5000/HZ))%100);
        }
 }
 
@@ -288,8 +286,6 @@ void smp_info(struct seq_file *m)
        int i;
 
        seq_printf(m, "State:\n");
-       for (i = 0; i < NR_CPUS; i++) {
-               if (cpu_online(i))
-                       seq_printf(m, "CPU%d\t\t: online\n", i);
-       }
+       for_each_online_cpu(i)
+               seq_printf(m, "CPU%d\t\t: online\n", i);
 }
index 52621348a56c2617c30cc0307e100b076f89b450..cea7fc6fc6e5b2ddf376f1481e695a114158ead1 100644 (file)
@@ -103,11 +103,9 @@ found_it:  seq_printf(p, "%3d: ", i);
 #ifndef CONFIG_SMP
                seq_printf(p, "%10u ", kstat_irqs(i));
 #else
-               for (x = 0; x < NR_CPUS; x++) {
-                       if (cpu_online(x))
-                               seq_printf(p, "%10u ",
-                                      kstat_cpu(cpu_logical_map(x)).irqs[i]);
-               }
+               for_each_online_cpu(x)
+                       seq_printf(p, "%10u ",
+                              kstat_cpu(cpu_logical_map(x)).irqs[i]);
 #endif
                seq_printf(p, "%c %s",
                        (action->flags & SA_INTERRUPT) ? '+' : ' ',
index 4219dd2ce3a2332094340c731d4142f4b569c461..41bb9596be48f443f57c66e5575739dab246d6ed 100644 (file)
@@ -249,11 +249,9 @@ void __init smp4d_boot_cpus(void)
        } else {
                unsigned long bogosum = 0;
                
-               for(i = 0; i < NR_CPUS; i++) {
-                       if (cpu_isset(i, cpu_present_map)) {
-                               bogosum += cpu_data(i).udelay_val;
-                               smp_highest_cpu = i;
-                       }
+               for_each_present_cpu(i) {
+                       bogosum += cpu_data(i).udelay_val;
+                       smp_highest_cpu = i;
                }
                SMP_PRINTK(("Total of %d Processors activated (%lu.%02lu BogoMIPS).\n", cpucount + 1, bogosum/(500000/HZ), (bogosum/(5000/HZ))%100));
                printk("Total of %d Processors activated (%lu.%02lu BogoMIPS).\n",
index fbbd8a474c4c62bfbc47ac5949f835c3dcad2a1f..1dde312eebda7ec16b58b09fa80c9d0780e13091 100644 (file)
@@ -218,10 +218,8 @@ void __init smp4m_boot_cpus(void)
                cpu_present_map = cpumask_of_cpu(smp_processor_id());
        } else {
                unsigned long bogosum = 0;
-               for(i = 0; i < NR_CPUS; i++) {
-                       if (cpu_isset(i, cpu_present_map))
-                               bogosum += cpu_data(i).udelay_val;
-               }
+               for_each_present_cpu(i)
+                       bogosum += cpu_data(i).udelay_val;
                printk("Total of %d Processors activated (%lu.%02lu BogoMIPS).\n",
                       cpucount + 1,
                       bogosum/(500000/HZ),
index 8c93ba655b33ba2325595c2ab97a2f04d2f96f45..e505a4125e35dba3f482b4176a621f2e3dd6d3a0 100644 (file)
@@ -117,9 +117,7 @@ int show_interrupts(struct seq_file *p, void *v)
 #ifndef CONFIG_SMP
                seq_printf(p, "%10u ", kstat_irqs(i));
 #else
-               for (j = 0; j < NR_CPUS; j++) {
-                       if (!cpu_online(j))
-                               continue;
+               for_each_online_cpu(j) {
                        seq_printf(p, "%10u ",
                                   kstat_cpu(j).irqs[i]);
                }
index 373a701c90a5ae82061028b45bc9733b26a5ac31..1b6e2ade1008ba26fc4cc89eec94d982e5c36f5b 100644 (file)
@@ -57,25 +57,21 @@ void smp_info(struct seq_file *m)
        int i;
        
        seq_printf(m, "State:\n");
-       for (i = 0; i < NR_CPUS; i++) {
-               if (cpu_online(i))
-                       seq_printf(m,
-                                  "CPU%d:\t\tonline\n", i);
-       }
+       for_each_online_cpu(i)
+               seq_printf(m, "CPU%d:\t\tonline\n", i);
 }
 
 void smp_bogo(struct seq_file *m)
 {
        int i;
        
-       for (i = 0; i < NR_CPUS; i++)
-               if (cpu_online(i))
-                       seq_printf(m,
-                                  "Cpu%dBogo\t: %lu.%02lu\n"
-                                  "Cpu%dClkTck\t: %016lx\n",
-                                  i, cpu_data(i).udelay_val / (500000/HZ),
-                                  (cpu_data(i).udelay_val / (5000/HZ)) % 100,
-                                  i, cpu_data(i).clock_tick);
+       for_each_online_cpu(i)
+               seq_printf(m,
+                          "Cpu%dBogo\t: %lu.%02lu\n"
+                          "Cpu%dClkTck\t: %016lx\n",
+                          i, cpu_data(i).udelay_val / (500000/HZ),
+                          (cpu_data(i).udelay_val / (5000/HZ)) % 100,
+                          i, cpu_data(i).clock_tick);
 }
 
 void __init smp_store_cpu_info(int id)
@@ -1282,7 +1278,7 @@ int setup_profiling_timer(unsigned int multiplier)
                return -EINVAL;
 
        spin_lock_irqsave(&prof_setup_lock, flags);
-       for (i = 0; i < NR_CPUS; i++)
+       for_each_cpu(i)
                prof_multiplier(i) = multiplier;
        current_tick_offset = (timer_tick_offset / multiplier);
        spin_unlock_irqrestore(&prof_setup_lock, flags);
@@ -1384,10 +1380,8 @@ void __init smp_cpus_done(unsigned int max_cpus)
        unsigned long bogosum = 0;
        int i;
 
-       for (i = 0; i < NR_CPUS; i++) {
-               if (cpu_online(i))
-                       bogosum += cpu_data(i).udelay_val;
-       }
+       for_each_online_cpu(i)
+               bogosum += cpu_data(i).udelay_val;
        printk("Total of %ld processors activated "
               "(%lu.%02lu BogoMIPS).\n",
               (long) num_online_cpus(),
index 30d2a1e545fea1fda11f9010ffd25d67854e8baa..d8bd0b345b1e2494f936765aef9e6a95da5a72dd 100644 (file)
@@ -38,9 +38,8 @@ int show_interrupts(struct seq_file *p, void *v)
 
        if (i == 0) {
                seq_printf(p, "           ");
-               for (j=0; j<NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "CPU%d       ",j);
+               for_each_online_cpu(j)
+                       seq_printf(p, "CPU%d       ",j);
                seq_putc(p, '\n');
        }
 
@@ -53,10 +52,8 @@ int show_interrupts(struct seq_file *p, void *v)
 #ifndef CONFIG_SMP
                seq_printf(p, "%10u ", kstat_irqs(i));
 #else
-               for (j=0; j<NR_CPUS; j++)
-                       if (cpu_online(j))
-                       seq_printf(p, "%10u ",
-                               kstat_cpu(j).irqs[i]);
+               for_each_online_cpu(j)
+                       seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
 #endif
                seq_printf(p, " %14s", irq_desc[i].handler->typename);
 
@@ -68,15 +65,13 @@ skip:
                spin_unlock_irqrestore(&irq_desc[i].lock, flags);
        } else if (i == NR_IRQS) {
                seq_printf(p, "NMI: ");
-               for (j = 0; j < NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "%10u ", cpu_pda(j)->__nmi_count);
+               for_each_online_cpu(j)
+                       seq_printf(p, "%10u ", cpu_pda(j)->__nmi_count);
                seq_putc(p, '\n');
 #ifdef CONFIG_X86_LOCAL_APIC
                seq_printf(p, "LOC: ");
-               for (j = 0; j < NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "%10u ", cpu_pda(j)->apic_timer_irqs);
+               for_each_online_cpu(j)
+                       seq_printf(p, "%10u ", cpu_pda(j)->apic_timer_irqs);
                seq_putc(p, '\n');
 #endif
                seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
index 5bf17e41cd2d2622138e030dc8f90ccc0d499d7f..66c009e10bac44a6fe4ce040da8653ebe3628ff3 100644 (file)
@@ -162,9 +162,7 @@ int __init check_nmi_watchdog (void)
        local_irq_enable();
        mdelay((10*1000)/nmi_hz); // wait 10 ticks
 
-       for (cpu = 0; cpu < NR_CPUS; cpu++) {
-               if (!cpu_online(cpu))
-                       continue;
+       for_each_online_cpu(cpu) {
                if (cpu_pda(cpu)->__nmi_count - counts[cpu] <= 5) {
                        endflag = 1;
                        printk("CPU#%d: NMI appears to be stuck (%d->%d)!\n",
index 4cbf6d91571f47aa465be4d3ddeb94e733fe709e..51f9bed455fab0c0576933a7702efb0d51cb84f4 100644 (file)
@@ -83,9 +83,8 @@ int show_interrupts(struct seq_file *p, void *v)
 
        if (i == 0) {
                seq_printf(p, "           ");
-               for (j=0; j<NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "CPU%d       ",j);
+               for_each_online_cpu(j)
+                       seq_printf(p, "CPU%d       ",j);
                seq_putc(p, '\n');
        }
 
@@ -98,9 +97,8 @@ int show_interrupts(struct seq_file *p, void *v)
 #ifndef CONFIG_SMP
                seq_printf(p, "%10u ", kstat_irqs(i));
 #else
-               for (j = 0; j < NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
+               for_each_online_cpu(j)
+                       seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
 #endif
                seq_printf(p, " %14s", irq_desc[i].handler->typename);
                seq_printf(p, "  %s", action->name);
@@ -113,9 +111,8 @@ skip:
                spin_unlock_irqrestore(&irq_desc[i].lock, flags);
        } else if (i == NR_IRQS) {
                seq_printf(p, "NMI: ");
-               for (j = 0; j < NR_CPUS; j++)
-                       if (cpu_online(j))
-                               seq_printf(p, "%10u ", nmi_count(j));
+               for_each_online_cpu(j)
+                       seq_printf(p, "%10u ", nmi_count(j));
                seq_putc(p, '\n');
                seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
        }
index 690a1aae0b34705c6d04cb08bc31f1c3dbc72c0d..0c13795dca38d0cdc8638b0f362a73a7b6c3e76b 100644 (file)
@@ -172,11 +172,9 @@ static struct net_device_stats *get_stats(struct net_device *dev)
 
        memset(stats, 0, sizeof(struct net_device_stats));
 
-       for (i=0; i < NR_CPUS; i++) {
+       for_each_cpu(i) {
                struct net_device_stats *lb_stats;
 
-               if (!cpu_possible(i)) 
-                       continue;
                lb_stats = &per_cpu(loopback_stats, i);
                stats->rx_bytes   += lb_stats->rx_bytes;
                stats->tx_bytes   += lb_stats->tx_bytes;
index 78193e4bbdb564981a98b00437bdad6a8b851500..330d3869b41ed342d0052af758cb16b28322931a 100644 (file)
@@ -38,9 +38,8 @@ void free_cpu_buffers(void)
 {
        int i;
  
-       for_each_online_cpu(i) {
+       for_each_online_cpu(i)
                vfree(cpu_buffer[i].buffer);
-       }
 }
 
 int alloc_cpu_buffers(void)
index 8955720a2c6b0685bde93bdfeff24e1006355771..713e6a7505d0b98d78c9132e6db9bc619d81d82f 100644 (file)
@@ -62,18 +62,15 @@ xfs_read_xfsstats(
                while (j < xstats[i].endpoint) {
                        val = 0;
                        /* sum over all cpus */
-                       for (c = 0; c < NR_CPUS; c++) {
-                               if (!cpu_possible(c)) continue;
+                       for_each_cpu(c)
                                val += *(((__u32*)&per_cpu(xfsstats, c) + j));
-                       }
                        len += sprintf(buffer + len, " %u", val);
                        j++;
                }
                buffer[len++] = '\n';
        }
        /* extra precision counters */
-       for (i = 0; i < NR_CPUS; i++) {
-               if (!cpu_possible(i)) continue;
+       for_each_cpu(i) {
                xs_xstrat_bytes += per_cpu(xfsstats, i).xs_xstrat_bytes;
                xs_write_bytes += per_cpu(xfsstats, i).xs_write_bytes;
                xs_read_bytes += per_cpu(xfsstats, i).xs_read_bytes;
index a02564972420b7720c21a3996afcb5d078e2c070..7079cc8372100aa8b2f7a3c3bd95e708a9a11531 100644 (file)
@@ -38,8 +38,7 @@ xfs_stats_clear_proc_handler(
 
        if (!ret && write && *valp) {
                printk("XFS Clearing xfsstats\n");
-               for (c = 0; c < NR_CPUS; c++) {
-                       if (!cpu_possible(c)) continue;
+               for_each_cpu(c) {
                        preempt_disable();
                        /* save vn_active, it's a universal truth! */
                        vn_active = per_cpu(xfsstats, c).vn_active;
index 6f92482cc96c6ebbd360c98899b4f4fc465828aa..0c017fc181c1d7eb724605006107b88fb2f185e5 100644 (file)
@@ -231,9 +231,8 @@ init_new_context(struct task_struct *tsk, struct mm_struct *mm)
 {
        int i;
 
-       for (i = 0; i < NR_CPUS; i++)
-               if (cpu_online(i))
-                       mm->context[i] = 0;
+       for_each_online_cpu(i)
+               mm->context[i] = 0;
        if (tsk != current)
                task_thread_info(tsk)->pcb.ptbr
                  = ((unsigned long)mm->pgd - IDENT_ADDR) >> PAGE_SHIFT;
index eb740e280d9c7912bfbc0ba8c399db944494ee69..420ccde6b916a31f8d601d46e601a3062bfc658b 100644 (file)
@@ -27,8 +27,8 @@ static inline cpumask_t node_to_cpumask(int node)
        cpumask_t node_cpu_mask = CPU_MASK_NONE;
        int cpu;
 
-       for(cpu = 0; cpu < NR_CPUS; cpu++) {
-               if (cpu_online(cpu) && (cpu_to_node(cpu) == node))
+       for_each_online_cpu(cpu) {
+               if (cpu_to_node(cpu) == node)
                        cpu_set(cpu, node_cpu_mask);
        }
 
index 9044aeb3782887d33d4b65abfb27f20cf593b1e0..78cf45547e31f0a5742be733f31c0a394297c040 100644 (file)
@@ -19,10 +19,9 @@ extern unsigned long __per_cpu_offset[NR_CPUS];
 #define percpu_modcopy(pcpudst, src, size)                     \
 do {                                                           \
        unsigned int __i;                                       \
-       for (__i = 0; __i < NR_CPUS; __i++)                     \
-               if (cpu_possible(__i))                          \
-                       memcpy((pcpudst)+__per_cpu_offset[__i], \
-                              (src), (size));                  \
+       for_each_cpu(__i)                                       \
+               memcpy((pcpudst)+__per_cpu_offset[__i],         \
+                      (src), (size));                          \
 } while (0)
 #else /* ! SMP */
 
index e31922c50e53473c5d340348e190cbf1ebe788d1..464301cd0d0300800e4889befa923a78e214fead 100644 (file)
 #define percpu_modcopy(pcpudst, src, size)                     \
 do {                                                           \
        unsigned int __i;                                       \
-       for (__i = 0; __i < NR_CPUS; __i++)                     \
-               if (cpu_possible(__i))                          \
-                       memcpy((pcpudst)+__per_cpu_offset(__i), \
-                              (src), (size));                  \
+       for_each_cpu(__i)                                       \
+               memcpy((pcpudst)+__per_cpu_offset(__i),         \
+                      (src), (size));                          \
 } while (0)
 
 extern void setup_per_cpu_areas(void);
index 123fcaca295e89e2be4c533b7d078f1dfa9f734a..e10ed87094f0ccff33e07ed20b8d20b14ad9dce9 100644 (file)
@@ -46,10 +46,9 @@ extern unsigned long __per_cpu_offset[NR_CPUS];
 #define percpu_modcopy(pcpudst, src, size)                     \
 do {                                                           \
        unsigned int __i;                                       \
-       for (__i = 0; __i < NR_CPUS; __i++)                     \
-               if (cpu_possible(__i))                          \
-                       memcpy((pcpudst)+__per_cpu_offset[__i], \
-                              (src), (size));                  \
+       for_each_cpu(__i)                                       \
+               memcpy((pcpudst)+__per_cpu_offset[__i],         \
+                      (src), (size));                          \
 } while (0)
 
 #else /* ! SMP */
index aea4e51e7cd13517829e3005535e5aa31c5d98c9..82032e159a76376040b8ac9084e788f75eeb4e1f 100644 (file)
@@ -26,10 +26,9 @@ register unsigned long __local_per_cpu_offset asm("g5");
 #define percpu_modcopy(pcpudst, src, size)                     \
 do {                                                           \
        unsigned int __i;                                       \
-       for (__i = 0; __i < NR_CPUS; __i++)                     \
-               if (cpu_possible(__i))                          \
-                       memcpy((pcpudst)+__per_cpu_offset(__i), \
-                              (src), (size));                  \
+       for_each_cpu(__i)                                       \
+               memcpy((pcpudst)+__per_cpu_offset(__i),         \
+                      (src), (size));                          \
 } while (0)
 #else /* ! SMP */
 
index 29a6b0408f755c1f1a8f6fd4c4016845df6b52d7..4405b4adeabad5e09a0d014f578dd8f618433740 100644 (file)
 #define percpu_modcopy(pcpudst, src, size)                     \
 do {                                                           \
        unsigned int __i;                                       \
-       for (__i = 0; __i < NR_CPUS; __i++)                     \
-               if (cpu_possible(__i))                          \
-                       memcpy((pcpudst)+__per_cpu_offset(__i), \
-                              (src), (size));                  \
+       for_each_cpu(__i)                                       \
+               memcpy((pcpudst)+__per_cpu_offset(__i),         \
+                      (src), (size));                          \
 } while (0)
 
 extern void setup_per_cpu_areas(void);
index eef5ccdcd7317942755af990969ca3c9c20030d2..fd647fde5ec18f0aba4124346fd4363d97fe4569 100644 (file)
@@ -149,22 +149,16 @@ struct disk_attribute {
 ({                                                                     \
        typeof(gendiskp->dkstats->field) res = 0;                       \
        int i;                                                          \
-       for (i=0; i < NR_CPUS; i++) {                                   \
-               if (!cpu_possible(i))                                   \
-                       continue;                                       \
+       for_each_cpu(i)                                                 \
                res += per_cpu_ptr(gendiskp->dkstats, i)->field;        \
-       }                                                               \
        res;                                                            \
 })
 
 static inline void disk_stat_set_all(struct gendisk *gendiskp, int value)      {
        int i;
-       for (i=0; i < NR_CPUS; i++) {
-               if (cpu_possible(i)) {
-                       memset(per_cpu_ptr(gendiskp->dkstats, i), value,        
-                                       sizeof (struct disk_stats));
-               }
-       }
+       for_each_cpu(i)
+               memset(per_cpu_ptr(gendiskp->dkstats, i), value,
+                               sizeof (struct disk_stats));
 }              
                                
 #else