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