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@xxxxxxxxxxxxxx> --- 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(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 4a68cb3eba78f..3d4bd3ca83593 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -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; diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c index 999227fc7c665..e67136954c095 100644 --- a/arch/x86/kvm/debugfs.c +++ b/arch/x86/kvm/debugfs.c @@ -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); } /* diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 70219e4069874..ca5f21b930d4d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -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; -- 2.34.1