[<prev] [next>] [day] [month] [year] [list]
Message-ID: <fca528bb34394de3a7e87a873fadd9df@honor.com>
Date: Sat, 21 Jun 2025 04:09:55 +0000
From: liuwenfang <liuwenfang@...or.com>
To: 'Tejun Heo' <tj@...nel.org>
CC: 'David Vernet' <void@...ifault.com>, 'Andrea Righi' <arighi@...dia.com>,
'Changwoo Min' <changwoo@...lia.com>, 'Ingo Molnar' <mingo@...hat.com>,
'Peter Zijlstra' <peterz@...radead.org>, 'Juri Lelli'
<juri.lelli@...hat.com>, 'Vincent Guittot' <vincent.guittot@...aro.org>,
'Dietmar Eggemann' <dietmar.eggemann@....com>, 'Steven Rostedt'
<rostedt@...dmis.org>, 'Ben Segall' <bsegall@...gle.com>, 'Mel Gorman'
<mgorman@...e.de>, 'Valentin Schneider' <vschneid@...hat.com>,
"'linux-kernel@...r.kernel.org'" <linux-kernel@...r.kernel.org>
Subject: [PATCH] sched_ext: Fix cpu_released while RT task and SCX task are
scheduled concurrently
Supposed RT task(rt1) is running on one CPU with its rq->scx.cpu_released
set to true, if the rt1 becomes sleeping, then the scheduler will balance
the remote SCX task(scx1) because there is no other RT task on its rq,
and rq->scx.cpu_released is false. While one RT task(rt2) is placed on
this rq(maybe rt2 wakeup or migration occurs) before the scx1 is enqueued,
then the scheduler will pick rt2. At last, rt2 will be running on this cpu
with rq->scx.cpu_released being false!
The main reason is that consume_remote_task() will unlock rq lock.
So, expose the switch_class() and check sched class again to fix the value
of rq->scx.cpu_released.
Signed-off-by: liuwenfang liuwenfang@...or.com
---
kernel/sched/ext.c | 2 +-
kernel/sched/sched.h | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index f5133249f..6bbea0ea1 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -3187,7 +3187,7 @@ preempt_reason_from_class(const struct sched_class *class)
return SCX_CPU_PREEMPT_UNKNOWN;
}
-static void switch_class(struct rq *rq, struct task_struct *next)
+void switch_class(struct rq *rq, struct task_struct *next)
{
const struct sched_class *next_class = next->sched_class;
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 47972f34e..d377075d0 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1738,6 +1738,7 @@ static inline void scx_rq_clock_invalidate(struct rq *rq)
WRITE_ONCE(rq->scx.flags, rq->scx.flags & ~SCX_RQ_CLK_VALID);
}
+void switch_class(struct rq *rq, struct task_struct *next);
#else /* !CONFIG_SCHED_CLASS_EXT */
#define scx_enabled() false
#define scx_switched_all() false
@@ -2470,6 +2471,11 @@ static inline void put_prev_set_next_task(struct rq *rq,
prev->sched_class->put_prev_task(rq, prev, next);
next->sched_class->set_next_task(rq, next, true);
+
+#ifdef CONFIG_SCHED_CLASS_EXT
+ if (scx_enabled())
+ switch_class(rq, next);
+#endif
}
/*
--
2.17.1
Powered by blists - more mailing lists