From mboxrd@z Thu Jan 1 00:00:00 1970 From: Laurent Vivier Subject: [PATCH/RFC 3/4, second shot]Introduce "account_guest_time" Date: Fri, 17 Aug 2007 13:51:49 +0200 Message-ID: <46C58BD5.3090207@bull.net> References: <46C4719A.2060308@bull.net> <46C4720F.7030304@bull.net> <46C4725A.4070607@bull.net> <46C4740F.2050701@bull.net> <1187303955.6449.7.camel@localhost.localdomain> <46C54FB8.7050504@bull.net> <1187339450.6449.115.camel@localhost.localdomain> <46C56774.2030009@bull.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070305070409050007030503" Cc: kvm-devel , linux-kernel , virtualization To: Laurent Vivier Return-path: In-Reply-To: <46C56774.2030009-6ktuUTfB/bM@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org This is a multi-part message in MIME format. --------------070305070409050007030503 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=ISO-8859-1 This is another way to compute guest time... I remove the "account modifi= ers" mechanism and call directly account_guest_time() from account_system_time= (). account_system_time() computes user, system and guest times according val= ue accumulated in vtime (a ktime_t) in task_struct by the virtual machine. --=20 ------------- Laurent.Vivier-6ktuUTfB/bM@public.gmane.org -------------- "Software is hard" - Donald Knuth --------------070305070409050007030503 Content-Type: text/plain; name="account_guest" Content-Disposition: inline; filename="account_guest" Content-Transfer-Encoding: quoted-printable Index: kvm/include/linux/sched.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 }; =20 /* Index: kvm/kernel/sched.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 =3D cputime64_add(cpustat->user, tmp); } =20 +#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 cpu= time) +{ + struct cpu_usage_stat *cpustat =3D &kstat_this_cpu.cpustat; + ktime_t kmsec =3D ktime_set(0, NSEC_PER_MSEC); + cputime_t cmsec =3D msecs_to_cputime(1); + + while ((ktime_to_ns(p->vtime) >=3D NSEC_PER_MSEC) && + (cputime_to_msecs(cputime) >=3D 1)) { + p->vtime =3D ktime_sub(p->vtime, kmsec); + p->utime =3D cputime_add(p->utime, cmsec); + p->gtime =3D cputime_add(p->gtime, cmsec); + + cpustat->guest =3D cputime64_add(cpustat->guest, + cputime_to_cputime64(cmsec)); + cpustat->user =3D cputime64_add(cpustat->user, + cputime_to_cputime64(cmsec)); + + cputime =3D 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 =3D this_rq(); cputime64_t tmp; =20 +#ifdef CONFIG_GUEST_ACCOUNTING + cputime =3D account_guest_time(p, cputime); +#endif + p->stime =3D cputime_add(p->stime, cputime); =20 /* Add system time to cpustat. */ --------------070305070409050007030503 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- 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/ --------------070305070409050007030503 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kvm-devel mailing list kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/kvm-devel --------------070305070409050007030503--