From 72dd06c0c28ac965246dc77c38350ff8a15b4895 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Mon, 15 Oct 2007 17:00:19 +0200 Subject: [PATCH] --- yaml --- r: 69141 b: refs/heads/master c: 94886b84b1bcdc95f34f70e7fce407efefe472e1 h: refs/heads/master i: 69139: d92fbcdff27b40fe9c9dd5ef190db16c199dab58 v: v3 --- [refs] | 2 +- trunk/include/linux/sched.h | 1 + trunk/kernel/sched.c | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index 234b890dc72e..dae4fb8e5d09 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 9ac52315d4cf5f561f36dabaf0720c00d3553162 +refs/heads/master: 94886b84b1bcdc95f34f70e7fce407efefe472e1 diff --git a/trunk/include/linux/sched.h b/trunk/include/linux/sched.h index fefce22e4c16..228e0a8ce248 100644 --- a/trunk/include/linux/sched.h +++ b/trunk/include/linux/sched.h @@ -1342,6 +1342,7 @@ static inline void put_task_struct(struct task_struct *t) #define PF_STARTING 0x00000002 /* being created */ #define PF_EXITING 0x00000004 /* getting shut down */ #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ +#define PF_VCPU 0x00000010 /* I'm a virtual CPU */ #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */ #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */ #define PF_DUMPCORE 0x00000200 /* dumped core */ diff --git a/trunk/kernel/sched.c b/trunk/kernel/sched.c index 9887ca005c50..5a91fe0b5de6 100644 --- a/trunk/kernel/sched.c +++ b/trunk/kernel/sched.c @@ -3302,6 +3302,25 @@ void account_user_time(struct task_struct *p, cputime_t cputime) cpustat->user = cputime64_add(cpustat->user, tmp); } +/* + * Account guest cpu time to a process. + * @p: the process that the cpu time gets accounted to + * @cputime: the cpu time spent in virtual machine since the last update + */ +void account_guest_time(struct task_struct *p, cputime_t cputime) +{ + cputime64_t tmp; + struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; + + tmp = cputime_to_cputime64(cputime); + + p->utime = cputime_add(p->utime, cputime); + p->gtime = cputime_add(p->gtime, cputime); + + cpustat->user = cputime64_add(cpustat->user, tmp); + cpustat->guest = cputime64_add(cpustat->guest, tmp); +} + /* * Account system cpu time to a process. * @p: the process that the cpu time gets accounted to @@ -3315,6 +3334,12 @@ void account_system_time(struct task_struct *p, int hardirq_offset, struct rq *rq = this_rq(); cputime64_t tmp; + if (p->flags & PF_VCPU) { + account_guest_time(p, cputime); + p->flags &= ~PF_VCPU; + return; + } + p->stime = cputime_add(p->stime, cputime); /* Add system time to cpustat. */