Commit 1ae5f5df authored by Peter Zijlstra's avatar Peter Zijlstra
Browse files

sched: Cleanup sched_delayed handling for class switches



Use the new sched_class::switching_from() method to dequeue delayed
tasks before switching to another class.

Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarVincent Guittot <vincent.guittot@linaro.org>
Reviewed-by: default avatarJuri Lelli <juri.lelli@redhat.com>
Acked-by: default avatarTejun Heo <tj@kernel.org>
parent 637b0682
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -7366,9 +7366,6 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
	if (prev_class != next_class)
		queue_flag |= DEQUEUE_CLASS;

	if (prev_class != next_class && p->se.sched_delayed)
		dequeue_task(rq, p, DEQUEUE_SLEEP | DEQUEUE_DELAYED | DEQUEUE_NOCLOCK);

	scoped_guard (sched_change, p, queue_flag) {
		/*
		 * Boosting condition are:
@@ -10840,9 +10837,16 @@ struct sched_change_ctx *sched_change_begin(struct task_struct *p, unsigned int
	lockdep_assert_rq_held(rq);

	if (flags & DEQUEUE_CLASS) {
		if (p->sched_class->switching_from)
		if (p->sched_class->switching_from) {
			/*
			 * switching_from_fair() assumes CLASS implies NOCLOCK;
			 * fixing this assumption would mean switching_from()
			 * would need to be able to change flags.
			 */
			WARN_ON(!(flags & DEQUEUE_NOCLOCK));
			p->sched_class->switching_from(rq, p);
		}
	}

	*ctx = (struct sched_change_ctx){
		.p = p,
+0 −6
Original line number Diff line number Diff line
@@ -3922,9 +3922,6 @@ static void scx_disable_workfn(struct kthread_work *work)
		if (old_class != new_class)
			queue_flags |= DEQUEUE_CLASS;

		if (old_class != new_class && p->se.sched_delayed)
			dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEUE_DELAYED | DEQUEUE_NOCLOCK);

		scoped_guard (sched_change, p, queue_flags) {
			p->sched_class = new_class;
		}
@@ -4673,9 +4670,6 @@ static int scx_enable(struct sched_ext_ops *ops, struct bpf_link *link)
		if (old_class != new_class)
			queue_flags |= DEQUEUE_CLASS;

		if (old_class != new_class && p->se.sched_delayed)
			dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEUE_DELAYED | DEQUEUE_NOCLOCK);

		scoped_guard (sched_change, p, queue_flags) {
			p->scx.slice = SCX_SLICE_DFL;
			p->sched_class = new_class;
+7 −0
Original line number Diff line number Diff line
@@ -13249,6 +13249,12 @@ static void attach_task_cfs_rq(struct task_struct *p)
	attach_entity_cfs_rq(se);
}

static void switching_from_fair(struct rq *rq, struct task_struct *p)
{
	if (p->se.sched_delayed)
		dequeue_task(rq, p, DEQUEUE_SLEEP | DEQUEUE_DELAYED | DEQUEUE_NOCLOCK);
}

static void switched_from_fair(struct rq *rq, struct task_struct *p)
{
	detach_task_cfs_rq(p);
@@ -13650,6 +13656,7 @@ DEFINE_SCHED_CLASS(fair) = {

	.reweight_task		= reweight_task_fair,
	.prio_changed		= prio_changed_fair,
	.switching_from		= switching_from_fair,
	.switched_from		= switched_from_fair,
	.switched_to		= switched_to_fair,

+0 −3
Original line number Diff line number Diff line
@@ -687,9 +687,6 @@ int __sched_setscheduler(struct task_struct *p,
	if (prev_class != next_class)
		queue_flags |= DEQUEUE_CLASS;

	if (prev_class != next_class && p->se.sched_delayed)
		dequeue_task(rq, p, DEQUEUE_SLEEP | DEQUEUE_DELAYED | DEQUEUE_NOCLOCK);

	scoped_guard (sched_change, p, queue_flags) {

		if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS)) {