idle_task.c 2.4 KB

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