From: Johannes Weiner <hannes@cmpxchg.org>
To: Parag W <parag.lkml@gmail.com>
Cc: anna-maria@linutronix.de, frederic@kernel.org,
linux-kernel@vger.kernel.org, peterz@infradead.org,
pmenzel@molgen.mpg.de, regressions@lists.linux.dev,
surenb@google.com, tglx@linutronix.de
Subject: Re: Error: psi: inconsistent task state! task=1:swapper/0 cpu=0 psi_flags=4 clear=0 set=4
Date: Mon, 23 Sep 2024 11:46:01 -0400 [thread overview]
Message-ID: <20240923154601.GC437832@cmpxchg.org> (raw)
In-Reply-To: <20240923120339.11809-1-parag.lkml@gmail.com>
On Mon, Sep 23, 2024 at 08:03:39AM -0400, Parag W wrote:
> FWIW, moving psi_enqueue to be after ->enqueue_task() in
> sched/core.c made no difference - I still get the inconsistent task
> state error. psi_dequeue() is already before ->dequeue_task() in
> line with uclamp.
Yes, that isn't enough.
AFAICS, in psi want to know when a task gets dequeued from a core POV,
even if the class holds on to it until picked again. If it's later
picked and dequeued by the class, I don't think there is a possible
call into psi. Lastly, if a sched_delayed task is woken and enqueued
from core, psi wants to know - we should call psi_enqueue() after
->enqueue_task has cleared sched_delayed.
I don't think we want the ttwu_runnable() callback: since the task
hasn't been dequeued yet from a core & PSI perspective, we shouldn't
update psi states either. The sched_delayed check in psi_enqueue()
should accomplish that. Oh, but wait: ->enqueue_task() will clear
sched_delayed beforehand. We should probably filter ENQUEUE_DELAYED?
This leaves me with the below diff. But I'm still getting the double
enqueue with it applied:
[root@ham ~]# dmesg | grep -i psi
[ 0.350533] psi: inconsistent task state! task=1:swapper/0 cpu=0 psi_flags=4 clear=0 set=4
Peter, what am I missing here?
---
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b6cc1cf499d6..4f036c66cf07 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2012,11 +2012,6 @@ void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
if (!(flags & ENQUEUE_NOCLOCK))
update_rq_clock(rq);
- if (!(flags & ENQUEUE_RESTORE)) {
- sched_info_enqueue(rq, p);
- psi_enqueue(p, (flags & ENQUEUE_WAKEUP) && !(flags & ENQUEUE_MIGRATED));
- }
-
p->sched_class->enqueue_task(rq, p, flags);
/*
* Must be after ->enqueue_task() because ENQUEUE_DELAYED can clear
@@ -2024,6 +2019,11 @@ void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
*/
uclamp_rq_inc(rq, p);
+ if (!(flags & (ENQUEUE_RESTORE|ENQUEUE_DELAYED))) {
+ sched_info_enqueue(rq, p);
+ psi_enqueue(p, (flags & ENQUEUE_WAKEUP) && !(flags & ENQUEUE_MIGRATED));
+ }
+
if (sched_core_enabled(rq))
sched_core_enqueue(rq, p);
}
diff --git a/kernel/sched/stats.h b/kernel/sched/stats.h
index 237780aa3c53..138c52c2f2c9 100644
--- a/kernel/sched/stats.h
+++ b/kernel/sched/stats.h
@@ -129,6 +129,9 @@ static inline void psi_enqueue(struct task_struct *p, bool wakeup)
if (static_branch_likely(&psi_disabled))
return;
+ if (p->se.sched_delayed)
+ return;
+
if (p->in_memstall)
set |= TSK_MEMSTALL_RUNNING;
@@ -148,6 +151,9 @@ static inline void psi_dequeue(struct task_struct *p, bool sleep)
if (static_branch_likely(&psi_disabled))
return;
+ if (p->se.sched_delayed)
+ return;
+
/*
* A voluntary sleep is a dequeue followed by a task switch. To
* avoid walking all ancestors twice, psi_task_switch() handles
next prev parent reply other threads:[~2024-09-23 15:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-21 22:50 Error: psi: inconsistent task state! task=1:swapper/0 cpu=0 psi_flags=4 clear=0 set=4 Paul Menzel
2024-09-22 6:53 ` Paul Menzel
2024-09-22 10:20 ` Johannes Weiner
2024-09-23 12:03 ` Parag W
2024-09-23 15:46 ` Johannes Weiner [this message]
2024-10-01 1:21 ` Johannes Weiner
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=20240923154601.GC437832@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=anna-maria@linutronix.de \
--cc=frederic@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=parag.lkml@gmail.com \
--cc=peterz@infradead.org \
--cc=pmenzel@molgen.mpg.de \
--cc=regressions@lists.linux.dev \
--cc=surenb@google.com \
--cc=tglx@linutronix.de \
/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