blob: 45630a76ed3a2801bde69beb21d534cc296d0784 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Steven Rostedt770cb242009-03-05 21:35:29 -05002/*
3 * trace_export.c - export basic ftrace utilities to user space
4 *
5 * Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com>
6 */
7#include <linux/stringify.h>
8#include <linux/kallsyms.h>
9#include <linux/seq_file.h>
Steven Rostedt770cb242009-03-05 21:35:29 -050010#include <linux/uaccess.h>
11#include <linux/ftrace.h>
12#include <linux/module.h>
13#include <linux/init.h>
Steven Rostedt770cb242009-03-05 21:35:29 -050014
15#include "trace_output.h"
16
Steven Rostedt (VMware)3dd80952018-05-09 14:17:48 -040017/* Stub function for events with triggers */
18static int ftrace_event_register(struct trace_event_call *call,
19 enum trace_reg type, void *data)
20{
21 return 0;
22}
23
Steven Rostedt4e5292e2009-09-12 19:26:21 -040024#undef TRACE_SYSTEM
25#define TRACE_SYSTEM ftrace
Steven Rostedtda4d0302009-03-09 17:14:30 -040026
Jiri Olsae59a0bf2012-02-15 15:51:51 +010027/*
28 * The FTRACE_ENTRY_REG macro allows ftrace entry to define register
29 * function and thus become accesible via perf.
30 */
31#undef FTRACE_ENTRY_REG
Jiri Olsa02aa3162012-02-15 15:51:53 +010032#define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, \
33 filter, regfn) \
34 FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
35 filter)
Jiri Olsae59a0bf2012-02-15 15:51:51 +010036
Steven Rostedt4e5292e2009-09-12 19:26:21 -040037/* not needed for this file */
38#undef __field_struct
39#define __field_struct(type, item)
Steven Rostedtda4d0302009-03-09 17:14:30 -040040
Steven Rostedt4e5292e2009-09-12 19:26:21 -040041#undef __field
Li Zefan05ffa2d2009-09-14 15:54:52 +080042#define __field(type, item) type item;
43
44#undef __field_desc
45#define __field_desc(type, container, item) type item;
46
47#undef __array
48#define __array(type, item, size) type item[size];
49
50#undef __array_desc
51#define __array_desc(type, container, item, size) type item[size];
52
53#undef __dynamic_array
54#define __dynamic_array(type, item) type item[];
55
56#undef F_STRUCT
57#define F_STRUCT(args...) args
58
59#undef F_printk
60#define F_printk(fmt, args...) fmt, args
61
62#undef FTRACE_ENTRY
Jiri Olsa02aa3162012-02-15 15:51:53 +010063#define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \
64struct ____ftrace_##name { \
65 tstruct \
66}; \
67static void __always_unused ____ftrace_check_##name(void) \
68{ \
69 struct ____ftrace_##name *__entry = NULL; \
70 \
71 /* force compile-time check on F_printk() */ \
72 printk(print); \
Li Zefan05ffa2d2009-09-14 15:54:52 +080073}
74
75#undef FTRACE_ENTRY_DUP
Jiri Olsa02aa3162012-02-15 15:51:53 +010076#define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print, filter) \
77 FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
78 filter)
Li Zefan05ffa2d2009-09-14 15:54:52 +080079
80#include "trace_entries.h"
81
Steven Rostedt4e5292e2009-09-12 19:26:21 -040082#undef __field
83#define __field(type, item) \
84 ret = trace_define_field(event_call, #type, #item, \
85 offsetof(typeof(field), item), \
86 sizeof(field.item), \
Jiri Olsa02aa3162012-02-15 15:51:53 +010087 is_signed_type(type), filter_type); \
Steven Rostedt4e5292e2009-09-12 19:26:21 -040088 if (ret) \
89 return ret;
90
91#undef __field_desc
92#define __field_desc(type, container, item) \
93 ret = trace_define_field(event_call, #type, #item, \
94 offsetof(typeof(field), \
95 container.item), \
96 sizeof(field.container.item), \
Jiri Olsa02aa3162012-02-15 15:51:53 +010097 is_signed_type(type), filter_type); \
Steven Rostedt4e5292e2009-09-12 19:26:21 -040098 if (ret) \
99 return ret;
100
101#undef __array
102#define __array(type, item, len) \
Steven Rostedt04295782010-11-12 22:32:11 -0500103 do { \
Vaibhav Nagarnaik87291342014-02-13 19:51:48 -0800104 char *type_str = #type"["__stringify(len)"]"; \
Steven Rostedt04295782010-11-12 22:32:11 -0500105 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
Vaibhav Nagarnaik87291342014-02-13 19:51:48 -0800106 ret = trace_define_field(event_call, type_str, #item, \
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400107 offsetof(typeof(field), item), \
Lai Jiangshanfb7ae9812009-12-15 15:39:38 +0800108 sizeof(field.item), \
Jiri Olsa02aa3162012-02-15 15:51:53 +0100109 is_signed_type(type), filter_type); \
Steven Rostedt04295782010-11-12 22:32:11 -0500110 if (ret) \
111 return ret; \
112 } while (0);
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400113
114#undef __array_desc
115#define __array_desc(type, container, item, len) \
116 BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
117 ret = trace_define_field(event_call, #type "[" #len "]", #item, \
118 offsetof(typeof(field), \
119 container.item), \
Lai Jiangshanfb7ae9812009-12-15 15:39:38 +0800120 sizeof(field.container.item), \
Jiri Olsa02aa3162012-02-15 15:51:53 +0100121 is_signed_type(type), filter_type); \
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400122 if (ret) \
123 return ret;
124
125#undef __dynamic_array
Lai Jiangshan809826a2009-12-15 15:39:34 +0800126#define __dynamic_array(type, item) \
Steven Rostedt (VMware)af3dcb52018-05-09 09:24:00 -0400127 ret = trace_define_field(event_call, #type "[]", #item, \
Lai Jiangshan809826a2009-12-15 15:39:34 +0800128 offsetof(typeof(field), item), \
Jiri Olsa02aa3162012-02-15 15:51:53 +0100129 0, is_signed_type(type), filter_type);\
Lai Jiangshan809826a2009-12-15 15:39:34 +0800130 if (ret) \
131 return ret;
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400132
133#undef FTRACE_ENTRY
Jiri Olsa02aa3162012-02-15 15:51:53 +0100134#define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \
Li Zefan7e4f44b2013-02-21 10:33:33 +0800135static int __init \
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400136ftrace_define_fields_##name(struct trace_event_call *event_call) \
Tom Zanussie45f2e22009-03-31 00:49:16 -0500137{ \
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400138 struct struct_name field; \
Tom Zanussie45f2e22009-03-31 00:49:16 -0500139 int ret; \
Jiri Olsa02aa3162012-02-15 15:51:53 +0100140 int filter_type = filter; \
Tom Zanussie45f2e22009-03-31 00:49:16 -0500141 \
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400142 tstruct; \
Tom Zanussie45f2e22009-03-31 00:49:16 -0500143 \
144 return ret; \
145}
146
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400147#include "trace_entries.h"
148
Lai Jiangshan509e7602009-12-15 15:39:42 +0800149#undef __entry
150#define __entry REC
151
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400152#undef __field
153#define __field(type, item)
154
155#undef __field_desc
156#define __field_desc(type, container, item)
157
158#undef __array
159#define __array(type, item, len)
160
161#undef __array_desc
162#define __array_desc(type, container, item, len)
163
164#undef __dynamic_array
165#define __dynamic_array(type, item)
166
Lai Jiangshan509e7602009-12-15 15:39:42 +0800167#undef F_printk
Wolfgang Mauerer01de9822012-03-22 11:18:20 +0100168#define F_printk(fmt, args...) __stringify(fmt) ", " __stringify(args)
Lai Jiangshan509e7602009-12-15 15:39:42 +0800169
Jiri Olsae59a0bf2012-02-15 15:51:51 +0100170#undef FTRACE_ENTRY_REG
Jiri Olsa02aa3162012-02-15 15:51:53 +0100171#define FTRACE_ENTRY_REG(call, struct_name, etype, tstruct, print, filter,\
172 regfn) \
Steven Rostedt770cb242009-03-05 21:35:29 -0500173 \
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400174struct trace_event_class __refdata event_class_ftrace_##call = { \
Steven Rostedt2e33af02010-04-22 10:35:55 -0400175 .system = __stringify(TRACE_SYSTEM), \
176 .define_fields = ftrace_define_fields_##call, \
Li Zefanffb9f992010-05-24 16:24:52 +0800177 .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
Jiri Olsae59a0bf2012-02-15 15:51:51 +0100178 .reg = regfn, \
Steven Rostedt2e33af02010-04-22 10:35:55 -0400179}; \
180 \
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400181struct trace_event_call __used event_##call = { \
Steven Rostedt2e33af02010-04-22 10:35:55 -0400182 .class = &event_class_ftrace_##call, \
Mathieu Desnoyersabb43f62014-04-09 17:06:08 -0400183 { \
184 .name = #call, \
185 }, \
186 .event.type = etype, \
Lai Jiangshan509e7602009-12-15 15:39:42 +0800187 .print_fmt = print, \
He Kuang754cb002015-03-03 15:21:33 +0800188 .flags = TRACE_EVENT_FL_IGNORE_ENABLE, \
Tom Zanussie1112b42009-03-31 00:48:49 -0500189}; \
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400190struct trace_event_call __used \
Steven Rostedte4a9ea52011-01-27 09:15:30 -0500191__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call;
Tom Zanussie1112b42009-03-31 00:48:49 -0500192
Jiri Olsae59a0bf2012-02-15 15:51:51 +0100193#undef FTRACE_ENTRY
Jiri Olsa02aa3162012-02-15 15:51:53 +0100194#define FTRACE_ENTRY(call, struct_name, etype, tstruct, print, filter) \
Jiri Olsae59a0bf2012-02-15 15:51:51 +0100195 FTRACE_ENTRY_REG(call, struct_name, etype, \
Jiri Olsa02aa3162012-02-15 15:51:53 +0100196 PARAMS(tstruct), PARAMS(print), filter, NULL)
Jiri Olsae59a0bf2012-02-15 15:51:51 +0100197
Yaowei Baic6650b22015-09-29 22:43:36 +0800198bool ftrace_event_is_function(struct trace_event_call *call)
Jiri Olsaced39002012-02-15 15:51:52 +0100199{
200 return call == &event_function;
201}
202
Steven Rostedt4e5292e2009-09-12 19:26:21 -0400203#include "trace_entries.h"