Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=94886b84b1bcdc95f34f70e7fce407efefe472e1
Commit:     94886b84b1bcdc95f34f70e7fce407efefe472e1
Parent:     9ac52315d4cf5f561f36dabaf0720c00d3553162
Author:     Laurent Vivier <[EMAIL PROTECTED]>
AuthorDate: Mon Oct 15 17:00:19 2007 +0200
Committer:  Ingo Molnar <[EMAIL PROTECTED]>
CommitDate: Mon Oct 15 17:00:19 2007 +0200

    sched: guest CPU accounting: maintain stats in account_system_time()
    
    modify account_system_time() to add cputime to cpustat->guest if we are
    running a VCPU. We add this cputime to cpustat->user instead of
    cpustat->system because this part of KVM code is in fact user code
    although it is executed in the kernel. We duplicate VCPU time between
    guest and user to allow an unmodified "top(1)" to display correct value.
    A modified "top(1)" is able to display good cpu user time and cpu guest
    time by subtracting cpu guest time from cpu user time. Update "gtime" in
    task_struct accordingly.
    
    Signed-off-by: Laurent Vivier <[EMAIL PROTECTED]>
    Acked-by: Avi Kivity <[EMAIL PROTECTED]>
    Signed-off-by: Ingo Molnar <[EMAIL PROTECTED]>
---
 include/linux/sched.h |    1 +
 kernel/sched.c        |   25 +++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index fefce22..228e0a8 100644
--- a/include/linux/sched.h
+++ b/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/kernel/sched.c b/kernel/sched.c
index 9887ca0..5a91fe0 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -3303,6 +3303,25 @@ void account_user_time(struct task_struct *p, cputime_t 
cputime)
 }
 
 /*
+ * 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
  * @hardirq_offset: the offset to subtract from hardirq_count()
@@ -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. */
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to