summaryrefslogtreecommitdiff
path: root/drivers/kvm/kvm_main.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2007-11-18 16:24:12 +0200
committerAvi Kivity <avi@qumranet.com>2008-01-30 17:53:04 +0200
commitba1389b7a04de07e6231693b7ebb34f5b5d1a3e6 (patch)
tree536139f6e1d3a918b13a9c44f2144c52366a55bb /drivers/kvm/kvm_main.c
parentf2b5756bb3fbdca912c4890e444c18650389d8ae (diff)
downloadlwn-ba1389b7a04de07e6231693b7ebb34f5b5d1a3e6.tar.gz
lwn-ba1389b7a04de07e6231693b7ebb34f5b5d1a3e6.zip
KVM: Extend stats support for VM stats
This is in addition to the current virtual cpu statistics. Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r--drivers/kvm/kvm_main.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index bde3cf741892..b0b6ff2a8cbe 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1281,7 +1281,22 @@ static struct notifier_block kvm_cpu_notifier = {
.priority = 20, /* must be > scheduler priority */
};
-static u64 stat_get(void *_offset)
+static u64 vm_stat_get(void *_offset)
+{
+ unsigned offset = (long)_offset;
+ u64 total = 0;
+ struct kvm *kvm;
+
+ spin_lock(&kvm_lock);
+ list_for_each_entry(kvm, &vm_list, vm_list)
+ total += *(u32 *)((void *)kvm + offset);
+ spin_unlock(&kvm_lock);
+ return total;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(vm_stat_fops, vm_stat_get, NULL, "%llu\n");
+
+static u64 vcpu_stat_get(void *_offset)
{
unsigned offset = (long)_offset;
u64 total = 0;
@@ -1300,7 +1315,12 @@ static u64 stat_get(void *_offset)
return total;
}
-DEFINE_SIMPLE_ATTRIBUTE(stat_fops, stat_get, NULL, "%llu\n");
+DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_fops, vcpu_stat_get, NULL, "%llu\n");
+
+static struct file_operations *stat_fops[] = {
+ [KVM_STAT_VCPU] = &vcpu_stat_fops,
+ [KVM_STAT_VM] = &vm_stat_fops,
+};
static void kvm_init_debug(void)
{
@@ -1310,7 +1330,7 @@ static void kvm_init_debug(void)
for (p = debugfs_entries; p->name; ++p)
p->dentry = debugfs_create_file(p->name, 0444, debugfs_dir,
(void *)(long)p->offset,
- &stat_fops);
+ stat_fops[p->kind]);
}
static void kvm_exit_debug(void)