Skip to contentSkip to conversation

sched/fair: Initiate a new task's util avg to a bounded value

PATCH In review Yuyang Du 3 participants 3 messages Mar 30, 2016 – Mar 31, 2016 Scheduler

lore
Share & tools
lore

Yuyang Du

author
#0 lore raw

PATCH v2 1/1 sched/fair: Initiate a new task's util avg to a bounded value

Hi Peter,

It looks like this patch is left last year. I fixed a bug - it did not init task group's entities.

And I started this new thread to attend to it.

Please refer to the link for the previous version and some data experimented:

http://article.gmane.org/gmane.linux.kernel/2117689

Would you please give it a look?

Thanks,
Yuyang

---
Subject: [PATCH v2] sched/fair: Initiate a new task's util avg to a bounded
value

A new task's util_avg is set to full utilization of a CPU (100% time running). This accelerates a new task's utilization ramp-up, useful to boost its execution in early time. However, it may result in (insanely) high utilization for a transient time period when a flood of tasks are spawned. Importantly, it violates the "fundamentally bounded" CPU utilization, and its side effect is negative if we don't take any measure to bound it.

This patch proposes an algorithm to address this issue. It has two methods to approach a sensible initial util_avg:

(1) An expected (or average) util_avg based on its cfs_rq's util_avg:

util_avg = cfs_rq->util_avg / (cfs_rq->load_avg + 1) * se.load.weight

(2) A trajectory of how successive new tasks' util develops, which gives 1/2 of the left utilization budget to a new task such that the additional util is noticeably large (when overall util is low) or unnoticeably small (when overall util is high enough). In the meantime, the aggregate utilization is well bounded:

util_avg_cap = (1024 - cfs_rq->avg.util_avg) / 2^n

where n denotes the nth task.

If util_avg is larger than util_avg_cap, then the effective util is clamped to the util_avg_cap.

---
 kernel/sched/core.c  |  2 ++
 kernel/sched/fair.c  | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 kernel/sched/sched.h |  1 +
 3 files changed, 58 insertions(+), 2 deletions(-)
kernel/sched/core.c +2 -0
index 0b21e7a..49180f6 100644
@@ -2413,6 +2413,8 @@ void wake_up_new_task(struct task_struct *p)
 	 */
 	set_task_cpu(p, select_task_rq(p, task_cpu(p), SD_BALANCE_FORK, 0));
 #endif
+	/* Post initialize new task's util average when its cfs_rq is set */
+	post_init_entity_util_avg(&p->se);
 
 	rq = __task_rq_lock(p);
 	activate_task(rq, p, 0);
kernel/sched/fair.c +55 -2

78 lines not on this page · raw message

kernel/sched/sched.h +1 -0
index e6d4a3f..0283235 100644
@@ -1313,6 +1313,7 @@ extern void init_dl_task_timer(struct sched_dl_entity *dl_se);
 unsigned long to_ratio(u64 period, u64 runtime);
 
 extern void init_entity_runnable_average(struct sched_entity *se);
+extern void post_init_entity_util_avg(struct sched_entity *se);
 
 #ifdef CONFIG_NO_HZ_FULL
 extern bool sched_can_stop_tick(struct rq *rq);
Signature · 1 line
2.1.4
maintainer
#1 lore raw
Quoted 5 lines · Yuyang Du

Hi Peter,

It looks like this patch is left last year. I fixed a bug - it did not init task group's entities.

Quoted 7 lines

And I started this new thread to attend to it.

Please refer to the link for the previous version and some data experimented:

http://article.gmane.org/gmane.linux.kernel/2117689

Would you please give it a look?

Ah yes, sorry I seem to have totally missed all that, its been a hectic few months.

Yes, this looks nice, I'll stuff it in, see what happens ;-)

#2 lore raw
In reply to Yuyang Du
sched/fair: Initiate a new task's util avg to a bounded value
Commit-ID:  2b8c41daba327c633228169e8bd8ec067ab443f8
Gitweb:     http://git.kernel.org/tip/2b8c41daba327c633228169e8bd8ec067ab443f8
Author:     Yuyang Du <[email protected]>
AuthorDate: Wed, 30 Mar 2016 04:30:56 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 31 Mar 2016 10:49:46 +0200

sched/fair: Initiate a new task's util avg to a bounded value

A new task's util_avg is set to full utilization of a CPU (100% time running). This accelerates a new task's utilization ramp-up, useful to boost its execution in early time. However, it may result in (insanely) high utilization for a transient time period when a flood of tasks are spawned. Importantly, it violates the "fundamentally bounded" CPU utilization, and its side effect is negative if we don't take any measure to bound it.

This patch proposes an algorithm to address this issue. It has two methods to approach a sensible initial util_avg:

(1) An expected (or average) util_avg based on its cfs_rq's util_avg:

util_avg = cfs_rq->util_avg / (cfs_rq->load_avg + 1) * se.load.weight

(2) A trajectory of how successive new tasks' util develops, which gives 1/2 of the left utilization budget to a new task such that the additional util is noticeably large (when overall util is low) or unnoticeably small (when overall util is high enough). In the meantime, the aggregate utilization is well bounded:

util_avg_cap = (1024 - cfs_rq->avg.util_avg) / 2^n

where n denotes the nth task.

If util_avg is larger than util_avg_cap, then the effective util is clamped to the util_avg_cap.

---
 kernel/sched/core.c  |  2 ++
 kernel/sched/fair.c  | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 kernel/sched/sched.h |  1 +
 3 files changed, 57 insertions(+), 2 deletions(-)
kernel/sched/core.c +2 -0
index b5cf01d..1159423 100644
@@ -2431,6 +2431,8 @@ void wake_up_new_task(struct task_struct *p)
 	 */
 	set_task_cpu(p, select_task_rq(p, task_cpu(p), SD_BALANCE_FORK, 0));
 #endif
+	/* Post initialize new task's util average when its cfs_rq is set */
+	post_init_entity_util_avg(&p->se);
 
 	rq = __task_rq_lock(p);
 	activate_task(rq, p, 0);
kernel/sched/fair.c +54 -2

77 lines not on this page · raw message

kernel/sched/sched.h +1 -0
index ec2e8d2..a7cbad7 100644
@@ -1313,6 +1313,7 @@ extern void init_dl_task_timer(struct sched_dl_entity *dl_se);
 unsigned long to_ratio(u64 period, u64 runtime);
 
 extern void init_entity_runnable_average(struct sched_entity *se);
+extern void post_init_entity_util_avg(struct sched_entity *se);
 
 #ifdef CONFIG_NO_HZ_FULL
 extern bool sched_can_stop_tick(struct rq *rq);