process.c 18 KB

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