From: Denis Plotnikov <den-plotnikov@yandex-team.ru>
To: kvm@vger.kernel.org
Cc: seanjc@google.com, pbonzini@redhat.com, yc-core@yandex-team.ru,
linux-kernel@vger.kernel.org
Subject: [PATCH] kvm/debugfs: add file to get vcpu steal time statistics
Date: Tue, 17 Sep 2024 14:20:28 +0300 [thread overview]
Message-ID: <20240917112028.278005-1-den-plotnikov@yandex-team.ru> (raw)
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
next reply other threads:[~2024-09-17 11:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-17 11:20 Denis Plotnikov [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240917112028.278005-1-den-plotnikov@yandex-team.ru \
--to=den-plotnikov@yandex-team.ru \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=yc-core@yandex-team.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®