Skip to contentSkip to conversation

cpuacct: per-cgroup utime/stime statistics - v5

PATCH In review Bharata B Rao 2 participants 3 messages Mar 24, 2009 – Mar 25, 2009 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpuacct: per-cgroup utime/stime statistics - v5

Hi,

Here is the next and hopefully final version of the cpuacct statistics patch to obtain per-cgroup system and user times.

Thanks for reviewing and tolerating so many iterations :)

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.

Changelog:

v5
- In cpuacct_stats_show(), use cputime64_to_clock_t() since we are operating on a 64bit variable here.

v4
- Remove comments in cpuacct_update_stats() which explained why rcu_read_lock() was needed (as per Peter Zijlstra's review comments).
- Don't say that percpu_counter_read() is broken in Documentation/cpuacct.txt as per KAMEZAWA Hiroyuki's review comments.

v3
- Fix a small race in the cpuacct hierarchy walk.

v2
- stime and utime now exported in clock_t units instead of msecs.
- Addressed the code review comments from Balbir and Li Zefan.
- Moved to -tip tree.

v1
- Moved the stime/utime accounting to cpuacct controller.

Earlier versions
- http://lkml.org/lkml/2009/2/25/129

---
 Documentation/cgroups/cpuacct.txt |   18 +++++++
 kernel/sched.c                    |   88 +++++++++++++++++++++++++++++++++++---
 2 files changed, 100 insertions(+), 6 deletions(-)
Documentation/cgroups/cpuacct.txt +18 -0
@@ -30,3 +30,21 @@ 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 spent by tasks of the cgroup in user mode.
+stime: Time spent by tasks of the cgroup in kernel mode.
+
+utime and stime are in USER_HZ unit.
+
+cpuacct controller uses percpu_counter interface to collect utime and
+stime. This causes two side effects:
+
+- It is theoretically possible to see wrong values for stime and utime.
+  This is because percpu_counter_read() on 32bit systems isn't safe
+  against concurrent writes.
+- It is possible to see slightly outdated values for stime and utime
+  due to the batch processing nature of percpu_counter.
kernel/sched.c +82 -6

156 lines not on this page · raw message

Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines

cpuacct: Add stime and utime statistics

Add per-cgroup cpuacct controller statistics like the system and user time consumed by the group of tasks.

except a bug below.

kernel/sched.c static struct cgroup_subsys_state *cpuac · line 9789

Quoted 13 lines
kernel/sched.c +8 -0
+	for (i = 0; i < CPUACCT_STAT_NSTATS; i++)
+		if (percpu_counter_init(&ca->cpustat[i], 0))
+			goto out_free_counters;
 
 	if (cgrp->parent)
 		ca->parent = cgroup_ca(cgrp->parent);
 
 	return &ca->css;
+
+out_free_counters:
+	i--;
+	while (i-- >= 0)
+		percpu_counter_destroy(&ca->cpustat[i]);

replace "i--; while (i-- >=0)" to "while (--i >=0)", otherwise you'll be accessing ca->cpustat[-1].

Quoted 6 lines
kernel/sched.c +5 -0
+	free_percpu(ca->cpuusage);
+out_free_ca:
+	kfree(ca);
+out:
+	return ERR_PTR(-ENOMEM);
 }
#2 lore raw
Quoted 6 lines · Li Zefan
Quoted 4 lines

cpuacct: Add stime and utime statistics

Add per-cgroup cpuacct controller statistics like the system and user time consumed by the group of tasks.

Thanks.

Quoted 10 lines

except a bug below.

Quoted 7 lines
kernel/sched.c +3 -0
+	for (i = 0; i < CPUACCT_STAT_NSTATS; i++)
+		if (percpu_counter_init(&ca->cpustat[i], 0))
+			goto out_free_counters;
 
 	if (cgrp->parent)
 		ca->parent = cgroup_ca(cgrp->parent);
Quoted 9 lines

kernel/sched.c static struct cgroup_subsys_state *cpuac · line 9789

Quoted 6 lines
kernel/sched.c +5 -0
 	return &ca->css;
+
+out_free_counters:
+	i--;
+	while (i-- >= 0)
+		percpu_counter_destroy(&ca->cpustat[i]);

replace "i--; while (i-- >=0)" to "while (--i >=0)", otherwise you'll be accessing ca->cpustat[-1].

Sorry about this. Posted the fixed version.

Regards,
Bharata.