public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: bharata@linux.vnet.ibm.com
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	Dhaval Giani <dhaval@linux.vnet.ibm.com>,
	Li Zefan <lizf@cn.fujitsu.com>,
	Balbir Singh <balbir@linux.vnet.ibm.com>,
	Paul Menage <menage@google.com>,
	linux-kernel@vger.kernel.org,
	Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>,
	Ingo Molnar <mingo@elte.hu>
Subject: Re: [PATCH] Add hierarchical accounting to cpu accounting controller
Date: Mon, 10 Nov 2008 11:22:41 +0100	[thread overview]
Message-ID: <1226312561.2697.4093.camel@twins> (raw)
In-Reply-To: <20081104124937.GB4898@in.ibm.com>

On Tue, 2008-11-04 at 18:19 +0530, Bharata B Rao wrote:

> Add hierarchical accounting to cpu accounting controller and cpuacct
> documentation.
> 
> Currently, while charging the task's cputime to its accounting group,
> the accounting group hierarchy isn't updated. This patch charges the cputime
> of a task to its accounting group and all its parent accounting groups.
> 
> Reported-by: Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>
> Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
> CC: Peter Zijlstra <a.p.zijlstra@chello.nl>
> CC: Ingo Molnar <mingo@elte.hu>
> CC: Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>
> Reviewed-by: Paul Menage <menage@google.com>

Seems sane and simple enough.

Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>

Ingo?

> ---
>  Documentation/controllers/cpuacct.txt |   32 ++++++++++++++++++++++++++++++++
>  kernel/sched.c                        |   10 ++++++++--
>  2 files changed, 40 insertions(+), 2 deletions(-)
> 
> --- /dev/null
> +++ b/Documentation/controllers/cpuacct.txt
> @@ -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 group of tasks.
> +
> +The CPU accounting controller supports multi-hierarchy groups. An accounting
> +group accumulates the CPU usage of all of it's child groups and
> +the tasks directly present in it's 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 comprises of 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 it's children
> +can be obtained from g1/cpuacct.usage and the same gets accumulated in
> +/cgroups/cpuacct.usage also.
> --- a/kernel/sched.c
> +++ b/kernel/sched.c
> @@ -9236,6 +9236,7 @@ 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;
> @@ -9269,6 +9270,9 @@ static struct cgroup_subsys_state *cpuac
>  		return ERR_PTR(-ENOMEM);
>  	}
>  
> +	if (cgrp->parent)
> +		ca->parent = cgroup_ca(cgrp->parent);
> +
>  	return &ca->css;
>  }
>  
> @@ -9348,14 +9352,16 @@ static int cpuacct_populate(struct cgrou
>  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;
>  	}
>  }



  parent reply	other threads:[~2008-11-10 10:22 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-23  5:43 [PATCH] Add hierarchical accounting to cpu accounting controller Bharata B Rao
2008-10-23  6:41 ` Bharata B Rao
2008-10-23 15:49 ` Paul Menage
2008-10-24  5:08   ` Bharata B Rao
2008-10-24 17:37     ` Paul Menage
2008-10-25  6:01       ` Bharata B Rao
2008-10-25 15:38         ` Paul Menage
2008-10-27  1:17           ` KAMEZAWA Hiroyuki
2008-10-27  4:43             ` Bharata B Rao
2008-10-27  6:57               ` Balbir Singh
2008-10-27  8:25                 ` Li Zefan
2008-10-30 17:16                   ` Dhaval Giani
2008-10-31  0:40                     ` KAMEZAWA Hiroyuki
2008-11-04 12:49                       ` Bharata B Rao
2008-11-04 17:20                         ` Randy Dunlap
2008-11-05  3:24                           ` Bharata B Rao
2008-11-05  3:29                             ` Srivatsa Vaddagiri
2008-11-10 10:21                               ` Dhaval Giani
2008-11-10 13:09                             ` Ingo Molnar
2008-11-10 15:11                               ` Bharata B Rao
2008-11-11 11:13                                 ` Ingo Molnar
2008-11-05  6:17                         ` Li Zefan
2008-11-06  6:43                         ` Balbir Singh
2008-11-10 10:22                         ` Peter Zijlstra [this message]
2008-11-10 13:05                           ` Balbir Singh
2008-11-05  3:31                     ` Li Zefan
2008-11-05  3:48                       ` KAMEZAWA Hiroyuki
2008-10-27  5:54         ` Li Zefan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1226312561.2697.4093.camel@twins \
    --to=a.p.zijlstra@chello.nl \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=bharata@linux.vnet.ibm.com \
    --cc=dhaval@linux.vnet.ibm.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=menage@google.com \
    --cc=mingo@elte.hu \
    --cc=vatsa@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox