sched_idletask.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 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. calc_load_account_idle(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 flags)
  33. {
  34. raw_spin_unlock_irq(&rq->lock);
  35. printk(KERN_ERR "bad: scheduling from the idle thread!\n");
  36. dump_stack();
  37. raw_spin_lock_irq(&rq->lock);
  38. }
  39. static void put_prev_task_idle(struct rq *rq, struct task_struct *prev)
  40. {
  41. }
  42. static void task_tick_idle(struct rq *rq, struct task_struct *curr, int queued)
  43. {
  44. }
  45. static void set_curr_task_idle(struct rq *rq)
  46. {
  47. }
  48. static void switched_to_idle(struct rq *rq, struct task_struct *p)
  49. {
  50. BUG();
  51. }
  52. static void
  53. prio_changed_idle(struct rq *rq, struct task_struct *p, int oldprio)
  54. {
  55. BUG();
  56. }
  57. static unsigned int get_rr_interval_idle(struct rq *rq, struct task_struct *task)
  58. {
  59. return 0;
  60. }
  61. /*
  62. * Simple, special scheduling class for the per-CPU idle tasks:
  63. */
  64. static const struct sched_class idle_sched_class = {
  65. /* .next is NULL */
  66. /* no enqueue/yield_task for idle tasks */
  67. /* dequeue is not valid, we print a debug message there: */
  68. .dequeue_task = dequeue_task_idle,
  69. .check_preempt_curr = check_preempt_curr_idle,
  70. .pick_next_task = pick_next_task_idle,
  71. .put_prev_task = put_prev_task_idle,
  72. #ifdef CONFIG_SMP
  73. .select_task_rq = select_task_rq_idle,
  74. #endif
  75. .set_curr_task = set_curr_task_idle,
  76. .task_tick = task_tick_idle,
  77. .get_rr_interval = get_rr_interval_idle,
  78. .prio_changed = prio_changed_idle,
  79. .switched_to = switched_to_idle,
  80. };