x86: fix crash on cpu hotplug on pat-incapable machines
[linux-2.6-block.git] / arch / x86 / kernel / process.c
CommitLineData
61c4628b
SS
1#include <linux/errno.h>
2#include <linux/kernel.h>
3#include <linux/mm.h>
4#include <linux/smp.h>
5#include <linux/slab.h>
6#include <linux/sched.h>
7f424a8b
PZ
7#include <linux/module.h>
8#include <linux/pm.h>
61c4628b 9
aa283f49 10struct kmem_cache *task_xstate_cachep;
61c4628b
SS
11
12int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
13{
14 *dst = *src;
aa283f49
SS
15 if (src->thread.xstate) {
16 dst->thread.xstate = kmem_cache_alloc(task_xstate_cachep,
17 GFP_KERNEL);
18 if (!dst->thread.xstate)
19 return -ENOMEM;
20 WARN_ON((unsigned long)dst->thread.xstate & 15);
21 memcpy(dst->thread.xstate, src->thread.xstate, xstate_size);
22 }
61c4628b
SS
23 return 0;
24}
25
aa283f49 26void free_thread_xstate(struct task_struct *tsk)
61c4628b 27{
aa283f49
SS
28 if (tsk->thread.xstate) {
29 kmem_cache_free(task_xstate_cachep, tsk->thread.xstate);
30 tsk->thread.xstate = NULL;
31 }
32}
33
aa283f49
SS
34void free_thread_info(struct thread_info *ti)
35{
36 free_thread_xstate(ti->task);
1679f271 37 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
61c4628b
SS
38}
39
40void arch_task_cache_init(void)
41{
42 task_xstate_cachep =
43 kmem_cache_create("task_xstate", xstate_size,
44 __alignof__(union thread_xstate),
45 SLAB_PANIC, NULL);
46}
7f424a8b
PZ
47
48static void do_nothing(void *unused)
49{
50}
51
52/*
53 * cpu_idle_wait - Used to ensure that all the CPUs discard old value of
54 * pm_idle and update to new pm_idle value. Required while changing pm_idle
55 * handler on SMP systems.
56 *
57 * Caller must have changed pm_idle to the new value before the call. Old
58 * pm_idle value will not be used by any CPU after the return of this function.
59 */
60void cpu_idle_wait(void)
61{
62 smp_mb();
63 /* kick all the CPUs so that they exit out of pm_idle */
64 smp_call_function(do_nothing, NULL, 0, 1);
65}
66EXPORT_SYMBOL_GPL(cpu_idle_wait);
67
68/*
69 * This uses new MONITOR/MWAIT instructions on P4 processors with PNI,
70 * which can obviate IPI to trigger checking of need_resched.
71 * We execute MONITOR against need_resched and enter optimized wait state
72 * through MWAIT. Whenever someone changes need_resched, we would be woken
73 * up from MWAIT (without an IPI).
74 *
75 * New with Core Duo processors, MWAIT can take some hints based on CPU
76 * capability.
77 */
78void mwait_idle_with_hints(unsigned long ax, unsigned long cx)
79{
80 if (!need_resched()) {
81 __monitor((void *)&current_thread_info()->flags, 0, 0);
82 smp_mb();
83 if (!need_resched())
84 __mwait(ax, cx);
85 }
86}
87
88/* Default MONITOR/MWAIT with no hints, used for default C1 state */
89static void mwait_idle(void)
90{
91 if (!need_resched()) {
92 __monitor((void *)&current_thread_info()->flags, 0, 0);
93 smp_mb();
94 if (!need_resched())
95 __sti_mwait(0, 0);
96 else
97 local_irq_enable();
98 } else
99 local_irq_enable();
100}
101
7f424a8b
PZ
102/*
103 * On SMP it's slightly faster (but much more power-consuming!)
104 * to poll the ->work.need_resched flag instead of waiting for the
105 * cross-CPU IPI to arrive. Use this option with caution.
106 */
107static void poll_idle(void)
108{
109 local_irq_enable();
110 cpu_relax();
111}
112
113void __cpuinit select_idle_routine(const struct cpuinfo_x86 *c)
114{
115 static int selected;
116
117 if (selected)
118 return;
119#ifdef CONFIG_X86_SMP
120 if (pm_idle == poll_idle && smp_num_siblings > 1) {
121 printk(KERN_WARNING "WARNING: polling idle and HT enabled,"
122 " performance may degrade.\n");
123 }
124#endif
a738d897 125 if (cpu_has(c, X86_FEATURE_MWAIT)) {
7f424a8b
PZ
126 /*
127 * Skip, if setup has overridden idle.
128 * One CPU supports mwait => All CPUs supports mwait
129 */
130 if (!pm_idle) {
131 printk(KERN_INFO "using mwait in idle threads.\n");
132 pm_idle = mwait_idle;
133 }
134 }
135 selected = 1;
136}
137
138static int __init idle_setup(char *str)
139{
140 if (!strcmp(str, "poll")) {
141 printk("using polling idle threads.\n");
142 pm_idle = poll_idle;
143 } else if (!strcmp(str, "mwait"))
144 force_mwait = 1;
145 else
146 return -1;
147
148 boot_option_idle_override = 1;
149 return 0;
150}
151early_param("idle", idle_setup);
152