All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Vivier <Laurent.Vivier@bull.net>
To: Laurent Vivier <Laurent.Vivier@bull.net>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
	kvm-devel <kvm-devel@lists.sourceforge.net>,
	Ingo Molnar <mingo@elte.hu>,
	virtualization <virtualization@lists.linux-foundation.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH/RFC 4/4, second shot]KVM uses "account_guest_time()"
Date: Fri, 17 Aug 2007 13:54:52 +0200	[thread overview]
Message-ID: <46C58C8C.3080803@bull.net> (raw)
In-Reply-To: <46C58BD5.3090207@bull.net>

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

KVM updates vtime in task_struct to allow account_guest_time() to modify user,
system and guest time in cpustat accordingly.

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

Index: kvm/drivers/kvm/Kconfig
===================================================================
--- kvm.orig/drivers/kvm/Kconfig	2007-08-17 10:24:46.000000000 +0200
+++ kvm/drivers/kvm/Kconfig	2007-08-17 10:25:25.000000000 +0200
@@ -41,4 +41,10 @@
 	  Provides support for KVM on AMD processors equipped with the AMD-V
 	  (SVM) extensions.
 
+config GUEST_ACCOUNTING
+	bool "Virtual Machine accounting support"
+	depends on KVM
+	---help---
+	  Allows to account CPU time used by the Virtual Machines.
+
 endif # VIRTUALIZATION
Index: kvm/drivers/kvm/kvm.h
===================================================================
--- kvm.orig/drivers/kvm/kvm.h	2007-08-17 10:19:30.000000000 +0200
+++ kvm/drivers/kvm/kvm.h	2007-08-17 10:21:56.000000000 +0200
@@ -589,6 +589,19 @@
 
 int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
 
+#ifdef CONFIG_GUEST_ACCOUNTING
+static inline ktime_t kvm_guest_enter(void)
+{
+	 return ktime_get();
+}
+
+static inline void kvm_guest_exit(ktime_t enter)
+{
+	 ktime_t delta = ktime_sub(ktime_get(), enter);
+	 current->vtime = ktime_add(current->vtime, delta);
+}
+#endif
+
 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-17 10:22:07.000000000 +0200
+++ kvm/drivers/kvm/svm.c	2007-08-17 10:23:32.000000000 +0200
@@ -1392,6 +1392,9 @@
 	u16 gs_selector;
 	u16 ldt_selector;
 	int r;
+#ifdef CONFIG_GUEST_ACCOUNTING
+	ktime_t now;
+#endif
 
 again:
 	r = kvm_mmu_reload(vcpu);
@@ -1404,6 +1407,9 @@
 	clgi();
 
 	vcpu->guest_mode = 1;
+#ifdef CONFIG_GUEST_ACCOUNTING
+	now = kvm_guest_enter();
+#endif
 	if (vcpu->requests)
 		if (test_and_clear_bit(KVM_TLB_FLUSH, &vcpu->requests))
 		    svm_flush_tlb(vcpu);
@@ -1536,6 +1542,9 @@
 #endif
 		: "cc", "memory" );
 
+#ifdef CONFIG_GUEST_ACCOUNTING
+	kvm_guest_exit(now);
+#endif
 	vcpu->guest_mode = 0;
 
 	if (vcpu->fpu_active) {
Index: kvm/drivers/kvm/vmx.c
===================================================================
--- kvm.orig/drivers/kvm/vmx.c	2007-08-17 10:23:36.000000000 +0200
+++ kvm/drivers/kvm/vmx.c	2007-08-17 10:24:37.000000000 +0200
@@ -2052,6 +2052,9 @@
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
 	u8 fail;
 	int r;
+#ifdef CONFIG_GUEST_ACCOUNTING
+	ktime_t now;
+#endif
 
 preempted:
 	if (vcpu->guest_debug.enabled)
@@ -2078,6 +2081,9 @@
 	local_irq_disable();
 
 	vcpu->guest_mode = 1;
+#ifdef CONFIG_GUEST_ACCOUNTING
+	now = kvm_guest_enter();
+#endif
 	if (vcpu->requests)
 		if (test_and_clear_bit(KVM_TLB_FLUSH, &vcpu->requests))
 		    vmx_flush_tlb(vcpu);
@@ -2198,6 +2204,9 @@
 		[cr2]"i"(offsetof(struct kvm_vcpu, cr2))
 	      : "cc", "memory" );
 
+#ifdef CONFIG_GUEST_ACCOUNTING
+	kvm_guest_exit(now);
+#endif
 	vcpu->guest_mode = 0;
 	local_irq_enable();
 

  parent reply	other threads:[~2007-08-17 11:54 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <46C4719A.2060308@bull.net>
2007-08-16 15:57 ` [PATCH/RFC 1/4]Introduce a new field "guest" in cpustat Laurent Vivier
2007-08-16 15:57 ` Laurent Vivier
     [not found] ` <46C4720F.7030304@bull.net>
2007-08-16 15:57   ` [PATCH/RFC 2/4]Introduce a new field "guest" in task_struct Laurent Vivier
2007-08-16 15:57   ` Laurent Vivier
     [not found]   ` <46C4725A.4070607@bull.net>
2007-08-16 15:58     ` [PATCH/RFC 3/4]Introduce "account modifiers" mechanism Laurent Vivier
2007-08-16 15:58     ` Laurent Vivier
2007-08-16 22:39       ` Rusty Russell
2007-08-16 22:39       ` Rusty Russell
2007-08-17  7:35         ` Laurent Vivier
2007-08-17  7:35           ` Laurent Vivier
2007-08-17  8:30           ` Rusty Russell
2007-08-17  8:30           ` Rusty Russell
2007-08-17  8:30             ` Rusty Russell
2007-08-17  9:16             ` Laurent Vivier
2007-08-17  9:16             ` Laurent Vivier
2007-08-17  9:16               ` Laurent Vivier
2007-08-17 11:51               ` [PATCH/RFC 3/4, second shot]Introduce "account_guest_time" Laurent Vivier
2007-08-17 11:51               ` Laurent Vivier
2007-08-17 11:51                 ` Laurent Vivier
2007-08-17 11:54                 ` [PATCH/RFC 4/4, second shot]KVM uses "account_guest_time()" Laurent Vivier
2007-08-17 11:54                 ` Laurent Vivier [this message]
2007-08-17 13:03                   ` [kvm-devel] " Avi Kivity
2007-08-17 13:03                   ` Avi Kivity
2007-08-17 13:03                     ` Avi Kivity
2007-08-17 13:16                     ` [kvm-devel] " Laurent Vivier
2007-08-17 13:16                       ` Laurent Vivier
2007-08-19  7:39                       ` [kvm-devel] " Avi Kivity
2007-08-19  7:39                       ` Avi Kivity
2007-08-19  7:39                         ` Avi Kivity
2007-08-17 13:16                     ` [kvm-devel] " Laurent Vivier
2007-08-17 12:59                 ` [kvm-devel] [PATCH/RFC 3/4, second shot]Introduce "account_guest_time" Avi Kivity
2007-08-17 12:59                 ` Avi Kivity
2007-08-17 12:55               ` [kvm-devel] [PATCH/RFC 3/4]Introduce "account modifiers" mechanism Avi Kivity
2007-08-17 12:55                 ` Avi Kivity
2007-08-17 13:08                 ` [kvm-devel] " Laurent Vivier
2007-08-17 13:08                   ` Laurent Vivier
2007-08-17 13:32                   ` [kvm-devel] " Christian Borntraeger
2007-08-17 13:32                   ` Christian Borntraeger
2007-08-17 13:32                     ` Christian Borntraeger
2007-08-19  7:41                   ` [kvm-devel] " Avi Kivity
2007-08-19  7:41                   ` Avi Kivity
2007-08-19  7:41                     ` Avi Kivity
2007-08-17 13:08                 ` [kvm-devel] " Laurent Vivier
2007-08-17 14:12                 ` Laurent Vivier
2007-08-17 14:12                 ` Laurent Vivier
2007-08-17 14:12                   ` Laurent Vivier
2007-08-19  7:38                   ` [kvm-devel] " Avi Kivity
2007-08-19  7:38                     ` Avi Kivity
2007-08-20  7:30                     ` [kvm-devel] " Laurent Vivier
2007-08-20  7:30                     ` Laurent Vivier
2007-08-20  7:30                       ` Laurent Vivier
2007-08-20  7:55                       ` [kvm-devel] " Avi Kivity
2007-08-20  7:55                         ` Avi Kivity
2007-08-20  7:55                       ` [kvm-devel] " Avi Kivity
2007-08-19  7:38                   ` Avi Kivity
2007-08-17 12:55               ` Avi Kivity
2007-08-17  7:35         ` Laurent Vivier
     [not found]     ` <46C472D2.7000702@bull.net>
2007-08-16 15:59       ` [PATCH/RFC 4/4]Modify KVM to use the "account modifiers" Laurent Vivier
2007-08-16 15:59       ` Laurent Vivier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46C58C8C.3080803@bull.net \
    --to=laurent.vivier@bull.net \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rusty@rustcorp.com.au \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.