Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Stage 1 of the trace events. |
| 3 | * |
| 4 | * Override the macros in <trace/trace_events.h> to include the following: |
| 5 | * |
| 6 | * struct ftrace_raw_<call> { |
| 7 | * struct trace_entry ent; |
| 8 | * <type> <item>; |
| 9 | * <type2> <item2>[<len>]; |
| 10 | * [...] |
| 11 | * }; |
| 12 | * |
| 13 | * The <type> <item> is created by the __field(type, item) macro or |
| 14 | * the __array(type2, item2, len) macro. |
| 15 | * We simply do "type item;", and that will create the fields |
| 16 | * in the structure. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/ftrace_event.h> |
| 20 | |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 21 | /* |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 22 | * DECLARE_EVENT_CLASS can be used to add a generic function |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 23 | * handlers for events. That is, if all events have the same |
| 24 | * parameters and just have distinct trace points. |
| 25 | * Each tracepoint can be defined with DEFINE_EVENT and that |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 26 | * will map the DECLARE_EVENT_CLASS to the tracepoint. |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 27 | * |
| 28 | * TRACE_EVENT is a one to one mapping between tracepoint and template. |
| 29 | */ |
| 30 | #undef TRACE_EVENT |
| 31 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 32 | DECLARE_EVENT_CLASS(name, \ |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 33 | PARAMS(proto), \ |
| 34 | PARAMS(args), \ |
| 35 | PARAMS(tstruct), \ |
| 36 | PARAMS(assign), \ |
| 37 | PARAMS(print)); \ |
| 38 | DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)); |
| 39 | |
| 40 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 41 | #undef __field |
| 42 | #define __field(type, item) type item; |
| 43 | |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 44 | #undef __field_ext |
| 45 | #define __field_ext(type, item, filter_type) type item; |
| 46 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 47 | #undef __array |
| 48 | #define __array(type, item, len) type item[len]; |
| 49 | |
| 50 | #undef __dynamic_array |
Li Zefan | 7d536cb | 2009-07-16 10:54:02 +0800 | [diff] [blame] | 51 | #define __dynamic_array(type, item, len) u32 __data_loc_##item; |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 52 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 53 | #undef __string |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 54 | #define __string(item, src) __dynamic_array(char, item, -1) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 55 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 56 | #undef TP_STRUCT__entry |
| 57 | #define TP_STRUCT__entry(args...) args |
| 58 | |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 59 | #undef DECLARE_EVENT_CLASS |
| 60 | #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \ |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 61 | struct ftrace_raw_##name { \ |
| 62 | struct trace_entry ent; \ |
| 63 | tstruct \ |
| 64 | char __data[0]; \ |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 65 | }; \ |
| 66 | \ |
| 67 | static struct ftrace_event_class event_class_##name; |
| 68 | |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 69 | #undef DEFINE_EVENT |
| 70 | #define DEFINE_EVENT(template, name, proto, args) \ |
Jeff Mahoney | 86c38a3 | 2010-02-24 13:59:23 -0500 | [diff] [blame] | 71 | static struct ftrace_event_call \ |
| 72 | __attribute__((__aligned__(4))) event_##name |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 73 | |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 74 | #undef DEFINE_EVENT_PRINT |
| 75 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 76 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 77 | |
Frederic Weisbecker | 0dd7b74 | 2009-08-28 00:50:06 +0200 | [diff] [blame] | 78 | #undef __cpparg |
| 79 | #define __cpparg(arg...) arg |
| 80 | |
Josh Stone | 9741987 | 2009-08-24 14:43:13 -0700 | [diff] [blame] | 81 | /* Callbacks are meaningless to ftrace. */ |
| 82 | #undef TRACE_EVENT_FN |
Frederic Weisbecker | 0dd7b74 | 2009-08-28 00:50:06 +0200 | [diff] [blame] | 83 | #define TRACE_EVENT_FN(name, proto, args, tstruct, \ |
| 84 | assign, print, reg, unreg) \ |
| 85 | TRACE_EVENT(name, __cpparg(proto), __cpparg(args), \ |
| 86 | __cpparg(tstruct), __cpparg(assign), __cpparg(print)) \ |
Josh Stone | 9741987 | 2009-08-24 14:43:13 -0700 | [diff] [blame] | 87 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 88 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 89 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 90 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 91 | /* |
| 92 | * Stage 2 of the trace events. |
| 93 | * |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 94 | * Include the following: |
| 95 | * |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 96 | * struct ftrace_data_offsets_<call> { |
Li Zefan | 7d536cb | 2009-07-16 10:54:02 +0800 | [diff] [blame] | 97 | * u32 <item1>; |
| 98 | * u32 <item2>; |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 99 | * [...] |
| 100 | * }; |
| 101 | * |
Li Zefan | 7d536cb | 2009-07-16 10:54:02 +0800 | [diff] [blame] | 102 | * The __dynamic_array() macro will create each u32 <item>, this is |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 103 | * to keep the offset of each array from the beginning of the event. |
Li Zefan | 7d536cb | 2009-07-16 10:54:02 +0800 | [diff] [blame] | 104 | * The size of an array is also encoded, in the higher 16 bits of <item>. |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 105 | */ |
| 106 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 107 | #undef __field |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 108 | #define __field(type, item) |
| 109 | |
| 110 | #undef __field_ext |
| 111 | #define __field_ext(type, item, filter_type) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 112 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 113 | #undef __array |
| 114 | #define __array(type, item, len) |
| 115 | |
| 116 | #undef __dynamic_array |
Li Zefan | 7d536cb | 2009-07-16 10:54:02 +0800 | [diff] [blame] | 117 | #define __dynamic_array(type, item, len) u32 item; |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 118 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 119 | #undef __string |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 120 | #define __string(item, src) __dynamic_array(char, item, -1) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 121 | |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 122 | #undef DECLARE_EVENT_CLASS |
| 123 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 124 | struct ftrace_data_offsets_##call { \ |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 125 | tstruct; \ |
| 126 | }; |
| 127 | |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 128 | #undef DEFINE_EVENT |
| 129 | #define DEFINE_EVENT(template, name, proto, args) |
| 130 | |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 131 | #undef DEFINE_EVENT_PRINT |
| 132 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 133 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 134 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 135 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 136 | |
| 137 | /* |
| 138 | * Stage 3 of the trace events. |
| 139 | * |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 140 | * Override the macros in <trace/trace_events.h> to include the following: |
| 141 | * |
| 142 | * enum print_line_t |
| 143 | * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags) |
| 144 | * { |
| 145 | * struct trace_seq *s = &iter->seq; |
| 146 | * struct ftrace_raw_<call> *field; <-- defined in stage 1 |
| 147 | * struct trace_entry *entry; |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 148 | * struct trace_seq *p; |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 149 | * int ret; |
| 150 | * |
| 151 | * entry = iter->ent; |
| 152 | * |
| 153 | * if (entry->type != event_<call>.id) { |
| 154 | * WARN_ON_ONCE(1); |
| 155 | * return TRACE_TYPE_UNHANDLED; |
| 156 | * } |
| 157 | * |
| 158 | * field = (typeof(field))entry; |
| 159 | * |
Li Zefan | 50354a8 | 2010-03-24 10:58:24 +0800 | [diff] [blame] | 160 | * p = &get_cpu_var(ftrace_event_seq); |
Steven Whitehouse | 56d8bd3 | 2009-06-03 14:52:03 +0100 | [diff] [blame] | 161 | * trace_seq_init(p); |
Li Zefan | 50354a8 | 2010-03-24 10:58:24 +0800 | [diff] [blame] | 162 | * ret = trace_seq_printf(s, "%s: ", <call>); |
| 163 | * if (ret) |
| 164 | * ret = trace_seq_printf(s, <TP_printk> "\n"); |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 165 | * put_cpu(); |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 166 | * if (!ret) |
| 167 | * return TRACE_TYPE_PARTIAL_LINE; |
| 168 | * |
| 169 | * return TRACE_TYPE_HANDLED; |
| 170 | * } |
| 171 | * |
| 172 | * This is the method used to print the raw event to the trace |
| 173 | * output format. Note, this is not needed if the data is read |
| 174 | * in binary. |
| 175 | */ |
| 176 | |
| 177 | #undef __entry |
| 178 | #define __entry field |
| 179 | |
| 180 | #undef TP_printk |
| 181 | #define TP_printk(fmt, args...) fmt "\n", args |
| 182 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 183 | #undef __get_dynamic_array |
| 184 | #define __get_dynamic_array(field) \ |
Li Zefan | 7d536cb | 2009-07-16 10:54:02 +0800 | [diff] [blame] | 185 | ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 186 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 187 | #undef __get_str |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 188 | #define __get_str(field) (char *)__get_dynamic_array(field) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 189 | |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 190 | #undef __print_flags |
| 191 | #define __print_flags(flag, delim, flag_array...) \ |
| 192 | ({ \ |
Steven Rostedt | a48f494 | 2009-09-14 11:18:02 -0400 | [diff] [blame] | 193 | static const struct trace_print_flags __flags[] = \ |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 194 | { flag_array, { -1, NULL }}; \ |
Steven Rostedt | a48f494 | 2009-09-14 11:18:02 -0400 | [diff] [blame] | 195 | ftrace_print_flags_seq(p, delim, flag, __flags); \ |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 196 | }) |
| 197 | |
Steven Rostedt | 0f4fc29 | 2009-05-20 19:21:47 -0400 | [diff] [blame] | 198 | #undef __print_symbolic |
| 199 | #define __print_symbolic(value, symbol_array...) \ |
| 200 | ({ \ |
| 201 | static const struct trace_print_flags symbols[] = \ |
| 202 | { symbol_array, { -1, NULL }}; \ |
| 203 | ftrace_print_symbols_seq(p, value, symbols); \ |
| 204 | }) |
| 205 | |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 206 | #undef DECLARE_EVENT_CLASS |
| 207 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
Steven Rostedt | 83f0d53 | 2010-02-16 10:38:47 -0500 | [diff] [blame] | 208 | static notrace enum print_line_t \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame^] | 209 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ |
| 210 | struct trace_event *trace_event) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 211 | { \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame^] | 212 | struct ftrace_event_call *event; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 213 | struct trace_seq *s = &iter->seq; \ |
| 214 | struct ftrace_raw_##call *field; \ |
| 215 | struct trace_entry *entry; \ |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 216 | struct trace_seq *p; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 217 | int ret; \ |
| 218 | \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame^] | 219 | event = container_of(trace_event, struct ftrace_event_call, \ |
| 220 | event); \ |
| 221 | \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 222 | entry = iter->ent; \ |
| 223 | \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame^] | 224 | if (entry->type != event->id) { \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 225 | WARN_ON_ONCE(1); \ |
| 226 | return TRACE_TYPE_UNHANDLED; \ |
| 227 | } \ |
| 228 | \ |
| 229 | field = (typeof(field))entry; \ |
| 230 | \ |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 231 | p = &get_cpu_var(ftrace_event_seq); \ |
Steven Whitehouse | 56d8bd3 | 2009-06-03 14:52:03 +0100 | [diff] [blame] | 232 | trace_seq_init(p); \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame^] | 233 | ret = trace_seq_printf(s, "%s: ", event->name); \ |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 234 | if (ret) \ |
| 235 | ret = trace_seq_printf(s, print); \ |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 236 | put_cpu(); \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 237 | if (!ret) \ |
| 238 | return TRACE_TYPE_PARTIAL_LINE; \ |
| 239 | \ |
| 240 | return TRACE_TYPE_HANDLED; \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame^] | 241 | } \ |
| 242 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ |
| 243 | .trace = ftrace_raw_output_##call, \ |
| 244 | }; |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 245 | |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 246 | #undef DEFINE_EVENT_PRINT |
| 247 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ |
Steven Rostedt | 83f0d53 | 2010-02-16 10:38:47 -0500 | [diff] [blame] | 248 | static notrace enum print_line_t \ |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 249 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ |
| 250 | struct trace_event *event) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 251 | { \ |
| 252 | struct trace_seq *s = &iter->seq; \ |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 253 | struct ftrace_raw_##template *field; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 254 | struct trace_entry *entry; \ |
| 255 | struct trace_seq *p; \ |
| 256 | int ret; \ |
| 257 | \ |
| 258 | entry = iter->ent; \ |
| 259 | \ |
| 260 | if (entry->type != event_##call.id) { \ |
| 261 | WARN_ON_ONCE(1); \ |
| 262 | return TRACE_TYPE_UNHANDLED; \ |
| 263 | } \ |
| 264 | \ |
| 265 | field = (typeof(field))entry; \ |
| 266 | \ |
| 267 | p = &get_cpu_var(ftrace_event_seq); \ |
| 268 | trace_seq_init(p); \ |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 269 | ret = trace_seq_printf(s, "%s: ", #call); \ |
| 270 | if (ret) \ |
| 271 | ret = trace_seq_printf(s, print); \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 272 | put_cpu(); \ |
| 273 | if (!ret) \ |
| 274 | return TRACE_TYPE_PARTIAL_LINE; \ |
| 275 | \ |
| 276 | return TRACE_TYPE_HANDLED; \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame^] | 277 | } \ |
| 278 | static struct trace_event_functions ftrace_event_type_funcs_##call = { \ |
| 279 | .trace = ftrace_raw_output_##call, \ |
| 280 | }; |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 281 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 282 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 283 | |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 284 | #undef __field_ext |
| 285 | #define __field_ext(type, item, filter_type) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 286 | ret = trace_define_field(event_call, #type, #item, \ |
| 287 | offsetof(typeof(field), item), \ |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 288 | sizeof(field.item), \ |
| 289 | is_signed_type(type), filter_type); \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 290 | if (ret) \ |
| 291 | return ret; |
| 292 | |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 293 | #undef __field |
| 294 | #define __field(type, item) __field_ext(type, item, FILTER_OTHER) |
| 295 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 296 | #undef __array |
| 297 | #define __array(type, item, len) \ |
| 298 | BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ |
| 299 | ret = trace_define_field(event_call, #type "[" #len "]", #item, \ |
| 300 | offsetof(typeof(field), item), \ |
Lai Jiangshan | fb7ae98 | 2009-12-15 15:39:38 +0800 | [diff] [blame] | 301 | sizeof(field.item), \ |
| 302 | is_signed_type(type), FILTER_OTHER); \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 303 | if (ret) \ |
| 304 | return ret; |
| 305 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 306 | #undef __dynamic_array |
| 307 | #define __dynamic_array(type, item, len) \ |
Lai Jiangshan | 68fd60a | 2009-07-16 10:53:34 +0800 | [diff] [blame] | 308 | ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \ |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 309 | offsetof(typeof(field), __data_loc_##item), \ |
Lai Jiangshan | fb7ae98 | 2009-12-15 15:39:38 +0800 | [diff] [blame] | 310 | sizeof(field.__data_loc_##item), \ |
| 311 | is_signed_type(type), FILTER_OTHER); |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 312 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 313 | #undef __string |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 314 | #define __string(item, src) __dynamic_array(char, item, -1) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 315 | |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 316 | #undef DECLARE_EVENT_CLASS |
| 317 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \ |
Steven Rostedt | 83f0d53 | 2010-02-16 10:38:47 -0500 | [diff] [blame] | 318 | static int notrace \ |
Li Zefan | 14be96c | 2009-08-19 15:53:52 +0800 | [diff] [blame] | 319 | ftrace_define_fields_##call(struct ftrace_event_call *event_call) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 320 | { \ |
| 321 | struct ftrace_raw_##call field; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 322 | int ret; \ |
| 323 | \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 324 | tstruct; \ |
| 325 | \ |
| 326 | return ret; \ |
| 327 | } |
| 328 | |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 329 | #undef DEFINE_EVENT |
| 330 | #define DEFINE_EVENT(template, name, proto, args) |
| 331 | |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 332 | #undef DEFINE_EVENT_PRINT |
| 333 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 334 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 335 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 336 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 337 | |
| 338 | /* |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 339 | * remember the offset of each array from the beginning of the event. |
| 340 | */ |
| 341 | |
| 342 | #undef __entry |
| 343 | #define __entry entry |
| 344 | |
| 345 | #undef __field |
| 346 | #define __field(type, item) |
| 347 | |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 348 | #undef __field_ext |
| 349 | #define __field_ext(type, item, filter_type) |
| 350 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 351 | #undef __array |
| 352 | #define __array(type, item, len) |
| 353 | |
| 354 | #undef __dynamic_array |
| 355 | #define __dynamic_array(type, item, len) \ |
| 356 | __data_offsets->item = __data_size + \ |
| 357 | offsetof(typeof(*entry), __data); \ |
Li Zefan | 7d536cb | 2009-07-16 10:54:02 +0800 | [diff] [blame] | 358 | __data_offsets->item |= (len * sizeof(type)) << 16; \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 359 | __data_size += (len) * sizeof(type); |
| 360 | |
| 361 | #undef __string |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 362 | #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 363 | |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 364 | #undef DECLARE_EVENT_CLASS |
| 365 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
Steven Rostedt | 83f0d53 | 2010-02-16 10:38:47 -0500 | [diff] [blame] | 366 | static inline notrace int ftrace_get_offsets_##call( \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 367 | struct ftrace_data_offsets_##call *__data_offsets, proto) \ |
| 368 | { \ |
| 369 | int __data_size = 0; \ |
| 370 | struct ftrace_raw_##call __maybe_unused *entry; \ |
| 371 | \ |
| 372 | tstruct; \ |
| 373 | \ |
| 374 | return __data_size; \ |
| 375 | } |
| 376 | |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 377 | #undef DEFINE_EVENT |
| 378 | #define DEFINE_EVENT(template, name, proto, args) |
| 379 | |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 380 | #undef DEFINE_EVENT_PRINT |
| 381 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 382 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 383 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 384 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 385 | |
| 386 | /* |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 387 | * Stage 4 of the trace events. |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 388 | * |
| 389 | * Override the macros in <trace/trace_events.h> to include the following: |
| 390 | * |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 391 | * For those macros defined with TRACE_EVENT: |
| 392 | * |
| 393 | * static struct ftrace_event_call event_<call>; |
| 394 | * |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 395 | * static void ftrace_raw_event_<call>(void *__data, proto) |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 396 | * { |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 397 | * struct ftrace_event_call *event_call = __data; |
Li Zefan | 50354a8 | 2010-03-24 10:58:24 +0800 | [diff] [blame] | 398 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 399 | * struct ring_buffer_event *event; |
| 400 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 401 | * struct ring_buffer *buffer; |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 402 | * unsigned long irq_flags; |
Li Zefan | 50354a8 | 2010-03-24 10:58:24 +0800 | [diff] [blame] | 403 | * int __data_size; |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 404 | * int pc; |
| 405 | * |
| 406 | * local_save_flags(irq_flags); |
| 407 | * pc = preempt_count(); |
| 408 | * |
Li Zefan | 50354a8 | 2010-03-24 10:58:24 +0800 | [diff] [blame] | 409 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); |
| 410 | * |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 411 | * event = trace_current_buffer_lock_reserve(&buffer, |
| 412 | * event_<call>.id, |
Li Zefan | 50354a8 | 2010-03-24 10:58:24 +0800 | [diff] [blame] | 413 | * sizeof(*entry) + __data_size, |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 414 | * irq_flags, pc); |
| 415 | * if (!event) |
| 416 | * return; |
| 417 | * entry = ring_buffer_event_data(event); |
| 418 | * |
Li Zefan | 50354a8 | 2010-03-24 10:58:24 +0800 | [diff] [blame] | 419 | * { <assign>; } <-- Here we assign the entries by the __field and |
| 420 | * __array macros. |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 421 | * |
Li Zefan | 50354a8 | 2010-03-24 10:58:24 +0800 | [diff] [blame] | 422 | * if (!filter_current_check_discard(buffer, event_call, entry, event)) |
| 423 | * trace_current_buffer_unlock_commit(buffer, |
| 424 | * event, irq_flags, pc); |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 425 | * } |
| 426 | * |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 427 | * static struct trace_event ftrace_event_type_<call> = { |
| 428 | * .trace = ftrace_raw_output_<call>, <-- stage 2 |
| 429 | * }; |
| 430 | * |
Li Zefan | 50354a8 | 2010-03-24 10:58:24 +0800 | [diff] [blame] | 431 | * static const char print_fmt_<call>[] = <TP_printk>; |
| 432 | * |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 433 | * static struct ftrace_event_class __used event_class_<template> = { |
| 434 | * .system = "<system>", |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 435 | * .define_fields = ftrace_define_fields_<call>, |
Steven Rostedt | 0405ab8 | 2010-04-22 11:46:44 -0400 | [diff] [blame] | 436 | * .fields = LIST_HEAD_INIT(event_class_##call.fields), |
| 437 | * .raw_init = trace_event_raw_init, |
| 438 | * .probe = ftrace_raw_event_##call, |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 439 | * }; |
| 440 | * |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 441 | * static struct ftrace_event_call __used |
| 442 | * __attribute__((__aligned__(4))) |
| 443 | * __attribute__((section("_ftrace_events"))) event_<call> = { |
| 444 | * .name = "<call>", |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 445 | * .class = event_class_<template>, |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 446 | * .event = &ftrace_event_type_<call>, |
Li Zefan | 50354a8 | 2010-03-24 10:58:24 +0800 | [diff] [blame] | 447 | * .print_fmt = print_fmt_<call>, |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 448 | * }; |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 449 | * |
| 450 | */ |
| 451 | |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 452 | #ifdef CONFIG_PERF_EVENTS |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 453 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 454 | #define _TRACE_PERF_PROTO(call, proto) \ |
| 455 | static notrace void \ |
| 456 | perf_trace_##call(void *__data, proto); |
| 457 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 458 | #define _TRACE_PERF_INIT(call) \ |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 459 | .perf_probe = perf_trace_##call, |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 460 | |
| 461 | #else |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 462 | #define _TRACE_PERF_PROTO(call, proto) |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 463 | #define _TRACE_PERF_INIT(call) |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 464 | #endif /* CONFIG_PERF_EVENTS */ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 465 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 466 | #undef __entry |
| 467 | #define __entry entry |
| 468 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 469 | #undef __field |
| 470 | #define __field(type, item) |
| 471 | |
| 472 | #undef __array |
| 473 | #define __array(type, item, len) |
| 474 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 475 | #undef __dynamic_array |
| 476 | #define __dynamic_array(type, item, len) \ |
| 477 | __entry->__data_loc_##item = __data_offsets.item; |
| 478 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 479 | #undef __string |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 480 | #define __string(item, src) __dynamic_array(char, item, -1) \ |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 481 | |
| 482 | #undef __assign_str |
| 483 | #define __assign_str(dst, src) \ |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 484 | strcpy(__get_str(dst), src); |
| 485 | |
Lai Jiangshan | 0fa0eda | 2009-12-15 15:39:57 +0800 | [diff] [blame] | 486 | #undef TP_fast_assign |
| 487 | #define TP_fast_assign(args...) args |
| 488 | |
| 489 | #undef TP_perf_assign |
| 490 | #define TP_perf_assign(args...) |
| 491 | |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 492 | #undef DECLARE_EVENT_CLASS |
| 493 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 494 | \ |
Steven Rostedt | 83f0d53 | 2010-02-16 10:38:47 -0500 | [diff] [blame] | 495 | static notrace void \ |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 496 | ftrace_raw_event_##call(void *__data, proto) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 497 | { \ |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 498 | struct ftrace_event_call *event_call = __data; \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 499 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 500 | struct ring_buffer_event *event; \ |
| 501 | struct ftrace_raw_##call *entry; \ |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 502 | struct ring_buffer *buffer; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 503 | unsigned long irq_flags; \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 504 | int __data_size; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 505 | int pc; \ |
| 506 | \ |
| 507 | local_save_flags(irq_flags); \ |
| 508 | pc = preempt_count(); \ |
| 509 | \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 510 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 511 | \ |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 512 | event = trace_current_buffer_lock_reserve(&buffer, \ |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 513 | event_call->id, \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 514 | sizeof(*entry) + __data_size, \ |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 515 | irq_flags, pc); \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 516 | if (!event) \ |
| 517 | return; \ |
| 518 | entry = ring_buffer_event_data(event); \ |
| 519 | \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 520 | tstruct \ |
| 521 | \ |
Li Zefan | a9c1c3a | 2009-06-01 15:35:13 +0800 | [diff] [blame] | 522 | { assign; } \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 523 | \ |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 524 | if (!filter_current_check_discard(buffer, event_call, entry, event)) \ |
| 525 | trace_nowake_buffer_unlock_commit(buffer, \ |
| 526 | event, irq_flags, pc); \ |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 527 | } |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 528 | /* |
| 529 | * The ftrace_test_probe is compiled out, it is only here as a build time check |
| 530 | * to make sure that if the tracepoint handling changes, the ftrace probe will |
| 531 | * fail to compile unless it too is updated. |
| 532 | */ |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 533 | |
| 534 | #undef DEFINE_EVENT |
| 535 | #define DEFINE_EVENT(template, call, proto, args) \ |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 536 | static inline void ftrace_test_probe_##call(void) \ |
| 537 | { \ |
| 538 | check_trace_callback_type_##call(ftrace_raw_event_##template); \ |
| 539 | } |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 540 | |
| 541 | #undef DEFINE_EVENT_PRINT |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame^] | 542 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 543 | |
| 544 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 545 | |
Lai Jiangshan | 509e760 | 2009-12-15 15:39:42 +0800 | [diff] [blame] | 546 | #undef __entry |
| 547 | #define __entry REC |
| 548 | |
| 549 | #undef __print_flags |
| 550 | #undef __print_symbolic |
| 551 | #undef __get_dynamic_array |
| 552 | #undef __get_str |
| 553 | |
| 554 | #undef TP_printk |
| 555 | #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args) |
| 556 | |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 557 | #undef DECLARE_EVENT_CLASS |
Lai Jiangshan | 509e760 | 2009-12-15 15:39:42 +0800 | [diff] [blame] | 558 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 559 | _TRACE_PERF_PROTO(call, PARAMS(proto)); \ |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 560 | static const char print_fmt_##call[] = print; \ |
| 561 | static struct ftrace_event_class __used event_class_##call = { \ |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 562 | .system = __stringify(TRACE_SYSTEM), \ |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 563 | .define_fields = ftrace_define_fields_##call, \ |
| 564 | .fields = LIST_HEAD_INIT(event_class_##call.fields),\ |
Steven Rostedt | 0405ab8 | 2010-04-22 11:46:44 -0400 | [diff] [blame] | 565 | .raw_init = trace_event_raw_init, \ |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 566 | .probe = ftrace_raw_event_##call, \ |
| 567 | _TRACE_PERF_INIT(call) \ |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 568 | }; |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 569 | |
| 570 | #undef DEFINE_EVENT |
| 571 | #define DEFINE_EVENT(template, call, proto, args) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 572 | \ |
| 573 | static struct ftrace_event_call __used \ |
| 574 | __attribute__((__aligned__(4))) \ |
| 575 | __attribute__((section("_ftrace_events"))) event_##call = { \ |
| 576 | .name = #call, \ |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 577 | .class = &event_class_##template, \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame^] | 578 | .event.funcs = &ftrace_event_type_funcs_##template, \ |
Lai Jiangshan | 509e760 | 2009-12-15 15:39:42 +0800 | [diff] [blame] | 579 | .print_fmt = print_fmt_##template, \ |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 580 | }; |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 581 | |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 582 | #undef DEFINE_EVENT_PRINT |
| 583 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 584 | \ |
Lai Jiangshan | 509e760 | 2009-12-15 15:39:42 +0800 | [diff] [blame] | 585 | static const char print_fmt_##call[] = print; \ |
| 586 | \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 587 | static struct ftrace_event_call __used \ |
| 588 | __attribute__((__aligned__(4))) \ |
| 589 | __attribute__((section("_ftrace_events"))) event_##call = { \ |
| 590 | .name = #call, \ |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 591 | .class = &event_class_##template, \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame^] | 592 | .event.funcs = &ftrace_event_type_funcs_##call, \ |
Lai Jiangshan | 509e760 | 2009-12-15 15:39:42 +0800 | [diff] [blame] | 593 | .print_fmt = print_fmt_##call, \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 597 | |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 598 | /* |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 599 | * Define the insertion callback to perf events |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 600 | * |
| 601 | * The job is very similar to ftrace_raw_event_<call> except that we don't |
| 602 | * insert in the ring buffer but in a perf counter. |
| 603 | * |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 604 | * static void ftrace_perf_<call>(proto) |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 605 | * { |
| 606 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; |
| 607 | * struct ftrace_event_call *event_call = &event_<call>; |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 608 | * extern void perf_tp_event(int, u64, u64, void *, int); |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 609 | * struct ftrace_raw_##call *entry; |
Frederic Weisbecker | 444a2a3 | 2009-11-06 04:13:05 +0100 | [diff] [blame] | 610 | * struct perf_trace_buf *trace_buf; |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 611 | * u64 __addr = 0, __count = 1; |
| 612 | * unsigned long irq_flags; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 613 | * struct trace_entry *ent; |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 614 | * int __entry_size; |
| 615 | * int __data_size; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 616 | * int __cpu |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 617 | * int pc; |
| 618 | * |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 619 | * pc = preempt_count(); |
| 620 | * |
| 621 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); |
Frederic Weisbecker | 304703a | 2009-08-10 16:11:32 +0200 | [diff] [blame] | 622 | * |
| 623 | * // Below we want to get the aligned size by taking into account |
| 624 | * // the u32 field that will later store the buffer size |
| 625 | * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32), |
| 626 | * sizeof(u64)); |
| 627 | * __entry_size -= sizeof(u32); |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 628 | * |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 629 | * // Protect the non nmi buffer |
| 630 | * // This also protects the rcu read side |
| 631 | * local_irq_save(irq_flags); |
| 632 | * __cpu = smp_processor_id(); |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 633 | * |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 634 | * if (in_nmi()) |
Paul E. McKenney | 8d53dd5 | 2010-03-03 17:50:18 -0800 | [diff] [blame] | 635 | * trace_buf = rcu_dereference_sched(perf_trace_buf_nmi); |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 636 | * else |
Paul E. McKenney | 8d53dd5 | 2010-03-03 17:50:18 -0800 | [diff] [blame] | 637 | * trace_buf = rcu_dereference_sched(perf_trace_buf); |
Frederic Weisbecker | 1853db0 | 2009-08-10 16:38:36 +0200 | [diff] [blame] | 638 | * |
Frederic Weisbecker | 444a2a3 | 2009-11-06 04:13:05 +0100 | [diff] [blame] | 639 | * if (!trace_buf) |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 640 | * goto end; |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 641 | * |
Frederic Weisbecker | 444a2a3 | 2009-11-06 04:13:05 +0100 | [diff] [blame] | 642 | * trace_buf = per_cpu_ptr(trace_buf, __cpu); |
| 643 | * |
| 644 | * // Avoid recursion from perf that could mess up the buffer |
| 645 | * if (trace_buf->recursion++) |
| 646 | * goto end_recursion; |
| 647 | * |
| 648 | * raw_data = trace_buf->buf; |
| 649 | * |
| 650 | * // Make recursion update visible before entering perf_tp_event |
| 651 | * // so that we protect from perf recursions. |
| 652 | * |
| 653 | * barrier(); |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 654 | * |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 655 | * //zero dead bytes from alignment to avoid stack leak to userspace: |
| 656 | * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; |
| 657 | * entry = (struct ftrace_raw_<call> *)raw_data; |
| 658 | * ent = &entry->ent; |
| 659 | * tracing_generic_entry_update(ent, irq_flags, pc); |
| 660 | * ent->type = event_call->id; |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 661 | * |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 662 | * <tstruct> <- do some jobs with dynamic arrays |
| 663 | * |
| 664 | * <assign> <- affect our values |
| 665 | * |
Linus Torvalds | 43c1266 | 2009-09-21 09:15:07 -0700 | [diff] [blame] | 666 | * perf_tp_event(event_call->id, __addr, __count, entry, |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 667 | * __entry_size); <- submit them to perf counter |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 668 | * |
| 669 | * } |
| 670 | */ |
| 671 | |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 672 | #ifdef CONFIG_PERF_EVENTS |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 673 | |
Lai Jiangshan | 509e760 | 2009-12-15 15:39:42 +0800 | [diff] [blame] | 674 | #undef __entry |
| 675 | #define __entry entry |
| 676 | |
| 677 | #undef __get_dynamic_array |
| 678 | #define __get_dynamic_array(field) \ |
| 679 | ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) |
| 680 | |
| 681 | #undef __get_str |
| 682 | #define __get_str(field) (char *)__get_dynamic_array(field) |
| 683 | |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 684 | #undef __perf_addr |
| 685 | #define __perf_addr(a) __addr = (a) |
| 686 | |
| 687 | #undef __perf_count |
| 688 | #define __perf_count(c) __count = (c) |
| 689 | |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 690 | #undef DECLARE_EVENT_CLASS |
| 691 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
Steven Rostedt | 83f0d53 | 2010-02-16 10:38:47 -0500 | [diff] [blame] | 692 | static notrace void \ |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 693 | perf_trace_##call(void *__data, proto) \ |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 694 | { \ |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 695 | struct ftrace_event_call *event_call = __data; \ |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 696 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 697 | struct ftrace_raw_##call *entry; \ |
| 698 | u64 __addr = 0, __count = 1; \ |
| 699 | unsigned long irq_flags; \ |
Frederic Weisbecker | c530665 | 2010-03-03 07:16:16 +0100 | [diff] [blame] | 700 | struct pt_regs *__regs; \ |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 701 | int __entry_size; \ |
| 702 | int __data_size; \ |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 703 | int rctx; \ |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 704 | \ |
| 705 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
Peter Zijlstra | a044560 | 2009-08-10 11:16:52 +0200 | [diff] [blame] | 706 | __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ |
| 707 | sizeof(u64)); \ |
Frederic Weisbecker | 304703a | 2009-08-10 16:11:32 +0200 | [diff] [blame] | 708 | __entry_size -= sizeof(u32); \ |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 709 | \ |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 710 | if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \ |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 711 | "profile buffer not large enough")) \ |
| 712 | return; \ |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 713 | entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \ |
Xiao Guangrong | 430ad5a | 2010-01-28 09:32:29 +0800 | [diff] [blame] | 714 | __entry_size, event_call->id, &rctx, &irq_flags); \ |
| 715 | if (!entry) \ |
| 716 | return; \ |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 717 | tstruct \ |
| 718 | \ |
| 719 | { assign; } \ |
| 720 | \ |
Frederic Weisbecker | c530665 | 2010-03-03 07:16:16 +0100 | [diff] [blame] | 721 | __regs = &__get_cpu_var(perf_trace_regs); \ |
| 722 | perf_fetch_caller_regs(__regs, 2); \ |
| 723 | \ |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 724 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ |
Frederic Weisbecker | c530665 | 2010-03-03 07:16:16 +0100 | [diff] [blame] | 725 | __count, irq_flags, __regs); \ |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 726 | } |
| 727 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 728 | /* |
| 729 | * This part is compiled out, it is only here as a build time check |
| 730 | * to make sure that if the tracepoint handling changes, the |
| 731 | * perf probe will fail to compile unless it too is updated. |
| 732 | */ |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 733 | #undef DEFINE_EVENT |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 734 | #define DEFINE_EVENT(template, call, proto, args) \ |
| 735 | static inline void perf_test_probe_##call(void) \ |
| 736 | { \ |
| 737 | check_trace_callback_type_##call(perf_trace_##template); \ |
| 738 | \ |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 739 | } |
| 740 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 741 | |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 742 | #undef DEFINE_EVENT_PRINT |
| 743 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 744 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 745 | |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 746 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 747 | #endif /* CONFIG_PERF_EVENTS */ |
Frederic Weisbecker | f413cdb | 2009-08-07 01:25:54 +0200 | [diff] [blame] | 748 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 749 | #undef _TRACE_PROFILE_INIT |
| 750 | |