Skip to content

Commit

Permalink
KVM: stats: Add stat to detect if vcpu is currently blocking
Browse files Browse the repository at this point in the history
Add a "blocking" stat that userspace can use to detect the case where a
vCPU is not being run because of an vCPU/guest action, e.g. HLT or WFS on
x86, WFI on arm64, etc...  Current guest/host/halt stats don't show this
well, e.g. if a guest halts for a long period of time then the vCPU could
could appear pathologically blocked due to a host condition, when in
reality the vCPU has been put into a not-runnable state by the guest.

Originally-by: Cannon Matthews <[email protected]>
Suggested-by: Sean Christopherson <[email protected]>
Reviewed-by: David Matlack <[email protected]>
Signed-off-by: Jing Zhang <[email protected]>
[sean: renamed stat to "blocking", massaged changelog]
Signed-off-by: Sean Christopherson <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
jingzhangos authored and bonzini committed Dec 8, 2021
1 parent fac4268 commit c385833
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/linux/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,8 @@ 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_ICOUNTER(VCPU_GENERIC, blocking)

extern struct dentry *kvm_debugfs_dir;

Expand Down
1 change: 1 addition & 0 deletions include/linux/kvm_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ 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 blocking;
};

#define KVM_STATS_NAME_SIZE 48
Expand Down
4 changes: 4 additions & 0 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3282,6 +3282,8 @@ bool kvm_vcpu_block(struct kvm_vcpu *vcpu)
struct rcuwait *wait = kvm_arch_vcpu_get_wait(vcpu);
bool waited = false;

vcpu->stat.generic.blocking = 1;

kvm_arch_vcpu_blocking(vcpu);

prepare_to_rcuwait(wait);
Expand All @@ -3298,6 +3300,8 @@ bool kvm_vcpu_block(struct kvm_vcpu *vcpu)

kvm_arch_vcpu_unblocking(vcpu);

vcpu->stat.generic.blocking = 0;

return waited;
}

Expand Down

0 comments on commit c385833

Please sign in to comment.