idle_task.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "sched.h"
  2. /*
  3. * idle-task scheduling class.
  4. *
  5. * (NOTE: these are not related to SCHED_IDLE tasks which are
  6. * handled in sched/fair.c)
  7. */
  8. #ifdef CONFIG_SMP
  9. static int
  10. select_task_rq_idle(struct task_struct *p, int sd_flag, int flags)
  11. {
  12. return task_cpu(p); /* IDLE tasks as never migrated */
  13. }
  14. static void pre_schedule_idle(struct rq *rq, struct task_struct *prev)
  15. {
  16. idle_exit_fair(rq);
  17. rq_last_tick_reset(rq);
  18. }
  19. static void post_schedule_idle(struct rq *rq)
  20. {
  21. idle_enter_fair(rq);
  22. }
  23. #endif /* CONFIG_SMP */
  24. /*
  25. * Idle tasks are unconditionally rescheduled:
  26. */
  27. static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p, int flags)
  28. {
  29. resched_task(rq->idle);
  30. }
  31. static struct task_struct *pick_next_task_idle(struct rq *rq)
  32. {
  33. schedstat_inc(rq, sched_goidle);
  34. #ifdef CONFIG_SMP
  35. /* Trigger the post schedule to do an idle_enter for CFS */
  36. rq->post_schedule = 1;
  37. #endif
  38. return rq->idle;
  39. }
  40. /*
  41. * It is not legal to sleep in the idle task - print a warning
  42. * message if some code attempts to do it:
  43. */
  44. static void
  45. dequeue_task_idle(struct rq *rq, struct task_struct *p, int flags)
  46. {
  47. raw_spin_unlock_irq(&rq->lock);
  48. printk(KERN_ERR "bad: scheduling from the idle thread!\n");
  49. dump_stack();
  50. raw_spin_lock_irq(&rq->lock);
  51. }
  52. static void put_prev_task_idle(struct rq *rq, struct task_struct *prev)
  53. {
  54. }
  55. static void task_tick_idle(struct rq *rq, struct task_struct *curr, int queued)
  56. {
  57. }
  58. static void set_curr_task_idle(struct rq *rq)
  59. {
  60. }
  61. static void switched_to_idle(struct rq *rq, struct task_struct *p)
  62. {
  63. BUG();
  64. }
  65. static void
  66. prio_changed_idle(struct rq *rq, struct task_struct *p, int oldprio)
  67. {
  68. BUG();
  69. }
  70. static unsigned int get_rr_interval_idle(struct rq *rq, struct task_struct *task)
  71. {
  72. return 0;
  73. }
  74. /*
  75. * Simple, special scheduling class for the per-CPU idle tasks:
  76. */
  77. const struct sched_class idle_sched_class = {
  78. /* .next is NULL */
  79. /* no enqueue/yield_task for idle tasks */
  80. /* dequeue is not valid, we print a debug message there: */
  81. .dequeue_task = dequeue_task_idle,
  82. .check_preempt_curr = check_preempt_curr_idle,
  83. .pick_next_task = pick_next_task_idle,
  84. .put_prev_task = put_prev_task_idle,
  85. #ifdef CONFIG_SMP
  86. .select_task_rq = select_task_rq_idle,
  87. .pre_schedule = pre_schedule_idle,
  88. .post_schedule = post_schedule_idle,
  89. #endif
  90. .set_curr_task = set_curr_task_idle,
  91. .task_tick = task_tick_idle,
  92. .get_rr_interval = get_rr_interval_idle,
  93. .prio_changed = prio_changed_idle,
  94. .switched_to = switched_to_idle,
  95. };