xref: /linux/kernel/trace/trace_entries.h (revision 69c5079b49fa120c1a108b6e28b3a6a8e4ae2db5)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * This file defines the trace event structures that go into the ring
4  * buffer directly. They are created via macros so that changes for them
5  * appear in the format file. Using macros will automate this process.
6  *
7  * The macro used to create a ftrace data structure is:
8  *
9  * FTRACE_ENTRY( name, struct_name, id, structure, print )
10  *
11  * @name: the name used the event name, as well as the name of
12  *   the directory that holds the format file.
13  *
14  * @struct_name: the name of the structure that is created.
15  *
16  * @id: The event identifier that is used to detect what event
17  *    this is from the ring buffer.
18  *
19  * @structure: the structure layout
20  *
21  *  - __field(	type,	item	)
22  *	  This is equivalent to declaring
23  *		type	item;
24  *	  in the structure.
25  *  - __array(	type,	item,	size	)
26  *	  This is equivalent to declaring
27  *		type	item[size];
28  *	  in the structure.
29  *
30  *   * for structures within structures, the format of the internal
31  *	structure is laid out. This allows the internal structure
32  *	to be deciphered for the format file. Although these macros
33  *	may become out of sync with the internal structure, they
34  *	will create a compile error if it happens. Since the
35  *	internal structures are just tracing helpers, this is not
36  *	an issue.
37  *
38  *	When an internal structure is used, it should use:
39  *
40  *	__field_struct(	type,	item	)
41  *
42  *	instead of __field. This will prevent it from being shown in
43  *	the output file. The fields in the structure should use.
44  *
45  *	__field_desc(	type,	container,	item		)
46  *	__array_desc(	type,	container,	item,	len	)
47  *
48  *	type, item and len are the same as __field and __array, but
49  *	container is added. This is the name of the item in
50  *	__field_struct that this is describing.
51  *
52  *
53  * @print: the print format shown to users in the format file.
54  */
55 
56 /*
57  * Function trace entry - function address and parent function address:
58  */
59 FTRACE_ENTRY_REG(function, ftrace_entry,
60 
61 	TRACE_FN,
62 
63 	F_STRUCT(
64 		__field_fn(	unsigned long,		ip		)
65 		__field_fn(	unsigned long,		parent_ip	)
66 		__dynamic_array( unsigned long,		args		)
67 	),
68 
69 	F_printk(" %ps <-- %ps",
70 		 (void *)__entry->ip, (void *)__entry->parent_ip),
71 
72 	perf_ftrace_event_register
73 );
74 
75 /* Function call entry */
76 FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry,
77 
78 	TRACE_GRAPH_ENT,
79 
80 	F_STRUCT(
81 		__field_struct(	struct ftrace_graph_ent,	graph_ent	)
82 		__field_packed(	unsigned long,	graph_ent,	func		)
83 		__field_packed(	unsigned long,	graph_ent,	depth		)
84 		__dynamic_array(unsigned long,	args				)
85 	),
86 
87 	F_printk("--> %ps (%lu)", (void *)__entry->func, __entry->depth)
88 );
89 
90 #ifdef CONFIG_FUNCTION_GRAPH_RETADDR
91 
92 /* Function call entry with a return address */
93 FTRACE_ENTRY_PACKED(fgraph_retaddr_entry, fgraph_retaddr_ent_entry,
94 
95 	TRACE_GRAPH_RETADDR_ENT,
96 
97 	F_STRUCT(
98 		__field_struct(	struct fgraph_retaddr_ent,	graph_rent	)
99 		__field_packed(	unsigned long,	graph_rent.ent,	func		)
100 		__field_packed(	unsigned long,	graph_rent.ent,	depth		)
101 		__field_packed(	unsigned long,	graph_rent,	retaddr		)
102 		__dynamic_array(unsigned long,	args				)
103 	),
104 
105 	F_printk("--> %ps (%lu) <- %ps", (void *)__entry->func, __entry->depth,
106 		(void *)__entry->retaddr)
107 );
108 
109 #else
110 
111 #ifndef fgraph_retaddr_ent_entry
112 #define fgraph_retaddr_ent_entry ftrace_graph_ent_entry
113 #endif
114 
115 #endif
116 
117 #ifdef CONFIG_FUNCTION_GRAPH_RETVAL
118 
119 /* Function return entry */
120 FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry,
121 
122 	TRACE_GRAPH_RET,
123 
124 	F_STRUCT(
125 		__field_struct(	struct ftrace_graph_ret,	ret	)
126 		__field_packed(	unsigned long,	ret,		func	)
127 		__field_packed(	unsigned long,	ret,		retval	)
128 		__field_packed(	unsigned int,	ret,		depth	)
129 		__field_packed(	unsigned int,	ret,		overrun	)
130 		__field(unsigned long long,	calltime		)
131 		__field(unsigned long long,	rettime			)
132 	),
133 
134 	F_printk("<-- %ps (%u) (start: %llx  end: %llx) over: %u retval: %lx",
135 		 (void *)__entry->func, __entry->depth,
136 		 __entry->calltime, __entry->rettime,
137 		 __entry->depth, __entry->retval)
138 );
139 
140 #else
141 
142 /* Function return entry */
143 FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry,
144 
145 	TRACE_GRAPH_RET,
146 
147 	F_STRUCT(
148 		__field_struct(	struct ftrace_graph_ret,	ret	)
149 		__field_packed(	unsigned long,	ret,		func	)
150 		__field_packed(	unsigned int,	ret,		depth	)
151 		__field_packed(	unsigned int,	ret,		overrun	)
152 		__field(unsigned long long,	calltime		)
153 		__field(unsigned long long,	rettime			)
154 	),
155 
156 	F_printk("<-- %ps (%u) (start: %llx  end: %llx) over: %u",
157 		 (void *)__entry->func, __entry->depth,
158 		 __entry->calltime, __entry->rettime,
159 		 __entry->depth)
160 );
161 
162 #endif
163 
164 /*
165  * Context switch trace entry - which task (and prio) we switched from/to:
166  *
167  * This is used for both wakeup and context switches. We only want
168  * to create one structure, but we need two outputs for it.
169  */
170 #define FTRACE_CTX_FIELDS					\
171 	__field(	unsigned int,	prev_pid	)	\
172 	__field(	unsigned int,	next_pid	)	\
173 	__field(	unsigned int,	next_cpu	)       \
174 	__field(	unsigned char,	prev_prio	)	\
175 	__field(	unsigned char,	prev_state	)	\
176 	__field(	unsigned char,	next_prio	)	\
177 	__field(	unsigned char,	next_state	)
178 
179 FTRACE_ENTRY(context_switch, ctx_switch_entry,
180 
181 	TRACE_CTX,
182 
183 	F_STRUCT(
184 		FTRACE_CTX_FIELDS
185 	),
186 
187 	F_printk("%u:%u:%u  ==> %u:%u:%u [%03u]",
188 		 __entry->prev_pid, __entry->prev_prio, __entry->prev_state,
189 		 __entry->next_pid, __entry->next_prio, __entry->next_state,
190 		 __entry->next_cpu)
191 );
192 
193 /*
194  * FTRACE_ENTRY_DUP only creates the format file, it will not
195  *  create another structure.
196  */
197 FTRACE_ENTRY_DUP(wakeup, ctx_switch_entry,
198 
199 	TRACE_WAKE,
200 
201 	F_STRUCT(
202 		FTRACE_CTX_FIELDS
203 	),
204 
205 	F_printk("%u:%u:%u  ==+ %u:%u:%u [%03u]",
206 		 __entry->prev_pid, __entry->prev_prio, __entry->prev_state,
207 		 __entry->next_pid, __entry->next_prio, __entry->next_state,
208 		 __entry->next_cpu)
209 );
210 
211 /*
212  * Stack-trace entry:
213  */
214 
215 #define FTRACE_STACK_ENTRIES	8
216 
217 FTRACE_ENTRY(kernel_stack, stack_entry,
218 
219 	TRACE_STACK,
220 
221 	F_STRUCT(
222 		__field(	int,		size	)
223 		__stack_array(	unsigned long,	caller,	FTRACE_STACK_ENTRIES, size)
224 	),
225 
226 	F_printk("\t=> %ps\n\t=> %ps\n\t=> %ps\n"
227 		 "\t=> %ps\n\t=> %ps\n\t=> %ps\n"
228 		 "\t=> %ps\n\t=> %ps\n",
229 		 (void *)__entry->caller[0], (void *)__entry->caller[1],
230 		 (void *)__entry->caller[2], (void *)__entry->caller[3],
231 		 (void *)__entry->caller[4], (void *)__entry->caller[5],
232 		 (void *)__entry->caller[6], (void *)__entry->caller[7])
233 );
234 
235 FTRACE_ENTRY(user_stack, userstack_entry,
236 
237 	TRACE_USER_STACK,
238 
239 	F_STRUCT(
240 		__field(	unsigned int,	tgid	)
241 		__array(	unsigned long,	caller, FTRACE_STACK_ENTRIES	)
242 	),
243 
244 	F_printk("\t=> %ps\n\t=> %ps\n\t=> %ps\n"
245 		 "\t=> %ps\n\t=> %ps\n\t=> %ps\n"
246 		 "\t=> %ps\n\t=> %ps\n",
247 		 (void *)__entry->caller[0], (void *)__entry->caller[1],
248 		 (void *)__entry->caller[2], (void *)__entry->caller[3],
249 		 (void *)__entry->caller[4], (void *)__entry->caller[5],
250 		 (void *)__entry->caller[6], (void *)__entry->caller[7])
251 );
252 
253 /*
254  * trace_printk entry:
255  */
256 FTRACE_ENTRY(bprint, bprint_entry,
257 
258 	TRACE_BPRINT,
259 
260 	F_STRUCT(
261 		__field(	unsigned long,	ip	)
262 		__field(	const char *,	fmt	)
263 		__dynamic_array(	u32,	buf	)
264 	),
265 
266 	F_printk("%ps: %s",
267 		 (void *)__entry->ip, __entry->fmt)
268 );
269 
270 FTRACE_ENTRY_REG(print, print_entry,
271 
272 	TRACE_PRINT,
273 
274 	F_STRUCT(
275 		__field(	unsigned long,	ip	)
276 		__dynamic_array(	char,	buf	)
277 	),
278 
279 	F_printk("%ps: %s",
280 		 (void *)__entry->ip, __entry->buf),
281 
282 	ftrace_event_register
283 );
284 
285 FTRACE_ENTRY(raw_data, raw_data_entry,
286 
287 	TRACE_RAW_DATA,
288 
289 	F_STRUCT(
290 		__field(	unsigned int,	id	)
291 		__dynamic_array(	char,	buf	)
292 	),
293 
294 	F_printk("id:%04x %08x",
295 		 __entry->id, (int)__entry->buf[0])
296 );
297 
298 FTRACE_ENTRY(bputs, bputs_entry,
299 
300 	TRACE_BPUTS,
301 
302 	F_STRUCT(
303 		__field(	unsigned long,	ip	)
304 		__field(	const char *,	str	)
305 	),
306 
307 	F_printk("%ps: %s",
308 		 (void *)__entry->ip, __entry->str)
309 );
310 
311 FTRACE_ENTRY(mmiotrace_rw, trace_mmiotrace_rw,
312 
313 	TRACE_MMIO_RW,
314 
315 	F_STRUCT(
316 		__field_struct(	struct mmiotrace_rw,	rw	)
317 		__field_desc(	resource_size_t, rw,	phys	)
318 		__field_desc(	unsigned long,	rw,	value	)
319 		__field_desc(	unsigned long,	rw,	pc	)
320 		__field_desc(	int,		rw,	map_id	)
321 		__field_desc(	unsigned char,	rw,	opcode	)
322 		__field_desc(	unsigned char,	rw,	width	)
323 	),
324 
325 	F_printk("%lx %lx %lx %d %x %x",
326 		 (unsigned long)__entry->phys, __entry->value, __entry->pc,
327 		 __entry->map_id, __entry->opcode, __entry->width)
328 );
329 
330 FTRACE_ENTRY(mmiotrace_map, trace_mmiotrace_map,
331 
332 	TRACE_MMIO_MAP,
333 
334 	F_STRUCT(
335 		__field_struct(	struct mmiotrace_map,	map	)
336 		__field_desc(	resource_size_t, map,	phys	)
337 		__field_desc(	unsigned long,	map,	virt	)
338 		__field_desc(	unsigned long,	map,	len	)
339 		__field_desc(	int,		map,	map_id	)
340 		__field_desc(	unsigned char,	map,	opcode	)
341 	),
342 
343 	F_printk("%lx %lx %lx %d %x",
344 		 (unsigned long)__entry->phys, __entry->virt, __entry->len,
345 		 __entry->map_id, __entry->opcode)
346 );
347 
348 
349 #define TRACE_FUNC_SIZE 30
350 #define TRACE_FILE_SIZE 20
351 
352 FTRACE_ENTRY(branch, trace_branch,
353 
354 	TRACE_BRANCH,
355 
356 	F_STRUCT(
357 		__field(	unsigned int,	line				)
358 		__array(	char,		func,	TRACE_FUNC_SIZE+1	)
359 		__array(	char,		file,	TRACE_FILE_SIZE+1	)
360 		__field(	char,		correct				)
361 		__field(	char,		constant			)
362 	),
363 
364 	F_printk("%u:%s:%s (%u)%s",
365 		 __entry->line,
366 		 __entry->func, __entry->file, __entry->correct,
367 		 __entry->constant ? " CONSTANT" : "")
368 );
369 
370 
371 FTRACE_ENTRY(hwlat, hwlat_entry,
372 
373 	TRACE_HWLAT,
374 
375 	F_STRUCT(
376 		__field(	u64,			duration	)
377 		__field(	u64,			outer_duration	)
378 		__field(	u64,			nmi_total_ts	)
379 		__field_struct( struct timespec64,	timestamp	)
380 		__field_desc(	s64,	timestamp,	tv_sec		)
381 		__field_desc(	long,	timestamp,	tv_nsec		)
382 		__field(	unsigned int,		nmi_count	)
383 		__field(	unsigned int,		seqnum		)
384 		__field(	unsigned int,		count		)
385 	),
386 
387 	F_printk("cnt:%u\tts:%010llu.%010lu\tinner:%llu\touter:%llu\tcount:%d\tnmi-ts:%llu\tnmi-count:%u\n",
388 		 __entry->seqnum,
389 		 __entry->tv_sec,
390 		 __entry->tv_nsec,
391 		 __entry->duration,
392 		 __entry->outer_duration,
393 		 __entry->count,
394 		 __entry->nmi_total_ts,
395 		 __entry->nmi_count)
396 );
397 
398 #define FUNC_REPEATS_GET_DELTA_TS(entry)				\
399 	(((u64)(entry)->top_delta_ts << 32) | (entry)->bottom_delta_ts)	\
400 
401 FTRACE_ENTRY(func_repeats, func_repeats_entry,
402 
403 	TRACE_FUNC_REPEATS,
404 
405 	F_STRUCT(
406 		__field(	unsigned long,	ip		)
407 		__field(	unsigned long,	parent_ip	)
408 		__field(	u16	,	count		)
409 		__field(	u16	,	top_delta_ts	)
410 		__field(	u32	,	bottom_delta_ts	)
411 	),
412 
413 	F_printk(" %ps <-%ps\t(repeats:%u  delta: -%llu)",
414 		 (void *)__entry->ip,
415 		 (void *)__entry->parent_ip,
416 		 __entry->count,
417 		 FUNC_REPEATS_GET_DELTA_TS(__entry))
418 );
419 
420 FTRACE_ENTRY(osnoise, osnoise_entry,
421 
422 	TRACE_OSNOISE,
423 
424 	F_STRUCT(
425 		__field(	u64,			noise		)
426 		__field(	u64,			runtime		)
427 		__field(	u64,			max_sample	)
428 		__field(	unsigned int,		hw_count	)
429 		__field(	unsigned int,		nmi_count	)
430 		__field(	unsigned int,		irq_count	)
431 		__field(	unsigned int,		softirq_count	)
432 		__field(	unsigned int,		thread_count	)
433 	),
434 
435 	F_printk("noise:%llu\tmax_sample:%llu\thw:%u\tnmi:%u\tirq:%u\tsoftirq:%u\tthread:%u\n",
436 		 __entry->noise,
437 		 __entry->max_sample,
438 		 __entry->hw_count,
439 		 __entry->nmi_count,
440 		 __entry->irq_count,
441 		 __entry->softirq_count,
442 		 __entry->thread_count)
443 );
444 
445 FTRACE_ENTRY(timerlat, timerlat_entry,
446 
447 	TRACE_TIMERLAT,
448 
449 	F_STRUCT(
450 		__field(	unsigned int,		seqnum		)
451 		__field(	int,			context		)
452 		__field(	u64,			timer_latency	)
453 	),
454 
455 	F_printk("seq:%u\tcontext:%d\ttimer_latency:%llu\n",
456 		 __entry->seqnum,
457 		 __entry->context,
458 		 __entry->timer_latency)
459 );
460