idle.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * The idle loop for all SuperH platforms.
  3. *
  4. * Copyright (C) 2002 - 2008 Paul Mundt
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/init.h>
  12. #include <linux/mm.h>
  13. #include <linux/pm.h>
  14. #include <linux/tick.h>
  15. #include <linux/preempt.h>
  16. #include <linux/thread_info.h>
  17. #include <linux/irqflags.h>
  18. #include <asm/pgalloc.h>
  19. #include <asm/system.h>
  20. #include <asm/atomic.h>
  21. static int hlt_counter;
  22. void (*pm_idle)(void);
  23. void (*pm_power_off)(void);
  24. EXPORT_SYMBOL(pm_power_off);
  25. static int __init nohlt_setup(char *__unused)
  26. {
  27. hlt_counter = 1;
  28. return 1;
  29. }
  30. __setup("nohlt", nohlt_setup);
  31. static int __init hlt_setup(char *__unused)
  32. {
  33. hlt_counter = 0;
  34. return 1;
  35. }
  36. __setup("hlt", hlt_setup);
  37. void default_idle(void)
  38. {
  39. if (!hlt_counter) {
  40. clear_thread_flag(TIF_POLLING_NRFLAG);
  41. smp_mb__after_clear_bit();
  42. set_bl_bit();
  43. stop_critical_timings();
  44. while (!need_resched())
  45. cpu_sleep();
  46. start_critical_timings();
  47. clear_bl_bit();
  48. set_thread_flag(TIF_POLLING_NRFLAG);
  49. } else
  50. while (!need_resched())
  51. cpu_relax();
  52. }
  53. void cpu_idle(void)
  54. {
  55. set_thread_flag(TIF_POLLING_NRFLAG);
  56. /* endless idle loop with no priority at all */
  57. while (1) {
  58. void (*idle)(void) = pm_idle;
  59. if (!idle)
  60. idle = default_idle;
  61. tick_nohz_stop_sched_tick(1);
  62. while (!need_resched())
  63. idle();
  64. tick_nohz_restart_sched_tick();
  65. preempt_enable_no_resched();
  66. schedule();
  67. preempt_disable();
  68. check_pgt_cache();
  69. }
  70. }