[PATCH v2 3/3] sched: decay a detached se when it's attached to its cfs_rq

From: byungchul . park
Date: Mon Aug 17 2015 - 03:46:47 EST


From: Byungchul Park <byungchul.park@xxxxxxx>

se's load can be valuable just after being detached from cfs_rq, however
it will become useless over time, e.g. in case of switching to another
sched class and switching back to fair class.

therefore even in case where se is already detached from cfs, decaying
its load is necessary when it gets attached back to cfs_rq.

Signed-off-by: Byungchul Park <byungchul.park@xxxxxxx>
---
kernel/sched/fair.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 346f2a6..554c9b7 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2711,6 +2711,14 @@ static inline void update_load_avg(struct sched_entity *se, int update_tg)

static void attach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se)
{
+ /*
+ * in case of migration and cgroup-change, cfs_rq has been changed.
+ * therfore, updating load should be already performed before.
+ */
+ if (se->avg.last_update_time)
+ __update_load_avg(cfs_rq->avg.last_update_time, cpu_of(rq_of(cfs_rq)),
+ &se->avg, 0, 0, NULL);
+
se->avg.last_update_time = cfs_rq->avg.last_update_time;
cfs_rq->avg.load_avg += se->avg.load_avg;
cfs_rq->avg.load_sum += se->avg.load_sum;
@@ -8045,6 +8053,9 @@ static void task_move_group_fair(struct task_struct *p, int queued)
{
detach_task_cfs_rq(p, queued);
set_task_rq(p, task_cpu(p));
+
+ /* Tell cfs_rq has been changed */
+ p->se.avg.last_update_time = 0;
attach_task_cfs_rq(p, queued);
}

--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/