From: Bharata B Rao <bharata@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: Balaji Rao <balajirrao@gmail.com>,
Dhaval Giani <dhaval@linux.vnet.ibm.com>,
Balbir Singh <balbir@linux.vnet.ibm.com>,
Li Zefan <lizf@cn.fujitsu.com>, Paul Menage <menage@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Subject: [RFC PATCH] cpuacct: per-cgroup utime/stime statistics - v1
Date: Tue, 10 Mar 2009 18:12:08 +0530 [thread overview]
Message-ID: <20090310124208.GC3902@in.ibm.com> (raw)
Hi,
Based on the comments received during my last post
(http://lkml.org/lkml/2009/2/25/129), here is a fresh attempt
to get per-cgroup utime/stime statistics as part of cpuacct controller.
This patch adds a new file cpuacct.stat which displays two stats:
utime and stime. I wasn't too sure about the usefulness of providing
per-cgroup guest and steal times and hence not including them here.
Note that I am using percpu_counter for collecting these two stats.
Since percpu_counter subsystem doesn't protect the readside, readers could
theoritically obtain incorrect values for these stats on 32bit systems.
I hope occasional wrong values is not too much of a concern for
statistics like this. If it is a problem, we have to either fix
percpu_counter or do it all by ourselves as Kamezawa attempted
for cpuacct.usage (http://lkml.org/lkml/2009/3/4/14)
Regards,
Bharata.
cpuacct: Add stime and utime statistics
Add per-cgroup cpuacct controller statistics like the system and user
time consumed by the group of tasks.
Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Signed-off-by: Balaji Rao <balajirrao@gmail.com>
---
Documentation/cgroups/cpuacct.txt | 8 +++
kernel/sched.c | 87 +++++++++++++++++++++++++++++++++++---
2 files changed, 89 insertions(+), 6 deletions(-)
--- a/Documentation/cgroups/cpuacct.txt
+++ b/Documentation/cgroups/cpuacct.txt
@@ -30,3 +30,11 @@ The above steps create a new group g1 an
process (bash) into it. CPU time consumed by this bash and its children
can be obtained from g1/cpuacct.usage and the same is accumulated in
/cgroups/cpuacct.usage also.
+
+cpuacct.stat file lists a few statistics which further divide the
+CPU time obtained by the cgroup into user and system times. Currently
+the following statistics are supported:
+
+utime: Time in milliseconds spent by tasks of the cgroup in user mode.
+stime: Time in milliseconds spent by tasks of the cgroup in kernel mode.
+
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -1393,10 +1393,22 @@ iter_move_one_task(struct rq *this_rq, i
struct rq_iterator *iterator);
#endif
+/* Time spent by the tasks of the cpu accounting group executing in ... */
+enum cpuacct_stat_index {
+ CPUACCT_STAT_UTIME, /* ... user mode */
+ CPUACCT_STAT_STIME, /* ... kernel mode */
+
+ CPUACCT_STAT_NSTATS,
+};
+
#ifdef CONFIG_CGROUP_CPUACCT
static void cpuacct_charge(struct task_struct *tsk, u64 cputime);
+static void cpuacct_update_stats(struct task_struct *tsk,
+ enum cpuacct_stat_index idx, int val);
#else
static inline void cpuacct_charge(struct task_struct *tsk, u64 cputime) {}
+static void cpuacct_update_stats(struct task_struct *tsk,
+ enum cpuacct_stat_index idx, int val) {}
#endif
static inline void inc_cpu_load(struct rq *rq, unsigned long load)
@@ -4182,6 +4194,8 @@ void account_user_time(struct task_struc
cpustat->nice = cputime64_add(cpustat->nice, tmp);
else
cpustat->user = cputime64_add(cpustat->user, tmp);
+
+ cpuacct_update_stats(p, CPUACCT_STAT_UTIME, cputime_to_msecs(cputime));
/* Account for user time used */
acct_update_integrals(p);
}
@@ -4243,6 +4257,8 @@ void account_system_time(struct task_str
else
cpustat->system = cputime64_add(cpustat->system, tmp);
+ cpuacct_update_stats(p, CPUACCT_STAT_STIME, cputime_to_msecs(cputime));
+
/* Account for system time used */
acct_update_integrals(p);
}
@@ -9438,6 +9454,7 @@ struct cpuacct {
struct cgroup_subsys_state css;
/* cpuusage holds pointer to a u64-type object on every cpu */
u64 *cpuusage;
+ struct percpu_counter cpustat[CPUACCT_STAT_NSTATS];
struct cpuacct *parent;
};
@@ -9462,20 +9479,33 @@ static struct cgroup_subsys_state *cpuac
struct cgroup_subsys *ss, struct cgroup *cgrp)
{
struct cpuacct *ca = kzalloc(sizeof(*ca), GFP_KERNEL);
+ int i;
if (!ca)
- return ERR_PTR(-ENOMEM);
+ goto out1;
ca->cpuusage = alloc_percpu(u64);
- if (!ca->cpuusage) {
- kfree(ca);
- return ERR_PTR(-ENOMEM);
- }
+ if (!ca->cpuusage)
+ goto out2;
+
+ for (i = 0; i < CPUACCT_STAT_NSTATS; i++)
+ if (percpu_counter_init(&ca->cpustat[i], 0))
+ goto out3;
if (cgrp->parent)
ca->parent = cgroup_ca(cgrp->parent);
return &ca->css;
+
+out3:
+ i--;
+ while (i-- >= 0)
+ percpu_counter_destroy(&ca->cpustat[i]);
+ free_percpu(ca->cpuusage);
+out2:
+ kfree(ca);
+out1:
+ return ERR_PTR(-ENOMEM);
}
/* destroy an existing cpu accounting group */
@@ -9483,7 +9513,10 @@ static void
cpuacct_destroy(struct cgroup_subsys *ss, struct cgroup *cgrp)
{
struct cpuacct *ca = cgroup_ca(cgrp);
+ int i;
+ for (i = 0; i < CPUACCT_STAT_NSTATS; i++)
+ percpu_counter_destroy(&ca->cpustat[i]);
free_percpu(ca->cpuusage);
kfree(ca);
}
@@ -9570,6 +9603,28 @@ static int cpuacct_percpu_seq_read(struc
return 0;
}
+static const struct cpuacct_stat_desc {
+ const char *msg;
+ u64 unit;
+} cpuacct_stat_desc[] = {
+ [CPUACCT_STAT_UTIME] = { "utime", 1, },
+ [CPUACCT_STAT_STIME] = { "stime", 1, },
+};
+
+static int cpuacct_stats_show(struct cgroup *cgrp, struct cftype *cft,
+ struct cgroup_map_cb *cb)
+{
+ struct cpuacct *ca = cgroup_ca(cgrp);
+ int i;
+
+ for (i = 0; i < CPUACCT_STAT_NSTATS; i++) {
+ s64 val = percpu_counter_read(&ca->cpustat[i]);
+ val *= cpuacct_stat_desc[i].unit;
+ cb->fill(cb, cpuacct_stat_desc[i].msg, val);
+ }
+ return 0;
+}
+
static struct cftype files[] = {
{
.name = "usage",
@@ -9580,7 +9635,10 @@ static struct cftype files[] = {
.name = "usage_percpu",
.read_seq_string = cpuacct_percpu_seq_read,
},
-
+ {
+ .name = "stat",
+ .read_map = cpuacct_stats_show,
+ },
};
static int cpuacct_populate(struct cgroup_subsys *ss, struct cgroup *cgrp)
@@ -9610,6 +9668,23 @@ static void cpuacct_charge(struct task_s
}
}
+/*
+ * Account the system/user time to the task's accounting group.
+ */
+static void cpuacct_update_stats(struct task_struct *tsk,
+ enum cpuacct_stat_index idx, int val)
+{
+ struct cpuacct *ca;
+
+ if (!cpuacct_subsys.active)
+ return;
+
+ ca = task_ca(tsk);
+
+ for (; ca; ca = ca->parent)
+ percpu_counter_add(&ca->cpustat[idx], val);
+}
+
struct cgroup_subsys cpuacct_subsys = {
.name = "cpuacct",
.create = cpuacct_create,
next reply other threads:[~2009-03-10 12:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-10 12:42 Bharata B Rao [this message]
2009-03-11 0:38 ` [RFC PATCH] cpuacct: per-cgroup utime/stime statistics - v1 KAMEZAWA Hiroyuki
2009-03-11 8:53 ` Bharata B Rao
2009-03-11 9:13 ` KAMEZAWA Hiroyuki
2009-03-11 15:34 ` Balbir Singh
2009-03-12 0:14 ` KAMEZAWA Hiroyuki
2009-03-12 4:29 ` Bharata B Rao
2009-03-12 4:35 ` Balbir Singh
2009-03-11 1:15 ` Li Zefan
2009-03-11 8:54 ` Bharata B Rao
2009-03-11 15:16 ` Balbir Singh
2009-03-11 16:44 ` Balbir Singh
2009-03-12 4:44 ` Bharata B Rao
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=20090310124208.GC3902@in.ibm.com \
--to=bharata@linux.vnet.ibm.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=balajirrao@gmail.com \
--cc=balbir@linux.vnet.ibm.com \
--cc=dhaval@linux.vnet.ibm.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizf@cn.fujitsu.com \
--cc=menage@google.com \
--cc=mingo@elte.hu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.