diff options
Diffstat (limited to 'kernel/cpu.c')
| -rw-r--r-- | kernel/cpu.c | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/kernel/cpu.c b/kernel/cpu.c index 2060c6e57027..a4eb5227a19e 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c | |||
| @@ -10,13 +10,18 @@ | |||
| 10 | #include <linux/sched.h> | 10 | #include <linux/sched.h> |
| 11 | #include <linux/unistd.h> | 11 | #include <linux/unistd.h> |
| 12 | #include <linux/cpu.h> | 12 | #include <linux/cpu.h> |
| 13 | #include <linux/oom.h> | ||
| 14 | #include <linux/rcupdate.h> | ||
| 13 | #include <linux/export.h> | 15 | #include <linux/export.h> |
| 16 | #include <linux/bug.h> | ||
| 14 | #include <linux/kthread.h> | 17 | #include <linux/kthread.h> |
| 15 | #include <linux/stop_machine.h> | 18 | #include <linux/stop_machine.h> |
| 16 | #include <linux/mutex.h> | 19 | #include <linux/mutex.h> |
| 17 | #include <linux/gfp.h> | 20 | #include <linux/gfp.h> |
| 18 | #include <linux/suspend.h> | 21 | #include <linux/suspend.h> |
| 19 | 22 | ||
| 23 | #include "smpboot.h" | ||
| 24 | |||
| 20 | #ifdef CONFIG_SMP | 25 | #ifdef CONFIG_SMP |
| 21 | /* Serializes the updates to cpu_online_mask, cpu_present_mask */ | 26 | /* Serializes the updates to cpu_online_mask, cpu_present_mask */ |
| 22 | static DEFINE_MUTEX(cpu_add_remove_lock); | 27 | static DEFINE_MUTEX(cpu_add_remove_lock); |
| @@ -171,6 +176,47 @@ void __ref unregister_cpu_notifier(struct notifier_block *nb) | |||
| 171 | } | 176 | } |
| 172 | EXPORT_SYMBOL(unregister_cpu_notifier); | 177 | EXPORT_SYMBOL(unregister_cpu_notifier); |
| 173 | 178 | ||
| 179 | /** | ||
| 180 | * clear_tasks_mm_cpumask - Safely clear tasks' mm_cpumask for a CPU | ||
| 181 | * @cpu: a CPU id | ||
| 182 | * | ||
| 183 | * This function walks all processes, finds a valid mm struct for each one and | ||
| 184 | * then clears a corresponding bit in mm's cpumask. While this all sounds | ||
| 185 | * trivial, there are various non-obvious corner cases, which this function | ||
| 186 | * tries to solve in a safe manner. | ||
| 187 | * | ||
| 188 | * Also note that the function uses a somewhat relaxed locking scheme, so it may | ||
| 189 | * be called only for an already offlined CPU. | ||
| 190 | */ | ||
| 191 | void clear_tasks_mm_cpumask(int cpu) | ||
| 192 | { | ||
| 193 | struct task_struct *p; | ||
| 194 | |||
| 195 | /* | ||
| 196 | * This function is called after the cpu is taken down and marked | ||
| 197 | * offline, so its not like new tasks will ever get this cpu set in | ||
| 198 | * their mm mask. -- Peter Zijlstra | ||
| 199 | * Thus, we may use rcu_read_lock() here, instead of grabbing | ||
| 200 | * full-fledged tasklist_lock. | ||
| 201 | */ | ||
| 202 | WARN_ON(cpu_online(cpu)); | ||
| 203 | rcu_read_lock(); | ||
| 204 | for_each_process(p) { | ||
| 205 | struct task_struct *t; | ||
| 206 | |||
| 207 | /* | ||
| 208 | * Main thread might exit, but other threads may still have | ||
| 209 | * a valid mm. Find one. | ||
| 210 | */ | ||
| 211 | t = find_lock_task_mm(p); | ||
| 212 | if (!t) | ||
| 213 | continue; | ||
| 214 | cpumask_clear_cpu(cpu, mm_cpumask(t->mm)); | ||
| 215 | task_unlock(t); | ||
| 216 | } | ||
| 217 | rcu_read_unlock(); | ||
| 218 | } | ||
| 219 | |||
| 174 | static inline void check_for_tasks(int cpu) | 220 | static inline void check_for_tasks(int cpu) |
| 175 | { | 221 | { |
| 176 | struct task_struct *p; | 222 | struct task_struct *p; |
| @@ -295,11 +341,19 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen) | |||
| 295 | int ret, nr_calls = 0; | 341 | int ret, nr_calls = 0; |
| 296 | void *hcpu = (void *)(long)cpu; | 342 | void *hcpu = (void *)(long)cpu; |
| 297 | unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; | 343 | unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; |
| 344 | struct task_struct *idle; | ||
| 298 | 345 | ||
| 299 | if (cpu_online(cpu) || !cpu_present(cpu)) | 346 | if (cpu_online(cpu) || !cpu_present(cpu)) |
| 300 | return -EINVAL; | 347 | return -EINVAL; |
| 301 | 348 | ||
| 302 | cpu_hotplug_begin(); | 349 | cpu_hotplug_begin(); |
| 350 | |||
| 351 | idle = idle_thread_get(cpu); | ||
| 352 | if (IS_ERR(idle)) { | ||
| 353 | ret = PTR_ERR(idle); | ||
| 354 | goto out; | ||
| 355 | } | ||
| 356 | |||
| 303 | ret = __cpu_notify(CPU_UP_PREPARE | mod, hcpu, -1, &nr_calls); | 357 | ret = __cpu_notify(CPU_UP_PREPARE | mod, hcpu, -1, &nr_calls); |
| 304 | if (ret) { | 358 | if (ret) { |
| 305 | nr_calls--; | 359 | nr_calls--; |
| @@ -309,7 +363,7 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen) | |||
| 309 | } | 363 | } |
| 310 | 364 | ||
| 311 | /* Arch-specific enabling code. */ | 365 | /* Arch-specific enabling code. */ |
| 312 | ret = __cpu_up(cpu); | 366 | ret = __cpu_up(cpu, idle); |
| 313 | if (ret != 0) | 367 | if (ret != 0) |
| 314 | goto out_notify; | 368 | goto out_notify; |
| 315 | BUG_ON(!cpu_online(cpu)); | 369 | BUG_ON(!cpu_online(cpu)); |
| @@ -320,6 +374,7 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen) | |||
| 320 | out_notify: | 374 | out_notify: |
| 321 | if (ret != 0) | 375 | if (ret != 0) |
| 322 | __cpu_notify(CPU_UP_CANCELED | mod, hcpu, nr_calls, NULL); | 376 | __cpu_notify(CPU_UP_CANCELED | mod, hcpu, nr_calls, NULL); |
| 377 | out: | ||
| 323 | cpu_hotplug_done(); | 378 | cpu_hotplug_done(); |
| 324 | 379 | ||
| 325 | return ret; | 380 | return ret; |
