All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: kvm@vger.kernel.org
Cc: riel@redhat.com, Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 4/5] kvmclock: account stolen time
Date: Fri, 16 Oct 2009 01:08:50 -0300	[thread overview]
Message-ID: <20091016041415.779161960@redhat.com> (raw)
In-Reply-To: 20091016040845.957760057@redhat.com

[-- Attachment #1: kvm-accounts-stolen --]
[-- Type: text/plain, Size: 2425 bytes --]

Which makes stolen time information available in procfs/vmstat.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: kvm/arch/x86/kernel/kvmclock.c
===================================================================
--- kvm.orig/arch/x86/kernel/kvmclock.c
+++ kvm/arch/x86/kernel/kvmclock.c
@@ -22,11 +22,14 @@
 #include <asm/msr.h>
 #include <asm/apic.h>
 #include <linux/percpu.h>
+#include <linux/kernel_stat.h>
 
 #include <asm/x86_init.h>
 #include <asm/reboot.h>
+#include <asm/cputime.h>
 
 #define KVM_SCALE 22
+#define NS_PER_TICK (1000000000LL / HZ)
 
 static int kvmclock = 1;
 
@@ -50,6 +53,29 @@ static DEFINE_PER_CPU_SHARED_ALIGNED(str
 
 static struct pvclock_wall_clock wall_clock;
 
+static DEFINE_PER_CPU(u64, total_stolen);
+static DEFINE_PER_CPU(u64, residual_stolen);
+
+void kvm_account_steal_time(void)
+{
+	struct kvm_vcpu_runtime_info *rinfo;
+	cputime_t ticks;
+	u64 stolen_time, stolen_delta;
+
+	rinfo = &get_cpu_var(run_info);
+	stolen_time = rinfo->stolen_time;
+	stolen_delta = stolen_time - __get_cpu_var(total_stolen);
+
+	__get_cpu_var(total_stolen) = stolen_time;
+	put_cpu_var(rinfo);
+
+	stolen_delta += __get_cpu_var(residual_stolen);
+
+	ticks = iter_div_u64_rem(stolen_delta, NS_PER_TICK, &stolen_delta);
+	__get_cpu_var(residual_stolen) = stolen_delta;
+	account_steal_ticks(ticks);
+}
+
 /*
  * The wallclock is the time of day when we booted. Since then, some time may
  * have elapsed since the hypervisor wrote the data. So we try to account for
Index: kvm/kernel/sched.c
===================================================================
--- kvm.orig/kernel/sched.c
+++ kvm/kernel/sched.c
@@ -74,6 +74,9 @@
 
 #include <asm/tlb.h>
 #include <asm/irq_regs.h>
+#ifdef CONFIG_KVM_CLOCK
+#include <asm/kvm_para.h>
+#endif
 
 #include "sched_cpupri.h"
 
@@ -5102,6 +5105,9 @@ void account_process_tick(struct task_st
 				    one_jiffy_scaled);
 	else
 		account_idle_time(cputime_one_jiffy);
+#ifdef CONFIG_KVM_CLOCK
+	kvm_account_steal_time();
+#endif
 }
 
 /*
Index: kvm/arch/x86/include/asm/kvm_para.h
===================================================================
--- kvm.orig/arch/x86/include/asm/kvm_para.h
+++ kvm/arch/x86/include/asm/kvm_para.h
@@ -58,6 +58,7 @@ struct kvm_vcpu_runtime_info {
 };
 
 extern void kvmclock_init(void);
+extern void kvm_account_steal_time(void);
 
 
 /* This instruction is vmcall.  On non-VT architectures, it will generate a



  parent reply	other threads:[~2009-10-16  4:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-16  4:08 [patch 0/5] report stolen time via pvclock Marcelo Tosatti
2009-10-16  4:08 ` [patch 1/5] KVM: x86: report stolen time Marcelo Tosatti
2009-10-16  4:08 ` [patch 2/5] pvclock: move code to pvclock.h Marcelo Tosatti
2009-10-16  4:08 ` [patch 3/5] kvmclock: stolen time aware sched_clock Marcelo Tosatti
2009-10-16  4:08 ` Marcelo Tosatti [this message]
2009-10-16  4:08 ` [patch 5/5] qemu-kvm-x86: report pvclock runtime capability Marcelo Tosatti

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=20091016041415.779161960@redhat.com \
    --to=mtosatti@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=riel@redhat.com \
    /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.