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