Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Steven Rostedt | 770cb24 | 2009-03-05 21:35:29 -0500 | [diff] [blame] | 2 | /* |
| 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 Rostedt | 770cb24 | 2009-03-05 21:35:29 -0500 | [diff] [blame] | 10 | #include <linux/uaccess.h> |
| 11 | #include <linux/ftrace.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
Steven Rostedt | 770cb24 | 2009-03-05 21:35:29 -0500 | [diff] [blame] | 14 | |
| 15 | #include "trace_output.h" |
| 16 | |
Steven Rostedt (VMware) | 3dd8095 | 2018-05-09 14:17:48 -0400 | [diff] [blame] | 17 | /* Stub function for events with triggers */ |
| 18 | static int ftrace_event_register(struct trace_event_call *call, |
| 19 | enum trace_reg type, void *data) |
| 20 | { |
| 21 | return 0; |
| 22 | } |
| 23 | |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 24 | #undef TRACE_SYSTEM |
| 25 | #define TRACE_SYSTEM ftrace |
Steven Rostedt | da4d030 | 2009-03-09 17:14:30 -0400 | [diff] [blame] | 26 | |
Jiri Olsa | e59a0bf | 2012-02-15 15:51:51 +0100 | [diff] [blame] | 27 | /* |
| 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 Olsa | 02aa316 | 2012-02-15 15:51:53 +0100 | [diff] [blame] | 32 | #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 Olsa | e59a0bf | 2012-02-15 15:51:51 +0100 | [diff] [blame] | 36 | |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 37 | /* not needed for this file */ |
| 38 | #undef __field_struct |
| 39 | #define __field_struct(type, item) |
Steven Rostedt | da4d030 | 2009-03-09 17:14:30 -0400 | [diff] [blame] | 40 | |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 41 | #undef __field |
Li Zefan | 05ffa2d | 2009-09-14 15:54:52 +0800 | [diff] [blame] | 42 | #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 Olsa | 02aa316 | 2012-02-15 15:51:53 +0100 | [diff] [blame] | 63 | #define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \ |
| 64 | struct ____ftrace_##name { \ |
| 65 | tstruct \ |
| 66 | }; \ |
| 67 | static 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 Zefan | 05ffa2d | 2009-09-14 15:54:52 +0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | #undef FTRACE_ENTRY_DUP |
Jiri Olsa | 02aa316 | 2012-02-15 15:51:53 +0100 | [diff] [blame] | 76 | #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 Zefan | 05ffa2d | 2009-09-14 15:54:52 +0800 | [diff] [blame] | 79 | |
| 80 | #include "trace_entries.h" |
| 81 | |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 82 | #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 Olsa | 02aa316 | 2012-02-15 15:51:53 +0100 | [diff] [blame] | 87 | is_signed_type(type), filter_type); \ |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 88 | 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 Olsa | 02aa316 | 2012-02-15 15:51:53 +0100 | [diff] [blame] | 97 | is_signed_type(type), filter_type); \ |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 98 | if (ret) \ |
| 99 | return ret; |
| 100 | |
| 101 | #undef __array |
| 102 | #define __array(type, item, len) \ |
Steven Rostedt | 0429578 | 2010-11-12 22:32:11 -0500 | [diff] [blame] | 103 | do { \ |
Vaibhav Nagarnaik | 8729134 | 2014-02-13 19:51:48 -0800 | [diff] [blame] | 104 | char *type_str = #type"["__stringify(len)"]"; \ |
Steven Rostedt | 0429578 | 2010-11-12 22:32:11 -0500 | [diff] [blame] | 105 | BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ |
Vaibhav Nagarnaik | 8729134 | 2014-02-13 19:51:48 -0800 | [diff] [blame] | 106 | ret = trace_define_field(event_call, type_str, #item, \ |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 107 | offsetof(typeof(field), item), \ |
Lai Jiangshan | fb7ae981 | 2009-12-15 15:39:38 +0800 | [diff] [blame] | 108 | sizeof(field.item), \ |
Jiri Olsa | 02aa316 | 2012-02-15 15:51:53 +0100 | [diff] [blame] | 109 | is_signed_type(type), filter_type); \ |
Steven Rostedt | 0429578 | 2010-11-12 22:32:11 -0500 | [diff] [blame] | 110 | if (ret) \ |
| 111 | return ret; \ |
| 112 | } while (0); |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 113 | |
| 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 Jiangshan | fb7ae981 | 2009-12-15 15:39:38 +0800 | [diff] [blame] | 120 | sizeof(field.container.item), \ |
Jiri Olsa | 02aa316 | 2012-02-15 15:51:53 +0100 | [diff] [blame] | 121 | is_signed_type(type), filter_type); \ |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 122 | if (ret) \ |
| 123 | return ret; |
| 124 | |
| 125 | #undef __dynamic_array |
Lai Jiangshan | 809826a | 2009-12-15 15:39:34 +0800 | [diff] [blame] | 126 | #define __dynamic_array(type, item) \ |
Steven Rostedt (VMware) | af3dcb5 | 2018-05-09 09:24:00 -0400 | [diff] [blame] | 127 | ret = trace_define_field(event_call, #type "[]", #item, \ |
Lai Jiangshan | 809826a | 2009-12-15 15:39:34 +0800 | [diff] [blame] | 128 | offsetof(typeof(field), item), \ |
Jiri Olsa | 02aa316 | 2012-02-15 15:51:53 +0100 | [diff] [blame] | 129 | 0, is_signed_type(type), filter_type);\ |
Lai Jiangshan | 809826a | 2009-12-15 15:39:34 +0800 | [diff] [blame] | 130 | if (ret) \ |
| 131 | return ret; |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 132 | |
| 133 | #undef FTRACE_ENTRY |
Jiri Olsa | 02aa316 | 2012-02-15 15:51:53 +0100 | [diff] [blame] | 134 | #define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \ |
Li Zefan | 7e4f44b | 2013-02-21 10:33:33 +0800 | [diff] [blame] | 135 | static int __init \ |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 136 | ftrace_define_fields_##name(struct trace_event_call *event_call) \ |
Tom Zanussi | e45f2e2 | 2009-03-31 00:49:16 -0500 | [diff] [blame] | 137 | { \ |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 138 | struct struct_name field; \ |
Tom Zanussi | e45f2e2 | 2009-03-31 00:49:16 -0500 | [diff] [blame] | 139 | int ret; \ |
Jiri Olsa | 02aa316 | 2012-02-15 15:51:53 +0100 | [diff] [blame] | 140 | int filter_type = filter; \ |
Tom Zanussi | e45f2e2 | 2009-03-31 00:49:16 -0500 | [diff] [blame] | 141 | \ |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 142 | tstruct; \ |
Tom Zanussi | e45f2e2 | 2009-03-31 00:49:16 -0500 | [diff] [blame] | 143 | \ |
| 144 | return ret; \ |
| 145 | } |
| 146 | |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 147 | #include "trace_entries.h" |
| 148 | |
Lai Jiangshan | 509e760 | 2009-12-15 15:39:42 +0800 | [diff] [blame] | 149 | #undef __entry |
| 150 | #define __entry REC |
| 151 | |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 152 | #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 Jiangshan | 509e760 | 2009-12-15 15:39:42 +0800 | [diff] [blame] | 167 | #undef F_printk |
Wolfgang Mauerer | 01de982 | 2012-03-22 11:18:20 +0100 | [diff] [blame] | 168 | #define F_printk(fmt, args...) __stringify(fmt) ", " __stringify(args) |
Lai Jiangshan | 509e760 | 2009-12-15 15:39:42 +0800 | [diff] [blame] | 169 | |
Jiri Olsa | e59a0bf | 2012-02-15 15:51:51 +0100 | [diff] [blame] | 170 | #undef FTRACE_ENTRY_REG |
Jiri Olsa | 02aa316 | 2012-02-15 15:51:53 +0100 | [diff] [blame] | 171 | #define FTRACE_ENTRY_REG(call, struct_name, etype, tstruct, print, filter,\ |
| 172 | regfn) \ |
Steven Rostedt | 770cb24 | 2009-03-05 21:35:29 -0500 | [diff] [blame] | 173 | \ |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 174 | struct trace_event_class __refdata event_class_ftrace_##call = { \ |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 175 | .system = __stringify(TRACE_SYSTEM), \ |
| 176 | .define_fields = ftrace_define_fields_##call, \ |
Li Zefan | ffb9f99 | 2010-05-24 16:24:52 +0800 | [diff] [blame] | 177 | .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\ |
Jiri Olsa | e59a0bf | 2012-02-15 15:51:51 +0100 | [diff] [blame] | 178 | .reg = regfn, \ |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 179 | }; \ |
| 180 | \ |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 181 | struct trace_event_call __used event_##call = { \ |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 182 | .class = &event_class_ftrace_##call, \ |
Mathieu Desnoyers | abb43f6 | 2014-04-09 17:06:08 -0400 | [diff] [blame] | 183 | { \ |
| 184 | .name = #call, \ |
| 185 | }, \ |
| 186 | .event.type = etype, \ |
Lai Jiangshan | 509e760 | 2009-12-15 15:39:42 +0800 | [diff] [blame] | 187 | .print_fmt = print, \ |
He Kuang | 754cb00 | 2015-03-03 15:21:33 +0800 | [diff] [blame] | 188 | .flags = TRACE_EVENT_FL_IGNORE_ENABLE, \ |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 189 | }; \ |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 190 | struct trace_event_call __used \ |
Steven Rostedt | e4a9ea5 | 2011-01-27 09:15:30 -0500 | [diff] [blame] | 191 | __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 192 | |
Jiri Olsa | e59a0bf | 2012-02-15 15:51:51 +0100 | [diff] [blame] | 193 | #undef FTRACE_ENTRY |
Jiri Olsa | 02aa316 | 2012-02-15 15:51:53 +0100 | [diff] [blame] | 194 | #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print, filter) \ |
Jiri Olsa | e59a0bf | 2012-02-15 15:51:51 +0100 | [diff] [blame] | 195 | FTRACE_ENTRY_REG(call, struct_name, etype, \ |
Jiri Olsa | 02aa316 | 2012-02-15 15:51:53 +0100 | [diff] [blame] | 196 | PARAMS(tstruct), PARAMS(print), filter, NULL) |
Jiri Olsa | e59a0bf | 2012-02-15 15:51:51 +0100 | [diff] [blame] | 197 | |
Yaowei Bai | c6650b2 | 2015-09-29 22:43:36 +0800 | [diff] [blame] | 198 | bool ftrace_event_is_function(struct trace_event_call *call) |
Jiri Olsa | ced3900 | 2012-02-15 15:51:52 +0100 | [diff] [blame] | 199 | { |
| 200 | return call == &event_function; |
| 201 | } |
| 202 | |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 203 | #include "trace_entries.h" |