diff options
author | Paul Menage <menage@google.com> | 2007-10-29 16:18:11 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2007-10-29 16:18:11 -0400 |
commit | fe5c7cc22897b809a2fbe05bea71963853df7f17 (patch) | |
tree | 6690ef27dbe5cf15a48cbb95c03b5e3e7950f5e9 /kernel | |
parent | ae8393e508e5f17add66964688c49bf0bfe4fcf9 (diff) |
sched: report CPU usage in CFS cgroup directories
Adds a cpu.usage file to the CFS cgroup that reports CPU usage in
milliseconds for that cgroup's tasks
[ mingo@elte.hu: style cleanups. ]
Signed-off-by: Paul Menage <menage@google.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/sched.c | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/kernel/sched.c b/kernel/sched.c index 470480790f3f..6c4abfbd68e6 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -7211,15 +7211,43 @@ static u64 cpu_shares_read_uint(struct cgroup *cgrp, struct cftype *cft) | |||
7211 | return (u64) tg->shares; | 7211 | return (u64) tg->shares; |
7212 | } | 7212 | } |
7213 | 7213 | ||
7214 | static struct cftype cpu_shares = { | 7214 | static u64 cpu_usage_read(struct cgroup *cgrp, struct cftype *cft) |
7215 | .name = "shares", | 7215 | { |
7216 | .read_uint = cpu_shares_read_uint, | 7216 | struct task_group *tg = cgroup_tg(cgrp); |
7217 | .write_uint = cpu_shares_write_uint, | 7217 | unsigned long flags; |
7218 | u64 res = 0; | ||
7219 | int i; | ||
7220 | |||
7221 | for_each_possible_cpu(i) { | ||
7222 | /* | ||
7223 | * Lock to prevent races with updating 64-bit counters | ||
7224 | * on 32-bit arches. | ||
7225 | */ | ||
7226 | spin_lock_irqsave(&cpu_rq(i)->lock, flags); | ||
7227 | res += tg->se[i]->sum_exec_runtime; | ||
7228 | spin_unlock_irqrestore(&cpu_rq(i)->lock, flags); | ||
7229 | } | ||
7230 | /* Convert from ns to ms */ | ||
7231 | do_div(res, 1000000); | ||
7232 | |||
7233 | return res; | ||
7234 | } | ||
7235 | |||
7236 | static struct cftype cpu_files[] = { | ||
7237 | { | ||
7238 | .name = "shares", | ||
7239 | .read_uint = cpu_shares_read_uint, | ||
7240 | .write_uint = cpu_shares_write_uint, | ||
7241 | }, | ||
7242 | { | ||
7243 | .name = "usage", | ||
7244 | .read_uint = cpu_usage_read, | ||
7245 | }, | ||
7218 | }; | 7246 | }; |
7219 | 7247 | ||
7220 | static int cpu_cgroup_populate(struct cgroup_subsys *ss, struct cgroup *cont) | 7248 | static int cpu_cgroup_populate(struct cgroup_subsys *ss, struct cgroup *cont) |
7221 | { | 7249 | { |
7222 | return cgroup_add_file(cont, ss, &cpu_shares); | 7250 | return cgroup_add_files(cont, ss, cpu_files, ARRAY_SIZE(cpu_files)); |
7223 | } | 7251 | } |
7224 | 7252 | ||
7225 | struct cgroup_subsys cpu_cgroup_subsys = { | 7253 | struct cgroup_subsys cpu_cgroup_subsys = { |