xref: /openbmc/linux/arch/powerpc/kvm/timing.h (revision 3381df09)
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 void kvmppc_create_vcpu_debugfs(struct kvm_vcpu *vcpu, unsigned int id);
18 void kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu);
19 
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 */
27 static inline void kvmppc_init_timing_stats(struct kvm_vcpu *vcpu) {}
28 static inline void kvmppc_update_timing_stats(struct kvm_vcpu *vcpu) {}
29 static inline void kvmppc_create_vcpu_debugfs(struct kvm_vcpu *vcpu,
30 						unsigned int id) {}
31 static inline void kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu) {}
32 static inline void kvmppc_set_exit_type(struct kvm_vcpu *vcpu, int type) {}
33 #endif /* CONFIG_KVM_EXIT_TIMING */
34 
35 /* account the exit in kvm_stats */
36 static inline void kvmppc_account_exit_stat(struct kvm_vcpu *vcpu, int type)
37 {
38 	/* type has to be known at build time for optimization */
39 
40 	/* The BUILD_BUG_ON below breaks in funny ways, commented out
41 	 * for now ... -BenH
42 	BUILD_BUG_ON(!__builtin_constant_p(type));
43 	*/
44 	switch (type) {
45 	case EXT_INTR_EXITS:
46 		vcpu->stat.ext_intr_exits++;
47 		break;
48 	case DEC_EXITS:
49 		vcpu->stat.dec_exits++;
50 		break;
51 	case EMULATED_INST_EXITS:
52 		vcpu->stat.emulated_inst_exits++;
53 		break;
54 	case DSI_EXITS:
55 		vcpu->stat.dsi_exits++;
56 		break;
57 	case ISI_EXITS:
58 		vcpu->stat.isi_exits++;
59 		break;
60 	case SYSCALL_EXITS:
61 		vcpu->stat.syscall_exits++;
62 		break;
63 	case DTLB_REAL_MISS_EXITS:
64 		vcpu->stat.dtlb_real_miss_exits++;
65 		break;
66 	case DTLB_VIRT_MISS_EXITS:
67 		vcpu->stat.dtlb_virt_miss_exits++;
68 		break;
69 	case MMIO_EXITS:
70 		vcpu->stat.mmio_exits++;
71 		break;
72 	case ITLB_REAL_MISS_EXITS:
73 		vcpu->stat.itlb_real_miss_exits++;
74 		break;
75 	case ITLB_VIRT_MISS_EXITS:
76 		vcpu->stat.itlb_virt_miss_exits++;
77 		break;
78 	case SIGNAL_EXITS:
79 		vcpu->stat.signal_exits++;
80 		break;
81 	case DBELL_EXITS:
82 		vcpu->stat.dbell_exits++;
83 		break;
84 	case GDBELL_EXITS:
85 		vcpu->stat.gdbell_exits++;
86 		break;
87 	}
88 }
89 
90 /* wrapper to set exit time and account for it in kvm_stats */
91 static inline void kvmppc_account_exit(struct kvm_vcpu *vcpu, int type)
92 {
93 	kvmppc_set_exit_type(vcpu, type);
94 	kvmppc_account_exit_stat(vcpu, type);
95 }
96 
97 #endif /* __POWERPC_KVM_EXITTIMING_H__ */
98