xref: /linux/drivers/gpu/drm/i915/gvt/trace.h (revision e5c86679d5e864947a52fb31e45a425dea3e7fa9)
1 /*
2  * Copyright © 2011-2016 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Jike Song <jike.song@intel.com>
25  *
26  * Contributors:
27  *    Zhi Wang <zhi.a.wang@intel.com>
28  *
29  */
30 
31 #if !defined(_GVT_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ)
32 #define _GVT_TRACE_H_
33 
34 #include <linux/types.h>
35 #include <linux/stringify.h>
36 #include <linux/tracepoint.h>
37 #include <asm/tsc.h>
38 
39 #undef TRACE_SYSTEM
40 #define TRACE_SYSTEM gvt
41 
42 TRACE_EVENT(spt_alloc,
43 	TP_PROTO(int id, void *spt, int type, unsigned long mfn,
44 		unsigned long gpt_gfn),
45 
46 	TP_ARGS(id, spt, type, mfn, gpt_gfn),
47 
48 	TP_STRUCT__entry(
49 		__field(int, id)
50 		__field(void *, spt)
51 		__field(int, type)
52 		__field(unsigned long, mfn)
53 		__field(unsigned long, gpt_gfn)
54 		),
55 
56 	TP_fast_assign(
57 		__entry->id = id;
58 		__entry->spt = spt;
59 		__entry->type = type;
60 		__entry->mfn = mfn;
61 		__entry->gpt_gfn = gpt_gfn;
62 	),
63 
64 	TP_printk("VM%d [alloc] spt %p type %d mfn 0x%lx gfn 0x%lx\n",
65 		__entry->id,
66 		__entry->spt,
67 		__entry->type,
68 		__entry->mfn,
69 		__entry->gpt_gfn)
70 );
71 
72 TRACE_EVENT(spt_free,
73 	TP_PROTO(int id, void *spt, int type),
74 
75 	TP_ARGS(id, spt, type),
76 
77 	TP_STRUCT__entry(
78 		__field(int, id)
79 		__field(void *, spt)
80 		__field(int, type)
81 		),
82 
83 	TP_fast_assign(
84 		__entry->id = id;
85 		__entry->spt = spt;
86 		__entry->type = type;
87 	),
88 
89 	TP_printk("VM%u [free] spt %p type %d\n",
90 		__entry->id,
91 		__entry->spt,
92 		__entry->type)
93 );
94 
95 #define MAX_BUF_LEN 256
96 
97 TRACE_EVENT(gma_index,
98 	TP_PROTO(const char *prefix, unsigned long gma,
99 		unsigned long index),
100 
101 	TP_ARGS(prefix, gma, index),
102 
103 	TP_STRUCT__entry(
104 		__array(char, buf, MAX_BUF_LEN)
105 	),
106 
107 	TP_fast_assign(
108 		snprintf(__entry->buf, MAX_BUF_LEN,
109 			"%s gma 0x%lx index 0x%lx\n", prefix, gma, index);
110 	),
111 
112 	TP_printk("%s", __entry->buf)
113 );
114 
115 TRACE_EVENT(gma_translate,
116 	TP_PROTO(int id, char *type, int ring_id, int pt_level,
117 		unsigned long gma, unsigned long gpa),
118 
119 	TP_ARGS(id, type, ring_id, pt_level, gma, gpa),
120 
121 	TP_STRUCT__entry(
122 		__array(char, buf, MAX_BUF_LEN)
123 	),
124 
125 	TP_fast_assign(
126 		snprintf(__entry->buf, MAX_BUF_LEN,
127 			"VM%d %s ring %d pt_level %d gma 0x%lx -> gpa 0x%lx\n",
128 				id, type, ring_id, pt_level, gma, gpa);
129 	),
130 
131 	TP_printk("%s", __entry->buf)
132 );
133 
134 TRACE_EVENT(spt_refcount,
135 	TP_PROTO(int id, char *action, void *spt, int before, int after),
136 
137 	TP_ARGS(id, action, spt, before, after),
138 
139 	TP_STRUCT__entry(
140 		__array(char, buf, MAX_BUF_LEN)
141 	),
142 
143 	TP_fast_assign(
144 		snprintf(__entry->buf, MAX_BUF_LEN,
145 			"VM%d [%s] spt %p before %d -> after %d\n",
146 				id, action, spt, before, after);
147 	),
148 
149 	TP_printk("%s", __entry->buf)
150 );
151 
152 TRACE_EVENT(spt_change,
153 	TP_PROTO(int id, char *action, void *spt, unsigned long gfn,
154 		int type),
155 
156 	TP_ARGS(id, action, spt, gfn, type),
157 
158 	TP_STRUCT__entry(
159 		__array(char, buf, MAX_BUF_LEN)
160 	),
161 
162 	TP_fast_assign(
163 		snprintf(__entry->buf, MAX_BUF_LEN,
164 			"VM%d [%s] spt %p gfn 0x%lx type %d\n",
165 				id, action, spt, gfn, type);
166 	),
167 
168 	TP_printk("%s", __entry->buf)
169 );
170 
171 TRACE_EVENT(gpt_change,
172 	TP_PROTO(int id, const char *tag, void *spt, int type, u64 v,
173 		unsigned long index),
174 
175 	TP_ARGS(id, tag, spt, type, v, index),
176 
177 	TP_STRUCT__entry(
178 		__array(char, buf, MAX_BUF_LEN)
179 	),
180 
181 	TP_fast_assign(
182 		snprintf(__entry->buf, MAX_BUF_LEN,
183 		"VM%d [%s] spt %p type %d entry 0x%llx index 0x%lx\n",
184 			id, tag, spt, type, v, index);
185 	),
186 
187 	TP_printk("%s", __entry->buf)
188 );
189 
190 TRACE_EVENT(oos_change,
191 	TP_PROTO(int id, const char *tag, int page_id, void *gpt, int type),
192 
193 	TP_ARGS(id, tag, page_id, gpt, type),
194 
195 	TP_STRUCT__entry(
196 		__array(char, buf, MAX_BUF_LEN)
197 	),
198 
199 	TP_fast_assign(
200 		snprintf(__entry->buf, MAX_BUF_LEN,
201 		"VM%d [oos %s] page id %d gpt %p type %d\n",
202 			id, tag, page_id, gpt, type);
203 	),
204 
205 	TP_printk("%s", __entry->buf)
206 );
207 
208 TRACE_EVENT(oos_sync,
209 	TP_PROTO(int id, int page_id, void *gpt, int type, u64 v,
210 		unsigned long index),
211 
212 	TP_ARGS(id, page_id, gpt, type, v, index),
213 
214 	TP_STRUCT__entry(
215 		__array(char, buf, MAX_BUF_LEN)
216 	),
217 
218 	TP_fast_assign(
219 	snprintf(__entry->buf, MAX_BUF_LEN,
220 	"VM%d [oos sync] page id %d gpt %p type %d entry 0x%llx index 0x%lx\n",
221 				id, page_id, gpt, type, v, index);
222 	),
223 
224 	TP_printk("%s", __entry->buf)
225 );
226 
227 #define MAX_CMD_STR_LEN	256
228 TRACE_EVENT(gvt_command,
229 		TP_PROTO(u8 vm_id, u8 ring_id, u32 ip_gma, u32 *cmd_va, u32 cmd_len, bool ring_buffer_cmd, cycles_t cost_pre_cmd_handler, cycles_t cost_cmd_handler),
230 
231 		TP_ARGS(vm_id, ring_id, ip_gma, cmd_va, cmd_len, ring_buffer_cmd, cost_pre_cmd_handler, cost_cmd_handler),
232 
233 		TP_STRUCT__entry(
234 			__field(u8, vm_id)
235 			__field(u8, ring_id)
236 			__field(int, i)
237 			__array(char, tmp_buf, MAX_CMD_STR_LEN)
238 			__array(char, cmd_str, MAX_CMD_STR_LEN)
239 			),
240 
241 		TP_fast_assign(
242 			__entry->vm_id = vm_id;
243 			__entry->ring_id = ring_id;
244 			__entry->cmd_str[0] = '\0';
245 			snprintf(__entry->tmp_buf, MAX_CMD_STR_LEN, "VM(%d) Ring(%d): %s ip(%08x) pre handler cost (%llu), handler cost (%llu) ", vm_id, ring_id, ring_buffer_cmd ? "RB":"BB", ip_gma, cost_pre_cmd_handler, cost_cmd_handler);
246 			strcat(__entry->cmd_str, __entry->tmp_buf);
247 			entry->i = 0;
248 			while (cmd_len > 0) {
249 				if (cmd_len >= 8) {
250 					snprintf(__entry->tmp_buf, MAX_CMD_STR_LEN, "%08x %08x %08x %08x %08x %08x %08x %08x ",
251 						cmd_va[__entry->i], cmd_va[__entry->i+1], cmd_va[__entry->i+2], cmd_va[__entry->i+3],
252 						cmd_va[__entry->i+4], cmd_va[__entry->i+5], cmd_va[__entry->i+6], cmd_va[__entry->i+7]);
253 					__entry->i += 8;
254 					cmd_len -= 8;
255 					strcat(__entry->cmd_str, __entry->tmp_buf);
256 				} else if (cmd_len >= 4) {
257 					snprintf(__entry->tmp_buf, MAX_CMD_STR_LEN, "%08x %08x %08x %08x ",
258 						cmd_va[__entry->i], cmd_va[__entry->i+1], cmd_va[__entry->i+2], cmd_va[__entry->i+3]);
259 					__entry->i += 4;
260 					cmd_len -= 4;
261 					strcat(__entry->cmd_str, __entry->tmp_buf);
262 				} else if (cmd_len >= 2) {
263 					snprintf(__entry->tmp_buf, MAX_CMD_STR_LEN, "%08x %08x ", cmd_va[__entry->i], cmd_va[__entry->i+1]);
264 					__entry->i += 2;
265 					cmd_len -= 2;
266 					strcat(__entry->cmd_str, __entry->tmp_buf);
267 				} else if (cmd_len == 1) {
268 					snprintf(__entry->tmp_buf, MAX_CMD_STR_LEN, "%08x ", cmd_va[__entry->i]);
269 					__entry->i += 1;
270 					cmd_len -= 1;
271 					strcat(__entry->cmd_str, __entry->tmp_buf);
272 				}
273 			}
274 			strcat(__entry->cmd_str, "\n");
275 		),
276 
277 		TP_printk("%s", __entry->cmd_str)
278 );
279 #endif /* _GVT_TRACE_H_ */
280 
281 /* This part must be out of protection */
282 #undef TRACE_INCLUDE_PATH
283 #define TRACE_INCLUDE_PATH .
284 #undef TRACE_INCLUDE_FILE
285 #define TRACE_INCLUDE_FILE trace
286 #include <trace/define_trace.h>
287