File Index
Files and directories
Sign in
FILE

stop_task.c

File preview with syntax highlighting.

linux-6.19.14/kernel/sched/stop_task.c C
  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
 12static int
 13select_task_rq_stop(struct task_struct *p, int cpu, int flags)
 14{
 15	return task_cpu(p); /* stop tasks as never migrate */
 16}
 17
 18static int
 19balance_stop(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
 20{
 21	return sched_stop_runnable(rq);
 22}
 23
 24static void
 25wakeup_preempt_stop(struct rq *rq, struct task_struct *p, int flags)
 26{
 27	/* we're never preempted */
 28}
 29
 30static 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
 35static 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
 43static void
 44enqueue_task_stop(struct rq *rq, struct task_struct *p, int flags)
 45{
 46	add_nr_running(rq, 1);
 47}
 48
 49static bool
 50dequeue_task_stop(struct rq *rq, struct task_struct *p, int flags)
 51{
 52	sub_nr_running(rq, 1);
 53	return true;
 54}
 55
 56static void yield_task_stop(struct rq *rq)
 57{
 58	BUG(); /* the stop task should never yield, its pointless. */
 59}
 60
 61static 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 */
 74static void task_tick_stop(struct rq *rq, struct task_struct *curr, int queued)
 75{
 76}
 77
 78static void switching_to_stop(struct rq *rq, struct task_struct *p)
 79{
 80	BUG(); /* its impossible to change to this class */
 81}
 82
 83static void
 84prio_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
 92static void update_curr_stop(struct rq *rq)
 93{
 94}
 95
 96/*
 97 * Simple, special scheduling class for the per-CPU stop tasks:
 98 */
 99DEFINE_SCHED_CLASS(stop) = {
100
101	.queue_mask		= 16,
102
103	.enqueue_task		= enqueue_task_stop,
104	.dequeue_task		= dequeue_task_stop,
105	.yield_task		= yield_task_stop,
106
107	.wakeup_preempt		= wakeup_preempt_stop,
108
109	.pick_task		= pick_task_stop,
110	.put_prev_task		= put_prev_task_stop,
111	.set_next_task          = set_next_task_stop,
112
113	.balance		= balance_stop,
114	.select_task_rq		= select_task_rq_stop,
115	.set_cpus_allowed	= set_cpus_allowed_common,
116
117	.task_tick		= task_tick_stop,
118
119	.prio_changed		= prio_changed_stop,
120	.switching_to		= switching_to_stop,
121	.update_curr		= update_curr_stop,
122};
~/ Read-only file preview.