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