public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add hierarchical accounting to cpu accounting controller
@ 2008-10-23  5:43 Bharata B Rao
  2008-10-23  6:41 ` Bharata B Rao
  2008-10-23 15:49 ` Paul Menage
  0 siblings, 2 replies; 28+ messages in thread
From: Bharata B Rao @ 2008-10-23  5:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: Srivatsa Vaddagiri, Peter Zijlstra, Ingo Molnar

Add hierarchical accounting to cpu accounting controller

Currently, while charging the task's cputime to its accounting group,
the accounting group hierarchy isn't updated. This patch charges the cputime
of a task to its accounting group and all its parent accounting groups.

Reported-by: Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>
Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
CC: Peter Zijlstra <a.p.zijlstra@chello.nl>
CC: Ingo Molnar <mingo@elte.hu>
---
 kernel/sched.c |   30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -9131,10 +9131,15 @@ struct cpuacct {
 	struct cgroup_subsys_state css;
 	/* cpuusage holds pointer to a u64-type object on every cpu */
 	u64 *cpuusage;
+	struct cpuacct *parent;
 };
 
+static struct cpuacct init_cpuacct_group;
 struct cgroup_subsys cpuacct_subsys;
 
+#define for_each_cpuacct_group(ca) \
+		for (; ca; ca = ca->parent)
+
 /* return cpu accounting group corresponding to this container */
 static inline struct cpuacct *cgroup_ca(struct cgroup *cgrp)
 {
@@ -9153,17 +9158,28 @@ static inline struct cpuacct *task_ca(st
 static struct cgroup_subsys_state *cpuacct_create(
 	struct cgroup_subsys *ss, struct cgroup *cgrp)
 {
-	struct cpuacct *ca = kzalloc(sizeof(*ca), GFP_KERNEL);
+	struct cpuacct *ca;
 
-	if (!ca)
-		return ERR_PTR(-ENOMEM);
+	if (!cgrp->parent) {
+		/* This is early initialization for the top cgroup */
+		ca = &init_cpuacct_group;
+	} else {
+		ca = kzalloc(sizeof(*ca), GFP_KERNEL);
+		if (!ca)
+			return ERR_PTR(-ENOMEM);
+	}
 
 	ca->cpuusage = alloc_percpu(u64);
 	if (!ca->cpuusage) {
-		kfree(ca);
+		if (cgrp->parent)
+			kfree(ca);
 		return ERR_PTR(-ENOMEM);
 	}
 
+	if (cgrp->parent) {
+		ca->css.cgroup = cgrp;
+		ca->parent = cgroup_ca(cgrp->parent);
+	}
 	return &ca->css;
 }
 
@@ -9243,14 +9259,16 @@ static int cpuacct_populate(struct cgrou
 static void cpuacct_charge(struct task_struct *tsk, u64 cputime)
 {
 	struct cpuacct *ca;
+	int cpu;
 
 	if (!cpuacct_subsys.active)
 		return;
 
+	cpu = task_cpu(tsk);
 	ca = task_ca(tsk);
-	if (ca) {
-		u64 *cpuusage = percpu_ptr(ca->cpuusage, task_cpu(tsk));
 
+	for_each_cpuacct_group(ca) {
+		u64 *cpuusage = percpu_ptr(ca->cpuusage, cpu);
 		*cpuusage += cputime;
 	}
 }

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2008-11-11 11:14 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-23  5:43 [PATCH] Add hierarchical accounting to cpu accounting controller Bharata B Rao
2008-10-23  6:41 ` Bharata B Rao
2008-10-23 15:49 ` Paul Menage
2008-10-24  5:08   ` Bharata B Rao
2008-10-24 17:37     ` Paul Menage
2008-10-25  6:01       ` Bharata B Rao
2008-10-25 15:38         ` Paul Menage
2008-10-27  1:17           ` KAMEZAWA Hiroyuki
2008-10-27  4:43             ` Bharata B Rao
2008-10-27  6:57               ` Balbir Singh
2008-10-27  8:25                 ` Li Zefan
2008-10-30 17:16                   ` Dhaval Giani
2008-10-31  0:40                     ` KAMEZAWA Hiroyuki
2008-11-04 12:49                       ` Bharata B Rao
2008-11-04 17:20                         ` Randy Dunlap
2008-11-05  3:24                           ` Bharata B Rao
2008-11-05  3:29                             ` Srivatsa Vaddagiri
2008-11-10 10:21                               ` Dhaval Giani
2008-11-10 13:09                             ` Ingo Molnar
2008-11-10 15:11                               ` Bharata B Rao
2008-11-11 11:13                                 ` Ingo Molnar
2008-11-05  6:17                         ` Li Zefan
2008-11-06  6:43                         ` Balbir Singh
2008-11-10 10:22                         ` Peter Zijlstra
2008-11-10 13:05                           ` Balbir Singh
2008-11-05  3:31                     ` Li Zefan
2008-11-05  3:48                       ` KAMEZAWA Hiroyuki
2008-10-27  5:54         ` Li Zefan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox