56 #include <linux/kernel.h>
59 #include <linux/hrtimer.h>
61 #include <linux/sched.h>
64 #include <linux/module.h>
69 #define INTEL_IDLE_VERSION "0.4"
70 #define PREFIX "intel_idle: "
79 static unsigned int mwait_substates;
81 #define LAPIC_TIMER_ALWAYS_RELIABLE 0xFFFFFFFF
83 static unsigned int lapic_timer_reliable_states = (1 << 1);
99 static int intel_idle_cpu_init(
int cpu);
109 #define CPUIDLE_FLAG_TLB_FLUSHED 0x10000
120 .desc =
"MWAIT 0x00",
123 .target_residency = 6,
124 .enter = &intel_idle },
127 .desc =
"MWAIT 0x10",
130 .target_residency = 80,
131 .enter = &intel_idle },
134 .desc =
"MWAIT 0x20",
137 .target_residency = 800,
138 .enter = &intel_idle },
145 .desc =
"MWAIT 0x00",
148 .target_residency = 1,
149 .enter = &intel_idle },
152 .desc =
"MWAIT 0x10",
155 .target_residency = 211,
156 .enter = &intel_idle },
159 .desc =
"MWAIT 0x20",
162 .target_residency = 345,
163 .enter = &intel_idle },
166 .desc =
"MWAIT 0x30",
169 .target_residency = 345,
170 .enter = &intel_idle },
177 .desc =
"MWAIT 0x00",
180 .target_residency = 1,
181 .enter = &intel_idle },
184 .desc =
"MWAIT 0x10",
187 .target_residency = 156,
188 .enter = &intel_idle },
191 .desc =
"MWAIT 0x20",
194 .target_residency = 300,
195 .enter = &intel_idle },
198 .desc =
"MWAIT 0x30",
201 .target_residency = 300,
202 .enter = &intel_idle },
209 .desc =
"MWAIT 0x00",
212 .target_residency = 4,
213 .enter = &intel_idle },
216 .desc =
"MWAIT 0x10",
219 .target_residency = 80,
220 .enter = &intel_idle },
224 .desc =
"MWAIT 0x30",
227 .target_residency = 400,
228 .enter = &intel_idle },
232 .desc =
"MWAIT 0x52",
235 .target_residency = 560,
236 .enter = &intel_idle },
239 static long get_driver_data(
int cstate)
279 unsigned long ecx = 1;
282 unsigned long eax = (
unsigned long)cpuidle_get_statedata(state_usage);
297 if (!(lapic_timer_reliable_states & (1 << (cstate))))
303 if (!need_resched()) {
314 usec_delta = ktime_to_us(ktime_sub(kt_after, kt_before));
318 if (!(lapic_timer_reliable_states & (1 << (cstate))))
327 static void __setup_broadcast_timer(
void *
arg)
333 CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
339 unsigned long action,
void *hcpu)
341 int hotcpu = (
unsigned long)hcpu;
344 switch (action & 0xf) {
356 dev =
per_cpu_ptr(intel_idle_cpuidle_devices, hotcpu);
358 intel_idle_cpu_init(hotcpu);
366 .notifier_call = cpu_hotplug_notify,
369 static void auto_demotion_disable(
void *
dummy)
371 unsigned long long msr_bits;
378 static const struct idle_cpu idle_cpu_nehalem = {
379 .state_table = nehalem_cstates,
383 static const struct idle_cpu idle_cpu_atom = {
384 .state_table = atom_cstates,
387 static const struct idle_cpu idle_cpu_lincroft = {
388 .state_table = atom_cstates,
392 static const struct idle_cpu idle_cpu_snb = {
393 .state_table = snb_cstates,
396 static const struct idle_cpu idle_cpu_ivb = {
397 .state_table = ivb_cstates,
400 #define ICPU(model, cpu) \
401 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, (unsigned long)&cpu }
403 static const struct x86_cpu_id intel_idle_ids[] = {
404 ICPU(0x1a, idle_cpu_nehalem),
405 ICPU(0x1e, idle_cpu_nehalem),
406 ICPU(0x1f, idle_cpu_nehalem),
407 ICPU(0x25, idle_cpu_nehalem),
408 ICPU(0x2c, idle_cpu_nehalem),
409 ICPU(0x2e, idle_cpu_nehalem),
410 ICPU(0x1c, idle_cpu_atom),
411 ICPU(0x26, idle_cpu_lincroft),
412 ICPU(0x2f, idle_cpu_nehalem),
413 ICPU(0x2a, idle_cpu_snb),
414 ICPU(0x2d, idle_cpu_snb),
415 ICPU(0x3a, idle_cpu_ivb),
416 ICPU(0x3e, idle_cpu_ivb),
424 static int intel_idle_probe(
void)
426 unsigned int eax,
ebx,
ecx;
429 if (max_cstate == 0) {
461 on_each_cpu(__setup_broadcast_timer, (
void *)
true, 1);
463 register_cpu_notifier(&cpu_hotplug_notifier);
469 lapic_timer_reliable_states);
477 static void intel_idle_cpuidle_devices_uninit(
void)
494 static int intel_idle_cpuidle_driver_init(
void)
504 if (cstate > max_cstate) {
511 num_substates = (mwait_substates >> ((cstate) * 4))
513 if (num_substates == 0)
516 if (cpuidle_state_table[cstate].
enter ==
NULL) {
518 if (*cpuidle_state_table[cstate].
name ==
'\0')
529 " states deeper than C2");
532 cpuidle_state_table[cstate];
549 static int intel_idle_cpu_init(
int cpu)
554 dev =
per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
561 if (cstate > max_cstate) {
567 num_substates = (mwait_substates >> ((cstate) * 4))
569 if (num_substates == 0)
572 if (cpuidle_state_table[cstate].
enter ==
NULL)
576 (
void *)get_driver_data(cstate);
585 intel_idle_cpuidle_devices_uninit();
595 static int __init intel_idle_init(
void)
603 retval = intel_idle_probe();
607 intel_idle_cpuidle_driver_init();
612 drv ? drv->
name :
"none");
617 if (intel_idle_cpuidle_devices ==
NULL)
621 retval = intel_idle_cpu_init(i);
631 static void __exit intel_idle_exit(
void)
633 intel_idle_cpuidle_devices_uninit();
638 on_each_cpu(__setup_broadcast_timer, (
void *)
false, 1);
639 unregister_cpu_notifier(&cpu_hotplug_notifier);