intel_idle.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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 <linux/hrtimer.h> /* ktime_get_real() */
  55. #include <trace/events/power.h>
  56. #include <linux/sched.h>
  57. #include <linux/notifier.h>
  58. #include <linux/cpu.h>
  59. #include <linux/module.h>
  60. #include <asm/cpu_device_id.h>
  61. #include <asm/mwait.h>
  62. #include <asm/msr.h>
  63. #define INTEL_IDLE_VERSION "0.4"
  64. #define PREFIX "intel_idle: "
  65. static struct cpuidle_driver intel_idle_driver = {
  66. .name = "intel_idle",
  67. .owner = THIS_MODULE,
  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 struct cpuidle_state *cpuidle_state_table;
  88. /*
  89. * Set this flag for states where the HW flushes the TLB for us
  90. * and so we don't need cross-calls to keep it consistent.
  91. * If this flag is set, SW flushes the TLB, so even if the
  92. * HW doesn't do the flushing, this flag is safe to use.
  93. */
  94. #define CPUIDLE_FLAG_TLB_FLUSHED 0x10000
  95. /*
  96. * States are indexed by the cstate number,
  97. * which is also the index into the MWAIT hint array.
  98. * Thus C0 is a dummy.
  99. */
  100. static struct cpuidle_state nehalem_cstates[MWAIT_MAX_NUM_CSTATES] = {
  101. { /* MWAIT C0 */ },
  102. { /* MWAIT C1 */
  103. .name = "C1-NHM",
  104. .desc = "MWAIT 0x00",
  105. .flags = CPUIDLE_FLAG_TIME_VALID,
  106. .exit_latency = 3,
  107. .target_residency = 6,
  108. .enter = &intel_idle },
  109. { /* MWAIT C2 */
  110. .name = "C3-NHM",
  111. .desc = "MWAIT 0x10",
  112. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  113. .exit_latency = 20,
  114. .target_residency = 80,
  115. .enter = &intel_idle },
  116. { /* MWAIT C3 */
  117. .name = "C6-NHM",
  118. .desc = "MWAIT 0x20",
  119. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  120. .exit_latency = 200,
  121. .target_residency = 800,
  122. .enter = &intel_idle },
  123. };
  124. static struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] = {
  125. { /* MWAIT C0 */ },
  126. { /* MWAIT C1 */
  127. .name = "C1-SNB",
  128. .desc = "MWAIT 0x00",
  129. .flags = CPUIDLE_FLAG_TIME_VALID,
  130. .exit_latency = 1,
  131. .target_residency = 1,
  132. .enter = &intel_idle },
  133. { /* MWAIT C2 */
  134. .name = "C3-SNB",
  135. .desc = "MWAIT 0x10",
  136. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  137. .exit_latency = 80,
  138. .target_residency = 211,
  139. .enter = &intel_idle },
  140. { /* MWAIT C3 */
  141. .name = "C6-SNB",
  142. .desc = "MWAIT 0x20",
  143. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  144. .exit_latency = 104,
  145. .target_residency = 345,
  146. .enter = &intel_idle },
  147. { /* MWAIT C4 */
  148. .name = "C7-SNB",
  149. .desc = "MWAIT 0x30",
  150. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  151. .exit_latency = 109,
  152. .target_residency = 345,
  153. .enter = &intel_idle },
  154. };
  155. static struct cpuidle_state ivb_cstates[MWAIT_MAX_NUM_CSTATES] = {
  156. { /* MWAIT C0 */ },
  157. { /* MWAIT C1 */
  158. .name = "C1-IVB",
  159. .desc = "MWAIT 0x00",
  160. .flags = CPUIDLE_FLAG_TIME_VALID,
  161. .exit_latency = 1,
  162. .target_residency = 1,
  163. .enter = &intel_idle },
  164. { /* MWAIT C2 */
  165. .name = "C3-IVB",
  166. .desc = "MWAIT 0x10",
  167. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  168. .exit_latency = 59,
  169. .target_residency = 156,
  170. .enter = &intel_idle },
  171. { /* MWAIT C3 */
  172. .name = "C6-IVB",
  173. .desc = "MWAIT 0x20",
  174. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  175. .exit_latency = 80,
  176. .target_residency = 300,
  177. .enter = &intel_idle },
  178. { /* MWAIT C4 */
  179. .name = "C7-IVB",
  180. .desc = "MWAIT 0x30",
  181. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  182. .exit_latency = 87,
  183. .target_residency = 300,
  184. .enter = &intel_idle },
  185. };
  186. static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
  187. { /* MWAIT C0 */ },
  188. { /* MWAIT C1 */
  189. .name = "C1-ATM",
  190. .desc = "MWAIT 0x00",
  191. .flags = CPUIDLE_FLAG_TIME_VALID,
  192. .exit_latency = 1,
  193. .target_residency = 4,
  194. .enter = &intel_idle },
  195. { /* MWAIT C2 */
  196. .name = "C2-ATM",
  197. .desc = "MWAIT 0x10",
  198. .flags = CPUIDLE_FLAG_TIME_VALID,
  199. .exit_latency = 20,
  200. .target_residency = 80,
  201. .enter = &intel_idle },
  202. { /* MWAIT C3 */ },
  203. { /* MWAIT C4 */
  204. .name = "C4-ATM",
  205. .desc = "MWAIT 0x30",
  206. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  207. .exit_latency = 100,
  208. .target_residency = 400,
  209. .enter = &intel_idle },
  210. { /* MWAIT C5 */ },
  211. { /* MWAIT C6 */
  212. .name = "C6-ATM",
  213. .desc = "MWAIT 0x52",
  214. .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
  215. .exit_latency = 140,
  216. .target_residency = 560,
  217. .enter = &intel_idle },
  218. };
  219. static long get_driver_data(int cstate)
  220. {
  221. int driver_data;
  222. switch (cstate) {
  223. case 1: /* MWAIT C1 */
  224. driver_data = 0x00;
  225. break;
  226. case 2: /* MWAIT C2 */
  227. driver_data = 0x10;
  228. break;
  229. case 3: /* MWAIT C3 */
  230. driver_data = 0x20;
  231. break;
  232. case 4: /* MWAIT C4 */
  233. driver_data = 0x30;
  234. break;
  235. case 5: /* MWAIT C5 */
  236. driver_data = 0x40;
  237. break;
  238. case 6: /* MWAIT C6 */
  239. driver_data = 0x52;
  240. break;
  241. default:
  242. driver_data = 0x00;
  243. }
  244. return driver_data;
  245. }
  246. /**
  247. * intel_idle
  248. * @dev: cpuidle_device
  249. * @drv: cpuidle driver
  250. * @index: index of cpuidle state
  251. *
  252. * Must be called under local_irq_disable().
  253. */
  254. static int intel_idle(struct cpuidle_device *dev,
  255. struct cpuidle_driver *drv, int index)
  256. {
  257. unsigned long ecx = 1; /* break on interrupt flag */
  258. struct cpuidle_state *state = &drv->states[index];
  259. struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
  260. unsigned long eax = (unsigned long)cpuidle_get_statedata(state_usage);
  261. unsigned int cstate;
  262. ktime_t kt_before, kt_after;
  263. s64 usec_delta;
  264. int cpu = smp_processor_id();
  265. cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK) + 1;
  266. /*
  267. * leave_mm() to avoid costly and often unnecessary wakeups
  268. * for flushing the user TLB's associated with the active mm.
  269. */
  270. if (state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
  271. leave_mm(cpu);
  272. if (!(lapic_timer_reliable_states & (1 << (cstate))))
  273. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
  274. kt_before = ktime_get_real();
  275. stop_critical_timings();
  276. if (!need_resched()) {
  277. __monitor((void *)&current_thread_info()->flags, 0, 0);
  278. smp_mb();
  279. if (!need_resched())
  280. __mwait(eax, ecx);
  281. }
  282. start_critical_timings();
  283. kt_after = ktime_get_real();
  284. usec_delta = ktime_to_us(ktime_sub(kt_after, kt_before));
  285. local_irq_enable();
  286. if (!(lapic_timer_reliable_states & (1 << (cstate))))
  287. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
  288. /* Update cpuidle counters */
  289. dev->last_residency = (int)usec_delta;
  290. return index;
  291. }
  292. static void __setup_broadcast_timer(void *arg)
  293. {
  294. unsigned long reason = (unsigned long)arg;
  295. int cpu = smp_processor_id();
  296. reason = reason ?
  297. CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
  298. clockevents_notify(reason, &cpu);
  299. }
  300. static int setup_broadcast_cpuhp_notify(struct notifier_block *n,
  301. unsigned long action, void *hcpu)
  302. {
  303. int hotcpu = (unsigned long)hcpu;
  304. switch (action & 0xf) {
  305. case CPU_ONLINE:
  306. smp_call_function_single(hotcpu, __setup_broadcast_timer,
  307. (void *)true, 1);
  308. break;
  309. }
  310. return NOTIFY_OK;
  311. }
  312. static struct notifier_block setup_broadcast_notifier = {
  313. .notifier_call = setup_broadcast_cpuhp_notify,
  314. };
  315. static void auto_demotion_disable(void *dummy)
  316. {
  317. unsigned long long msr_bits;
  318. rdmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
  319. msr_bits &= ~(icpu->auto_demotion_disable_flags);
  320. wrmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
  321. }
  322. static const struct idle_cpu idle_cpu_nehalem = {
  323. .state_table = nehalem_cstates,
  324. .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
  325. };
  326. static const struct idle_cpu idle_cpu_atom = {
  327. .state_table = atom_cstates,
  328. };
  329. static const struct idle_cpu idle_cpu_lincroft = {
  330. .state_table = atom_cstates,
  331. .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
  332. };
  333. static const struct idle_cpu idle_cpu_snb = {
  334. .state_table = snb_cstates,
  335. };
  336. static const struct idle_cpu idle_cpu_ivb = {
  337. .state_table = ivb_cstates,
  338. };
  339. #define ICPU(model, cpu) \
  340. { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, (unsigned long)&cpu }
  341. static const struct x86_cpu_id intel_idle_ids[] = {
  342. ICPU(0x1a, idle_cpu_nehalem),
  343. ICPU(0x1e, idle_cpu_nehalem),
  344. ICPU(0x1f, idle_cpu_nehalem),
  345. ICPU(0x25, idle_cpu_nehalem),
  346. ICPU(0x2c, idle_cpu_nehalem),
  347. ICPU(0x2e, idle_cpu_nehalem),
  348. ICPU(0x1c, idle_cpu_atom),
  349. ICPU(0x26, idle_cpu_lincroft),
  350. ICPU(0x2f, idle_cpu_nehalem),
  351. ICPU(0x2a, idle_cpu_snb),
  352. ICPU(0x2d, idle_cpu_snb),
  353. ICPU(0x3a, idle_cpu_ivb),
  354. {}
  355. };
  356. MODULE_DEVICE_TABLE(x86cpu, intel_idle_ids);
  357. /*
  358. * intel_idle_probe()
  359. */
  360. static int intel_idle_probe(void)
  361. {
  362. unsigned int eax, ebx, ecx;
  363. const struct x86_cpu_id *id;
  364. if (max_cstate == 0) {
  365. pr_debug(PREFIX "disabled\n");
  366. return -EPERM;
  367. }
  368. id = x86_match_cpu(intel_idle_ids);
  369. if (!id) {
  370. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
  371. boot_cpu_data.x86 == 6)
  372. pr_debug(PREFIX "does not run on family %d model %d\n",
  373. boot_cpu_data.x86, boot_cpu_data.x86_model);
  374. return -ENODEV;
  375. }
  376. if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
  377. return -ENODEV;
  378. cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
  379. if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
  380. !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
  381. !mwait_substates)
  382. return -ENODEV;
  383. pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates);
  384. icpu = (const struct idle_cpu *)id->driver_data;
  385. cpuidle_state_table = icpu->state_table;
  386. if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
  387. lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
  388. else {
  389. on_each_cpu(__setup_broadcast_timer, (void *)true, 1);
  390. register_cpu_notifier(&setup_broadcast_notifier);
  391. }
  392. pr_debug(PREFIX "v" INTEL_IDLE_VERSION
  393. " model 0x%X\n", boot_cpu_data.x86_model);
  394. pr_debug(PREFIX "lapic_timer_reliable_states 0x%x\n",
  395. lapic_timer_reliable_states);
  396. return 0;
  397. }
  398. /*
  399. * intel_idle_cpuidle_devices_uninit()
  400. * unregister, free cpuidle_devices
  401. */
  402. static void intel_idle_cpuidle_devices_uninit(void)
  403. {
  404. int i;
  405. struct cpuidle_device *dev;
  406. for_each_online_cpu(i) {
  407. dev = per_cpu_ptr(intel_idle_cpuidle_devices, i);
  408. cpuidle_unregister_device(dev);
  409. }
  410. free_percpu(intel_idle_cpuidle_devices);
  411. return;
  412. }
  413. /*
  414. * intel_idle_cpuidle_driver_init()
  415. * allocate, initialize cpuidle_states
  416. */
  417. static int intel_idle_cpuidle_driver_init(void)
  418. {
  419. int cstate;
  420. struct cpuidle_driver *drv = &intel_idle_driver;
  421. drv->state_count = 1;
  422. for (cstate = 1; cstate < MWAIT_MAX_NUM_CSTATES; ++cstate) {
  423. int num_substates;
  424. if (cstate > max_cstate) {
  425. printk(PREFIX "max_cstate %d reached\n",
  426. max_cstate);
  427. break;
  428. }
  429. /* does the state exist in CPUID.MWAIT? */
  430. num_substates = (mwait_substates >> ((cstate) * 4))
  431. & MWAIT_SUBSTATE_MASK;
  432. if (num_substates == 0)
  433. continue;
  434. /* is the state not enabled? */
  435. if (cpuidle_state_table[cstate].enter == NULL) {
  436. /* does the driver not know about the state? */
  437. if (*cpuidle_state_table[cstate].name == '\0')
  438. pr_debug(PREFIX "unaware of model 0x%x"
  439. " MWAIT %d please"
  440. " contact lenb@kernel.org",
  441. boot_cpu_data.x86_model, cstate);
  442. continue;
  443. }
  444. if ((cstate > 2) &&
  445. !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
  446. mark_tsc_unstable("TSC halts in idle"
  447. " states deeper than C2");
  448. drv->states[drv->state_count] = /* structure copy */
  449. cpuidle_state_table[cstate];
  450. drv->state_count += 1;
  451. }
  452. if (icpu->auto_demotion_disable_flags)
  453. on_each_cpu(auto_demotion_disable, NULL, 1);
  454. return 0;
  455. }
  456. /*
  457. * intel_idle_cpu_init()
  458. * allocate, initialize, register cpuidle_devices
  459. * @cpu: cpu/core to initialize
  460. */
  461. int intel_idle_cpu_init(int cpu)
  462. {
  463. int cstate;
  464. struct cpuidle_device *dev;
  465. dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
  466. dev->state_count = 1;
  467. for (cstate = 1; cstate < MWAIT_MAX_NUM_CSTATES; ++cstate) {
  468. int num_substates;
  469. if (cstate > max_cstate) {
  470. printk(PREFIX "max_cstate %d reached\n", max_cstate);
  471. break;
  472. }
  473. /* does the state exist in CPUID.MWAIT? */
  474. num_substates = (mwait_substates >> ((cstate) * 4))
  475. & MWAIT_SUBSTATE_MASK;
  476. if (num_substates == 0)
  477. continue;
  478. /* is the state not enabled? */
  479. if (cpuidle_state_table[cstate].enter == NULL)
  480. continue;
  481. dev->states_usage[dev->state_count].driver_data =
  482. (void *)get_driver_data(cstate);
  483. dev->state_count += 1;
  484. }
  485. dev->cpu = cpu;
  486. if (cpuidle_register_device(dev)) {
  487. pr_debug(PREFIX "cpuidle_register_device %d failed!\n", cpu);
  488. intel_idle_cpuidle_devices_uninit();
  489. return -EIO;
  490. }
  491. if (icpu->auto_demotion_disable_flags)
  492. smp_call_function_single(cpu, auto_demotion_disable, NULL, 1);
  493. return 0;
  494. }
  495. EXPORT_SYMBOL_GPL(intel_idle_cpu_init);
  496. static int __init intel_idle_init(void)
  497. {
  498. int retval, i;
  499. /* Do not load intel_idle at all for now if idle= is passed */
  500. if (boot_option_idle_override != IDLE_NO_OVERRIDE)
  501. return -ENODEV;
  502. retval = intel_idle_probe();
  503. if (retval)
  504. return retval;
  505. intel_idle_cpuidle_driver_init();
  506. retval = cpuidle_register_driver(&intel_idle_driver);
  507. if (retval) {
  508. printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
  509. cpuidle_get_driver()->name);
  510. return retval;
  511. }
  512. intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
  513. if (intel_idle_cpuidle_devices == NULL)
  514. return -ENOMEM;
  515. for_each_online_cpu(i) {
  516. retval = intel_idle_cpu_init(i);
  517. if (retval) {
  518. cpuidle_unregister_driver(&intel_idle_driver);
  519. return retval;
  520. }
  521. }
  522. return 0;
  523. }
  524. static void __exit intel_idle_exit(void)
  525. {
  526. intel_idle_cpuidle_devices_uninit();
  527. cpuidle_unregister_driver(&intel_idle_driver);
  528. if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE) {
  529. on_each_cpu(__setup_broadcast_timer, (void *)false, 1);
  530. unregister_cpu_notifier(&setup_broadcast_notifier);
  531. }
  532. return;
  533. }
  534. module_init(intel_idle_init);
  535. module_exit(intel_idle_exit);
  536. module_param(max_cstate, int, 0444);
  537. MODULE_AUTHOR("Len Brown <len.brown@intel.com>");
  538. MODULE_DESCRIPTION("Cpuidle driver for Intel Hardware v" INTEL_IDLE_VERSION);
  539. MODULE_LICENSE("GPL");