From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752127AbbHTLXU (ORCPT ); Thu, 20 Aug 2015 07:23:20 -0400 Received: from lgeamrelo04.lge.com ([156.147.1.127]:43177 "EHLO lgeamrelo04.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751401AbbHTLWl (ORCPT ); Thu, 20 Aug 2015 07:22:41 -0400 X-Original-SENDERIP: 10.177.222.33 X-Original-MAILFROM: byungchul.park@lge.com From: byungchul.park@lge.com To: mingo@kernel.org, peterz@infradead.org Cc: linux-kernel@vger.kernel.org, yuyang.du@intel.com, Byungchul Park Subject: [PATCH v4 4/5] sched: sync a se with its cfs_rq when switching sched class to fair class Date: Thu, 20 Aug 2015 20:21:59 +0900 Message-Id: <1440069720-27038-5-git-send-email-byungchul.park@lge.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1440069720-27038-1-git-send-email-byungchul.park@lge.com> References: <1440069720-27038-1-git-send-email-byungchul.park@lge.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Byungchul Park we have to sync a se with its cfs_rq, when switching sched class to fair class. current code does not sync it because the se average load won't be valid any more if it has been dettached for a long time. however the se's average load would be valid just after being detached from cfs_rq, so we need to sync it in that case, e.g. priority inheritance. to solve the problem that a se average load becomes more useless over time, this patch decays its average load even for the duration that the se has been detached, when it gets attached to the cfs_rq. Signed-off-by: Byungchul Park --- kernel/sched/fair.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d58e9aa..af6ad5f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2712,6 +2712,18 @@ 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, more care should be taken + * because se's cfs_rq was changed, that means calling __update_load_avg + * with new cfs_rq->avg.last_update_time is meaningless. So we skip the + * update here. We have to update it with prev cfs_rq just before changing + * se's cfs_rq, and get here soon. + */ + 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; @@ -7945,6 +7957,9 @@ static void switched_to_fair(struct rq *rq, struct task_struct *p) se->depth = se->parent ? se->parent->depth + 1 : 0; #endif + /* Synchronize task with its cfs_rq */ + attach_entity_load_avg(cfs_rq_of(&p->se), &p->se); + if (!task_on_rq_queued(p)) { /* @@ -8044,6 +8059,10 @@ static void task_move_group_fair(struct task_struct *p, int queued) /* Synchronize task with its prev cfs_rq */ detach_entity_load_avg(cfs_rq, se); set_task_rq(p, task_cpu(p)); + + /* Tell se's cfs_rq has been changed -- migrated */ + p->se.avg.last_update_time = 0; + se->depth = se->parent ? se->parent->depth + 1 : 0; cfs_rq = cfs_rq_of(se); if (!queued) -- 1.7.9.5