11da177e4SLinus Torvalds /* CPU control. 21da177e4SLinus Torvalds * (C) 2001, 2002, 2003, 2004 Rusty Russell 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * This code is licenced under the GPL. 51da177e4SLinus Torvalds */ 61da177e4SLinus Torvalds #include <linux/proc_fs.h> 71da177e4SLinus Torvalds #include <linux/smp.h> 81da177e4SLinus Torvalds #include <linux/init.h> 91da177e4SLinus Torvalds #include <linux/notifier.h> 101da177e4SLinus Torvalds #include <linux/sched.h> 111da177e4SLinus Torvalds #include <linux/unistd.h> 121da177e4SLinus Torvalds #include <linux/cpu.h> 13cb79295eSAnton Vorontsov #include <linux/oom.h> 14cb79295eSAnton Vorontsov #include <linux/rcupdate.h> 159984de1aSPaul Gortmaker #include <linux/export.h> 16e4cc2f87SAnton Vorontsov #include <linux/bug.h> 171da177e4SLinus Torvalds #include <linux/kthread.h> 181da177e4SLinus Torvalds #include <linux/stop_machine.h> 1981615b62SIngo Molnar #include <linux/mutex.h> 205a0e3ad6STejun Heo #include <linux/gfp.h> 2179cfbdfaSSrivatsa S. Bhat #include <linux/suspend.h> 221da177e4SLinus Torvalds 2338498a67SThomas Gleixner #include "smpboot.h" 2438498a67SThomas Gleixner 2598a79d6aSRusty Russell #ifdef CONFIG_SMP 26b3199c02SRusty Russell /* Serializes the updates to cpu_online_mask, cpu_present_mask */ 27aa953877SLinus Torvalds static DEFINE_MUTEX(cpu_add_remove_lock); 281da177e4SLinus Torvalds 2979a6cdebSLai Jiangshan /* 3079a6cdebSLai Jiangshan * The following two API's must be used when attempting 3179a6cdebSLai Jiangshan * to serialize the updates to cpu_online_mask, cpu_present_mask. 3279a6cdebSLai Jiangshan */ 3379a6cdebSLai Jiangshan void cpu_maps_update_begin(void) 3479a6cdebSLai Jiangshan { 3579a6cdebSLai Jiangshan mutex_lock(&cpu_add_remove_lock); 3679a6cdebSLai Jiangshan } 3779a6cdebSLai Jiangshan 3879a6cdebSLai Jiangshan void cpu_maps_update_done(void) 3979a6cdebSLai Jiangshan { 4079a6cdebSLai Jiangshan mutex_unlock(&cpu_add_remove_lock); 4179a6cdebSLai Jiangshan } 4279a6cdebSLai Jiangshan 435c113fbeSDaniel J Blueman static RAW_NOTIFIER_HEAD(cpu_chain); 441da177e4SLinus Torvalds 45e3920fb4SRafael J. Wysocki /* If set, cpu_up and cpu_down will return -EBUSY and do nothing. 46e3920fb4SRafael J. Wysocki * Should always be manipulated under cpu_add_remove_lock 47e3920fb4SRafael J. Wysocki */ 48e3920fb4SRafael J. Wysocki static int cpu_hotplug_disabled; 49e3920fb4SRafael J. Wysocki 5079a6cdebSLai Jiangshan #ifdef CONFIG_HOTPLUG_CPU 5179a6cdebSLai Jiangshan 52d221938cSGautham R Shenoy static struct { 53d221938cSGautham R Shenoy struct task_struct *active_writer; 54d221938cSGautham R Shenoy struct mutex lock; /* Synchronizes accesses to refcount, */ 55d221938cSGautham R Shenoy /* 56d221938cSGautham R Shenoy * Also blocks the new readers during 57d221938cSGautham R Shenoy * an ongoing cpu hotplug operation. 58d221938cSGautham R Shenoy */ 59d221938cSGautham R Shenoy int refcount; 6031950eb6SLinus Torvalds } cpu_hotplug = { 6131950eb6SLinus Torvalds .active_writer = NULL, 6231950eb6SLinus Torvalds .lock = __MUTEX_INITIALIZER(cpu_hotplug.lock), 6331950eb6SLinus Torvalds .refcount = 0, 6431950eb6SLinus Torvalds }; 65d221938cSGautham R Shenoy 6686ef5c9aSGautham R Shenoy void get_online_cpus(void) 67a9d9baa1SAshok Raj { 68d221938cSGautham R Shenoy might_sleep(); 69d221938cSGautham R Shenoy if (cpu_hotplug.active_writer == current) 70aa953877SLinus Torvalds return; 71d221938cSGautham R Shenoy mutex_lock(&cpu_hotplug.lock); 72d221938cSGautham R Shenoy cpu_hotplug.refcount++; 73d221938cSGautham R Shenoy mutex_unlock(&cpu_hotplug.lock); 74d221938cSGautham R Shenoy 75a9d9baa1SAshok Raj } 7686ef5c9aSGautham R Shenoy EXPORT_SYMBOL_GPL(get_online_cpus); 77a9d9baa1SAshok Raj 7886ef5c9aSGautham R Shenoy void put_online_cpus(void) 79a9d9baa1SAshok Raj { 80d221938cSGautham R Shenoy if (cpu_hotplug.active_writer == current) 81aa953877SLinus Torvalds return; 82d221938cSGautham R Shenoy mutex_lock(&cpu_hotplug.lock); 83075663d1SSrivatsa S. Bhat 84075663d1SSrivatsa S. Bhat if (WARN_ON(!cpu_hotplug.refcount)) 85075663d1SSrivatsa S. Bhat cpu_hotplug.refcount++; /* try to fix things up */ 86075663d1SSrivatsa S. Bhat 87d2ba7e2aSOleg Nesterov if (!--cpu_hotplug.refcount && unlikely(cpu_hotplug.active_writer)) 88d2ba7e2aSOleg Nesterov wake_up_process(cpu_hotplug.active_writer); 89d221938cSGautham R Shenoy mutex_unlock(&cpu_hotplug.lock); 90d221938cSGautham R Shenoy 91a9d9baa1SAshok Raj } 9286ef5c9aSGautham R Shenoy EXPORT_SYMBOL_GPL(put_online_cpus); 93a9d9baa1SAshok Raj 94d221938cSGautham R Shenoy /* 95d221938cSGautham R Shenoy * This ensures that the hotplug operation can begin only when the 96d221938cSGautham R Shenoy * refcount goes to zero. 97d221938cSGautham R Shenoy * 98d221938cSGautham R Shenoy * Note that during a cpu-hotplug operation, the new readers, if any, 99d221938cSGautham R Shenoy * will be blocked by the cpu_hotplug.lock 100d221938cSGautham R Shenoy * 101d2ba7e2aSOleg Nesterov * Since cpu_hotplug_begin() is always called after invoking 102d2ba7e2aSOleg Nesterov * cpu_maps_update_begin(), we can be sure that only one writer is active. 103d221938cSGautham R Shenoy * 104d221938cSGautham R Shenoy * Note that theoretically, there is a possibility of a livelock: 105d221938cSGautham R Shenoy * - Refcount goes to zero, last reader wakes up the sleeping 106d221938cSGautham R Shenoy * writer. 107d221938cSGautham R Shenoy * - Last reader unlocks the cpu_hotplug.lock. 108d221938cSGautham R Shenoy * - A new reader arrives at this moment, bumps up the refcount. 109d221938cSGautham R Shenoy * - The writer acquires the cpu_hotplug.lock finds the refcount 110d221938cSGautham R Shenoy * non zero and goes to sleep again. 111d221938cSGautham R Shenoy * 112d221938cSGautham R Shenoy * However, this is very difficult to achieve in practice since 11386ef5c9aSGautham R Shenoy * get_online_cpus() not an api which is called all that often. 114d221938cSGautham R Shenoy * 115d221938cSGautham R Shenoy */ 116b9d10be7SToshi Kani void cpu_hotplug_begin(void) 117d221938cSGautham R Shenoy { 118d221938cSGautham R Shenoy cpu_hotplug.active_writer = current; 119d2ba7e2aSOleg Nesterov 120d2ba7e2aSOleg Nesterov for (;;) { 121d2ba7e2aSOleg Nesterov mutex_lock(&cpu_hotplug.lock); 122d2ba7e2aSOleg Nesterov if (likely(!cpu_hotplug.refcount)) 123d2ba7e2aSOleg Nesterov break; 124d2ba7e2aSOleg Nesterov __set_current_state(TASK_UNINTERRUPTIBLE); 125d221938cSGautham R Shenoy mutex_unlock(&cpu_hotplug.lock); 126d221938cSGautham R Shenoy schedule(); 127d221938cSGautham R Shenoy } 128d221938cSGautham R Shenoy } 129d221938cSGautham R Shenoy 130b9d10be7SToshi Kani void cpu_hotplug_done(void) 131d221938cSGautham R Shenoy { 132d221938cSGautham R Shenoy cpu_hotplug.active_writer = NULL; 133d221938cSGautham R Shenoy mutex_unlock(&cpu_hotplug.lock); 134d221938cSGautham R Shenoy } 13579a6cdebSLai Jiangshan 13616e53dbfSSrivatsa S. Bhat /* 13716e53dbfSSrivatsa S. Bhat * Wait for currently running CPU hotplug operations to complete (if any) and 13816e53dbfSSrivatsa S. Bhat * disable future CPU hotplug (from sysfs). The 'cpu_add_remove_lock' protects 13916e53dbfSSrivatsa S. Bhat * the 'cpu_hotplug_disabled' flag. The same lock is also acquired by the 14016e53dbfSSrivatsa S. Bhat * hotplug path before performing hotplug operations. So acquiring that lock 14116e53dbfSSrivatsa S. Bhat * guarantees mutual exclusion from any currently running hotplug operations. 14216e53dbfSSrivatsa S. Bhat */ 14316e53dbfSSrivatsa S. Bhat void cpu_hotplug_disable(void) 14416e53dbfSSrivatsa S. Bhat { 14516e53dbfSSrivatsa S. Bhat cpu_maps_update_begin(); 14616e53dbfSSrivatsa S. Bhat cpu_hotplug_disabled = 1; 14716e53dbfSSrivatsa S. Bhat cpu_maps_update_done(); 14816e53dbfSSrivatsa S. Bhat } 14916e53dbfSSrivatsa S. Bhat 15016e53dbfSSrivatsa S. Bhat void cpu_hotplug_enable(void) 15116e53dbfSSrivatsa S. Bhat { 15216e53dbfSSrivatsa S. Bhat cpu_maps_update_begin(); 15316e53dbfSSrivatsa S. Bhat cpu_hotplug_disabled = 0; 15416e53dbfSSrivatsa S. Bhat cpu_maps_update_done(); 15516e53dbfSSrivatsa S. Bhat } 15616e53dbfSSrivatsa S. Bhat 157b9d10be7SToshi Kani #endif /* CONFIG_HOTPLUG_CPU */ 15879a6cdebSLai Jiangshan 1591da177e4SLinus Torvalds /* Need to know about CPUs going up/down? */ 160f7b16c10SSam Ravnborg int __ref register_cpu_notifier(struct notifier_block *nb) 1611da177e4SLinus Torvalds { 162bd5349cfSNeil Brown int ret; 163d221938cSGautham R Shenoy cpu_maps_update_begin(); 164bd5349cfSNeil Brown ret = raw_notifier_chain_register(&cpu_chain, nb); 165d221938cSGautham R Shenoy cpu_maps_update_done(); 166bd5349cfSNeil Brown return ret; 1671da177e4SLinus Torvalds } 16865edc68cSChandra Seetharaman 169e9fb7631SAkinobu Mita static int __cpu_notify(unsigned long val, void *v, int nr_to_call, 170e9fb7631SAkinobu Mita int *nr_calls) 171e9fb7631SAkinobu Mita { 172e6bde73bSAkinobu Mita int ret; 173e6bde73bSAkinobu Mita 174e6bde73bSAkinobu Mita ret = __raw_notifier_call_chain(&cpu_chain, val, v, nr_to_call, 175e9fb7631SAkinobu Mita nr_calls); 176e6bde73bSAkinobu Mita 177e6bde73bSAkinobu Mita return notifier_to_errno(ret); 178e9fb7631SAkinobu Mita } 179e9fb7631SAkinobu Mita 180e9fb7631SAkinobu Mita static int cpu_notify(unsigned long val, void *v) 181e9fb7631SAkinobu Mita { 182e9fb7631SAkinobu Mita return __cpu_notify(val, v, -1, NULL); 183e9fb7631SAkinobu Mita } 184e9fb7631SAkinobu Mita 18500b9b0afSLinus Torvalds #ifdef CONFIG_HOTPLUG_CPU 18600b9b0afSLinus Torvalds 187e9fb7631SAkinobu Mita static void cpu_notify_nofail(unsigned long val, void *v) 188e9fb7631SAkinobu Mita { 18900b9b0afSLinus Torvalds BUG_ON(cpu_notify(val, v)); 190e9fb7631SAkinobu Mita } 1911da177e4SLinus Torvalds EXPORT_SYMBOL(register_cpu_notifier); 1921da177e4SLinus Torvalds 1939647155fSSam Ravnborg void __ref unregister_cpu_notifier(struct notifier_block *nb) 1941da177e4SLinus Torvalds { 195d221938cSGautham R Shenoy cpu_maps_update_begin(); 196bd5349cfSNeil Brown raw_notifier_chain_unregister(&cpu_chain, nb); 197d221938cSGautham R Shenoy cpu_maps_update_done(); 1981da177e4SLinus Torvalds } 1991da177e4SLinus Torvalds EXPORT_SYMBOL(unregister_cpu_notifier); 2001da177e4SLinus Torvalds 201e4cc2f87SAnton Vorontsov /** 202e4cc2f87SAnton Vorontsov * clear_tasks_mm_cpumask - Safely clear tasks' mm_cpumask for a CPU 203e4cc2f87SAnton Vorontsov * @cpu: a CPU id 204e4cc2f87SAnton Vorontsov * 205e4cc2f87SAnton Vorontsov * This function walks all processes, finds a valid mm struct for each one and 206e4cc2f87SAnton Vorontsov * then clears a corresponding bit in mm's cpumask. While this all sounds 207e4cc2f87SAnton Vorontsov * trivial, there are various non-obvious corner cases, which this function 208e4cc2f87SAnton Vorontsov * tries to solve in a safe manner. 209e4cc2f87SAnton Vorontsov * 210e4cc2f87SAnton Vorontsov * Also note that the function uses a somewhat relaxed locking scheme, so it may 211e4cc2f87SAnton Vorontsov * be called only for an already offlined CPU. 212e4cc2f87SAnton Vorontsov */ 213cb79295eSAnton Vorontsov void clear_tasks_mm_cpumask(int cpu) 214cb79295eSAnton Vorontsov { 215cb79295eSAnton Vorontsov struct task_struct *p; 216cb79295eSAnton Vorontsov 217cb79295eSAnton Vorontsov /* 218cb79295eSAnton Vorontsov * This function is called after the cpu is taken down and marked 219cb79295eSAnton Vorontsov * offline, so its not like new tasks will ever get this cpu set in 220cb79295eSAnton Vorontsov * their mm mask. -- Peter Zijlstra 221cb79295eSAnton Vorontsov * Thus, we may use rcu_read_lock() here, instead of grabbing 222cb79295eSAnton Vorontsov * full-fledged tasklist_lock. 223cb79295eSAnton Vorontsov */ 224e4cc2f87SAnton Vorontsov WARN_ON(cpu_online(cpu)); 225cb79295eSAnton Vorontsov rcu_read_lock(); 226cb79295eSAnton Vorontsov for_each_process(p) { 227cb79295eSAnton Vorontsov struct task_struct *t; 228cb79295eSAnton Vorontsov 229e4cc2f87SAnton Vorontsov /* 230e4cc2f87SAnton Vorontsov * Main thread might exit, but other threads may still have 231e4cc2f87SAnton Vorontsov * a valid mm. Find one. 232e4cc2f87SAnton Vorontsov */ 233cb79295eSAnton Vorontsov t = find_lock_task_mm(p); 234cb79295eSAnton Vorontsov if (!t) 235cb79295eSAnton Vorontsov continue; 236cb79295eSAnton Vorontsov cpumask_clear_cpu(cpu, mm_cpumask(t->mm)); 237cb79295eSAnton Vorontsov task_unlock(t); 238cb79295eSAnton Vorontsov } 239cb79295eSAnton Vorontsov rcu_read_unlock(); 240cb79295eSAnton Vorontsov } 241cb79295eSAnton Vorontsov 2421da177e4SLinus Torvalds static inline void check_for_tasks(int cpu) 2431da177e4SLinus Torvalds { 2441da177e4SLinus Torvalds struct task_struct *p; 2456fac4829SFrederic Weisbecker cputime_t utime, stime; 2461da177e4SLinus Torvalds 2471da177e4SLinus Torvalds write_lock_irq(&tasklist_lock); 2481da177e4SLinus Torvalds for_each_process(p) { 2496fac4829SFrederic Weisbecker task_cputime(p, &utime, &stime); 25011854247SPeter Zijlstra if (task_cpu(p) == cpu && p->state == TASK_RUNNING && 2516fac4829SFrederic Weisbecker (utime || stime)) 2529d3cfc4cSFrans Pop printk(KERN_WARNING "Task %s (pid = %d) is on cpu %d " 2539d3cfc4cSFrans Pop "(state = %ld, flags = %x)\n", 254ba25f9dcSPavel Emelyanov p->comm, task_pid_nr(p), cpu, 255ba25f9dcSPavel Emelyanov p->state, p->flags); 2561da177e4SLinus Torvalds } 2571da177e4SLinus Torvalds write_unlock_irq(&tasklist_lock); 2581da177e4SLinus Torvalds } 2591da177e4SLinus Torvalds 260db912f96SAvi Kivity struct take_cpu_down_param { 261db912f96SAvi Kivity unsigned long mod; 262db912f96SAvi Kivity void *hcpu; 263db912f96SAvi Kivity }; 264db912f96SAvi Kivity 2651da177e4SLinus Torvalds /* Take this CPU down. */ 266514a20a5SSam Ravnborg static int __ref take_cpu_down(void *_param) 2671da177e4SLinus Torvalds { 268db912f96SAvi Kivity struct take_cpu_down_param *param = _param; 2691da177e4SLinus Torvalds int err; 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds /* Ensure this CPU doesn't handle any more interrupts. */ 2721da177e4SLinus Torvalds err = __cpu_disable(); 2731da177e4SLinus Torvalds if (err < 0) 274f3705136SZwane Mwaikambo return err; 275f3705136SZwane Mwaikambo 276e9fb7631SAkinobu Mita cpu_notify(CPU_DYING | param->mod, param->hcpu); 27714e568e7SThomas Gleixner /* Park the stopper thread */ 27814e568e7SThomas Gleixner kthread_park(current); 279f3705136SZwane Mwaikambo return 0; 2801da177e4SLinus Torvalds } 2811da177e4SLinus Torvalds 282e3920fb4SRafael J. Wysocki /* Requires cpu_add_remove_lock to be held */ 283514a20a5SSam Ravnborg static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) 2841da177e4SLinus Torvalds { 285e7407dccSHeiko Carstens int err, nr_calls = 0; 286e7407dccSHeiko Carstens void *hcpu = (void *)(long)cpu; 2878bb78442SRafael J. Wysocki unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; 288db912f96SAvi Kivity struct take_cpu_down_param tcd_param = { 289db912f96SAvi Kivity .mod = mod, 290db912f96SAvi Kivity .hcpu = hcpu, 291db912f96SAvi Kivity }; 2921da177e4SLinus Torvalds 293e3920fb4SRafael J. Wysocki if (num_online_cpus() == 1) 294e3920fb4SRafael J. Wysocki return -EBUSY; 2951da177e4SLinus Torvalds 296e3920fb4SRafael J. Wysocki if (!cpu_online(cpu)) 297e3920fb4SRafael J. Wysocki return -EINVAL; 2981da177e4SLinus Torvalds 299d221938cSGautham R Shenoy cpu_hotplug_begin(); 3004d51985eSMichael Rodriguez 301e9fb7631SAkinobu Mita err = __cpu_notify(CPU_DOWN_PREPARE | mod, hcpu, -1, &nr_calls); 302e6bde73bSAkinobu Mita if (err) { 303a0d8cdb6SAkinobu Mita nr_calls--; 304e9fb7631SAkinobu Mita __cpu_notify(CPU_DOWN_FAILED | mod, hcpu, nr_calls, NULL); 3051da177e4SLinus Torvalds printk("%s: attempt to take down CPU %u failed\n", 306af1f16d0SHarvey Harrison __func__, cpu); 307baaca49fSGautham R Shenoy goto out_release; 3081da177e4SLinus Torvalds } 3091da177e4SLinus Torvalds 3106acce3efSPeter Zijlstra /* 3116acce3efSPeter Zijlstra * By now we've cleared cpu_active_mask, wait for all preempt-disabled 3126acce3efSPeter Zijlstra * and RCU users of this state to go away such that all new such users 3136acce3efSPeter Zijlstra * will observe it. 3146acce3efSPeter Zijlstra * 3156acce3efSPeter Zijlstra * For CONFIG_PREEMPT we have preemptible RCU and its sync_rcu() might 3166acce3efSPeter Zijlstra * not imply sync_sched(), so explicitly call both. 317*106dd5afSMichael wang * 318*106dd5afSMichael wang * Do sync before park smpboot threads to take care the rcu boost case. 3196acce3efSPeter Zijlstra */ 3206acce3efSPeter Zijlstra #ifdef CONFIG_PREEMPT 3216acce3efSPeter Zijlstra synchronize_sched(); 3226acce3efSPeter Zijlstra #endif 3236acce3efSPeter Zijlstra synchronize_rcu(); 3246acce3efSPeter Zijlstra 325*106dd5afSMichael wang smpboot_park_threads(cpu); 326*106dd5afSMichael wang 3276acce3efSPeter Zijlstra /* 3286acce3efSPeter Zijlstra * So now all preempt/rcu users must observe !cpu_active(). 3296acce3efSPeter Zijlstra */ 3306acce3efSPeter Zijlstra 331e0b582ecSRusty Russell err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu)); 33204321587SRusty Russell if (err) { 3331da177e4SLinus Torvalds /* CPU didn't die: tell everyone. Can't complain. */ 334f97f8f06SThomas Gleixner smpboot_unpark_threads(cpu); 335e9fb7631SAkinobu Mita cpu_notify_nofail(CPU_DOWN_FAILED | mod, hcpu); 3366a1bdc1bSOleg Nesterov goto out_release; 3371da177e4SLinus Torvalds } 33804321587SRusty Russell BUG_ON(cpu_online(cpu)); 3391da177e4SLinus Torvalds 34048c5ccaeSPeter Zijlstra /* 34148c5ccaeSPeter Zijlstra * The migration_call() CPU_DYING callback will have removed all 34248c5ccaeSPeter Zijlstra * runnable tasks from the cpu, there's only the idle task left now 34348c5ccaeSPeter Zijlstra * that the migration thread is done doing the stop_machine thing. 34451a96c77SPeter Zijlstra * 34551a96c77SPeter Zijlstra * Wait for the stop thread to go away. 34648c5ccaeSPeter Zijlstra */ 34751a96c77SPeter Zijlstra while (!idle_cpu(cpu)) 34851a96c77SPeter Zijlstra cpu_relax(); 3491da177e4SLinus Torvalds 3501da177e4SLinus Torvalds /* This actually kills the CPU. */ 3511da177e4SLinus Torvalds __cpu_die(cpu); 3521da177e4SLinus Torvalds 3531da177e4SLinus Torvalds /* CPU is completely dead: tell everyone. Too late to complain. */ 354e9fb7631SAkinobu Mita cpu_notify_nofail(CPU_DEAD | mod, hcpu); 3551da177e4SLinus Torvalds 3561da177e4SLinus Torvalds check_for_tasks(cpu); 3571da177e4SLinus Torvalds 358baaca49fSGautham R Shenoy out_release: 359d221938cSGautham R Shenoy cpu_hotplug_done(); 360e9fb7631SAkinobu Mita if (!err) 361e9fb7631SAkinobu Mita cpu_notify_nofail(CPU_POST_DEAD | mod, hcpu); 362e3920fb4SRafael J. Wysocki return err; 363e3920fb4SRafael J. Wysocki } 364e3920fb4SRafael J. Wysocki 365514a20a5SSam Ravnborg int __ref cpu_down(unsigned int cpu) 366e3920fb4SRafael J. Wysocki { 3679ea09af3SHeiko Carstens int err; 368e3920fb4SRafael J. Wysocki 369d221938cSGautham R Shenoy cpu_maps_update_begin(); 370e761b772SMax Krasnyansky 371e761b772SMax Krasnyansky if (cpu_hotplug_disabled) { 372e3920fb4SRafael J. Wysocki err = -EBUSY; 373e761b772SMax Krasnyansky goto out; 374e761b772SMax Krasnyansky } 375e761b772SMax Krasnyansky 3768bb78442SRafael J. Wysocki err = _cpu_down(cpu, 0); 377e3920fb4SRafael J. Wysocki 378e761b772SMax Krasnyansky out: 379d221938cSGautham R Shenoy cpu_maps_update_done(); 3801da177e4SLinus Torvalds return err; 3811da177e4SLinus Torvalds } 382b62b8ef9SZhang Rui EXPORT_SYMBOL(cpu_down); 3831da177e4SLinus Torvalds #endif /*CONFIG_HOTPLUG_CPU*/ 3841da177e4SLinus Torvalds 385e3920fb4SRafael J. Wysocki /* Requires cpu_add_remove_lock to be held */ 3860db0628dSPaul Gortmaker static int _cpu_up(unsigned int cpu, int tasks_frozen) 3871da177e4SLinus Torvalds { 388baaca49fSGautham R Shenoy int ret, nr_calls = 0; 3891da177e4SLinus Torvalds void *hcpu = (void *)(long)cpu; 3908bb78442SRafael J. Wysocki unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; 3913bb5d2eeSSuresh Siddha struct task_struct *idle; 3921da177e4SLinus Torvalds 393d221938cSGautham R Shenoy cpu_hotplug_begin(); 39438498a67SThomas Gleixner 3955e5041f3SYasuaki Ishimatsu if (cpu_online(cpu) || !cpu_present(cpu)) { 3965e5041f3SYasuaki Ishimatsu ret = -EINVAL; 3975e5041f3SYasuaki Ishimatsu goto out; 3985e5041f3SYasuaki Ishimatsu } 3995e5041f3SYasuaki Ishimatsu 4003bb5d2eeSSuresh Siddha idle = idle_thread_get(cpu); 4013bb5d2eeSSuresh Siddha if (IS_ERR(idle)) { 4023bb5d2eeSSuresh Siddha ret = PTR_ERR(idle); 40338498a67SThomas Gleixner goto out; 4043bb5d2eeSSuresh Siddha } 40538498a67SThomas Gleixner 406f97f8f06SThomas Gleixner ret = smpboot_create_threads(cpu); 407f97f8f06SThomas Gleixner if (ret) 408f97f8f06SThomas Gleixner goto out; 409f97f8f06SThomas Gleixner 410e9fb7631SAkinobu Mita ret = __cpu_notify(CPU_UP_PREPARE | mod, hcpu, -1, &nr_calls); 411e6bde73bSAkinobu Mita if (ret) { 412a0d8cdb6SAkinobu Mita nr_calls--; 4134d51985eSMichael Rodriguez printk(KERN_WARNING "%s: attempt to bring up CPU %u failed\n", 414af1f16d0SHarvey Harrison __func__, cpu); 4151da177e4SLinus Torvalds goto out_notify; 4161da177e4SLinus Torvalds } 4171da177e4SLinus Torvalds 4181da177e4SLinus Torvalds /* Arch-specific enabling code. */ 4193bb5d2eeSSuresh Siddha ret = __cpu_up(cpu, idle); 4201da177e4SLinus Torvalds if (ret != 0) 4211da177e4SLinus Torvalds goto out_notify; 4226978c705SEric Sesterhenn BUG_ON(!cpu_online(cpu)); 4231da177e4SLinus Torvalds 424f97f8f06SThomas Gleixner /* Wake the per cpu threads */ 425f97f8f06SThomas Gleixner smpboot_unpark_threads(cpu); 426f97f8f06SThomas Gleixner 4271da177e4SLinus Torvalds /* Now call notifier in preparation. */ 428e9fb7631SAkinobu Mita cpu_notify(CPU_ONLINE | mod, hcpu); 4291da177e4SLinus Torvalds 4301da177e4SLinus Torvalds out_notify: 4311da177e4SLinus Torvalds if (ret != 0) 432e9fb7631SAkinobu Mita __cpu_notify(CPU_UP_CANCELED | mod, hcpu, nr_calls, NULL); 43338498a67SThomas Gleixner out: 434d221938cSGautham R Shenoy cpu_hotplug_done(); 435e3920fb4SRafael J. Wysocki 4361da177e4SLinus Torvalds return ret; 4371da177e4SLinus Torvalds } 438e3920fb4SRafael J. Wysocki 4390db0628dSPaul Gortmaker int cpu_up(unsigned int cpu) 440e3920fb4SRafael J. Wysocki { 441e3920fb4SRafael J. Wysocki int err = 0; 442cf23422bSminskey guo 443cf23422bSminskey guo #ifdef CONFIG_MEMORY_HOTPLUG 444cf23422bSminskey guo int nid; 445cf23422bSminskey guo pg_data_t *pgdat; 446cf23422bSminskey guo #endif 447cf23422bSminskey guo 448e0b582ecSRusty Russell if (!cpu_possible(cpu)) { 44973e753a5SKAMEZAWA Hiroyuki printk(KERN_ERR "can't online cpu %d because it is not " 45073e753a5SKAMEZAWA Hiroyuki "configured as may-hotadd at boot time\n", cpu); 45187d5e023SChen Gong #if defined(CONFIG_IA64) 45273e753a5SKAMEZAWA Hiroyuki printk(KERN_ERR "please check additional_cpus= boot " 45373e753a5SKAMEZAWA Hiroyuki "parameter\n"); 45473e753a5SKAMEZAWA Hiroyuki #endif 45573e753a5SKAMEZAWA Hiroyuki return -EINVAL; 45673e753a5SKAMEZAWA Hiroyuki } 457e3920fb4SRafael J. Wysocki 458cf23422bSminskey guo #ifdef CONFIG_MEMORY_HOTPLUG 459cf23422bSminskey guo nid = cpu_to_node(cpu); 460cf23422bSminskey guo if (!node_online(nid)) { 461cf23422bSminskey guo err = mem_online_node(nid); 462cf23422bSminskey guo if (err) 463cf23422bSminskey guo return err; 464cf23422bSminskey guo } 465cf23422bSminskey guo 466cf23422bSminskey guo pgdat = NODE_DATA(nid); 467cf23422bSminskey guo if (!pgdat) { 468cf23422bSminskey guo printk(KERN_ERR 469cf23422bSminskey guo "Can't online cpu %d due to NULL pgdat\n", cpu); 470cf23422bSminskey guo return -ENOMEM; 471cf23422bSminskey guo } 472cf23422bSminskey guo 4734eaf3f64SHaicheng Li if (pgdat->node_zonelists->_zonerefs->zone == NULL) { 4744eaf3f64SHaicheng Li mutex_lock(&zonelists_mutex); 4759adb62a5SJiang Liu build_all_zonelists(NULL, NULL); 4764eaf3f64SHaicheng Li mutex_unlock(&zonelists_mutex); 4774eaf3f64SHaicheng Li } 478cf23422bSminskey guo #endif 479cf23422bSminskey guo 480d221938cSGautham R Shenoy cpu_maps_update_begin(); 481e761b772SMax Krasnyansky 482e761b772SMax Krasnyansky if (cpu_hotplug_disabled) { 483e3920fb4SRafael J. Wysocki err = -EBUSY; 484e761b772SMax Krasnyansky goto out; 485e761b772SMax Krasnyansky } 486e761b772SMax Krasnyansky 4878bb78442SRafael J. Wysocki err = _cpu_up(cpu, 0); 488e3920fb4SRafael J. Wysocki 489e761b772SMax Krasnyansky out: 490d221938cSGautham R Shenoy cpu_maps_update_done(); 491e3920fb4SRafael J. Wysocki return err; 492e3920fb4SRafael J. Wysocki } 493a513f6baSPaul E. McKenney EXPORT_SYMBOL_GPL(cpu_up); 494e3920fb4SRafael J. Wysocki 495f3de4be9SRafael J. Wysocki #ifdef CONFIG_PM_SLEEP_SMP 496e0b582ecSRusty Russell static cpumask_var_t frozen_cpus; 497e3920fb4SRafael J. Wysocki 498e3920fb4SRafael J. Wysocki int disable_nonboot_cpus(void) 499e3920fb4SRafael J. Wysocki { 500e9a5f426SRafael J. Wysocki int cpu, first_cpu, error = 0; 501e3920fb4SRafael J. Wysocki 502d221938cSGautham R Shenoy cpu_maps_update_begin(); 503e0b582ecSRusty Russell first_cpu = cpumask_first(cpu_online_mask); 5049ee349adSXiaotian Feng /* 5059ee349adSXiaotian Feng * We take down all of the non-boot CPUs in one shot to avoid races 506e3920fb4SRafael J. Wysocki * with the userspace trying to use the CPU hotplug at the same time 507e3920fb4SRafael J. Wysocki */ 508e0b582ecSRusty Russell cpumask_clear(frozen_cpus); 5096ad4c188SPeter Zijlstra 510e3920fb4SRafael J. Wysocki printk("Disabling non-boot CPUs ...\n"); 511e3920fb4SRafael J. Wysocki for_each_online_cpu(cpu) { 512e3920fb4SRafael J. Wysocki if (cpu == first_cpu) 513e3920fb4SRafael J. Wysocki continue; 5148bb78442SRafael J. Wysocki error = _cpu_down(cpu, 1); 515feae3203SMike Travis if (!error) 516e0b582ecSRusty Russell cpumask_set_cpu(cpu, frozen_cpus); 517feae3203SMike Travis else { 518e3920fb4SRafael J. Wysocki printk(KERN_ERR "Error taking CPU%d down: %d\n", 519e3920fb4SRafael J. Wysocki cpu, error); 520e3920fb4SRafael J. Wysocki break; 521e3920fb4SRafael J. Wysocki } 522e3920fb4SRafael J. Wysocki } 52386886e55SJoseph Cihula 524e3920fb4SRafael J. Wysocki if (!error) { 525e3920fb4SRafael J. Wysocki BUG_ON(num_online_cpus() > 1); 526e3920fb4SRafael J. Wysocki /* Make sure the CPUs won't be enabled by someone else */ 527e3920fb4SRafael J. Wysocki cpu_hotplug_disabled = 1; 528e3920fb4SRafael J. Wysocki } else { 529e1d9fd2eSIngo Molnar printk(KERN_ERR "Non-boot CPUs are not disabled\n"); 530e3920fb4SRafael J. Wysocki } 531d221938cSGautham R Shenoy cpu_maps_update_done(); 532e3920fb4SRafael J. Wysocki return error; 533e3920fb4SRafael J. Wysocki } 534e3920fb4SRafael J. Wysocki 535d0af9eedSSuresh Siddha void __weak arch_enable_nonboot_cpus_begin(void) 536d0af9eedSSuresh Siddha { 537d0af9eedSSuresh Siddha } 538d0af9eedSSuresh Siddha 539d0af9eedSSuresh Siddha void __weak arch_enable_nonboot_cpus_end(void) 540d0af9eedSSuresh Siddha { 541d0af9eedSSuresh Siddha } 542d0af9eedSSuresh Siddha 543fa7303e2SSam Ravnborg void __ref enable_nonboot_cpus(void) 544e3920fb4SRafael J. Wysocki { 545e3920fb4SRafael J. Wysocki int cpu, error; 546e3920fb4SRafael J. Wysocki 547e3920fb4SRafael J. Wysocki /* Allow everyone to use the CPU hotplug again */ 548d221938cSGautham R Shenoy cpu_maps_update_begin(); 549e3920fb4SRafael J. Wysocki cpu_hotplug_disabled = 0; 550e0b582ecSRusty Russell if (cpumask_empty(frozen_cpus)) 5511d64b9cbSRafael J. Wysocki goto out; 552e3920fb4SRafael J. Wysocki 5534d51985eSMichael Rodriguez printk(KERN_INFO "Enabling non-boot CPUs ...\n"); 554d0af9eedSSuresh Siddha 555d0af9eedSSuresh Siddha arch_enable_nonboot_cpus_begin(); 556d0af9eedSSuresh Siddha 557e0b582ecSRusty Russell for_each_cpu(cpu, frozen_cpus) { 5588bb78442SRafael J. Wysocki error = _cpu_up(cpu, 1); 559e3920fb4SRafael J. Wysocki if (!error) { 5604d51985eSMichael Rodriguez printk(KERN_INFO "CPU%d is up\n", cpu); 561e3920fb4SRafael J. Wysocki continue; 562e3920fb4SRafael J. Wysocki } 5631d64b9cbSRafael J. Wysocki printk(KERN_WARNING "Error taking CPU%d up: %d\n", cpu, error); 564e3920fb4SRafael J. Wysocki } 565d0af9eedSSuresh Siddha 566d0af9eedSSuresh Siddha arch_enable_nonboot_cpus_end(); 567d0af9eedSSuresh Siddha 568e0b582ecSRusty Russell cpumask_clear(frozen_cpus); 5691d64b9cbSRafael J. Wysocki out: 570d221938cSGautham R Shenoy cpu_maps_update_done(); 571e3920fb4SRafael J. Wysocki } 572e0b582ecSRusty Russell 573d7268a31SFenghua Yu static int __init alloc_frozen_cpus(void) 574e0b582ecSRusty Russell { 575e0b582ecSRusty Russell if (!alloc_cpumask_var(&frozen_cpus, GFP_KERNEL|__GFP_ZERO)) 576e0b582ecSRusty Russell return -ENOMEM; 577e0b582ecSRusty Russell return 0; 578e0b582ecSRusty Russell } 579e0b582ecSRusty Russell core_initcall(alloc_frozen_cpus); 58079cfbdfaSSrivatsa S. Bhat 58179cfbdfaSSrivatsa S. Bhat /* 58279cfbdfaSSrivatsa S. Bhat * When callbacks for CPU hotplug notifications are being executed, we must 58379cfbdfaSSrivatsa S. Bhat * ensure that the state of the system with respect to the tasks being frozen 58479cfbdfaSSrivatsa S. Bhat * or not, as reported by the notification, remains unchanged *throughout the 58579cfbdfaSSrivatsa S. Bhat * duration* of the execution of the callbacks. 58679cfbdfaSSrivatsa S. Bhat * Hence we need to prevent the freezer from racing with regular CPU hotplug. 58779cfbdfaSSrivatsa S. Bhat * 58879cfbdfaSSrivatsa S. Bhat * This synchronization is implemented by mutually excluding regular CPU 58979cfbdfaSSrivatsa S. Bhat * hotplug and Suspend/Hibernate call paths by hooking onto the Suspend/ 59079cfbdfaSSrivatsa S. Bhat * Hibernate notifications. 59179cfbdfaSSrivatsa S. Bhat */ 59279cfbdfaSSrivatsa S. Bhat static int 59379cfbdfaSSrivatsa S. Bhat cpu_hotplug_pm_callback(struct notifier_block *nb, 59479cfbdfaSSrivatsa S. Bhat unsigned long action, void *ptr) 59579cfbdfaSSrivatsa S. Bhat { 59679cfbdfaSSrivatsa S. Bhat switch (action) { 59779cfbdfaSSrivatsa S. Bhat 59879cfbdfaSSrivatsa S. Bhat case PM_SUSPEND_PREPARE: 59979cfbdfaSSrivatsa S. Bhat case PM_HIBERNATION_PREPARE: 60016e53dbfSSrivatsa S. Bhat cpu_hotplug_disable(); 60179cfbdfaSSrivatsa S. Bhat break; 60279cfbdfaSSrivatsa S. Bhat 60379cfbdfaSSrivatsa S. Bhat case PM_POST_SUSPEND: 60479cfbdfaSSrivatsa S. Bhat case PM_POST_HIBERNATION: 60516e53dbfSSrivatsa S. Bhat cpu_hotplug_enable(); 60679cfbdfaSSrivatsa S. Bhat break; 60779cfbdfaSSrivatsa S. Bhat 60879cfbdfaSSrivatsa S. Bhat default: 60979cfbdfaSSrivatsa S. Bhat return NOTIFY_DONE; 61079cfbdfaSSrivatsa S. Bhat } 61179cfbdfaSSrivatsa S. Bhat 61279cfbdfaSSrivatsa S. Bhat return NOTIFY_OK; 61379cfbdfaSSrivatsa S. Bhat } 61479cfbdfaSSrivatsa S. Bhat 61579cfbdfaSSrivatsa S. Bhat 616d7268a31SFenghua Yu static int __init cpu_hotplug_pm_sync_init(void) 61779cfbdfaSSrivatsa S. Bhat { 6186e32d479SFenghua Yu /* 6196e32d479SFenghua Yu * cpu_hotplug_pm_callback has higher priority than x86 6206e32d479SFenghua Yu * bsp_pm_callback which depends on cpu_hotplug_pm_callback 6216e32d479SFenghua Yu * to disable cpu hotplug to avoid cpu hotplug race. 6226e32d479SFenghua Yu */ 62379cfbdfaSSrivatsa S. Bhat pm_notifier(cpu_hotplug_pm_callback, 0); 62479cfbdfaSSrivatsa S. Bhat return 0; 62579cfbdfaSSrivatsa S. Bhat } 62679cfbdfaSSrivatsa S. Bhat core_initcall(cpu_hotplug_pm_sync_init); 62779cfbdfaSSrivatsa S. Bhat 628f3de4be9SRafael J. Wysocki #endif /* CONFIG_PM_SLEEP_SMP */ 62968f4f1ecSMax Krasnyansky 630e545a614SManfred Spraul /** 631e545a614SManfred Spraul * notify_cpu_starting(cpu) - call the CPU_STARTING notifiers 632e545a614SManfred Spraul * @cpu: cpu that just started 633e545a614SManfred Spraul * 634e545a614SManfred Spraul * This function calls the cpu_chain notifiers with CPU_STARTING. 635e545a614SManfred Spraul * It must be called by the arch code on the new cpu, before the new cpu 636e545a614SManfred Spraul * enables interrupts and before the "boot" cpu returns from __cpu_up(). 637e545a614SManfred Spraul */ 6380db0628dSPaul Gortmaker void notify_cpu_starting(unsigned int cpu) 639e545a614SManfred Spraul { 640e545a614SManfred Spraul unsigned long val = CPU_STARTING; 641e545a614SManfred Spraul 642e545a614SManfred Spraul #ifdef CONFIG_PM_SLEEP_SMP 643e0b582ecSRusty Russell if (frozen_cpus != NULL && cpumask_test_cpu(cpu, frozen_cpus)) 644e545a614SManfred Spraul val = CPU_STARTING_FROZEN; 645e545a614SManfred Spraul #endif /* CONFIG_PM_SLEEP_SMP */ 646e9fb7631SAkinobu Mita cpu_notify(val, (void *)(long)cpu); 647e545a614SManfred Spraul } 648e545a614SManfred Spraul 64968f4f1ecSMax Krasnyansky #endif /* CONFIG_SMP */ 650b8d317d1SMike Travis 651e56b3bc7SLinus Torvalds /* 652e56b3bc7SLinus Torvalds * cpu_bit_bitmap[] is a special, "compressed" data structure that 653e56b3bc7SLinus Torvalds * represents all NR_CPUS bits binary values of 1<<nr. 654e56b3bc7SLinus Torvalds * 655e0b582ecSRusty Russell * It is used by cpumask_of() to get a constant address to a CPU 656e56b3bc7SLinus Torvalds * mask value that has a single bit set only. 657e56b3bc7SLinus Torvalds */ 658b8d317d1SMike Travis 659e56b3bc7SLinus Torvalds /* cpu_bit_bitmap[0] is empty - so we can back into it */ 6604d51985eSMichael Rodriguez #define MASK_DECLARE_1(x) [x+1][0] = (1UL << (x)) 661e56b3bc7SLinus Torvalds #define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1(x+1) 662e56b3bc7SLinus Torvalds #define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2(x+2) 663e56b3bc7SLinus Torvalds #define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4(x+4) 664b8d317d1SMike Travis 665e56b3bc7SLinus Torvalds const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = { 666b8d317d1SMike Travis 667e56b3bc7SLinus Torvalds MASK_DECLARE_8(0), MASK_DECLARE_8(8), 668e56b3bc7SLinus Torvalds MASK_DECLARE_8(16), MASK_DECLARE_8(24), 669e56b3bc7SLinus Torvalds #if BITS_PER_LONG > 32 670e56b3bc7SLinus Torvalds MASK_DECLARE_8(32), MASK_DECLARE_8(40), 671e56b3bc7SLinus Torvalds MASK_DECLARE_8(48), MASK_DECLARE_8(56), 672b8d317d1SMike Travis #endif 673b8d317d1SMike Travis }; 674e56b3bc7SLinus Torvalds EXPORT_SYMBOL_GPL(cpu_bit_bitmap); 6752d3854a3SRusty Russell 6762d3854a3SRusty Russell const DECLARE_BITMAP(cpu_all_bits, NR_CPUS) = CPU_BITS_ALL; 6772d3854a3SRusty Russell EXPORT_SYMBOL(cpu_all_bits); 678b3199c02SRusty Russell 679b3199c02SRusty Russell #ifdef CONFIG_INIT_ALL_POSSIBLE 680b3199c02SRusty Russell static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly 681b3199c02SRusty Russell = CPU_BITS_ALL; 682b3199c02SRusty Russell #else 683b3199c02SRusty Russell static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly; 684b3199c02SRusty Russell #endif 685b3199c02SRusty Russell const struct cpumask *const cpu_possible_mask = to_cpumask(cpu_possible_bits); 686b3199c02SRusty Russell EXPORT_SYMBOL(cpu_possible_mask); 687b3199c02SRusty Russell 688b3199c02SRusty Russell static DECLARE_BITMAP(cpu_online_bits, CONFIG_NR_CPUS) __read_mostly; 689b3199c02SRusty Russell const struct cpumask *const cpu_online_mask = to_cpumask(cpu_online_bits); 690b3199c02SRusty Russell EXPORT_SYMBOL(cpu_online_mask); 691b3199c02SRusty Russell 692b3199c02SRusty Russell static DECLARE_BITMAP(cpu_present_bits, CONFIG_NR_CPUS) __read_mostly; 693b3199c02SRusty Russell const struct cpumask *const cpu_present_mask = to_cpumask(cpu_present_bits); 694b3199c02SRusty Russell EXPORT_SYMBOL(cpu_present_mask); 695b3199c02SRusty Russell 696b3199c02SRusty Russell static DECLARE_BITMAP(cpu_active_bits, CONFIG_NR_CPUS) __read_mostly; 697b3199c02SRusty Russell const struct cpumask *const cpu_active_mask = to_cpumask(cpu_active_bits); 698b3199c02SRusty Russell EXPORT_SYMBOL(cpu_active_mask); 6993fa41520SRusty Russell 7003fa41520SRusty Russell void set_cpu_possible(unsigned int cpu, bool possible) 7013fa41520SRusty Russell { 7023fa41520SRusty Russell if (possible) 7033fa41520SRusty Russell cpumask_set_cpu(cpu, to_cpumask(cpu_possible_bits)); 7043fa41520SRusty Russell else 7053fa41520SRusty Russell cpumask_clear_cpu(cpu, to_cpumask(cpu_possible_bits)); 7063fa41520SRusty Russell } 7073fa41520SRusty Russell 7083fa41520SRusty Russell void set_cpu_present(unsigned int cpu, bool present) 7093fa41520SRusty Russell { 7103fa41520SRusty Russell if (present) 7113fa41520SRusty Russell cpumask_set_cpu(cpu, to_cpumask(cpu_present_bits)); 7123fa41520SRusty Russell else 7133fa41520SRusty Russell cpumask_clear_cpu(cpu, to_cpumask(cpu_present_bits)); 7143fa41520SRusty Russell } 7153fa41520SRusty Russell 7163fa41520SRusty Russell void set_cpu_online(unsigned int cpu, bool online) 7173fa41520SRusty Russell { 7183fa41520SRusty Russell if (online) 7193fa41520SRusty Russell cpumask_set_cpu(cpu, to_cpumask(cpu_online_bits)); 7203fa41520SRusty Russell else 7213fa41520SRusty Russell cpumask_clear_cpu(cpu, to_cpumask(cpu_online_bits)); 7223fa41520SRusty Russell } 7233fa41520SRusty Russell 7243fa41520SRusty Russell void set_cpu_active(unsigned int cpu, bool active) 7253fa41520SRusty Russell { 7263fa41520SRusty Russell if (active) 7273fa41520SRusty Russell cpumask_set_cpu(cpu, to_cpumask(cpu_active_bits)); 7283fa41520SRusty Russell else 7293fa41520SRusty Russell cpumask_clear_cpu(cpu, to_cpumask(cpu_active_bits)); 7303fa41520SRusty Russell } 7313fa41520SRusty Russell 7323fa41520SRusty Russell void init_cpu_present(const struct cpumask *src) 7333fa41520SRusty Russell { 7343fa41520SRusty Russell cpumask_copy(to_cpumask(cpu_present_bits), src); 7353fa41520SRusty Russell } 7363fa41520SRusty Russell 7373fa41520SRusty Russell void init_cpu_possible(const struct cpumask *src) 7383fa41520SRusty Russell { 7393fa41520SRusty Russell cpumask_copy(to_cpumask(cpu_possible_bits), src); 7403fa41520SRusty Russell } 7413fa41520SRusty Russell 7423fa41520SRusty Russell void init_cpu_online(const struct cpumask *src) 7433fa41520SRusty Russell { 7443fa41520SRusty Russell cpumask_copy(to_cpumask(cpu_online_bits), src); 7453fa41520SRusty Russell } 746