diff options
| -rw-r--r-- | include/linux/stop_machine.h | 34 | ||||
| -rw-r--r-- | kernel/cpu.c | 3 | ||||
| -rw-r--r-- | kernel/stop_machine.c | 27 |
3 files changed, 39 insertions, 25 deletions
diff --git a/include/linux/stop_machine.h b/include/linux/stop_machine.h index 36c2c7284eb3..f1cb0ba6d715 100644 --- a/include/linux/stop_machine.h +++ b/include/linux/stop_machine.h | |||
| @@ -5,19 +5,19 @@ | |||
| 5 | (and more). So the "read" side to such a lock is anything which | 5 | (and more). So the "read" side to such a lock is anything which |
| 6 | diables preeempt. */ | 6 | diables preeempt. */ |
| 7 | #include <linux/cpu.h> | 7 | #include <linux/cpu.h> |
| 8 | #include <linux/cpumask.h> | ||
| 8 | #include <asm/system.h> | 9 | #include <asm/system.h> |
| 9 | 10 | ||
| 10 | #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP) | 11 | #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP) |
| 11 | 12 | ||
| 13 | /* Deprecated, but useful for transition. */ | ||
| 12 | #define ALL_CPUS ~0U | 14 | #define ALL_CPUS ~0U |
| 13 | 15 | ||
| 14 | /** | 16 | /** |
| 15 | * stop_machine_run: freeze the machine on all CPUs and run this function | 17 | * stop_machine: freeze the machine on all CPUs and run this function |
| 16 | * @fn: the function to run | 18 | * @fn: the function to run |
| 17 | * @data: the data ptr for the @fn() | 19 | * @data: the data ptr for the @fn() |
| 18 | * @cpu: if @cpu == n, run @fn() on cpu n | 20 | * @cpus: the cpus to run the @fn() on (NULL = any online cpu) |
| 19 | * if @cpu == NR_CPUS, run @fn() on any cpu | ||
| 20 | * if @cpu == ALL_CPUS, run @fn() on every online CPU. | ||
| 21 | * | 21 | * |
| 22 | * Description: This causes a thread to be scheduled on every cpu, | 22 | * Description: This causes a thread to be scheduled on every cpu, |
| 23 | * each of which disables interrupts. The result is that noone is | 23 | * each of which disables interrupts. The result is that noone is |
| @@ -26,22 +26,22 @@ | |||
| 26 | * | 26 | * |
| 27 | * This can be thought of as a very heavy write lock, equivalent to | 27 | * This can be thought of as a very heavy write lock, equivalent to |
| 28 | * grabbing every spinlock in the kernel. */ | 28 | * grabbing every spinlock in the kernel. */ |
| 29 | int stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu); | 29 | int stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus); |
| 30 | 30 | ||
| 31 | /** | 31 | /** |
| 32 | * __stop_machine_run: freeze the machine on all CPUs and run this function | 32 | * __stop_machine: freeze the machine on all CPUs and run this function |
| 33 | * @fn: the function to run | 33 | * @fn: the function to run |
| 34 | * @data: the data ptr for the @fn | 34 | * @data: the data ptr for the @fn |
| 35 | * @cpu: the cpu to run @fn on (or any, if @cpu == NR_CPUS. | 35 | * @cpus: the cpus to run the @fn() on (NULL = any online cpu) |
| 36 | * | 36 | * |
| 37 | * Description: This is a special version of the above, which assumes cpus | 37 | * Description: This is a special version of the above, which assumes cpus |
| 38 | * won't come or go while it's being called. Used by hotplug cpu. | 38 | * won't come or go while it's being called. Used by hotplug cpu. |
| 39 | */ | 39 | */ |
| 40 | int __stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu); | 40 | int __stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus); |
| 41 | #else | 41 | #else |
| 42 | 42 | ||
| 43 | static inline int stop_machine_run(int (*fn)(void *), void *data, | 43 | static inline int stop_machine(int (*fn)(void *), void *data, |
| 44 | unsigned int cpu) | 44 | const cpumask_t *cpus) |
| 45 | { | 45 | { |
| 46 | int ret; | 46 | int ret; |
| 47 | local_irq_disable(); | 47 | local_irq_disable(); |
| @@ -50,4 +50,18 @@ static inline int stop_machine_run(int (*fn)(void *), void *data, | |||
| 50 | return ret; | 50 | return ret; |
| 51 | } | 51 | } |
| 52 | #endif /* CONFIG_SMP */ | 52 | #endif /* CONFIG_SMP */ |
| 53 | |||
| 54 | static inline int __deprecated stop_machine_run(int (*fn)(void *), void *data, | ||
| 55 | unsigned int cpu) | ||
| 56 | { | ||
| 57 | /* If they don't care which cpu fn runs on, just pick one. */ | ||
| 58 | if (cpu == NR_CPUS) | ||
| 59 | return stop_machine(fn, data, NULL); | ||
| 60 | else if (cpu == ~0U) | ||
| 61 | return stop_machine(fn, data, &cpu_possible_map); | ||
| 62 | else { | ||
| 63 | cpumask_t cpus = cpumask_of_cpu(cpu); | ||
| 64 | return stop_machine(fn, data, &cpus); | ||
| 65 | } | ||
| 66 | } | ||
| 53 | #endif /* _LINUX_STOP_MACHINE */ | 67 | #endif /* _LINUX_STOP_MACHINE */ |
diff --git a/kernel/cpu.c b/kernel/cpu.c index 53cf508f975a..29510d68338a 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c | |||
| @@ -248,8 +248,9 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) | |||
| 248 | cpus_setall(tmp); | 248 | cpus_setall(tmp); |
| 249 | cpu_clear(cpu, tmp); | 249 | cpu_clear(cpu, tmp); |
| 250 | set_cpus_allowed_ptr(current, &tmp); | 250 | set_cpus_allowed_ptr(current, &tmp); |
| 251 | tmp = cpumask_of_cpu(cpu); | ||
| 251 | 252 | ||
| 252 | err = __stop_machine_run(take_cpu_down, &tcd_param, cpu); | 253 | err = __stop_machine(take_cpu_down, &tcd_param, &tmp); |
| 253 | if (err) { | 254 | if (err) { |
| 254 | /* CPU didn't die: tell everyone. Can't complain. */ | 255 | /* CPU didn't die: tell everyone. Can't complain. */ |
| 255 | if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod, | 256 | if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod, |
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index 35882dccc943..e446c7c7d6a9 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c | |||
| @@ -100,7 +100,7 @@ static int chill(void *unused) | |||
| 100 | return 0; | 100 | return 0; |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | int __stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu) | 103 | int __stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus) |
| 104 | { | 104 | { |
| 105 | int i, err; | 105 | int i, err; |
| 106 | struct stop_machine_data active, idle; | 106 | struct stop_machine_data active, idle; |
| @@ -112,10 +112,6 @@ int __stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu) | |||
| 112 | idle.fn = chill; | 112 | idle.fn = chill; |
| 113 | idle.data = NULL; | 113 | idle.data = NULL; |
| 114 | 114 | ||
| 115 | /* If they don't care which cpu fn runs on, just pick one. */ | ||
| 116 | if (cpu == NR_CPUS) | ||
| 117 | cpu = any_online_cpu(cpu_online_map); | ||
| 118 | |||
| 119 | /* This could be too big for stack on large machines. */ | 115 | /* This could be too big for stack on large machines. */ |
| 120 | threads = kcalloc(NR_CPUS, sizeof(threads[0]), GFP_KERNEL); | 116 | threads = kcalloc(NR_CPUS, sizeof(threads[0]), GFP_KERNEL); |
| 121 | if (!threads) | 117 | if (!threads) |
| @@ -128,13 +124,16 @@ int __stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu) | |||
| 128 | set_state(STOPMACHINE_PREPARE); | 124 | set_state(STOPMACHINE_PREPARE); |
| 129 | 125 | ||
| 130 | for_each_online_cpu(i) { | 126 | for_each_online_cpu(i) { |
| 131 | struct stop_machine_data *smdata; | 127 | struct stop_machine_data *smdata = &idle; |
| 132 | struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 }; | 128 | struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 }; |
| 133 | 129 | ||
| 134 | if (cpu == ALL_CPUS || i == cpu) | 130 | if (!cpus) { |
| 135 | smdata = &active; | 131 | if (i == first_cpu(cpu_online_map)) |
| 136 | else | 132 | smdata = &active; |
| 137 | smdata = &idle; | 133 | } else { |
| 134 | if (cpu_isset(i, *cpus)) | ||
| 135 | smdata = &active; | ||
| 136 | } | ||
| 138 | 137 | ||
| 139 | threads[i] = kthread_create((void *)stop_cpu, smdata, "kstop%u", | 138 | threads[i] = kthread_create((void *)stop_cpu, smdata, "kstop%u", |
| 140 | i); | 139 | i); |
| @@ -154,7 +153,7 @@ int __stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu) | |||
| 154 | 153 | ||
| 155 | /* We've created all the threads. Wake them all: hold this CPU so one | 154 | /* We've created all the threads. Wake them all: hold this CPU so one |
| 156 | * doesn't hit this CPU until we're ready. */ | 155 | * doesn't hit this CPU until we're ready. */ |
| 157 | cpu = get_cpu(); | 156 | get_cpu(); |
| 158 | for_each_online_cpu(i) | 157 | for_each_online_cpu(i) |
| 159 | wake_up_process(threads[i]); | 158 | wake_up_process(threads[i]); |
| 160 | 159 | ||
| @@ -177,15 +176,15 @@ kill_threads: | |||
| 177 | return err; | 176 | return err; |
| 178 | } | 177 | } |
| 179 | 178 | ||
| 180 | int stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu) | 179 | int stop_machine(int (*fn)(void *), void *data, const cpumask_t *cpus) |
| 181 | { | 180 | { |
| 182 | int ret; | 181 | int ret; |
| 183 | 182 | ||
| 184 | /* No CPUs can come up or down during this. */ | 183 | /* No CPUs can come up or down during this. */ |
| 185 | get_online_cpus(); | 184 | get_online_cpus(); |
| 186 | ret = __stop_machine_run(fn, data, cpu); | 185 | ret = __stop_machine(fn, data, cpus); |
| 187 | put_online_cpus(); | 186 | put_online_cpus(); |
| 188 | 187 | ||
| 189 | return ret; | 188 | return ret; |
| 190 | } | 189 | } |
| 191 | EXPORT_SYMBOL_GPL(stop_machine_run); | 190 | EXPORT_SYMBOL_GPL(stop_machine); |
