===================================================================
@@ -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
===================================================================
@@ -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
}
/*
===================================================================
@@ -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