diff options
Diffstat (limited to 'kernel/cpu.c')
-rw-r--r-- | kernel/cpu.c | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/kernel/cpu.c b/kernel/cpu.c index 36e70845cfc3..208cf3497c10 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c | |||
@@ -97,7 +97,7 @@ static inline void check_for_tasks(int cpu) | |||
97 | (!cputime_eq(p->utime, cputime_zero) || | 97 | (!cputime_eq(p->utime, cputime_zero) || |
98 | !cputime_eq(p->stime, cputime_zero))) | 98 | !cputime_eq(p->stime, cputime_zero))) |
99 | printk(KERN_WARNING "Task %s (pid = %d) is on cpu %d\ | 99 | printk(KERN_WARNING "Task %s (pid = %d) is on cpu %d\ |
100 | (state = %ld, flags = %lx) \n", | 100 | (state = %ld, flags = %x) \n", |
101 | p->comm, p->pid, cpu, p->state, p->flags); | 101 | p->comm, p->pid, cpu, p->state, p->flags); |
102 | } | 102 | } |
103 | write_unlock_irq(&tasklist_lock); | 103 | write_unlock_irq(&tasklist_lock); |
@@ -120,11 +120,13 @@ static int take_cpu_down(void *unused) | |||
120 | } | 120 | } |
121 | 121 | ||
122 | /* Requires cpu_add_remove_lock to be held */ | 122 | /* Requires cpu_add_remove_lock to be held */ |
123 | static int _cpu_down(unsigned int cpu) | 123 | static int _cpu_down(unsigned int cpu, int tasks_frozen) |
124 | { | 124 | { |
125 | int err; | 125 | int err, nr_calls = 0; |
126 | struct task_struct *p; | 126 | struct task_struct *p; |
127 | cpumask_t old_allowed, tmp; | 127 | cpumask_t old_allowed, tmp; |
128 | void *hcpu = (void *)(long)cpu; | ||
129 | unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; | ||
128 | 130 | ||
129 | if (num_online_cpus() == 1) | 131 | if (num_online_cpus() == 1) |
130 | return -EBUSY; | 132 | return -EBUSY; |
@@ -132,12 +134,16 @@ static int _cpu_down(unsigned int cpu) | |||
132 | if (!cpu_online(cpu)) | 134 | if (!cpu_online(cpu)) |
133 | return -EINVAL; | 135 | return -EINVAL; |
134 | 136 | ||
135 | err = raw_notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE, | 137 | raw_notifier_call_chain(&cpu_chain, CPU_LOCK_ACQUIRE, hcpu); |
136 | (void *)(long)cpu); | 138 | err = __raw_notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE | mod, |
139 | hcpu, -1, &nr_calls); | ||
137 | if (err == NOTIFY_BAD) { | 140 | if (err == NOTIFY_BAD) { |
141 | __raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod, | ||
142 | hcpu, nr_calls, NULL); | ||
138 | printk("%s: attempt to take down CPU %u failed\n", | 143 | printk("%s: attempt to take down CPU %u failed\n", |
139 | __FUNCTION__, cpu); | 144 | __FUNCTION__, cpu); |
140 | return -EINVAL; | 145 | err = -EINVAL; |
146 | goto out_release; | ||
141 | } | 147 | } |
142 | 148 | ||
143 | /* Ensure that we are not runnable on dying cpu */ | 149 | /* Ensure that we are not runnable on dying cpu */ |
@@ -152,8 +158,8 @@ static int _cpu_down(unsigned int cpu) | |||
152 | 158 | ||
153 | if (IS_ERR(p) || cpu_online(cpu)) { | 159 | if (IS_ERR(p) || cpu_online(cpu)) { |
154 | /* CPU didn't die: tell everyone. Can't complain. */ | 160 | /* CPU didn't die: tell everyone. Can't complain. */ |
155 | if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED, | 161 | if (raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod, |
156 | (void *)(long)cpu) == NOTIFY_BAD) | 162 | hcpu) == NOTIFY_BAD) |
157 | BUG(); | 163 | BUG(); |
158 | 164 | ||
159 | if (IS_ERR(p)) { | 165 | if (IS_ERR(p)) { |
@@ -170,13 +176,9 @@ static int _cpu_down(unsigned int cpu) | |||
170 | /* This actually kills the CPU. */ | 176 | /* This actually kills the CPU. */ |
171 | __cpu_die(cpu); | 177 | __cpu_die(cpu); |
172 | 178 | ||
173 | /* Move it here so it can run. */ | ||
174 | kthread_bind(p, get_cpu()); | ||
175 | put_cpu(); | ||
176 | |||
177 | /* CPU is completely dead: tell everyone. Too late to complain. */ | 179 | /* CPU is completely dead: tell everyone. Too late to complain. */ |
178 | if (raw_notifier_call_chain(&cpu_chain, CPU_DEAD, | 180 | if (raw_notifier_call_chain(&cpu_chain, CPU_DEAD | mod, |
179 | (void *)(long)cpu) == NOTIFY_BAD) | 181 | hcpu) == NOTIFY_BAD) |
180 | BUG(); | 182 | BUG(); |
181 | 183 | ||
182 | check_for_tasks(cpu); | 184 | check_for_tasks(cpu); |
@@ -185,6 +187,8 @@ out_thread: | |||
185 | err = kthread_stop(p); | 187 | err = kthread_stop(p); |
186 | out_allowed: | 188 | out_allowed: |
187 | set_cpus_allowed(current, old_allowed); | 189 | set_cpus_allowed(current, old_allowed); |
190 | out_release: | ||
191 | raw_notifier_call_chain(&cpu_chain, CPU_LOCK_RELEASE, hcpu); | ||
188 | return err; | 192 | return err; |
189 | } | 193 | } |
190 | 194 | ||
@@ -196,7 +200,7 @@ int cpu_down(unsigned int cpu) | |||
196 | if (cpu_hotplug_disabled) | 200 | if (cpu_hotplug_disabled) |
197 | err = -EBUSY; | 201 | err = -EBUSY; |
198 | else | 202 | else |
199 | err = _cpu_down(cpu); | 203 | err = _cpu_down(cpu, 0); |
200 | 204 | ||
201 | mutex_unlock(&cpu_add_remove_lock); | 205 | mutex_unlock(&cpu_add_remove_lock); |
202 | return err; | 206 | return err; |
@@ -204,15 +208,18 @@ int cpu_down(unsigned int cpu) | |||
204 | #endif /*CONFIG_HOTPLUG_CPU*/ | 208 | #endif /*CONFIG_HOTPLUG_CPU*/ |
205 | 209 | ||
206 | /* Requires cpu_add_remove_lock to be held */ | 210 | /* Requires cpu_add_remove_lock to be held */ |
207 | static int __cpuinit _cpu_up(unsigned int cpu) | 211 | static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen) |
208 | { | 212 | { |
209 | int ret; | 213 | int ret, nr_calls = 0; |
210 | void *hcpu = (void *)(long)cpu; | 214 | void *hcpu = (void *)(long)cpu; |
215 | unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; | ||
211 | 216 | ||
212 | if (cpu_online(cpu) || !cpu_present(cpu)) | 217 | if (cpu_online(cpu) || !cpu_present(cpu)) |
213 | return -EINVAL; | 218 | return -EINVAL; |
214 | 219 | ||
215 | ret = raw_notifier_call_chain(&cpu_chain, CPU_UP_PREPARE, hcpu); | 220 | raw_notifier_call_chain(&cpu_chain, CPU_LOCK_ACQUIRE, hcpu); |
221 | ret = __raw_notifier_call_chain(&cpu_chain, CPU_UP_PREPARE | mod, hcpu, | ||
222 | -1, &nr_calls); | ||
216 | if (ret == NOTIFY_BAD) { | 223 | if (ret == NOTIFY_BAD) { |
217 | printk("%s: attempt to bring up CPU %u failed\n", | 224 | printk("%s: attempt to bring up CPU %u failed\n", |
218 | __FUNCTION__, cpu); | 225 | __FUNCTION__, cpu); |
@@ -229,12 +236,13 @@ static int __cpuinit _cpu_up(unsigned int cpu) | |||
229 | BUG_ON(!cpu_online(cpu)); | 236 | BUG_ON(!cpu_online(cpu)); |
230 | 237 | ||
231 | /* Now call notifier in preparation. */ | 238 | /* Now call notifier in preparation. */ |
232 | raw_notifier_call_chain(&cpu_chain, CPU_ONLINE, hcpu); | 239 | raw_notifier_call_chain(&cpu_chain, CPU_ONLINE | mod, hcpu); |
233 | 240 | ||
234 | out_notify: | 241 | out_notify: |
235 | if (ret != 0) | 242 | if (ret != 0) |
236 | raw_notifier_call_chain(&cpu_chain, | 243 | __raw_notifier_call_chain(&cpu_chain, |
237 | CPU_UP_CANCELED, hcpu); | 244 | CPU_UP_CANCELED | mod, hcpu, nr_calls, NULL); |
245 | raw_notifier_call_chain(&cpu_chain, CPU_LOCK_RELEASE, hcpu); | ||
238 | 246 | ||
239 | return ret; | 247 | return ret; |
240 | } | 248 | } |
@@ -247,19 +255,13 @@ int __cpuinit cpu_up(unsigned int cpu) | |||
247 | if (cpu_hotplug_disabled) | 255 | if (cpu_hotplug_disabled) |
248 | err = -EBUSY; | 256 | err = -EBUSY; |
249 | else | 257 | else |
250 | err = _cpu_up(cpu); | 258 | err = _cpu_up(cpu, 0); |
251 | 259 | ||
252 | mutex_unlock(&cpu_add_remove_lock); | 260 | mutex_unlock(&cpu_add_remove_lock); |
253 | return err; | 261 | return err; |
254 | } | 262 | } |
255 | 263 | ||
256 | #ifdef CONFIG_SUSPEND_SMP | 264 | #ifdef CONFIG_SUSPEND_SMP |
257 | /* Needed to prevent the microcode driver from requesting firmware in its CPU | ||
258 | * hotplug notifier during the suspend/resume. | ||
259 | */ | ||
260 | int suspend_cpu_hotplug; | ||
261 | EXPORT_SYMBOL(suspend_cpu_hotplug); | ||
262 | |||
263 | static cpumask_t frozen_cpus; | 265 | static cpumask_t frozen_cpus; |
264 | 266 | ||
265 | int disable_nonboot_cpus(void) | 267 | int disable_nonboot_cpus(void) |
@@ -267,7 +269,6 @@ int disable_nonboot_cpus(void) | |||
267 | int cpu, first_cpu, error = 0; | 269 | int cpu, first_cpu, error = 0; |
268 | 270 | ||
269 | mutex_lock(&cpu_add_remove_lock); | 271 | mutex_lock(&cpu_add_remove_lock); |
270 | suspend_cpu_hotplug = 1; | ||
271 | first_cpu = first_cpu(cpu_online_map); | 272 | first_cpu = first_cpu(cpu_online_map); |
272 | /* We take down all of the non-boot CPUs in one shot to avoid races | 273 | /* We take down all of the non-boot CPUs in one shot to avoid races |
273 | * with the userspace trying to use the CPU hotplug at the same time | 274 | * with the userspace trying to use the CPU hotplug at the same time |
@@ -277,7 +278,7 @@ int disable_nonboot_cpus(void) | |||
277 | for_each_online_cpu(cpu) { | 278 | for_each_online_cpu(cpu) { |
278 | if (cpu == first_cpu) | 279 | if (cpu == first_cpu) |
279 | continue; | 280 | continue; |
280 | error = _cpu_down(cpu); | 281 | error = _cpu_down(cpu, 1); |
281 | if (!error) { | 282 | if (!error) { |
282 | cpu_set(cpu, frozen_cpus); | 283 | cpu_set(cpu, frozen_cpus); |
283 | printk("CPU%d is down\n", cpu); | 284 | printk("CPU%d is down\n", cpu); |
@@ -294,7 +295,6 @@ int disable_nonboot_cpus(void) | |||
294 | } else { | 295 | } else { |
295 | printk(KERN_ERR "Non-boot CPUs are not disabled\n"); | 296 | printk(KERN_ERR "Non-boot CPUs are not disabled\n"); |
296 | } | 297 | } |
297 | suspend_cpu_hotplug = 0; | ||
298 | mutex_unlock(&cpu_add_remove_lock); | 298 | mutex_unlock(&cpu_add_remove_lock); |
299 | return error; | 299 | return error; |
300 | } | 300 | } |
@@ -309,10 +309,9 @@ void enable_nonboot_cpus(void) | |||
309 | if (cpus_empty(frozen_cpus)) | 309 | if (cpus_empty(frozen_cpus)) |
310 | goto out; | 310 | goto out; |
311 | 311 | ||
312 | suspend_cpu_hotplug = 1; | ||
313 | printk("Enabling non-boot CPUs ...\n"); | 312 | printk("Enabling non-boot CPUs ...\n"); |
314 | for_each_cpu_mask(cpu, frozen_cpus) { | 313 | for_each_cpu_mask(cpu, frozen_cpus) { |
315 | error = _cpu_up(cpu); | 314 | error = _cpu_up(cpu, 1); |
316 | if (!error) { | 315 | if (!error) { |
317 | printk("CPU%d is up\n", cpu); | 316 | printk("CPU%d is up\n", cpu); |
318 | continue; | 317 | continue; |
@@ -320,7 +319,6 @@ void enable_nonboot_cpus(void) | |||
320 | printk(KERN_WARNING "Error taking CPU%d up: %d\n", cpu, error); | 319 | printk(KERN_WARNING "Error taking CPU%d up: %d\n", cpu, error); |
321 | } | 320 | } |
322 | cpus_clear(frozen_cpus); | 321 | cpus_clear(frozen_cpus); |
323 | suspend_cpu_hotplug = 0; | ||
324 | out: | 322 | out: |
325 | mutex_unlock(&cpu_add_remove_lock); | 323 | mutex_unlock(&cpu_add_remove_lock); |
326 | } | 324 | } |