[patch 4/5] kvmclock: account stolen time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Which makes stolen time information available in procfs/vmstat.

Signed-off-by: Marcelo Tosatti <mtosatti@xxxxxxxxxx>

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


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux