Path: blob/master/Documentation/cgroups/cpuacct.txt
10821 views
CPU Accounting Controller1-------------------------23The CPU accounting controller is used to group tasks using cgroups and4account the CPU usage of these groups of tasks.56The CPU accounting controller supports multi-hierarchy groups. An accounting7group accumulates the CPU usage of all of its child groups and the tasks8directly present in its group.910Accounting groups can be created by first mounting the cgroup filesystem.1112# mount -t cgroup -ocpuacct none /sys/fs/cgroup1314With the above step, the initial or the parent accounting group becomes15visible at /sys/fs/cgroup. At bootup, this group includes all the tasks in16the system. /sys/fs/cgroup/tasks lists the tasks in this cgroup.17/sys/fs/cgroup/cpuacct.usage gives the CPU time (in nanoseconds) obtained18by this group which is essentially the CPU time obtained by all the tasks19in the system.2021New accounting groups can be created under the parent group /sys/fs/cgroup.2223# cd /sys/fs/cgroup24# mkdir g125# echo $$ > g12627The above steps create a new group g1 and move the current shell28process (bash) into it. CPU time consumed by this bash and its children29can be obtained from g1/cpuacct.usage and the same is accumulated in30/sys/fs/cgroup/cpuacct.usage also.3132cpuacct.stat file lists a few statistics which further divide the33CPU time obtained by the cgroup into user and system times. Currently34the following statistics are supported:3536user: Time spent by tasks of the cgroup in user mode.37system: Time spent by tasks of the cgroup in kernel mode.3839user and system are in USER_HZ unit.4041cpuacct controller uses percpu_counter interface to collect user and42system times. This has two side effects:4344- It is theoretically possible to see wrong values for user and system times.45This is because percpu_counter_read() on 32bit systems isn't safe46against concurrent writes.47- It is possible to see slightly outdated values for user and system times48due to the batch processing nature of percpu_counter.495051