sched_idletask.c 2.9 KB

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