idle_64.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Idle daemon for PowerPC. Idle daemon will handle any action
  3. * that needs to be taken when the system becomes idle.
  4. *
  5. * Originally Written by Cort Dougan (cort@cs.nmt.edu)
  6. *
  7. * iSeries supported added by Mike Corrigan <mikejc@us.ibm.com>
  8. *
  9. * Additional shared processor, SMT, and firmware support
  10. * Copyright (c) 2003 Dave Engebretsen <engebret@us.ibm.com>
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. */
  17. #include <linux/config.h>
  18. #include <linux/sched.h>
  19. #include <linux/kernel.h>
  20. #include <linux/smp.h>
  21. #include <linux/cpu.h>
  22. #include <linux/sysctl.h>
  23. #include <asm/system.h>
  24. #include <asm/processor.h>
  25. #include <asm/cputable.h>
  26. #include <asm/time.h>
  27. #include <asm/machdep.h>
  28. #include <asm/smp.h>
  29. extern void power4_idle(void);
  30. void default_idle(void)
  31. {
  32. unsigned int cpu = smp_processor_id();
  33. set_thread_flag(TIF_POLLING_NRFLAG);
  34. while (1) {
  35. if (!need_resched()) {
  36. while (!need_resched() && !cpu_is_offline(cpu)) {
  37. ppc64_runlatch_off();
  38. /*
  39. * Go into low thread priority and possibly
  40. * low power mode.
  41. */
  42. HMT_low();
  43. HMT_very_low();
  44. }
  45. HMT_medium();
  46. }
  47. ppc64_runlatch_on();
  48. preempt_enable_no_resched();
  49. schedule();
  50. preempt_disable();
  51. if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
  52. cpu_die();
  53. }
  54. }
  55. void native_idle(void)
  56. {
  57. while (1) {
  58. ppc64_runlatch_off();
  59. if (!need_resched())
  60. power4_idle();
  61. if (need_resched()) {
  62. ppc64_runlatch_on();
  63. preempt_enable_no_resched();
  64. schedule();
  65. preempt_disable();
  66. }
  67. if (cpu_is_offline(smp_processor_id()) &&
  68. system_state == SYSTEM_RUNNING)
  69. cpu_die();
  70. }
  71. }
  72. void cpu_idle(void)
  73. {
  74. BUG_ON(NULL == ppc_md.idle_loop);
  75. ppc_md.idle_loop();
  76. }
  77. int powersave_nap;
  78. #ifdef CONFIG_SYSCTL
  79. /*
  80. * Register the sysctl to set/clear powersave_nap.
  81. */
  82. static ctl_table powersave_nap_ctl_table[]={
  83. {
  84. .ctl_name = KERN_PPC_POWERSAVE_NAP,
  85. .procname = "powersave-nap",
  86. .data = &powersave_nap,
  87. .maxlen = sizeof(int),
  88. .mode = 0644,
  89. .proc_handler = &proc_dointvec,
  90. },
  91. { 0, },
  92. };
  93. static ctl_table powersave_nap_sysctl_root[] = {
  94. { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, },
  95. { 0,},
  96. };
  97. static int __init
  98. register_powersave_nap_sysctl(void)
  99. {
  100. register_sysctl_table(powersave_nap_sysctl_root, 0);
  101. return 0;
  102. }
  103. __initcall(register_powersave_nap_sysctl);
  104. #endif