idle_task.c 2.3 KB

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