mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH] sched/fair: update the vruntime to be max vruntime when yield
@ 2023-02-22  8:03 Xuewen Yan
  2023-02-27  1:51 ` Xuewen Yan
  2023-02-27 15:40 ` Peter Zijlstra
  0 siblings, 2 replies; 21+ messages in thread
From: Xuewen Yan @ 2023-02-22  8:03 UTC (permalink / raw)
  To: vincent.guittot, mingo, peterz, juri.lelli, dietmar.eggemann
  Cc: rostedt, bsegall, mgorman, bristot, vschneid, qyousef,
	linux-kernel, ke.wang, zhaoyang.huang

When task call the sched_yield, cfs would set the cfs's skip buddy.
If there is no other task call the sched_yield syscall, the task would
always be skiped when there are tasks in rq. As a result, the task's
vruntime would not be updated for long time, and the cfs's min_vruntime
is almost not updated.
When this scenario happens, when the yield task had wait for a long time,
and other tasks run a long time, once there is other task call the sched_yield,
the cfs's skip_buddy is covered, at this time, the first task can run normally,
but the task's vruntime is small, as a result, the task would always run,
because other task's vruntime is big. This would lead to other tasks can not
run for a long time.
In order to mitigate this, update the yield_task's vruntime to be cfs's max vruntime.
This way, the cfs's min vruntime can be updated as the process running.

Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
---
 kernel/sched/fair.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index ff4dbbae3b10..a9ff1921fc07 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -670,7 +670,6 @@ static struct sched_entity *__pick_next_entity(struct sched_entity *se)
 	return __node_2_se(next);
 }
 
-#ifdef CONFIG_SCHED_DEBUG
 struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq)
 {
 	struct rb_node *last = rb_last(&cfs_rq->tasks_timeline.rb_root);
@@ -681,6 +680,7 @@ struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq)
 	return __node_2_se(last);
 }
 
+#ifdef CONFIG_SCHED_DEBUG
 /**************************************************************
  * Scheduling class statistics methods:
  */
@@ -7751,8 +7751,18 @@ static void set_next_buddy(struct sched_entity *se)
 
 static void set_skip_buddy(struct sched_entity *se)
 {
-	for_each_sched_entity(se)
-		cfs_rq_of(se)->skip = se;
+	for_each_sched_entity(se) {
+		struct sched_entity *last;
+		struct cfs_rq *cfs_rq = cfs_rq_of(se);
+
+		last = __pick_last_entity(cfs_rq);
+		if (last) {
+			se->vruntime = last->vruntime;
+			update_min_vruntime(cfs_rq);
+		}
+
+		cfs_rq->skip = se;
+	}
 }
 
 /*
-- 
2.25.1


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

end of thread, other threads:[~2023-08-26 20:47 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-22  8:03 [RFC PATCH] sched/fair: update the vruntime to be max vruntime when yield Xuewen Yan
2023-02-27  1:51 ` Xuewen Yan
2023-02-27 15:40 ` Peter Zijlstra
2023-02-27 16:21   ` Steven Rostedt
2023-02-27 22:07   ` Qais Yousef
2023-02-28  7:42     ` Xuewen Yan
2023-02-28  7:53       ` Vincent Guittot
2023-02-28  8:20         ` Xuewen Yan
2023-02-28  9:07           ` Vincent Guittot
2023-02-28 13:31             ` Qais Yousef
2023-02-28 13:45               ` Vincent Guittot
2023-03-01  7:30                 ` Xuewen Yan
2023-03-01  8:09                   ` Vincent Guittot
2023-03-01  8:20                     ` Xuewen Yan
2023-03-01 11:23                       ` Dietmar Eggemann
2023-03-01 13:29                         ` Vincent Guittot
2023-06-30 14:40                       ` Qais Yousef
2023-08-21  7:51                         ` Xuewen Yan
2023-08-22 15:54                           ` Vincent Guittot
2023-08-23  2:03                             ` Xuewen Yan
2023-08-26 20:46                               ` Qais Yousef

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

all inboxes | Powered by JetHome®