idle_task.c 2.4 KB

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