ia64/linux-2.6.18-xen.hg

view kernel/cpu.c @ 912:dd42cdb0ab89

[IA64] Build blktap2 driver by default in x86 builds.

add CONFIG_XEN_BLKDEV_TAP2=y to buildconfigs/linux-defconfig_xen_ia64.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Mon Jun 29 12:09:16 2009 +0900 (2009-06-29)
parents a37a8c474d8b
children
line source
1 /* 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>
16 #include <linux/mutex.h>
18 /* This protects CPUs going up and down... */
19 static DEFINE_MUTEX(cpu_add_remove_lock);
20 static DEFINE_MUTEX(cpu_bitmask_lock);
22 static __cpuinitdata BLOCKING_NOTIFIER_HEAD(cpu_chain);
24 #ifdef CONFIG_HOTPLUG_CPU
26 /* Crappy recursive lock-takers in cpufreq! Complain loudly about idiots */
27 static struct task_struct *recursive;
28 static int recursive_depth;
30 void lock_cpu_hotplug(void)
31 {
32 struct task_struct *tsk = current;
34 if (tsk == recursive) {
35 static int warnings = 10;
36 if (warnings) {
37 printk(KERN_ERR "Lukewarm IQ detected in hotplug locking\n");
38 WARN_ON(1);
39 warnings--;
40 }
41 recursive_depth++;
42 return;
43 }
44 mutex_lock(&cpu_bitmask_lock);
45 recursive = tsk;
46 }
47 EXPORT_SYMBOL_GPL(lock_cpu_hotplug);
49 void unlock_cpu_hotplug(void)
50 {
51 /* cpufreq lock-takers fixed in mainline; shut up until dom0 kernel catches up*/
52 #ifdef CONFIG_XEN
53 WARN_ON(recursive != current);
54 #endif
55 if (recursive_depth) {
56 recursive_depth--;
57 return;
58 }
59 mutex_unlock(&cpu_bitmask_lock);
60 recursive = NULL;
61 }
62 EXPORT_SYMBOL_GPL(unlock_cpu_hotplug);
64 #endif /* CONFIG_HOTPLUG_CPU */
66 /* Need to know about CPUs going up/down? */
67 int __cpuinit register_cpu_notifier(struct notifier_block *nb)
68 {
69 return blocking_notifier_chain_register(&cpu_chain, nb);
70 }
72 #ifdef CONFIG_HOTPLUG_CPU
74 EXPORT_SYMBOL(register_cpu_notifier);
76 void unregister_cpu_notifier(struct notifier_block *nb)
77 {
78 blocking_notifier_chain_unregister(&cpu_chain, nb);
79 }
80 EXPORT_SYMBOL(unregister_cpu_notifier);
82 static inline void check_for_tasks(int cpu)
83 {
84 struct task_struct *p;
86 write_lock_irq(&tasklist_lock);
87 for_each_process(p) {
88 if (task_cpu(p) == cpu &&
89 (!cputime_eq(p->utime, cputime_zero) ||
90 !cputime_eq(p->stime, cputime_zero)))
91 printk(KERN_WARNING "Task %s (pid = %d) is on cpu %d\
92 (state = %ld, flags = %lx) \n",
93 p->comm, p->pid, cpu, p->state, p->flags);
94 }
95 write_unlock_irq(&tasklist_lock);
96 }
98 /* Take this CPU down. */
99 static int take_cpu_down(void *unused)
100 {
101 int err;
103 /* Ensure this CPU doesn't handle any more interrupts. */
104 err = __cpu_disable();
105 if (err < 0)
106 return err;
108 /* Force idle task to run as soon as we yield: it should
109 immediately notice cpu is offline and die quickly. */
110 sched_idle_next();
111 return 0;
112 }
114 int cpu_down(unsigned int cpu)
115 {
116 int err;
117 struct task_struct *p;
118 cpumask_t old_allowed, tmp;
120 mutex_lock(&cpu_add_remove_lock);
121 if (num_online_cpus() == 1) {
122 err = -EBUSY;
123 goto out;
124 }
126 if (!cpu_online(cpu)) {
127 err = -EINVAL;
128 goto out;
129 }
131 err = blocking_notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE,
132 (void *)(long)cpu);
133 if (err == NOTIFY_BAD) {
134 printk("%s: attempt to take down CPU %u failed\n",
135 __FUNCTION__, cpu);
136 err = -EINVAL;
137 goto out;
138 }
140 /* Ensure that we are not runnable on dying cpu */
141 old_allowed = current->cpus_allowed;
142 tmp = CPU_MASK_ALL;
143 cpu_clear(cpu, tmp);
144 set_cpus_allowed(current, tmp);
146 mutex_lock(&cpu_bitmask_lock);
147 p = __stop_machine_run(take_cpu_down, NULL, cpu);
148 mutex_unlock(&cpu_bitmask_lock);
150 if (IS_ERR(p)) {
151 /* CPU didn't die: tell everyone. Can't complain. */
152 if (blocking_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED,
153 (void *)(long)cpu) == NOTIFY_BAD)
154 BUG();
156 err = PTR_ERR(p);
157 goto out_allowed;
158 }
160 if (cpu_online(cpu))
161 goto out_thread;
163 /* Wait for it to sleep (leaving idle task). */
164 while (!idle_cpu(cpu))
165 yield();
167 /* This actually kills the CPU. */
168 __cpu_die(cpu);
170 /* Move it here so it can run. */
171 kthread_bind(p, get_cpu());
172 put_cpu();
174 /* CPU is completely dead: tell everyone. Too late to complain. */
175 if (blocking_notifier_call_chain(&cpu_chain, CPU_DEAD,
176 (void *)(long)cpu) == NOTIFY_BAD)
177 BUG();
179 check_for_tasks(cpu);
181 out_thread:
182 err = kthread_stop(p);
183 out_allowed:
184 set_cpus_allowed(current, old_allowed);
185 out:
186 mutex_unlock(&cpu_add_remove_lock);
187 return err;
188 }
189 #endif /*CONFIG_HOTPLUG_CPU*/
191 int __devinit cpu_up(unsigned int cpu)
192 {
193 int ret;
194 void *hcpu = (void *)(long)cpu;
196 mutex_lock(&cpu_add_remove_lock);
197 if (cpu_online(cpu) || !cpu_present(cpu)) {
198 ret = -EINVAL;
199 goto out;
200 }
202 ret = blocking_notifier_call_chain(&cpu_chain, CPU_UP_PREPARE, hcpu);
203 if (ret == NOTIFY_BAD) {
204 printk("%s: attempt to bring up CPU %u failed\n",
205 __FUNCTION__, cpu);
206 ret = -EINVAL;
207 goto out_notify;
208 }
210 /* Arch-specific enabling code. */
211 mutex_lock(&cpu_bitmask_lock);
212 ret = __cpu_up(cpu);
213 mutex_unlock(&cpu_bitmask_lock);
214 if (ret != 0)
215 goto out_notify;
216 BUG_ON(!cpu_online(cpu));
218 /* Now call notifier in preparation. */
219 blocking_notifier_call_chain(&cpu_chain, CPU_ONLINE, hcpu);
221 out_notify:
222 if (ret != 0)
223 blocking_notifier_call_chain(&cpu_chain,
224 CPU_UP_CANCELED, hcpu);
225 out:
226 mutex_unlock(&cpu_add_remove_lock);
227 return ret;
228 }