process.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. #include <linux/errno.h>
  2. #include <linux/kernel.h>
  3. #include <linux/mm.h>
  4. #include <linux/smp.h>
  5. #include <linux/prctl.h>
  6. #include <linux/slab.h>
  7. #include <linux/sched.h>
  8. #include <linux/module.h>
  9. #include <linux/pm.h>
  10. #include <linux/clockchips.h>
  11. #include <linux/random.h>
  12. #include <linux/user-return-notifier.h>
  13. #include <linux/dmi.h>
  14. #include <linux/utsname.h>
  15. #include <linux/stackprotector.h>
  16. #include <linux/tick.h>
  17. #include <linux/cpuidle.h>
  18. #include <trace/events/power.h>
  19. #include <linux/hw_breakpoint.h>
  20. #include <asm/cpu.h>
  21. #include <asm/apic.h>
  22. #include <asm/syscalls.h>
  23. #include <asm/idle.h>
  24. #include <asm/uaccess.h>
  25. #include <asm/i387.h>
  26. #include <asm/fpu-internal.h>
  27. #include <asm/debugreg.h>
  28. #include <asm/nmi.h>
  29. /*
  30. * per-CPU TSS segments. Threads are completely 'soft' on Linux,
  31. * no more per-task TSS's. The TSS size is kept cacheline-aligned
  32. * so they are allowed to end up in the .data..cacheline_aligned
  33. * section. Since TSS's are completely CPU-local, we want them
  34. * on exact cacheline boundaries, to eliminate cacheline ping-pong.
  35. */
  36. DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
  37. #ifdef CONFIG_X86_64
  38. static DEFINE_PER_CPU(unsigned char, is_idle);
  39. static ATOMIC_NOTIFIER_HEAD(idle_notifier);
  40. void idle_notifier_register(struct notifier_block *n)
  41. {
  42. atomic_notifier_chain_register(&idle_notifier, n);
  43. }
  44. EXPORT_SYMBOL_GPL(idle_notifier_register);
  45. void idle_notifier_unregister(struct notifier_block *n)
  46. {
  47. atomic_notifier_chain_unregister(&idle_notifier, n);
  48. }
  49. EXPORT_SYMBOL_GPL(idle_notifier_unregister);
  50. #endif
  51. struct kmem_cache *task_xstate_cachep;
  52. EXPORT_SYMBOL_GPL(task_xstate_cachep);
  53. int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
  54. {
  55. int ret;
  56. *dst = *src;
  57. if (fpu_allocated(&src->thread.fpu)) {
  58. memset(&dst->thread.fpu, 0, sizeof(dst->thread.fpu));
  59. ret = fpu_alloc(&dst->thread.fpu);
  60. if (ret)
  61. return ret;
  62. fpu_copy(&dst->thread.fpu, &src->thread.fpu);
  63. }
  64. return 0;
  65. }
  66. void free_thread_xstate(struct task_struct *tsk)
  67. {
  68. fpu_free(&tsk->thread.fpu);
  69. }
  70. void free_thread_info(struct thread_info *ti)
  71. {
  72. free_thread_xstate(ti->task);
  73. free_pages((unsigned long)ti, THREAD_ORDER);
  74. }
  75. void arch_task_cache_init(void)
  76. {
  77. task_xstate_cachep =
  78. kmem_cache_create("task_xstate", xstate_size,
  79. __alignof__(union thread_xstate),
  80. SLAB_PANIC | SLAB_NOTRACK, NULL);
  81. }
  82. /*
  83. * Free current thread data structures etc..
  84. */
  85. void exit_thread(void)
  86. {
  87. struct task_struct *me = current;
  88. struct thread_struct *t = &me->thread;
  89. unsigned long *bp = t->io_bitmap_ptr;
  90. if (bp) {
  91. struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
  92. t->io_bitmap_ptr = NULL;
  93. clear_thread_flag(TIF_IO_BITMAP);
  94. /*
  95. * Careful, clear this in the TSS too:
  96. */
  97. memset(tss->io_bitmap, 0xff, t->io_bitmap_max);
  98. t->io_bitmap_max = 0;
  99. put_cpu();
  100. kfree(bp);
  101. }
  102. }
  103. void show_regs(struct pt_regs *regs)
  104. {
  105. show_registers(regs);
  106. show_trace(NULL, regs, (unsigned long *)kernel_stack_pointer(regs), 0);
  107. }
  108. void show_regs_common(void)
  109. {
  110. const char *vendor, *product, *board;
  111. vendor = dmi_get_system_info(DMI_SYS_VENDOR);
  112. if (!vendor)
  113. vendor = "";
  114. product = dmi_get_system_info(DMI_PRODUCT_NAME);
  115. if (!product)
  116. product = "";
  117. /* Board Name is optional */
  118. board = dmi_get_system_info(DMI_BOARD_NAME);
  119. printk(KERN_CONT "\n");
  120. printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
  121. current->pid, current->comm, print_tainted(),
  122. init_utsname()->release,
  123. (int)strcspn(init_utsname()->version, " "),
  124. init_utsname()->version);
  125. printk(KERN_CONT " %s %s", vendor, product);
  126. if (board)
  127. printk(KERN_CONT "/%s", board);
  128. printk(KERN_CONT "\n");
  129. }
  130. void flush_thread(void)
  131. {
  132. struct task_struct *tsk = current;
  133. flush_ptrace_hw_breakpoint(tsk);
  134. memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
  135. /*
  136. * Forget coprocessor state..
  137. */
  138. tsk->fpu_counter = 0;
  139. clear_fpu(tsk);
  140. clear_used_math();
  141. }
  142. static void hard_disable_TSC(void)
  143. {
  144. write_cr4(read_cr4() | X86_CR4_TSD);
  145. }
  146. void disable_TSC(void)
  147. {
  148. preempt_disable();
  149. if (!test_and_set_thread_flag(TIF_NOTSC))
  150. /*
  151. * Must flip the CPU state synchronously with
  152. * TIF_NOTSC in the current running context.
  153. */
  154. hard_disable_TSC();
  155. preempt_enable();
  156. }
  157. static void hard_enable_TSC(void)
  158. {
  159. write_cr4(read_cr4() & ~X86_CR4_TSD);
  160. }
  161. static void enable_TSC(void)
  162. {
  163. preempt_disable();
  164. if (test_and_clear_thread_flag(TIF_NOTSC))
  165. /*
  166. * Must flip the CPU state synchronously with
  167. * TIF_NOTSC in the current running context.
  168. */
  169. hard_enable_TSC();
  170. preempt_enable();
  171. }
  172. int get_tsc_mode(unsigned long adr)
  173. {
  174. unsigned int val;
  175. if (test_thread_flag(TIF_NOTSC))
  176. val = PR_TSC_SIGSEGV;
  177. else
  178. val = PR_TSC_ENABLE;
  179. return put_user(val, (unsigned int __user *)adr);
  180. }
  181. int set_tsc_mode(unsigned int val)
  182. {
  183. if (val == PR_TSC_SIGSEGV)
  184. disable_TSC();
  185. else if (val == PR_TSC_ENABLE)
  186. enable_TSC();
  187. else
  188. return -EINVAL;
  189. return 0;
  190. }
  191. void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
  192. struct tss_struct *tss)
  193. {
  194. struct thread_struct *prev, *next;
  195. prev = &prev_p->thread;
  196. next = &next_p->thread;
  197. if (test_tsk_thread_flag(prev_p, TIF_BLOCKSTEP) ^
  198. test_tsk_thread_flag(next_p, TIF_BLOCKSTEP)) {
  199. unsigned long debugctl = get_debugctlmsr();
  200. debugctl &= ~DEBUGCTLMSR_BTF;
  201. if (test_tsk_thread_flag(next_p, TIF_BLOCKSTEP))
  202. debugctl |= DEBUGCTLMSR_BTF;
  203. update_debugctlmsr(debugctl);
  204. }
  205. if (test_tsk_thread_flag(prev_p, TIF_NOTSC) ^
  206. test_tsk_thread_flag(next_p, TIF_NOTSC)) {
  207. /* prev and next are different */
  208. if (test_tsk_thread_flag(next_p, TIF_NOTSC))
  209. hard_disable_TSC();
  210. else
  211. hard_enable_TSC();
  212. }
  213. if (test_tsk_thread_flag(next_p, TIF_IO_BITMAP)) {
  214. /*
  215. * Copy the relevant range of the IO bitmap.
  216. * Normally this is 128 bytes or less:
  217. */
  218. memcpy(tss->io_bitmap, next->io_bitmap_ptr,
  219. max(prev->io_bitmap_max, next->io_bitmap_max));
  220. } else if (test_tsk_thread_flag(prev_p, TIF_IO_BITMAP)) {
  221. /*
  222. * Clear any possible leftover bits:
  223. */
  224. memset(tss->io_bitmap, 0xff, prev->io_bitmap_max);
  225. }
  226. propagate_user_return_notify(prev_p, next_p);
  227. }
  228. int sys_fork(struct pt_regs *regs)
  229. {
  230. return do_fork(SIGCHLD, regs->sp, regs, 0, NULL, NULL);
  231. }
  232. /*
  233. * This is trivial, and on the face of it looks like it
  234. * could equally well be done in user mode.
  235. *
  236. * Not so, for quite unobvious reasons - register pressure.
  237. * In user mode vfork() cannot have a stack frame, and if
  238. * done by calling the "clone()" system call directly, you
  239. * do not have enough call-clobbered registers to hold all
  240. * the information you need.
  241. */
  242. int sys_vfork(struct pt_regs *regs)
  243. {
  244. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->sp, regs, 0,
  245. NULL, NULL);
  246. }
  247. long
  248. sys_clone(unsigned long clone_flags, unsigned long newsp,
  249. void __user *parent_tid, void __user *child_tid, struct pt_regs *regs)
  250. {
  251. if (!newsp)
  252. newsp = regs->sp;
  253. return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
  254. }
  255. /*
  256. * This gets run with %si containing the
  257. * function to call, and %di containing
  258. * the "args".
  259. */
  260. extern void kernel_thread_helper(void);
  261. /*
  262. * Create a kernel thread
  263. */
  264. int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
  265. {
  266. struct pt_regs regs;
  267. memset(&regs, 0, sizeof(regs));
  268. regs.si = (unsigned long) fn;
  269. regs.di = (unsigned long) arg;
  270. #ifdef CONFIG_X86_32
  271. regs.ds = __USER_DS;
  272. regs.es = __USER_DS;
  273. regs.fs = __KERNEL_PERCPU;
  274. regs.gs = __KERNEL_STACK_CANARY;
  275. #else
  276. regs.ss = __KERNEL_DS;
  277. #endif
  278. regs.orig_ax = -1;
  279. regs.ip = (unsigned long) kernel_thread_helper;
  280. regs.cs = __KERNEL_CS | get_kernel_rpl();
  281. regs.flags = X86_EFLAGS_IF | X86_EFLAGS_BIT1;
  282. /* Ok, create the new process.. */
  283. return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
  284. }
  285. EXPORT_SYMBOL(kernel_thread);
  286. /*
  287. * sys_execve() executes a new program.
  288. */
  289. long sys_execve(const char __user *name,
  290. const char __user *const __user *argv,
  291. const char __user *const __user *envp, struct pt_regs *regs)
  292. {
  293. long error;
  294. char *filename;
  295. filename = getname(name);
  296. error = PTR_ERR(filename);
  297. if (IS_ERR(filename))
  298. return error;
  299. error = do_execve(filename, argv, envp, regs);
  300. #ifdef CONFIG_X86_32
  301. if (error == 0) {
  302. /* Make sure we don't return using sysenter.. */
  303. set_thread_flag(TIF_IRET);
  304. }
  305. #endif
  306. putname(filename);
  307. return error;
  308. }
  309. /*
  310. * Idle related variables and functions
  311. */
  312. unsigned long boot_option_idle_override = IDLE_NO_OVERRIDE;
  313. EXPORT_SYMBOL(boot_option_idle_override);
  314. /*
  315. * Powermanagement idle function, if any..
  316. */
  317. void (*pm_idle)(void);
  318. #ifdef CONFIG_APM_MODULE
  319. EXPORT_SYMBOL(pm_idle);
  320. #endif
  321. static inline int hlt_use_halt(void)
  322. {
  323. return 1;
  324. }
  325. #ifndef CONFIG_SMP
  326. static inline void play_dead(void)
  327. {
  328. BUG();
  329. }
  330. #endif
  331. #ifdef CONFIG_X86_64
  332. void enter_idle(void)
  333. {
  334. percpu_write(is_idle, 1);
  335. atomic_notifier_call_chain(&idle_notifier, IDLE_START, NULL);
  336. }
  337. static void __exit_idle(void)
  338. {
  339. if (x86_test_and_clear_bit_percpu(0, is_idle) == 0)
  340. return;
  341. atomic_notifier_call_chain(&idle_notifier, IDLE_END, NULL);
  342. }
  343. /* Called from interrupts to signify idle end */
  344. void exit_idle(void)
  345. {
  346. /* idle loop has pid 0 */
  347. if (current->pid)
  348. return;
  349. __exit_idle();
  350. }
  351. #endif
  352. /*
  353. * The idle thread. There's no useful work to be
  354. * done, so just try to conserve power and have a
  355. * low exit latency (ie sit in a loop waiting for
  356. * somebody to say that they'd like to reschedule)
  357. */
  358. void cpu_idle(void)
  359. {
  360. /*
  361. * If we're the non-boot CPU, nothing set the stack canary up
  362. * for us. CPU0 already has it initialized but no harm in
  363. * doing it again. This is a good place for updating it, as
  364. * we wont ever return from this function (so the invalid
  365. * canaries already on the stack wont ever trigger).
  366. */
  367. boot_init_stack_canary();
  368. current_thread_info()->status |= TS_POLLING;
  369. while (1) {
  370. tick_nohz_idle_enter();
  371. while (!need_resched()) {
  372. rmb();
  373. if (cpu_is_offline(smp_processor_id()))
  374. play_dead();
  375. /*
  376. * Idle routines should keep interrupts disabled
  377. * from here on, until they go to idle.
  378. * Otherwise, idle callbacks can misfire.
  379. */
  380. local_touch_nmi();
  381. local_irq_disable();
  382. enter_idle();
  383. /* Don't trace irqs off for idle */
  384. stop_critical_timings();
  385. /* enter_idle() needs rcu for notifiers */
  386. rcu_idle_enter();
  387. if (cpuidle_idle_call())
  388. pm_idle();
  389. rcu_idle_exit();
  390. start_critical_timings();
  391. /* In many cases the interrupt that ended idle
  392. has already called exit_idle. But some idle
  393. loops can be woken up without interrupt. */
  394. __exit_idle();
  395. }
  396. tick_nohz_idle_exit();
  397. preempt_enable_no_resched();
  398. schedule();
  399. preempt_disable();
  400. }
  401. }
  402. /*
  403. * We use this if we don't have any better
  404. * idle routine..
  405. */
  406. void default_idle(void)
  407. {
  408. if (hlt_use_halt()) {
  409. trace_power_start_rcuidle(POWER_CSTATE, 1, smp_processor_id());
  410. trace_cpu_idle_rcuidle(1, smp_processor_id());
  411. current_thread_info()->status &= ~TS_POLLING;
  412. /*
  413. * TS_POLLING-cleared state must be visible before we
  414. * test NEED_RESCHED:
  415. */
  416. smp_mb();
  417. if (!need_resched())
  418. safe_halt(); /* enables interrupts racelessly */
  419. else
  420. local_irq_enable();
  421. current_thread_info()->status |= TS_POLLING;
  422. trace_power_end_rcuidle(smp_processor_id());
  423. trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, smp_processor_id());
  424. } else {
  425. local_irq_enable();
  426. /* loop is done by the caller */
  427. cpu_relax();
  428. }
  429. }
  430. #ifdef CONFIG_APM_MODULE
  431. EXPORT_SYMBOL(default_idle);
  432. #endif
  433. bool set_pm_idle_to_default(void)
  434. {
  435. bool ret = !!pm_idle;
  436. pm_idle = default_idle;
  437. return ret;
  438. }
  439. void stop_this_cpu(void *dummy)
  440. {
  441. local_irq_disable();
  442. /*
  443. * Remove this CPU:
  444. */
  445. set_cpu_online(smp_processor_id(), false);
  446. disable_local_APIC();
  447. for (;;) {
  448. if (hlt_works(smp_processor_id()))
  449. halt();
  450. }
  451. }
  452. static void do_nothing(void *unused)
  453. {
  454. }
  455. /*
  456. * cpu_idle_wait - Used to ensure that all the CPUs discard old value of
  457. * pm_idle and update to new pm_idle value. Required while changing pm_idle
  458. * handler on SMP systems.
  459. *
  460. * Caller must have changed pm_idle to the new value before the call. Old
  461. * pm_idle value will not be used by any CPU after the return of this function.
  462. */
  463. void cpu_idle_wait(void)
  464. {
  465. smp_mb();
  466. /* kick all the CPUs so that they exit out of pm_idle */
  467. smp_call_function(do_nothing, NULL, 1);
  468. }
  469. EXPORT_SYMBOL_GPL(cpu_idle_wait);
  470. /* Default MONITOR/MWAIT with no hints, used for default C1 state */
  471. static void mwait_idle(void)
  472. {
  473. if (!need_resched()) {
  474. trace_power_start_rcuidle(POWER_CSTATE, 1, smp_processor_id());
  475. trace_cpu_idle_rcuidle(1, smp_processor_id());
  476. if (this_cpu_has(X86_FEATURE_CLFLUSH_MONITOR))
  477. clflush((void *)&current_thread_info()->flags);
  478. __monitor((void *)&current_thread_info()->flags, 0, 0);
  479. smp_mb();
  480. if (!need_resched())
  481. __sti_mwait(0, 0);
  482. else
  483. local_irq_enable();
  484. trace_power_end_rcuidle(smp_processor_id());
  485. trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, smp_processor_id());
  486. } else
  487. local_irq_enable();
  488. }
  489. /*
  490. * On SMP it's slightly faster (but much more power-consuming!)
  491. * to poll the ->work.need_resched flag instead of waiting for the
  492. * cross-CPU IPI to arrive. Use this option with caution.
  493. */
  494. static void poll_idle(void)
  495. {
  496. trace_power_start_rcuidle(POWER_CSTATE, 0, smp_processor_id());
  497. trace_cpu_idle_rcuidle(0, smp_processor_id());
  498. local_irq_enable();
  499. while (!need_resched())
  500. cpu_relax();
  501. trace_power_end_rcuidle(smp_processor_id());
  502. trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, smp_processor_id());
  503. }
  504. /*
  505. * mwait selection logic:
  506. *
  507. * It depends on the CPU. For AMD CPUs that support MWAIT this is
  508. * wrong. Family 0x10 and 0x11 CPUs will enter C1 on HLT. Powersavings
  509. * then depend on a clock divisor and current Pstate of the core. If
  510. * all cores of a processor are in halt state (C1) the processor can
  511. * enter the C1E (C1 enhanced) state. If mwait is used this will never
  512. * happen.
  513. *
  514. * idle=mwait overrides this decision and forces the usage of mwait.
  515. */
  516. #define MWAIT_INFO 0x05
  517. #define MWAIT_ECX_EXTENDED_INFO 0x01
  518. #define MWAIT_EDX_C1 0xf0
  519. int mwait_usable(const struct cpuinfo_x86 *c)
  520. {
  521. u32 eax, ebx, ecx, edx;
  522. if (boot_option_idle_override == IDLE_FORCE_MWAIT)
  523. return 1;
  524. if (c->cpuid_level < MWAIT_INFO)
  525. return 0;
  526. cpuid(MWAIT_INFO, &eax, &ebx, &ecx, &edx);
  527. /* Check, whether EDX has extended info about MWAIT */
  528. if (!(ecx & MWAIT_ECX_EXTENDED_INFO))
  529. return 1;
  530. /*
  531. * edx enumeratios MONITOR/MWAIT extensions. Check, whether
  532. * C1 supports MWAIT
  533. */
  534. return (edx & MWAIT_EDX_C1);
  535. }
  536. bool amd_e400_c1e_detected;
  537. EXPORT_SYMBOL(amd_e400_c1e_detected);
  538. static cpumask_var_t amd_e400_c1e_mask;
  539. void amd_e400_remove_cpu(int cpu)
  540. {
  541. if (amd_e400_c1e_mask != NULL)
  542. cpumask_clear_cpu(cpu, amd_e400_c1e_mask);
  543. }
  544. /*
  545. * AMD Erratum 400 aware idle routine. We check for C1E active in the interrupt
  546. * pending message MSR. If we detect C1E, then we handle it the same
  547. * way as C3 power states (local apic timer and TSC stop)
  548. */
  549. static void amd_e400_idle(void)
  550. {
  551. if (need_resched())
  552. return;
  553. if (!amd_e400_c1e_detected) {
  554. u32 lo, hi;
  555. rdmsr(MSR_K8_INT_PENDING_MSG, lo, hi);
  556. if (lo & K8_INTP_C1E_ACTIVE_MASK) {
  557. amd_e400_c1e_detected = true;
  558. if (!boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
  559. mark_tsc_unstable("TSC halt in AMD C1E");
  560. printk(KERN_INFO "System has AMD C1E enabled\n");
  561. }
  562. }
  563. if (amd_e400_c1e_detected) {
  564. int cpu = smp_processor_id();
  565. if (!cpumask_test_cpu(cpu, amd_e400_c1e_mask)) {
  566. cpumask_set_cpu(cpu, amd_e400_c1e_mask);
  567. /*
  568. * Force broadcast so ACPI can not interfere.
  569. */
  570. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
  571. &cpu);
  572. printk(KERN_INFO "Switch to broadcast mode on CPU%d\n",
  573. cpu);
  574. }
  575. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
  576. default_idle();
  577. /*
  578. * The switch back from broadcast mode needs to be
  579. * called with interrupts disabled.
  580. */
  581. local_irq_disable();
  582. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
  583. local_irq_enable();
  584. } else
  585. default_idle();
  586. }
  587. void __cpuinit select_idle_routine(const struct cpuinfo_x86 *c)
  588. {
  589. #ifdef CONFIG_SMP
  590. if (pm_idle == poll_idle && smp_num_siblings > 1) {
  591. printk_once(KERN_WARNING "WARNING: polling idle and HT enabled,"
  592. " performance may degrade.\n");
  593. }
  594. #endif
  595. if (pm_idle)
  596. return;
  597. if (cpu_has(c, X86_FEATURE_MWAIT) && mwait_usable(c)) {
  598. /*
  599. * One CPU supports mwait => All CPUs supports mwait
  600. */
  601. printk(KERN_INFO "using mwait in idle threads.\n");
  602. pm_idle = mwait_idle;
  603. } else if (cpu_has_amd_erratum(amd_erratum_400)) {
  604. /* E400: APIC timer interrupt does not wake up CPU from C1e */
  605. printk(KERN_INFO "using AMD E400 aware idle routine\n");
  606. pm_idle = amd_e400_idle;
  607. } else
  608. pm_idle = default_idle;
  609. }
  610. void __init init_amd_e400_c1e_mask(void)
  611. {
  612. /* If we're using amd_e400_idle, we need to allocate amd_e400_c1e_mask. */
  613. if (pm_idle == amd_e400_idle)
  614. zalloc_cpumask_var(&amd_e400_c1e_mask, GFP_KERNEL);
  615. }
  616. static int __init idle_setup(char *str)
  617. {
  618. if (!str)
  619. return -EINVAL;
  620. if (!strcmp(str, "poll")) {
  621. printk("using polling idle threads.\n");
  622. pm_idle = poll_idle;
  623. boot_option_idle_override = IDLE_POLL;
  624. } else if (!strcmp(str, "mwait")) {
  625. boot_option_idle_override = IDLE_FORCE_MWAIT;
  626. WARN_ONCE(1, "\"idle=mwait\" will be removed in 2012\n");
  627. } else if (!strcmp(str, "halt")) {
  628. /*
  629. * When the boot option of idle=halt is added, halt is
  630. * forced to be used for CPU idle. In such case CPU C2/C3
  631. * won't be used again.
  632. * To continue to load the CPU idle driver, don't touch
  633. * the boot_option_idle_override.
  634. */
  635. pm_idle = default_idle;
  636. boot_option_idle_override = IDLE_HALT;
  637. } else if (!strcmp(str, "nomwait")) {
  638. /*
  639. * If the boot option of "idle=nomwait" is added,
  640. * it means that mwait will be disabled for CPU C2/C3
  641. * states. In such case it won't touch the variable
  642. * of boot_option_idle_override.
  643. */
  644. boot_option_idle_override = IDLE_NOMWAIT;
  645. } else
  646. return -1;
  647. return 0;
  648. }
  649. early_param("idle", idle_setup);
  650. unsigned long arch_align_stack(unsigned long sp)
  651. {
  652. if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
  653. sp -= get_random_int() % 8192;
  654. return sp & ~0xf;
  655. }
  656. unsigned long arch_randomize_brk(struct mm_struct *mm)
  657. {
  658. unsigned long range_end = mm->brk + 0x02000000;
  659. return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
  660. }