Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sched: Initialize the vruntime of a new task when it is first enqueued

When creating a new task, we initialize vruntime of the newly task at
sched_cgroup_fork(). However, the timing of executing this action is too
early and may not be accurate.

Because it uses current CPU to init the vruntime, but the new task
actually runs on the cpu which be assigned at wake_up_new_task().

To optimize this case, we pass ENQUEUE_INITIAL flag to activate_task()
in wake_up_new_task(), in this way, when place_entity is called in
enqueue_entity(), the vruntime of the new task will be initialized.

In addition, place_entity() in task_fork_fair() was introduced for two
reasons:
1. Previously, the __enqueue_entity() was in task_new_fair(),
in order to provide vruntime for enqueueing the newly task, the
vruntime assignment equation "se->vruntime = cfs_rq->min_vruntime" was
introduced by commit e9acbff6484d ("sched: introduce se->vruntime").
This is the initial state of place_entity().

2. commit 4d78e7b656aa ("sched: new task placement for vruntime") added
child_runs_first task placement feature which based on vruntime, this
also requires the new task's vruntime value.

After removing the child_runs_first and enqueue_entity() from
task_fork_fair(), this place_entity() no longer makes sense, so remove
it also.

Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20240627133359.1370598-1-zhangqiao22@huawei.com

authored by

Zhang Qiao and committed by
Peter Zijlstra
c40dd90a fe7a11c7

+1 -16
+1 -1
kernel/sched/core.c
··· 4686 4686 update_rq_clock(rq); 4687 4687 post_init_entity_util_avg(p); 4688 4688 4689 - activate_task(rq, p, ENQUEUE_NOCLOCK); 4689 + activate_task(rq, p, ENQUEUE_NOCLOCK | ENQUEUE_INITIAL); 4690 4690 trace_sched_wakeup_new(p); 4691 4691 wakeup_preempt(rq, p, WF_FORK); 4692 4692 #ifdef CONFIG_SMP
-15
kernel/sched/fair.c
··· 12702 12702 */ 12703 12703 static void task_fork_fair(struct task_struct *p) 12704 12704 { 12705 - struct sched_entity *se = &p->se, *curr; 12706 - struct cfs_rq *cfs_rq; 12707 - struct rq *rq = this_rq(); 12708 - struct rq_flags rf; 12709 - 12710 - rq_lock(rq, &rf); 12711 - update_rq_clock(rq); 12712 - 12713 12705 set_task_max_allowed_capacity(p); 12714 - 12715 - cfs_rq = task_cfs_rq(current); 12716 - curr = cfs_rq->curr; 12717 - if (curr) 12718 - update_curr(cfs_rq); 12719 - place_entity(cfs_rq, se, ENQUEUE_INITIAL); 12720 - rq_unlock(rq, &rf); 12721 12706 } 12722 12707 12723 12708 /*