idle.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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/module.h>
  23. #include <linux/sysctl.h>
  24. #include <linux/smp.h>
  25. #include <asm/system.h>
  26. #include <asm/processor.h>
  27. #include <asm/mmu.h>
  28. #include <asm/cputable.h>
  29. #include <asm/time.h>
  30. #include <asm/iSeries/HvCall.h>
  31. #include <asm/iSeries/ItLpQueue.h>
  32. #include <asm/plpar_wrappers.h>
  33. #include <asm/systemcfg.h>
  34. #include <asm/machdep.h>
  35. extern void power4_idle(void);
  36. static int (*idle_loop)(void);
  37. int default_idle(void)
  38. {
  39. long oldval;
  40. unsigned int cpu = smp_processor_id();
  41. while (1) {
  42. oldval = test_and_clear_thread_flag(TIF_NEED_RESCHED);
  43. if (!oldval) {
  44. set_thread_flag(TIF_POLLING_NRFLAG);
  45. while (!need_resched() && !cpu_is_offline(cpu)) {
  46. barrier();
  47. /*
  48. * Go into low thread priority and possibly
  49. * low power mode.
  50. */
  51. HMT_low();
  52. HMT_very_low();
  53. }
  54. HMT_medium();
  55. clear_thread_flag(TIF_POLLING_NRFLAG);
  56. } else {
  57. set_need_resched();
  58. }
  59. schedule();
  60. if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
  61. cpu_die();
  62. }
  63. return 0;
  64. }
  65. int native_idle(void)
  66. {
  67. while(1) {
  68. /* check CPU type here */
  69. if (!need_resched())
  70. power4_idle();
  71. if (need_resched())
  72. schedule();
  73. if (cpu_is_offline(raw_smp_processor_id()) &&
  74. system_state == SYSTEM_RUNNING)
  75. cpu_die();
  76. }
  77. return 0;
  78. }
  79. void cpu_idle(void)
  80. {
  81. BUG_ON(NULL == ppc_md.idle_loop);
  82. ppc_md.idle_loop();
  83. }
  84. int powersave_nap;
  85. #ifdef CONFIG_SYSCTL
  86. /*
  87. * Register the sysctl to set/clear powersave_nap.
  88. */
  89. static ctl_table powersave_nap_ctl_table[]={
  90. {
  91. .ctl_name = KERN_PPC_POWERSAVE_NAP,
  92. .procname = "powersave-nap",
  93. .data = &powersave_nap,
  94. .maxlen = sizeof(int),
  95. .mode = 0644,
  96. .proc_handler = &proc_dointvec,
  97. },
  98. { 0, },
  99. };
  100. static ctl_table powersave_nap_sysctl_root[] = {
  101. { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, },
  102. { 0,},
  103. };
  104. static int __init
  105. register_powersave_nap_sysctl(void)
  106. {
  107. register_sysctl_table(powersave_nap_sysctl_root, 0);
  108. return 0;
  109. }
  110. __initcall(register_powersave_nap_sysctl);
  111. #endif
  112. int idle_setup(void)
  113. {
  114. /*
  115. * Move that junk to each platform specific file, eventually define
  116. * a pSeries_idle for shared processor stuff
  117. */
  118. #ifdef CONFIG_PPC_ISERIES
  119. idle_loop = iSeries_idle;
  120. return 1;
  121. #else
  122. idle_loop = default_idle;
  123. #endif
  124. #ifdef CONFIG_PPC_PSERIES
  125. if (systemcfg->platform & PLATFORM_PSERIES) {
  126. if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR) {
  127. if (get_paca()->lppaca.shared_proc) {
  128. printk(KERN_INFO "Using shared processor idle loop\n");
  129. idle_loop = shared_idle;
  130. } else {
  131. printk(KERN_INFO "Using dedicated idle loop\n");
  132. idle_loop = dedicated_idle;
  133. }
  134. } else {
  135. printk(KERN_INFO "Using default idle loop\n");
  136. idle_loop = default_idle;
  137. }
  138. }
  139. #endif /* CONFIG_PPC_PSERIES */
  140. #ifndef CONFIG_PPC_ISERIES
  141. if (systemcfg->platform == PLATFORM_POWERMAC ||
  142. systemcfg->platform == PLATFORM_MAPLE) {
  143. printk(KERN_INFO "Using native/NAP idle loop\n");
  144. idle_loop = native_idle;
  145. }
  146. #endif /* CONFIG_PPC_ISERIES */
  147. return 1;
  148. }