Messages in this thread Patch in this message | | | Date | Mon, 13 Oct 2008 23:50:11 +0200 | From | Heiko Carstens <> | Subject | [PATCH/RFC v2 4/6] stop_machine: special case for one cpu |
| |
From: Heiko Carstens <heiko.carstens@de.ibm.com>
If only one cpu is online we might as well use the non-smp variant of stop_machine which should be much faster since no scheduling is needed.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> --- include/linux/stop_machine.h | 16 +++++++++++----- kernel/stop_machine.c | 3 +++ 2 files changed, 14 insertions(+), 5 deletions(-)
Index: linux-2.6/include/linux/stop_machine.h =================================================================== --- linux-2.6.orig/include/linux/stop_machine.h +++ linux-2.6/include/linux/stop_machine.h @@ -8,6 +8,16 @@ #include <linux/cpumask.h> #include <asm/system.h> +static inline int stop_machine_simple(int (*fn)(void *), void *data, + const cpumask_t *cpus) +{ + int ret; + local_irq_disable(); + ret = fn(data); + local_irq_enable(); + return ret; +} + #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP) /** @@ -40,11 +50,7 @@ int __stop_machine(int (*fn)(void *), vo static inline int stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus) { - int ret; - local_irq_disable(); - ret = fn(data); - local_irq_enable(); - return ret; + return stop_machine_simple(fn, data, cpus); } #endif /* CONFIG_SMP */ #endif /* _LINUX_STOP_MACHINE */ Index: linux-2.6/kernel/stop_machine.c =================================================================== --- linux-2.6.orig/kernel/stop_machine.c +++ linux-2.6/kernel/stop_machine.c @@ -111,6 +111,9 @@ int __stop_machine(int (*fn)(void *), vo struct work_struct *sm_work; int i; + if (num_online_cpus() == 1) + return stop_machine_simple(fn, data, cpus); + /* Set up initial state. */ mutex_lock(&lock); num_threads = num_online_cpus(); --
| |