1*da82c92fSMauro Carvalho Chehab========================= 2*da82c92fSMauro Carvalho ChehabCPU Accounting Controller 3*da82c92fSMauro Carvalho Chehab========================= 4*da82c92fSMauro Carvalho Chehab 5*da82c92fSMauro Carvalho ChehabThe CPU accounting controller is used to group tasks using cgroups and 6*da82c92fSMauro Carvalho Chehabaccount the CPU usage of these groups of tasks. 7*da82c92fSMauro Carvalho Chehab 8*da82c92fSMauro Carvalho ChehabThe CPU accounting controller supports multi-hierarchy groups. An accounting 9*da82c92fSMauro Carvalho Chehabgroup accumulates the CPU usage of all of its child groups and the tasks 10*da82c92fSMauro Carvalho Chehabdirectly present in its group. 11*da82c92fSMauro Carvalho Chehab 12*da82c92fSMauro Carvalho ChehabAccounting groups can be created by first mounting the cgroup filesystem:: 13*da82c92fSMauro Carvalho Chehab 14*da82c92fSMauro Carvalho Chehab # mount -t cgroup -ocpuacct none /sys/fs/cgroup 15*da82c92fSMauro Carvalho Chehab 16*da82c92fSMauro Carvalho ChehabWith the above step, the initial or the parent accounting group becomes 17*da82c92fSMauro Carvalho Chehabvisible at /sys/fs/cgroup. At bootup, this group includes all the tasks in 18*da82c92fSMauro Carvalho Chehabthe system. /sys/fs/cgroup/tasks lists the tasks in this cgroup. 19*da82c92fSMauro Carvalho Chehab/sys/fs/cgroup/cpuacct.usage gives the CPU time (in nanoseconds) obtained 20*da82c92fSMauro Carvalho Chehabby this group which is essentially the CPU time obtained by all the tasks 21*da82c92fSMauro Carvalho Chehabin the system. 22*da82c92fSMauro Carvalho Chehab 23*da82c92fSMauro Carvalho ChehabNew accounting groups can be created under the parent group /sys/fs/cgroup:: 24*da82c92fSMauro Carvalho Chehab 25*da82c92fSMauro Carvalho Chehab # cd /sys/fs/cgroup 26*da82c92fSMauro Carvalho Chehab # mkdir g1 27*da82c92fSMauro Carvalho Chehab # echo $$ > g1/tasks 28*da82c92fSMauro Carvalho Chehab 29*da82c92fSMauro Carvalho ChehabThe above steps create a new group g1 and move the current shell 30*da82c92fSMauro Carvalho Chehabprocess (bash) into it. CPU time consumed by this bash and its children 31*da82c92fSMauro Carvalho Chehabcan be obtained from g1/cpuacct.usage and the same is accumulated in 32*da82c92fSMauro Carvalho Chehab/sys/fs/cgroup/cpuacct.usage also. 33*da82c92fSMauro Carvalho Chehab 34*da82c92fSMauro Carvalho Chehabcpuacct.stat file lists a few statistics which further divide the 35*da82c92fSMauro Carvalho ChehabCPU time obtained by the cgroup into user and system times. Currently 36*da82c92fSMauro Carvalho Chehabthe following statistics are supported: 37*da82c92fSMauro Carvalho Chehab 38*da82c92fSMauro Carvalho Chehabuser: Time spent by tasks of the cgroup in user mode. 39*da82c92fSMauro Carvalho Chehabsystem: Time spent by tasks of the cgroup in kernel mode. 40*da82c92fSMauro Carvalho Chehab 41*da82c92fSMauro Carvalho Chehabuser and system are in USER_HZ unit. 42*da82c92fSMauro Carvalho Chehab 43*da82c92fSMauro Carvalho Chehabcpuacct controller uses percpu_counter interface to collect user and 44*da82c92fSMauro Carvalho Chehabsystem times. This has two side effects: 45*da82c92fSMauro Carvalho Chehab 46*da82c92fSMauro Carvalho Chehab- It is theoretically possible to see wrong values for user and system times. 47*da82c92fSMauro Carvalho Chehab This is because percpu_counter_read() on 32bit systems isn't safe 48*da82c92fSMauro Carvalho Chehab against concurrent writes. 49*da82c92fSMauro Carvalho Chehab- It is possible to see slightly outdated values for user and system times 50*da82c92fSMauro Carvalho Chehab due to the batch processing nature of percpu_counter. 51