idle.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. int default_idle(void)
  37. {
  38. long oldval;
  39. unsigned int cpu = smp_processor_id();
  40. while (1) {
  41. oldval = test_and_clear_thread_flag(TIF_NEED_RESCHED);
  42. if (!oldval) {
  43. set_thread_flag(TIF_POLLING_NRFLAG);
  44. while (!need_resched() && !cpu_is_offline(cpu)) {
  45. barrier();
  46. /*
  47. * Go into low thread priority and possibly
  48. * low power mode.
  49. */
  50. HMT_low();
  51. HMT_very_low();
  52. }
  53. HMT_medium();
  54. clear_thread_flag(TIF_POLLING_NRFLAG);
  55. } else {
  56. set_need_resched();
  57. }
  58. schedule();
  59. if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
  60. cpu_die();
  61. }
  62. return 0;
  63. }
  64. int native_idle(void)
  65. {
  66. while(1) {
  67. /* check CPU type here */
  68. if (!need_resched())
  69. power4_idle();
  70. if (need_resched())
  71. schedule();
  72. if (cpu_is_offline(raw_smp_processor_id()) &&
  73. system_state == SYSTEM_RUNNING)
  74. cpu_die();
  75. }
  76. return 0;
  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