sched_idletask.c 3.0 KB

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