| 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 task_struct *prev, 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) | 
|---|
| 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, count: 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, count: 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 switched_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, int oldprio) | 
|---|
| 85 | { | 
|---|
| 86 | BUG(); /* how!?, what priority? */ | 
|---|
| 87 | } | 
|---|
| 88 |  | 
|---|
| 89 | static void update_curr_stop(struct rq *rq) | 
|---|
| 90 | { | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | /* | 
|---|
| 94 | * Simple, special scheduling class for the per-CPU stop tasks: | 
|---|
| 95 | */ | 
|---|
| 96 | DEFINE_SCHED_CLASS(stop) = { | 
|---|
| 97 |  | 
|---|
| 98 | .enqueue_task		= enqueue_task_stop, | 
|---|
| 99 | .dequeue_task		= dequeue_task_stop, | 
|---|
| 100 | .yield_task		= yield_task_stop, | 
|---|
| 101 |  | 
|---|
| 102 | .wakeup_preempt		= wakeup_preempt_stop, | 
|---|
| 103 |  | 
|---|
| 104 | .pick_task		= pick_task_stop, | 
|---|
| 105 | .put_prev_task		= put_prev_task_stop, | 
|---|
| 106 | .set_next_task          = set_next_task_stop, | 
|---|
| 107 |  | 
|---|
| 108 | .balance		= balance_stop, | 
|---|
| 109 | .select_task_rq		= select_task_rq_stop, | 
|---|
| 110 | .set_cpus_allowed	= set_cpus_allowed_common, | 
|---|
| 111 |  | 
|---|
| 112 | .task_tick		= task_tick_stop, | 
|---|
| 113 |  | 
|---|
| 114 | .prio_changed		= prio_changed_stop, | 
|---|
| 115 | .switched_to		= switched_to_stop, | 
|---|
| 116 | .update_curr		= update_curr_stop, | 
|---|
| 117 | }; | 
|---|
| 118 |  | 
|---|