@@ -421,6 +421,9 @@ struct kvm_arch{
struct kvm_xen_hvm_config xen_hvm_config;
};
+#define KVM_ARCH_STAT \
+ u32 tsc_resync;
+
struct kvm_vm_stat {
u32 mmu_shadow_zapped;
u32 mmu_pte_write;
@@ -450,6 +453,7 @@ struct kvm_vcpu_stat {
u32 halt_wakeup;
u32 request_irq_exits;
u32 irq_exits;
+ u32 rdtsc_exits;
u32 host_state_reload;
u32 efer_reload;
u32 fpu_reload;
@@ -2036,6 +2036,7 @@ static int rdtsc_interception(struct vcpu_svm *svm)
kvm_register_write(&svm->vcpu, VCPU_REGS_RAX, tsc & 0xffffffff);
tsc >>= 32;
kvm_register_write(&svm->vcpu, VCPU_REGS_RDX, tsc & 0xffffffff);
+ ++svm->vcpu.stat.rdtsc_exits;
skip_emulated_instruction(&svm->vcpu);
return 1;
}
@@ -129,6 +129,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
{ "hypercalls", VCPU_STAT(hypercalls) },
{ "request_irq", VCPU_STAT(request_irq_exits) },
{ "irq_exits", VCPU_STAT(irq_exits) },
+ { "rdtsc_exits", VCPU_STAT(rdtsc_exits) },
{ "host_state_reload", VCPU_STAT(host_state_reload) },
{ "efer_reload", VCPU_STAT(efer_reload) },
{ "fpu_reload", VCPU_STAT(fpu_reload) },
@@ -146,6 +147,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
{ "mmu_unsync", VM_STAT(mmu_unsync) },
{ "remote_tlb_flush", VM_STAT(remote_tlb_flush) },
{ "largepages", VM_STAT(lpages) },
+ { "tsc_resync", KVM_STAT(tsc_resync) },
{ NULL }
};
@@ -977,6 +979,7 @@ static void kvm_do_sync_tsc(int cpu)
smp_call_function_single(tsc_base_cpu, kvm_sync_tsc,
(void *)&cpu, 1);
}
+ ++kvm_stats.tsc_resync;
out_unlock:
spin_unlock(&kvm_tsc_lock);
@@ -503,6 +503,7 @@ static inline void kvm_migrate_timers(struct kvm_vcpu *vcpu)
enum kvm_stat_kind {
KVM_STAT_VM,
KVM_STAT_VCPU,
+ KVM_STAT_GLOBAL
};
struct kvm_stats_debugfs_item {
@@ -514,6 +515,17 @@ struct kvm_stats_debugfs_item {
extern struct kvm_stats_debugfs_item debugfs_entries[];
extern struct dentry *kvm_debugfs_dir;
+#ifndef KVM_ARCH_STAT
+#define KVM_ARCH_STAT
+#endif
+
+struct kvm_stat {
+ KVM_ARCH_STAT
+};
+
+extern struct kvm_stat kvm_stats;
+#define KVM_STAT(x) offsetof(struct kvm_stat, x), KVM_STAT_GLOBAL
+
#ifdef KVM_ARCH_WANT_MMU_NOTIFIER
static inline int mmu_notifier_retry(struct kvm_vcpu *vcpu, unsigned long mmu_seq)
{
@@ -1971,9 +1971,23 @@ static int vcpu_stat_get(void *_offset, u64 *val)
DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_fops, vcpu_stat_get, NULL, "%llu\n");
+struct kvm_stat kvm_stats;
+EXPORT_SYMBOL_GPL(kvm_stats);
+
+static int kvm_stat_get(void *_offset, u64 *val)
+{
+ unsigned offset = (long)_offset;
+
+ *val = *(u32 *)((void *)&kvm_stats + offset);
+ return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(kvm_stat_fops, kvm_stat_get, NULL, "%llu\n");
+
static const struct file_operations *stat_fops[] = {
- [KVM_STAT_VCPU] = &vcpu_stat_fops,
- [KVM_STAT_VM] = &vm_stat_fops,
+ [KVM_STAT_VCPU] = &vcpu_stat_fops,
+ [KVM_STAT_VM] = &vm_stat_fops,
+ [KVM_STAT_GLOBAL] = &kvm_stat_fops,
};
static void kvm_init_debug(void)