1 #include <linux/errno.h>
2 #include <linux/kernel.h>
5 #include <linux/slab.h>
6 #include <linux/sched.h>
7 #include <linux/module.h>
10 struct kmem_cache
*task_xstate_cachep
;
12 int arch_dup_task_struct(struct task_struct
*dst
, struct task_struct
*src
)
15 if (src
->thread
.xstate
) {
16 dst
->thread
.xstate
= kmem_cache_alloc(task_xstate_cachep
,
18 if (!dst
->thread
.xstate
)
20 WARN_ON((unsigned long)dst
->thread
.xstate
& 15);
21 memcpy(dst
->thread
.xstate
, src
->thread
.xstate
, xstate_size
);
26 void free_thread_xstate(struct task_struct
*tsk
)
28 if (tsk
->thread
.xstate
) {
29 kmem_cache_free(task_xstate_cachep
, tsk
->thread
.xstate
);
30 tsk
->thread
.xstate
= NULL
;
34 void free_thread_info(struct thread_info
*ti
)
36 free_thread_xstate(ti
->task
);
37 free_pages((unsigned long)ti
, get_order(THREAD_SIZE
));
40 void arch_task_cache_init(void)
43 kmem_cache_create("task_xstate", xstate_size
,
44 __alignof__(union thread_xstate
),
48 static void do_nothing(void *unused
)
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.
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.
60 void cpu_idle_wait(void)
63 /* kick all the CPUs so that they exit out of pm_idle */
64 smp_call_function(do_nothing
, NULL
, 0, 1);
66 EXPORT_SYMBOL_GPL(cpu_idle_wait
);
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).
75 * New with Core Duo processors, MWAIT can take some hints based on CPU
78 void mwait_idle_with_hints(unsigned long ax
, unsigned long cx
)
80 if (!need_resched()) {
81 __monitor((void *)¤t_thread_info()->flags
, 0, 0);
88 /* Default MONITOR/MWAIT with no hints, used for default C1 state */
89 static void mwait_idle(void)
91 if (!need_resched()) {
92 __monitor((void *)¤t_thread_info()->flags
, 0, 0);
103 static int __cpuinit
mwait_usable(const struct cpuinfo_x86
*c
)
107 /* Any C1 states supported? */
108 return c
->cpuid_level
>= 5 && ((cpuid_edx(5) >> 4) & 0xf) > 0;
112 * On SMP it's slightly faster (but much more power-consuming!)
113 * to poll the ->work.need_resched flag instead of waiting for the
114 * cross-CPU IPI to arrive. Use this option with caution.
116 static void poll_idle(void)
122 void __cpuinit
select_idle_routine(const struct cpuinfo_x86
*c
)
128 #ifdef CONFIG_X86_SMP
129 if (pm_idle
== poll_idle
&& smp_num_siblings
> 1) {
130 printk(KERN_WARNING
"WARNING: polling idle and HT enabled,"
131 " performance may degrade.\n");
134 if (cpu_has(c
, X86_FEATURE_MWAIT
) && mwait_usable(c
)) {
136 * Skip, if setup has overridden idle.
137 * One CPU supports mwait => All CPUs supports mwait
140 printk(KERN_INFO
"using mwait in idle threads.\n");
141 pm_idle
= mwait_idle
;
147 static int __init
idle_setup(char *str
)
149 if (!strcmp(str
, "poll")) {
150 printk("using polling idle threads.\n");
152 } else if (!strcmp(str
, "mwait"))
157 boot_option_idle_override
= 1;
160 early_param("idle", idle_setup
);