0001 =========================
0002 CPU Accounting Controller
0003 =========================
0004
0005 The CPU accounting controller is used to group tasks using cgroups and
0006 account the CPU usage of these groups of tasks.
0007
0008 The CPU accounting controller supports multi-hierarchy groups. An accounting
0009 group accumulates the CPU usage of all of its child groups and the tasks
0010 directly present in its group.
0011
0012 Accounting groups can be created by first mounting the cgroup filesystem::
0013
0014 # mount -t cgroup -ocpuacct none /sys/fs/cgroup
0015
0016 With the above step, the initial or the parent accounting group becomes
0017 visible at /sys/fs/cgroup. At bootup, this group includes all the tasks in
0018 the system. /sys/fs/cgroup/tasks lists the tasks in this cgroup.
0019 /sys/fs/cgroup/cpuacct.usage gives the CPU time (in nanoseconds) obtained
0020 by this group which is essentially the CPU time obtained by all the tasks
0021 in the system.
0022
0023 New accounting groups can be created under the parent group /sys/fs/cgroup::
0024
0025 # cd /sys/fs/cgroup
0026 # mkdir g1
0027 # echo $$ > g1/tasks
0028
0029 The above steps create a new group g1 and move the current shell
0030 process (bash) into it. CPU time consumed by this bash and its children
0031 can be obtained from g1/cpuacct.usage and the same is accumulated in
0032 /sys/fs/cgroup/cpuacct.usage also.
0033
0034 cpuacct.stat file lists a few statistics which further divide the
0035 CPU time obtained by the cgroup into user and system times. Currently
0036 the following statistics are supported:
0037
0038 user: Time spent by tasks of the cgroup in user mode.
0039 system: Time spent by tasks of the cgroup in kernel mode.
0040
0041 user and system are in USER_HZ unit.
0042
0043 cpuacct controller uses percpu_counter interface to collect user and
0044 system times. This has two side effects:
0045
0046 - It is theoretically possible to see wrong values for user and system times.
0047 This is because percpu_counter_read() on 32bit systems isn't safe
0048 against concurrent writes.
0049 - It is possible to see slightly outdated values for user and system times
0050 due to the batch processing nature of percpu_counter.