process.c 17 KB

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