KVM: Add provisioning for ulong vm stats and u64 vcpu stats
authorSuraj Jitindar Singh <sjitindarsingh@gmail.com>
Tue, 2 Aug 2016 04:03:22 +0000 (14:03 +1000)
committerPaul Mackerras <paulus@ozlabs.org>
Thu, 8 Sep 2016 02:25:37 +0000 (12:25 +1000)
vms and vcpus have statistics associated with them which can be viewed
within the debugfs. Currently it is assumed within the vcpu_stat_get() and
vm_stat_get() functions that all of these statistics are represented as
u32s, however the next patch adds some u64 vcpu statistics.

Change all vcpu statistics to u64 and modify vcpu_stat_get() accordingly.
Since vcpu statistics are per vcpu, they will only be updated by a single
vcpu at a time so this shouldn't present a problem on 32-bit machines
which can't atomically increment 64-bit numbers. However vm statistics
could potentially be updated by multiple vcpus from that vm at a time.
To avoid the overhead of atomics make all vm statistics ulong such that
they are 64-bit on 64-bit systems where they can be atomically incremented
and are 32-bit on 32-bit systems which may not be able to atomically
increment 64-bit numbers. Modify vm_stat_get() to expect ulongs.

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Reviewed-by: David Matlack <dmatlack@google.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
arch/arm/include/asm/kvm_host.h
arch/arm64/include/asm/kvm_host.h
arch/mips/include/asm/kvm_host.h
arch/powerpc/include/asm/kvm_host.h
arch/s390/include/asm/kvm_host.h
arch/x86/include/asm/kvm_host.h
virt/kvm/kvm_main.c

index de338d93d11b9002bb48a778064f0acf6d6dd79d..6ad21f04a922466aa59a957aa587c7d20409d85f 100644 (file)
@@ -183,15 +183,15 @@ struct kvm_vcpu_arch {
 };
 
 struct kvm_vm_stat {
-       u32 remote_tlb_flush;
+       ulong remote_tlb_flush;
 };
 
 struct kvm_vcpu_stat {
-       u32 halt_successful_poll;
-       u32 halt_attempted_poll;
-       u32 halt_poll_invalid;
-       u32 halt_wakeup;
-       u32 hvc_exit_stat;
+       u64 halt_successful_poll;
+       u64 halt_attempted_poll;
+       u64 halt_poll_invalid;
+       u64 halt_wakeup;
+       u64 hvc_exit_stat;
        u64 wfe_exit_stat;
        u64 wfi_exit_stat;
        u64 mmio_exit_user;
index 3eda975837d0ffea69f748153aa055ca28a7c049..bd94e67667599dc1ce499ab30de2cca91f4e97be 100644 (file)
@@ -290,15 +290,15 @@ struct kvm_vcpu_arch {
 #endif
 
 struct kvm_vm_stat {
-       u32 remote_tlb_flush;
+       ulong remote_tlb_flush;
 };
 
 struct kvm_vcpu_stat {
-       u32 halt_successful_poll;
-       u32 halt_attempted_poll;
-       u32 halt_poll_invalid;
-       u32 halt_wakeup;
-       u32 hvc_exit_stat;
+       u64 halt_successful_poll;
+       u64 halt_attempted_poll;
+       u64 halt_poll_invalid;
+       u64 halt_wakeup;
+       u64 hvc_exit_stat;
        u64 wfe_exit_stat;
        u64 wfi_exit_stat;
        u64 mmio_exit_user;
index b54bcadd8aecab6c294591361cae8c64818247c6..5f488dc8a7d593755e5ef6e30ef7963db4b3fc4c 100644 (file)
 extern atomic_t kvm_mips_instance;
 
 struct kvm_vm_stat {
-       u32 remote_tlb_flush;
+       ulong remote_tlb_flush;
 };
 
 struct kvm_vcpu_stat {
-       u32 wait_exits;
-       u32 cache_exits;
-       u32 signal_exits;
-       u32 int_exits;
-       u32 cop_unusable_exits;
-       u32 tlbmod_exits;
-       u32 tlbmiss_ld_exits;
-       u32 tlbmiss_st_exits;
-       u32 addrerr_st_exits;
-       u32 addrerr_ld_exits;
-       u32 syscall_exits;
-       u32 resvd_inst_exits;
-       u32 break_inst_exits;
-       u32 trap_inst_exits;
-       u32 msa_fpe_exits;
-       u32 fpe_exits;
-       u32 msa_disabled_exits;
-       u32 flush_dcache_exits;
-       u32 halt_successful_poll;
-       u32 halt_attempted_poll;
-       u32 halt_poll_invalid;
-       u32 halt_wakeup;
+       u64 wait_exits;
+       u64 cache_exits;
+       u64 signal_exits;
+       u64 int_exits;
+       u64 cop_unusable_exits;
+       u64 tlbmod_exits;
+       u64 tlbmiss_ld_exits;
+       u64 tlbmiss_st_exits;
+       u64 addrerr_st_exits;
+       u64 addrerr_ld_exits;
+       u64 syscall_exits;
+       u64 resvd_inst_exits;
+       u64 break_inst_exits;
+       u64 trap_inst_exits;
+       u64 msa_fpe_exits;
+       u64 fpe_exits;
+       u64 msa_disabled_exits;
+       u64 flush_dcache_exits;
+       u64 halt_successful_poll;
+       u64 halt_attempted_poll;
+       u64 halt_poll_invalid;
+       u64 halt_wakeup;
 };
 
 struct kvm_arch_memory_slot {
index 6ece4a854a59efe4e7107c6b66fbd314ff7c8aea..5ec1dcf300f615b5a61f7957cefd7d7beb9f4047 100644 (file)
@@ -97,41 +97,41 @@ struct kvmppc_vcpu_book3s;
 struct kvmppc_book3s_shadow_vcpu;
 
 struct kvm_vm_stat {
-       u32 remote_tlb_flush;
+       ulong remote_tlb_flush;
 };
 
 struct kvm_vcpu_stat {
-       u32 sum_exits;
-       u32 mmio_exits;
-       u32 signal_exits;
-       u32 light_exits;
+       u64 sum_exits;
+       u64 mmio_exits;
+       u64 signal_exits;
+       u64 light_exits;
        /* Account for special types of light exits: */
-       u32 itlb_real_miss_exits;
-       u32 itlb_virt_miss_exits;
-       u32 dtlb_real_miss_exits;
-       u32 dtlb_virt_miss_exits;
-       u32 syscall_exits;
-       u32 isi_exits;
-       u32 dsi_exits;
-       u32 emulated_inst_exits;
-       u32 dec_exits;
-       u32 ext_intr_exits;
-       u32 halt_successful_poll;
-       u32 halt_attempted_poll;
-       u32 halt_poll_invalid;
-       u32 halt_wakeup;
-       u32 dbell_exits;
-       u32 gdbell_exits;
-       u32 ld;
-       u32 st;
+       u64 itlb_real_miss_exits;
+       u64 itlb_virt_miss_exits;
+       u64 dtlb_real_miss_exits;
+       u64 dtlb_virt_miss_exits;
+       u64 syscall_exits;
+       u64 isi_exits;
+       u64 dsi_exits;
+       u64 emulated_inst_exits;
+       u64 dec_exits;
+       u64 ext_intr_exits;
+       u64 halt_successful_poll;
+       u64 halt_attempted_poll;
+       u64 halt_poll_invalid;
+       u64 halt_wakeup;
+       u64 dbell_exits;
+       u64 gdbell_exits;
+       u64 ld;
+       u64 st;
 #ifdef CONFIG_PPC_BOOK3S
-       u32 pf_storage;
-       u32 pf_instruc;
-       u32 sp_storage;
-       u32 sp_instruc;
-       u32 queue_intr;
-       u32 ld_slow;
-       u32 st_slow;
+       u64 pf_storage;
+       u64 pf_instruc;
+       u64 sp_storage;
+       u64 sp_instruc;
+       u64 queue_intr;
+       u64 ld_slow;
+       u64 st_slow;
 #endif
 };
 
index 8e5daf7a76cedf2e88456af8caa69075250e9c86..2bbe675c96b96aa99d9603c3009d9ff9047ce0d8 100644 (file)
@@ -245,72 +245,72 @@ struct sie_page {
 } __packed;
 
 struct kvm_vcpu_stat {
-       u32 exit_userspace;
-       u32 exit_null;
-       u32 exit_external_request;
-       u32 exit_external_interrupt;
-       u32 exit_stop_request;
-       u32 exit_validity;
-       u32 exit_instruction;
-       u32 exit_pei;
-       u32 halt_successful_poll;
-       u32 halt_attempted_poll;
-       u32 halt_poll_invalid;
-       u32 halt_wakeup;
-       u32 instruction_lctl;
-       u32 instruction_lctlg;
-       u32 instruction_stctl;
-       u32 instruction_stctg;
-       u32 exit_program_interruption;
-       u32 exit_instr_and_program;
-       u32 exit_operation_exception;
-       u32 deliver_external_call;
-       u32 deliver_emergency_signal;
-       u32 deliver_service_signal;
-       u32 deliver_virtio_interrupt;
-       u32 deliver_stop_signal;
-       u32 deliver_prefix_signal;
-       u32 deliver_restart_signal;
-       u32 deliver_program_int;
-       u32 deliver_io_int;
-       u32 exit_wait_state;
-       u32 instruction_pfmf;
-       u32 instruction_stidp;
-       u32 instruction_spx;
-       u32 instruction_stpx;
-       u32 instruction_stap;
-       u32 instruction_storage_key;
-       u32 instruction_ipte_interlock;
-       u32 instruction_stsch;
-       u32 instruction_chsc;
-       u32 instruction_stsi;
-       u32 instruction_stfl;
-       u32 instruction_tprot;
-       u32 instruction_sie;
-       u32 instruction_essa;
-       u32 instruction_sthyi;
-       u32 instruction_sigp_sense;
-       u32 instruction_sigp_sense_running;
-       u32 instruction_sigp_external_call;
-       u32 instruction_sigp_emergency;
-       u32 instruction_sigp_cond_emergency;
-       u32 instruction_sigp_start;
-       u32 instruction_sigp_stop;
-       u32 instruction_sigp_stop_store_status;
-       u32 instruction_sigp_store_status;
-       u32 instruction_sigp_store_adtl_status;
-       u32 instruction_sigp_arch;
-       u32 instruction_sigp_prefix;
-       u32 instruction_sigp_restart;
-       u32 instruction_sigp_init_cpu_reset;
-       u32 instruction_sigp_cpu_reset;
-       u32 instruction_sigp_unknown;
-       u32 diagnose_10;
-       u32 diagnose_44;
-       u32 diagnose_9c;
-       u32 diagnose_258;
-       u32 diagnose_308;
-       u32 diagnose_500;
+       u64 exit_userspace;
+       u64 exit_null;
+       u64 exit_external_request;
+       u64 exit_external_interrupt;
+       u64 exit_stop_request;
+       u64 exit_validity;
+       u64 exit_instruction;
+       u64 exit_pei;
+       u64 halt_successful_poll;
+       u64 halt_attempted_poll;
+       u64 halt_poll_invalid;
+       u64 halt_wakeup;
+       u64 instruction_lctl;
+       u64 instruction_lctlg;
+       u64 instruction_stctl;
+       u64 instruction_stctg;
+       u64 exit_program_interruption;
+       u64 exit_instr_and_program;
+       u64 exit_operation_exception;
+       u64 deliver_external_call;
+       u64 deliver_emergency_signal;
+       u64 deliver_service_signal;
+       u64 deliver_virtio_interrupt;
+       u64 deliver_stop_signal;
+       u64 deliver_prefix_signal;
+       u64 deliver_restart_signal;
+       u64 deliver_program_int;
+       u64 deliver_io_int;
+       u64 exit_wait_state;
+       u64 instruction_pfmf;
+       u64 instruction_stidp;
+       u64 instruction_spx;
+       u64 instruction_stpx;
+       u64 instruction_stap;
+       u64 instruction_storage_key;
+       u64 instruction_ipte_interlock;
+       u64 instruction_stsch;
+       u64 instruction_chsc;
+       u64 instruction_stsi;
+       u64 instruction_stfl;
+       u64 instruction_tprot;
+       u64 instruction_sie;
+       u64 instruction_essa;
+       u64 instruction_sthyi;
+       u64 instruction_sigp_sense;
+       u64 instruction_sigp_sense_running;
+       u64 instruction_sigp_external_call;
+       u64 instruction_sigp_emergency;
+       u64 instruction_sigp_cond_emergency;
+       u64 instruction_sigp_start;
+       u64 instruction_sigp_stop;
+       u64 instruction_sigp_stop_store_status;
+       u64 instruction_sigp_store_status;
+       u64 instruction_sigp_store_adtl_status;
+       u64 instruction_sigp_arch;
+       u64 instruction_sigp_prefix;
+       u64 instruction_sigp_restart;
+       u64 instruction_sigp_init_cpu_reset;
+       u64 instruction_sigp_cpu_reset;
+       u64 instruction_sigp_unknown;
+       u64 diagnose_10;
+       u64 diagnose_44;
+       u64 diagnose_9c;
+       u64 diagnose_258;
+       u64 diagnose_308;
+       u64 diagnose_500;
 };
 
 #define PGM_OPERATION                  0x01
@@ -577,7 +577,7 @@ struct kvm_vcpu_arch {
 };
 
 struct kvm_vm_stat {
-       u32 remote_tlb_flush;
+       ulong remote_tlb_flush;
 };
 
 struct kvm_arch_memory_slot {
index 33ae3a4d0159893cacdaf54bbcf3bcbf3be127fd..67c8f5268af5d38725ab9e0d0b3b829e24210c08 100644 (file)
@@ -790,45 +790,45 @@ struct kvm_arch {
 };
 
 struct kvm_vm_stat {
-       u32 mmu_shadow_zapped;
-       u32 mmu_pte_write;
-       u32 mmu_pte_updated;
-       u32 mmu_pde_zapped;
-       u32 mmu_flooded;
-       u32 mmu_recycled;
-       u32 mmu_cache_miss;
-       u32 mmu_unsync;
-       u32 remote_tlb_flush;
-       u32 lpages;
+       ulong mmu_shadow_zapped;
+       ulong mmu_pte_write;
+       ulong mmu_pte_updated;
+       ulong mmu_pde_zapped;
+       ulong mmu_flooded;
+       ulong mmu_recycled;
+       ulong mmu_cache_miss;
+       ulong mmu_unsync;
+       ulong remote_tlb_flush;
+       ulong lpages;
 };
 
 struct kvm_vcpu_stat {
-       u32 pf_fixed;
-       u32 pf_guest;
-       u32 tlb_flush;
-       u32 invlpg;
-
-       u32 exits;
-       u32 io_exits;
-       u32 mmio_exits;
-       u32 signal_exits;
-       u32 irq_window_exits;
-       u32 nmi_window_exits;
-       u32 halt_exits;
-       u32 halt_successful_poll;
-       u32 halt_attempted_poll;
-       u32 halt_poll_invalid;
-       u32 halt_wakeup;
-       u32 request_irq_exits;
-       u32 irq_exits;
-       u32 host_state_reload;
-       u32 efer_reload;
-       u32 fpu_reload;
-       u32 insn_emulation;
-       u32 insn_emulation_fail;
-       u32 hypercalls;
-       u32 irq_injections;
-       u32 nmi_injections;
+       u64 pf_fixed;
+       u64 pf_guest;
+       u64 tlb_flush;
+       u64 invlpg;
+
+       u64 exits;
+       u64 io_exits;
+       u64 mmio_exits;
+       u64 signal_exits;
+       u64 irq_window_exits;
+       u64 nmi_window_exits;
+       u64 halt_exits;
+       u64 halt_successful_poll;
+       u64 halt_attempted_poll;
+       u64 halt_poll_invalid;
+       u64 halt_wakeup;
+       u64 request_irq_exits;
+       u64 irq_exits;
+       u64 host_state_reload;
+       u64 efer_reload;
+       u64 fpu_reload;
+       u64 insn_emulation;
+       u64 insn_emulation_fail;
+       u64 hypercalls;
+       u64 irq_injections;
+       u64 nmi_injections;
 };
 
 struct x86_instruction_info;
index 195078225aa5d0c3b3214fd40e0b5f441c5d7518..4171ef3265437ab246ab64c1fb4fb6c0f2cbcc01 100644 (file)
@@ -3619,7 +3619,7 @@ static int vm_stat_get_per_vm(void *data, u64 *val)
 {
        struct kvm_stat_data *stat_data = (struct kvm_stat_data *)data;
 
-       *val = *(u32 *)((void *)stat_data->kvm + stat_data->offset);
+       *val = *(ulong *)((void *)stat_data->kvm + stat_data->offset);
 
        return 0;
 }
@@ -3649,7 +3649,7 @@ static int vcpu_stat_get_per_vm(void *data, u64 *val)
        *val = 0;
 
        kvm_for_each_vcpu(i, vcpu, stat_data->kvm)
-               *val += *(u32 *)((void *)vcpu + stat_data->offset);
+               *val += *(u64 *)((void *)vcpu + stat_data->offset);
 
        return 0;
 }