idle.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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/systemcfg.h>
  28. #include <asm/machdep.h>
  29. #include <asm/smp.h>
  30. extern void power4_idle(void);
  31. void default_idle(void)
  32. {
  33. long oldval;
  34. unsigned int cpu = smp_processor_id();
  35. while (1) {
  36. oldval = test_and_clear_thread_flag(TIF_NEED_RESCHED);
  37. if (!oldval) {
  38. set_thread_flag(TIF_POLLING_NRFLAG);
  39. while (!need_resched() && !cpu_is_offline(cpu)) {
  40. ppc64_runlatch_off();
  41. /*
  42. * Go into low thread priority and possibly
  43. * low power mode.
  44. */
  45. HMT_low();
  46. HMT_very_low();
  47. }
  48. HMT_medium();
  49. clear_thread_flag(TIF_POLLING_NRFLAG);
  50. } else {
  51. set_need_resched();
  52. }
  53. ppc64_runlatch_on();
  54. preempt_enable_no_resched();
  55. schedule();
  56. preempt_disable();
  57. if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
  58. cpu_die();
  59. }
  60. }
  61. void native_idle(void)
  62. {
  63. while (1) {
  64. ppc64_runlatch_off();
  65. if (!need_resched())
  66. power4_idle();
  67. if (need_resched()) {
  68. ppc64_runlatch_on();
  69. preempt_enable_no_resched();
  70. schedule();
  71. preempt_disable();
  72. }
  73. if (cpu_is_offline(smp_processor_id()) &&
  74. system_state == SYSTEM_RUNNING)
  75. cpu_die();
  76. }
  77. }
  78. void cpu_idle(void)
  79. {
  80. BUG_ON(NULL == ppc_md.idle_loop);
  81. ppc_md.idle_loop();
  82. }
  83. int powersave_nap;
  84. #ifdef CONFIG_SYSCTL
  85. /*
  86. * Register the sysctl to set/clear powersave_nap.
  87. */
  88. static ctl_table powersave_nap_ctl_table[]={
  89. {
  90. .ctl_name = KERN_PPC_POWERSAVE_NAP,
  91. .procname = "powersave-nap",
  92. .data = &powersave_nap,
  93. .maxlen = sizeof(int),
  94. .mode = 0644,
  95. .proc_handler = &proc_dointvec,
  96. },
  97. { 0, },
  98. };
  99. static ctl_table powersave_nap_sysctl_root[] = {
  100. { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, },
  101. { 0,},
  102. };
  103. static int __init
  104. register_powersave_nap_sysctl(void)
  105. {
  106. register_sysctl_table(powersave_nap_sysctl_root, 0);
  107. return 0;
  108. }
  109. __initcall(register_powersave_nap_sysctl);
  110. #endif