aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmerigo Wang <amwang@redhat.com>2011-03-22 19:34:06 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-22 20:44:11 -0400
commit34db18a054c600b6f81787165669dc572fe4de25 (patch)
tree6a8a0abf4f64ccad677ea2468c3e8465ac4e0c29
parentfa9ee9c4b9885dfdf8eccac19b8b4fc8a7c53288 (diff)
smp: move smp setup functions to kernel/smp.c
Move setup_nr_cpu_ids(), smp_init() and some other SMP boot parameter setup functions from init/main.c to kenrel/smp.c, saves some #ifdef CONFIG_SMP. Signed-off-by: WANG Cong <amwang@redhat.com> Cc: Rakib Mullick <rakib.mullick@gmail.com> Cc: David Howells <dhowells@redhat.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Tejun Heo <tj@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/smp.h2
-rw-r--r--init/main.c90
-rw-r--r--kernel/smp.c81
3 files changed, 84 insertions, 89 deletions
diff --git a/include/linux/smp.h b/include/linux/smp.h
index 6dc95cac6b3d..48159dd320d0 100644
--- a/include/linux/smp.h
+++ b/include/linux/smp.h
@@ -114,6 +114,8 @@ int on_each_cpu(smp_call_func_t func, void *info, int wait);
114void smp_prepare_boot_cpu(void); 114void smp_prepare_boot_cpu(void);
115 115
116extern unsigned int setup_max_cpus; 116extern unsigned int setup_max_cpus;
117extern void __init setup_nr_cpu_ids(void);
118extern void __init smp_init(void);
117 119
118#else /* !SMP */ 120#else /* !SMP */
119 121
diff --git a/init/main.c b/init/main.c
index 33c37c379e96..3627bb37225c 100644
--- a/init/main.c
+++ b/init/main.c
@@ -129,63 +129,6 @@ static char *static_command_line;
129static char *execute_command; 129static char *execute_command;
130static char *ramdisk_execute_command; 130static char *ramdisk_execute_command;
131 131
132#ifdef CONFIG_SMP
133/* Setup configured maximum number of CPUs to activate */
134unsigned int setup_max_cpus = NR_CPUS;
135EXPORT_SYMBOL(setup_max_cpus);
136
137
138/*
139 * Setup routine for controlling SMP activation
140 *
141 * Command-line option of "nosmp" or "maxcpus=0" will disable SMP
142 * activation entirely (the MPS table probe still happens, though).
143 *
144 * Command-line option of "maxcpus=<NUM>", where <NUM> is an integer
145 * greater than 0, limits the maximum number of CPUs activated in
146 * SMP mode to <NUM>.
147 */
148
149void __weak arch_disable_smp_support(void) { }
150
151static int __init nosmp(char *str)
152{
153 setup_max_cpus = 0;
154 arch_disable_smp_support();
155
156 return 0;
157}
158
159early_param("nosmp", nosmp);
160
161/* this is hard limit */
162static int __init nrcpus(char *str)
163{
164 int nr_cpus;
165
166 get_option(&str, &nr_cpus);
167 if (nr_cpus > 0 && nr_cpus < nr_cpu_ids)
168 nr_cpu_ids = nr_cpus;
169
170 return 0;
171}
172
173early_param("nr_cpus", nrcpus);
174
175static int __init maxcpus(char *str)
176{
177 get_option(&str, &setup_max_cpus);
178 if (setup_max_cpus == 0)
179 arch_disable_smp_support();
180
181 return 0;
182}
183
184early_param("maxcpus", maxcpus);
185#else
186static const unsigned int setup_max_cpus = NR_CPUS;
187#endif
188
189/* 132/*
190 * If set, this is an indication to the drivers that reset the underlying 133 * If set, this is an indication to the drivers that reset the underlying
191 * device before going ahead with the initialization otherwise driver might 134 * device before going ahead with the initialization otherwise driver might
@@ -362,7 +305,7 @@ static int __init rdinit_setup(char *str)
362__setup("rdinit=", rdinit_setup); 305__setup("rdinit=", rdinit_setup);
363 306
364#ifndef CONFIG_SMP 307#ifndef CONFIG_SMP
365 308static const unsigned int setup_max_cpus = NR_CPUS;
366#ifdef CONFIG_X86_LOCAL_APIC 309#ifdef CONFIG_X86_LOCAL_APIC
367static void __init smp_init(void) 310static void __init smp_init(void)
368{ 311{
@@ -374,37 +317,6 @@ static void __init smp_init(void)
374 317
375static inline void setup_nr_cpu_ids(void) { } 318static inline void setup_nr_cpu_ids(void) { }
376static inline void smp_prepare_cpus(unsigned int maxcpus) { } 319static inline void smp_prepare_cpus(unsigned int maxcpus) { }
377
378#else
379
380/* Setup number of possible processor ids */
381int nr_cpu_ids __read_mostly = NR_CPUS;
382EXPORT_SYMBOL(nr_cpu_ids);
383
384/* An arch may set nr_cpu_ids earlier if needed, so this would be redundant */
385static void __init setup_nr_cpu_ids(void)
386{
387 nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1;
388}
389
390/* Called by boot processor to activate the rest. */
391static void __init smp_init(void)
392{
393 unsigned int cpu;
394
395 /* FIXME: This should be done in userspace --RR */
396 for_each_present_cpu(cpu) {
397 if (num_online_cpus() >= setup_max_cpus)
398 break;
399 if (!cpu_online(cpu))
400 cpu_up(cpu);
401 }
402
403 /* Any cleanup work */
404 printk(KERN_INFO "Brought up %ld CPUs\n", (long)num_online_cpus());
405 smp_cpus_done(setup_max_cpus);
406}
407
408#endif 320#endif
409 321
410/* 322/*
diff --git a/kernel/smp.c b/kernel/smp.c
index 7cbd0f293df4..73a195193558 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -604,6 +604,87 @@ void ipi_call_unlock_irq(void)
604} 604}
605#endif /* USE_GENERIC_SMP_HELPERS */ 605#endif /* USE_GENERIC_SMP_HELPERS */
606 606
607/* Setup configured maximum number of CPUs to activate */
608unsigned int setup_max_cpus = NR_CPUS;
609EXPORT_SYMBOL(setup_max_cpus);
610
611
612/*
613 * Setup routine for controlling SMP activation
614 *
615 * Command-line option of "nosmp" or "maxcpus=0" will disable SMP
616 * activation entirely (the MPS table probe still happens, though).
617 *
618 * Command-line option of "maxcpus=<NUM>", where <NUM> is an integer
619 * greater than 0, limits the maximum number of CPUs activated in
620 * SMP mode to <NUM>.
621 */
622
623void __weak arch_disable_smp_support(void) { }
624
625static int __init nosmp(char *str)
626{
627 setup_max_cpus = 0;
628 arch_disable_smp_support();
629
630 return 0;
631}
632
633early_param("nosmp", nosmp);
634
635/* this is hard limit */
636static int __init nrcpus(char *str)
637{
638 int nr_cpus;
639
640 get_option(&str, &nr_cpus);
641 if (nr_cpus > 0 && nr_cpus < nr_cpu_ids)
642 nr_cpu_ids = nr_cpus;
643
644 return 0;
645}
646
647early_param("nr_cpus", nrcpus);
648
649static int __init maxcpus(char *str)
650{
651 get_option(&str, &setup_max_cpus);
652 if (setup_max_cpus == 0)
653 arch_disable_smp_support();
654
655 return 0;
656}
657
658early_param("maxcpus", maxcpus);
659
660/* Setup number of possible processor ids */
661int nr_cpu_ids __read_mostly = NR_CPUS;
662EXPORT_SYMBOL(nr_cpu_ids);
663
664/* An arch may set nr_cpu_ids earlier if needed, so this would be redundant */
665void __init setup_nr_cpu_ids(void)
666{
667 nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1;
668}
669
670/* Called by boot processor to activate the rest. */
671void __init smp_init(void)
672{
673 unsigned int cpu;
674
675 /* FIXME: This should be done in userspace --RR */
676 for_each_present_cpu(cpu) {
677 if (num_online_cpus() >= setup_max_cpus)
678 break;
679 if (!cpu_online(cpu))
680 cpu_up(cpu);
681 }
682
683 /* Any cleanup work */
684 printk(KERN_INFO "Brought up %ld CPUs\n", (long)num_online_cpus());
685 smp_cpus_done(setup_max_cpus);
686}
687
607/* 688/*
608 * Call a function on all processors. May be used during early boot while 689 * Call a function on all processors. May be used during early boot while
609 * early_boot_irqs_disabled is set. Use local_irq_save/restore() instead 690 * early_boot_irqs_disabled is set. Use local_irq_save/restore() instead