percpu data changes
Subsystems (16)
It seems that powerpc has gone and changed their implementation of percpu data so that there is no memory allocated for not-possible CPUs. To save a bit of RAM.
This means that any code which does
for (i = 0; i < NR_CPUS; i++) touch(percpudata(i))
will explode on powerpc.
I have a patch queued up (for 2.6.16) which fixes most users of percpu data. Make them use for_each_cpu(). I'll send that in a moment.
I also have a patch queued up (from Eric Dumazet) which will convert architectures which use asm-generic/percpu.h to not allocate memory for !possible CPUs. I don't intend to merge this until after 2.6.16. Once this is merged, code which _does_ touch percpu data for !possible CPUs will explode.
As part of this I've just done a kernel-wide sweep for all instances of NR_CPUS. I don't _think_ I found any percpu bugs such as the above, but sometimes it's not clear.
While I was there I did a general cleanup of quite a lot of open-coded cruft, make it use the nice macros.
So please review the below post-2.6.16 patch with an eye to the following:
- Any stuff you don't want added to your arch
- Any code which _does_ affect percpu data and which might possibly be used on powerpc. Such changes will need to go into 2.6.16.
Thanks.
From: Andrew Morton <[email protected]>
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.
---
arch/cris/kernel/irq.c | 10 ++---- arch/frv/kernel/irq.c | 10 ++---- arch/i386/kernel/cpu/cpufreq/powernow-k8.c | 4 -- arch/i386/kernel/io_apic.c | 22 +++++-------- arch/i386/kernel/nmi.c | 4 +- arch/i386/oprofile/nmi_int.c | 7 +--- arch/m32r/kernel/irq.c | 10 ++---- arch/mips/kernel/irq.c | 10 ++---- arch/mips/kernel/smp.c | 4 +- arch/mips/sgi-ip27/ip27-irq.c | 5 --- arch/parisc/kernel/smp.c | 25 ++++++--------- arch/powerpc/kernel/irq.c | 5 +-- arch/powerpc/kernel/setup-common.c | 5 +-- arch/powerpc/kernel/setup_32.c | 5 +-- arch/powerpc/platforms/powermac/smp.c | 4 -- arch/ppc/kernel/setup.c | 10 ++---- arch/s390/kernel/smp.c | 4 -- arch/sh/kernel/irq.c | 5 +-- arch/sh/kernel/setup.c | 5 +-- arch/sh64/kernel/irq.c | 5 +-- arch/sparc/kernel/irq.c | 5 +-- arch/sparc/kernel/smp.c | 24 ++++++--------- arch/sparc/kernel/sun4d_irq.c | 8 +---- arch/sparc/kernel/sun4d_smp.c | 8 +---- arch/sparc/kernel/sun4m_smp.c | 6 +-- arch/sparc64/kernel/irq.c | 4 -- arch/sparc64/kernel/setup.c | 15 +++------ arch/sparc64/kernel/smp.c | 30 +++++++------------ arch/x86_64/kernel/irq.c | 21 +++++-------- arch/x86_64/kernel/nmi.c | 6 +-- arch/xtensa/kernel/irq.c | 15 +++------ drivers/net/loopback.c | 4 -- drivers/oprofile/cpu_buffer.c | 3 - fs/xfs/linux-2.6/xfs_stats.c | 7 +--- fs/xfs/linux-2.6/xfs_sysctl.c | 3 - include/asm-alpha/mmu_context.h | 5 +-- include/asm-alpha/topology.h | 4 +- include/asm-generic/percpu.h | 7 +--- include/asm-powerpc/percpu.h | 7 +--- include/asm-s390/percpu.h | 7 +--- include/asm-sparc64/percpu.h | 7 +--- include/asm-x86_64/percpu.h | 7 +--- include/linux/genhd.h | 14 ++------ 43 files changed, 144 insertions(+), 232 deletions(-)
arch/cris/kernel/irq.c renamed from arch/cris/kernel/irq.c~more-for_each_cpu-conversions +4 -6
@@ -52,9 +52,8 @@ int show_interrupts(struct seq_file *p,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,#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);
arch/frv/kernel/irq.c renamed from arch/frv/kernel/irq.c~more-for_each_cpu-conversions +4 -6
@@ -75,9 +75,8 @@ int show_interrupts(struct seq_file *p,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,#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;
arch/i386/kernel/cpu/cpufreq/powernow-k8.c renamed from arch/i386/kernel/cpu/cpufreq/powernow-k8.c~more-for_each_cpu-conversions +1 -3
@@ -1145,9 +1145,7 @@ static int __cpuinit powernowk8_init(voi {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++; }
arch/i386/kernel/io_apic.c renamed from arch/i386/kernel/io_apic.c~more-for_each_cpu-conversions +9 -13
@@ -349,8 +349,8 @@ static inline void rotate_irqs_among_cpu {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 ? */
@@ -379,7 +379,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))
@@ -420,9 +420,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)) {
@@ -439,9 +437,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))
@@ -617,9 +613,7 @@ static int __init balanced_irq_init(voidif (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 ) {
@@ -636,9 +630,11 @@ static int __init balanced_irq_init(voidelse 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 ; }
arch/i386/kernel/nmi.c renamed from arch/i386/kernel/nmi.c~more-for_each_cpu-conversions +2 -2
@@ -143,7 +143,7 @@ static int __init check_nmi_watchdog(voilocal_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 ;/*
arch/i386/oprofile/nmi_int.c renamed from arch/i386/oprofile/nmi_int.c~more-for_each_cpu-conversions +2 -5
@@ -122,7 +122,7 @@ static void nmi_save_registers(void * dustatic 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 ;
arch/m32r/kernel/irq.c renamed from arch/m32r/kernel/irq.c~more-for_each_cpu-conversions +4 -6
@@ -37,9 +37,8 @@ int show_interrupts(struct seq_file *p,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,#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);
arch/mips/kernel/irq.c renamed from arch/mips/kernel/irq.c~more-for_each_cpu-conversions +4 -6
@@ -68,9 +68,8 @@ int show_interrupts(struct seq_file *p,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,#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);
arch/mips/kernel/smp.c renamed from arch/mips/kernel/smp.c~more-for_each_cpu-conversions +2 -2
@@ -166,8 +166,8 @@ int smp_call_function (void (*func) (voimb ();/* 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 */
arch/mips/sgi-ip27/ip27-irq.c renamed from arch/mips/sgi-ip27/ip27-irq.c~more-for_each_cpu-conversions +1 -4
@@ -88,12 +88,9 @@ static inline int find_level(cpuid_t *cp {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;
arch/parisc/kernel/smp.c renamed from arch/parisc/kernel/smp.c~more-for_each_cpu-conversions +10 -15
@@ -298,8 +298,8 @@ send_IPI_allbutself(enum ipi_message_typ {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 :
arch/powerpc/kernel/irq.c renamed from arch/powerpc/kernel/irq.c~more-for_each_cpu-conversions +2 -3
@@ -137,9 +137,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
arch/powerpc/kernel/setup_32.c renamed from arch/powerpc/kernel/setup_32.c~more-for_each_cpu-conversions +2 -3
@@ -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 ) {
arch/powerpc/kernel/setup-common.c renamed from arch/powerpc/kernel/setup-common.c~more-for_each_cpu-conversions +2 -3
@@ -162,9 +162,8 @@ static int show_cpuinfo(struct seq_file#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 */
arch/powerpc/platforms/powermac/smp.c renamed from arch/powerpc/platforms/powermac/smp.c~more-for_each_cpu-conversions +1 -3
@@ -191,9 +191,7 @@ static void smp_psurge_message_pass(intif (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) {
arch/ppc/kernel/setup.c renamed from arch/ppc/kernel/setup.c~more-for_each_cpu-conversions +4 -6
@@ -168,9 +168,8 @@ int show_cpuinfo(struct seq_file *m, voi/* 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 ) {
arch/s390/kernel/smp.c renamed from arch/s390/kernel/smp.c~more-for_each_cpu-conversions +1 -3
@@ -767,9 +767,7 @@ void __init smp_prepare_cpus(unsigned in*/ 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 );
arch/sh64/kernel/irq.c renamed from arch/sh64/kernel/irq.c~more-for_each_cpu-conversions +2 -3
@@ -53,9 +53,8 @@ int show_interrupts(struct seq_file *p,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' ); }
arch/sh/kernel/irq.c renamed from arch/sh/kernel/irq.c~more-for_each_cpu-conversions +2 -3
@@ -35,9 +35,8 @@ int show_interrupts(struct seq_file *p,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' ); }
arch/sh/kernel/setup.c renamed from arch/sh/kernel/setup.c~more-for_each_cpu-conversions +2 -3
@@ -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 ; }
arch/sparc64/kernel/irq.c renamed from arch/sparc64/kernel/irq.c~more-for_each_cpu-conversions +1 -3
@@ -115,9 +115,7 @@ int show_interrupts(struct seq_file *p,#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]); }
arch/sparc64/kernel/setup.c renamed from arch/sparc64/kernel/setup.c~more-for_each_cpu-conversions +6 -9
@@ -690,15 +690,12 @@ static int __init topology_init(void)while (!cpu_find_by_instance (ncpus_probed,NULL ,NULL )) ncpus_probed++; -for (i =0 ; i <NR_CPUS ; i++) { -if (cpu_possible (i)) { -struct cpu *p =kmalloc (sizeof (*p),GFP_KERNEL ); - -if (p) { -memset (p,0 ,sizeof (*p)); -register_cpu (p, i,NULL ); - err =0 ; - } +for_each_cpu (i) { +struct cpu *p =kmalloc (sizeof (*p),GFP_KERNEL ); +if (p) { +memset (p,0 ,sizeof (*p)); +register_cpu (p, i,NULL ); + err =0 ; } }
arch/sparc64/kernel/smp.c renamed from arch/sparc64/kernel/smp.c~more-for_each_cpu-conversions +12 -18
@@ -54,25 +54,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)
@@ -1071,7 +1067,7 @@ int setup_profiling_timer(unsigned int mreturn -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);
@@ -1140,10 +1136,8 @@ void __init smp_cpus_done(unsigned int munsigned 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(),
arch/sparc/kernel/irq.c renamed from arch/sparc/kernel/irq.c~more-for_each_cpu-conversions +2 -3
@@ -184,9 +184,8 @@ int show_interrupts(struct seq_file *p,#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
arch/sparc/kernel/smp.c renamed from arch/sparc/kernel/smp.c~more-for_each_cpu-conversions +10 -14
@@ -243,9 +243,8 @@ int setup_profiling_timer(unsigned int mreturn -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); }
arch/sparc/kernel/sun4d_irq.c renamed from arch/sparc/kernel/sun4d_irq.c~more-for_each_cpu-conversions +3 -5
@@ -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) ? '+' : ' ',
arch/sparc/kernel/sun4d_smp.c renamed from arch/sparc/kernel/sun4d_smp.c~more-for_each_cpu-conversions +3 -5
@@ -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",
arch/sparc/kernel/sun4m_smp.c renamed from arch/sparc/kernel/sun4m_smp.c~more-for_each_cpu-conversions +2 -4
@@ -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),
arch/x86_64/kernel/irq.c renamed from arch/x86_64/kernel/irq.c~more-for_each_cpu-conversions +8 -13
@@ -38,9 +38,8 @@ int show_interrupts(struct seq_file *p,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,#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));
arch/x86_64/kernel/nmi.c renamed from arch/x86_64/kernel/nmi.c~more-for_each_cpu-conversions +2 -4
@@ -161,9 +161,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",
@@ -462,7 +460,7 @@ void touch_nmi_watchdog (void)* do it ourselves because the alert count increase is not * atomic. */ -for (i =0 ; i <NR_CPUS ; i++) +for_each_cpu (i)per_cpu (nmi_touch, i) =1 ;touch_softlockup_watchdog ();
arch/xtensa/kernel/irq.c renamed from arch/xtensa/kernel/irq.c~more-for_each_cpu-conversions +6 -9
@@ -83,9 +83,8 @@ int show_interrupts(struct seq_file *p,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,#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)); }
drivers/net/loopback.c renamed from drivers/net/loopback.c~more-for_each_cpu-conversions +1 -3
@@ -172,11 +172,9 @@ static struct net_device_stats *get_statmemset (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;
drivers/oprofile/cpu_buffer.c renamed from drivers/oprofile/cpu_buffer.c~more-for_each_cpu-conversions +1 -2
@@ -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 )
fs/xfs/linux-2.6/xfs_stats.c renamed from fs/xfs/linux-2.6/xfs_stats.c~more-for_each_cpu-conversions +2 -5
@@ -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;
fs/xfs/linux-2.6/xfs_sysctl.c renamed from fs/xfs/linux-2.6/xfs_sysctl.c~more-for_each_cpu-conversions +1 -2
@@ -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;
include/asm-alpha/mmu_context.h renamed from include/asm-alpha/mmu_context.h~more-for_each_cpu-conversions +2 -3
@@ -231,9 +231,8 @@ init_new_context(struct task_struct *tsk {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 ;
include/asm-alpha/topology.h renamed from include/asm-alpha/topology.h~more-for_each_cpu-conversions +2 -2
@@ -27,8 +27,8 @@ static inline cpumask_t node_to_cpumask(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); }
include/asm-generic/percpu.h renamed from include/asm-generic/percpu.h~more-for_each_cpu-conversions +3 -4
@@ -19,10 +19,9 @@ extern unsigned long __per_cpu_offset[NR#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 */
include/asm-powerpc/percpu.h renamed from include/asm-powerpc/percpu.h~more-for_each_cpu-conversions +3 -4
@@ -27,10 +27,9 @@#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 );
include/asm-s390/percpu.h renamed from include/asm-s390/percpu.h~more-for_each_cpu-conversions +3 -4
@@ -46,10 +46,9 @@ extern unsigned long __per_cpu_offset[NR#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 */
include/asm-sparc64/percpu.h renamed from include/asm-sparc64/percpu.h~more-for_each_cpu-conversions +3 -4
@@ -26,10 +26,9 @@ register unsigned long __local_per_cpu_o#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 */
include/asm-x86_64/percpu.h renamed from include/asm-x86_64/percpu.h~more-for_each_cpu-conversions +3 -4
@@ -26,10 +26,9 @@#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 );
include/linux/genhd.h renamed from include/linux/genhd.h~more-for_each_cpu-conversions +4 -10
@@ -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
_
Andrew Morton
Acked-by Ingo MolnarQuoted 3 lines · Andrew Morton
I have a patch queued up (for 2.6.16) which fixes most users of percpu
data. Make them usefor_each_cpu(). I'll send that in a moment.
From: Eric Dumazet <[email protected]>
percpu_data blindly allocates bootmem memory to store NR_CPUS instances of cpudata, instead of allocating memory only for possible cpus.
As a preparation for changing that, we need to convert various 0 -> NR_CPUS loops to use for_each_cpu().
(The above only applies to users of asm-generic/percpu.h. powerpc has gone it alone and is presently only allocating memory for present CPUs, so t's currently corrupting memory).
---
arch/i386/kernel/nmi.c | 2 +- block/ll_rw_blk.c | 2 +- drivers/scsi/scsi.c | 2 +- fs/file.c | 3 +-- kernel/sched.c | 2 +- net/core/utils.c | 2 +- net/ipv4/proc.c | 2 +- net/ipv6/proc.c | 2 +- net/socket.c | 2 +- main.c | 0 10 files changed, 9 insertions(+), 10 deletions(-)
arch/i386/kernel/nmi.c renamed from arch/i386/kernel/nmi.c~reduce-size-of-percpudata-and-make-sure-per_cpuobject +1 -1
@@ -138,7 +138,7 @@ static int __init check_nmi_watchdog(voiif (nmi_watchdog ==NMI_LOCAL_APIC )smp_call_function (nmi_cpu_busy, (void *)&endflag,0 ,0 ); -for (cpu =0 ; cpu <NR_CPUS ; cpu++) +for_each_cpu (cpu) prev_nmi_count[cpu] =per_cpu (irq_stat, cpu).__nmi_count;local_irq_enable ();mdelay ((10 *1000 )/nmi_hz);// wait 10 ticks
block/ll_rw_blk.c renamed from block/ll_rw_blk.c~reduce-size-of-percpudata-and-make-sure-per_cpuobject +1 -1
@@ -3453,7 +3453,7 @@ int __init blk_dev_init(void) iocontext_cachep =kmem_cache_create ("blkdev_ioc" ,sizeof (struct io_context ),0 ,SLAB_PANIC ,NULL ,NULL ); -for (i =0 ; i <NR_CPUS ; i++) +for_each_cpu (i)INIT_LIST_HEAD (&per_cpu (blk_cpu_done, i));open_softirq (BLOCK_SOFTIRQ , blk_done_softirq,NULL );
drivers/scsi/scsi.c renamed from drivers/scsi/scsi.c~reduce-size-of-percpudata-and-make-sure-per_cpuobject +1 -1
@@ -1245,7 +1245,7 @@ static int __init init_scsi(void)if (error) goto cleanup_sysctl; -for (i =0 ; i <NR_CPUS ; i++) +for_each_cpu (i)INIT_LIST_HEAD (&per_cpu (scsi_done_q, i));devfs_mk_dir ("scsi" );
fs/file.c renamed from fs/file.c~reduce-size-of-percpudata-and-make-sure-per_cpuobject +1 -2
@@ -379,7 +379,6 @@ static void __devinit fdtable_defer_listvoid __init files_defer_init (void ) {int i; -/* Really early - can't use for_each_cpu */ -for (i =0 ; i <NR_CPUS ; i++) +for_each_cpu (i)fdtable_defer_list_init (i); }
diff -puN init/main.c~reduce-size-of-percpudata-and-make-sure-per_cpuobject init/main.c
kernel/sched.c renamed from kernel/sched.c~reduce-size-of-percpudata-and-make-sure-per_cpuobject +1 -1
@@ -6109,7 +6109,7 @@ void __init sched_init(void)runqueue_t *rq;int i, j, k; -for (i =0 ; i <NR_CPUS ; i++) { +for_each_cpu (i) {prio_array_t *array; rq =cpu_rq (i);
net/core/utils.c renamed from net/core/utils.c~reduce-size-of-percpudata-and-make-sure-per_cpuobject +1 -1
@@ -121,7 +121,7 @@ void __init net_random_init(void) {int i; -for (i =0 ; i <NR_CPUS ; i++) { +for_each_cpu (i) {struct nrnd_state *state = &per_cpu (net_rand_state,i);__net_srandom (state, i+jiffies); }
net/ipv4/proc.c renamed from net/ipv4/proc.c~reduce-size-of-percpudata-and-make-sure-per_cpuobject +1 -1
@@ -49,7 +49,7 @@ static int fold_prot_inuse(struct protoint res =0 ;int cpu; -for (cpu =0 ; cpu <NR_CPUS ; cpu++) +for_each_cpu (cpu) res += proto->stats[cpu].inuse;return res;
net/ipv6/proc.c renamed from net/ipv6/proc.c~reduce-size-of-percpudata-and-make-sure-per_cpuobject +1 -1
@@ -38,7 +38,7 @@ static int fold_prot_inuse(struct protoint res =0 ;int cpu; -for (cpu=0 ; cpu<NR_CPUS ; cpu++) +for_each_cpu (cpu) res += proto->stats[cpu].inuse;return res;
net/socket.c renamed from net/socket.c~reduce-size-of-percpudata-and-make-sure-per_cpuobject +1 -1
@@ -2078,7 +2078,7 @@ void socket_seq_show(struct seq_file *seint cpu;int counter =0 ; -for (cpu =0 ; cpu <NR_CPUS ; cpu++) +for_each_cpu (cpu) counter +=per_cpu (sockets_in_use, cpu);/* It can be negative, by the way. 8) */
_
Quoted 5 lines · Andrew Morton
Quoted 3 lines · Andrew Morton
I have a patch queued up (for 2.6.16) which fixes most users of percpu
data. Make them usefor_each_cpu(). I'll send that in a moment.
A couple more.
net/core/dev.c | 2 +- net/core/utils.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/core/dev.c renamed from net/core/dev.c~reduce-size-of-percpudata-and-make-sure-per_cpuobject-update +1 -1
@@ -3237,7 +3237,7 @@ static int __init net_dev_init(void)* Initialise the packet receive queues. */ -for (i =0 ; i <NR_CPUS ; i++) { +for_each_cpu (i) {struct softnet_data *queue; queue = &per_cpu (softnet_data, i);
net/core/utils.c renamed from net/core/utils.c~reduce-size-of-percpudata-and-make-sure-per_cpuobject-update +1 -1
@@ -133,7 +133,7 @@ static int net_random_reseed(void)unsigned long seed[NR_CPUS ];get_random_bytes (seed,sizeof (seed)); -for (i =0 ; i <NR_CPUS ; i++) { +for_each_cpu (i) {struct nrnd_state *state = &per_cpu (net_rand_state,i);__net_srandom (state, seed[i]); }
_
Quoted 10 lines · Andrew Morton
It seems that powerpc has gone and changed their implementation of percpu data so that there is no memory allocated for not-possible CPUs. To save a bit of RAM.
This means that any code which doesfor (i = 0; i < NR_CPUS; i++) touch(percpudata(i))will explode on powerpc.
I have a patch queued up (for 2.6.16) which fixes most users of percpu data. Make them usefor_each_cpu(). I'll send that in a moment.
...
Blanket Acked-by: William Irwin <[email protected]>
-- wli
David S. Miller
maintainerFrom: Andrew Morton <[email protected]>
Date: Fri, 3 Feb 2006 01:35:21 -0800
Quoted 5 lines
A couple more.
net/core/dev.c | 2 +- net/core/utils.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Looks good to me, please merge this in Andrew.
David S. Miller
maintainerFrom: Andrew Morton <[email protected]>
Date: Fri, 3 Feb 2006 01:17:48 -0800
Quoted 8 lines
So please review the below post-2.6.16 patch with an eye to the following:
- Any stuff you don't want added to your arch
- Any code which _does_ affect percpu data and which might possibly be used on powerpc. Such changes will need to go into 2.6.16.
Thanks.
Sparc64 bits look fine to me.
Quoted 11 lines · Andrew Morton
It seems that powerpc has gone and changed their implementation of percpu data so that there is no memory allocated for not-possible CPUs. To save a bit of RAM.
This means that any code which does
for (i = 0; i < NR_CPUS; i++) touch(percpudata(i))will explode on powerpc.
It also explodes since some time on x86-64.
But I added a workaround now (or rather sent one and Linus dropped it) to point the not possible CPUs to the reference data and not free it. With that violating that protocol is mostly harmless.
Later the plan was to point it to unmapped data to catch all users.
-Andi
Quoted 12 lines · Andi Kleen
Quoted 10 lines · Andrew Morton
It seems that powerpc has gone and changed their implementation of percpu data so that there is no memory allocated for not-possible CPUs. To save a bit of RAM.
This means that any code which does
for (i = 0; i < NR_CPUS; i++) touch(percpudata(i))will explode on powerpc.
Quoted 7 lines
It also explodes since some time on x86-64.
But I added a workaround now (or rather sent one and Linus dropped it) to point the not possible CPUs to the reference data and not free it. With that violating that protocol is mostly harmless.
Later the plan was to point it to unmapped data to catch all users.
Maybe you can port the following i386 patch to x86_64 ? (I dont have a x86_64 test machine at this moment)
(This was sent to Andrew Jan 29th, and is included in 2.6.16-rc1-mm5)
Eric
arch/i386/Kconfig.debug +12 -0
@@ -61,6 +61,18 @@ portion of the kernel code won't be covered by a 2MB TLB anymore. If in doubt, say "N". +config DEBUG_INITDATA + bool "Read/Write protect kernel init data structures" + depends on DEBUG_KERNEL + help + The init data is normally freed when kernel has booted. + Some code may still try to read or write to data in this area. + If you say Y here, the kernel will mark this zone as not readable + or writeable at all. Buggy code will then fault. + This option may have a slight performance impact because a + portion of the kernel code won't be covered by a 2MB TLB anymore. + If in doubt, say "N". + config 4KSTACKS bool "Use 4Kb + 4Kb for kernel stacks instead of 8Kb" if DEBUG_KERNEL default y
arch/i386/mm/init.c +7 -0
@@ -750,11 +750,18 @@for (addr = begin; addr < end; addr +=PAGE_SIZE ) {ClearPageReserved (virt_to_page (addr));set_page_count (virt_to_page (addr),1 ); +#ifdef CONFIG_DEBUG_INITDATA +change_page_attr (virt_to_page (addr),1 ,__pgprot (0 )); +#else memset ((void *)addr,0xcc ,PAGE_SIZE ); +#endif free_page (addr); totalram_pages++; }printk (KERN_INFO "Freeing %s: %ldk freed\n" , what, (end - begin) >>10 ); +#ifdef CONFIG_DEBUG_INITDATA +global_flush_tlb (); +#endif }void free_initmem (void )
Quoted 15 lines · Eric Dumazet
Quoted 14 lines · Andi Kleen
Quoted 10 lines · Andrew Morton
It seems that powerpc has gone and changed their implementation of percpu data so that there is no memory allocated for not-possible CPUs. To save a bit of RAM.
This means that any code which does
for (i = 0; i < NR_CPUS; i++) touch(percpudata(i))will explode on powerpc.
It also explodes since some time on x86-64.
Quoted 8 lines
Quoted 5 lines
But I added a workaround now (or rather sent one and Linus dropped it) to point the not possible CPUs to the reference data and not free it. With that violating that protocol is mostly harmless.
Later the plan was to point it to unmapped data to catch all users.
Maybe you can port the following i386 patch to
x86_64? (I dont have ax86_64test machine at this moment)
Yes good idea. I will add it after 2.6.16.
-Andi
Kyle McMartin
Acked-byQuoted 2 lines · Andrew Morton
Cc Kyle McMartin <[email protected]>
Looks good.
Cheers!
Kyle