at commit 205cccd0
| 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 | |
| 12 | static int |
| 13 | select_task_rq_stop(struct task_struct *p, int cpu, int flags) |
| 14 | { |
| 15 | return task_cpu(p); /* stop tasks as never migrate */ |
| 16 | } |
| 17 | |
| 18 | static int |
| 19 | balance_stop(struct rq *rq, struct rq_flags *rf) |
| 20 | { |
| 21 | return sched_stop_runnable(rq); |
| 22 | } |
| 23 | |
| 24 | static void |
| 25 | wakeup_preempt_stop(struct rq *rq, struct task_struct *p, int flags) |
| 26 | { |
| 27 | /* we're never preempted */ |
| 28 | } |
| 29 | |
| 30 | static void set_next_task_stop(struct rq *rq, struct task_struct *stop, bool first) |
| 31 | { |
| 32 | stop->se.exec_start = rq_clock_task(rq); |
| 33 | } |
| 34 | |
| 35 | static struct task_struct *pick_task_stop(struct rq *rq, struct rq_flags *rf) |
| 36 | { |
| 37 | if (!sched_stop_runnable(rq)) |
| 38 | return NULL; |
| 39 | |
| 40 | return rq->stop; |
| 41 | } |
| 42 | |
| 43 | static void |
| 44 | enqueue_task_stop(struct rq *rq, struct task_struct *p, int flags) |
| 45 | { |
| 46 | add_nr_running(rq, 1); |
| 47 | } |
| 48 | |
| 49 | static bool |
| 50 | dequeue_task_stop(struct rq *rq, struct task_struct *p, int flags) |
| 51 | { |
| 52 | sub_nr_running(rq, 1); |
| 53 | return true; |
| 54 | } |
| 55 | |
| 56 | static void yield_task_stop(struct rq *rq) |
| 57 | { |
| 58 | BUG(); /* the stop task should never yield, its pointless. */ |
| 59 | } |
| 60 | |
| 61 | static void put_prev_task_stop(struct rq *rq, struct task_struct *prev, struct task_struct *next) |
| 62 | { |
| 63 | update_curr_common(rq); |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * scheduler tick hitting a task of our scheduling class. |
| 68 | * |
| 69 | * NOTE: This function can be called remotely by the tick offload that |
| 70 | * goes along full dynticks. Therefore no local assumption can be made |
| 71 | * and everything must be accessed through the @rq and @curr passed in |
| 72 | * parameters. |
| 73 | */ |
| 74 | static void task_tick_stop(struct rq *rq, struct task_struct *curr, int queued) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | static void switching_to_stop(struct rq *rq, struct task_struct *p) |
| 79 | { |
| 80 | BUG(); /* its impossible to change to this class */ |
| 81 | } |
| 82 | |
| 83 | static void |
| 84 | prio_changed_stop(struct rq *rq, struct task_struct *p, u64 oldprio) |
| 85 | { |
| 86 | if (p->prio == oldprio) |
| 87 | return; |
| 88 | |
| 89 | BUG(); /* how!?, what priority? */ |
| 90 | } |
| 91 | |
| 92 | static void update_curr_stop(struct rq *rq) |
| 93 | { |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * Simple, special scheduling class for the per-CPU stop tasks: |
| 98 | */ |
| 99 | DEFINE_SCHED_CLASS(stop) = { |
| 100 | .enqueue_task = enqueue_task_stop, |
| 101 | .dequeue_task = dequeue_task_stop, |
| 102 | .yield_task = yield_task_stop, |
| 103 | |
| 104 | .wakeup_preempt = wakeup_preempt_stop, |
| 105 | |
| 106 | .pick_task = pick_task_stop, |
| 107 | .put_prev_task = put_prev_task_stop, |
| 108 | .set_next_task = set_next_task_stop, |
| 109 | |
| 110 | .balance = balance_stop, |
| 111 | .select_task_rq = select_task_rq_stop, |
| 112 | .set_cpus_allowed = set_cpus_allowed_common, |
| 113 | |
| 114 | .task_tick = task_tick_stop, |
| 115 | |
| 116 | .prio_changed = prio_changed_stop, |
| 117 | .switching_to = switching_to_stop, |
| 118 | .update_curr = update_curr_stop, |
| 119 | }; |