Re: [RESEND 2][PATCH 4/4] Modify KVM to update guest time accounting.

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Laurent Vivier <Laurent.Vivier@...>
Cc: linux-kernel <linux-kernel@...>, Avi Kivity <avi@...>
Date: Monday, October 15, 2007 - 5:38 am

* Laurent Vivier <Laurent.Vivier@bull.net> wrote:


FYI, KVM abstracted its guest-mode entry code recently so this did not 
apply - find below the reworked patch.

	Ingo

------------------->
Subject: sched: guest CPU accounting: maintain guest state in KVM
From: Laurent Vivier <Laurent.Vivier@bull.net>

Modify KVM to update guest time accounting.

[ mingo@elte.hu: ported to 2.6.24 KVM. ]

Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
Acked-by: Avi Kivity <avi@qumranet.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 drivers/kvm/kvm.h      |   16 ++++++++++++++++
 drivers/kvm/kvm_main.c |    2 ++
 2 files changed, 18 insertions(+)

Index: linux/drivers/kvm/kvm.h
===================================================================
--- linux.orig/drivers/kvm/kvm.h
+++ linux/drivers/kvm/kvm.h
@@ -624,6 +624,22 @@ void kvm_mmu_unload(struct kvm_vcpu *vcp
 
 int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
 
+/*
+ * Compatibility define - PF_VCPU is only available in v2.6.24+ kernels:
+ */
+#ifndef PF_VCPU
+# define PF_VCPU	0
+#endif
+
+static inline void kvm_guest_enter(void)
+{
+	current->flags |= PF_VCPU;
+}
+
+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: linux/drivers/kvm/kvm_main.c
===================================================================
--- linux.orig/drivers/kvm/kvm_main.c
+++ linux/drivers/kvm/kvm_main.c
@@ -2046,6 +2046,7 @@ again:
 		kvm_x86_ops->inject_pending_vectors(vcpu, kvm_run);
 
 	vcpu->guest_mode = 1;
+	kvm_guest_enter();
 
 	if (vcpu->requests)
 		if (test_and_clear_bit(KVM_TLB_FLUSH, &vcpu->requests))
@@ -2053,6 +2054,7 @@ again:
 
 	kvm_x86_ops->run(vcpu, kvm_run);
 
+	kvm_guest_exit();
 	vcpu->guest_mode = 0;
 	local_irq_enable();
 
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [RESEND 2][PATCH 4/4] Modify KVM to update guest time ac..., Ingo Molnar, (Mon Oct 15, 5:38 am)
Re: [RESEND 2][PATCH 4/4] Modify KVM to update guest , Christian Borntraeger, (Mon Oct 15, 7:19 am)
[PATCH] move kvm_guest_exit() after local_irq_enable(), Laurent Vivier, (Thu Oct 18, 9:19 am)
[PATCH] clear PF_VCPU in kvm_guest_exit(), Laurent Vivier, (Wed Oct 17, 9:08 am)
Use virtual cpu accounting if available for guest times., Christian Borntraeger, (Thu Oct 18, 8:39 am)
Re: [kvm-devel] Use virtual cpu accounting if available for ..., Hollis Blanchard, (Fri Oct 19, 12:57 pm)
Re: [PATCH] clear PF_VCPU in kvm_guest_exit(), Avi Kivity, (Wed Oct 17, 10:16 am)
Re: [PATCH] clear PF_VCPU in kvm_guest_exit(), Laurent Vivier, (Wed Oct 17, 11:09 am)
Re: [PATCH] clear PF_VCPU in kvm_guest_exit(), Christian Borntraeger, (Wed Oct 17, 9:18 am)
Re: [RESEND 2][PATCH 4/4] Modify KVM to update guest , Christian Borntraeger, (Mon Oct 15, 7:33 am)
Re: [RESEND 2][PATCH 4/4] Modify KVM to update guest time ac..., Christian Borntraeger, (Mon Oct 15, 10:39 am)