stop_task.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "sched.h"
  2. /*
  3. * stop-task scheduling class.
  4. *
  5. * The stop task is the highest priority task in the system, it preempts
  6. * everything and will be preempted by nothing.
  7. *
  8. * See kernel/stop_machine.c
  9. */
  10. #ifdef CONFIG_SMP
  11. static int
  12. select_task_rq_stop(struct task_struct *p, int sd_flag, int flags)
  13. {
  14. return task_cpu(p); /* stop tasks as never migrate */
  15. }
  16. #endif /* CONFIG_SMP */
  17. static void
  18. check_preempt_curr_stop(struct rq *rq, struct task_struct *p, int flags)
  19. {
  20. /* we're never preempted */
  21. }
  22. static struct task_struct *pick_next_task_stop(struct rq *rq)
  23. {
  24. struct task_struct *stop = rq->stop;
  25. if (stop && stop->on_rq) {
  26. stop->se.exec_start = rq->clock_task;
  27. return stop;
  28. }
  29. return NULL;
  30. }
  31. static void
  32. enqueue_task_stop(struct rq *rq, struct task_struct *p, int flags)
  33. {
  34. inc_nr_running(rq);
  35. }
  36. static void
  37. dequeue_task_stop(struct rq *rq, struct task_struct *p, int flags)
  38. {
  39. dec_nr_running(rq);
  40. }
  41. static void yield_task_stop(struct rq *rq)
  42. {
  43. BUG(); /* the stop task should never yield, its pointless. */
  44. }
  45. static void put_prev_task_stop(struct rq *rq, struct task_struct *prev)
  46. {
  47. struct task_struct *curr = rq->curr;
  48. u64 delta_exec;
  49. delta_exec = rq->clock_task - curr->se.exec_start;
  50. if (unlikely((s64)delta_exec < 0))
  51. delta_exec = 0;
  52. schedstat_set(curr->se.statistics.exec_max,
  53. max(curr->se.statistics.exec_max, delta_exec));
  54. curr->se.sum_exec_runtime += delta_exec;
  55. account_group_exec_runtime(curr, delta_exec);
  56. curr->se.exec_start = rq->clock_task;
  57. cpuacct_charge(curr, delta_exec);
  58. }
  59. static void task_tick_stop(struct rq *rq, struct task_struct *curr, int queued)
  60. {
  61. }
  62. static void set_curr_task_stop(struct rq *rq)
  63. {
  64. struct task_struct *stop = rq->stop;
  65. stop->se.exec_start = rq->clock_task;
  66. }
  67. static void switched_to_stop(struct rq *rq, struct task_struct *p)
  68. {
  69. BUG(); /* its impossible to change to this class */
  70. }
  71. static void
  72. prio_changed_stop(struct rq *rq, struct task_struct *p, int oldprio)
  73. {
  74. BUG(); /* how!?, what priority? */
  75. }
  76. static unsigned int
  77. get_rr_interval_stop(struct rq *rq, struct task_struct *task)
  78. {
  79. return 0;
  80. }
  81. /*
  82. * Simple, special scheduling class for the per-CPU stop tasks:
  83. */
  84. const struct sched_class stop_sched_class = {
  85. .next = &rt_sched_class,
  86. .enqueue_task = enqueue_task_stop,
  87. .dequeue_task = dequeue_task_stop,
  88. .yield_task = yield_task_stop,
  89. .check_preempt_curr = check_preempt_curr_stop,
  90. .pick_next_task = pick_next_task_stop,
  91. .put_prev_task = put_prev_task_stop,
  92. #ifdef CONFIG_SMP
  93. .select_task_rq = select_task_rq_stop,
  94. #endif
  95. .set_curr_task = set_curr_task_stop,
  96. .task_tick = task_tick_stop,
  97. .get_rr_interval = get_rr_interval_stop,
  98. .prio_changed = prio_changed_stop,
  99. .switched_to = switched_to_stop,
  100. };