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 | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 21 | #undef __field |
| 22 | #define __field(type, item) type item; |
| 23 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 24 | #undef __array |
| 25 | #define __array(type, item, len) type item[len]; |
| 26 | |
| 27 | #undef __dynamic_array |
| 28 | #define __dynamic_array(type, item, len) unsigned short __data_loc_##item; |
| 29 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 30 | #undef __string |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 31 | #define __string(item, src) __dynamic_array(char, item, -1) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 32 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 33 | #undef TP_STRUCT__entry |
| 34 | #define TP_STRUCT__entry(args...) args |
| 35 | |
| 36 | #undef TRACE_EVENT |
| 37 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ |
| 38 | struct ftrace_raw_##name { \ |
| 39 | struct trace_entry ent; \ |
| 40 | tstruct \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 41 | char __data[0]; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 42 | }; \ |
| 43 | static struct ftrace_event_call event_##name |
| 44 | |
| 45 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 46 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 47 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 48 | /* |
| 49 | * Stage 2 of the trace events. |
| 50 | * |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 51 | * Include the following: |
| 52 | * |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 53 | * struct ftrace_data_offsets_<call> { |
| 54 | * int <item1>; |
| 55 | * int <item2>; |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 56 | * [...] |
| 57 | * }; |
| 58 | * |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 59 | * The __dynamic_array() macro will create each int <item>, this is |
| 60 | * to keep the offset of each array from the beginning of the event. |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 61 | */ |
| 62 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 63 | #undef __field |
| 64 | #define __field(type, item); |
| 65 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 66 | #undef __array |
| 67 | #define __array(type, item, len) |
| 68 | |
| 69 | #undef __dynamic_array |
| 70 | #define __dynamic_array(type, item, len) int item; |
| 71 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 72 | #undef __string |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 73 | #define __string(item, src) __dynamic_array(char, item, -1) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 74 | |
| 75 | #undef TRACE_EVENT |
| 76 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 77 | struct ftrace_data_offsets_##call { \ |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 78 | tstruct; \ |
| 79 | }; |
| 80 | |
| 81 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 82 | |
| 83 | /* |
| 84 | * Stage 3 of the trace events. |
| 85 | * |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 86 | * Override the macros in <trace/trace_events.h> to include the following: |
| 87 | * |
| 88 | * enum print_line_t |
| 89 | * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags) |
| 90 | * { |
| 91 | * struct trace_seq *s = &iter->seq; |
| 92 | * struct ftrace_raw_<call> *field; <-- defined in stage 1 |
| 93 | * struct trace_entry *entry; |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 94 | * struct trace_seq *p; |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 95 | * int ret; |
| 96 | * |
| 97 | * entry = iter->ent; |
| 98 | * |
| 99 | * if (entry->type != event_<call>.id) { |
| 100 | * WARN_ON_ONCE(1); |
| 101 | * return TRACE_TYPE_UNHANDLED; |
| 102 | * } |
| 103 | * |
| 104 | * field = (typeof(field))entry; |
| 105 | * |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 106 | * p = get_cpu_var(ftrace_event_seq); |
Steven Whitehouse | 56d8bd3 | 2009-06-03 14:52:03 +0100 | [diff] [blame^] | 107 | * trace_seq_init(p); |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 108 | * ret = trace_seq_printf(s, <TP_printk> "\n"); |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 109 | * put_cpu(); |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 110 | * if (!ret) |
| 111 | * return TRACE_TYPE_PARTIAL_LINE; |
| 112 | * |
| 113 | * return TRACE_TYPE_HANDLED; |
| 114 | * } |
| 115 | * |
| 116 | * This is the method used to print the raw event to the trace |
| 117 | * output format. Note, this is not needed if the data is read |
| 118 | * in binary. |
| 119 | */ |
| 120 | |
| 121 | #undef __entry |
| 122 | #define __entry field |
| 123 | |
| 124 | #undef TP_printk |
| 125 | #define TP_printk(fmt, args...) fmt "\n", args |
| 126 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 127 | #undef __get_dynamic_array |
| 128 | #define __get_dynamic_array(field) \ |
| 129 | ((void *)__entry + __entry->__data_loc_##field) |
| 130 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 131 | #undef __get_str |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 132 | #define __get_str(field) (char *)__get_dynamic_array(field) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 133 | |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 134 | #undef __print_flags |
| 135 | #define __print_flags(flag, delim, flag_array...) \ |
| 136 | ({ \ |
| 137 | static const struct trace_print_flags flags[] = \ |
| 138 | { flag_array, { -1, NULL }}; \ |
| 139 | ftrace_print_flags_seq(p, delim, flag, flags); \ |
| 140 | }) |
| 141 | |
Steven Rostedt | 0f4fc29 | 2009-05-20 19:21:47 -0400 | [diff] [blame] | 142 | #undef __print_symbolic |
| 143 | #define __print_symbolic(value, symbol_array...) \ |
| 144 | ({ \ |
| 145 | static const struct trace_print_flags symbols[] = \ |
| 146 | { symbol_array, { -1, NULL }}; \ |
| 147 | ftrace_print_symbols_seq(p, value, symbols); \ |
| 148 | }) |
| 149 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 150 | #undef TRACE_EVENT |
| 151 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ |
| 152 | enum print_line_t \ |
| 153 | ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ |
| 154 | { \ |
| 155 | struct trace_seq *s = &iter->seq; \ |
| 156 | struct ftrace_raw_##call *field; \ |
| 157 | struct trace_entry *entry; \ |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 158 | struct trace_seq *p; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 159 | int ret; \ |
| 160 | \ |
| 161 | entry = iter->ent; \ |
| 162 | \ |
| 163 | if (entry->type != event_##call.id) { \ |
| 164 | WARN_ON_ONCE(1); \ |
| 165 | return TRACE_TYPE_UNHANDLED; \ |
| 166 | } \ |
| 167 | \ |
| 168 | field = (typeof(field))entry; \ |
| 169 | \ |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 170 | p = &get_cpu_var(ftrace_event_seq); \ |
Steven Whitehouse | 56d8bd3 | 2009-06-03 14:52:03 +0100 | [diff] [blame^] | 171 | trace_seq_init(p); \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 172 | ret = trace_seq_printf(s, #call ": " print); \ |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 173 | put_cpu(); \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 174 | if (!ret) \ |
| 175 | return TRACE_TYPE_PARTIAL_LINE; \ |
| 176 | \ |
| 177 | return TRACE_TYPE_HANDLED; \ |
| 178 | } |
| 179 | |
| 180 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 181 | |
| 182 | /* |
| 183 | * Setup the showing format of trace point. |
| 184 | * |
| 185 | * int |
| 186 | * ftrace_format_##call(struct trace_seq *s) |
| 187 | * { |
| 188 | * struct ftrace_raw_##call field; |
| 189 | * int ret; |
| 190 | * |
| 191 | * ret = trace_seq_printf(s, #type " " #item ";" |
| 192 | * " offset:%u; size:%u;\n", |
| 193 | * offsetof(struct ftrace_raw_##call, item), |
| 194 | * sizeof(field.type)); |
| 195 | * |
| 196 | * } |
| 197 | */ |
| 198 | |
| 199 | #undef TP_STRUCT__entry |
| 200 | #define TP_STRUCT__entry(args...) args |
| 201 | |
| 202 | #undef __field |
| 203 | #define __field(type, item) \ |
| 204 | ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \ |
| 205 | "offset:%u;\tsize:%u;\n", \ |
| 206 | (unsigned int)offsetof(typeof(field), item), \ |
| 207 | (unsigned int)sizeof(field.item)); \ |
| 208 | if (!ret) \ |
| 209 | return 0; |
| 210 | |
| 211 | #undef __array |
| 212 | #define __array(type, item, len) \ |
| 213 | ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \ |
| 214 | "offset:%u;\tsize:%u;\n", \ |
| 215 | (unsigned int)offsetof(typeof(field), item), \ |
| 216 | (unsigned int)sizeof(field.item)); \ |
| 217 | if (!ret) \ |
| 218 | return 0; |
| 219 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 220 | #undef __dynamic_array |
| 221 | #define __dynamic_array(type, item, len) \ |
| 222 | ret = trace_seq_printf(s, "\tfield:__data_loc " #item ";\t" \ |
Li Zefan | 6e25db4 | 2009-05-29 11:24:59 +0800 | [diff] [blame] | 223 | "offset:%u;\tsize:%u;\n", \ |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 224 | (unsigned int)offsetof(typeof(field), \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 225 | __data_loc_##item), \ |
| 226 | (unsigned int)sizeof(field.__data_loc_##item)); \ |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 227 | if (!ret) \ |
| 228 | return 0; |
| 229 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 230 | #undef __string |
| 231 | #define __string(item, src) __dynamic_array(char, item, -1) |
| 232 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 233 | #undef __entry |
| 234 | #define __entry REC |
| 235 | |
| 236 | #undef TP_printk |
| 237 | #define TP_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args) |
| 238 | |
| 239 | #undef TP_fast_assign |
| 240 | #define TP_fast_assign(args...) args |
| 241 | |
| 242 | #undef TRACE_EVENT |
| 243 | #define TRACE_EVENT(call, proto, args, tstruct, func, print) \ |
| 244 | static int \ |
| 245 | ftrace_format_##call(struct trace_seq *s) \ |
| 246 | { \ |
Jeremy Fitzhardinge | 76aa811 | 2009-04-16 23:35:39 -0700 | [diff] [blame] | 247 | struct ftrace_raw_##call field __attribute__((unused)); \ |
| 248 | int ret = 0; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 249 | \ |
| 250 | tstruct; \ |
| 251 | \ |
| 252 | trace_seq_printf(s, "\nprint fmt: " print); \ |
| 253 | \ |
| 254 | return ret; \ |
| 255 | } |
| 256 | |
| 257 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 258 | |
| 259 | #undef __field |
| 260 | #define __field(type, item) \ |
| 261 | ret = trace_define_field(event_call, #type, #item, \ |
| 262 | offsetof(typeof(field), item), \ |
Tom Zanussi | a118e4d | 2009-04-28 03:04:53 -0500 | [diff] [blame] | 263 | sizeof(field.item), is_signed_type(type)); \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 264 | if (ret) \ |
| 265 | return ret; |
| 266 | |
| 267 | #undef __array |
| 268 | #define __array(type, item, len) \ |
| 269 | BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \ |
| 270 | ret = trace_define_field(event_call, #type "[" #len "]", #item, \ |
| 271 | offsetof(typeof(field), item), \ |
Tom Zanussi | a118e4d | 2009-04-28 03:04:53 -0500 | [diff] [blame] | 272 | sizeof(field.item), 0); \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 273 | if (ret) \ |
| 274 | return ret; |
| 275 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 276 | #undef __dynamic_array |
| 277 | #define __dynamic_array(type, item, len) \ |
| 278 | ret = trace_define_field(event_call, "__data_loc" "[" #type "]", #item,\ |
| 279 | offsetof(typeof(field), __data_loc_##item), \ |
| 280 | sizeof(field.__data_loc_##item), 0); |
| 281 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 282 | #undef __string |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 283 | #define __string(item, src) __dynamic_array(char, item, -1) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 284 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 285 | #undef TRACE_EVENT |
| 286 | #define TRACE_EVENT(call, proto, args, tstruct, func, print) \ |
| 287 | int \ |
| 288 | ftrace_define_fields_##call(void) \ |
| 289 | { \ |
| 290 | struct ftrace_raw_##call field; \ |
| 291 | struct ftrace_event_call *event_call = &event_##call; \ |
| 292 | int ret; \ |
| 293 | \ |
Tom Zanussi | a118e4d | 2009-04-28 03:04:53 -0500 | [diff] [blame] | 294 | __common_field(int, type, 1); \ |
| 295 | __common_field(unsigned char, flags, 0); \ |
| 296 | __common_field(unsigned char, preempt_count, 0); \ |
| 297 | __common_field(int, pid, 1); \ |
| 298 | __common_field(int, tgid, 1); \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 299 | \ |
| 300 | tstruct; \ |
| 301 | \ |
| 302 | return ret; \ |
| 303 | } |
| 304 | |
| 305 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 306 | |
| 307 | /* |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 308 | * remember the offset of each array from the beginning of the event. |
| 309 | */ |
| 310 | |
| 311 | #undef __entry |
| 312 | #define __entry entry |
| 313 | |
| 314 | #undef __field |
| 315 | #define __field(type, item) |
| 316 | |
| 317 | #undef __array |
| 318 | #define __array(type, item, len) |
| 319 | |
| 320 | #undef __dynamic_array |
| 321 | #define __dynamic_array(type, item, len) \ |
| 322 | __data_offsets->item = __data_size + \ |
| 323 | offsetof(typeof(*entry), __data); \ |
| 324 | __data_size += (len) * sizeof(type); |
| 325 | |
| 326 | #undef __string |
| 327 | #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) \ |
| 328 | |
| 329 | #undef TRACE_EVENT |
| 330 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ |
| 331 | static inline int ftrace_get_offsets_##call( \ |
| 332 | struct ftrace_data_offsets_##call *__data_offsets, proto) \ |
| 333 | { \ |
| 334 | int __data_size = 0; \ |
| 335 | struct ftrace_raw_##call __maybe_unused *entry; \ |
| 336 | \ |
| 337 | tstruct; \ |
| 338 | \ |
| 339 | return __data_size; \ |
| 340 | } |
| 341 | |
| 342 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 343 | |
| 344 | /* |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 345 | * Stage 4 of the trace events. |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 346 | * |
| 347 | * Override the macros in <trace/trace_events.h> to include the following: |
| 348 | * |
| 349 | * static void ftrace_event_<call>(proto) |
| 350 | * { |
| 351 | * event_trace_printk(_RET_IP_, "<call>: " <fmt>); |
| 352 | * } |
| 353 | * |
| 354 | * static int ftrace_reg_event_<call>(void) |
| 355 | * { |
| 356 | * int ret; |
| 357 | * |
| 358 | * ret = register_trace_<call>(ftrace_event_<call>); |
| 359 | * if (!ret) |
| 360 | * pr_info("event trace: Could not activate trace point " |
| 361 | * "probe to <call>"); |
| 362 | * return ret; |
| 363 | * } |
| 364 | * |
| 365 | * static void ftrace_unreg_event_<call>(void) |
| 366 | * { |
| 367 | * unregister_trace_<call>(ftrace_event_<call>); |
| 368 | * } |
| 369 | * |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 370 | * |
| 371 | * For those macros defined with TRACE_EVENT: |
| 372 | * |
| 373 | * static struct ftrace_event_call event_<call>; |
| 374 | * |
| 375 | * static void ftrace_raw_event_<call>(proto) |
| 376 | * { |
| 377 | * struct ring_buffer_event *event; |
| 378 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 |
| 379 | * unsigned long irq_flags; |
| 380 | * int pc; |
| 381 | * |
| 382 | * local_save_flags(irq_flags); |
| 383 | * pc = preempt_count(); |
| 384 | * |
| 385 | * event = trace_current_buffer_lock_reserve(event_<call>.id, |
| 386 | * sizeof(struct ftrace_raw_<call>), |
| 387 | * irq_flags, pc); |
| 388 | * if (!event) |
| 389 | * return; |
| 390 | * entry = ring_buffer_event_data(event); |
| 391 | * |
| 392 | * <assign>; <-- Here we assign the entries by the __field and |
| 393 | * __array macros. |
| 394 | * |
| 395 | * trace_current_buffer_unlock_commit(event, irq_flags, pc); |
| 396 | * } |
| 397 | * |
| 398 | * static int ftrace_raw_reg_event_<call>(void) |
| 399 | * { |
| 400 | * int ret; |
| 401 | * |
| 402 | * ret = register_trace_<call>(ftrace_raw_event_<call>); |
| 403 | * if (!ret) |
| 404 | * pr_info("event trace: Could not activate trace point " |
| 405 | * "probe to <call>"); |
| 406 | * return ret; |
| 407 | * } |
| 408 | * |
| 409 | * static void ftrace_unreg_event_<call>(void) |
| 410 | * { |
| 411 | * unregister_trace_<call>(ftrace_raw_event_<call>); |
| 412 | * } |
| 413 | * |
| 414 | * static struct trace_event ftrace_event_type_<call> = { |
| 415 | * .trace = ftrace_raw_output_<call>, <-- stage 2 |
| 416 | * }; |
| 417 | * |
| 418 | * static int ftrace_raw_init_event_<call>(void) |
| 419 | * { |
| 420 | * int id; |
| 421 | * |
| 422 | * id = register_ftrace_event(&ftrace_event_type_<call>); |
| 423 | * if (!id) |
| 424 | * return -ENODEV; |
| 425 | * event_<call>.id = id; |
| 426 | * return 0; |
| 427 | * } |
| 428 | * |
| 429 | * static struct ftrace_event_call __used |
| 430 | * __attribute__((__aligned__(4))) |
| 431 | * __attribute__((section("_ftrace_events"))) event_<call> = { |
| 432 | * .name = "<call>", |
| 433 | * .system = "<system>", |
| 434 | * .raw_init = ftrace_raw_init_event_<call>, |
| 435 | * .regfunc = ftrace_reg_event_<call>, |
| 436 | * .unregfunc = ftrace_unreg_event_<call>, |
| 437 | * .show_format = ftrace_format_<call>, |
| 438 | * } |
| 439 | * |
| 440 | */ |
| 441 | |
| 442 | #undef TP_FMT |
| 443 | #define TP_FMT(fmt, args...) fmt "\n", ##args |
| 444 | |
| 445 | #ifdef CONFIG_EVENT_PROFILE |
| 446 | #define _TRACE_PROFILE(call, proto, args) \ |
| 447 | static void ftrace_profile_##call(proto) \ |
| 448 | { \ |
| 449 | extern void perf_tpcounter_event(int); \ |
| 450 | perf_tpcounter_event(event_##call.id); \ |
| 451 | } \ |
| 452 | \ |
Zhaolei | f2aebae | 2009-05-27 21:36:02 +0800 | [diff] [blame] | 453 | static int ftrace_profile_enable_##call(struct ftrace_event_call *event_call) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 454 | { \ |
| 455 | int ret = 0; \ |
| 456 | \ |
Zhaolei | f2aebae | 2009-05-27 21:36:02 +0800 | [diff] [blame] | 457 | if (!atomic_inc_return(&event_call->profile_count)) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 458 | ret = register_trace_##call(ftrace_profile_##call); \ |
| 459 | \ |
| 460 | return ret; \ |
| 461 | } \ |
| 462 | \ |
Zhaolei | f2aebae | 2009-05-27 21:36:02 +0800 | [diff] [blame] | 463 | static void ftrace_profile_disable_##call(struct ftrace_event_call *event_call)\ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 464 | { \ |
Zhaolei | f2aebae | 2009-05-27 21:36:02 +0800 | [diff] [blame] | 465 | if (atomic_add_negative(-1, &event_call->profile_count)) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 466 | unregister_trace_##call(ftrace_profile_##call); \ |
| 467 | } |
| 468 | |
| 469 | #define _TRACE_PROFILE_INIT(call) \ |
| 470 | .profile_count = ATOMIC_INIT(-1), \ |
| 471 | .profile_enable = ftrace_profile_enable_##call, \ |
| 472 | .profile_disable = ftrace_profile_disable_##call, |
| 473 | |
| 474 | #else |
| 475 | #define _TRACE_PROFILE(call, proto, args) |
| 476 | #define _TRACE_PROFILE_INIT(call) |
| 477 | #endif |
| 478 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 479 | #undef __entry |
| 480 | #define __entry entry |
| 481 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 482 | #undef __field |
| 483 | #define __field(type, item) |
| 484 | |
| 485 | #undef __array |
| 486 | #define __array(type, item, len) |
| 487 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 488 | #undef __dynamic_array |
| 489 | #define __dynamic_array(type, item, len) \ |
| 490 | __entry->__data_loc_##item = __data_offsets.item; |
| 491 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 492 | #undef __string |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 493 | #define __string(item, src) __dynamic_array(char, item, -1) \ |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 494 | |
| 495 | #undef __assign_str |
| 496 | #define __assign_str(dst, src) \ |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 497 | strcpy(__get_str(dst), src); |
| 498 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 499 | #undef TRACE_EVENT |
| 500 | #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \ |
| 501 | _TRACE_PROFILE(call, PARAMS(proto), PARAMS(args)) \ |
| 502 | \ |
| 503 | static struct ftrace_event_call event_##call; \ |
| 504 | \ |
| 505 | static void ftrace_raw_event_##call(proto) \ |
| 506 | { \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 507 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
Zhaolei | f2aebae | 2009-05-27 21:36:02 +0800 | [diff] [blame] | 508 | struct ftrace_event_call *event_call = &event_##call; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 509 | struct ring_buffer_event *event; \ |
| 510 | struct ftrace_raw_##call *entry; \ |
| 511 | unsigned long irq_flags; \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 512 | int __data_size; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 513 | int pc; \ |
| 514 | \ |
| 515 | local_save_flags(irq_flags); \ |
| 516 | pc = preempt_count(); \ |
| 517 | \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 518 | __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 519 | \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 520 | event = trace_current_buffer_lock_reserve(event_##call.id, \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 521 | sizeof(*entry) + __data_size, \ |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 522 | irq_flags, pc); \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 523 | if (!event) \ |
| 524 | return; \ |
| 525 | entry = ring_buffer_event_data(event); \ |
| 526 | \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 527 | \ |
| 528 | tstruct \ |
| 529 | \ |
Li Zefan | a9c1c3a | 2009-06-01 15:35:13 +0800 | [diff] [blame] | 530 | { assign; } \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 531 | \ |
Zhaolei | f2aebae | 2009-05-27 21:36:02 +0800 | [diff] [blame] | 532 | if (!filter_current_check_discard(event_call, entry, event)) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 533 | trace_nowake_buffer_unlock_commit(event, irq_flags, pc); \ |
| 534 | } \ |
| 535 | \ |
| 536 | static int ftrace_raw_reg_event_##call(void) \ |
| 537 | { \ |
| 538 | int ret; \ |
| 539 | \ |
| 540 | ret = register_trace_##call(ftrace_raw_event_##call); \ |
| 541 | if (ret) \ |
| 542 | pr_info("event trace: Could not activate trace point " \ |
| 543 | "probe to " #call "\n"); \ |
| 544 | return ret; \ |
| 545 | } \ |
| 546 | \ |
| 547 | static void ftrace_raw_unreg_event_##call(void) \ |
| 548 | { \ |
| 549 | unregister_trace_##call(ftrace_raw_event_##call); \ |
| 550 | } \ |
| 551 | \ |
| 552 | static struct trace_event ftrace_event_type_##call = { \ |
| 553 | .trace = ftrace_raw_output_##call, \ |
| 554 | }; \ |
| 555 | \ |
| 556 | static int ftrace_raw_init_event_##call(void) \ |
| 557 | { \ |
| 558 | int id; \ |
| 559 | \ |
| 560 | id = register_ftrace_event(&ftrace_event_type_##call); \ |
| 561 | if (!id) \ |
| 562 | return -ENODEV; \ |
| 563 | event_##call.id = id; \ |
| 564 | INIT_LIST_HEAD(&event_##call.fields); \ |
| 565 | init_preds(&event_##call); \ |
| 566 | return 0; \ |
| 567 | } \ |
| 568 | \ |
| 569 | static struct ftrace_event_call __used \ |
| 570 | __attribute__((__aligned__(4))) \ |
| 571 | __attribute__((section("_ftrace_events"))) event_##call = { \ |
| 572 | .name = #call, \ |
| 573 | .system = __stringify(TRACE_SYSTEM), \ |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 574 | .event = &ftrace_event_type_##call, \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 575 | .raw_init = ftrace_raw_init_event_##call, \ |
| 576 | .regfunc = ftrace_raw_reg_event_##call, \ |
| 577 | .unregfunc = ftrace_raw_unreg_event_##call, \ |
| 578 | .show_format = ftrace_format_##call, \ |
| 579 | .define_fields = ftrace_define_fields_##call, \ |
| 580 | _TRACE_PROFILE_INIT(call) \ |
| 581 | } |
| 582 | |
| 583 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 584 | |
| 585 | #undef _TRACE_PROFILE |
| 586 | #undef _TRACE_PROFILE_INIT |
| 587 | |