blob: b0c4152995f8bb78664869174368f77a85bfd1fc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* CPU control.
2 * (C) 2001, 2002, 2003, 2004 Rusty Russell
3 *
4 * This code is licenced under the GPL.
5 */
6#include <linux/proc_fs.h>
7#include <linux/smp.h>
8#include <linux/init.h>
9#include <linux/notifier.h>
10#include <linux/sched.h>
11#include <linux/unistd.h>
12#include <linux/cpu.h>
13#include <linux/module.h>
14#include <linux/kthread.h>
15#include <linux/stop_machine.h>
Ingo Molnar81615b62006-06-26 00:24:32 -070016#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Gautham R Shenoyd2219382008-01-25 21:08:01 +010018/* Serializes the updates to cpu_online_map, cpu_present_map */
Linus Torvaldsaa953872006-07-23 12:12:16 -070019static DEFINE_MUTEX(cpu_add_remove_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Neil Brownbd5349c2006-10-17 00:10:35 -070021static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -070023/* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
24 * Should always be manipulated under cpu_add_remove_lock
25 */
26static int cpu_hotplug_disabled;
27
Gautham R Shenoyd2219382008-01-25 21:08:01 +010028static struct {
29 struct task_struct *active_writer;
30 struct mutex lock; /* Synchronizes accesses to refcount, */
31 /*
32 * Also blocks the new readers during
33 * an ongoing cpu hotplug operation.
34 */
35 int refcount;
36 wait_queue_head_t writer_queue;
37} cpu_hotplug;
Ashok Raj90d45d12005-11-08 21:34:24 -080038
Gautham R Shenoyd2219382008-01-25 21:08:01 +010039#define writer_exists() (cpu_hotplug.active_writer != NULL)
40
41void __init cpu_hotplug_init(void)
42{
43 cpu_hotplug.active_writer = NULL;
44 mutex_init(&cpu_hotplug.lock);
45 cpu_hotplug.refcount = 0;
46 init_waitqueue_head(&cpu_hotplug.writer_queue);
47}
48
49#ifdef CONFIG_HOTPLUG_CPU
Ashok Raj90d45d12005-11-08 21:34:24 -080050
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +010051void get_online_cpus(void)
Ashok Raja9d9baa2005-11-28 13:43:46 -080052{
Gautham R Shenoyd2219382008-01-25 21:08:01 +010053 might_sleep();
54 if (cpu_hotplug.active_writer == current)
Linus Torvaldsaa953872006-07-23 12:12:16 -070055 return;
Gautham R Shenoyd2219382008-01-25 21:08:01 +010056 mutex_lock(&cpu_hotplug.lock);
57 cpu_hotplug.refcount++;
58 mutex_unlock(&cpu_hotplug.lock);
59
Ashok Raja9d9baa2005-11-28 13:43:46 -080060}
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +010061EXPORT_SYMBOL_GPL(get_online_cpus);
Ashok Raj90d45d12005-11-08 21:34:24 -080062
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +010063void put_online_cpus(void)
Ashok Raja9d9baa2005-11-28 13:43:46 -080064{
Gautham R Shenoyd2219382008-01-25 21:08:01 +010065 if (cpu_hotplug.active_writer == current)
Linus Torvaldsaa953872006-07-23 12:12:16 -070066 return;
Gautham R Shenoyd2219382008-01-25 21:08:01 +010067 mutex_lock(&cpu_hotplug.lock);
68 cpu_hotplug.refcount--;
69
70 if (unlikely(writer_exists()) && !cpu_hotplug.refcount)
71 wake_up(&cpu_hotplug.writer_queue);
72
73 mutex_unlock(&cpu_hotplug.lock);
74
Ashok Raja9d9baa2005-11-28 13:43:46 -080075}
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +010076EXPORT_SYMBOL_GPL(put_online_cpus);
Ashok Raja9d9baa2005-11-28 13:43:46 -080077
Ashok Raja9d9baa2005-11-28 13:43:46 -080078#endif /* CONFIG_HOTPLUG_CPU */
Ashok Raj90d45d12005-11-08 21:34:24 -080079
Gautham R Shenoyd2219382008-01-25 21:08:01 +010080/*
81 * The following two API's must be used when attempting
82 * to serialize the updates to cpu_online_map, cpu_present_map.
83 */
84void cpu_maps_update_begin(void)
85{
86 mutex_lock(&cpu_add_remove_lock);
87}
88
89void cpu_maps_update_done(void)
90{
91 mutex_unlock(&cpu_add_remove_lock);
92}
93
94/*
95 * This ensures that the hotplug operation can begin only when the
96 * refcount goes to zero.
97 *
98 * Note that during a cpu-hotplug operation, the new readers, if any,
99 * will be blocked by the cpu_hotplug.lock
100 *
101 * Since cpu_maps_update_begin is always called after invoking
102 * cpu_maps_update_begin, we can be sure that only one writer is active.
103 *
104 * Note that theoretically, there is a possibility of a livelock:
105 * - Refcount goes to zero, last reader wakes up the sleeping
106 * writer.
107 * - Last reader unlocks the cpu_hotplug.lock.
108 * - A new reader arrives at this moment, bumps up the refcount.
109 * - The writer acquires the cpu_hotplug.lock finds the refcount
110 * non zero and goes to sleep again.
111 *
112 * However, this is very difficult to achieve in practice since
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +0100113 * get_online_cpus() not an api which is called all that often.
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100114 *
115 */
116static void cpu_hotplug_begin(void)
117{
118 DECLARE_WAITQUEUE(wait, current);
119
120 mutex_lock(&cpu_hotplug.lock);
121
122 cpu_hotplug.active_writer = current;
123 add_wait_queue_exclusive(&cpu_hotplug.writer_queue, &wait);
124 while (cpu_hotplug.refcount) {
125 set_current_state(TASK_UNINTERRUPTIBLE);
126 mutex_unlock(&cpu_hotplug.lock);
127 schedule();
128 mutex_lock(&cpu_hotplug.lock);
129 }
130 remove_wait_queue_locked(&cpu_hotplug.writer_queue, &wait);
131}
132
133static void cpu_hotplug_done(void)
134{
135 cpu_hotplug.active_writer = NULL;
136 mutex_unlock(&cpu_hotplug.lock);
137}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/* Need to know about CPUs going up/down? */
Chandra Seetharaman65edc682006-06-27 02:54:08 -0700139int __cpuinit register_cpu_notifier(struct notifier_block *nb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
Neil Brownbd5349c2006-10-17 00:10:35 -0700141 int ret;
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100142 cpu_maps_update_begin();
Neil Brownbd5349c2006-10-17 00:10:35 -0700143 ret = raw_notifier_chain_register(&cpu_chain, nb);
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100144 cpu_maps_update_done();
Neil Brownbd5349c2006-10-17 00:10:35 -0700145 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
Chandra Seetharaman65edc682006-06-27 02:54:08 -0700147
148#ifdef CONFIG_HOTPLUG_CPU
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150EXPORT_SYMBOL(register_cpu_notifier);
151
152void unregister_cpu_notifier(struct notifier_block *nb)
153{
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100154 cpu_maps_update_begin();
Neil Brownbd5349c2006-10-17 00:10:35 -0700155 raw_notifier_chain_unregister(&cpu_chain, nb);
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100156 cpu_maps_update_done();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158EXPORT_SYMBOL(unregister_cpu_notifier);
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160static inline void check_for_tasks(int cpu)
161{
162 struct task_struct *p;
163
164 write_lock_irq(&tasklist_lock);
165 for_each_process(p) {
166 if (task_cpu(p) == cpu &&
167 (!cputime_eq(p->utime, cputime_zero) ||
168 !cputime_eq(p->stime, cputime_zero)))
169 printk(KERN_WARNING "Task %s (pid = %d) is on cpu %d\
Heiko Carstense7407dc2007-05-09 02:34:04 -0700170 (state = %ld, flags = %x) \n",
Pavel Emelyanovba25f9d2007-10-18 23:40:40 -0700171 p->comm, task_pid_nr(p), cpu,
172 p->state, p->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
174 write_unlock_irq(&tasklist_lock);
175}
176
Avi Kivitydb912f92007-05-24 12:23:10 +0300177struct take_cpu_down_param {
178 unsigned long mod;
179 void *hcpu;
180};
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182/* Take this CPU down. */
Avi Kivitydb912f92007-05-24 12:23:10 +0300183static int take_cpu_down(void *_param)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
Avi Kivitydb912f92007-05-24 12:23:10 +0300185 struct take_cpu_down_param *param = _param;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 int err;
187
Avi Kivitydb912f92007-05-24 12:23:10 +0300188 raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
189 param->hcpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 /* Ensure this CPU doesn't handle any more interrupts. */
191 err = __cpu_disable();
192 if (err < 0)
Zwane Mwaikambof3705132005-06-25 14:54:50 -0700193 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Zwane Mwaikambof3705132005-06-25 14:54:50 -0700195 /* Force idle task to run as soon as we yield: it should
196 immediately notice cpu is offline and die quickly. */
197 sched_idle_next();
198 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700201/* Requires cpu_add_remove_lock to be held */
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700202static int _cpu_down(unsigned int cpu, int tasks_frozen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
Heiko Carstense7407dc2007-05-09 02:34:04 -0700204 int err, nr_calls = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 struct task_struct *p;
206 cpumask_t old_allowed, tmp;
Heiko Carstense7407dc2007-05-09 02:34:04 -0700207 void *hcpu = (void *)(long)cpu;
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700208 unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
Avi Kivitydb912f92007-05-24 12:23:10 +0300209 struct take_cpu_down_param tcd_param = {
210 .mod = mod,
211 .hcpu = hcpu,
212 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700214 if (num_online_cpus() == 1)
215 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700217 if (!cpu_online(cpu))
218 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100220 cpu_hotplug_begin();
Heiko Carstense7407dc2007-05-09 02:34:04 -0700221 raw_notifier_call_chain(&cpu_chain, CPU_LOCK_ACQUIRE, hcpu);
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700222 err = __raw_notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE | mod,
Heiko Carstense7407dc2007-05-09 02:34:04 -0700223 hcpu, -1, &nr_calls);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 if (err == NOTIFY_BAD) {
Akinobu Mitaa0d8cdb2007-10-18 03:05:12 -0700225 nr_calls--;
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700226 __raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod,
227 hcpu, nr_calls, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 printk("%s: attempt to take down CPU %u failed\n",
229 __FUNCTION__, cpu);
Gautham R Shenoybaaca492007-05-09 02:34:03 -0700230 err = -EINVAL;
231 goto out_release;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
233
234 /* Ensure that we are not runnable on dying cpu */
235 old_allowed = current->cpus_allowed;
236 tmp = CPU_MASK_ALL;
237 cpu_clear(cpu, tmp);
238 set_cpus_allowed(current, tmp);
239
Avi Kivitydb912f92007-05-24 12:23:10 +0300240 p = __stop_machine_run(take_cpu_down, &tcd_param, cpu);
Linus Torvaldsaa953872006-07-23 12:12:16 -0700241
Satoru Takeuchi8fa1d7d2006-10-28 10:38:57 -0700242 if (IS_ERR(p) || cpu_online(cpu)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 /* CPU didn't die: tell everyone. Can't complain. */
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700244 if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod,
Heiko Carstense7407dc2007-05-09 02:34:04 -0700245 hcpu) == NOTIFY_BAD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 BUG();
247
Satoru Takeuchi8fa1d7d2006-10-28 10:38:57 -0700248 if (IS_ERR(p)) {
249 err = PTR_ERR(p);
250 goto out_allowed;
251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 goto out_thread;
Satoru Takeuchi8fa1d7d2006-10-28 10:38:57 -0700253 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255 /* Wait for it to sleep (leaving idle task). */
256 while (!idle_cpu(cpu))
257 yield();
258
259 /* This actually kills the CPU. */
260 __cpu_die(cpu);
261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 /* CPU is completely dead: tell everyone. Too late to complain. */
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700263 if (raw_notifier_call_chain(&cpu_chain, CPU_DEAD | mod,
264 hcpu) == NOTIFY_BAD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 BUG();
266
267 check_for_tasks(cpu);
268
269out_thread:
270 err = kthread_stop(p);
271out_allowed:
272 set_cpus_allowed(current, old_allowed);
Gautham R Shenoybaaca492007-05-09 02:34:03 -0700273out_release:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700274 raw_notifier_call_chain(&cpu_chain, CPU_LOCK_RELEASE, hcpu);
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100275 cpu_hotplug_done();
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700276 return err;
277}
278
279int cpu_down(unsigned int cpu)
280{
281 int err = 0;
282
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100283 cpu_maps_update_begin();
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700284 if (cpu_hotplug_disabled)
285 err = -EBUSY;
286 else
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700287 err = _cpu_down(cpu, 0);
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700288
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100289 cpu_maps_update_done();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 return err;
291}
292#endif /*CONFIG_HOTPLUG_CPU*/
293
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700294/* Requires cpu_add_remove_lock to be held */
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700295static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
Gautham R Shenoybaaca492007-05-09 02:34:03 -0700297 int ret, nr_calls = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 void *hcpu = (void *)(long)cpu;
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700299 unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700301 if (cpu_online(cpu) || !cpu_present(cpu))
302 return -EINVAL;
Ashok Raj90d45d12005-11-08 21:34:24 -0800303
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100304 cpu_hotplug_begin();
Gautham R Shenoybaaca492007-05-09 02:34:03 -0700305 raw_notifier_call_chain(&cpu_chain, CPU_LOCK_ACQUIRE, hcpu);
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700306 ret = __raw_notifier_call_chain(&cpu_chain, CPU_UP_PREPARE | mod, hcpu,
Gautham R Shenoybaaca492007-05-09 02:34:03 -0700307 -1, &nr_calls);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 if (ret == NOTIFY_BAD) {
Akinobu Mitaa0d8cdb2007-10-18 03:05:12 -0700309 nr_calls--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 printk("%s: attempt to bring up CPU %u failed\n",
311 __FUNCTION__, cpu);
312 ret = -EINVAL;
313 goto out_notify;
314 }
315
316 /* Arch-specific enabling code. */
317 ret = __cpu_up(cpu);
318 if (ret != 0)
319 goto out_notify;
Eric Sesterhenn6978c702006-03-24 18:45:21 +0100320 BUG_ON(!cpu_online(cpu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 /* Now call notifier in preparation. */
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700323 raw_notifier_call_chain(&cpu_chain, CPU_ONLINE | mod, hcpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325out_notify:
326 if (ret != 0)
Gautham R Shenoybaaca492007-05-09 02:34:03 -0700327 __raw_notifier_call_chain(&cpu_chain,
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700328 CPU_UP_CANCELED | mod, hcpu, nr_calls, NULL);
Gautham R Shenoybaaca492007-05-09 02:34:03 -0700329 raw_notifier_call_chain(&cpu_chain, CPU_LOCK_RELEASE, hcpu);
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100330 cpu_hotplug_done();
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 return ret;
333}
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700334
Gautham R Shenoyb282b6f2007-01-10 23:15:34 -0800335int __cpuinit cpu_up(unsigned int cpu)
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700336{
337 int err = 0;
KAMEZAWA Hiroyuki73e753a2007-10-18 23:40:47 -0700338 if (!cpu_isset(cpu, cpu_possible_map)) {
339 printk(KERN_ERR "can't online cpu %d because it is not "
340 "configured as may-hotadd at boot time\n", cpu);
341#if defined(CONFIG_IA64) || defined(CONFIG_X86_64) || defined(CONFIG_S390)
342 printk(KERN_ERR "please check additional_cpus= boot "
343 "parameter\n");
344#endif
345 return -EINVAL;
346 }
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700347
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100348 cpu_maps_update_begin();
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700349 if (cpu_hotplug_disabled)
350 err = -EBUSY;
351 else
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700352 err = _cpu_up(cpu, 0);
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700353
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100354 cpu_maps_update_done();
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700355 return err;
356}
357
Rafael J. Wysockif3de4be2007-08-30 23:56:29 -0700358#ifdef CONFIG_PM_SLEEP_SMP
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700359static cpumask_t frozen_cpus;
360
361int disable_nonboot_cpus(void)
362{
Ingo Molnare1d9fd22006-12-23 16:55:29 +0100363 int cpu, first_cpu, error = 0;
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700364
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100365 cpu_maps_update_begin();
Rafael J. Wysocki1d64b9c2007-04-01 23:49:49 -0700366 first_cpu = first_cpu(cpu_online_map);
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700367 /* We take down all of the non-boot CPUs in one shot to avoid races
368 * with the userspace trying to use the CPU hotplug at the same time
369 */
370 cpus_clear(frozen_cpus);
371 printk("Disabling non-boot CPUs ...\n");
372 for_each_online_cpu(cpu) {
373 if (cpu == first_cpu)
374 continue;
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700375 error = _cpu_down(cpu, 1);
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700376 if (!error) {
377 cpu_set(cpu, frozen_cpus);
378 printk("CPU%d is down\n", cpu);
379 } else {
380 printk(KERN_ERR "Error taking CPU%d down: %d\n",
381 cpu, error);
382 break;
383 }
384 }
385 if (!error) {
386 BUG_ON(num_online_cpus() > 1);
387 /* Make sure the CPUs won't be enabled by someone else */
388 cpu_hotplug_disabled = 1;
389 } else {
Ingo Molnare1d9fd22006-12-23 16:55:29 +0100390 printk(KERN_ERR "Non-boot CPUs are not disabled\n");
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700391 }
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100392 cpu_maps_update_done();
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700393 return error;
394}
395
396void enable_nonboot_cpus(void)
397{
398 int cpu, error;
399
400 /* Allow everyone to use the CPU hotplug again */
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100401 cpu_maps_update_begin();
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700402 cpu_hotplug_disabled = 0;
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800403 if (cpus_empty(frozen_cpus))
Rafael J. Wysocki1d64b9c2007-04-01 23:49:49 -0700404 goto out;
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700405
406 printk("Enabling non-boot CPUs ...\n");
407 for_each_cpu_mask(cpu, frozen_cpus) {
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700408 error = _cpu_up(cpu, 1);
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700409 if (!error) {
410 printk("CPU%d is up\n", cpu);
411 continue;
412 }
Rafael J. Wysocki1d64b9c2007-04-01 23:49:49 -0700413 printk(KERN_WARNING "Error taking CPU%d up: %d\n", cpu, error);
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700414 }
415 cpus_clear(frozen_cpus);
Rafael J. Wysocki1d64b9c2007-04-01 23:49:49 -0700416out:
Gautham R Shenoyd2219382008-01-25 21:08:01 +0100417 cpu_maps_update_done();
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -0700418}
Rafael J. Wysockif3de4be2007-08-30 23:56:29 -0700419#endif /* CONFIG_PM_SLEEP_SMP */