sched_idletask.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * idle-task scheduling class.
  3. *
  4. * (NOTE: these are not related to SCHED_IDLE tasks which are
  5. * handled in sched_fair.c)
  6. */
  7. #ifdef CONFIG_SMP
  8. static int
  9. select_task_rq_idle(struct rq *rq, struct task_struct *p, int sd_flag, int flags)
  10. {
  11. return task_cpu(p); /* IDLE tasks as never migrated */
  12. }
  13. #endif /* CONFIG_SMP */
  14. /*
  15. * Idle tasks are unconditionally rescheduled:
  16. */
  17. static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p, int flags)
  18. {
  19. resched_task(rq->idle);
  20. }
  21. static struct task_struct *pick_next_task_idle(struct rq *rq)
  22. {
  23. schedstat_inc(rq, sched_goidle);
  24. /* adjust the active tasks as we might go into a long sleep */
  25. calc_load_account_active(rq);
  26. return rq->idle;
  27. }
  28. /*
  29. * It is not legal to sleep in the idle task - print a warning
  30. * message if some code attempts to do it:
  31. */
  32. static void
  33. dequeue_task_idle(struct rq *rq, struct task_struct *p, int sleep)
  34. {
  35. raw_spin_unlock_irq(&rq->lock);
  36. printk(KERN_ERR "bad: scheduling from the idle thread!\n");
  37. dump_stack();
  38. raw_spin_lock_irq(&rq->lock);
  39. }
  40. static void put_prev_task_idle(struct rq *rq, struct task_struct *prev)
  41. {
  42. }
  43. static void task_tick_idle(struct rq *rq, struct task_struct *curr, int queued)
  44. {
  45. }
  46. static void set_curr_task_idle(struct rq *rq)
  47. {
  48. }
  49. static void switched_to_idle(struct rq *rq, struct task_struct *p,
  50. int running)
  51. {
  52. /* Can this actually happen?? */
  53. if (running)
  54. resched_task(rq->curr);
  55. else
  56. check_preempt_curr(rq, p, 0);
  57. }
  58. static void prio_changed_idle(struct rq *rq, struct task_struct *p,
  59. int oldprio, int running)
  60. {
  61. /* This can happen for hot plug CPUS */
  62. /*
  63. * Reschedule if we are currently running on this runqueue and
  64. * our priority decreased, or if we are not currently running on
  65. * this runqueue and our priority is higher than the current's
  66. */
  67. if (running) {
  68. if (p->prio > oldprio)
  69. resched_task(rq->curr);
  70. } else
  71. check_preempt_curr(rq, p, 0);
  72. }
  73. static unsigned int get_rr_interval_idle(struct rq *rq, struct task_struct *task)
  74. {
  75. return 0;
  76. }
  77. /*
  78. * Simple, special scheduling class for the per-CPU idle tasks:
  79. */
  80. static const struct sched_class idle_sched_class = {
  81. /* .next is NULL */
  82. /* no enqueue/yield_task for idle tasks */
  83. /* dequeue is not valid, we print a debug message there: */
  84. .dequeue_task = dequeue_task_idle,
  85. .check_preempt_curr = check_preempt_curr_idle,
  86. .pick_next_task = pick_next_task_idle,
  87. .put_prev_task = put_prev_task_idle,
  88. #ifdef CONFIG_SMP
  89. .select_task_rq = select_task_rq_idle,
  90. #endif
  91. .set_curr_task = set_curr_task_idle,
  92. .task_tick = task_tick_idle,
  93. .get_rr_interval = get_rr_interval_idle,
  94. .prio_changed = prio_changed_idle,
  95. .switched_to = switched_to_idle,
  96. /* no .task_new for idle tasks */
  97. };