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