kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: stats: add stats to detect if vcpu is currently halted
@ 2021-08-17 23:05 Jing Zhang
  2021-08-17 23:46 ` Sean Christopherson
  0 siblings, 1 reply; 10+ messages in thread
From: Jing Zhang @ 2021-08-17 23:05 UTC (permalink / raw)
  To: KVM, Paolo Bonzini, David Matlack, Peter Shier, Oliver Upton,
	Cannon Matthews
  Cc: Jing Zhang

Current guest/host/halt stats don't show when we are currently halting
well. If a guest halts for a long period of time they could appear
pathologically blocked but really it's the opposite there's nothing to
do.
Simply count the number of times we enter and leave the kvm_vcpu_block
function per vcpu, if they are unequal, then a VCPU is currently
halting.
The existing stats like halt_exits and halt_wakeups don't quite capture
this. The time spend halted and halt polling is reported eventually, but
not until we wakeup and resume. If a guest were to indefinitely halt one
of it's CPUs we would never know, it may simply appear blocked.

Original-by: Cannon Matthews <cannonmatthews@google.com>
Signed-off-by: Jing Zhang <jingzhangos@google.com>
---
 include/linux/kvm_host.h  | 4 +++-
 include/linux/kvm_types.h | 2 ++
 virt/kvm/kvm_main.c       | 2 ++
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index d447b21cdd73..23d2e19af3ce 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1459,7 +1459,9 @@ struct _kvm_stats_desc {
 	STATS_DESC_LOGHIST_TIME_NSEC(VCPU_GENERIC, halt_poll_fail_hist,	       \
 			HALT_POLL_HIST_COUNT),				       \
 	STATS_DESC_LOGHIST_TIME_NSEC(VCPU_GENERIC, halt_wait_hist,	       \
-			HALT_POLL_HIST_COUNT)
+			HALT_POLL_HIST_COUNT),				       \
+	STATS_DESC_COUNTER(VCPU_GENERIC, halt_block_starts),		       \
+	STATS_DESC_COUNTER(VCPU_GENERIC, halt_block_ends)
 
 extern struct dentry *kvm_debugfs_dir;
 
diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h
index de7fb5f364d8..ea7d26017fa6 100644
--- a/include/linux/kvm_types.h
+++ b/include/linux/kvm_types.h
@@ -93,6 +93,8 @@ struct kvm_vcpu_stat_generic {
 	u64 halt_poll_success_hist[HALT_POLL_HIST_COUNT];
 	u64 halt_poll_fail_hist[HALT_POLL_HIST_COUNT];
 	u64 halt_wait_hist[HALT_POLL_HIST_COUNT];
+	u64 halt_block_starts;
+	u64 halt_block_ends;
 };
 
 #define KVM_STATS_NAME_SIZE	48
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 3e67c93ca403..5c3a21d2fbea 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3206,6 +3206,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
 	bool waited = false;
 	u64 block_ns;
 
+	++vcpu->stat.generic.halt_block_starts;
 	kvm_arch_vcpu_blocking(vcpu);
 
 	start = cur = poll_end = ktime_get();
@@ -3285,6 +3286,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
 
 	trace_kvm_vcpu_wakeup(block_ns, waited, vcpu_valid_wakeup(vcpu));
 	kvm_arch_vcpu_block_finish(vcpu);
+	++vcpu->stat.generic.halt_block_ends;
 }
 EXPORT_SYMBOL_GPL(kvm_vcpu_block);
 

base-commit: a3e0b8bd99ab098514bde2434301fa6fde040da2
-- 
2.33.0.rc1.237.g0d66db33f3-goog


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

end of thread, other threads:[~2021-09-22 16:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-17 23:05 [PATCH] KVM: stats: add stats to detect if vcpu is currently halted Jing Zhang
2021-08-17 23:46 ` Sean Christopherson
2021-08-18 16:09   ` Jing Zhang
2021-08-18 16:57     ` Sean Christopherson
2021-08-18 17:01     ` Cannon Matthews
2021-08-19 18:09       ` Jing Zhang
2021-08-19 22:37       ` Sean Christopherson
2021-08-20 18:42         ` Jing Zhang
2021-09-22 16:39           ` Sean Christopherson
2021-09-22 16:41             ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).