Skip to contentSkip to conversation

Modify KVM to update guest time accounting.

PATCH Superseded Laurent Vivier 2 participants 9 messages Aug 20, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

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

Signature · 2 lines
------------- Laurent.Vivier-6ktuUTfB/[email protected]  --------------
          "Software is hard" - Donald Knuth
drivers/kvm/kvm.h +11 -0
Index: kvm/drivers/kvm/kvm.h
===================================================================
@@ -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)
 {
drivers/kvm/svm.c +2 -0
Index: kvm/drivers/kvm/svm.c
===================================================================
@@ -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) {
drivers/kvm/vmx.c +2 -0
Index: kvm/drivers/kvm/vmx.c
===================================================================
@@ -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();
 
drivers/kvm/Kconfig +1 -0
Index: kvm/drivers/kvm/Kconfig
===================================================================
@@ -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

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

_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

#1 lore raw
Quoted 9 lines · Laurent Vivier

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

Index: kvm/drivers/kvm/kvm.h
===================================================================

drivers/kvm/kvm.h void kvm_mmu_unload(struct kvm_vcpu *vcp · line 597

Quoted 9 lines
drivers/kvm/kvm.h +5 -0
@@ -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?

drivers/kvm/kvm.h void kvm_mmu_unload(struct kvm_vcpu *vcp

Quoted 5 lines
drivers/kvm/kvm.h +4 -0
+}
+
+static inline void kvm_guest_exit(void)
+{
 

Missing content?

Signature · 8 lines
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/
#8 lore raw
In reply to Laurent Vivier
Quoted 9 lines · Laurent Vivier

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

Index: kvm/drivers/kvm/kvm.h
===================================================================

drivers/kvm/kvm.h void kvm_mmu_unload(struct kvm_vcpu *vcp · line 597

Quoted 9 lines
drivers/kvm/kvm.h +5 -0
@@ -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?

drivers/kvm/kvm.h void kvm_mmu_unload(struct kvm_vcpu *vcp

Quoted 5 lines
drivers/kvm/kvm.h +4 -0
+}
+
+static inline void kvm_guest_exit(void)
+{
 

Missing content?

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
In reply to Avi Kivity
Quoted 13 lines · Avi Kivity
Quoted 12 lines · Laurent Vivier

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

Index: kvm/drivers/kvm/kvm.h
===================================================================

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +0 -0
@@ -589,6 +589,17 @@ void kvm_mmu_unload(struct kvm_vcpu *vcp
 
 int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
 
Quoted 8 lines

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 void kvm_mmu_unload(struct kvm_vcpu *vcp · line 597

Quoted 6 lines
drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +5 -0
+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.

Quoted 7 lines

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 void kvm_mmu_unload(struct kvm_vcpu *vcp · line 602

Quoted 5 lines
drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +4 -0
+}
+
+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

Signature · 2 lines
------------- Laurent.Vivier-6ktuUTfB/[email protected]  --------------
          "Software is hard" - Donald Knuth

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

_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

#7 lore raw
In reply to Avi Kivity
Quoted 13 lines · Avi Kivity
Quoted 12 lines · Laurent Vivier

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

Index: kvm/drivers/kvm/kvm.h
===================================================================

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +0 -0
@@ -589,6 +589,17 @@ void kvm_mmu_unload(struct kvm_vcpu *vcp
 
 int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
 
Quoted 8 lines

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 void kvm_mmu_unload(struct kvm_vcpu *vcp · line 597

Quoted 6 lines
drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +5 -0
+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.

Quoted 7 lines

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 void kvm_mmu_unload(struct kvm_vcpu *vcp · line 602

Quoted 5 lines
drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +4 -0
+}
+
+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

Signature · 2 lines
------------- [email protected]  --------------
          "Software is hard" - Donald Knuth

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/virtualization

#3 lore raw
In reply to Laurent Vivier
Quoted 26 lines · Laurent Vivier
Quoted 14 lines · Avi Kivity
Quoted 12 lines · Laurent Vivier

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

Index: kvm/drivers/kvm/kvm.h
===================================================================

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +0 -0
@@ -589,6 +589,17 @@ void kvm_mmu_unload(struct kvm_vcpu *vcp
 
 int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
 
Quoted 9 lines

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 void kvm_mmu_unload(struct kvm_vcpu *vcp · line 598

Quoted 7 lines
drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +5 -0
+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?

Quoted 4 lines

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).

Quoted 9 lines
Quoted 8 lines

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 void kvm_mmu_unload(struct kvm_vcpu *vcp · line 603

Quoted 6 lines
drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +4 -0
+}
+
+static inline void kvm_guest_exit(void)
+{
 

Missing content?

Quoted 7 lines

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)?

Signature · 1 line
error compiling committee.c: too many arguments to function
#6 lore raw
In reply to Laurent Vivier
Quoted 26 lines · Laurent Vivier
Quoted 14 lines · Avi Kivity
Quoted 12 lines · Laurent Vivier

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

Index: kvm/drivers/kvm/kvm.h
===================================================================

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +0 -0
@@ -589,6 +589,17 @@ void kvm_mmu_unload(struct kvm_vcpu *vcp
 
 int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
 
Quoted 9 lines

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 void kvm_mmu_unload(struct kvm_vcpu *vcp · line 598

Quoted 7 lines
drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +5 -0
+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?

Quoted 4 lines

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).

Quoted 9 lines
Quoted 8 lines

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 void kvm_mmu_unload(struct kvm_vcpu *vcp · line 603

Quoted 6 lines
drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +4 -0
+}
+
+static inline void kvm_guest_exit(void)
+{
 

Missing content?

Quoted 7 lines

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)?

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw
In reply to Avi Kivity
Quoted 26 lines · Avi Kivity
Quoted 25 lines · Laurent Vivier
Quoted 23 lines · Avi Kivity
Quoted 9 lines · Laurent Vivier

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

Index: kvm/drivers/kvm/kvm.h
===================================================================

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 void kvm_mmu_unload(struct kvm_vcpu *vcp · line 598

Quoted 10 lines
drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +5 -0
@@ -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?

Quoted 8 lines
Quoted 4 lines

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

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 void kvm_mmu_unload(struct kvm_vcpu *vcp · line 603

Quoted 6 lines
drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +4 -0
+}
+
+static inline void kvm_guest_exit(void)
+{
 

Missing content?

No, empty function.

Quoted 8 lines
Quoted 5 lines

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

Signature · 2 lines
------------- Laurent.Vivier-6ktuUTfB/[email protected]  --------------
          "Software is hard" - Donald Knuth

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

_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

#5 lore raw
In reply to Avi Kivity
Quoted 26 lines · Avi Kivity
Quoted 25 lines · Laurent Vivier
Quoted 23 lines · Avi Kivity
Quoted 9 lines · Laurent Vivier

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

Index: kvm/drivers/kvm/kvm.h
===================================================================

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 void kvm_mmu_unload(struct kvm_vcpu *vcp · line 598

Quoted 10 lines
drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +5 -0
@@ -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?

Quoted 8 lines
Quoted 4 lines

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

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines

drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 void kvm_mmu_unload(struct kvm_vcpu *vcp · line 603

Quoted 6 lines
drivers/kvm/kvm.h 2007-08-20 13:23:58.000000000 +0200 renamed from drivers/kvm/kvm.h 2007-08-20 13:23:53.000000000 +0200 +4 -0
+}
+
+static inline void kvm_guest_exit(void)
+{
 

Missing content?

No, empty function.

Quoted 8 lines
Quoted 5 lines

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

Signature · 2 lines
------------- [email protected]  --------------
          "Software is hard" - Donald Knuth

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/virtualization