Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 121326
b: refs/heads/master
c: 934352f
h: refs/heads/master
v: v3
  • Loading branch information
Bharata B Rao authored and Ingo Molnar committed Nov 11, 2008
1 parent a04c099 commit 4a1ceba
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ff9b48c3598732926fa09afd7f526981c32a48cc
refs/heads/master: 934352f214b3251eb0793c1209d346595a661d80
32 changes: 32 additions & 0 deletions trunk/Documentation/controllers/cpuacct.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
CPU Accounting Controller
-------------------------

The CPU accounting controller is used to group tasks using cgroups and
account the CPU usage of these groups of tasks.

The CPU accounting controller supports multi-hierarchy groups. An accounting
group accumulates the CPU usage of all of its child groups and the tasks
directly present in its group.

Accounting groups can be created by first mounting the cgroup filesystem.

# mkdir /cgroups
# mount -t cgroup -ocpuacct none /cgroups

With the above step, the initial or the parent accounting group
becomes visible at /cgroups. At bootup, this group includes all the
tasks in the system. /cgroups/tasks lists the tasks in this cgroup.
/cgroups/cpuacct.usage gives the CPU time (in nanoseconds) obtained by
this group which is essentially the CPU time obtained by all the tasks
in the system.

New accounting groups can be created under the parent group /cgroups.

# cd /cgroups
# mkdir g1
# echo $$ > g1

The above steps create a new group g1 and move the current shell
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.
12 changes: 9 additions & 3 deletions trunk/kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -9196,11 +9196,12 @@ struct cgroup_subsys cpu_cgroup_subsys = {
* (balbir@in.ibm.com).
*/

/* track cpu usage of a group of tasks */
/* track cpu usage of a group of tasks and its child groups */
struct cpuacct {
struct cgroup_subsys_state css;
/* cpuusage holds pointer to a u64-type object on every cpu */
u64 *cpuusage;
struct cpuacct *parent;
};

struct cgroup_subsys cpuacct_subsys;
Expand Down Expand Up @@ -9234,6 +9235,9 @@ static struct cgroup_subsys_state *cpuacct_create(
return ERR_PTR(-ENOMEM);
}

if (cgrp->parent)
ca->parent = cgroup_ca(cgrp->parent);

return &ca->css;
}

Expand Down Expand Up @@ -9313,14 +9317,16 @@ static int cpuacct_populate(struct cgroup_subsys *ss, struct cgroup *cgrp)
static void cpuacct_charge(struct task_struct *tsk, u64 cputime)
{
struct cpuacct *ca;
int cpu;

if (!cpuacct_subsys.active)
return;

cpu = task_cpu(tsk);
ca = task_ca(tsk);
if (ca) {
u64 *cpuusage = percpu_ptr(ca->cpuusage, task_cpu(tsk));

for (; ca; ca = ca->parent) {
u64 *cpuusage = percpu_ptr(ca->cpuusage, cpu);
*cpuusage += cputime;
}
}
Expand Down

0 comments on commit 4a1ceba

Please sign in to comment.