linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 4/4] Modify KVM to update guest time accounting.
@ 2007-08-20 13:14 Laurent Vivier
  2007-08-20 13:40 ` [kvm-devel] " Avi Kivity
  0 siblings, 1 reply; 5+ messages in thread
From: Laurent Vivier @ 2007-08-20 13:14 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: kvm-devel, linux-kernel, virtualization

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

[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

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

Index: kvm/drivers/kvm/kvm.h
===================================================================
--- kvm.orig/drivers/kvm/kvm.h	2007-08-20 13:23:53.000000000 +0200
+++ kvm/drivers/kvm/kvm.h	2007-08-20 13:23:58.000000000 +0200
@@ -589,6 +589,17 @@ void kvm_mmu_unload(struct kvm_vcpu *vcp
 
 int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
 
+static inline void kvm_guest_enter(void)
+{
+#ifdef CONFIG_GUEST_ACCOUNTING
+	current->flags |= PF_VCPU;
+#endif
+}
+
+static inline void kvm_guest_exit(void)
+{
+}
+
 static inline int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
 				     u32 error_code)
 {
Index: kvm/drivers/kvm/svm.c
===================================================================
--- kvm.orig/drivers/kvm/svm.c	2007-08-20 13:23:53.000000000 +0200
+++ kvm/drivers/kvm/svm.c	2007-08-20 13:23:58.000000000 +0200
@@ -1404,6 +1404,7 @@ again:
 	clgi();
 
 	vcpu->guest_mode = 1;
+	kvm_guest_enter();
 	if (vcpu->requests)
 		if (test_and_clear_bit(KVM_TLB_FLUSH, &vcpu->requests))
 		    svm_flush_tlb(vcpu);
@@ -1536,6 +1537,7 @@ again:
 #endif
 		: "cc", "memory" );
 
+	kvm_guest_exit();
 	vcpu->guest_mode = 0;
 
 	if (vcpu->fpu_active) {
Index: kvm/drivers/kvm/vmx.c
===================================================================
--- kvm.orig/drivers/kvm/vmx.c	2007-08-20 13:23:53.000000000 +0200
+++ kvm/drivers/kvm/vmx.c	2007-08-20 13:23:58.000000000 +0200
@@ -2078,6 +2078,7 @@ again:
 	local_irq_disable();
 
 	vcpu->guest_mode = 1;
+	kvm_guest_enter();
 	if (vcpu->requests)
 		if (test_and_clear_bit(KVM_TLB_FLUSH, &vcpu->requests))
 		    vmx_flush_tlb(vcpu);
@@ -2198,6 +2199,7 @@ again:
 		[cr2]"i"(offsetof(struct kvm_vcpu, cr2))
 	      : "cc", "memory" );
 
+	kvm_guest_exit();
 	vcpu->guest_mode = 0;
 	local_irq_enable();
 
Index: kvm/drivers/kvm/Kconfig
===================================================================
--- kvm.orig/drivers/kvm/Kconfig	2007-08-20 13:36:58.000000000 +0200
+++ kvm/drivers/kvm/Kconfig	2007-08-20 13:37:36.000000000 +0200
@@ -13,6 +13,7 @@ config KVM
 	depends on X86 && EXPERIMENTAL
 	select PREEMPT_NOTIFIERS
 	select ANON_INODES
+	select GUEST_ACCOUNTING
 	---help---
 	  Support hosting fully virtualized guest machines using hardware
 	  virtualization extensions.  You will need a fairly recent

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

* Re: [kvm-devel] [PATCH 4/4] Modify KVM to update guest time accounting.
  2007-08-20 13:14 [PATCH 4/4] Modify KVM to update guest time accounting Laurent Vivier
@ 2007-08-20 13:40 ` Avi Kivity
  2007-08-20 13:49   ` Laurent Vivier
  0 siblings, 1 reply; 5+ messages in thread
From: Avi Kivity @ 2007-08-20 13:40 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: Ingo Molnar, kvm-devel, linux-kernel, virtualization

Laurent Vivier wrote:
> [PATCH 4/4] Modify KVM to update guest time accounting.
>
>   

> Index: kvm/drivers/kvm/kvm.h
> ===================================================================
> --- kvm.orig/drivers/kvm/kvm.h	2007-08-20 13:23:53.000000000 +0200
> +++ kvm/drivers/kvm/kvm.h	2007-08-20 13:23:58.000000000 +0200
> @@ -589,6 +589,17 @@ void kvm_mmu_unload(struct kvm_vcpu *vcp
>  
>  int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
>  
> +static inline void kvm_guest_enter(void)
> +{
> +#ifdef CONFIG_GUEST_ACCOUNTING
> +	current->flags |= PF_VCPU;
> +#endif
>   

Since you select GUEST_ACCOUNTING, the #ifdef is always true?

> +}
> +
> +static inline void kvm_guest_exit(void)
> +{
>   

Missing content?

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


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

* Re: [kvm-devel] [PATCH 4/4] Modify KVM to update guest time accounting.
  2007-08-20 13:40 ` [kvm-devel] " Avi Kivity
@ 2007-08-20 13:49   ` Laurent Vivier
  2007-08-20 14:08     ` Avi Kivity
  0 siblings, 1 reply; 5+ messages in thread
From: Laurent Vivier @ 2007-08-20 13:49 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Ingo Molnar, kvm-devel, linux-kernel, virtualization

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

Avi Kivity wrote:
> Laurent Vivier wrote:
>> [PATCH 4/4] Modify KVM to update guest time accounting.
>>
>>   
> 
>> Index: kvm/drivers/kvm/kvm.h
>> ===================================================================
>> --- kvm.orig/drivers/kvm/kvm.h    2007-08-20 13:23:53.000000000 +0200
>> +++ kvm/drivers/kvm/kvm.h    2007-08-20 13:23:58.000000000 +0200
>> @@ -589,6 +589,17 @@ void kvm_mmu_unload(struct kvm_vcpu *vcp
>>  
>>  int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
>>  
>> +static inline void kvm_guest_enter(void)
>> +{
>> +#ifdef CONFIG_GUEST_ACCOUNTING
>> +    current->flags |= PF_VCPU;
>> +#endif
>>   
> 
> Since you select GUEST_ACCOUNTING, the #ifdef is always true?

It is just to avoid error if we compile kvm module outside of the kernel, with
kernel without support of guest accounting. Can be removed if you want.

>> +}
>> +
>> +static inline void kvm_guest_exit(void)
>> +{
>>   
> 
> Missing content?

No, empty function.

It is just to introduce "symmetry" in code, the VCPU code begins with
"kvm_guest_start()" and ends with "kvm_guest_exit()". And we have no operation
to do in kvm_guest_exit() (the PF_VCPU is cleared by account_system_time()), so
"empty function", removed by the optimizer (I hope).

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] 5+ messages in thread

* Re: [kvm-devel] [PATCH 4/4] Modify KVM to update guest time accounting.
  2007-08-20 13:49   ` Laurent Vivier
@ 2007-08-20 14:08     ` Avi Kivity
  2007-08-20 14:22       ` Laurent Vivier
  0 siblings, 1 reply; 5+ messages in thread
From: Avi Kivity @ 2007-08-20 14:08 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: Ingo Molnar, kvm-devel, linux-kernel, virtualization

Laurent Vivier wrote:
> Avi Kivity wrote:
>   
>> Laurent Vivier wrote:
>>     
>>> [PATCH 4/4] Modify KVM to update guest time accounting.
>>>
>>>   
>>>       
>>> Index: kvm/drivers/kvm/kvm.h
>>> ===================================================================
>>> --- kvm.orig/drivers/kvm/kvm.h    2007-08-20 13:23:53.000000000 +0200
>>> +++ kvm/drivers/kvm/kvm.h    2007-08-20 13:23:58.000000000 +0200
>>> @@ -589,6 +589,17 @@ void kvm_mmu_unload(struct kvm_vcpu *vcp
>>>  
>>>  int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
>>>  
>>> +static inline void kvm_guest_enter(void)
>>> +{
>>> +#ifdef CONFIG_GUEST_ACCOUNTING
>>> +    current->flags |= PF_VCPU;
>>> +#endif
>>>   
>>>       
>> Since you select GUEST_ACCOUNTING, the #ifdef is always true?
>>     
>
> It is just to avoid error if we compile kvm module outside of the kernel, with
> kernel without support of guest accounting. Can be removed if you want.
>
>   

Ah okay.  We take care of the external module in 
external-module-compat.h (in this case, we can #define PF_VCPU to 0 if 
it is undefined).

>>> +}
>>> +
>>> +static inline void kvm_guest_exit(void)
>>> +{
>>>   
>>>       
>> Missing content?
>>     
>
> No, empty function.
>
> It is just to introduce "symmetry" in code, the VCPU code begins with
> "kvm_guest_start()" and ends with "kvm_guest_exit()". And we have no operation
> to do in kvm_guest_exit() (the PF_VCPU is cleared by account_system_time()), so
> "empty function", removed by the optimizer (I hope).
>   

But what if account_system_time() is not called (because we exited 
before the timer interrupt hit)?


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


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

* Re: [kvm-devel] [PATCH 4/4] Modify KVM to update guest time accounting.
  2007-08-20 14:08     ` Avi Kivity
@ 2007-08-20 14:22       ` Laurent Vivier
  0 siblings, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2007-08-20 14:22 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel, linux-kernel, virtualization

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

Avi Kivity wrote:
> Laurent Vivier wrote:
>> Avi Kivity wrote:
>>   
>>> Laurent Vivier wrote:
>>>     
>>>> [PATCH 4/4] Modify KVM to update guest time accounting.
>>>>
>>>>   
>>>>       
>>>> Index: kvm/drivers/kvm/kvm.h
>>>> ===================================================================
>>>> --- kvm.orig/drivers/kvm/kvm.h    2007-08-20 13:23:53.000000000 +0200
>>>> +++ kvm/drivers/kvm/kvm.h    2007-08-20 13:23:58.000000000 +0200
>>>> @@ -589,6 +589,17 @@ void kvm_mmu_unload(struct kvm_vcpu *vcp
>>>>  
>>>>  int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
>>>>  
>>>> +static inline void kvm_guest_enter(void)
>>>> +{
>>>> +#ifdef CONFIG_GUEST_ACCOUNTING
>>>> +    current->flags |= PF_VCPU;
>>>> +#endif
>>>>   
>>>>       
>>> Since you select GUEST_ACCOUNTING, the #ifdef is always true?
>>>     
>> It is just to avoid error if we compile kvm module outside of the kernel, with
>> kernel without support of guest accounting. Can be removed if you want.
>>
>>   
> 
> Ah okay.  We take care of the external module in 
> external-module-compat.h (in this case, we can #define PF_VCPU to 0 if 
> it is undefined).

OK

>>>> +}
>>>> +
>>>> +static inline void kvm_guest_exit(void)
>>>> +{
>>>>   
>>>>       
>>> Missing content?
>>>     
>> No, empty function.
>>
>> It is just to introduce "symmetry" in code, the VCPU code begins with
>> "kvm_guest_start()" and ends with "kvm_guest_exit()". And we have no operation
>> to do in kvm_guest_exit() (the PF_VCPU is cleared by account_system_time()), so
>> "empty function", removed by the optimizer (I hope).
>>   
> 
> But what if account_system_time() is not called (because we exited 
> before the timer interrupt hit)?

account_system_time() is called by the scheduler on tick. If we clear PF_VCPU in
kvm_guest_exit(), the flag is always cleared when account_system_time() is
executed, so we account "0", if we call account_system_time() directly from
kvm_guest_exit() we account "1", so we subtract 1 to system time, and we have
perhaps not used 1 tick in system: in my opinion this implies wrong results.

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] 5+ messages in thread

end of thread, other threads:[~2007-08-20 14:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-20 13:14 [PATCH 4/4] Modify KVM to update guest time accounting Laurent Vivier
2007-08-20 13:40 ` [kvm-devel] " Avi Kivity
2007-08-20 13:49   ` Laurent Vivier
2007-08-20 14:08     ` Avi Kivity
2007-08-20 14:22       ` Laurent Vivier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).