idle.c 2.5 KB

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