Blame view

kernel/cpu.c 17.6 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
  /* CPU control.
   * (C) 2001, 2002, 2003, 2004 Rusty Russell
   *
   * This code is licenced under the GPL.
   */
  #include <linux/proc_fs.h>
  #include <linux/smp.h>
  #include <linux/init.h>
  #include <linux/notifier.h>
  #include <linux/sched.h>
  #include <linux/unistd.h>
  #include <linux/cpu.h>
cb79295e2   Anton Vorontsov   cpu: introduce cl...
13
14
  #include <linux/oom.h>
  #include <linux/rcupdate.h>
9984de1a5   Paul Gortmaker   kernel: Map most ...
15
  #include <linux/export.h>
e4cc2f873   Anton Vorontsov   kernel/cpu.c: doc...
16
  #include <linux/bug.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
  #include <linux/kthread.h>
  #include <linux/stop_machine.h>
81615b624   Ingo Molnar   [PATCH] Convert k...
19
  #include <linux/mutex.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
20
  #include <linux/gfp.h>
79cfbdfa8   Srivatsa S. Bhat   PM / Sleep: Fix r...
21
  #include <linux/suspend.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22

38498a67a   Thomas Gleixner   smp: Add generic ...
23
  #include "smpboot.h"
98a79d6a5   Rusty Russell   cpumask: centrali...
24
  #ifdef CONFIG_SMP
b3199c025   Rusty Russell   cpumask: switch o...
25
  /* Serializes the updates to cpu_online_mask, cpu_present_mask */
aa9538777   Linus Torvalds   cpu hotplug: simp...
26
  static DEFINE_MUTEX(cpu_add_remove_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27

79a6cdeb7   Lai Jiangshan   cpuhotplug: do no...
28
29
30
31
32
33
34
35
36
37
38
39
40
  /*
   * The following two API's must be used when attempting
   * to serialize the updates to cpu_online_mask, cpu_present_mask.
   */
  void cpu_maps_update_begin(void)
  {
  	mutex_lock(&cpu_add_remove_lock);
  }
  
  void cpu_maps_update_done(void)
  {
  	mutex_unlock(&cpu_add_remove_lock);
  }
5c113fbee   Daniel J Blueman   fix cpu_chain sec...
41
  static RAW_NOTIFIER_HEAD(cpu_chain);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42

e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
43
44
45
46
  /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
   * Should always be manipulated under cpu_add_remove_lock
   */
  static int cpu_hotplug_disabled;
79a6cdeb7   Lai Jiangshan   cpuhotplug: do no...
47
  #ifdef CONFIG_HOTPLUG_CPU
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
48
49
50
51
52
53
54
55
  static struct {
  	struct task_struct *active_writer;
  	struct mutex lock; /* Synchronizes accesses to refcount, */
  	/*
  	 * Also blocks the new readers during
  	 * an ongoing cpu hotplug operation.
  	 */
  	int refcount;
31950eb66   Linus Torvalds   mm/init: cpu_hotp...
56
57
58
59
60
  } cpu_hotplug = {
  	.active_writer = NULL,
  	.lock = __MUTEX_INITIALIZER(cpu_hotplug.lock),
  	.refcount = 0,
  };
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
61

86ef5c9a8   Gautham R Shenoy   cpu-hotplug: repl...
62
  void get_online_cpus(void)
a9d9baa1e   Ashok Raj   [PATCH] clean up ...
63
  {
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
64
65
  	might_sleep();
  	if (cpu_hotplug.active_writer == current)
aa9538777   Linus Torvalds   cpu hotplug: simp...
66
  		return;
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
67
68
69
  	mutex_lock(&cpu_hotplug.lock);
  	cpu_hotplug.refcount++;
  	mutex_unlock(&cpu_hotplug.lock);
a9d9baa1e   Ashok Raj   [PATCH] clean up ...
70
  }
86ef5c9a8   Gautham R Shenoy   cpu-hotplug: repl...
71
  EXPORT_SYMBOL_GPL(get_online_cpus);
90d45d17f   Ashok Raj   [PATCH] cpu hotpl...
72

86ef5c9a8   Gautham R Shenoy   cpu-hotplug: repl...
73
  void put_online_cpus(void)
a9d9baa1e   Ashok Raj   [PATCH] clean up ...
74
  {
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
75
  	if (cpu_hotplug.active_writer == current)
aa9538777   Linus Torvalds   cpu hotplug: simp...
76
  		return;
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
77
  	mutex_lock(&cpu_hotplug.lock);
075663d19   Srivatsa S. Bhat   CPU hotplug, debu...
78
79
80
  
  	if (WARN_ON(!cpu_hotplug.refcount))
  		cpu_hotplug.refcount++; /* try to fix things up */
d2ba7e2ae   Oleg Nesterov   simplify cpu_hotp...
81
82
  	if (!--cpu_hotplug.refcount && unlikely(cpu_hotplug.active_writer))
  		wake_up_process(cpu_hotplug.active_writer);
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
83
  	mutex_unlock(&cpu_hotplug.lock);
a9d9baa1e   Ashok Raj   [PATCH] clean up ...
84
  }
86ef5c9a8   Gautham R Shenoy   cpu-hotplug: repl...
85
  EXPORT_SYMBOL_GPL(put_online_cpus);
a9d9baa1e   Ashok Raj   [PATCH] clean up ...
86

d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
87
88
89
90
91
92
93
  /*
   * This ensures that the hotplug operation can begin only when the
   * refcount goes to zero.
   *
   * Note that during a cpu-hotplug operation, the new readers, if any,
   * will be blocked by the cpu_hotplug.lock
   *
d2ba7e2ae   Oleg Nesterov   simplify cpu_hotp...
94
95
   * Since cpu_hotplug_begin() is always called after invoking
   * cpu_maps_update_begin(), we can be sure that only one writer is active.
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
96
97
98
99
100
101
102
103
104
105
   *
   * Note that theoretically, there is a possibility of a livelock:
   * - Refcount goes to zero, last reader wakes up the sleeping
   *   writer.
   * - Last reader unlocks the cpu_hotplug.lock.
   * - A new reader arrives at this moment, bumps up the refcount.
   * - The writer acquires the cpu_hotplug.lock finds the refcount
   *   non zero and goes to sleep again.
   *
   * However, this is very difficult to achieve in practice since
86ef5c9a8   Gautham R Shenoy   cpu-hotplug: repl...
106
   * get_online_cpus() not an api which is called all that often.
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
107
108
109
110
   *
   */
  static void cpu_hotplug_begin(void)
  {
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
111
  	cpu_hotplug.active_writer = current;
d2ba7e2ae   Oleg Nesterov   simplify cpu_hotp...
112
113
114
115
116
117
  
  	for (;;) {
  		mutex_lock(&cpu_hotplug.lock);
  		if (likely(!cpu_hotplug.refcount))
  			break;
  		__set_current_state(TASK_UNINTERRUPTIBLE);
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
118
119
  		mutex_unlock(&cpu_hotplug.lock);
  		schedule();
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
120
  	}
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
121
122
123
124
125
126
127
  }
  
  static void cpu_hotplug_done(void)
  {
  	cpu_hotplug.active_writer = NULL;
  	mutex_unlock(&cpu_hotplug.lock);
  }
79a6cdeb7   Lai Jiangshan   cpuhotplug: do no...
128

16e53dbf1   Srivatsa S. Bhat   CPU hotplug: prov...
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  /*
   * Wait for currently running CPU hotplug operations to complete (if any) and
   * disable future CPU hotplug (from sysfs). The 'cpu_add_remove_lock' protects
   * the 'cpu_hotplug_disabled' flag. The same lock is also acquired by the
   * hotplug path before performing hotplug operations. So acquiring that lock
   * guarantees mutual exclusion from any currently running hotplug operations.
   */
  void cpu_hotplug_disable(void)
  {
  	cpu_maps_update_begin();
  	cpu_hotplug_disabled = 1;
  	cpu_maps_update_done();
  }
  
  void cpu_hotplug_enable(void)
  {
  	cpu_maps_update_begin();
  	cpu_hotplug_disabled = 0;
  	cpu_maps_update_done();
  }
79a6cdeb7   Lai Jiangshan   cpuhotplug: do no...
149
150
151
  #else /* #if CONFIG_HOTPLUG_CPU */
  static void cpu_hotplug_begin(void) {}
  static void cpu_hotplug_done(void) {}
25985edce   Lucas De Marchi   Fix common misspe...
152
  #endif	/* #else #if CONFIG_HOTPLUG_CPU */
79a6cdeb7   Lai Jiangshan   cpuhotplug: do no...
153

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
154
  /* Need to know about CPUs going up/down? */
f7b16c108   Sam Ravnborg   cpu: fix section ...
155
  int __ref register_cpu_notifier(struct notifier_block *nb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
  {
bd5349cfd   Neil Brown   [PATCH] Convert c...
157
  	int ret;
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
158
  	cpu_maps_update_begin();
bd5349cfd   Neil Brown   [PATCH] Convert c...
159
  	ret = raw_notifier_chain_register(&cpu_chain, nb);
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
160
  	cpu_maps_update_done();
bd5349cfd   Neil Brown   [PATCH] Convert c...
161
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162
  }
65edc68c3   Chandra Seetharaman   [PATCH] cpu hotpl...
163

e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
164
165
166
  static int __cpu_notify(unsigned long val, void *v, int nr_to_call,
  			int *nr_calls)
  {
e6bde73b0   Akinobu Mita   cpu-hotplug: retu...
167
168
169
  	int ret;
  
  	ret = __raw_notifier_call_chain(&cpu_chain, val, v, nr_to_call,
e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
170
  					nr_calls);
e6bde73b0   Akinobu Mita   cpu-hotplug: retu...
171
172
  
  	return notifier_to_errno(ret);
e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
173
174
175
176
177
178
  }
  
  static int cpu_notify(unsigned long val, void *v)
  {
  	return __cpu_notify(val, v, -1, NULL);
  }
00b9b0af5   Linus Torvalds   Avoid warning whe...
179
  #ifdef CONFIG_HOTPLUG_CPU
e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
180
181
  static void cpu_notify_nofail(unsigned long val, void *v)
  {
00b9b0af5   Linus Torvalds   Avoid warning whe...
182
  	BUG_ON(cpu_notify(val, v));
e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
183
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
184
  EXPORT_SYMBOL(register_cpu_notifier);
9647155ff   Sam Ravnborg   cpu: fix section ...
185
  void __ref unregister_cpu_notifier(struct notifier_block *nb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
186
  {
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
187
  	cpu_maps_update_begin();
bd5349cfd   Neil Brown   [PATCH] Convert c...
188
  	raw_notifier_chain_unregister(&cpu_chain, nb);
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
189
  	cpu_maps_update_done();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
190
191
  }
  EXPORT_SYMBOL(unregister_cpu_notifier);
e4cc2f873   Anton Vorontsov   kernel/cpu.c: doc...
192
193
194
195
196
197
198
199
200
201
202
203
  /**
   * clear_tasks_mm_cpumask - Safely clear tasks' mm_cpumask for a CPU
   * @cpu: a CPU id
   *
   * This function walks all processes, finds a valid mm struct for each one and
   * then clears a corresponding bit in mm's cpumask.  While this all sounds
   * trivial, there are various non-obvious corner cases, which this function
   * tries to solve in a safe manner.
   *
   * Also note that the function uses a somewhat relaxed locking scheme, so it may
   * be called only for an already offlined CPU.
   */
cb79295e2   Anton Vorontsov   cpu: introduce cl...
204
205
206
207
208
209
210
211
212
213
214
  void clear_tasks_mm_cpumask(int cpu)
  {
  	struct task_struct *p;
  
  	/*
  	 * This function is called after the cpu is taken down and marked
  	 * offline, so its not like new tasks will ever get this cpu set in
  	 * their mm mask. -- Peter Zijlstra
  	 * Thus, we may use rcu_read_lock() here, instead of grabbing
  	 * full-fledged tasklist_lock.
  	 */
e4cc2f873   Anton Vorontsov   kernel/cpu.c: doc...
215
  	WARN_ON(cpu_online(cpu));
cb79295e2   Anton Vorontsov   cpu: introduce cl...
216
217
218
  	rcu_read_lock();
  	for_each_process(p) {
  		struct task_struct *t;
e4cc2f873   Anton Vorontsov   kernel/cpu.c: doc...
219
220
221
222
  		/*
  		 * Main thread might exit, but other threads may still have
  		 * a valid mm. Find one.
  		 */
cb79295e2   Anton Vorontsov   cpu: introduce cl...
223
224
225
226
227
228
229
230
  		t = find_lock_task_mm(p);
  		if (!t)
  			continue;
  		cpumask_clear_cpu(cpu, mm_cpumask(t->mm));
  		task_unlock(t);
  	}
  	rcu_read_unlock();
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
231
232
233
  static inline void check_for_tasks(int cpu)
  {
  	struct task_struct *p;
6fac4829c   Frederic Weisbecker   cputime: Use acce...
234
  	cputime_t utime, stime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
235
236
237
  
  	write_lock_irq(&tasklist_lock);
  	for_each_process(p) {
6fac4829c   Frederic Weisbecker   cputime: Use acce...
238
  		task_cputime(p, &utime, &stime);
11854247e   Peter Zijlstra   sched: Fix incorr...
239
  		if (task_cpu(p) == cpu && p->state == TASK_RUNNING &&
6fac4829c   Frederic Weisbecker   cputime: Use acce...
240
  		    (utime || stime))
9d3cfc4c1   Frans Pop   sched: Correct pr...
241
242
243
244
245
  			printk(KERN_WARNING "Task %s (pid = %d) is on cpu %d "
  				"(state = %ld, flags = %x)
  ",
  				p->comm, task_pid_nr(p), cpu,
  				p->state, p->flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
246
247
248
  	}
  	write_unlock_irq(&tasklist_lock);
  }
db912f963   Avi Kivity   HOTPLUG: Add CPU_...
249
250
251
252
  struct take_cpu_down_param {
  	unsigned long mod;
  	void *hcpu;
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
253
  /* Take this CPU down. */
514a20a5d   Sam Ravnborg   cpu: fix section ...
254
  static int __ref take_cpu_down(void *_param)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
255
  {
db912f963   Avi Kivity   HOTPLUG: Add CPU_...
256
  	struct take_cpu_down_param *param = _param;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
257
  	int err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
258
259
260
  	/* Ensure this CPU doesn't handle any more interrupts. */
  	err = __cpu_disable();
  	if (err < 0)
f37051364   Zwane Mwaikambo   [PATCH] i386 CPU ...
261
  		return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
262

e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
263
  	cpu_notify(CPU_DYING | param->mod, param->hcpu);
14e568e78   Thomas Gleixner   stop_machine: Use...
264
265
  	/* Park the stopper thread */
  	kthread_park(current);
f37051364   Zwane Mwaikambo   [PATCH] i386 CPU ...
266
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
267
  }
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
268
  /* Requires cpu_add_remove_lock to be held */
514a20a5d   Sam Ravnborg   cpu: fix section ...
269
  static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
270
  {
e7407dcc6   Heiko Carstens   call cpu_chain wi...
271
  	int err, nr_calls = 0;
e7407dcc6   Heiko Carstens   call cpu_chain wi...
272
  	void *hcpu = (void *)(long)cpu;
8bb784428   Rafael J. Wysocki   Add suspend-relat...
273
  	unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
db912f963   Avi Kivity   HOTPLUG: Add CPU_...
274
275
276
277
  	struct take_cpu_down_param tcd_param = {
  		.mod = mod,
  		.hcpu = hcpu,
  	};
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
278

e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
279
280
  	if (num_online_cpus() == 1)
  		return -EBUSY;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
281

e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
282
283
  	if (!cpu_online(cpu))
  		return -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284

d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
285
  	cpu_hotplug_begin();
4d51985e4   Michael Rodriguez   kernel/cpu.c: fix...
286

e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
287
  	err = __cpu_notify(CPU_DOWN_PREPARE | mod, hcpu, -1, &nr_calls);
e6bde73b0   Akinobu Mita   cpu-hotplug: retu...
288
  	if (err) {
a0d8cdb65   Akinobu Mita   cpu hotplug: cpu:...
289
  		nr_calls--;
e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
290
  		__cpu_notify(CPU_DOWN_FAILED | mod, hcpu, nr_calls, NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
291
292
  		printk("%s: attempt to take down CPU %u failed
  ",
af1f16d08   Harvey Harrison   kernel: replace r...
293
  				__func__, cpu);
baaca49f4   Gautham R Shenoy   Define and use ne...
294
  		goto out_release;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
295
  	}
f97f8f06a   Thomas Gleixner   smpboot: Provide ...
296
  	smpboot_park_threads(cpu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
297

e0b582ec5   Rusty Russell   cpumask: convert ...
298
  	err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu));
043215875   Rusty Russell   Hotplug CPU: don'...
299
  	if (err) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
300
  		/* CPU didn't die: tell everyone.  Can't complain. */
f97f8f06a   Thomas Gleixner   smpboot: Provide ...
301
  		smpboot_unpark_threads(cpu);
e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
302
  		cpu_notify_nofail(CPU_DOWN_FAILED | mod, hcpu);
6a1bdc1b5   Oleg Nesterov   sched: _cpu_down(...
303
  		goto out_release;
8fa1d7d3b   Satoru Takeuchi   [PATCH] cpu-hotpl...
304
  	}
043215875   Rusty Russell   Hotplug CPU: don'...
305
  	BUG_ON(cpu_online(cpu));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
306

48c5ccae8   Peter Zijlstra   sched: Simplify c...
307
308
309
310
  	/*
  	 * The migration_call() CPU_DYING callback will have removed all
  	 * runnable tasks from the cpu, there's only the idle task left now
  	 * that the migration thread is done doing the stop_machine thing.
51a96c778   Peter Zijlstra   cpu: Remove incor...
311
312
  	 *
  	 * Wait for the stop thread to go away.
48c5ccae8   Peter Zijlstra   sched: Simplify c...
313
  	 */
51a96c778   Peter Zijlstra   cpu: Remove incor...
314
315
  	while (!idle_cpu(cpu))
  		cpu_relax();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
316
317
318
  
  	/* This actually kills the CPU. */
  	__cpu_die(cpu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
319
  	/* CPU is completely dead: tell everyone.  Too late to complain. */
e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
320
  	cpu_notify_nofail(CPU_DEAD | mod, hcpu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
321
322
  
  	check_for_tasks(cpu);
baaca49f4   Gautham R Shenoy   Define and use ne...
323
  out_release:
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
324
  	cpu_hotplug_done();
e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
325
326
  	if (!err)
  		cpu_notify_nofail(CPU_POST_DEAD | mod, hcpu);
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
327
328
  	return err;
  }
514a20a5d   Sam Ravnborg   cpu: fix section ...
329
  int __ref cpu_down(unsigned int cpu)
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
330
  {
9ea09af3b   Heiko Carstens   stop_machine: int...
331
  	int err;
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
332

d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
333
  	cpu_maps_update_begin();
e761b7725   Max Krasnyansky   cpu hotplug, sche...
334
335
  
  	if (cpu_hotplug_disabled) {
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
336
  		err = -EBUSY;
e761b7725   Max Krasnyansky   cpu hotplug, sche...
337
338
  		goto out;
  	}
e761b7725   Max Krasnyansky   cpu hotplug, sche...
339
  	err = _cpu_down(cpu, 0);
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
340

e761b7725   Max Krasnyansky   cpu hotplug, sche...
341
  out:
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
342
  	cpu_maps_update_done();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
343
344
  	return err;
  }
b62b8ef90   Zhang Rui   force offline the...
345
  EXPORT_SYMBOL(cpu_down);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
346
  #endif /*CONFIG_HOTPLUG_CPU*/
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
347
  /* Requires cpu_add_remove_lock to be held */
8bb784428   Rafael J. Wysocki   Add suspend-relat...
348
  static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
349
  {
baaca49f4   Gautham R Shenoy   Define and use ne...
350
  	int ret, nr_calls = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
351
  	void *hcpu = (void *)(long)cpu;
8bb784428   Rafael J. Wysocki   Add suspend-relat...
352
  	unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
3bb5d2ee3   Suresh Siddha   smp, idle: Alloca...
353
  	struct task_struct *idle;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
354

d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
355
  	cpu_hotplug_begin();
38498a67a   Thomas Gleixner   smp: Add generic ...
356

5e5041f35   Yasuaki Ishimatsu   ACPI / processor:...
357
358
359
360
  	if (cpu_online(cpu) || !cpu_present(cpu)) {
  		ret = -EINVAL;
  		goto out;
  	}
3bb5d2ee3   Suresh Siddha   smp, idle: Alloca...
361
362
363
  	idle = idle_thread_get(cpu);
  	if (IS_ERR(idle)) {
  		ret = PTR_ERR(idle);
38498a67a   Thomas Gleixner   smp: Add generic ...
364
  		goto out;
3bb5d2ee3   Suresh Siddha   smp, idle: Alloca...
365
  	}
38498a67a   Thomas Gleixner   smp: Add generic ...
366

f97f8f06a   Thomas Gleixner   smpboot: Provide ...
367
368
369
  	ret = smpboot_create_threads(cpu);
  	if (ret)
  		goto out;
e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
370
  	ret = __cpu_notify(CPU_UP_PREPARE | mod, hcpu, -1, &nr_calls);
e6bde73b0   Akinobu Mita   cpu-hotplug: retu...
371
  	if (ret) {
a0d8cdb65   Akinobu Mita   cpu hotplug: cpu:...
372
  		nr_calls--;
4d51985e4   Michael Rodriguez   kernel/cpu.c: fix...
373
374
  		printk(KERN_WARNING "%s: attempt to bring up CPU %u failed
  ",
af1f16d08   Harvey Harrison   kernel: replace r...
375
  				__func__, cpu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
376
377
378
379
  		goto out_notify;
  	}
  
  	/* Arch-specific enabling code. */
3bb5d2ee3   Suresh Siddha   smp, idle: Alloca...
380
  	ret = __cpu_up(cpu, idle);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
381
382
  	if (ret != 0)
  		goto out_notify;
6978c7052   Eric Sesterhenn   BUG_ON() Conversi...
383
  	BUG_ON(!cpu_online(cpu));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
384

f97f8f06a   Thomas Gleixner   smpboot: Provide ...
385
386
  	/* Wake the per cpu threads */
  	smpboot_unpark_threads(cpu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
387
  	/* Now call notifier in preparation. */
e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
388
  	cpu_notify(CPU_ONLINE | mod, hcpu);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
389
390
391
  
  out_notify:
  	if (ret != 0)
e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
392
  		__cpu_notify(CPU_UP_CANCELED | mod, hcpu, nr_calls, NULL);
38498a67a   Thomas Gleixner   smp: Add generic ...
393
  out:
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
394
  	cpu_hotplug_done();
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
395
396
397
  
  	return ret;
  }
b282b6f8a   Gautham R Shenoy   [PATCH] Change cp...
398
  int __cpuinit cpu_up(unsigned int cpu)
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
399
400
  {
  	int err = 0;
cf23422b9   minskey guo   cpu/mem hotplug: ...
401
402
403
404
405
  
  #ifdef	CONFIG_MEMORY_HOTPLUG
  	int nid;
  	pg_data_t	*pgdat;
  #endif
e0b582ec5   Rusty Russell   cpumask: convert ...
406
  	if (!cpu_possible(cpu)) {
73e753a50   KAMEZAWA Hiroyuki   CPU HOTPLUG: avoi...
407
408
409
  		printk(KERN_ERR "can't online cpu %d because it is not "
  			"configured as may-hotadd at boot time
  ", cpu);
87d5e0236   Chen Gong   kernel/cpu.c: del...
410
  #if defined(CONFIG_IA64)
73e753a50   KAMEZAWA Hiroyuki   CPU HOTPLUG: avoi...
411
412
413
414
415
416
  		printk(KERN_ERR "please check additional_cpus= boot "
  				"parameter
  ");
  #endif
  		return -EINVAL;
  	}
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
417

cf23422b9   minskey guo   cpu/mem hotplug: ...
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
  #ifdef	CONFIG_MEMORY_HOTPLUG
  	nid = cpu_to_node(cpu);
  	if (!node_online(nid)) {
  		err = mem_online_node(nid);
  		if (err)
  			return err;
  	}
  
  	pgdat = NODE_DATA(nid);
  	if (!pgdat) {
  		printk(KERN_ERR
  			"Can't online cpu %d due to NULL pgdat
  ", cpu);
  		return -ENOMEM;
  	}
4eaf3f643   Haicheng Li   mem-hotplug: fix ...
433
434
  	if (pgdat->node_zonelists->_zonerefs->zone == NULL) {
  		mutex_lock(&zonelists_mutex);
9adb62a5d   Jiang Liu   mm/hotplug: corre...
435
  		build_all_zonelists(NULL, NULL);
4eaf3f643   Haicheng Li   mem-hotplug: fix ...
436
437
  		mutex_unlock(&zonelists_mutex);
  	}
cf23422b9   minskey guo   cpu/mem hotplug: ...
438
  #endif
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
439
  	cpu_maps_update_begin();
e761b7725   Max Krasnyansky   cpu hotplug, sche...
440
441
  
  	if (cpu_hotplug_disabled) {
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
442
  		err = -EBUSY;
e761b7725   Max Krasnyansky   cpu hotplug, sche...
443
444
445
446
  		goto out;
  	}
  
  	err = _cpu_up(cpu, 0);
e761b7725   Max Krasnyansky   cpu hotplug, sche...
447
  out:
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
448
  	cpu_maps_update_done();
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
449
450
  	return err;
  }
a513f6bab   Paul E. McKenney   cpu: Export cpu_up()
451
  EXPORT_SYMBOL_GPL(cpu_up);
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
452

f3de4be9d   Rafael J. Wysocki   PM: Fix dependenc...
453
  #ifdef CONFIG_PM_SLEEP_SMP
e0b582ec5   Rusty Russell   cpumask: convert ...
454
  static cpumask_var_t frozen_cpus;
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
455
456
457
  
  int disable_nonboot_cpus(void)
  {
e9a5f426b   Rafael J. Wysocki   CPU: Avoid using ...
458
  	int cpu, first_cpu, error = 0;
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
459

d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
460
  	cpu_maps_update_begin();
e0b582ec5   Rusty Russell   cpumask: convert ...
461
  	first_cpu = cpumask_first(cpu_online_mask);
9ee349ad6   Xiaotian Feng   sched: Fix set_cp...
462
463
  	/*
  	 * We take down all of the non-boot CPUs in one shot to avoid races
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
464
465
  	 * with the userspace trying to use the CPU hotplug at the same time
  	 */
e0b582ec5   Rusty Russell   cpumask: convert ...
466
  	cpumask_clear(frozen_cpus);
6ad4c1888   Peter Zijlstra   sched: Fix balanc...
467

e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
468
469
470
471
472
  	printk("Disabling non-boot CPUs ...
  ");
  	for_each_online_cpu(cpu) {
  		if (cpu == first_cpu)
  			continue;
8bb784428   Rafael J. Wysocki   Add suspend-relat...
473
  		error = _cpu_down(cpu, 1);
feae3203d   Mike Travis   timers, init: Lim...
474
  		if (!error)
e0b582ec5   Rusty Russell   cpumask: convert ...
475
  			cpumask_set_cpu(cpu, frozen_cpus);
feae3203d   Mike Travis   timers, init: Lim...
476
  		else {
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
477
478
479
480
481
482
  			printk(KERN_ERR "Error taking CPU%d down: %d
  ",
  				cpu, error);
  			break;
  		}
  	}
86886e55b   Joseph Cihula   x86, intel_txt: I...
483

e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
484
485
486
487
488
  	if (!error) {
  		BUG_ON(num_online_cpus() > 1);
  		/* Make sure the CPUs won't be enabled by someone else */
  		cpu_hotplug_disabled = 1;
  	} else {
e1d9fd2e3   Ingo Molnar   [PATCH] suspend: ...
489
490
  		printk(KERN_ERR "Non-boot CPUs are not disabled
  ");
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
491
  	}
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
492
  	cpu_maps_update_done();
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
493
494
  	return error;
  }
d0af9eed5   Suresh Siddha   x86, pat/mtrr: Re...
495
496
497
498
499
500
501
  void __weak arch_enable_nonboot_cpus_begin(void)
  {
  }
  
  void __weak arch_enable_nonboot_cpus_end(void)
  {
  }
fa7303e22   Sam Ravnborg   cpu: fix section ...
502
  void __ref enable_nonboot_cpus(void)
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
503
504
505
506
  {
  	int cpu, error;
  
  	/* Allow everyone to use the CPU hotplug again */
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
507
  	cpu_maps_update_begin();
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
508
  	cpu_hotplug_disabled = 0;
e0b582ec5   Rusty Russell   cpumask: convert ...
509
  	if (cpumask_empty(frozen_cpus))
1d64b9cb1   Rafael J. Wysocki   [PATCH] Fix micro...
510
  		goto out;
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
511

4d51985e4   Michael Rodriguez   kernel/cpu.c: fix...
512
513
  	printk(KERN_INFO "Enabling non-boot CPUs ...
  ");
d0af9eed5   Suresh Siddha   x86, pat/mtrr: Re...
514
515
  
  	arch_enable_nonboot_cpus_begin();
e0b582ec5   Rusty Russell   cpumask: convert ...
516
  	for_each_cpu(cpu, frozen_cpus) {
8bb784428   Rafael J. Wysocki   Add suspend-relat...
517
  		error = _cpu_up(cpu, 1);
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
518
  		if (!error) {
4d51985e4   Michael Rodriguez   kernel/cpu.c: fix...
519
520
  			printk(KERN_INFO "CPU%d is up
  ", cpu);
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
521
522
  			continue;
  		}
1d64b9cb1   Rafael J. Wysocki   [PATCH] Fix micro...
523
524
  		printk(KERN_WARNING "Error taking CPU%d up: %d
  ", cpu, error);
e3920fb42   Rafael J. Wysocki   [PATCH] Disable C...
525
  	}
d0af9eed5   Suresh Siddha   x86, pat/mtrr: Re...
526
527
  
  	arch_enable_nonboot_cpus_end();
e0b582ec5   Rusty Russell   cpumask: convert ...
528
  	cpumask_clear(frozen_cpus);
1d64b9cb1   Rafael J. Wysocki   [PATCH] Fix micro...
529
  out:
d221938c0   Gautham R Shenoy   cpu-hotplug: refc...
530
  	cpu_maps_update_done();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
531
  }
e0b582ec5   Rusty Russell   cpumask: convert ...
532

d7268a31c   Fenghua Yu   CPU: Add right qu...
533
  static int __init alloc_frozen_cpus(void)
e0b582ec5   Rusty Russell   cpumask: convert ...
534
535
536
537
538
539
  {
  	if (!alloc_cpumask_var(&frozen_cpus, GFP_KERNEL|__GFP_ZERO))
  		return -ENOMEM;
  	return 0;
  }
  core_initcall(alloc_frozen_cpus);
79cfbdfa8   Srivatsa S. Bhat   PM / Sleep: Fix r...
540
541
  
  /*
79cfbdfa8   Srivatsa S. Bhat   PM / Sleep: Fix r...
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
   * When callbacks for CPU hotplug notifications are being executed, we must
   * ensure that the state of the system with respect to the tasks being frozen
   * or not, as reported by the notification, remains unchanged *throughout the
   * duration* of the execution of the callbacks.
   * Hence we need to prevent the freezer from racing with regular CPU hotplug.
   *
   * This synchronization is implemented by mutually excluding regular CPU
   * hotplug and Suspend/Hibernate call paths by hooking onto the Suspend/
   * Hibernate notifications.
   */
  static int
  cpu_hotplug_pm_callback(struct notifier_block *nb,
  			unsigned long action, void *ptr)
  {
  	switch (action) {
  
  	case PM_SUSPEND_PREPARE:
  	case PM_HIBERNATION_PREPARE:
16e53dbf1   Srivatsa S. Bhat   CPU hotplug: prov...
560
  		cpu_hotplug_disable();
79cfbdfa8   Srivatsa S. Bhat   PM / Sleep: Fix r...
561
562
563
564
  		break;
  
  	case PM_POST_SUSPEND:
  	case PM_POST_HIBERNATION:
16e53dbf1   Srivatsa S. Bhat   CPU hotplug: prov...
565
  		cpu_hotplug_enable();
79cfbdfa8   Srivatsa S. Bhat   PM / Sleep: Fix r...
566
567
568
569
570
571
572
573
  		break;
  
  	default:
  		return NOTIFY_DONE;
  	}
  
  	return NOTIFY_OK;
  }
d7268a31c   Fenghua Yu   CPU: Add right qu...
574
  static int __init cpu_hotplug_pm_sync_init(void)
79cfbdfa8   Srivatsa S. Bhat   PM / Sleep: Fix r...
575
  {
6e32d479d   Fenghua Yu   kernel/cpu.c: Add...
576
577
578
579
580
  	/*
  	 * cpu_hotplug_pm_callback has higher priority than x86
  	 * bsp_pm_callback which depends on cpu_hotplug_pm_callback
  	 * to disable cpu hotplug to avoid cpu hotplug race.
  	 */
79cfbdfa8   Srivatsa S. Bhat   PM / Sleep: Fix r...
581
582
583
584
  	pm_notifier(cpu_hotplug_pm_callback, 0);
  	return 0;
  }
  core_initcall(cpu_hotplug_pm_sync_init);
f3de4be9d   Rafael J. Wysocki   PM: Fix dependenc...
585
  #endif /* CONFIG_PM_SLEEP_SMP */
68f4f1ec0   Max Krasnyansky   sched: Move cpu m...
586

e545a6140   Manfred Spraul   kernel/cpu.c: cre...
587
588
589
590
591
592
593
594
  /**
   * notify_cpu_starting(cpu) - call the CPU_STARTING notifiers
   * @cpu: cpu that just started
   *
   * This function calls the cpu_chain notifiers with CPU_STARTING.
   * It must be called by the arch code on the new cpu, before the new cpu
   * enables interrupts and before the "boot" cpu returns from __cpu_up().
   */
841964145   Al Viro   cpuinit fixes in ...
595
  void __cpuinit notify_cpu_starting(unsigned int cpu)
e545a6140   Manfred Spraul   kernel/cpu.c: cre...
596
597
598
599
  {
  	unsigned long val = CPU_STARTING;
  
  #ifdef CONFIG_PM_SLEEP_SMP
e0b582ec5   Rusty Russell   cpumask: convert ...
600
  	if (frozen_cpus != NULL && cpumask_test_cpu(cpu, frozen_cpus))
e545a6140   Manfred Spraul   kernel/cpu.c: cre...
601
602
  		val = CPU_STARTING_FROZEN;
  #endif /* CONFIG_PM_SLEEP_SMP */
e9fb7631e   Akinobu Mita   cpu-hotplug: intr...
603
  	cpu_notify(val, (void *)(long)cpu);
e545a6140   Manfred Spraul   kernel/cpu.c: cre...
604
  }
68f4f1ec0   Max Krasnyansky   sched: Move cpu m...
605
  #endif /* CONFIG_SMP */
b8d317d10   Mike Travis   cpumask: make cpu...
606

e56b3bc79   Linus Torvalds   cpu masks: optimi...
607
608
609
610
  /*
   * cpu_bit_bitmap[] is a special, "compressed" data structure that
   * represents all NR_CPUS bits binary values of 1<<nr.
   *
e0b582ec5   Rusty Russell   cpumask: convert ...
611
   * It is used by cpumask_of() to get a constant address to a CPU
e56b3bc79   Linus Torvalds   cpu masks: optimi...
612
613
   * mask value that has a single bit set only.
   */
b8d317d10   Mike Travis   cpumask: make cpu...
614

e56b3bc79   Linus Torvalds   cpu masks: optimi...
615
  /* cpu_bit_bitmap[0] is empty - so we can back into it */
4d51985e4   Michael Rodriguez   kernel/cpu.c: fix...
616
  #define MASK_DECLARE_1(x)	[x+1][0] = (1UL << (x))
e56b3bc79   Linus Torvalds   cpu masks: optimi...
617
618
619
  #define MASK_DECLARE_2(x)	MASK_DECLARE_1(x), MASK_DECLARE_1(x+1)
  #define MASK_DECLARE_4(x)	MASK_DECLARE_2(x), MASK_DECLARE_2(x+2)
  #define MASK_DECLARE_8(x)	MASK_DECLARE_4(x), MASK_DECLARE_4(x+4)
b8d317d10   Mike Travis   cpumask: make cpu...
620

e56b3bc79   Linus Torvalds   cpu masks: optimi...
621
622
623
624
625
626
627
  const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {
  
  	MASK_DECLARE_8(0),	MASK_DECLARE_8(8),
  	MASK_DECLARE_8(16),	MASK_DECLARE_8(24),
  #if BITS_PER_LONG > 32
  	MASK_DECLARE_8(32),	MASK_DECLARE_8(40),
  	MASK_DECLARE_8(48),	MASK_DECLARE_8(56),
b8d317d10   Mike Travis   cpumask: make cpu...
628
629
  #endif
  };
e56b3bc79   Linus Torvalds   cpu masks: optimi...
630
  EXPORT_SYMBOL_GPL(cpu_bit_bitmap);
2d3854a37   Rusty Russell   cpumask: introduc...
631
632
633
  
  const DECLARE_BITMAP(cpu_all_bits, NR_CPUS) = CPU_BITS_ALL;
  EXPORT_SYMBOL(cpu_all_bits);
b3199c025   Rusty Russell   cpumask: switch o...
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
  
  #ifdef CONFIG_INIT_ALL_POSSIBLE
  static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly
  	= CPU_BITS_ALL;
  #else
  static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly;
  #endif
  const struct cpumask *const cpu_possible_mask = to_cpumask(cpu_possible_bits);
  EXPORT_SYMBOL(cpu_possible_mask);
  
  static DECLARE_BITMAP(cpu_online_bits, CONFIG_NR_CPUS) __read_mostly;
  const struct cpumask *const cpu_online_mask = to_cpumask(cpu_online_bits);
  EXPORT_SYMBOL(cpu_online_mask);
  
  static DECLARE_BITMAP(cpu_present_bits, CONFIG_NR_CPUS) __read_mostly;
  const struct cpumask *const cpu_present_mask = to_cpumask(cpu_present_bits);
  EXPORT_SYMBOL(cpu_present_mask);
  
  static DECLARE_BITMAP(cpu_active_bits, CONFIG_NR_CPUS) __read_mostly;
  const struct cpumask *const cpu_active_mask = to_cpumask(cpu_active_bits);
  EXPORT_SYMBOL(cpu_active_mask);
3fa415206   Rusty Russell   cpumask: make set...
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
  
  void set_cpu_possible(unsigned int cpu, bool possible)
  {
  	if (possible)
  		cpumask_set_cpu(cpu, to_cpumask(cpu_possible_bits));
  	else
  		cpumask_clear_cpu(cpu, to_cpumask(cpu_possible_bits));
  }
  
  void set_cpu_present(unsigned int cpu, bool present)
  {
  	if (present)
  		cpumask_set_cpu(cpu, to_cpumask(cpu_present_bits));
  	else
  		cpumask_clear_cpu(cpu, to_cpumask(cpu_present_bits));
  }
  
  void set_cpu_online(unsigned int cpu, bool online)
  {
  	if (online)
  		cpumask_set_cpu(cpu, to_cpumask(cpu_online_bits));
  	else
  		cpumask_clear_cpu(cpu, to_cpumask(cpu_online_bits));
  }
  
  void set_cpu_active(unsigned int cpu, bool active)
  {
  	if (active)
  		cpumask_set_cpu(cpu, to_cpumask(cpu_active_bits));
  	else
  		cpumask_clear_cpu(cpu, to_cpumask(cpu_active_bits));
  }
  
  void init_cpu_present(const struct cpumask *src)
  {
  	cpumask_copy(to_cpumask(cpu_present_bits), src);
  }
  
  void init_cpu_possible(const struct cpumask *src)
  {
  	cpumask_copy(to_cpumask(cpu_possible_bits), src);
  }
  
  void init_cpu_online(const struct cpumask *src)
  {
  	cpumask_copy(to_cpumask(cpu_online_bits), src);
  }
fc325e614   Anson Huang   ENGR00273073-1 ar...
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
  
  static ATOMIC_NOTIFIER_HEAD(idle_notifier);
  void idle_notifier_register(struct notifier_block *n)
  {
  	atomic_notifier_chain_register(&idle_notifier, n);
  }
  EXPORT_SYMBOL_GPL(idle_notifier_register);
  
  void idle_notifier_unregister(struct notifier_block *n)
  {
  	atomic_notifier_chain_unregister(&idle_notifier, n);
  }
  EXPORT_SYMBOL_GPL(idle_notifier_unregister);
  
  void idle_notifier_call_chain(unsigned long val)
  {
  	atomic_notifier_call_chain(&idle_notifier, val, NULL);
  }
  EXPORT_SYMBOL_GPL(idle_notifier_call_chain);