idle_task.c 2.6 KB

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