intel_idle.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /*
  2. * intel_idle.c - native hardware idle loop for modern Intel processors
  3. *
  4. * Copyright (c) 2010, Intel Corporation.
  5. * Len Brown <len.brown@intel.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. /*
  21. * intel_idle is a cpuidle driver that loads on specific Intel processors
  22. * in lieu of the legacy ACPI processor_idle driver. The intent is to
  23. * make Linux more efficient on these processors, as intel_idle knows
  24. * more than ACPI, as well as make Linux more immune to ACPI BIOS bugs.
  25. */
  26. /*
  27. * Design Assumptions
  28. *
  29. * All CPUs have same idle states as boot CPU
  30. *
  31. * Chipset BM_STS (bus master status) bit is a NOP
  32. * for preventing entry into deep C-stats
  33. */
  34. /*
  35. * Known limitations
  36. *
  37. * The driver currently initializes for_each_online_cpu() upon modprobe.
  38. * It it unaware of subsequent processors hot-added to the system.
  39. * This means that if you boot with maxcpus=n and later online
  40. * processors above n, those processors will use C1 only.
  41. *
  42. * ACPI has a .suspend hack to turn off deep c-statees during suspend
  43. * to avoid complications with the lapic timer workaround.
  44. * Have not seen issues with suspend, but may need same workaround here.
  45. *
  46. * There is currently no kernel-based automatic probing/loading mechanism
  47. * if the driver is built as a module.
  48. */
  49. /* un-comment DEBUG to enable pr_debug() statements */
  50. #define DEBUG
  51. #include <linux/kernel.h>
  52. #include <linux/cpuidle.h>
  53. #include <linux/clockchips.h>
  54. #include <trace/events/power.h>
  55. #include <linux/sched.h>
  56. #include <linux/notifier.h>
  57. #include <linux/cpu.h>
  58. #include <linux/module.h>
  59. #include <asm/cpu_device_id.h>
  60. #include <asm/mwait.h>
  61. #include <asm/msr.h>
  62. #define INTEL_IDLE_VERSION "0.4"
  63. #define PREFIX "intel_idle: "
  64. static struct cpuidle_driver intel_idle_driver = {
  65. .name = "intel_idle",
  66. .owner = THIS_MODULE,
  67. .en_core_tk_irqen = 1,
  68. };
  69. /* intel_idle.max_cstate=0 disables driver */
  70. static int max_cstate = MWAIT_MAX_NUM_CSTATES - 1;
  71. static unsigned int mwait_substates;
  72. #define LAPIC_TIMER_ALWAYS_RELIABLE 0xFFFFFFFF
  73. /* Reliable LAPIC Timer States, bit 1 for C1 etc. */
  74. static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */
  75. struct idle_cpu {
  76. struct cpuidle_state *state_table;
  77. /*
  78. * Hardware C-state auto-demotion may not always be optimal.
  79. * Indicate which enable bits to clear here.
  80. */
  81. unsigned long auto_demotion_disable_flags;
  82. };
  83. static const struct idle_cpu *icpu;
  84. static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
  85. static int intel_idle(struct cpuidle_device *dev,
  86. struct cpuidle_driver *drv, int index);
  87. static int intel_idle_cpu_init(int cpu);
  88. static struct cpuidle_state *cpuidle_state_table;
  89. /*
  90. * Set this flag for states where the HW flushes the TLB for us
  91. * and so we don't need cross-calls to keep it consistent.
  92. * If this flag is set, SW flushes the TLB, so even if the
  93. * HW doesn't do the flushing, this flag is safe to use.
  94. */
  95. #define CPUIDLE_FLAG_TLB_FLUSHED 0x10000
  96. /*
  97. * States are indexed by the cstate number,
  98. * which is also the index into the MWAIT hint array.
  99. * Thus C0 is a dummy.
  100. */
  101. static struct cpuidle_state nehalem_cstates[MWAIT_MAX_NUM_CSTATES] = {
  102. { /* MWAIT C0 */ },
  103. { /* MWAIT C1 */
  104. .name = "C1-NHM",
  105. .desc = "MWAIT 0x00",
  106. .flags = CPUIDLE_FLAG_TIME_VALID,
  107. .exit_latency = 3,
  108. .target_residency = 6,
  109. .enter = &intel_idle },
  110. { /* MWAIT C2 */
  111. .name = "C3-NHM",
  112. .desc = "MWAIT 0x10",
  113. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  114. .exit_latency = 20,
  115. .target_residency = 80,
  116. .enter = &intel_idle },
  117. { /* MWAIT C3 */
  118. .name = "C6-NHM",
  119. .desc = "MWAIT 0x20",
  120. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  121. .exit_latency = 200,
  122. .target_residency = 800,
  123. .enter = &intel_idle },
  124. };
  125. static struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] = {
  126. { /* MWAIT C0 */ },
  127. { /* MWAIT C1 */
  128. .name = "C1-SNB",
  129. .desc = "MWAIT 0x00",
  130. .flags = CPUIDLE_FLAG_TIME_VALID,
  131. .exit_latency = 1,
  132. .target_residency = 1,
  133. .enter = &intel_idle },
  134. { /* MWAIT C2 */
  135. .name = "C3-SNB",
  136. .desc = "MWAIT 0x10",
  137. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  138. .exit_latency = 80,
  139. .target_residency = 211,
  140. .enter = &intel_idle },
  141. { /* MWAIT C3 */
  142. .name = "C6-SNB",
  143. .desc = "MWAIT 0x20",
  144. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  145. .exit_latency = 104,
  146. .target_residency = 345,
  147. .enter = &intel_idle },
  148. { /* MWAIT C4 */
  149. .name = "C7-SNB",
  150. .desc = "MWAIT 0x30",
  151. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  152. .exit_latency = 109,
  153. .target_residency = 345,
  154. .enter = &intel_idle },
  155. };
  156. static struct cpuidle_state ivb_cstates[MWAIT_MAX_NUM_CSTATES] = {
  157. { /* MWAIT C0 */ },
  158. { /* MWAIT C1 */
  159. .name = "C1-IVB",
  160. .desc = "MWAIT 0x00",
  161. .flags = CPUIDLE_FLAG_TIME_VALID,
  162. .exit_latency = 1,
  163. .target_residency = 1,
  164. .enter = &intel_idle },
  165. { /* MWAIT C2 */
  166. .name = "C3-IVB",
  167. .desc = "MWAIT 0x10",
  168. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  169. .exit_latency = 59,
  170. .target_residency = 156,
  171. .enter = &intel_idle },
  172. { /* MWAIT C3 */
  173. .name = "C6-IVB",
  174. .desc = "MWAIT 0x20",
  175. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  176. .exit_latency = 80,
  177. .target_residency = 300,
  178. .enter = &intel_idle },
  179. { /* MWAIT C4 */
  180. .name = "C7-IVB",
  181. .desc = "MWAIT 0x30",
  182. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  183. .exit_latency = 87,
  184. .target_residency = 300,
  185. .enter = &intel_idle },
  186. };
  187. static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
  188. { /* MWAIT C0 */ },
  189. { /* MWAIT C1 */
  190. .name = "C1-ATM",
  191. .desc = "MWAIT 0x00",
  192. .flags = CPUIDLE_FLAG_TIME_VALID,
  193. .exit_latency = 1,
  194. .target_residency = 4,
  195. .enter = &intel_idle },
  196. { /* MWAIT C2 */
  197. .name = "C2-ATM",
  198. .desc = "MWAIT 0x10",
  199. .flags = CPUIDLE_FLAG_TIME_VALID,
  200. .exit_latency = 20,
  201. .target_residency = 80,
  202. .enter = &intel_idle },
  203. { /* MWAIT C3 */ },
  204. { /* MWAIT C4 */
  205. .name = "C4-ATM",
  206. .desc = "MWAIT 0x30",
  207. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  208. .exit_latency = 100,
  209. .target_residency = 400,
  210. .enter = &intel_idle },
  211. { /* MWAIT C5 */ },
  212. { /* MWAIT C6 */
  213. .name = "C6-ATM",
  214. .desc = "MWAIT 0x52",
  215. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  216. .exit_latency = 140,
  217. .target_residency = 560,
  218. .enter = &intel_idle },
  219. };
  220. static long get_driver_data(int cstate)
  221. {
  222. int driver_data;
  223. switch (cstate) {
  224. case 1: /* MWAIT C1 */
  225. driver_data = 0x00;
  226. break;
  227. case 2: /* MWAIT C2 */
  228. driver_data = 0x10;
  229. break;
  230. case 3: /* MWAIT C3 */
  231. driver_data = 0x20;
  232. break;
  233. case 4: /* MWAIT C4 */
  234. driver_data = 0x30;
  235. break;
  236. case 5: /* MWAIT C5 */
  237. driver_data = 0x40;
  238. break;
  239. case 6: /* MWAIT C6 */
  240. driver_data = 0x52;
  241. break;
  242. default:
  243. driver_data = 0x00;
  244. }
  245. return driver_data;
  246. }
  247. /**
  248. * intel_idle
  249. * @dev: cpuidle_device
  250. * @drv: cpuidle driver
  251. * @index: index of cpuidle state
  252. *
  253. * Must be called under local_irq_disable().
  254. */
  255. static int intel_idle(struct cpuidle_device *dev,
  256. struct cpuidle_driver *drv, int index)
  257. {
  258. unsigned long ecx = 1; /* break on interrupt flag */
  259. struct cpuidle_state *state = &drv->states[index];
  260. struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
  261. unsigned long eax = (unsigned long)cpuidle_get_statedata(state_usage);
  262. unsigned int cstate;
  263. int cpu = smp_processor_id();
  264. cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK) + 1;
  265. /*
  266. * leave_mm() to avoid costly and often unnecessary wakeups
  267. * for flushing the user TLB's associated with the active mm.
  268. */
  269. if (state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
  270. leave_mm(cpu);
  271. if (!(lapic_timer_reliable_states & (1 << (cstate))))
  272. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
  273. stop_critical_timings();
  274. if (!need_resched()) {
  275. __monitor((void *)&current_thread_info()->flags, 0, 0);
  276. smp_mb();
  277. if (!need_resched())
  278. __mwait(eax, ecx);
  279. }
  280. start_critical_timings();
  281. if (!(lapic_timer_reliable_states & (1 << (cstate))))
  282. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
  283. return index;
  284. }
  285. static void __setup_broadcast_timer(void *arg)
  286. {
  287. unsigned long reason = (unsigned long)arg;
  288. int cpu = smp_processor_id();
  289. reason = reason ?
  290. CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
  291. clockevents_notify(reason, &cpu);
  292. }
  293. static int cpu_hotplug_notify(struct notifier_block *n,
  294. unsigned long action, void *hcpu)
  295. {
  296. int hotcpu = (unsigned long)hcpu;
  297. struct cpuidle_device *dev;
  298. switch (action & 0xf) {
  299. case CPU_ONLINE:
  300. if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
  301. smp_call_function_single(hotcpu, __setup_broadcast_timer,
  302. (void *)true, 1);
  303. /*
  304. * Some systems can hotplug a cpu at runtime after
  305. * the kernel has booted, we have to initialize the
  306. * driver in this case
  307. */
  308. dev = per_cpu_ptr(intel_idle_cpuidle_devices, hotcpu);
  309. if (!dev->registered)
  310. intel_idle_cpu_init(hotcpu);
  311. break;
  312. }
  313. return NOTIFY_OK;
  314. }
  315. static struct notifier_block cpu_hotplug_notifier = {
  316. .notifier_call = cpu_hotplug_notify,
  317. };
  318. static void auto_demotion_disable(void *dummy)
  319. {
  320. unsigned long long msr_bits;
  321. rdmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
  322. msr_bits &= ~(icpu->auto_demotion_disable_flags);
  323. wrmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
  324. }
  325. static const struct idle_cpu idle_cpu_nehalem = {
  326. .state_table = nehalem_cstates,
  327. .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
  328. };
  329. static const struct idle_cpu idle_cpu_atom = {
  330. .state_table = atom_cstates,
  331. };
  332. static const struct idle_cpu idle_cpu_lincroft = {
  333. .state_table = atom_cstates,
  334. .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
  335. };
  336. static const struct idle_cpu idle_cpu_snb = {
  337. .state_table = snb_cstates,
  338. };
  339. static const struct idle_cpu idle_cpu_ivb = {
  340. .state_table = ivb_cstates,
  341. };
  342. #define ICPU(model, cpu) \
  343. { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, (unsigned long)&cpu }
  344. static const struct x86_cpu_id intel_idle_ids[] = {
  345. ICPU(0x1a, idle_cpu_nehalem),
  346. ICPU(0x1e, idle_cpu_nehalem),
  347. ICPU(0x1f, idle_cpu_nehalem),
  348. ICPU(0x25, idle_cpu_nehalem),
  349. ICPU(0x2c, idle_cpu_nehalem),
  350. ICPU(0x2e, idle_cpu_nehalem),
  351. ICPU(0x1c, idle_cpu_atom),
  352. ICPU(0x26, idle_cpu_lincroft),
  353. ICPU(0x2f, idle_cpu_nehalem),
  354. ICPU(0x2a, idle_cpu_snb),
  355. ICPU(0x2d, idle_cpu_snb),
  356. ICPU(0x3a, idle_cpu_ivb),
  357. ICPU(0x3e, idle_cpu_ivb),
  358. {}
  359. };
  360. MODULE_DEVICE_TABLE(x86cpu, intel_idle_ids);
  361. /*
  362. * intel_idle_probe()
  363. */
  364. static int intel_idle_probe(void)
  365. {
  366. unsigned int eax, ebx, ecx;
  367. const struct x86_cpu_id *id;
  368. if (max_cstate == 0) {
  369. pr_debug(PREFIX "disabled\n");
  370. return -EPERM;
  371. }
  372. id = x86_match_cpu(intel_idle_ids);
  373. if (!id) {
  374. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
  375. boot_cpu_data.x86 == 6)
  376. pr_debug(PREFIX "does not run on family %d model %d\n",
  377. boot_cpu_data.x86, boot_cpu_data.x86_model);
  378. return -ENODEV;
  379. }
  380. if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
  381. return -ENODEV;
  382. cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
  383. if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
  384. !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
  385. !mwait_substates)
  386. return -ENODEV;
  387. pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates);
  388. icpu = (const struct idle_cpu *)id->driver_data;
  389. cpuidle_state_table = icpu->state_table;
  390. if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
  391. lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
  392. else
  393. on_each_cpu(__setup_broadcast_timer, (void *)true, 1);
  394. register_cpu_notifier(&cpu_hotplug_notifier);
  395. pr_debug(PREFIX "v" INTEL_IDLE_VERSION
  396. " model 0x%X\n", boot_cpu_data.x86_model);
  397. pr_debug(PREFIX "lapic_timer_reliable_states 0x%x\n",
  398. lapic_timer_reliable_states);
  399. return 0;
  400. }
  401. /*
  402. * intel_idle_cpuidle_devices_uninit()
  403. * unregister, free cpuidle_devices
  404. */
  405. static void intel_idle_cpuidle_devices_uninit(void)
  406. {
  407. int i;
  408. struct cpuidle_device *dev;
  409. for_each_online_cpu(i) {
  410. dev = per_cpu_ptr(intel_idle_cpuidle_devices, i);
  411. cpuidle_unregister_device(dev);
  412. }
  413. free_percpu(intel_idle_cpuidle_devices);
  414. return;
  415. }
  416. /*
  417. * intel_idle_cpuidle_driver_init()
  418. * allocate, initialize cpuidle_states
  419. */
  420. static int intel_idle_cpuidle_driver_init(void)
  421. {
  422. int cstate;
  423. struct cpuidle_driver *drv = &intel_idle_driver;
  424. drv->state_count = 1;
  425. for (cstate = 1; cstate < MWAIT_MAX_NUM_CSTATES; ++cstate) {
  426. int num_substates;
  427. if (cstate > max_cstate) {
  428. printk(PREFIX "max_cstate %d reached\n",
  429. max_cstate);
  430. break;
  431. }
  432. /* does the state exist in CPUID.MWAIT? */
  433. num_substates = (mwait_substates >> ((cstate) * 4))
  434. & MWAIT_SUBSTATE_MASK;
  435. if (num_substates == 0)
  436. continue;
  437. /* is the state not enabled? */
  438. if (cpuidle_state_table[cstate].enter == NULL) {
  439. /* does the driver not know about the state? */
  440. if (*cpuidle_state_table[cstate].name == '\0')
  441. pr_debug(PREFIX "unaware of model 0x%x"
  442. " MWAIT %d please"
  443. " contact lenb@kernel.org",
  444. boot_cpu_data.x86_model, cstate);
  445. continue;
  446. }
  447. if ((cstate > 2) &&
  448. !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
  449. mark_tsc_unstable("TSC halts in idle"
  450. " states deeper than C2");
  451. drv->states[drv->state_count] = /* structure copy */
  452. cpuidle_state_table[cstate];
  453. drv->state_count += 1;
  454. }
  455. if (icpu->auto_demotion_disable_flags)
  456. on_each_cpu(auto_demotion_disable, NULL, 1);
  457. return 0;
  458. }
  459. /*
  460. * intel_idle_cpu_init()
  461. * allocate, initialize, register cpuidle_devices
  462. * @cpu: cpu/core to initialize
  463. */
  464. static int intel_idle_cpu_init(int cpu)
  465. {
  466. int cstate;
  467. struct cpuidle_device *dev;
  468. dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
  469. dev->state_count = 1;
  470. for (cstate = 1; cstate < MWAIT_MAX_NUM_CSTATES; ++cstate) {
  471. int num_substates;
  472. if (cstate > max_cstate) {
  473. printk(PREFIX "max_cstate %d reached\n", max_cstate);
  474. break;
  475. }
  476. /* does the state exist in CPUID.MWAIT? */
  477. num_substates = (mwait_substates >> ((cstate) * 4))
  478. & MWAIT_SUBSTATE_MASK;
  479. if (num_substates == 0)
  480. continue;
  481. /* is the state not enabled? */
  482. if (cpuidle_state_table[cstate].enter == NULL)
  483. continue;
  484. dev->states_usage[dev->state_count].driver_data =
  485. (void *)get_driver_data(cstate);
  486. dev->state_count += 1;
  487. }
  488. dev->cpu = cpu;
  489. if (cpuidle_register_device(dev)) {
  490. pr_debug(PREFIX "cpuidle_register_device %d failed!\n", cpu);
  491. intel_idle_cpuidle_devices_uninit();
  492. return -EIO;
  493. }
  494. if (icpu->auto_demotion_disable_flags)
  495. smp_call_function_single(cpu, auto_demotion_disable, NULL, 1);
  496. return 0;
  497. }
  498. static int __init intel_idle_init(void)
  499. {
  500. int retval, i;
  501. /* Do not load intel_idle at all for now if idle= is passed */
  502. if (boot_option_idle_override != IDLE_NO_OVERRIDE)
  503. return -ENODEV;
  504. retval = intel_idle_probe();
  505. if (retval)
  506. return retval;
  507. intel_idle_cpuidle_driver_init();
  508. retval = cpuidle_register_driver(&intel_idle_driver);
  509. if (retval) {
  510. struct cpuidle_driver *drv = cpuidle_get_driver();
  511. printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
  512. drv ? drv->name : "none");
  513. return retval;
  514. }
  515. intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
  516. if (intel_idle_cpuidle_devices == NULL)
  517. return -ENOMEM;
  518. for_each_online_cpu(i) {
  519. retval = intel_idle_cpu_init(i);
  520. if (retval) {
  521. cpuidle_unregister_driver(&intel_idle_driver);
  522. return retval;
  523. }
  524. }
  525. if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
  526. register_cpu_notifier(&setup_broadcast_notifier);
  527. return 0;
  528. }
  529. static void __exit intel_idle_exit(void)
  530. {
  531. intel_idle_cpuidle_devices_uninit();
  532. cpuidle_unregister_driver(&intel_idle_driver);
  533. if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
  534. on_each_cpu(__setup_broadcast_timer, (void *)false, 1);
  535. unregister_cpu_notifier(&cpu_hotplug_notifier);
  536. return;
  537. }
  538. module_init(intel_idle_init);
  539. module_exit(intel_idle_exit);
  540. module_param(max_cstate, int, 0444);
  541. MODULE_AUTHOR("Len Brown <len.brown@intel.com>");
  542. MODULE_DESCRIPTION("Cpuidle driver for Intel Hardware v" INTEL_IDLE_VERSION);
  543. MODULE_LICENSE("GPL");