stop_task.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // SPDX-License-Identifier: GPL-2.0
  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. #include "sched.h"
  11. #ifdef CONFIG_SMP
  12. static int
  13. select_task_rq_stop(struct task_struct *p, int cpu, int sd_flag, int flags)
  14. {
  15. return task_cpu(p); /* stop tasks as never migrate */
  16. }
  17. #endif /* CONFIG_SMP */
  18. static void
  19. check_preempt_curr_stop(struct rq *rq, struct task_struct *p, int flags)
  20. {
  21. /* we're never preempted */
  22. }
  23. static struct task_struct *
  24. pick_next_task_stop(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
  25. {
  26. struct task_struct *stop = rq->stop;
  27. if (!stop || !task_on_rq_queued(stop))
  28. return NULL;
  29. put_prev_task(rq, prev);
  30. stop->se.exec_start = rq_clock_task(rq);
  31. return stop;
  32. }
  33. static void
  34. enqueue_task_stop(struct rq *rq, struct task_struct *p, int flags)
  35. {
  36. add_nr_running(rq, 1);
  37. }
  38. static void
  39. dequeue_task_stop(struct rq *rq, struct task_struct *p, int flags)
  40. {
  41. sub_nr_running(rq, 1);
  42. }
  43. static void yield_task_stop(struct rq *rq)
  44. {
  45. BUG(); /* the stop task should never yield, its pointless. */
  46. }
  47. static void put_prev_task_stop(struct rq *rq, struct task_struct *prev)
  48. {
  49. struct task_struct *curr = rq->curr;
  50. u64 delta_exec;
  51. delta_exec = rq_clock_task(rq) - curr->se.exec_start;
  52. if (unlikely((s64)delta_exec < 0))
  53. delta_exec = 0;
  54. schedstat_set(curr->se.statistics.exec_max,
  55. max(curr->se.statistics.exec_max, delta_exec));
  56. curr->se.sum_exec_runtime += delta_exec;
  57. account_group_exec_runtime(curr, delta_exec);
  58. curr->se.exec_start = rq_clock_task(rq);
  59. cgroup_account_cputime(curr, delta_exec);
  60. }
  61. /*
  62. * scheduler tick hitting a task of our scheduling class.
  63. *
  64. * NOTE: This function can be called remotely by the tick offload that
  65. * goes along full dynticks. Therefore no local assumption can be made
  66. * and everything must be accessed through the @rq and @curr passed in
  67. * parameters.
  68. */
  69. static void task_tick_stop(struct rq *rq, struct task_struct *curr, int queued)
  70. {
  71. }
  72. static void set_curr_task_stop(struct rq *rq)
  73. {
  74. struct task_struct *stop = rq->stop;
  75. stop->se.exec_start = rq_clock_task(rq);
  76. }
  77. static void switched_to_stop(struct rq *rq, struct task_struct *p)
  78. {
  79. BUG(); /* its impossible to change to this class */
  80. }
  81. static void
  82. prio_changed_stop(struct rq *rq, struct task_struct *p, int oldprio)
  83. {
  84. BUG(); /* how!?, what priority? */
  85. }
  86. static unsigned int
  87. get_rr_interval_stop(struct rq *rq, struct task_struct *task)
  88. {
  89. return 0;
  90. }
  91. static void update_curr_stop(struct rq *rq)
  92. {
  93. }
  94. /*
  95. * Simple, special scheduling class for the per-CPU stop tasks:
  96. */
  97. const struct sched_class stop_sched_class = {
  98. .next = &dl_sched_class,
  99. .enqueue_task = enqueue_task_stop,
  100. .dequeue_task = dequeue_task_stop,
  101. .yield_task = yield_task_stop,
  102. .check_preempt_curr = check_preempt_curr_stop,
  103. .pick_next_task = pick_next_task_stop,
  104. .put_prev_task = put_prev_task_stop,
  105. #ifdef CONFIG_SMP
  106. .select_task_rq = select_task_rq_stop,
  107. .set_cpus_allowed = set_cpus_allowed_common,
  108. #endif
  109. .set_curr_task = set_curr_task_stop,
  110. .task_tick = task_tick_stop,
  111. .get_rr_interval = get_rr_interval_stop,
  112. .prio_changed = prio_changed_stop,
  113. .switched_to = switched_to_stop,
  114. .update_curr = update_curr_stop,
  115. };