public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm/debugfs: add file to get vcpu steal time statistics
@ 2024-09-17 11:20 Denis Plotnikov
  2024-09-22  8:04 ` Sean Christopherson
  0 siblings, 1 reply; 8+ messages in thread
From: Denis Plotnikov @ 2024-09-17 11:20 UTC (permalink / raw)
  To: kvm; +Cc: seanjc, pbonzini, yc-core, linux-kernel

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(+)

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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-11-26  9:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-17 11:20 [PATCH] kvm/debugfs: add file to get vcpu steal time statistics Denis Plotnikov
2024-09-22  8:04 ` Sean Christopherson
2024-09-23  9:32   ` Denis Plotnikov
2024-09-23 11:46     ` Sean Christopherson
2024-09-30 14:29       ` Denis Plotnikov
2024-09-30 15:44         ` Sean Christopherson
2024-11-05 12:43           ` Denis Plotnikov
2024-11-26  9:54             ` Denis Plotnikov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox