public inbox for linux-next@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: vschneid@redhat.com, linux-kernel@vger.kernel.org,
	sfr@canb.auug.org.au, linux-next@vger.kernel.org,
	kernel-team@meta.com
Subject: Re: [BUG almost bisected] Splat in dequeue_rt_stack() and build error
Date: Thu, 3 Oct 2024 20:50:37 +0200	[thread overview]
Message-ID: <20241003185037.GA5594@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <7b14822a-ee98-4e46-9828-1e41b1ce76f3@paulmck-laptop>

On Thu, Oct 03, 2024 at 09:04:30AM -0700, Paul E. McKenney wrote:
> On Thu, Oct 03, 2024 at 04:22:40PM +0200, Peter Zijlstra wrote:
> > On Thu, Oct 03, 2024 at 05:45:47AM -0700, Paul E. McKenney wrote:
> > 
> > > I ran 100*TREE03 for 18 hours each, and got 23 instances of *something*
> > > happening (and I need to suppress stalls on the repeat).  One of the
> > > earlier bugs happened early, but sadly not this one.
> > 
> > Damn, I don't have the amount of CPU hours available you mention in your
> > later email. I'll just go up the rounds to 20 minutes and see if
> > something wants to go bang before I have to shut down the noise
> > pollution for the day...
> 
> Indeed, this was one reason I was soliciting debug patches.  ;-)

Sooo... I was contemplating if something like the below might perhaps
help some. It's a bit of a mess (I'll try and clean up if/when it
actually proves to work), but it compiles and survives a hand full of 1m
runs.

I'll try and give it more runs tomorrow when I can power up the big
machines again -- unless you've already told me it's crap by then :-)

---
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 43e453ab7e20..1fe850788195 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7010,20 +7010,20 @@ int default_wake_function(wait_queue_entry_t *curr, unsigned mode, int wake_flag
 }
 EXPORT_SYMBOL(default_wake_function);
 
-void __setscheduler_prio(struct task_struct *p, int prio)
+const struct sched_class *__setscheduler_class(struct task_struct *p, int prio)
 {
 	if (dl_prio(prio))
-		p->sched_class = &dl_sched_class;
-	else if (rt_prio(prio))
-		p->sched_class = &rt_sched_class;
+		return &dl_sched_class;
+
+	if (rt_prio(prio))
+		return &rt_sched_class;
+
 #ifdef CONFIG_SCHED_CLASS_EXT
-	else if (task_should_scx(p))
-		p->sched_class = &ext_sched_class;
+	if (task_should_scx(p))
+		return &ext_sched_class;
 #endif
-	else
-		p->sched_class = &fair_sched_class;
 
-	p->prio = prio;
+	return &fair_sched_class;
 }
 
 #ifdef CONFIG_RT_MUTEXES
@@ -7069,7 +7069,7 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
 {
 	int prio, oldprio, queued, running, queue_flag =
 		DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK;
-	const struct sched_class *prev_class;
+	const struct sched_class *prev_class, *next_class;
 	struct rq_flags rf;
 	struct rq *rq;
 
@@ -7127,6 +7127,11 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
 		queue_flag &= ~DEQUEUE_MOVE;
 
 	prev_class = p->sched_class;
+	next_class = __setscheduler_class(p, prio);
+
+	if (prev_class != next_class && p->se.sched_delayed)
+		dequeue_task(rq, p, DEQUEUE_SLEEP | DEQUEUE_DELAYED | DEQUEUE_NOCLOCK);
+
 	queued = task_on_rq_queued(p);
 	running = task_current(rq, p);
 	if (queued)
@@ -7164,7 +7169,9 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
 			p->rt.timeout = 0;
 	}
 
-	__setscheduler_prio(p, prio);
+	p->sched_class = next_class;
+	p->prio = prio;
+
 	check_class_changing(rq, p, prev_class);
 
 	if (queued)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index ab497fafa7be..c157d4860a3b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -13177,22 +13177,6 @@ static void attach_task_cfs_rq(struct task_struct *p)
 static void switched_from_fair(struct rq *rq, struct task_struct *p)
 {
 	detach_task_cfs_rq(p);
-	/*
-	 * Since this is called after changing class, this is a little weird
-	 * and we cannot use DEQUEUE_DELAYED.
-	 */
-	if (p->se.sched_delayed) {
-		/* First, dequeue it from its new class' structures */
-		dequeue_task(rq, p, DEQUEUE_NOCLOCK | DEQUEUE_SLEEP);
-		/*
-		 * Now, clean up the fair_sched_class side of things
-		 * related to sched_delayed being true and that wasn't done
-		 * due to the generic dequeue not using DEQUEUE_DELAYED.
-		 */
-		finish_delayed_dequeue_entity(&p->se);
-		p->se.rel_deadline = 0;
-		__block_task(rq, p);
-	}
 }
 
 static void switched_to_fair(struct rq *rq, struct task_struct *p)
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index b1c3588a8f00..fba524c81c63 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3797,7 +3797,7 @@ static inline int rt_effective_prio(struct task_struct *p, int prio)
 
 extern int __sched_setscheduler(struct task_struct *p, const struct sched_attr *attr, bool user, bool pi);
 extern int __sched_setaffinity(struct task_struct *p, struct affinity_context *ctx);
-extern void __setscheduler_prio(struct task_struct *p, int prio);
+extern const struct sched_class *__setscheduler_class(struct task_struct *p, int prio);
 extern void set_load_weight(struct task_struct *p, bool update_load);
 extern void enqueue_task(struct rq *rq, struct task_struct *p, int flags);
 extern bool dequeue_task(struct rq *rq, struct task_struct *p, int flags);
diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
index aa70beee9895..0470bcc3d204 100644
--- a/kernel/sched/syscalls.c
+++ b/kernel/sched/syscalls.c
@@ -529,7 +529,7 @@ int __sched_setscheduler(struct task_struct *p,
 {
 	int oldpolicy = -1, policy = attr->sched_policy;
 	int retval, oldprio, newprio, queued, running;
-	const struct sched_class *prev_class;
+	const struct sched_class *prev_class, *next_class;
 	struct balance_callback *head;
 	struct rq_flags rf;
 	int reset_on_fork;
@@ -706,6 +706,12 @@ int __sched_setscheduler(struct task_struct *p,
 			queue_flags &= ~DEQUEUE_MOVE;
 	}
 
+	prev_class = p->sched_class;
+	next_class = __setscheduler_class(p, newprio);
+
+	if (prev_class != next_class && p->se.sched_delayed)
+		dequeue_task(rq, p, DEQUEUE_SLEEP | DEQUEUE_DELAYED | DEQUEUE_NOCLOCK);
+
 	queued = task_on_rq_queued(p);
 	running = task_current(rq, p);
 	if (queued)
@@ -713,11 +719,10 @@ int __sched_setscheduler(struct task_struct *p,
 	if (running)
 		put_prev_task(rq, p);
 
-	prev_class = p->sched_class;
-
 	if (!(attr->sched_flags & SCHED_FLAG_KEEP_PARAMS)) {
 		__setscheduler_params(p, attr);
-		__setscheduler_prio(p, newprio);
+		p->sched_class = next_class;
+		p->prio = newprio;
 	}
 	__setscheduler_uclamp(p, attr);
 	check_class_changing(rq, p, prev_class);

  reply	other threads:[~2024-10-03 18:50 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-21 21:57 [BUG almost bisected] Splat in dequeue_rt_stack() and build error Paul E. McKenney
2024-08-22 23:01 ` Paul E. McKenney
2024-08-23  7:47 ` Peter Zijlstra
2024-08-23 12:46   ` Paul E. McKenney
2024-08-23 21:51     ` Paul E. McKenney
2024-08-24  6:54       ` Peter Zijlstra
2024-08-24 15:26         ` Paul E. McKenney
2024-08-25  2:10           ` Paul E. McKenney
2024-08-25 19:36             ` Paul E. McKenney
2024-08-26 11:44   ` Valentin Schneider
2024-08-26 16:31     ` Paul E. McKenney
2024-08-27 10:03       ` Valentin Schneider
2024-08-27 15:41         ` Valentin Schneider
2024-08-27 17:33           ` Paul E. McKenney
2024-08-27 18:35             ` Paul E. McKenney
2024-08-27 20:30               ` Valentin Schneider
2024-08-27 20:36                 ` Paul E. McKenney
2024-08-28 12:35                   ` Valentin Schneider
2024-08-28 13:03                     ` Paul E. McKenney
2024-08-28 13:40                       ` Paul E. McKenney
2024-08-28 13:44                     ` Chen Yu
2024-08-28 14:32                       ` Valentin Schneider
2024-08-28 16:35                         ` Paul E. McKenney
2024-08-28 18:17                           ` Valentin Schneider
2024-08-28 18:39                             ` Paul E. McKenney
2024-08-29 10:28                               ` Paul E. McKenney
2024-08-29 13:50                                 ` Valentin Schneider
2024-08-29 14:13                                   ` Paul E. McKenney
2024-09-08 16:32                                     ` Paul E. McKenney
2024-09-13 14:08                                       ` Paul E. McKenney
2024-09-13 16:55                                         ` Valentin Schneider
2024-09-13 18:00                                           ` Paul E. McKenney
2024-09-30 19:09                                             ` Paul E. McKenney
2024-09-30 20:44                                               ` Valentin Schneider
2024-10-01 10:10                                                 ` Paul E. McKenney
2024-10-01 12:52                                                   ` Valentin Schneider
2024-10-01 16:47                                                     ` Paul E. McKenney
2024-10-02  9:01                                                       ` Tomas Glozar
2024-10-02 12:07                                                         ` Paul E. McKenney
2024-10-10 11:24                                                         ` Tomas Glozar
2024-10-10 15:01                                                           ` Paul E. McKenney
2024-10-10 23:28                                                             ` Paul E. McKenney
2024-10-14 18:55                                                               ` Paul E. McKenney
2024-10-21 19:25                                                                 ` Paul E. McKenney
2024-11-14 18:16                                                                   ` Paul E. McKenney
2024-12-15 18:31                                                                     ` Paul E. McKenney
2024-12-16 14:38                                                                       ` Tomas Glozar
2024-12-16 19:36                                                                         ` Paul E. McKenney
2024-12-17 16:42                                                                           ` Paul E. McKenney
2024-10-22  6:33                                                           ` Tomas Glozar
2024-10-03  8:40 ` Peter Zijlstra
2024-10-03  8:47   ` Peter Zijlstra
2024-10-03  9:27     ` Peter Zijlstra
2024-10-03 12:28       ` Peter Zijlstra
2024-10-03 12:45         ` Paul E. McKenney
2024-10-03 14:22           ` Peter Zijlstra
2024-10-03 16:04             ` Paul E. McKenney
2024-10-03 18:50               ` Peter Zijlstra [this message]
2024-10-03 19:12                 ` Paul E. McKenney
2024-10-04 13:22                 ` Paul E. McKenney
2024-10-04 13:35                 ` Peter Zijlstra
2024-10-06 20:44                   ` Paul E. McKenney
2024-10-07  9:34                     ` Peter Zijlstra
2024-10-08 11:11                     ` Peter Zijlstra
2024-10-08 16:24                       ` Paul E. McKenney
2024-10-08 22:34                         ` Paul E. McKenney
2024-10-03 12:44       ` Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241003185037.GA5594@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=sfr@canb.auug.org.au \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox