[PATCH v2 2/2] sched: Fix sched_child_runs_first

Zhang Qiao posted 2 patches 3 years, 5 months ago
[PATCH v2 2/2] sched: Fix sched_child_runs_first
Posted by Zhang Qiao 3 years, 5 months ago
There are two cases that the sched_child_runs_first maybe not
work fine:
1) when call clone3() with CLONE_INTO_CGROUP flags, will creating
the child task into a cgroup different from the parent's cgroup,
so that child and parent's cfs_rq is diffent.
2) Assign a different cpu to the new task when fork balancing.

Above two case, the child and the parent will attach to different
cpu and cfs_rq. At this time, we can't swap the child and parent's
vruntime, and i think only do swap vruntime when the parent and
child in the same cfs_rq. This patch will add the cfs_rq check
before swap vruntime.

Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
---
 kernel/sched/fair.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 34845d425180..6061ceb1b7cb 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -11612,7 +11612,9 @@ static void task_fork_fair(struct task_struct *p)
 	}
 	place_entity(cfs_rq, se, 1);
 
-	if (sysctl_sched_child_runs_first && curr && entity_before(curr, se)) {
+	if (sysctl_sched_child_runs_first &&
+		cfs_rq == task_cfs_rq(current) &&
+		curr && entity_before(curr, se)) {
 		/*
 		 * Upon rescheduling, sched_class::put_prev_task() will place
 		 * 'current' within the tree based on its new key value.
-- 
2.17.1