mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: byungchul.park@lge.com
To: mingo@kernel.org, peterz@infradead.org
Cc: linux-kernel@vger.kernel.org, yuyang.du@intel.com,
	Byungchul Park <byungchul.park@lge.com>
Subject: [PATCH v3] sched: sync with the prev cfs when changing cgroup within a cpu
Date: Wed, 12 Aug 2015 16:05:15 +0900	[thread overview]
Message-ID: <1439363115-2259-1-git-send-email-byungchul.park@lge.com> (raw)

From: Byungchul Park <byungchul.park@lge.com>

change from v2 to v3
* rebase to tip git

change from v1 to v2
* use #ifdef CONFIG_SMP to load tracking code
* make commit message compact which made confused

----->8-----
>From 31c4509d09cd43bf52c12ef85716aa4c3b729b57 Mon Sep 17 00:00:00 2001
From: Byungchul Park <byungchul.park@lge.com>
Date: Wed, 12 Aug 2015 15:51:21 +0900
Subject: [PATCH v3] sched: sync with the prev cfs when changing cgroup within
 a cpu

current code seems to be wrong with cfs_rq's avg loads when changing
a task's cgroup(=cfs_rq) to another. i tested with "echo pid > cgroup" and
found that e.g. cfs_rq->avg.load_avg became larger and larger whenever i
changed a cgroup to another again and again.

we have to sync se's average load with both *prev* cfs_rq and next cfs_rq
when changing its group.

Signed-off-by: Byungchul Park <byungchul.park@lge.com>
---
 kernel/sched/fair.c |   24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 2a33d7b..25028b9 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8017,8 +8017,28 @@ static void task_move_group_fair(struct task_struct *p, int queued)
 	if (!queued && (!se->sum_exec_runtime || p->state == TASK_WAKING))
 		queued = 1;
 
-	if (!queued)
-		se->vruntime -= cfs_rq_of(se)->min_vruntime;
+	if (!queued) {
+		cfs_rq = cfs_rq_of(se);
+		se->vruntime -= cfs_rq->min_vruntime;
+
+#ifdef CONFIG_SMP
+		/*
+		 * synchronize task with its prev cfs_rq
+		 * remove our load when we leave
+		 */
+		__update_load_avg(cfs_rq->avg.last_update_time, cpu_of(rq_of(cfs_rq)), &se->avg,
+				se->on_rq * scale_load_down(se->load.weight), cfs_rq->curr == se, NULL);
+
+		cfs_rq->avg.load_avg =
+			max_t(long, cfs_rq->avg.load_avg - se->avg.load_avg, 0);
+		cfs_rq->avg.load_sum =
+			max_t(s64, cfs_rq->avg.load_sum - se->avg.load_sum, 0);
+		cfs_rq->avg.util_avg =
+			max_t(long, cfs_rq->avg.util_avg - se->avg.util_avg, 0);
+		cfs_rq->avg.util_sum =
+			max_t(s32, cfs_rq->avg.util_sum - se->avg.util_sum, 0);
+#endif
+	}
 	set_task_rq(p, task_cpu(p));
 	se->depth = se->parent ? se->parent->depth + 1 : 0;
 	if (!queued) {
-- 
1.7.9.5


             reply	other threads:[~2015-08-12  7:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-12  7:05 byungchul.park [this message]
2015-08-12  1:05 ` Yuyang Du
2015-08-12 23:57   ` Byungchul Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1439363115-2259-1-git-send-email-byungchul.park@lge.com \
    --to=byungchul.park@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=yuyang.du@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®