From: Krish Sadhukhan <krish.sadhukhan@oracle.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com,
vkuznets@redhat.com, wanpengli@tencent.com, joro@8bytes.org
Subject: [PATCH 3/3 v3] KVM: x86: Add a new VM statistic to show number of VCPUs created in a given VM
Date: Tue, 8 Jun 2021 21:19:35 -0400 [thread overview]
Message-ID: <20210609011935.103017-4-krish.sadhukhan@oracle.com> (raw)
In-Reply-To: <20210609011935.103017-1-krish.sadhukhan@oracle.com>
'struct kvm' already has a member for tracking the number of VCPUs created
in a given VM. Add this as a new VM statistic to KVM debugfs. This statistic
can be a useful metric to track the usage of VCPUs on a host running
customer VMs.
Signed-off-by: Krish Sadhukhan <Krish.Sadhukhan@oracle.com>
---
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/x86.c | 1 +
virt/kvm/kvm_main.c | 2 ++
3 files changed, 4 insertions(+)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index f6d5387bb88f..8f61a3fc3d39 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1138,6 +1138,7 @@ struct kvm_vm_stat {
ulong lpages;
ulong nx_lpage_splits;
ulong max_mmu_page_hash_collisions;
+ ulong vcpus;
};
struct kvm_vcpu_stat {
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index baa953757911..7a1ff3052488 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -258,6 +258,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
VM_STAT("largepages", lpages, .mode = 0444),
VM_STAT("nx_largepages_splitted", nx_lpage_splits, .mode = 0444),
VM_STAT("max_mmu_page_hash_collisions", max_mmu_page_hash_collisions),
+ VM_STAT("vcpus", vcpus),
{ NULL }
};
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 6b4feb92dc79..d910e4020a43 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3318,6 +3318,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
}
kvm->created_vcpus++;
+ kvm->stat.vcpus++;
mutex_unlock(&kvm->lock);
r = kvm_arch_vcpu_precreate(kvm, id);
@@ -3394,6 +3395,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
vcpu_decrement:
mutex_lock(&kvm->lock);
kvm->created_vcpus--;
+ kvm->stat.vcpus--;
mutex_unlock(&kvm->lock);
return r;
}
--
2.27.0
next prev parent reply other threads:[~2021-06-09 2:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-09 1:19 [PATCH 0/3 v3] KVM: nVMX: nSVM: Add more statistics to KVM debugfs Krish Sadhukhan
2021-06-09 1:19 ` [PATCH 1/3 v3] KVM: nVMX: nSVM: 'nested_run' should count guest-entry attempts that make it to guest code Krish Sadhukhan
2021-06-09 1:19 ` [PATCH 2/3 v3] KVM: nVMX: nSVM: Add a new VCPU statistic to show if VCPU is in guest mode Krish Sadhukhan
2021-06-09 1:19 ` Krish Sadhukhan [this message]
2021-06-09 5:08 ` [PATCH 3/3 v3] KVM: x86: Add a new VM statistic to show number of VCPUs created in a given VM kernel test robot
2021-06-09 7:08 ` kernel test robot
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=20210609011935.103017-4-krish.sadhukhan@oracle.com \
--to=krish.sadhukhan@oracle.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
/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;
as well as URLs for NNTP newsgroup(s).