All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Virtual Machine Time Accounting
@ 2007-08-20 13:13 Laurent Vivier
  2007-08-20 13:41   ` Avi Kivity
                   ` (5 more replies)
  0 siblings, 6 replies; 32+ messages in thread
From: Laurent Vivier @ 2007-08-20 13:13 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: kvm-devel, linux-kernel, virtualization

The aim of these four patches is to introduce Virtual Machine time accounting.

_Ingo_, as these patches modify files of the scheduler, could you have a look to
them, please ?

[PATCH 1/4] as recent CPUs introduce a third running state, after "user" and
"system", we need a new field, "guest", in cpustat to store the time used by
the CPU to run virtual CPU. Modify /proc/stat to display this new field.

[PATCH 2/4] like for cpustat, introduce the "gtime" (guest time of the task) and
"cgtime" (guest time of the task children) fields for the
tasks. Modify signal_struct and task_struct. Modify /proc/<pid>/stat to display
these new fields.

[PATCH 3/4] 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" and "cgtime" in signal_struct and
task_struct accordingly.

[PATCH 4/4] Modify KVM to update guest time accounting.

Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
-- 
------------- Laurent.Vivier@bull.net  --------------
          "Software is hard" - Donald Knuth

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [kvm-devel] [PATCH 0/4] Virtual Machine Time Accounting
@ 2007-08-20 13:41   ` Avi Kivity
  0 siblings, 0 replies; 32+ messages in thread
From: Avi Kivity @ 2007-08-20 13:41 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: Ingo Molnar, kvm-devel, linux-kernel, virtualization

Laurent Vivier wrote:
> The aim of these four patches is to introduce Virtual Machine time accounting.
>   

1-3 look good to me.  4 needs minor edits...

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
@ 2007-08-20 13:41   ` Avi Kivity
  0 siblings, 0 replies; 32+ messages in thread
From: Avi Kivity @ 2007-08-20 13:41 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: kvm-devel, linux-kernel, virtualization

Laurent Vivier wrote:
> The aim of these four patches is to introduce Virtual Machine time accounting.
>   

1-3 look good to me.  4 needs minor edits...

-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
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/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [kvm-devel] [PATCH 0/4] Virtual Machine Time Accounting
  2007-08-20 13:13 [PATCH 0/4] Virtual Machine Time Accounting Laurent Vivier
  2007-08-20 13:41   ` Avi Kivity
@ 2007-08-20 13:41 ` Avi Kivity
  2007-08-20 13:43 ` John Stoffel
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 32+ messages in thread
From: Avi Kivity @ 2007-08-20 13:41 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: kvm-devel, Ingo Molnar, linux-kernel, virtualization

Laurent Vivier wrote:
> The aim of these four patches is to introduce Virtual Machine time accounting.
>   

1-3 look good to me.  4 needs minor edits...

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
@ 2007-08-20 13:43   ` John Stoffel
  0 siblings, 0 replies; 32+ messages in thread
From: John Stoffel @ 2007-08-20 13:43 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: Ingo Molnar, kvm-devel, linux-kernel, virtualization



Laurent> The aim of these four patches is to introduce Virtual Machine
Laurent> time accounting.

So what does this buy us?  What increased functionality?  

Laurent> [PATCH 1/4] as recent CPUs introduce a third running state,
Laurent> after "user" and "system", we need a new field, "guest", in
Laurent> cpustat to store the time used by the CPU to run virtual
Laurent> CPU. Modify /proc/stat to display this new field.

What happens when you have multiple guests, is this state cummulative?  

I've glanced over these patches and the #ifdefs are ugly..., esp since
the overhead seems to exist even if you don't run any Guest CPUs.  Or
whatever you're doing here.

Please justify this patch more in terms of what it provides and why
it's a good thing to have.  

Thanks,
John

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
@ 2007-08-20 13:43   ` John Stoffel
  0 siblings, 0 replies; 32+ messages in thread
From: John Stoffel @ 2007-08-20 13:43 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: kvm-devel, linux-kernel, virtualization



Laurent> The aim of these four patches is to introduce Virtual Machine
Laurent> time accounting.

So what does this buy us?  What increased functionality?  

Laurent> [PATCH 1/4] as recent CPUs introduce a third running state,
Laurent> after "user" and "system", we need a new field, "guest", in
Laurent> cpustat to store the time used by the CPU to run virtual
Laurent> CPU. Modify /proc/stat to display this new field.

What happens when you have multiple guests, is this state cummulative?  

I've glanced over these patches and the #ifdefs are ugly..., esp since
the overhead seems to exist even if you don't run any Guest CPUs.  Or
whatever you're doing here.

Please justify this patch more in terms of what it provides and why
it's a good thing to have.  

Thanks,
John

-------------------------------------------------------------------------
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/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2007-08-20 13:13 [PATCH 0/4] Virtual Machine Time Accounting Laurent Vivier
  2007-08-20 13:41   ` Avi Kivity
  2007-08-20 13:41 ` [kvm-devel] " Avi Kivity
@ 2007-08-20 13:43 ` John Stoffel
  2007-08-20 13:43   ` John Stoffel
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 32+ messages in thread
From: John Stoffel @ 2007-08-20 13:43 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: kvm-devel, Ingo Molnar, linux-kernel, virtualization



Laurent> The aim of these four patches is to introduce Virtual Machine
Laurent> time accounting.

So what does this buy us?  What increased functionality?  

Laurent> [PATCH 1/4] as recent CPUs introduce a third running state,
Laurent> after "user" and "system", we need a new field, "guest", in
Laurent> cpustat to store the time used by the CPU to run virtual
Laurent> CPU. Modify /proc/stat to display this new field.

What happens when you have multiple guests, is this state cummulative?  

I've glanced over these patches and the #ifdefs are ugly..., esp since
the overhead seems to exist even if you don't run any Guest CPUs.  Or
whatever you're doing here.

Please justify this patch more in terms of what it provides and why
it's a good thing to have.  

Thanks,
John

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
@ 2007-08-20 14:39     ` Laurent Vivier
  0 siblings, 0 replies; 32+ messages in thread
From: Laurent Vivier @ 2007-08-20 14:39 UTC (permalink / raw)
  To: John Stoffel; +Cc: Ingo Molnar, kvm-devel, linux-kernel, virtualization

[-- Attachment #1: Type: text/plain, Size: 1764 bytes --]

Hi John,

John Stoffel wrote:
> 
> Laurent> The aim of these four patches is to introduce Virtual Machine
> Laurent> time accounting.
> 
> So what does this buy us?  What increased functionality?  
> 

functionnalities:

- allow to measure time spent by a CPU in a virtual CPU.
- allow to display in /proc/state this value by CPU
- allow to display in /proc/<pid>/state this value by process
- allow KVM to use these 3 previous functionnalities

> Laurent> [PATCH 1/4] as recent CPUs introduce a third running state,
> Laurent> after "user" and "system", we need a new field, "guest", in
> Laurent> cpustat to store the time used by the CPU to run virtual
> Laurent> CPU. Modify /proc/stat to display this new field.
> 
> What happens when you have multiple guests, is this state cummulative?  

Yes, like system time and user time are.

> I've glanced over these patches and the #ifdefs are ugly..., esp since

#ifdefs are ugly, I agree... I can remove them.
But "#ifdef" allows to save space and time (and it is not a beauty show).

> the overhead seems to exist even if you don't run any Guest CPUs.  Or
> whatever you're doing here.

Can you explain ?

> Please justify this patch more in terms of what it provides and why
> it's a good thing to have.  

Well... it provides the time spent by CPUs in virtual CPUs.
It is usefull only if you run Virtual Machine on your host (like KVM, lguest,
kqemu...) to know how many time your CPUs dedicate to virtual machine execution.
It's a good thing to have like user time and system time are good things to
have... do you use 'top' or 'time' sometime ?


Laurent
-- 
------------- Laurent.Vivier@bull.net  --------------
          "Software is hard" - Donald Knuth


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
@ 2007-08-20 14:39     ` Laurent Vivier
  0 siblings, 0 replies; 32+ messages in thread
From: Laurent Vivier @ 2007-08-20 14:39 UTC (permalink / raw)
  To: John Stoffel; +Cc: kvm-devel, linux-kernel, virtualization


[-- Attachment #1.1: Type: text/plain, Size: 1784 bytes --]

Hi John,

John Stoffel wrote:
> 
> Laurent> The aim of these four patches is to introduce Virtual Machine
> Laurent> time accounting.
> 
> So what does this buy us?  What increased functionality?  
> 

functionnalities:

- allow to measure time spent by a CPU in a virtual CPU.
- allow to display in /proc/state this value by CPU
- allow to display in /proc/<pid>/state this value by process
- allow KVM to use these 3 previous functionnalities

> Laurent> [PATCH 1/4] as recent CPUs introduce a third running state,
> Laurent> after "user" and "system", we need a new field, "guest", in
> Laurent> cpustat to store the time used by the CPU to run virtual
> Laurent> CPU. Modify /proc/stat to display this new field.
> 
> What happens when you have multiple guests, is this state cummulative?  

Yes, like system time and user time are.

> I've glanced over these patches and the #ifdefs are ugly..., esp since

#ifdefs are ugly, I agree... I can remove them.
But "#ifdef" allows to save space and time (and it is not a beauty show).

> the overhead seems to exist even if you don't run any Guest CPUs.  Or
> whatever you're doing here.

Can you explain ?

> Please justify this patch more in terms of what it provides and why
> it's a good thing to have.  

Well... it provides the time spent by CPUs in virtual CPUs.
It is usefull only if you run Virtual Machine on your host (like KVM, lguest,
kqemu...) to know how many time your CPUs dedicate to virtual machine execution.
It's a good thing to have like user time and system time are good things to
have... do you use 'top' or 'time' sometime ?


Laurent
-- 
------------- Laurent.Vivier-6ktuUTfB/bM@public.gmane.org  --------------
          "Software is hard" - Donald Knuth


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: 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 #3: 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

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2007-08-20 13:43   ` John Stoffel
  (?)
@ 2007-08-20 14:39   ` Laurent Vivier
  -1 siblings, 0 replies; 32+ messages in thread
From: Laurent Vivier @ 2007-08-20 14:39 UTC (permalink / raw)
  To: John Stoffel; +Cc: kvm-devel, Ingo Molnar, linux-kernel, virtualization


[-- Attachment #1.1: Type: text/plain, Size: 1764 bytes --]

Hi John,

John Stoffel wrote:
> 
> Laurent> The aim of these four patches is to introduce Virtual Machine
> Laurent> time accounting.
> 
> So what does this buy us?  What increased functionality?  
> 

functionnalities:

- allow to measure time spent by a CPU in a virtual CPU.
- allow to display in /proc/state this value by CPU
- allow to display in /proc/<pid>/state this value by process
- allow KVM to use these 3 previous functionnalities

> Laurent> [PATCH 1/4] as recent CPUs introduce a third running state,
> Laurent> after "user" and "system", we need a new field, "guest", in
> Laurent> cpustat to store the time used by the CPU to run virtual
> Laurent> CPU. Modify /proc/stat to display this new field.
> 
> What happens when you have multiple guests, is this state cummulative?  

Yes, like system time and user time are.

> I've glanced over these patches and the #ifdefs are ugly..., esp since

#ifdefs are ugly, I agree... I can remove them.
But "#ifdef" allows to save space and time (and it is not a beauty show).

> the overhead seems to exist even if you don't run any Guest CPUs.  Or
> whatever you're doing here.

Can you explain ?

> Please justify this patch more in terms of what it provides and why
> it's a good thing to have.  

Well... it provides the time spent by CPUs in virtual CPUs.
It is usefull only if you run Virtual Machine on your host (like KVM, lguest,
kqemu...) to know how many time your CPUs dedicate to virtual machine execution.
It's a good thing to have like user time and system time are good things to
have... do you use 'top' or 'time' sometime ?


Laurent
-- 
------------- Laurent.Vivier@bull.net  --------------
          "Software is hard" - Donald Knuth


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 184 bytes --]

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
@ 2007-08-20 16:13       ` Jeremy Fitzhardinge
  0 siblings, 0 replies; 32+ messages in thread
From: Jeremy Fitzhardinge @ 2007-08-20 16:13 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: John Stoffel, kvm-devel, Ingo Molnar, linux-kernel, virtualization

Laurent Vivier wrote:
> functionnalities:
>
> - allow to measure time spent by a CPU in a virtual CPU.
> - allow to display in /proc/state this value by CPU
> - allow to display in /proc/<pid>/state this value by process
> - allow KVM to use these 3 previous functionnalities
>   

So, currently time spent in a kvm guest is accumulated as qemu-kvm
usertime, right?  Given that qemu knows when its running in qemu vs
guest context, couldn't it provide the breakdown between user and guest
time (ditto lguest)?

    J

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
@ 2007-08-20 16:13       ` Jeremy Fitzhardinge
  0 siblings, 0 replies; 32+ messages in thread
From: Jeremy Fitzhardinge @ 2007-08-20 16:13 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: kvm-devel, John Stoffel, linux-kernel, virtualization

Laurent Vivier wrote:
> functionnalities:
>
> - allow to measure time spent by a CPU in a virtual CPU.
> - allow to display in /proc/state this value by CPU
> - allow to display in /proc/<pid>/state this value by process
> - allow KVM to use these 3 previous functionnalities
>   

So, currently time spent in a kvm guest is accumulated as qemu-kvm
usertime, right?  Given that qemu knows when its running in qemu vs
guest context, couldn't it provide the breakdown between user and guest
time (ditto lguest)?

    J

-------------------------------------------------------------------------
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/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2007-08-20 14:39     ` Laurent Vivier
  (?)
@ 2007-08-20 16:13     ` Jeremy Fitzhardinge
  -1 siblings, 0 replies; 32+ messages in thread
From: Jeremy Fitzhardinge @ 2007-08-20 16:13 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: kvm-devel, Ingo Molnar, John Stoffel, linux-kernel, virtualization

Laurent Vivier wrote:
> functionnalities:
>
> - allow to measure time spent by a CPU in a virtual CPU.
> - allow to display in /proc/state this value by CPU
> - allow to display in /proc/<pid>/state this value by process
> - allow KVM to use these 3 previous functionnalities
>   

So, currently time spent in a kvm guest is accumulated as qemu-kvm
usertime, right?  Given that qemu knows when its running in qemu vs
guest context, couldn't it provide the breakdown between user and guest
time (ditto lguest)?

    J

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2007-08-20 16:13       ` Jeremy Fitzhardinge
  (?)
  (?)
@ 2007-08-20 23:30       ` Rusty Russell
  -1 siblings, 0 replies; 32+ messages in thread
From: Rusty Russell @ 2007-08-20 23:30 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: Laurent Vivier, kvm-devel, Ingo Molnar, John Stoffel,
	linux-kernel, virtualization

On Mon, 2007-08-20 at 09:13 -0700, Jeremy Fitzhardinge wrote:
> Laurent Vivier wrote:
> > functionnalities:
> >
> > - allow to measure time spent by a CPU in a virtual CPU.
> > - allow to display in /proc/state this value by CPU
> > - allow to display in /proc/<pid>/state this value by process
> > - allow KVM to use these 3 previous functionnalities
> >   
> 
> So, currently time spent in a kvm guest is accumulated as qemu-kvm
> usertime, right?  Given that qemu knows when its running in qemu vs
> guest context, couldn't it provide the breakdown between user and guest
> time (ditto lguest)?

No, unfortunately it's accumulated as system time.

Rusty.



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2007-08-20 16:13       ` Jeremy Fitzhardinge
  (?)
@ 2007-08-20 23:30       ` Rusty Russell
  -1 siblings, 0 replies; 32+ messages in thread
From: Rusty Russell @ 2007-08-20 23:30 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: kvm-devel, Laurent Vivier, John Stoffel, linux-kernel,
	virtualization, Ingo Molnar

On Mon, 2007-08-20 at 09:13 -0700, Jeremy Fitzhardinge wrote:
> Laurent Vivier wrote:
> > functionnalities:
> >
> > - allow to measure time spent by a CPU in a virtual CPU.
> > - allow to display in /proc/state this value by CPU
> > - allow to display in /proc/<pid>/state this value by process
> > - allow KVM to use these 3 previous functionnalities
> >   
> 
> So, currently time spent in a kvm guest is accumulated as qemu-kvm
> usertime, right?  Given that qemu knows when its running in qemu vs
> guest context, couldn't it provide the breakdown between user and guest
> time (ditto lguest)?

No, unfortunately it's accumulated as system time.

Rusty.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [kvm-devel] [PATCH 0/4] Virtual Machine Time Accounting
  2007-08-20 16:13       ` Jeremy Fitzhardinge
                         ` (3 preceding siblings ...)
  (?)
@ 2007-08-21 12:54       ` Avi Kivity
  -1 siblings, 0 replies; 32+ messages in thread
From: Avi Kivity @ 2007-08-21 12:54 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: Laurent Vivier, kvm-devel, John Stoffel, linux-kernel, virtualization

Jeremy Fitzhardinge wrote:
> Laurent Vivier wrote:
>   
>> functionnalities:
>>
>> - allow to measure time spent by a CPU in a virtual CPU.
>> - allow to display in /proc/state this value by CPU
>> - allow to display in /proc/<pid>/state this value by process
>> - allow KVM to use these 3 previous functionnalities
>>   
>>     
>
> So, currently time spent in a kvm guest is accumulated as qemu-kvm
> usertime, right?  Given that qemu knows when its running in qemu vs
> guest context, couldn't it provide the breakdown between user and guest
> time (ditto lguest)?
>   

qemu doesn't (and shouldn't) do accounting; that's best done by 
interrupt driven code.

The patches do account for guest time in a separate counter; guest time 
is added to both user time and the new counter.  This allows an old 
'top' to see guest time (accounted as user time), and a new 'top' to 
separate guest time and user time by performing the appropriate 
mathematical operation.


-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [kvm-devel] [PATCH 0/4] Virtual Machine Time Accounting
  2007-08-20 16:13       ` Jeremy Fitzhardinge
                         ` (2 preceding siblings ...)
  (?)
@ 2007-08-21 12:54       ` Avi Kivity
  -1 siblings, 0 replies; 32+ messages in thread
From: Avi Kivity @ 2007-08-21 12:54 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: kvm-devel, Laurent Vivier, John Stoffel, linux-kernel, virtualization

Jeremy Fitzhardinge wrote:
> Laurent Vivier wrote:
>   
>> functionnalities:
>>
>> - allow to measure time spent by a CPU in a virtual CPU.
>> - allow to display in /proc/state this value by CPU
>> - allow to display in /proc/<pid>/state this value by process
>> - allow KVM to use these 3 previous functionnalities
>>   
>>     
>
> So, currently time spent in a kvm guest is accumulated as qemu-kvm
> usertime, right?  Given that qemu knows when its running in qemu vs
> guest context, couldn't it provide the breakdown between user and guest
> time (ditto lguest)?
>   

qemu doesn't (and shouldn't) do accounting; that's best done by 
interrupt driven code.

The patches do account for guest time in a separate counter; guest time 
is added to both user time and the new counter.  This allows an old 
'top' to see guest time (accounted as user time), and a new 'top' to 
separate guest time and user time by performing the appropriate 
mathematical operation.


-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2007-08-20 13:13 [PATCH 0/4] Virtual Machine Time Accounting Laurent Vivier
                   ` (3 preceding siblings ...)
  2007-08-20 13:43   ` John Stoffel
@ 2009-08-04 14:16 ` Peter Zijlstra
  2009-08-04 15:07   ` Martin Schwidefsky
  2009-08-04 15:07   ` Martin Schwidefsky
  2009-08-04 14:16 ` Peter Zijlstra
  5 siblings, 2 replies; 32+ messages in thread
From: Peter Zijlstra @ 2009-08-04 14:16 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: Ingo Molnar, kvm-devel, linux-kernel, virtualization, Martin Schwidefsky

These patches never seem to have made it onto LKML?!

On Mon, 2007-08-20 at 15:13 +0200, Laurent Vivier wrote:
> The aim of these four patches is to introduce Virtual Machine time accounting.
> 
> _Ingo_, as these patches modify files of the scheduler, could you have a look to
> them, please ?
> 
> [PATCH 1/4] as recent CPUs introduce a third running state, after "user" and
> "system", we need a new field, "guest", in cpustat to store the time used by
> the CPU to run virtual CPU. Modify /proc/stat to display this new field.
> 
> [PATCH 2/4] like for cpustat, introduce the "gtime" (guest time of the task) and
> "cgtime" (guest time of the task children) fields for the
> tasks. Modify signal_struct and task_struct. Modify /proc/<pid>/stat to display
> these new fields.
> 
> [PATCH 3/4] 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" and "cgtime" in signal_struct and
> task_struct accordingly.
> 
> [PATCH 4/4] Modify KVM to update guest time accounting.

Isn't this exactly what CONFIG_VIRT_CPU_ACCOUNTING is about?

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2007-08-20 13:13 [PATCH 0/4] Virtual Machine Time Accounting Laurent Vivier
                   ` (4 preceding siblings ...)
  2009-08-04 14:16 ` Peter Zijlstra
@ 2009-08-04 14:16 ` Peter Zijlstra
  5 siblings, 0 replies; 32+ messages in thread
From: Peter Zijlstra @ 2009-08-04 14:16 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: kvm-devel, Martin Schwidefsky, Ingo Molnar, linux-kernel, virtualization

These patches never seem to have made it onto LKML?!

On Mon, 2007-08-20 at 15:13 +0200, Laurent Vivier wrote:
> The aim of these four patches is to introduce Virtual Machine time accounting.
> 
> _Ingo_, as these patches modify files of the scheduler, could you have a look to
> them, please ?
> 
> [PATCH 1/4] as recent CPUs introduce a third running state, after "user" and
> "system", we need a new field, "guest", in cpustat to store the time used by
> the CPU to run virtual CPU. Modify /proc/stat to display this new field.
> 
> [PATCH 2/4] like for cpustat, introduce the "gtime" (guest time of the task) and
> "cgtime" (guest time of the task children) fields for the
> tasks. Modify signal_struct and task_struct. Modify /proc/<pid>/stat to display
> these new fields.
> 
> [PATCH 3/4] 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" and "cgtime" in signal_struct and
> task_struct accordingly.
> 
> [PATCH 4/4] Modify KVM to update guest time accounting.

Isn't this exactly what CONFIG_VIRT_CPU_ACCOUNTING is about?

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2009-08-04 14:16 ` Peter Zijlstra
  2009-08-04 15:07   ` Martin Schwidefsky
@ 2009-08-04 15:07   ` Martin Schwidefsky
  2009-08-04 16:26     ` Peter Zijlstra
  2009-08-04 16:26     ` Peter Zijlstra
  1 sibling, 2 replies; 32+ messages in thread
From: Martin Schwidefsky @ 2009-08-04 15:07 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Laurent Vivier, Ingo Molnar, kvm-devel, linux-kernel, virtualization

On Tue, 04 Aug 2009 16:16:38 +0200
Peter Zijlstra <peterz@infradead.org> wrote:

> These patches never seem to have made it onto LKML?!
> 
> On Mon, 2007-08-20 at 15:13 +0200, Laurent Vivier wrote:
> > The aim of these four patches is to introduce Virtual Machine time accounting.
> > 
> > _Ingo_, as these patches modify files of the scheduler, could you have a look to
> > them, please ?
> > 
> > [PATCH 1/4] as recent CPUs introduce a third running state, after "user" and
> > "system", we need a new field, "guest", in cpustat to store the time used by
> > the CPU to run virtual CPU. Modify /proc/stat to display this new field.
> > 
> > [PATCH 2/4] like for cpustat, introduce the "gtime" (guest time of the task) and
> > "cgtime" (guest time of the task children) fields for the
> > tasks. Modify signal_struct and task_struct. Modify /proc/<pid>/stat to display
> > these new fields.
> > 
> > [PATCH 3/4] 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" and "cgtime" in signal_struct and
> > task_struct accordingly.
> > 
> > [PATCH 4/4] Modify KVM to update guest time accounting.
> 
> Isn't this exactly what CONFIG_VIRT_CPU_ACCOUNTING is about?

Not really, CONFIG_VIRT_CPU_ACCOUNT is a mechanism to sort out the
steal time in the >guest< and to increase the precision of the cpu
accounting values in general. The patches from Laurent improve the
code in the >host< that sorts out guest time vs. system time. The
patches do make sense to me.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2009-08-04 14:16 ` Peter Zijlstra
@ 2009-08-04 15:07   ` Martin Schwidefsky
  2009-08-04 15:07   ` Martin Schwidefsky
  1 sibling, 0 replies; 32+ messages in thread
From: Martin Schwidefsky @ 2009-08-04 15:07 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: kvm-devel, Laurent Vivier, Ingo Molnar, linux-kernel, virtualization

On Tue, 04 Aug 2009 16:16:38 +0200
Peter Zijlstra <peterz@infradead.org> wrote:

> These patches never seem to have made it onto LKML?!
> 
> On Mon, 2007-08-20 at 15:13 +0200, Laurent Vivier wrote:
> > The aim of these four patches is to introduce Virtual Machine time accounting.
> > 
> > _Ingo_, as these patches modify files of the scheduler, could you have a look to
> > them, please ?
> > 
> > [PATCH 1/4] as recent CPUs introduce a third running state, after "user" and
> > "system", we need a new field, "guest", in cpustat to store the time used by
> > the CPU to run virtual CPU. Modify /proc/stat to display this new field.
> > 
> > [PATCH 2/4] like for cpustat, introduce the "gtime" (guest time of the task) and
> > "cgtime" (guest time of the task children) fields for the
> > tasks. Modify signal_struct and task_struct. Modify /proc/<pid>/stat to display
> > these new fields.
> > 
> > [PATCH 3/4] 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" and "cgtime" in signal_struct and
> > task_struct accordingly.
> > 
> > [PATCH 4/4] Modify KVM to update guest time accounting.
> 
> Isn't this exactly what CONFIG_VIRT_CPU_ACCOUNTING is about?

Not really, CONFIG_VIRT_CPU_ACCOUNT is a mechanism to sort out the
steal time in the >guest< and to increase the precision of the cpu
accounting values in general. The patches from Laurent improve the
code in the >host< that sorts out guest time vs. system time. The
patches do make sense to me.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2009-08-04 15:07   ` Martin Schwidefsky
  2009-08-04 16:26     ` Peter Zijlstra
@ 2009-08-04 16:26     ` Peter Zijlstra
  2009-08-04 17:29       ` Martin Schwidefsky
  2009-08-04 17:29       ` Martin Schwidefsky
  1 sibling, 2 replies; 32+ messages in thread
From: Peter Zijlstra @ 2009-08-04 16:26 UTC (permalink / raw)
  To: Martin Schwidefsky
  Cc: Laurent Vivier, Ingo Molnar, kvm-devel, linux-kernel, virtualization

On Tue, 2009-08-04 at 17:07 +0200, Martin Schwidefsky wrote:
> On Tue, 04 Aug 2009 16:16:38 +0200
> Peter Zijlstra <peterz@infradead.org> wrote:
> 
> > These patches never seem to have made it onto LKML?!
> > 
> > On Mon, 2007-08-20 at 15:13 +0200, Laurent Vivier wrote:
> > > The aim of these four patches is to introduce Virtual Machine time accounting.
> > > 
> > > _Ingo_, as these patches modify files of the scheduler, could you have a look to
> > > them, please ?
> > > 
> > > [PATCH 1/4] as recent CPUs introduce a third running state, after "user" and
> > > "system", we need a new field, "guest", in cpustat to store the time used by
> > > the CPU to run virtual CPU. Modify /proc/stat to display this new field.
> > > 
> > > [PATCH 2/4] like for cpustat, introduce the "gtime" (guest time of the task) and
> > > "cgtime" (guest time of the task children) fields for the
> > > tasks. Modify signal_struct and task_struct. Modify /proc/<pid>/stat to display
> > > these new fields.
> > > 
> > > [PATCH 3/4] 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" and "cgtime" in signal_struct and
> > > task_struct accordingly.
> > > 
> > > [PATCH 4/4] Modify KVM to update guest time accounting.
> > 
> > Isn't this exactly what CONFIG_VIRT_CPU_ACCOUNTING is about?
> 
> Not really, CONFIG_VIRT_CPU_ACCOUNT is a mechanism to sort out the
> steal time in the >guest< and to increase the precision of the cpu
> accounting values in general. The patches from Laurent improve the
> code in the >host< that sorts out guest time vs. system time.

Ah, that wasn't clear, it keeps mentioning guest all over the place ;-)

So its going to split user time into user and guest. Does that really
make sense? For the host kernel it really is just another user process,
no?

>  The patches do make sense to me.

No idea there as they never made it to my lkml folder.


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2009-08-04 15:07   ` Martin Schwidefsky
@ 2009-08-04 16:26     ` Peter Zijlstra
  2009-08-04 16:26     ` Peter Zijlstra
  1 sibling, 0 replies; 32+ messages in thread
From: Peter Zijlstra @ 2009-08-04 16:26 UTC (permalink / raw)
  To: Martin Schwidefsky
  Cc: kvm-devel, Laurent Vivier, Ingo Molnar, linux-kernel, virtualization

On Tue, 2009-08-04 at 17:07 +0200, Martin Schwidefsky wrote:
> On Tue, 04 Aug 2009 16:16:38 +0200
> Peter Zijlstra <peterz@infradead.org> wrote:
> 
> > These patches never seem to have made it onto LKML?!
> > 
> > On Mon, 2007-08-20 at 15:13 +0200, Laurent Vivier wrote:
> > > The aim of these four patches is to introduce Virtual Machine time accounting.
> > > 
> > > _Ingo_, as these patches modify files of the scheduler, could you have a look to
> > > them, please ?
> > > 
> > > [PATCH 1/4] as recent CPUs introduce a third running state, after "user" and
> > > "system", we need a new field, "guest", in cpustat to store the time used by
> > > the CPU to run virtual CPU. Modify /proc/stat to display this new field.
> > > 
> > > [PATCH 2/4] like for cpustat, introduce the "gtime" (guest time of the task) and
> > > "cgtime" (guest time of the task children) fields for the
> > > tasks. Modify signal_struct and task_struct. Modify /proc/<pid>/stat to display
> > > these new fields.
> > > 
> > > [PATCH 3/4] 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" and "cgtime" in signal_struct and
> > > task_struct accordingly.
> > > 
> > > [PATCH 4/4] Modify KVM to update guest time accounting.
> > 
> > Isn't this exactly what CONFIG_VIRT_CPU_ACCOUNTING is about?
> 
> Not really, CONFIG_VIRT_CPU_ACCOUNT is a mechanism to sort out the
> steal time in the >guest< and to increase the precision of the cpu
> accounting values in general. The patches from Laurent improve the
> code in the >host< that sorts out guest time vs. system time.

Ah, that wasn't clear, it keeps mentioning guest all over the place ;-)

So its going to split user time into user and guest. Does that really
make sense? For the host kernel it really is just another user process,
no?

>  The patches do make sense to me.

No idea there as they never made it to my lkml folder.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2009-08-04 16:26     ` Peter Zijlstra
@ 2009-08-04 17:29       ` Martin Schwidefsky
  2009-08-04 17:33         ` Peter Zijlstra
  2009-08-04 17:33         ` Peter Zijlstra
  2009-08-04 17:29       ` Martin Schwidefsky
  1 sibling, 2 replies; 32+ messages in thread
From: Martin Schwidefsky @ 2009-08-04 17:29 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Laurent Vivier, Ingo Molnar, kvm-devel, linux-kernel, virtualization

On Tue, 04 Aug 2009 18:26:41 +0200
Peter Zijlstra <peterz@infradead.org> wrote:

> On Tue, 2009-08-04 at 17:07 +0200, Martin Schwidefsky wrote:
> > On Tue, 04 Aug 2009 16:16:38 +0200
> > Peter Zijlstra <peterz@infradead.org> wrote:
> > 
> > > These patches never seem to have made it onto LKML?!
> > > 
> > > On Mon, 2007-08-20 at 15:13 +0200, Laurent Vivier wrote:
> > > > The aim of these four patches is to introduce Virtual Machine time accounting.
> > > > 
> > > > _Ingo_, as these patches modify files of the scheduler, could you have a look to
> > > > them, please ?
> > > > 
> > > > [PATCH 1/4] as recent CPUs introduce a third running state, after "user" and
> > > > "system", we need a new field, "guest", in cpustat to store the time used by
> > > > the CPU to run virtual CPU. Modify /proc/stat to display this new field.
> > > > 
> > > > [PATCH 2/4] like for cpustat, introduce the "gtime" (guest time of the task) and
> > > > "cgtime" (guest time of the task children) fields for the
> > > > tasks. Modify signal_struct and task_struct. Modify /proc/<pid>/stat to display
> > > > these new fields.
> > > > 
> > > > [PATCH 3/4] 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" and "cgtime" in signal_struct and
> > > > task_struct accordingly.
> > > > 
> > > > [PATCH 4/4] Modify KVM to update guest time accounting.
> > > 
> > > Isn't this exactly what CONFIG_VIRT_CPU_ACCOUNTING is about?
> > 
> > Not really, CONFIG_VIRT_CPU_ACCOUNT is a mechanism to sort out the
> > steal time in the >guest< and to increase the precision of the cpu
> > accounting values in general. The patches from Laurent improve the
> > code in the >host< that sorts out guest time vs. system time.
> 
> Ah, that wasn't clear, it keeps mentioning guest all over the place ;-)
> 
> So its going to split user time into user and guest. Does that really
> make sense? For the host kernel it really is just another user process,
> no?

The code (at least in parts) is already upstream. Look at the
account_guest_time function:

static void account_guest_time(struct task_struct *p, cputime_t cputime,
                               cputime_t cputime_scaled)
{
        cputime64_t tmp;
        struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;

        tmp = cputime_to_cputime64(cputime);

        /* Add guest time to process. */
        p->utime = cputime_add(p->utime, cputime);
        p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
        account_group_user_time(p, cputime);
        p->gtime = cputime_add(p->gtime, cputime);

        /* Add guest time to cpustat. */
        cpustat->user = cputime64_add(cpustat->user, tmp);
        cpustat->guest = cputime64_add(cpustat->guest, tmp);
}

The cpu time for a guest is added to p->utime AND p->gtime. That is
done not to break existing tools that know nothing about guest time.
A guest time aware tool can subtract the p->gtime from p->utime to
get the time spent by the process outside of the guest context.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2009-08-04 16:26     ` Peter Zijlstra
  2009-08-04 17:29       ` Martin Schwidefsky
@ 2009-08-04 17:29       ` Martin Schwidefsky
  1 sibling, 0 replies; 32+ messages in thread
From: Martin Schwidefsky @ 2009-08-04 17:29 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: kvm-devel, Laurent Vivier, Ingo Molnar, linux-kernel, virtualization

On Tue, 04 Aug 2009 18:26:41 +0200
Peter Zijlstra <peterz@infradead.org> wrote:

> On Tue, 2009-08-04 at 17:07 +0200, Martin Schwidefsky wrote:
> > On Tue, 04 Aug 2009 16:16:38 +0200
> > Peter Zijlstra <peterz@infradead.org> wrote:
> > 
> > > These patches never seem to have made it onto LKML?!
> > > 
> > > On Mon, 2007-08-20 at 15:13 +0200, Laurent Vivier wrote:
> > > > The aim of these four patches is to introduce Virtual Machine time accounting.
> > > > 
> > > > _Ingo_, as these patches modify files of the scheduler, could you have a look to
> > > > them, please ?
> > > > 
> > > > [PATCH 1/4] as recent CPUs introduce a third running state, after "user" and
> > > > "system", we need a new field, "guest", in cpustat to store the time used by
> > > > the CPU to run virtual CPU. Modify /proc/stat to display this new field.
> > > > 
> > > > [PATCH 2/4] like for cpustat, introduce the "gtime" (guest time of the task) and
> > > > "cgtime" (guest time of the task children) fields for the
> > > > tasks. Modify signal_struct and task_struct. Modify /proc/<pid>/stat to display
> > > > these new fields.
> > > > 
> > > > [PATCH 3/4] 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" and "cgtime" in signal_struct and
> > > > task_struct accordingly.
> > > > 
> > > > [PATCH 4/4] Modify KVM to update guest time accounting.
> > > 
> > > Isn't this exactly what CONFIG_VIRT_CPU_ACCOUNTING is about?
> > 
> > Not really, CONFIG_VIRT_CPU_ACCOUNT is a mechanism to sort out the
> > steal time in the >guest< and to increase the precision of the cpu
> > accounting values in general. The patches from Laurent improve the
> > code in the >host< that sorts out guest time vs. system time.
> 
> Ah, that wasn't clear, it keeps mentioning guest all over the place ;-)
> 
> So its going to split user time into user and guest. Does that really
> make sense? For the host kernel it really is just another user process,
> no?

The code (at least in parts) is already upstream. Look at the
account_guest_time function:

static void account_guest_time(struct task_struct *p, cputime_t cputime,
                               cputime_t cputime_scaled)
{
        cputime64_t tmp;
        struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;

        tmp = cputime_to_cputime64(cputime);

        /* Add guest time to process. */
        p->utime = cputime_add(p->utime, cputime);
        p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
        account_group_user_time(p, cputime);
        p->gtime = cputime_add(p->gtime, cputime);

        /* Add guest time to cpustat. */
        cpustat->user = cputime64_add(cpustat->user, tmp);
        cpustat->guest = cputime64_add(cpustat->guest, tmp);
}

The cpu time for a guest is added to p->utime AND p->gtime. That is
done not to break existing tools that know nothing about guest time.
A guest time aware tool can subtract the p->gtime from p->utime to
get the time spent by the process outside of the guest context.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2009-08-04 17:29       ` Martin Schwidefsky
  2009-08-04 17:33         ` Peter Zijlstra
@ 2009-08-04 17:33         ` Peter Zijlstra
  2009-08-04 18:12           ` Martin Schwidefsky
                             ` (3 more replies)
  1 sibling, 4 replies; 32+ messages in thread
From: Peter Zijlstra @ 2009-08-04 17:33 UTC (permalink / raw)
  To: Martin Schwidefsky
  Cc: Laurent Vivier, Ingo Molnar, kvm-devel, linux-kernel, virtualization

On Tue, 2009-08-04 at 19:29 +0200, Martin Schwidefsky wrote:

> > So its going to split user time into user and guest. Does that really
> > make sense? For the host kernel it really is just another user process,
> > no?
> 
> The code (at least in parts) is already upstream. Look at the
> account_guest_time function:
> 
> static void account_guest_time(struct task_struct *p, cputime_t cputime,
>                                cputime_t cputime_scaled)
> {
>         cputime64_t tmp;
>         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
> 
>         tmp = cputime_to_cputime64(cputime);
> 
>         /* Add guest time to process. */
>         p->utime = cputime_add(p->utime, cputime);
>         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
>         account_group_user_time(p, cputime);
>         p->gtime = cputime_add(p->gtime, cputime);
> 
>         /* Add guest time to cpustat. */
>         cpustat->user = cputime64_add(cpustat->user, tmp);
>         cpustat->guest = cputime64_add(cpustat->guest, tmp);
> }
> 
> The cpu time for a guest is added to p->utime AND p->gtime. That is
> done not to break existing tools that know nothing about guest time.
> A guest time aware tool can subtract the p->gtime from p->utime to
> get the time spent by the process outside of the guest context.

But why? How a vcpu anything other than yet another userspace process?


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2009-08-04 17:29       ` Martin Schwidefsky
@ 2009-08-04 17:33         ` Peter Zijlstra
  2009-08-04 17:33         ` Peter Zijlstra
  1 sibling, 0 replies; 32+ messages in thread
From: Peter Zijlstra @ 2009-08-04 17:33 UTC (permalink / raw)
  To: Martin Schwidefsky
  Cc: kvm-devel, Laurent Vivier, Ingo Molnar, linux-kernel, virtualization

On Tue, 2009-08-04 at 19:29 +0200, Martin Schwidefsky wrote:

> > So its going to split user time into user and guest. Does that really
> > make sense? For the host kernel it really is just another user process,
> > no?
> 
> The code (at least in parts) is already upstream. Look at the
> account_guest_time function:
> 
> static void account_guest_time(struct task_struct *p, cputime_t cputime,
>                                cputime_t cputime_scaled)
> {
>         cputime64_t tmp;
>         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
> 
>         tmp = cputime_to_cputime64(cputime);
> 
>         /* Add guest time to process. */
>         p->utime = cputime_add(p->utime, cputime);
>         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
>         account_group_user_time(p, cputime);
>         p->gtime = cputime_add(p->gtime, cputime);
> 
>         /* Add guest time to cpustat. */
>         cpustat->user = cputime64_add(cpustat->user, tmp);
>         cpustat->guest = cputime64_add(cpustat->guest, tmp);
> }
> 
> The cpu time for a guest is added to p->utime AND p->gtime. That is
> done not to break existing tools that know nothing about guest time.
> A guest time aware tool can subtract the p->gtime from p->utime to
> get the time spent by the process outside of the guest context.

But why? How a vcpu anything other than yet another userspace process?

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2009-08-04 17:33         ` Peter Zijlstra
  2009-08-04 18:12           ` Martin Schwidefsky
@ 2009-08-04 18:12           ` Martin Schwidefsky
  2009-08-04 22:23           ` Jeremy Fitzhardinge
  2009-08-04 22:23           ` Jeremy Fitzhardinge
  3 siblings, 0 replies; 32+ messages in thread
From: Martin Schwidefsky @ 2009-08-04 18:12 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Laurent Vivier, Ingo Molnar, kvm-devel, linux-kernel, virtualization

On Tue, 04 Aug 2009 19:33:14 +0200
Peter Zijlstra <peterz@infradead.org> wrote:

> On Tue, 2009-08-04 at 19:29 +0200, Martin Schwidefsky wrote:
> 
> > > So its going to split user time into user and guest. Does that really
> > > make sense? For the host kernel it really is just another user process,
> > > no?
> > 
> > The code (at least in parts) is already upstream. Look at the
> > account_guest_time function:
> > 
> > static void account_guest_time(struct task_struct *p, cputime_t cputime,
> >                                cputime_t cputime_scaled)
> > {
> >         cputime64_t tmp;
> >         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
> > 
> >         tmp = cputime_to_cputime64(cputime);
> > 
> >         /* Add guest time to process. */
> >         p->utime = cputime_add(p->utime, cputime);
> >         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
> >         account_group_user_time(p, cputime);
> >         p->gtime = cputime_add(p->gtime, cputime);
> > 
> >         /* Add guest time to cpustat. */
> >         cpustat->user = cputime64_add(cpustat->user, tmp);
> >         cpustat->guest = cputime64_add(cpustat->guest, tmp);
> > }
> > 
> > The cpu time for a guest is added to p->utime AND p->gtime. That is
> > done not to break existing tools that know nothing about guest time.
> > A guest time aware tool can subtract the p->gtime from p->utime to
> > get the time spent by the process outside of the guest context.
> 
> But why? How a vcpu anything other than yet another userspace process?

Because you have two different contexts where you spent time, the
"normal" process context and the "guest" process context. To know how
much of your cpu time is spent on virtualization overhead is an
interesting number.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2009-08-04 17:33         ` Peter Zijlstra
@ 2009-08-04 18:12           ` Martin Schwidefsky
  2009-08-04 18:12           ` Martin Schwidefsky
                             ` (2 subsequent siblings)
  3 siblings, 0 replies; 32+ messages in thread
From: Martin Schwidefsky @ 2009-08-04 18:12 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: kvm-devel, Laurent Vivier, Ingo Molnar, linux-kernel, virtualization

On Tue, 04 Aug 2009 19:33:14 +0200
Peter Zijlstra <peterz@infradead.org> wrote:

> On Tue, 2009-08-04 at 19:29 +0200, Martin Schwidefsky wrote:
> 
> > > So its going to split user time into user and guest. Does that really
> > > make sense? For the host kernel it really is just another user process,
> > > no?
> > 
> > The code (at least in parts) is already upstream. Look at the
> > account_guest_time function:
> > 
> > static void account_guest_time(struct task_struct *p, cputime_t cputime,
> >                                cputime_t cputime_scaled)
> > {
> >         cputime64_t tmp;
> >         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
> > 
> >         tmp = cputime_to_cputime64(cputime);
> > 
> >         /* Add guest time to process. */
> >         p->utime = cputime_add(p->utime, cputime);
> >         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
> >         account_group_user_time(p, cputime);
> >         p->gtime = cputime_add(p->gtime, cputime);
> > 
> >         /* Add guest time to cpustat. */
> >         cpustat->user = cputime64_add(cpustat->user, tmp);
> >         cpustat->guest = cputime64_add(cpustat->guest, tmp);
> > }
> > 
> > The cpu time for a guest is added to p->utime AND p->gtime. That is
> > done not to break existing tools that know nothing about guest time.
> > A guest time aware tool can subtract the p->gtime from p->utime to
> > get the time spent by the process outside of the guest context.
> 
> But why? How a vcpu anything other than yet another userspace process?

Because you have two different contexts where you spent time, the
"normal" process context and the "guest" process context. To know how
much of your cpu time is spent on virtualization overhead is an
interesting number.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2009-08-04 17:33         ` Peter Zijlstra
  2009-08-04 18:12           ` Martin Schwidefsky
  2009-08-04 18:12           ` Martin Schwidefsky
@ 2009-08-04 22:23           ` Jeremy Fitzhardinge
  2009-08-04 22:23           ` Jeremy Fitzhardinge
  3 siblings, 0 replies; 32+ messages in thread
From: Jeremy Fitzhardinge @ 2009-08-04 22:23 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Martin Schwidefsky, kvm-devel, Laurent Vivier, Ingo Molnar,
	linux-kernel, virtualization

On 08/04/09 10:33, Peter Zijlstra wrote:
> On Tue, 2009-08-04 at 19:29 +0200, Martin Schwidefsky wrote:
>
>   
>>> So its going to split user time into user and guest. Does that really
>>> make sense? For the host kernel it really is just another user process,
>>> no?
>>>       
>> The code (at least in parts) is already upstream. Look at the
>> account_guest_time function:
>>
>> static void account_guest_time(struct task_struct *p, cputime_t cputime,
>>                                cputime_t cputime_scaled)
>> {
>>         cputime64_t tmp;
>>         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
>>
>>         tmp = cputime_to_cputime64(cputime);
>>
>>         /* Add guest time to process. */
>>         p->utime = cputime_add(p->utime, cputime);
>>         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
>>         account_group_user_time(p, cputime);
>>         p->gtime = cputime_add(p->gtime, cputime);
>>
>>         /* Add guest time to cpustat. */
>>         cpustat->user = cputime64_add(cpustat->user, tmp);
>>         cpustat->guest = cputime64_add(cpustat->guest, tmp);
>> }
>>
>> The cpu time for a guest is added to p->utime AND p->gtime. That is
>> done not to break existing tools that know nothing about guest time.
>> A guest time aware tool can subtract the p->gtime from p->utime to
>> get the time spent by the process outside of the guest context.
>>     
>
> But why? How a vcpu anything other than yet another userspace process?
>   

Normally a running process can either be accumulating user or system
time.  From the host's perspective, the time spent running a vcpu is
more or less a form of system time[*], but the CPU happens to be in an
odd state (for kvm it would be in an actual completely different CPU
mode; for lguest it would just be configured unusually).

[* I think?  I assume qemu goes into a syscall for a while to run the
vcpu, then returns to qemu userspace when it needs to handle some
exception ]

I don't see that vcpu time is so particularly distinct from any other
kind of system time that it really needs a whole special form of time
accounting, unless the scheduler is being modified to schedule guests
differently from normal processes.  Otherwise it just seems like
something that could be relegated to one of the existing
tracing/benchmarking/profiling mechanisms.

(Full disclosure: these patches are completely irrelevant to Xen.)

    J

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 0/4] Virtual Machine Time Accounting
  2009-08-04 17:33         ` Peter Zijlstra
                             ` (2 preceding siblings ...)
  2009-08-04 22:23           ` Jeremy Fitzhardinge
@ 2009-08-04 22:23           ` Jeremy Fitzhardinge
  3 siblings, 0 replies; 32+ messages in thread
From: Jeremy Fitzhardinge @ 2009-08-04 22:23 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: kvm-devel, Laurent Vivier, linux-kernel, virtualization,
	Martin Schwidefsky, Ingo Molnar

On 08/04/09 10:33, Peter Zijlstra wrote:
> On Tue, 2009-08-04 at 19:29 +0200, Martin Schwidefsky wrote:
>
>   
>>> So its going to split user time into user and guest. Does that really
>>> make sense? For the host kernel it really is just another user process,
>>> no?
>>>       
>> The code (at least in parts) is already upstream. Look at the
>> account_guest_time function:
>>
>> static void account_guest_time(struct task_struct *p, cputime_t cputime,
>>                                cputime_t cputime_scaled)
>> {
>>         cputime64_t tmp;
>>         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
>>
>>         tmp = cputime_to_cputime64(cputime);
>>
>>         /* Add guest time to process. */
>>         p->utime = cputime_add(p->utime, cputime);
>>         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
>>         account_group_user_time(p, cputime);
>>         p->gtime = cputime_add(p->gtime, cputime);
>>
>>         /* Add guest time to cpustat. */
>>         cpustat->user = cputime64_add(cpustat->user, tmp);
>>         cpustat->guest = cputime64_add(cpustat->guest, tmp);
>> }
>>
>> The cpu time for a guest is added to p->utime AND p->gtime. That is
>> done not to break existing tools that know nothing about guest time.
>> A guest time aware tool can subtract the p->gtime from p->utime to
>> get the time spent by the process outside of the guest context.
>>     
>
> But why? How a vcpu anything other than yet another userspace process?
>   

Normally a running process can either be accumulating user or system
time.  From the host's perspective, the time spent running a vcpu is
more or less a form of system time[*], but the CPU happens to be in an
odd state (for kvm it would be in an actual completely different CPU
mode; for lguest it would just be configured unusually).

[* I think?  I assume qemu goes into a syscall for a while to run the
vcpu, then returns to qemu userspace when it needs to handle some
exception ]

I don't see that vcpu time is so particularly distinct from any other
kind of system time that it really needs a whole special form of time
accounting, unless the scheduler is being modified to schedule guests
differently from normal processes.  Otherwise it just seems like
something that could be relegated to one of the existing
tracing/benchmarking/profiling mechanisms.

(Full disclosure: these patches are completely irrelevant to Xen.)

    J

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 0/4] Virtual Machine Time Accounting
@ 2007-08-20 13:13 Laurent Vivier
  0 siblings, 0 replies; 32+ messages in thread
From: Laurent Vivier @ 2007-08-20 13:13 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: kvm-devel, linux-kernel, virtualization

The aim of these four patches is to introduce Virtual Machine time accounting.

_Ingo_, as these patches modify files of the scheduler, could you have a look to
them, please ?

[PATCH 1/4] as recent CPUs introduce a third running state, after "user" and
"system", we need a new field, "guest", in cpustat to store the time used by
the CPU to run virtual CPU. Modify /proc/stat to display this new field.

[PATCH 2/4] like for cpustat, introduce the "gtime" (guest time of the task) and
"cgtime" (guest time of the task children) fields for the
tasks. Modify signal_struct and task_struct. Modify /proc/<pid>/stat to display
these new fields.

[PATCH 3/4] 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" and "cgtime" in signal_struct and
task_struct accordingly.

[PATCH 4/4] Modify KVM to update guest time accounting.

Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
-- 
------------- Laurent.Vivier@bull.net  --------------
          "Software is hard" - Donald Knuth

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2009-08-04 22:23 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-20 13:13 [PATCH 0/4] Virtual Machine Time Accounting Laurent Vivier
2007-08-20 13:41 ` [kvm-devel] " Avi Kivity
2007-08-20 13:41   ` Avi Kivity
2007-08-20 13:41 ` [kvm-devel] " Avi Kivity
2007-08-20 13:43 ` John Stoffel
2007-08-20 13:43 ` John Stoffel
2007-08-20 13:43   ` John Stoffel
2007-08-20 14:39   ` Laurent Vivier
2007-08-20 14:39   ` Laurent Vivier
2007-08-20 14:39     ` Laurent Vivier
2007-08-20 16:13     ` Jeremy Fitzhardinge
2007-08-20 16:13     ` Jeremy Fitzhardinge
2007-08-20 16:13       ` Jeremy Fitzhardinge
2007-08-20 23:30       ` Rusty Russell
2007-08-20 23:30       ` Rusty Russell
2007-08-21 12:54       ` [kvm-devel] " Avi Kivity
2007-08-21 12:54       ` Avi Kivity
2009-08-04 14:16 ` Peter Zijlstra
2009-08-04 15:07   ` Martin Schwidefsky
2009-08-04 15:07   ` Martin Schwidefsky
2009-08-04 16:26     ` Peter Zijlstra
2009-08-04 16:26     ` Peter Zijlstra
2009-08-04 17:29       ` Martin Schwidefsky
2009-08-04 17:33         ` Peter Zijlstra
2009-08-04 17:33         ` Peter Zijlstra
2009-08-04 18:12           ` Martin Schwidefsky
2009-08-04 18:12           ` Martin Schwidefsky
2009-08-04 22:23           ` Jeremy Fitzhardinge
2009-08-04 22:23           ` Jeremy Fitzhardinge
2009-08-04 17:29       ` Martin Schwidefsky
2009-08-04 14:16 ` Peter Zijlstra
  -- strict thread matches above, loose matches on Subject: below --
2007-08-20 13:13 Laurent Vivier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.