aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched.c
diff options
context:
space:
mode:
authorPaul Menage <menage@google.com>2007-10-19 02:39:42 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-19 14:53:36 -0400
commit62d0df64065e7c135d0002f069444fbdfc64768f (patch)
tree9087bf336182ab9c619460ba2370a223200179bc /kernel/sched.c
parent8793d854edbc2774943a4b0de3304dc73991159a (diff)
Task Control Groups: example CPU accounting subsystem
This example demonstrates how to use the generic cgroup subsystem for a simple resource tracker that counts, for the processes in a cgroup, the total CPU time used and the %CPU used in the last complete 10 second interval. Portions contributed by Balbir Singh <balbir@in.ibm.com> Signed-off-by: Paul Menage <menage@google.com> Cc: Serge E. Hallyn <serue@us.ibm.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Dave Hansen <haveblue@us.ibm.com> Cc: Balbir Singh <balbir@in.ibm.com> Cc: Paul Jackson <pj@sgi.com> Cc: Kirill Korotaev <dev@openvz.org> Cc: Herbert Poetzl <herbert@13thfloor.at> Cc: Srivatsa Vaddagiri <vatsa@in.ibm.com> Cc: Cedric Le Goater <clg@fr.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/sched.c')
-rw-r--r--kernel/sched.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index ed90be46fb31..72a2a16e2214 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -51,6 +51,7 @@
51#include <linux/cpu.h> 51#include <linux/cpu.h>
52#include <linux/cpuset.h> 52#include <linux/cpuset.h>
53#include <linux/percpu.h> 53#include <linux/percpu.h>
54#include <linux/cpu_acct.h>
54#include <linux/kthread.h> 55#include <linux/kthread.h>
55#include <linux/seq_file.h> 56#include <linux/seq_file.h>
56#include <linux/sysctl.h> 57#include <linux/sysctl.h>
@@ -3307,9 +3308,13 @@ void account_user_time(struct task_struct *p, cputime_t cputime)
3307{ 3308{
3308 struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; 3309 struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
3309 cputime64_t tmp; 3310 cputime64_t tmp;
3311 struct rq *rq = this_rq();
3310 3312
3311 p->utime = cputime_add(p->utime, cputime); 3313 p->utime = cputime_add(p->utime, cputime);
3312 3314
3315 if (p != rq->idle)
3316 cpuacct_charge(p, cputime);
3317
3313 /* Add user time to cpustat. */ 3318 /* Add user time to cpustat. */
3314 tmp = cputime_to_cputime64(cputime); 3319 tmp = cputime_to_cputime64(cputime);
3315 if (TASK_NICE(p) > 0) 3320 if (TASK_NICE(p) > 0)
@@ -3374,9 +3379,10 @@ void account_system_time(struct task_struct *p, int hardirq_offset,
3374 cpustat->irq = cputime64_add(cpustat->irq, tmp); 3379 cpustat->irq = cputime64_add(cpustat->irq, tmp);
3375 else if (softirq_count()) 3380 else if (softirq_count())
3376 cpustat->softirq = cputime64_add(cpustat->softirq, tmp); 3381 cpustat->softirq = cputime64_add(cpustat->softirq, tmp);
3377 else if (p != rq->idle) 3382 else if (p != rq->idle) {
3378 cpustat->system = cputime64_add(cpustat->system, tmp); 3383 cpustat->system = cputime64_add(cpustat->system, tmp);
3379 else if (atomic_read(&rq->nr_iowait) > 0) 3384 cpuacct_charge(p, cputime);
3385 } else if (atomic_read(&rq->nr_iowait) > 0)
3380 cpustat->iowait = cputime64_add(cpustat->iowait, tmp); 3386 cpustat->iowait = cputime64_add(cpustat->iowait, tmp);
3381 else 3387 else
3382 cpustat->idle = cputime64_add(cpustat->idle, tmp); 3388 cpustat->idle = cputime64_add(cpustat->idle, tmp);
@@ -3412,8 +3418,10 @@ void account_steal_time(struct task_struct *p, cputime_t steal)
3412 cpustat->iowait = cputime64_add(cpustat->iowait, tmp); 3418 cpustat->iowait = cputime64_add(cpustat->iowait, tmp);
3413 else 3419 else
3414 cpustat->idle = cputime64_add(cpustat->idle, tmp); 3420 cpustat->idle = cputime64_add(cpustat->idle, tmp);
3415 } else 3421 } else {
3416 cpustat->steal = cputime64_add(cpustat->steal, tmp); 3422 cpustat->steal = cputime64_add(cpustat->steal, tmp);
3423 cpuacct_charge(p, -tmp);
3424 }
3417} 3425}
3418 3426
3419/* 3427/*