Linux 4.15.6
[linux/fpc-iii.git] / kernel / sched / stop_task.c
blob210b1f2146ff2f44b7ee1021b3a99b262857c841
1 // SPDX-License-Identifier: GPL-2.0
2 #include "sched.h"
4 /*
5 * stop-task scheduling class.
7 * The stop task is the highest priority task in the system, it preempts
8 * everything and will be preempted by nothing.
10 * See kernel/stop_machine.c
13 #ifdef CONFIG_SMP
14 static int
15 select_task_rq_stop(struct task_struct *p, int cpu, int sd_flag, int flags)
17 return task_cpu(p); /* stop tasks as never migrate */
19 #endif /* CONFIG_SMP */
21 static void
22 check_preempt_curr_stop(struct rq *rq, struct task_struct *p, int flags)
24 /* we're never preempted */
27 static struct task_struct *
28 pick_next_task_stop(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
30 struct task_struct *stop = rq->stop;
32 if (!stop || !task_on_rq_queued(stop))
33 return NULL;
35 put_prev_task(rq, prev);
37 stop->se.exec_start = rq_clock_task(rq);
39 return stop;
42 static void
43 enqueue_task_stop(struct rq *rq, struct task_struct *p, int flags)
45 add_nr_running(rq, 1);
48 static void
49 dequeue_task_stop(struct rq *rq, struct task_struct *p, int flags)
51 sub_nr_running(rq, 1);
54 static void yield_task_stop(struct rq *rq)
56 BUG(); /* the stop task should never yield, its pointless. */
59 static void put_prev_task_stop(struct rq *rq, struct task_struct *prev)
61 struct task_struct *curr = rq->curr;
62 u64 delta_exec;
64 delta_exec = rq_clock_task(rq) - curr->se.exec_start;
65 if (unlikely((s64)delta_exec < 0))
66 delta_exec = 0;
68 schedstat_set(curr->se.statistics.exec_max,
69 max(curr->se.statistics.exec_max, delta_exec));
71 curr->se.sum_exec_runtime += delta_exec;
72 account_group_exec_runtime(curr, delta_exec);
74 curr->se.exec_start = rq_clock_task(rq);
75 cgroup_account_cputime(curr, delta_exec);
78 static void task_tick_stop(struct rq *rq, struct task_struct *curr, int queued)
82 static void set_curr_task_stop(struct rq *rq)
84 struct task_struct *stop = rq->stop;
86 stop->se.exec_start = rq_clock_task(rq);
89 static void switched_to_stop(struct rq *rq, struct task_struct *p)
91 BUG(); /* its impossible to change to this class */
94 static void
95 prio_changed_stop(struct rq *rq, struct task_struct *p, int oldprio)
97 BUG(); /* how!?, what priority? */
100 static unsigned int
101 get_rr_interval_stop(struct rq *rq, struct task_struct *task)
103 return 0;
106 static void update_curr_stop(struct rq *rq)
111 * Simple, special scheduling class for the per-CPU stop tasks:
113 const struct sched_class stop_sched_class = {
114 .next = &dl_sched_class,
116 .enqueue_task = enqueue_task_stop,
117 .dequeue_task = dequeue_task_stop,
118 .yield_task = yield_task_stop,
120 .check_preempt_curr = check_preempt_curr_stop,
122 .pick_next_task = pick_next_task_stop,
123 .put_prev_task = put_prev_task_stop,
125 #ifdef CONFIG_SMP
126 .select_task_rq = select_task_rq_stop,
127 .set_cpus_allowed = set_cpus_allowed_common,
128 #endif
130 .set_curr_task = set_curr_task_stop,
131 .task_tick = task_tick_stop,
133 .get_rr_interval = get_rr_interval_stop,
135 .prio_changed = prio_changed_stop,
136 .switched_to = switched_to_stop,
137 .update_curr = update_curr_stop,