xref: /linux/arch/loongarch/kvm/trace.h (revision 2d7f3d1a5866705be2393150e1ffdf67030ab88d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020-2023 Loongson Technology Corporation Limited
4  */
5 
6 #if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
7 #define _TRACE_KVM_H
8 
9 #include <linux/tracepoint.h>
10 #include <asm/kvm_csr.h>
11 
12 #undef	TRACE_SYSTEM
13 #define TRACE_SYSTEM	kvm
14 
15 /*
16  * Tracepoints for VM enters
17  */
18 DECLARE_EVENT_CLASS(kvm_transition,
19 	TP_PROTO(struct kvm_vcpu *vcpu),
20 	TP_ARGS(vcpu),
21 	TP_STRUCT__entry(
22 		__field(unsigned long, pc)
23 	),
24 
25 	TP_fast_assign(
26 		__entry->pc = vcpu->arch.pc;
27 	),
28 
29 	TP_printk("PC: 0x%08lx", __entry->pc)
30 );
31 
32 DEFINE_EVENT(kvm_transition, kvm_enter,
33 	     TP_PROTO(struct kvm_vcpu *vcpu),
34 	     TP_ARGS(vcpu));
35 
36 DEFINE_EVENT(kvm_transition, kvm_reenter,
37 	     TP_PROTO(struct kvm_vcpu *vcpu),
38 	     TP_ARGS(vcpu));
39 
40 DEFINE_EVENT(kvm_transition, kvm_out,
41 	     TP_PROTO(struct kvm_vcpu *vcpu),
42 	     TP_ARGS(vcpu));
43 
44 /* Further exit reasons */
45 #define KVM_TRACE_EXIT_IDLE		64
46 #define KVM_TRACE_EXIT_CACHE		65
47 
48 /* Tracepoints for VM exits */
49 #define kvm_trace_symbol_exit_types			\
50 	{ KVM_TRACE_EXIT_IDLE,		"IDLE" },	\
51 	{ KVM_TRACE_EXIT_CACHE,		"CACHE" }
52 
53 DECLARE_EVENT_CLASS(kvm_exit,
54 	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int reason),
55 	    TP_ARGS(vcpu, reason),
56 	    TP_STRUCT__entry(
57 			__field(unsigned long, pc)
58 			__field(unsigned int, reason)
59 	    ),
60 
61 	    TP_fast_assign(
62 			__entry->pc = vcpu->arch.pc;
63 			__entry->reason = reason;
64 	    ),
65 
66 	    TP_printk("[%s]PC: 0x%08lx",
67 		      __print_symbolic(__entry->reason,
68 				       kvm_trace_symbol_exit_types),
69 		      __entry->pc)
70 );
71 
72 DEFINE_EVENT(kvm_exit, kvm_exit_idle,
73 	     TP_PROTO(struct kvm_vcpu *vcpu, unsigned int reason),
74 	     TP_ARGS(vcpu, reason));
75 
76 DEFINE_EVENT(kvm_exit, kvm_exit_cache,
77 	     TP_PROTO(struct kvm_vcpu *vcpu, unsigned int reason),
78 	     TP_ARGS(vcpu, reason));
79 
80 DEFINE_EVENT(kvm_exit, kvm_exit,
81 	     TP_PROTO(struct kvm_vcpu *vcpu, unsigned int reason),
82 	     TP_ARGS(vcpu, reason));
83 
84 TRACE_EVENT(kvm_exit_gspr,
85 	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int inst_word),
86 	    TP_ARGS(vcpu, inst_word),
87 	    TP_STRUCT__entry(
88 			__field(unsigned int, inst_word)
89 	    ),
90 
91 	    TP_fast_assign(
92 			__entry->inst_word = inst_word;
93 	    ),
94 
95 	    TP_printk("Inst word: 0x%08x", __entry->inst_word)
96 );
97 
98 #define KVM_TRACE_AUX_SAVE		0
99 #define KVM_TRACE_AUX_RESTORE		1
100 #define KVM_TRACE_AUX_ENABLE		2
101 #define KVM_TRACE_AUX_DISABLE		3
102 #define KVM_TRACE_AUX_DISCARD		4
103 
104 #define KVM_TRACE_AUX_FPU		1
105 #define KVM_TRACE_AUX_LSX		2
106 #define KVM_TRACE_AUX_LASX		3
107 
108 #define kvm_trace_symbol_aux_op				\
109 	{ KVM_TRACE_AUX_SAVE,		"save" },	\
110 	{ KVM_TRACE_AUX_RESTORE,	"restore" },	\
111 	{ KVM_TRACE_AUX_ENABLE,		"enable" },	\
112 	{ KVM_TRACE_AUX_DISABLE,	"disable" },	\
113 	{ KVM_TRACE_AUX_DISCARD,	"discard" }
114 
115 #define kvm_trace_symbol_aux_state			\
116 	{ KVM_TRACE_AUX_FPU,     "FPU" },		\
117 	{ KVM_TRACE_AUX_LSX,     "LSX" },		\
118 	{ KVM_TRACE_AUX_LASX,    "LASX" }
119 
120 TRACE_EVENT(kvm_aux,
121 	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int op,
122 		     unsigned int state),
123 	    TP_ARGS(vcpu, op, state),
124 	    TP_STRUCT__entry(
125 			__field(unsigned long, pc)
126 			__field(u8, op)
127 			__field(u8, state)
128 	    ),
129 
130 	    TP_fast_assign(
131 			__entry->pc = vcpu->arch.pc;
132 			__entry->op = op;
133 			__entry->state = state;
134 	    ),
135 
136 	    TP_printk("%s %s PC: 0x%08lx",
137 		      __print_symbolic(__entry->op,
138 				       kvm_trace_symbol_aux_op),
139 		      __print_symbolic(__entry->state,
140 				       kvm_trace_symbol_aux_state),
141 		      __entry->pc)
142 );
143 
144 TRACE_EVENT(kvm_vpid_change,
145 	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned long vpid),
146 	    TP_ARGS(vcpu, vpid),
147 	    TP_STRUCT__entry(
148 			__field(unsigned long, vpid)
149 	    ),
150 
151 	    TP_fast_assign(
152 			__entry->vpid = vpid;
153 	    ),
154 
155 	    TP_printk("VPID: 0x%08lx", __entry->vpid)
156 );
157 
158 #endif /* _TRACE_KVM_H */
159 
160 #undef TRACE_INCLUDE_PATH
161 #define TRACE_INCLUDE_PATH ../../arch/loongarch/kvm
162 #undef TRACE_INCLUDE_FILE
163 #define TRACE_INCLUDE_FILE trace
164 
165 /* This part must be outside protection */
166 #include <trace/define_trace.h>
167