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