From: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
To: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
Cc: kvm-devel
<kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
linux-kernel
<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
virtualization
<virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
Subject: [PATCH/RFC 3/4, second shot]Introduce "account_guest_time"
Date: Fri, 17 Aug 2007 13:51:49 +0200 [thread overview]
Message-ID: <46C58BD5.3090207@bull.net> (raw)
In-Reply-To: <46C56774.2030009-6ktuUTfB/bM@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 432 bytes --]
This is another way to compute guest time... I remove the "account modifiers"
mechanism and call directly account_guest_time() from account_system_time().
account_system_time() computes user, system and guest times according value
accumulated in vtime (a ktime_t) in task_struct by the virtual machine.
--
------------- Laurent.Vivier-6ktuUTfB/bM@public.gmane.org --------------
"Software is hard" - Donald Knuth
[-- Attachment #2: account_guest --]
[-- Type: text/plain, Size: 2005 bytes --]
Index: kvm/include/linux/sched.h
===================================================================
--- kvm.orig/include/linux/sched.h 2007-08-17 10:18:53.000000000 +0200
+++ kvm/include/linux/sched.h 2007-08-17 12:33:22.000000000 +0200
@@ -1192,6 +1192,9 @@
#ifdef CONFIG_FAULT_INJECTION
int make_it_fail;
#endif
+#ifdef CONFIG_GUEST_ACCOUNTING
+ ktime_t vtime;
+#endif
};
/*
Index: kvm/kernel/sched.c
===================================================================
--- kvm.orig/kernel/sched.c 2007-08-17 10:18:53.000000000 +0200
+++ kvm/kernel/sched.c 2007-08-17 12:33:07.000000000 +0200
@@ -3233,6 +3233,37 @@
cpustat->user = cputime64_add(cpustat->user, tmp);
}
+#ifdef CONFIG_GUEST_ACCOUNTING
+/*
+ * Account guest time to a process
+ * @p: the process that the cpu time gets accounted to
+ * @cputime: the cpu time spent in kernel space since the last update
+ */
+
+static cputime_t account_guest_time(struct task_struct *p, cputime_t cputime)
+{
+ struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
+ ktime_t kmsec = ktime_set(0, NSEC_PER_MSEC);
+ cputime_t cmsec = msecs_to_cputime(1);
+
+ while ((ktime_to_ns(p->vtime) >= NSEC_PER_MSEC) &&
+ (cputime_to_msecs(cputime) >= 1)) {
+ p->vtime = ktime_sub(p->vtime, kmsec);
+ p->utime = cputime_add(p->utime, cmsec);
+ p->gtime = cputime_add(p->gtime, cmsec);
+
+ cpustat->guest = cputime64_add(cpustat->guest,
+ cputime_to_cputime64(cmsec));
+ cpustat->user = cputime64_add(cpustat->user,
+ cputime_to_cputime64(cmsec));
+
+ cputime = cputime_sub(cputime, cmsec);
+ }
+
+ return cputime;
+}
+#endif
+
/*
* Account system cpu time to a process.
* @p: the process that the cpu time gets accounted to
@@ -3246,6 +3277,10 @@
struct rq *rq = this_rq();
cputime64_t tmp;
+#ifdef CONFIG_GUEST_ACCOUNTING
+ cputime = account_guest_time(p, cputime);
+#endif
+
p->stime = cputime_add(p->stime, cputime);
/* Add system time to cpustat. */
[-- Attachment #3: Type: text/plain, Size: 315 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
[-- Attachment #4: Type: text/plain, Size: 186 bytes --]
_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel
next prev parent reply other threads:[~2007-08-17 11:51 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <46C4719A.2060308@bull.net>
2007-08-16 15:57 ` [PATCH/RFC 1/4]Introduce a new field "guest" in cpustat Laurent Vivier
[not found] ` <46C4720F.7030304@bull.net>
2007-08-16 15:57 ` [PATCH/RFC 2/4]Introduce a new field "guest" in task_struct Laurent Vivier
[not found] ` <46C4725A.4070607@bull.net>
2007-08-16 15:58 ` [PATCH/RFC 3/4]Introduce "account modifiers" mechanism Laurent Vivier
2007-08-16 22:39 ` Rusty Russell
[not found] ` <1187303955.6449.7.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-08-17 7:35 ` Laurent Vivier
[not found] ` <46C54FB8.7050504-6ktuUTfB/bM@public.gmane.org>
2007-08-17 8:30 ` Rusty Russell
[not found] ` <1187339450.6449.115.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-08-17 9:16 ` Laurent Vivier
[not found] ` <46C56774.2030009-6ktuUTfB/bM@public.gmane.org>
2007-08-17 11:51 ` Laurent Vivier [this message]
2007-08-17 11:54 ` [PATCH/RFC 4/4, second shot]KVM uses "account_guest_time()" Laurent Vivier
[not found] ` <46C58C8C.3080803-6ktuUTfB/bM@public.gmane.org>
2007-08-17 13:03 ` Avi Kivity
[not found] ` <46C59C92.40902-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-08-17 13:16 ` Laurent Vivier
[not found] ` <46C59FA6.7020601-6ktuUTfB/bM@public.gmane.org>
2007-08-19 7:39 ` Avi Kivity
2007-08-17 12:59 ` [kvm-devel] [PATCH/RFC 3/4, second shot]Introduce "account_guest_time" Avi Kivity
2007-08-17 12:55 ` [PATCH/RFC 3/4]Introduce "account modifiers" mechanism Avi Kivity
[not found] ` <46C59AB1.6070505-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-08-17 13:08 ` Laurent Vivier
[not found] ` <46C59DC6.4020308-6ktuUTfB/bM@public.gmane.org>
2007-08-17 13:32 ` Christian Borntraeger
2007-08-19 7:41 ` Avi Kivity
2007-08-17 14:12 ` Laurent Vivier
[not found] ` <46C5ACE8.2050004-6ktuUTfB/bM@public.gmane.org>
2007-08-19 7:38 ` Avi Kivity
[not found] ` <46C7F362.80106-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-08-20 7:30 ` Laurent Vivier
[not found] ` <46C94306.8080300-6ktuUTfB/bM@public.gmane.org>
2007-08-20 7:55 ` Avi Kivity
[not found] ` <46C472D2.7000702@bull.net>
2007-08-16 15:59 ` [PATCH/RFC 4/4]Modify KVM to use the "account modifiers" Laurent Vivier
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=46C58BD5.3090207@bull.net \
--to=laurent.vivier-6ktuutfb/bm@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
/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