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