Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sched: Add sched_class->switching_to() and expose check_class_changing/changed()

When a task switches to a new sched_class, the prev and new classes are
notified through ->switched_from() and ->switched_to(), respectively, after
the switching is done.

A new BPF extensible sched_class will have callbacks that allow the BPF
scheduler to keep track of relevant task states (like priority and cpumask).
Those callbacks aren't called while a task is on a different sched_class.
When a task comes back, we wanna tell the BPF progs the up-to-date state
before the task gets enqueued, so we need a hook which is called before the
switching is committed.

This patch adds ->switching_to() which is called during sched_class switch
through check_class_changing() before the task is restored. Also, this patch
exposes check_class_changing/changed() in kernel/sched/sched.h. They will be
used by the new BPF extensible sched_class to implement implicit sched_class
switching which is used e.g. when falling back to CFS when the BPF scheduler
fails or unloads.

This is a prep patch and doesn't cause any behavior changes. The new
operation and exposed functions aren't used yet.

v3: Refreshed on top of tip:sched/core.

v2: Improve patch description w/ details on planned use.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: David Vernet <dvernet@meta.com>
Acked-by: Josh Don <joshdon@google.com>
Acked-by: Hao Luo <haoluo@google.com>
Acked-by: Barret Rhoden <brho@google.com>

+16
+12
kernel/sched/core.c
··· 2036 2036 } 2037 2037 2038 2038 /* 2039 + * ->switching_to() is called with the pi_lock and rq_lock held and must not 2040 + * mess with locking. 2041 + */ 2042 + void check_class_changing(struct rq *rq, struct task_struct *p, 2043 + const struct sched_class *prev_class) 2044 + { 2045 + if (prev_class != p->sched_class && p->sched_class->switching_to) 2046 + p->sched_class->switching_to(rq, p); 2047 + } 2048 + 2049 + /* 2039 2050 * switched_from, switched_to and prio_changed must _NOT_ drop rq->lock, 2040 2051 * use the balance_callback list if you want balancing. 2041 2052 * ··· 7032 7021 } 7033 7022 7034 7023 __setscheduler_prio(p, prio); 7024 + check_class_changing(rq, p, prev_class); 7035 7025 7036 7026 if (queued) 7037 7027 enqueue_task(rq, p, queue_flag);
+3
kernel/sched/sched.h
··· 2322 2322 * cannot assume the switched_from/switched_to pair is serialized by 2323 2323 * rq->lock. They are however serialized by p->pi_lock. 2324 2324 */ 2325 + void (*switching_to) (struct rq *this_rq, struct task_struct *task); 2325 2326 void (*switched_from)(struct rq *this_rq, struct task_struct *task); 2326 2327 void (*switched_to) (struct rq *this_rq, struct task_struct *task); 2327 2328 void (*reweight_task)(struct rq *this_rq, struct task_struct *task, ··· 3609 3608 extern void enqueue_task(struct rq *rq, struct task_struct *p, int flags); 3610 3609 extern void dequeue_task(struct rq *rq, struct task_struct *p, int flags); 3611 3610 3611 + extern void check_class_changing(struct rq *rq, struct task_struct *p, 3612 + const struct sched_class *prev_class); 3612 3613 extern void check_class_changed(struct rq *rq, struct task_struct *p, 3613 3614 const struct sched_class *prev_class, 3614 3615 int oldprio);
+1
kernel/sched/syscalls.c
··· 797 797 __setscheduler_prio(p, newprio); 798 798 } 799 799 __setscheduler_uclamp(p, attr); 800 + check_class_changing(rq, p, prev_class); 800 801 801 802 if (queued) { 802 803 /*