lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 5 Oct 2015 18:16:23 +0900
From:	<byungchul.park@....com>
To:	mingo@...nel.org, peterz@...radead.org
CC:	linux-kernel@...r.kernel.org, yuyang.du@...el.com, pjt@...gle.com,
	efault@....de, tglx@...utronix.de,
	Byungchul Park <byungchul.park@....com>
Subject: [PATCH 1/2] sched: make fair sched class can handle the cgroup change by other class

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

Original fair sched class can handle the cgroup change occured within its
class with task_move_group_fair(), but there is no way to know it if the
change happened outside. This patch makes the fair sched class can handle
the change of cgroup which happened even at other sched class.

Additionally, it makes sched_move_task() more flexable so that any other
sched class can add task_move_group_xx() callback easily in future when
it is needed.

Signed-off-by: Byungchul Park <byungchul.park@....com>
---
 kernel/sched/core.c  |   17 +++++++++++------
 kernel/sched/fair.c  |   47 ++++++++++++++++++++++++++++++++++++++++-------
 kernel/sched/sched.h |    3 ++-
 3 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index a91df61..41b735e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7686,6 +7686,7 @@ void sched_offline_group(struct task_group *tg)
  */
 void sched_move_task(struct task_struct *tsk)
 {
+	const struct sched_class *class;
 	struct task_group *tg;
 	int queued, running;
 	unsigned long flags;
@@ -7711,12 +7712,16 @@ void sched_move_task(struct task_struct *tsk)
 	tg = autogroup_task_group(tsk, tg);
 	tsk->sched_task_group = tg;
 
-#ifdef CONFIG_FAIR_GROUP_SCHED
-	if (tsk->sched_class->task_move_group)
-		tsk->sched_class->task_move_group(tsk);
-	else
-#endif
-		set_task_rq(tsk, task_cpu(tsk));
+
+	for_each_class(class) {
+		if (class->task_move_group_from)
+			class->task_move_group_from(tsk);
+	}
+	set_task_rq(tsk, task_cpu(tsk));
+	for_each_class(class) {
+		if (class->task_move_group_to)
+			class->task_move_group_to(tsk);
+	}
 
 	if (unlikely(running))
 		tsk->sched_class->set_curr_task(rq);
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 077076f..e8dabc5 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8076,16 +8076,48 @@ void init_cfs_rq(struct cfs_rq *cfs_rq)
 }
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
-static void task_move_group_fair(struct task_struct *p)
+static void task_move_group_from_fair(struct task_struct *p)
 {
-	detach_task_cfs_rq(p);
-	set_task_rq(p, task_cpu(p));
+	struct sched_entity *se = &p->se;
+	struct cfs_rq *cfs_rq = cfs_rq_of(se);
+
+	if (p->sched_class == &fair_sched_class)
+		detach_task_cfs_rq(p);
+	else if (sched_feat(ATTACH_AGE_LOAD)) {
+		/*
+		 * Detaching was already done by switched_from_fair() when
+		 * the task got off from the fair_sched_class. But now that
+		 * the base cfs_rq for aging is about to be changed, if we
+		 * enabled ATTACH_AGE_LOAD then we perform the aging here
+		 * with the old cfs_rq, as the cfs_rq is not changed yet.
+		 */
+		__update_load_avg(cfs_rq->avg.last_update_time, task_cpu(p),
+				  &se->avg, 0, 0, NULL);
+	}
+}
+
+static void task_move_group_to_fair(struct task_struct *p)
+{
+	struct sched_entity *se = &p->se;
+	struct cfs_rq *cfs_rq = cfs_rq_of(se);
 
+	if (p->sched_class == &fair_sched_class) {
 #ifdef CONFIG_SMP
-	/* Tell se's cfs_rq has been changed -- migrated */
-	p->se.avg.last_update_time = 0;
+		/* Tell se's cfs_rq has been changed -- migrated */
+		se->avg.last_update_time = 0;
 #endif
-	attach_task_cfs_rq(p);
+		attach_task_cfs_rq(p);
+	}
+	else {
+		/*
+		 * Attaching will be done by switched_to_fair() when
+		 * the task is going to switch its sched_class to fair.
+		 * However, se->avg's last_update_time needs to be
+		 * updated here because the base cfs_rq for aging was
+		 * changed right now. (see sched_move_task().)
+		 */
+		se->avg.last_update_time = cfs_rq->avg.last_update_time;
+	}
 }
 
 void free_fair_sched_group(struct task_group *tg)
@@ -8305,7 +8337,8 @@ const struct sched_class fair_sched_class = {
 	.update_curr		= update_curr_fair,
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
-	.task_move_group	= task_move_group_fair,
+	.task_move_group_from	= task_move_group_from_fair,
+	.task_move_group_to	= task_move_group_to_fair,
 #endif
 };
 
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index af6f252..9432c66 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1220,7 +1220,8 @@ struct sched_class {
 	void (*update_curr) (struct rq *rq);
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
-	void (*task_move_group) (struct task_struct *p);
+	void (*task_move_group_from) (struct task_struct *p);
+	void (*task_move_group_to) (struct task_struct *p);
 #endif
 };
 
-- 
1.7.9.5

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ