The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] sched/eevdf: Avoid NULL in pick_eevdf
@ 2023-11-20  7:38 Xuewen Yan
  2023-11-20  8:49 ` Abel Wu
  0 siblings, 1 reply; 5+ messages in thread
From: Xuewen Yan @ 2023-11-20  7:38 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid
  Cc: linux-kernel, ke.wang, xuewen.yan94

Now in pick_eevdf function, add the pick_first_entity to prevent
picking null when using eevdf, however, the leftmost may be null.
As a result, it would cause oops because the se is NULL.

Fix this by compare the curr and left, if the left is null, set
the se be curr.

Fixes: 147f3efaa241 ("sched/fair: Implement an EEVDF-like scheduling policy")
Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
---
 kernel/sched/fair.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index d7a3c63a2171..10916f6778ac 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -951,12 +951,28 @@ static struct sched_entity *__pick_eevdf(struct cfs_rq *cfs_rq)
 	return NULL;
 }
 
+/* Just simply choose the se with the smallest vruntime */
+static struct sched_entity *__pick_cfs(struct cfs_rq *cfs_rq)
+{
+	struct sched_entity *curr = cfs_rq->curr;
+	struct sched_entity *left = __pick_first_entity(cfs_rq);
+
+	/*
+	 * If curr is set we have to see if its left of the leftmost entity
+	 * still in the tree, provided there was anything in the tree at all.
+	 */
+	if (!left || (curr && entity_before(curr, left)))
+		left = curr;
+
+	return left;
+}
+
 static struct sched_entity *pick_eevdf(struct cfs_rq *cfs_rq)
 {
 	struct sched_entity *se = __pick_eevdf(cfs_rq);
 
 	if (!se) {
-		struct sched_entity *left = __pick_first_entity(cfs_rq);
+		struct sched_entity *left = __pick_cfs(cfs_rq);
 		if (left) {
 			pr_err("EEVDF scheduling fail, picking leftmost\n");
 			return left;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-12-12  3:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-20  7:38 [PATCH] sched/eevdf: Avoid NULL in pick_eevdf Xuewen Yan
2023-11-20  8:49 ` Abel Wu
2023-11-21  5:08   ` Xuewen Yan
2023-12-12  2:51   ` Xuewen Yan
2023-12-12  3:17     ` Abel Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox