1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 *
4 * Copyright IBM Corp. 2008
5 *
6 * Authors: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
7 */
8
9 #ifndef __POWERPC_KVM_EXITTIMING_H__
10 #define __POWERPC_KVM_EXITTIMING_H__
11
12 #include <linux/kvm_host.h>
13
14 #ifdef CONFIG_KVM_EXIT_TIMING
15 void kvmppc_init_timing_stats(struct kvm_vcpu *vcpu);
16 void kvmppc_update_timing_stats(struct kvm_vcpu *vcpu);
17 int kvmppc_create_vcpu_debugfs_e500(struct kvm_vcpu *vcpu,
18 struct dentry *debugfs_dentry);
19
kvmppc_set_exit_type(struct kvm_vcpu * vcpu,int type)20 static inline void kvmppc_set_exit_type(struct kvm_vcpu *vcpu, int type)
21 {
22 vcpu->arch.last_exit_type = type;
23 }
24
25 #else
26 /* if exit timing is not configured there is no need to build the c file */
kvmppc_init_timing_stats(struct kvm_vcpu * vcpu)27 static inline void kvmppc_init_timing_stats(struct kvm_vcpu *vcpu) {}
kvmppc_update_timing_stats(struct kvm_vcpu * vcpu)28 static inline void kvmppc_update_timing_stats(struct kvm_vcpu *vcpu) {}
kvmppc_create_vcpu_debugfs_e500(struct kvm_vcpu * vcpu,struct dentry * debugfs_dentry)29 static inline int kvmppc_create_vcpu_debugfs_e500(struct kvm_vcpu *vcpu,
30 struct dentry *debugfs_dentry)
31 {
32 return 0;
33 }
kvmppc_set_exit_type(struct kvm_vcpu * vcpu,int type)34 static inline void kvmppc_set_exit_type(struct kvm_vcpu *vcpu, int type) {}
35 #endif /* CONFIG_KVM_EXIT_TIMING */
36
37 /* account the exit in kvm_stats */
kvmppc_account_exit_stat(struct kvm_vcpu * vcpu,int type)38 static inline void kvmppc_account_exit_stat(struct kvm_vcpu *vcpu, int type)
39 {
40 /* type has to be known at build time for optimization */
41
42 /* The BUILD_BUG_ON below breaks in funny ways, commented out
43 * for now ... -BenH
44 BUILD_BUG_ON(!__builtin_constant_p(type));
45 */
46 switch (type) {
47 case EXT_INTR_EXITS:
48 vcpu->stat.ext_intr_exits++;
49 break;
50 case DEC_EXITS:
51 vcpu->stat.dec_exits++;
52 break;
53 case EMULATED_INST_EXITS:
54 vcpu->stat.emulated_inst_exits++;
55 break;
56 case DSI_EXITS:
57 vcpu->stat.dsi_exits++;
58 break;
59 case ISI_EXITS:
60 vcpu->stat.isi_exits++;
61 break;
62 case SYSCALL_EXITS:
63 vcpu->stat.syscall_exits++;
64 break;
65 case DTLB_REAL_MISS_EXITS:
66 vcpu->stat.dtlb_real_miss_exits++;
67 break;
68 case DTLB_VIRT_MISS_EXITS:
69 vcpu->stat.dtlb_virt_miss_exits++;
70 break;
71 case MMIO_EXITS:
72 vcpu->stat.mmio_exits++;
73 break;
74 case ITLB_REAL_MISS_EXITS:
75 vcpu->stat.itlb_real_miss_exits++;
76 break;
77 case ITLB_VIRT_MISS_EXITS:
78 vcpu->stat.itlb_virt_miss_exits++;
79 break;
80 case SIGNAL_EXITS:
81 vcpu->stat.signal_exits++;
82 break;
83 case DBELL_EXITS:
84 vcpu->stat.dbell_exits++;
85 break;
86 case GDBELL_EXITS:
87 vcpu->stat.gdbell_exits++;
88 break;
89 }
90 }
91
92 /* wrapper to set exit time and account for it in kvm_stats */
kvmppc_account_exit(struct kvm_vcpu * vcpu,int type)93 static inline void kvmppc_account_exit(struct kvm_vcpu *vcpu, int type)
94 {
95 kvmppc_set_exit_type(vcpu, type);
96 kvmppc_account_exit_stat(vcpu, type);
97 }
98
99 #endif /* __POWERPC_KVM_EXITTIMING_H__ */
100