};
static LIST_HEAD(smp_alt_modules);
static DEFINE_SPINLOCK(smp_alt);
+static int smp_mode = 1; /* protected by smp_alt */
void alternatives_smp_module_add(struct module *mod, char *name,
void *locks, void *locks_end,
BUG_ON(!smp && (num_online_cpus() > 1));
spin_lock_irqsave(&smp_alt, flags);
- if (smp) {
+
+ /*
+ * Avoid unnecessary switches because it forces JIT based VMs to
+ * throw away all cached translations, which can be quite costly.
+ */
+ if (smp == smp_mode) {
+ /* nothing */
+ } else if (smp) {
printk(KERN_INFO "SMP alternatives: switching to SMP code\n");
clear_cpu_cap(&boot_cpu_data, X86_FEATURE_UP);
clear_cpu_cap(&cpu_data(0), X86_FEATURE_UP);
alternatives_smp_unlock(mod->locks, mod->locks_end,
mod->text, mod->text_end);
}
+ smp_mode = smp;
spin_unlock_irqrestore(&smp_alt, flags);
}
alternatives_smp_module_add(NULL, "core kernel",
__smp_locks, __smp_locks_end,
_text, _etext);
- alternatives_smp_switch(0);
+
+ /* Only switch to UP mode if we don't immediately boot others */
+ if (num_possible_cpus() == 1 || setup_max_cpus <= 1)
+ alternatives_smp_switch(0);
}
#endif
apply_paravirt(__parainstructions, __parainstructions_end);
#ifdef CONFIG_SMP
/* Setup configured maximum number of CPUs to activate */
-static unsigned int __initdata max_cpus = NR_CPUS;
+unsigned int __initdata setup_max_cpus = NR_CPUS;
/*
* Setup routine for controlling SMP activation
static int __init nosmp(char *str)
{
- max_cpus = 0;
+ setup_max_cpus = 0;
disable_ioapic_setup();
return 0;
}
static int __init maxcpus(char *str)
{
- get_option(&str, &max_cpus);
- if (max_cpus == 0)
+ get_option(&str, &setup_max_cpus);
+ if (setup_max_cpus == 0)
disable_ioapic_setup();
return 0;
early_param("maxcpus", maxcpus);
#else
-#define max_cpus NR_CPUS
+#define setup_max_cpus NR_CPUS
#endif
/*
/* FIXME: This should be done in userspace --RR */
for_each_present_cpu(cpu) {
- if (num_online_cpus() >= max_cpus)
+ if (num_online_cpus() >= setup_max_cpus)
break;
if (!cpu_online(cpu))
cpu_up(cpu);
/* Any cleanup work */
printk(KERN_INFO "Brought up %ld CPUs\n", (long)num_online_cpus());
- smp_cpus_done(max_cpus);
+ smp_cpus_done(setup_max_cpus);
}
#endif
__set_special_pids(1, 1);
cad_pid = task_pid(current);
- smp_prepare_cpus(max_cpus);
+ smp_prepare_cpus(setup_max_cpus);
do_pre_smp_initcalls();