@@ -899,6 +899,7 @@ struct kvm_vcpu_arch {
u64 msr_val;
u64 last_steal;
struct gfn_to_hva_cache cache;
+ u64 steal_total;
} st;
u64 l1_tsc_offset;
@@ -11,6 +11,7 @@
#include "lapic.h"
#include "mmu.h"
#include "mmu/mmu_internal.h"
+#include "cpuid.h"
static int vcpu_get_timer_advance_ns(void *data, u64 *val)
{
@@ -56,6 +57,19 @@ static int vcpu_get_tsc_scaling_frac_bits(void *data, u64 *val)
DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits, NULL, "%llu\n");
+static int vcpu_get_steal_time(void *data, u64 *val)
+{
+ struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
+
+ if (!guest_pv_has(vcpu, KVM_FEATURE_STEAL_TIME))
+ return 1;
+
+ *val = vcpu->arch.st.steal_total;
+ return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(vcpu_steal_time_fops, vcpu_get_steal_time, NULL, "%llu\n");
+
void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
{
debugfs_create_file("guest_mode", 0444, debugfs_dentry, vcpu,
@@ -76,6 +90,9 @@ void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_
debugfs_dentry, vcpu,
&vcpu_tsc_scaling_frac_fops);
}
+
+ debugfs_create_file("steal-time", 0444, debugfs_dentry, vcpu,
+ &vcpu_steal_time_fops);
}
/*
@@ -3735,6 +3735,7 @@ static void record_steal_time(struct kvm_vcpu *vcpu)
steal += current->sched_info.run_delay -
vcpu->arch.st.last_steal;
vcpu->arch.st.last_steal = current->sched_info.run_delay;
+ vcpu->arch.st.steal_total = steal;
unsafe_put_user(steal, &st->steal, out);
version += 1;
It's helpful to know whether some other host activity affects a virtual machine to estimate virtual machine quality of sevice. The fact of virtual machine affection from the host side can be obtained by reading "preemption_reported" counter via kvm entries of sysfs, but the exact vcpu waiting time isn't reported to the host. This patch adds this reporting. Signed-off-by: Denis Plotnikov <den-plotnikov@yandex-team.ru> --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/debugfs.c | 17 +++++++++++++++++ arch/x86/kvm/x86.c | 1 + 3 files changed, 19 insertions(+)