]> git.karo-electronics.de Git - karo-tx-linux.git/blob - kernel/cpu.c
33caf5e97701b74a1383986571d86b7e4e532734
[karo-tx-linux.git] / kernel / cpu.c
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/oom.h>
14 #include <linux/rcupdate.h>
15 #include <linux/export.h>
16 #include <linux/bug.h>
17 #include <linux/kthread.h>
18 #include <linux/stop_machine.h>
19 #include <linux/mutex.h>
20 #include <linux/gfp.h>
21 #include <linux/suspend.h>
22 #include <linux/lockdep.h>
23
24 #include "smpboot.h"
25
26 #ifdef CONFIG_SMP
27 /* Serializes the updates to cpu_online_mask, cpu_present_mask */
28 static DEFINE_MUTEX(cpu_add_remove_lock);
29
30 /*
31  * The following two API's must be used when attempting
32  * to serialize the updates to cpu_online_mask, cpu_present_mask.
33  */
34 void cpu_maps_update_begin(void)
35 {
36         mutex_lock(&cpu_add_remove_lock);
37 }
38
39 void cpu_maps_update_done(void)
40 {
41         mutex_unlock(&cpu_add_remove_lock);
42 }
43
44 static RAW_NOTIFIER_HEAD(cpu_chain);
45
46 /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
47  * Should always be manipulated under cpu_add_remove_lock
48  */
49 static int cpu_hotplug_disabled;
50
51 #ifdef CONFIG_HOTPLUG_CPU
52
53 static struct {
54         struct task_struct *active_writer;
55         struct mutex lock; /* Synchronizes accesses to refcount, */
56         /*
57          * Also blocks the new readers during
58          * an ongoing cpu hotplug operation.
59          */
60         int refcount;
61
62 #ifdef CONFIG_DEBUG_LOCK_ALLOC
63         struct lockdep_map dep_map;
64 #endif
65 } cpu_hotplug = {
66         .active_writer = NULL,
67         .lock = __MUTEX_INITIALIZER(cpu_hotplug.lock),
68         .refcount = 0,
69 #ifdef CONFIG_DEBUG_LOCK_ALLOC
70         .dep_map = {.name = "cpu_hotplug.lock" },
71 #endif
72 };
73
74 /* Lockdep annotations for get/put_online_cpus() and cpu_hotplug_begin/end() */
75 #define cpuhp_lock_acquire_read() lock_map_acquire_read(&cpu_hotplug.dep_map)
76 #define cpuhp_lock_acquire()      lock_map_acquire(&cpu_hotplug.dep_map)
77 #define cpuhp_lock_release()      lock_map_release(&cpu_hotplug.dep_map)
78
79 void get_online_cpus(void)
80 {
81         might_sleep();
82         if (cpu_hotplug.active_writer == current)
83                 return;
84         cpuhp_lock_acquire_read();
85         mutex_lock(&cpu_hotplug.lock);
86         cpu_hotplug.refcount++;
87         mutex_unlock(&cpu_hotplug.lock);
88
89 }
90 EXPORT_SYMBOL_GPL(get_online_cpus);
91
92 void put_online_cpus(void)
93 {
94         if (cpu_hotplug.active_writer == current)
95                 return;
96         mutex_lock(&cpu_hotplug.lock);
97
98         if (WARN_ON(!cpu_hotplug.refcount))
99                 cpu_hotplug.refcount++; /* try to fix things up */
100
101         if (!--cpu_hotplug.refcount && unlikely(cpu_hotplug.active_writer))
102                 wake_up_process(cpu_hotplug.active_writer);
103         mutex_unlock(&cpu_hotplug.lock);
104         cpuhp_lock_release();
105
106 }
107 EXPORT_SYMBOL_GPL(put_online_cpus);
108
109 /*
110  * This ensures that the hotplug operation can begin only when the
111  * refcount goes to zero.
112  *
113  * Note that during a cpu-hotplug operation, the new readers, if any,
114  * will be blocked by the cpu_hotplug.lock
115  *
116  * Since cpu_hotplug_begin() is always called after invoking
117  * cpu_maps_update_begin(), we can be sure that only one writer is active.
118  *
119  * Note that theoretically, there is a possibility of a livelock:
120  * - Refcount goes to zero, last reader wakes up the sleeping
121  *   writer.
122  * - Last reader unlocks the cpu_hotplug.lock.
123  * - A new reader arrives at this moment, bumps up the refcount.
124  * - The writer acquires the cpu_hotplug.lock finds the refcount
125  *   non zero and goes to sleep again.
126  *
127  * However, this is very difficult to achieve in practice since
128  * get_online_cpus() not an api which is called all that often.
129  *
130  */
131 void cpu_hotplug_begin(void)
132 {
133         cpu_hotplug.active_writer = current;
134
135         cpuhp_lock_acquire();
136         for (;;) {
137                 mutex_lock(&cpu_hotplug.lock);
138                 if (likely(!cpu_hotplug.refcount))
139                         break;
140                 __set_current_state(TASK_UNINTERRUPTIBLE);
141                 mutex_unlock(&cpu_hotplug.lock);
142                 schedule();
143         }
144 }
145
146 void cpu_hotplug_done(void)
147 {
148         cpu_hotplug.active_writer = NULL;
149         mutex_unlock(&cpu_hotplug.lock);
150         cpuhp_lock_release();
151 }
152
153 /*
154  * Wait for currently running CPU hotplug operations to complete (if any) and
155  * disable future CPU hotplug (from sysfs). The 'cpu_add_remove_lock' protects
156  * the 'cpu_hotplug_disabled' flag. The same lock is also acquired by the
157  * hotplug path before performing hotplug operations. So acquiring that lock
158  * guarantees mutual exclusion from any currently running hotplug operations.
159  */
160 void cpu_hotplug_disable(void)
161 {
162         cpu_maps_update_begin();
163         cpu_hotplug_disabled = 1;
164         cpu_maps_update_done();
165 }
166
167 void cpu_hotplug_enable(void)
168 {
169         cpu_maps_update_begin();
170         cpu_hotplug_disabled = 0;
171         cpu_maps_update_done();
172 }
173
174 #endif  /* CONFIG_HOTPLUG_CPU */
175
176 /* Need to know about CPUs going up/down? */
177 int __ref register_cpu_notifier(struct notifier_block *nb)
178 {
179         int ret;
180         cpu_maps_update_begin();
181         ret = raw_notifier_chain_register(&cpu_chain, nb);
182         cpu_maps_update_done();
183         return ret;
184 }
185
186 static int __cpu_notify(unsigned long val, void *v, int nr_to_call,
187                         int *nr_calls)
188 {
189         int ret;
190
191         ret = __raw_notifier_call_chain(&cpu_chain, val, v, nr_to_call,
192                                         nr_calls);
193
194         return notifier_to_errno(ret);
195 }
196
197 static int cpu_notify(unsigned long val, void *v)
198 {
199         return __cpu_notify(val, v, -1, NULL);
200 }
201
202 #ifdef CONFIG_HOTPLUG_CPU
203
204 static void cpu_notify_nofail(unsigned long val, void *v)
205 {
206         BUG_ON(cpu_notify(val, v));
207 }
208 EXPORT_SYMBOL(register_cpu_notifier);
209
210 void __ref unregister_cpu_notifier(struct notifier_block *nb)
211 {
212         cpu_maps_update_begin();
213         raw_notifier_chain_unregister(&cpu_chain, nb);
214         cpu_maps_update_done();
215 }
216 EXPORT_SYMBOL(unregister_cpu_notifier);
217
218 /**
219  * clear_tasks_mm_cpumask - Safely clear tasks' mm_cpumask for a CPU
220  * @cpu: a CPU id
221  *
222  * This function walks all processes, finds a valid mm struct for each one and
223  * then clears a corresponding bit in mm's cpumask.  While this all sounds
224  * trivial, there are various non-obvious corner cases, which this function
225  * tries to solve in a safe manner.
226  *
227  * Also note that the function uses a somewhat relaxed locking scheme, so it may
228  * be called only for an already offlined CPU.
229  */
230 void clear_tasks_mm_cpumask(int cpu)
231 {
232         struct task_struct *p;
233
234         /*
235          * This function is called after the cpu is taken down and marked
236          * offline, so its not like new tasks will ever get this cpu set in
237          * their mm mask. -- Peter Zijlstra
238          * Thus, we may use rcu_read_lock() here, instead of grabbing
239          * full-fledged tasklist_lock.
240          */
241         WARN_ON(cpu_online(cpu));
242         rcu_read_lock();
243         for_each_process(p) {
244                 struct task_struct *t;
245
246                 /*
247                  * Main thread might exit, but other threads may still have
248                  * a valid mm. Find one.
249                  */
250                 t = find_lock_task_mm(p);
251                 if (!t)
252                         continue;
253                 cpumask_clear_cpu(cpu, mm_cpumask(t->mm));
254                 task_unlock(t);
255         }
256         rcu_read_unlock();
257 }
258
259 static inline void check_for_tasks(int cpu)
260 {
261         struct task_struct *p;
262         cputime_t utime, stime;
263
264         write_lock_irq(&tasklist_lock);
265         for_each_process(p) {
266                 task_cputime(p, &utime, &stime);
267                 if (task_cpu(p) == cpu && p->state == TASK_RUNNING &&
268                     (utime || stime))
269                         printk(KERN_WARNING "Task %s (pid = %d) is on cpu %d "
270                                 "(state = %ld, flags = %x)\n",
271                                 p->comm, task_pid_nr(p), cpu,
272                                 p->state, p->flags);
273         }
274         write_unlock_irq(&tasklist_lock);
275 }
276
277 struct take_cpu_down_param {
278         unsigned long mod;
279         void *hcpu;
280 };
281
282 /* Take this CPU down. */
283 static int __ref take_cpu_down(void *_param)
284 {
285         struct take_cpu_down_param *param = _param;
286         int err;
287
288         /* Ensure this CPU doesn't handle any more interrupts. */
289         err = __cpu_disable();
290         if (err < 0)
291                 return err;
292
293         cpu_notify(CPU_DYING | param->mod, param->hcpu);
294         /* Park the stopper thread */
295         kthread_park(current);
296         return 0;
297 }
298
299 /* Requires cpu_add_remove_lock to be held */
300 static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
301 {
302         int err, nr_calls = 0;
303         void *hcpu = (void *)(long)cpu;
304         unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
305         struct take_cpu_down_param tcd_param = {
306                 .mod = mod,
307                 .hcpu = hcpu,
308         };
309
310         if (num_online_cpus() == 1)
311                 return -EBUSY;
312
313         if (!cpu_online(cpu))
314                 return -EINVAL;
315
316         cpu_hotplug_begin();
317
318         err = __cpu_notify(CPU_DOWN_PREPARE | mod, hcpu, -1, &nr_calls);
319         if (err) {
320                 nr_calls--;
321                 __cpu_notify(CPU_DOWN_FAILED | mod, hcpu, nr_calls, NULL);
322                 printk("%s: attempt to take down CPU %u failed\n",
323                                 __func__, cpu);
324                 goto out_release;
325         }
326
327         /*
328          * By now we've cleared cpu_active_mask, wait for all preempt-disabled
329          * and RCU users of this state to go away such that all new such users
330          * will observe it.
331          *
332          * For CONFIG_PREEMPT we have preemptible RCU and its sync_rcu() might
333          * not imply sync_sched(), so explicitly call both.
334          *
335          * Do sync before park smpboot threads to take care the rcu boost case.
336          */
337 #ifdef CONFIG_PREEMPT
338         synchronize_sched();
339 #endif
340         synchronize_rcu();
341
342         smpboot_park_threads(cpu);
343
344         /*
345          * So now all preempt/rcu users must observe !cpu_active().
346          */
347
348         err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu));
349         if (err) {
350                 /* CPU didn't die: tell everyone.  Can't complain. */
351                 smpboot_unpark_threads(cpu);
352                 cpu_notify_nofail(CPU_DOWN_FAILED | mod, hcpu);
353                 goto out_release;
354         }
355         BUG_ON(cpu_online(cpu));
356
357         /*
358          * The migration_call() CPU_DYING callback will have removed all
359          * runnable tasks from the cpu, there's only the idle task left now
360          * that the migration thread is done doing the stop_machine thing.
361          *
362          * Wait for the stop thread to go away.
363          */
364         while (!idle_cpu(cpu))
365                 cpu_relax();
366
367         /* This actually kills the CPU. */
368         __cpu_die(cpu);
369
370         /* CPU is completely dead: tell everyone.  Too late to complain. */
371         cpu_notify_nofail(CPU_DEAD | mod, hcpu);
372
373         check_for_tasks(cpu);
374
375 out_release:
376         cpu_hotplug_done();
377         if (!err)
378                 cpu_notify_nofail(CPU_POST_DEAD | mod, hcpu);
379         return err;
380 }
381
382 int __ref cpu_down(unsigned int cpu)
383 {
384         int err;
385
386         cpu_maps_update_begin();
387
388         if (cpu_hotplug_disabled) {
389                 err = -EBUSY;
390                 goto out;
391         }
392
393         err = _cpu_down(cpu, 0);
394
395 out:
396         cpu_maps_update_done();
397         return err;
398 }
399 EXPORT_SYMBOL(cpu_down);
400 #endif /*CONFIG_HOTPLUG_CPU*/
401
402 /* Requires cpu_add_remove_lock to be held */
403 static int _cpu_up(unsigned int cpu, int tasks_frozen)
404 {
405         int ret, nr_calls = 0;
406         void *hcpu = (void *)(long)cpu;
407         unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
408         struct task_struct *idle;
409
410         cpu_hotplug_begin();
411
412         if (cpu_online(cpu) || !cpu_present(cpu)) {
413                 ret = -EINVAL;
414                 goto out;
415         }
416
417         idle = idle_thread_get(cpu);
418         if (IS_ERR(idle)) {
419                 ret = PTR_ERR(idle);
420                 goto out;
421         }
422
423         ret = smpboot_create_threads(cpu);
424         if (ret)
425                 goto out;
426
427         ret = __cpu_notify(CPU_UP_PREPARE | mod, hcpu, -1, &nr_calls);
428         if (ret) {
429                 nr_calls--;
430                 printk(KERN_WARNING "%s: attempt to bring up CPU %u failed\n",
431                                 __func__, cpu);
432                 goto out_notify;
433         }
434
435         /* Arch-specific enabling code. */
436         ret = __cpu_up(cpu, idle);
437         if (ret != 0)
438                 goto out_notify;
439         BUG_ON(!cpu_online(cpu));
440
441         /* Wake the per cpu threads */
442         smpboot_unpark_threads(cpu);
443
444         /* Now call notifier in preparation. */
445         cpu_notify(CPU_ONLINE | mod, hcpu);
446
447 out_notify:
448         if (ret != 0)
449                 __cpu_notify(CPU_UP_CANCELED | mod, hcpu, nr_calls, NULL);
450 out:
451         cpu_hotplug_done();
452
453         return ret;
454 }
455
456 int cpu_up(unsigned int cpu)
457 {
458         int err = 0;
459
460         if (!cpu_possible(cpu)) {
461                 printk(KERN_ERR "can't online cpu %d because it is not "
462                         "configured as may-hotadd at boot time\n", cpu);
463 #if defined(CONFIG_IA64)
464                 printk(KERN_ERR "please check additional_cpus= boot "
465                                 "parameter\n");
466 #endif
467                 return -EINVAL;
468         }
469
470         err = try_online_node(cpu_to_node(cpu));
471         if (err)
472                 return err;
473
474         cpu_maps_update_begin();
475
476         if (cpu_hotplug_disabled) {
477                 err = -EBUSY;
478                 goto out;
479         }
480
481         err = _cpu_up(cpu, 0);
482
483 out:
484         cpu_maps_update_done();
485         return err;
486 }
487 EXPORT_SYMBOL_GPL(cpu_up);
488
489 #ifdef CONFIG_PM_SLEEP_SMP
490 static cpumask_var_t frozen_cpus;
491
492 int disable_nonboot_cpus(void)
493 {
494         int cpu, first_cpu, error = 0;
495
496         cpu_maps_update_begin();
497         first_cpu = cpumask_first(cpu_online_mask);
498         /*
499          * We take down all of the non-boot CPUs in one shot to avoid races
500          * with the userspace trying to use the CPU hotplug at the same time
501          */
502         cpumask_clear(frozen_cpus);
503
504         printk("Disabling non-boot CPUs ...\n");
505         for_each_online_cpu(cpu) {
506                 if (cpu == first_cpu)
507                         continue;
508                 error = _cpu_down(cpu, 1);
509                 if (!error)
510                         cpumask_set_cpu(cpu, frozen_cpus);
511                 else {
512                         printk(KERN_ERR "Error taking CPU%d down: %d\n",
513                                 cpu, error);
514                         break;
515                 }
516         }
517
518         if (!error) {
519                 BUG_ON(num_online_cpus() > 1);
520                 /* Make sure the CPUs won't be enabled by someone else */
521                 cpu_hotplug_disabled = 1;
522         } else {
523                 printk(KERN_ERR "Non-boot CPUs are not disabled\n");
524         }
525         cpu_maps_update_done();
526         return error;
527 }
528
529 void __weak arch_enable_nonboot_cpus_begin(void)
530 {
531 }
532
533 void __weak arch_enable_nonboot_cpus_end(void)
534 {
535 }
536
537 void __ref enable_nonboot_cpus(void)
538 {
539         int cpu, error;
540
541         /* Allow everyone to use the CPU hotplug again */
542         cpu_maps_update_begin();
543         cpu_hotplug_disabled = 0;
544         if (cpumask_empty(frozen_cpus))
545                 goto out;
546
547         printk(KERN_INFO "Enabling non-boot CPUs ...\n");
548
549         arch_enable_nonboot_cpus_begin();
550
551         for_each_cpu(cpu, frozen_cpus) {
552                 error = _cpu_up(cpu, 1);
553                 if (!error) {
554                         printk(KERN_INFO "CPU%d is up\n", cpu);
555                         continue;
556                 }
557                 printk(KERN_WARNING "Error taking CPU%d up: %d\n", cpu, error);
558         }
559
560         arch_enable_nonboot_cpus_end();
561
562         cpumask_clear(frozen_cpus);
563 out:
564         cpu_maps_update_done();
565 }
566
567 static int __init alloc_frozen_cpus(void)
568 {
569         if (!alloc_cpumask_var(&frozen_cpus, GFP_KERNEL|__GFP_ZERO))
570                 return -ENOMEM;
571         return 0;
572 }
573 core_initcall(alloc_frozen_cpus);
574
575 /*
576  * When callbacks for CPU hotplug notifications are being executed, we must
577  * ensure that the state of the system with respect to the tasks being frozen
578  * or not, as reported by the notification, remains unchanged *throughout the
579  * duration* of the execution of the callbacks.
580  * Hence we need to prevent the freezer from racing with regular CPU hotplug.
581  *
582  * This synchronization is implemented by mutually excluding regular CPU
583  * hotplug and Suspend/Hibernate call paths by hooking onto the Suspend/
584  * Hibernate notifications.
585  */
586 static int
587 cpu_hotplug_pm_callback(struct notifier_block *nb,
588                         unsigned long action, void *ptr)
589 {
590         switch (action) {
591
592         case PM_SUSPEND_PREPARE:
593         case PM_HIBERNATION_PREPARE:
594                 cpu_hotplug_disable();
595                 break;
596
597         case PM_POST_SUSPEND:
598         case PM_POST_HIBERNATION:
599                 cpu_hotplug_enable();
600                 break;
601
602         default:
603                 return NOTIFY_DONE;
604         }
605
606         return NOTIFY_OK;
607 }
608
609
610 static int __init cpu_hotplug_pm_sync_init(void)
611 {
612         /*
613          * cpu_hotplug_pm_callback has higher priority than x86
614          * bsp_pm_callback which depends on cpu_hotplug_pm_callback
615          * to disable cpu hotplug to avoid cpu hotplug race.
616          */
617         pm_notifier(cpu_hotplug_pm_callback, 0);
618         return 0;
619 }
620 core_initcall(cpu_hotplug_pm_sync_init);
621
622 #endif /* CONFIG_PM_SLEEP_SMP */
623
624 /**
625  * notify_cpu_starting(cpu) - call the CPU_STARTING notifiers
626  * @cpu: cpu that just started
627  *
628  * This function calls the cpu_chain notifiers with CPU_STARTING.
629  * It must be called by the arch code on the new cpu, before the new cpu
630  * enables interrupts and before the "boot" cpu returns from __cpu_up().
631  */
632 void notify_cpu_starting(unsigned int cpu)
633 {
634         unsigned long val = CPU_STARTING;
635
636 #ifdef CONFIG_PM_SLEEP_SMP
637         if (frozen_cpus != NULL && cpumask_test_cpu(cpu, frozen_cpus))
638                 val = CPU_STARTING_FROZEN;
639 #endif /* CONFIG_PM_SLEEP_SMP */
640         cpu_notify(val, (void *)(long)cpu);
641 }
642
643 #endif /* CONFIG_SMP */
644
645 /*
646  * cpu_bit_bitmap[] is a special, "compressed" data structure that
647  * represents all NR_CPUS bits binary values of 1<<nr.
648  *
649  * It is used by cpumask_of() to get a constant address to a CPU
650  * mask value that has a single bit set only.
651  */
652
653 /* cpu_bit_bitmap[0] is empty - so we can back into it */
654 #define MASK_DECLARE_1(x)       [x+1][0] = (1UL << (x))
655 #define MASK_DECLARE_2(x)       MASK_DECLARE_1(x), MASK_DECLARE_1(x+1)
656 #define MASK_DECLARE_4(x)       MASK_DECLARE_2(x), MASK_DECLARE_2(x+2)
657 #define MASK_DECLARE_8(x)       MASK_DECLARE_4(x), MASK_DECLARE_4(x+4)
658
659 const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {
660
661         MASK_DECLARE_8(0),      MASK_DECLARE_8(8),
662         MASK_DECLARE_8(16),     MASK_DECLARE_8(24),
663 #if BITS_PER_LONG > 32
664         MASK_DECLARE_8(32),     MASK_DECLARE_8(40),
665         MASK_DECLARE_8(48),     MASK_DECLARE_8(56),
666 #endif
667 };
668 EXPORT_SYMBOL_GPL(cpu_bit_bitmap);
669
670 const DECLARE_BITMAP(cpu_all_bits, NR_CPUS) = CPU_BITS_ALL;
671 EXPORT_SYMBOL(cpu_all_bits);
672
673 #ifdef CONFIG_INIT_ALL_POSSIBLE
674 static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly
675         = CPU_BITS_ALL;
676 #else
677 static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly;
678 #endif
679 const struct cpumask *const cpu_possible_mask = to_cpumask(cpu_possible_bits);
680 EXPORT_SYMBOL(cpu_possible_mask);
681
682 static DECLARE_BITMAP(cpu_online_bits, CONFIG_NR_CPUS) __read_mostly;
683 const struct cpumask *const cpu_online_mask = to_cpumask(cpu_online_bits);
684 EXPORT_SYMBOL(cpu_online_mask);
685
686 static DECLARE_BITMAP(cpu_present_bits, CONFIG_NR_CPUS) __read_mostly;
687 const struct cpumask *const cpu_present_mask = to_cpumask(cpu_present_bits);
688 EXPORT_SYMBOL(cpu_present_mask);
689
690 static DECLARE_BITMAP(cpu_active_bits, CONFIG_NR_CPUS) __read_mostly;
691 const struct cpumask *const cpu_active_mask = to_cpumask(cpu_active_bits);
692 EXPORT_SYMBOL(cpu_active_mask);
693
694 void set_cpu_possible(unsigned int cpu, bool possible)
695 {
696         if (possible)
697                 cpumask_set_cpu(cpu, to_cpumask(cpu_possible_bits));
698         else
699                 cpumask_clear_cpu(cpu, to_cpumask(cpu_possible_bits));
700 }
701
702 void set_cpu_present(unsigned int cpu, bool present)
703 {
704         if (present)
705                 cpumask_set_cpu(cpu, to_cpumask(cpu_present_bits));
706         else
707                 cpumask_clear_cpu(cpu, to_cpumask(cpu_present_bits));
708 }
709
710 void set_cpu_online(unsigned int cpu, bool online)
711 {
712         if (online)
713                 cpumask_set_cpu(cpu, to_cpumask(cpu_online_bits));
714         else
715                 cpumask_clear_cpu(cpu, to_cpumask(cpu_online_bits));
716 }
717
718 void set_cpu_active(unsigned int cpu, bool active)
719 {
720         if (active)
721                 cpumask_set_cpu(cpu, to_cpumask(cpu_active_bits));
722         else
723                 cpumask_clear_cpu(cpu, to_cpumask(cpu_active_bits));
724 }
725
726 void init_cpu_present(const struct cpumask *src)
727 {
728         cpumask_copy(to_cpumask(cpu_present_bits), src);
729 }
730
731 void init_cpu_possible(const struct cpumask *src)
732 {
733         cpumask_copy(to_cpumask(cpu_possible_bits), src);
734 }
735
736 void init_cpu_online(const struct cpumask *src)
737 {
738         cpumask_copy(to_cpumask(cpu_online_bits), src);
739 }