Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Stage 1 of the trace events. |
| 4 | * |
Hou Pengyang | eba12ab | 2015-03-03 21:48:18 +0000 | [diff] [blame] | 5 | * Override the macros in the event tracepoint header <trace/events/XXX.h> |
| 6 | * to include the following: |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 7 | * |
Steven Rostedt (Red Hat) | a723776 | 2015-05-13 15:27:47 -0400 | [diff] [blame] | 8 | * struct trace_event_raw_<call> { |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 9 | * struct trace_entry ent; |
| 10 | * <type> <item>; |
| 11 | * <type2> <item2>[<len>]; |
| 12 | * [...] |
| 13 | * }; |
| 14 | * |
| 15 | * The <type> <item> is created by the __field(type, item) macro or |
| 16 | * the __array(type2, item2, len) macro. |
| 17 | * We simply do "type item;", and that will create the fields |
| 18 | * in the structure. |
| 19 | */ |
| 20 | |
Steven Rostedt (Red Hat) | af658dc | 2015-04-29 14:36:05 -0400 | [diff] [blame] | 21 | #include <linux/trace_events.h> |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 22 | |
Steven Rostedt (Red Hat) | acd388f | 2015-03-31 14:37:12 -0400 | [diff] [blame] | 23 | #ifndef TRACE_SYSTEM_VAR |
| 24 | #define TRACE_SYSTEM_VAR TRACE_SYSTEM |
| 25 | #endif |
| 26 | |
| 27 | #define __app__(x, y) str__##x##y |
| 28 | #define __app(x, y) __app__(x, y) |
| 29 | |
| 30 | #define TRACE_SYSTEM_STRING __app(TRACE_SYSTEM_VAR,__trace_system_name) |
| 31 | |
| 32 | #define TRACE_MAKE_SYSTEM_STR() \ |
| 33 | static const char TRACE_SYSTEM_STRING[] = \ |
| 34 | __stringify(TRACE_SYSTEM) |
| 35 | |
| 36 | TRACE_MAKE_SYSTEM_STR(); |
| 37 | |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 38 | #undef TRACE_DEFINE_ENUM |
| 39 | #define TRACE_DEFINE_ENUM(a) \ |
Jeremy Linton | 00f4b65 | 2017-05-31 16:56:43 -0500 | [diff] [blame] | 40 | static struct trace_eval_map __used __initdata \ |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 41 | __##TRACE_SYSTEM##_##a = \ |
| 42 | { \ |
| 43 | .system = TRACE_SYSTEM_STRING, \ |
Jeremy Linton | 00f4b65 | 2017-05-31 16:56:43 -0500 | [diff] [blame] | 44 | .eval_string = #a, \ |
| 45 | .eval_value = a \ |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 46 | }; \ |
Jeremy Linton | 00f4b65 | 2017-05-31 16:56:43 -0500 | [diff] [blame] | 47 | static struct trace_eval_map __used \ |
Joe Perches | 33def84 | 2020-10-21 19:36:07 -0700 | [diff] [blame] | 48 | __section("_ftrace_eval_map") \ |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 49 | *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a |
| 50 | |
Jeremy Linton | 4f0dfd7 | 2017-05-31 16:56:50 -0500 | [diff] [blame] | 51 | #undef TRACE_DEFINE_SIZEOF |
| 52 | #define TRACE_DEFINE_SIZEOF(a) \ |
| 53 | static struct trace_eval_map __used __initdata \ |
| 54 | __##TRACE_SYSTEM##_##a = \ |
| 55 | { \ |
| 56 | .system = TRACE_SYSTEM_STRING, \ |
| 57 | .eval_string = "sizeof(" #a ")", \ |
| 58 | .eval_value = sizeof(a) \ |
| 59 | }; \ |
| 60 | static struct trace_eval_map __used \ |
Joe Perches | 33def84 | 2020-10-21 19:36:07 -0700 | [diff] [blame] | 61 | __section("_ftrace_eval_map") \ |
Jeremy Linton | 4f0dfd7 | 2017-05-31 16:56:50 -0500 | [diff] [blame] | 62 | *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a |
| 63 | |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 64 | /* |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 65 | * DECLARE_EVENT_CLASS can be used to add a generic function |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 66 | * handlers for events. That is, if all events have the same |
| 67 | * parameters and just have distinct trace points. |
| 68 | * Each tracepoint can be defined with DEFINE_EVENT and that |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 69 | * will map the DECLARE_EVENT_CLASS to the tracepoint. |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 70 | * |
| 71 | * TRACE_EVENT is a one to one mapping between tracepoint and template. |
| 72 | */ |
| 73 | #undef TRACE_EVENT |
| 74 | #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 75 | DECLARE_EVENT_CLASS(name, \ |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 76 | PARAMS(proto), \ |
| 77 | PARAMS(args), \ |
| 78 | PARAMS(tstruct), \ |
| 79 | PARAMS(assign), \ |
| 80 | PARAMS(print)); \ |
| 81 | DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)); |
| 82 | |
| 83 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 84 | #undef __field |
| 85 | #define __field(type, item) type item; |
| 86 | |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 87 | #undef __field_ext |
| 88 | #define __field_ext(type, item, filter_type) type item; |
| 89 | |
Steven Rostedt | 4d4c9cc | 2014-06-17 08:59:16 -0400 | [diff] [blame] | 90 | #undef __field_struct |
| 91 | #define __field_struct(type, item) type item; |
| 92 | |
| 93 | #undef __field_struct_ext |
| 94 | #define __field_struct_ext(type, item, filter_type) type item; |
| 95 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 96 | #undef __array |
| 97 | #define __array(type, item, len) type item[len]; |
| 98 | |
| 99 | #undef __dynamic_array |
Li Zefan | 7d536cb | 2009-07-16 10:54:02 +0800 | [diff] [blame] | 100 | #define __dynamic_array(type, item, len) u32 __data_loc_##item; |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 101 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 102 | #undef __string |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 103 | #define __string(item, src) __dynamic_array(char, item, -1) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 104 | |
Steven Rostedt (VMware) | 883b4ae | 2021-07-16 20:55:10 -0400 | [diff] [blame] | 105 | #undef __string_len |
| 106 | #define __string_len(item, src, len) __dynamic_array(char, item, -1) |
| 107 | |
Steven Rostedt (Red Hat) | 4449bf9 | 2014-05-06 13:10:24 -0400 | [diff] [blame] | 108 | #undef __bitmask |
| 109 | #define __bitmask(item, nr_bits) __dynamic_array(char, item, -1) |
| 110 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 111 | #undef TP_STRUCT__entry |
| 112 | #define TP_STRUCT__entry(args...) args |
| 113 | |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 114 | #undef DECLARE_EVENT_CLASS |
| 115 | #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \ |
Steven Rostedt (Red Hat) | a723776 | 2015-05-13 15:27:47 -0400 | [diff] [blame] | 116 | struct trace_event_raw_##name { \ |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 117 | struct trace_entry ent; \ |
| 118 | tstruct \ |
| 119 | char __data[0]; \ |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 120 | }; \ |
| 121 | \ |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 122 | static struct trace_event_class event_class_##name; |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 123 | |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 124 | #undef DEFINE_EVENT |
| 125 | #define DEFINE_EVENT(template, name, proto, args) \ |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 126 | static struct trace_event_call __used \ |
Jeff Mahoney | 86c38a3 | 2010-02-24 13:59:23 -0500 | [diff] [blame] | 127 | __attribute__((__aligned__(4))) event_##name |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 128 | |
Steven Rostedt | f5abaa1 | 2013-06-20 11:44:44 -0400 | [diff] [blame] | 129 | #undef DEFINE_EVENT_FN |
| 130 | #define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg) \ |
| 131 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 132 | |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 133 | #undef DEFINE_EVENT_PRINT |
| 134 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 135 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 136 | |
Josh Stone | 9741987 | 2009-08-24 14:43:13 -0700 | [diff] [blame] | 137 | /* Callbacks are meaningless to ftrace. */ |
| 138 | #undef TRACE_EVENT_FN |
Frederic Weisbecker | 0dd7b74 | 2009-08-28 00:50:06 +0200 | [diff] [blame] | 139 | #define TRACE_EVENT_FN(name, proto, args, tstruct, \ |
| 140 | assign, print, reg, unreg) \ |
Frederic Weisbecker | 819ce45 | 2010-07-20 18:41:24 +0200 | [diff] [blame] | 141 | TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \ |
| 142 | PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ |
Josh Stone | 9741987 | 2009-08-24 14:43:13 -0700 | [diff] [blame] | 143 | |
Denis Kirjanov | 2701121 | 2015-12-14 23:18:05 +0300 | [diff] [blame] | 144 | #undef TRACE_EVENT_FN_COND |
| 145 | #define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct, \ |
| 146 | assign, print, reg, unreg) \ |
| 147 | TRACE_EVENT_CONDITION(name, PARAMS(proto), PARAMS(args), PARAMS(cond), \ |
| 148 | PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ |
| 149 | |
Frederic Weisbecker | 1ed0c59 | 2010-11-18 01:46:57 +0100 | [diff] [blame] | 150 | #undef TRACE_EVENT_FLAGS |
| 151 | #define TRACE_EVENT_FLAGS(name, value) \ |
Frederic Weisbecker | 53cf810b | 2010-11-18 02:11:42 +0100 | [diff] [blame] | 152 | __TRACE_EVENT_FLAGS(name, value) |
Frederic Weisbecker | 1ed0c59 | 2010-11-18 01:46:57 +0100 | [diff] [blame] | 153 | |
Peter Zijlstra | d5b5f39 | 2013-11-14 16:23:04 +0100 | [diff] [blame] | 154 | #undef TRACE_EVENT_PERF_PERM |
| 155 | #define TRACE_EVENT_PERF_PERM(name, expr...) \ |
| 156 | __TRACE_EVENT_PERF_PERM(name, expr) |
| 157 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 158 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 159 | |
| 160 | /* |
| 161 | * Stage 2 of the trace events. |
| 162 | * |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 163 | * Include the following: |
| 164 | * |
Steven Rostedt (Red Hat) | 62323a1 | 2015-05-13 15:33:52 -0400 | [diff] [blame] | 165 | * struct trace_event_data_offsets_<call> { |
Li Zefan | 7d536cb | 2009-07-16 10:54:02 +0800 | [diff] [blame] | 166 | * u32 <item1>; |
| 167 | * u32 <item2>; |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 168 | * [...] |
| 169 | * }; |
| 170 | * |
Li Zefan | 7d536cb | 2009-07-16 10:54:02 +0800 | [diff] [blame] | 171 | * The __dynamic_array() macro will create each u32 <item>, this is |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 172 | * 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] | 173 | * 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] | 174 | */ |
| 175 | |
Steven Rostedt (Red Hat) | 0c564a5 | 2015-03-24 17:58:09 -0400 | [diff] [blame] | 176 | #undef TRACE_DEFINE_ENUM |
| 177 | #define TRACE_DEFINE_ENUM(a) |
| 178 | |
Jeremy Linton | 4f0dfd7 | 2017-05-31 16:56:50 -0500 | [diff] [blame] | 179 | #undef TRACE_DEFINE_SIZEOF |
| 180 | #define TRACE_DEFINE_SIZEOF(a) |
| 181 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 182 | #undef __field |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 183 | #define __field(type, item) |
| 184 | |
| 185 | #undef __field_ext |
| 186 | #define __field_ext(type, item, filter_type) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 187 | |
Steven Rostedt | 4d4c9cc | 2014-06-17 08:59:16 -0400 | [diff] [blame] | 188 | #undef __field_struct |
| 189 | #define __field_struct(type, item) |
| 190 | |
| 191 | #undef __field_struct_ext |
| 192 | #define __field_struct_ext(type, item, filter_type) |
| 193 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 194 | #undef __array |
| 195 | #define __array(type, item, len) |
| 196 | |
| 197 | #undef __dynamic_array |
Li Zefan | 7d536cb | 2009-07-16 10:54:02 +0800 | [diff] [blame] | 198 | #define __dynamic_array(type, item, len) u32 item; |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 199 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 200 | #undef __string |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 201 | #define __string(item, src) __dynamic_array(char, item, -1) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 202 | |
Steven Rostedt (VMware) | 883b4ae | 2021-07-16 20:55:10 -0400 | [diff] [blame] | 203 | #undef __string_len |
| 204 | #define __string_len(item, src, len) __dynamic_array(char, item, -1) |
| 205 | |
Steven Rostedt (Red Hat) | 4449bf9 | 2014-05-06 13:10:24 -0400 | [diff] [blame] | 206 | #undef __bitmask |
| 207 | #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1) |
| 208 | |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 209 | #undef DECLARE_EVENT_CLASS |
| 210 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
Steven Rostedt (Red Hat) | 62323a1 | 2015-05-13 15:33:52 -0400 | [diff] [blame] | 211 | struct trace_event_data_offsets_##call { \ |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 212 | tstruct; \ |
| 213 | }; |
| 214 | |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 215 | #undef DEFINE_EVENT |
| 216 | #define DEFINE_EVENT(template, name, proto, args) |
| 217 | |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 218 | #undef DEFINE_EVENT_PRINT |
Wei Yang | 61df16f | 2020-06-12 17:28:43 +0800 | [diff] [blame] | 219 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 220 | |
Frederic Weisbecker | 1ed0c59 | 2010-11-18 01:46:57 +0100 | [diff] [blame] | 221 | #undef TRACE_EVENT_FLAGS |
| 222 | #define TRACE_EVENT_FLAGS(event, flag) |
| 223 | |
Peter Zijlstra | d5b5f39 | 2013-11-14 16:23:04 +0100 | [diff] [blame] | 224 | #undef TRACE_EVENT_PERF_PERM |
| 225 | #define TRACE_EVENT_PERF_PERM(event, expr...) |
| 226 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 227 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 228 | |
| 229 | /* |
| 230 | * Stage 3 of the trace events. |
| 231 | * |
Hou Pengyang | eba12ab | 2015-03-03 21:48:18 +0000 | [diff] [blame] | 232 | * Override the macros in the event tracepoint header <trace/events/XXX.h> |
| 233 | * to include the following: |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 234 | * |
| 235 | * enum print_line_t |
Steven Rostedt (Red Hat) | 892c505 | 2015-05-05 14:18:11 -0400 | [diff] [blame] | 236 | * trace_raw_output_<call>(struct trace_iterator *iter, int flags) |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 237 | * { |
| 238 | * struct trace_seq *s = &iter->seq; |
Steven Rostedt (Red Hat) | a723776 | 2015-05-13 15:27:47 -0400 | [diff] [blame] | 239 | * struct trace_event_raw_<call> *field; <-- defined in stage 1 |
Lai Jiangshan | bc289ae | 2010-06-03 18:26:24 +0800 | [diff] [blame] | 240 | * struct trace_seq *p = &iter->tmp_seq; |
Masami Hiramatsu | 1600cbc | 2020-10-15 23:55:16 +0900 | [diff] [blame] | 241 | * |
| 242 | * -------(for event)------- |
| 243 | * |
| 244 | * struct trace_entry *entry; |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 245 | * |
| 246 | * entry = iter->ent; |
| 247 | * |
Steven Rostedt | 32c0eda | 2010-04-23 10:38:03 -0400 | [diff] [blame] | 248 | * if (entry->type != event_<call>->event.type) { |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 249 | * WARN_ON_ONCE(1); |
| 250 | * return TRACE_TYPE_UNHANDLED; |
| 251 | * } |
| 252 | * |
| 253 | * field = (typeof(field))entry; |
| 254 | * |
Steven Whitehouse | 56d8bd3 | 2009-06-03 14:52:03 +0100 | [diff] [blame] | 255 | * trace_seq_init(p); |
Masami Hiramatsu | 1600cbc | 2020-10-15 23:55:16 +0900 | [diff] [blame] | 256 | * return trace_output_call(iter, <call>, <TP_printk> "\n"); |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 257 | * |
Masami Hiramatsu | 1600cbc | 2020-10-15 23:55:16 +0900 | [diff] [blame] | 258 | * ------(or, for event class)------ |
| 259 | * |
| 260 | * int ret; |
| 261 | * |
| 262 | * field = (typeof(field))iter->ent; |
| 263 | * |
| 264 | * ret = trace_raw_output_prep(iter, trace_event); |
| 265 | * if (ret != TRACE_TYPE_HANDLED) |
| 266 | * return ret; |
| 267 | * |
| 268 | * trace_event_printf(iter, <TP_printk> "\n"); |
| 269 | * |
| 270 | * return trace_handle_return(s); |
| 271 | * ------- |
| 272 | * } |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 273 | * |
| 274 | * This is the method used to print the raw event to the trace |
| 275 | * output format. Note, this is not needed if the data is read |
| 276 | * in binary. |
| 277 | */ |
| 278 | |
| 279 | #undef __entry |
| 280 | #define __entry field |
| 281 | |
| 282 | #undef TP_printk |
| 283 | #define TP_printk(fmt, args...) fmt "\n", args |
| 284 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 285 | #undef __get_dynamic_array |
| 286 | #define __get_dynamic_array(field) \ |
Li Zefan | 7d536cb | 2009-07-16 10:54:02 +0800 | [diff] [blame] | 287 | ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 288 | |
Steven Rostedt (Red Hat) | beba4bb | 2014-06-04 14:29:33 -0400 | [diff] [blame] | 289 | #undef __get_dynamic_array_len |
| 290 | #define __get_dynamic_array_len(field) \ |
| 291 | ((__entry->__data_loc_##field >> 16) & 0xffff) |
| 292 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 293 | #undef __get_str |
Daniel Bristot de Oliveira | 934de5f | 2016-07-01 20:44:34 -0300 | [diff] [blame] | 294 | #define __get_str(field) ((char *)__get_dynamic_array(field)) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 295 | |
Steven Rostedt (Red Hat) | 4449bf9 | 2014-05-06 13:10:24 -0400 | [diff] [blame] | 296 | #undef __get_bitmask |
| 297 | #define __get_bitmask(field) \ |
| 298 | ({ \ |
| 299 | void *__bitmask = __get_dynamic_array(field); \ |
| 300 | unsigned int __bitmask_size; \ |
Steven Rostedt (Red Hat) | beba4bb | 2014-06-04 14:29:33 -0400 | [diff] [blame] | 301 | __bitmask_size = __get_dynamic_array_len(field); \ |
Steven Rostedt (Red Hat) | 645df98 | 2015-05-04 18:12:44 -0400 | [diff] [blame] | 302 | trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \ |
Steven Rostedt (Red Hat) | 4449bf9 | 2014-05-06 13:10:24 -0400 | [diff] [blame] | 303 | }) |
| 304 | |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 305 | #undef __print_flags |
| 306 | #define __print_flags(flag, delim, flag_array...) \ |
| 307 | ({ \ |
Steven Rostedt | a48f494 | 2009-09-14 11:18:02 -0400 | [diff] [blame] | 308 | static const struct trace_print_flags __flags[] = \ |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 309 | { flag_array, { -1, NULL }}; \ |
Steven Rostedt (Red Hat) | 645df98 | 2015-05-04 18:12:44 -0400 | [diff] [blame] | 310 | trace_print_flags_seq(p, delim, flag, __flags); \ |
Steven Rostedt | be74b73 | 2009-05-26 20:25:22 +0200 | [diff] [blame] | 311 | }) |
| 312 | |
Steven Rostedt | 0f4fc29 | 2009-05-20 19:21:47 -0400 | [diff] [blame] | 313 | #undef __print_symbolic |
| 314 | #define __print_symbolic(value, symbol_array...) \ |
| 315 | ({ \ |
| 316 | static const struct trace_print_flags symbols[] = \ |
| 317 | { symbol_array, { -1, NULL }}; \ |
Steven Rostedt (Red Hat) | 645df98 | 2015-05-04 18:12:44 -0400 | [diff] [blame] | 318 | trace_print_symbols_seq(p, value, symbols); \ |
Steven Rostedt | 0f4fc29 | 2009-05-20 19:21:47 -0400 | [diff] [blame] | 319 | }) |
| 320 | |
Ross Zwisler | d3213e8 | 2017-02-22 15:39:47 -0800 | [diff] [blame] | 321 | #undef __print_flags_u64 |
liubo | 2fc1b6f | 2011-04-19 09:35:28 +0800 | [diff] [blame] | 322 | #undef __print_symbolic_u64 |
| 323 | #if BITS_PER_LONG == 32 |
Ross Zwisler | d3213e8 | 2017-02-22 15:39:47 -0800 | [diff] [blame] | 324 | #define __print_flags_u64(flag, delim, flag_array...) \ |
| 325 | ({ \ |
| 326 | static const struct trace_print_flags_u64 __flags[] = \ |
| 327 | { flag_array, { -1, NULL } }; \ |
| 328 | trace_print_flags_seq_u64(p, delim, flag, __flags); \ |
| 329 | }) |
| 330 | |
liubo | 2fc1b6f | 2011-04-19 09:35:28 +0800 | [diff] [blame] | 331 | #define __print_symbolic_u64(value, symbol_array...) \ |
| 332 | ({ \ |
| 333 | static const struct trace_print_flags_u64 symbols[] = \ |
| 334 | { symbol_array, { -1, NULL } }; \ |
Steven Rostedt (Red Hat) | 645df98 | 2015-05-04 18:12:44 -0400 | [diff] [blame] | 335 | trace_print_symbols_seq_u64(p, value, symbols); \ |
liubo | 2fc1b6f | 2011-04-19 09:35:28 +0800 | [diff] [blame] | 336 | }) |
| 337 | #else |
Ross Zwisler | d3213e8 | 2017-02-22 15:39:47 -0800 | [diff] [blame] | 338 | #define __print_flags_u64(flag, delim, flag_array...) \ |
| 339 | __print_flags(flag, delim, flag_array) |
| 340 | |
liubo | 2fc1b6f | 2011-04-19 09:35:28 +0800 | [diff] [blame] | 341 | #define __print_symbolic_u64(value, symbol_array...) \ |
| 342 | __print_symbolic(value, symbol_array) |
| 343 | #endif |
| 344 | |
Kei Tokunaga | 5a2e399 | 2010-04-01 20:40:58 +0900 | [diff] [blame] | 345 | #undef __print_hex |
Daniel Borkmann | 2acae0d | 2017-01-25 02:28:16 +0100 | [diff] [blame] | 346 | #define __print_hex(buf, buf_len) \ |
Daniel Borkmann | 3898fac | 2017-02-02 17:09:54 +0100 | [diff] [blame] | 347 | trace_print_hex_seq(p, buf, buf_len, false) |
Daniel Borkmann | 2acae0d | 2017-01-25 02:28:16 +0100 | [diff] [blame] | 348 | |
| 349 | #undef __print_hex_str |
| 350 | #define __print_hex_str(buf, buf_len) \ |
Daniel Borkmann | 3898fac | 2017-02-02 17:09:54 +0100 | [diff] [blame] | 351 | trace_print_hex_seq(p, buf, buf_len, true) |
Kei Tokunaga | 5a2e399 | 2010-04-01 20:40:58 +0900 | [diff] [blame] | 352 | |
Dave Martin | 6ea2248 | 2015-01-28 12:48:53 +0000 | [diff] [blame] | 353 | #undef __print_array |
| 354 | #define __print_array(array, count, el_size) \ |
| 355 | ({ \ |
| 356 | BUILD_BUG_ON(el_size != 1 && el_size != 2 && \ |
| 357 | el_size != 4 && el_size != 8); \ |
Steven Rostedt (Red Hat) | 645df98 | 2015-05-04 18:12:44 -0400 | [diff] [blame] | 358 | trace_print_array_seq(p, array, count, el_size); \ |
Dave Martin | 6ea2248 | 2015-01-28 12:48:53 +0000 | [diff] [blame] | 359 | }) |
| 360 | |
Piotr Maziarz | ef56e04 | 2019-11-07 13:45:38 +0100 | [diff] [blame] | 361 | #undef __print_hex_dump |
| 362 | #define __print_hex_dump(prefix_str, prefix_type, \ |
| 363 | rowsize, groupsize, buf, len, ascii) \ |
| 364 | trace_print_hex_dump_seq(p, prefix_str, prefix_type, \ |
| 365 | rowsize, groupsize, buf, len, ascii) |
| 366 | |
Steven Rostedt | 62de4f2 | 2021-06-22 16:42:26 +0200 | [diff] [blame] | 367 | #undef __print_ns_to_secs |
| 368 | #define __print_ns_to_secs(value) \ |
| 369 | ({ \ |
| 370 | u64 ____val = (u64)(value); \ |
| 371 | do_div(____val, NSEC_PER_SEC); \ |
| 372 | ____val; \ |
| 373 | }) |
| 374 | |
| 375 | #undef __print_ns_without_secs |
| 376 | #define __print_ns_without_secs(value) \ |
| 377 | ({ \ |
| 378 | u64 ____val = (u64)(value); \ |
| 379 | (u32) do_div(____val, NSEC_PER_SEC); \ |
| 380 | }) |
| 381 | |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 382 | #undef DECLARE_EVENT_CLASS |
| 383 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
Steven Rostedt | 83f0d53 | 2010-02-16 10:38:47 -0500 | [diff] [blame] | 384 | static notrace enum print_line_t \ |
Steven Rostedt (Red Hat) | 892c505 | 2015-05-05 14:18:11 -0400 | [diff] [blame] | 385 | trace_raw_output_##call(struct trace_iterator *iter, int flags, \ |
| 386 | struct trace_event *trace_event) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 387 | { \ |
| 388 | struct trace_seq *s = &iter->seq; \ |
Li Zefan | f71130d | 2013-02-21 10:32:38 +0800 | [diff] [blame] | 389 | struct trace_seq __maybe_unused *p = &iter->tmp_seq; \ |
Steven Rostedt (Red Hat) | a723776 | 2015-05-13 15:27:47 -0400 | [diff] [blame] | 390 | struct trace_event_raw_##call *field; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 391 | int ret; \ |
| 392 | \ |
Li Zefan | f71130d | 2013-02-21 10:32:38 +0800 | [diff] [blame] | 393 | field = (typeof(field))iter->ent; \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 394 | \ |
Steven Rostedt (Red Hat) | 892c505 | 2015-05-05 14:18:11 -0400 | [diff] [blame] | 395 | ret = trace_raw_output_prep(iter, trace_event); \ |
Steven Rostedt (Red Hat) | 8e2e095 | 2014-11-14 11:42:06 -0500 | [diff] [blame] | 396 | if (ret != TRACE_TYPE_HANDLED) \ |
Li Zefan | f71130d | 2013-02-21 10:32:38 +0800 | [diff] [blame] | 397 | return ret; \ |
| 398 | \ |
Masami Hiramatsu | efbbdaa | 2020-10-15 23:55:07 +0900 | [diff] [blame] | 399 | trace_event_printf(iter, print); \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 400 | \ |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 401 | return trace_handle_return(s); \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 402 | } \ |
Steven Rostedt (Red Hat) | 3ad017b | 2015-05-13 15:35:44 -0400 | [diff] [blame] | 403 | static struct trace_event_functions trace_event_type_funcs_##call = { \ |
Steven Rostedt (Red Hat) | 892c505 | 2015-05-05 14:18:11 -0400 | [diff] [blame] | 404 | .trace = trace_raw_output_##call, \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 405 | }; |
Steven Rostedt | ff038f5 | 2009-11-18 20:27:27 -0500 | [diff] [blame] | 406 | |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 407 | #undef DEFINE_EVENT_PRINT |
| 408 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ |
Steven Rostedt | 83f0d53 | 2010-02-16 10:38:47 -0500 | [diff] [blame] | 409 | static notrace enum print_line_t \ |
Steven Rostedt (Red Hat) | 892c505 | 2015-05-05 14:18:11 -0400 | [diff] [blame] | 410 | trace_raw_output_##call(struct trace_iterator *iter, int flags, \ |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 411 | struct trace_event *event) \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 412 | { \ |
Steven Rostedt (Red Hat) | a723776 | 2015-05-13 15:27:47 -0400 | [diff] [blame] | 413 | struct trace_event_raw_##template *field; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 414 | struct trace_entry *entry; \ |
Lai Jiangshan | bc289ae | 2010-06-03 18:26:24 +0800 | [diff] [blame] | 415 | struct trace_seq *p = &iter->tmp_seq; \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 416 | \ |
| 417 | entry = iter->ent; \ |
| 418 | \ |
Steven Rostedt | 32c0eda | 2010-04-23 10:38:03 -0400 | [diff] [blame] | 419 | if (entry->type != event_##call.event.type) { \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 420 | WARN_ON_ONCE(1); \ |
| 421 | return TRACE_TYPE_UNHANDLED; \ |
| 422 | } \ |
| 423 | \ |
| 424 | field = (typeof(field))entry; \ |
| 425 | \ |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 426 | trace_seq_init(p); \ |
Steven Rostedt (Red Hat) | 892c505 | 2015-05-05 14:18:11 -0400 | [diff] [blame] | 427 | return trace_output_call(iter, #call, print); \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 428 | } \ |
Steven Rostedt (Red Hat) | 3ad017b | 2015-05-13 15:35:44 -0400 | [diff] [blame] | 429 | static struct trace_event_functions trace_event_type_funcs_##call = { \ |
Steven Rostedt (Red Hat) | 892c505 | 2015-05-05 14:18:11 -0400 | [diff] [blame] | 430 | .trace = trace_raw_output_##call, \ |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 431 | }; |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 432 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 433 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 434 | |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 435 | #undef __field_ext |
Peter Zijlstra | 04ae87a | 2019-10-24 22:26:59 +0200 | [diff] [blame] | 436 | #define __field_ext(_type, _item, _filter_type) { \ |
| 437 | .type = #_type, .name = #_item, \ |
| 438 | .size = sizeof(_type), .align = __alignof__(_type), \ |
| 439 | .is_signed = is_signed_type(_type), .filter_type = _filter_type }, |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 440 | |
Steven Rostedt | 4d4c9cc | 2014-06-17 08:59:16 -0400 | [diff] [blame] | 441 | #undef __field_struct_ext |
Peter Zijlstra | 04ae87a | 2019-10-24 22:26:59 +0200 | [diff] [blame] | 442 | #define __field_struct_ext(_type, _item, _filter_type) { \ |
| 443 | .type = #_type, .name = #_item, \ |
| 444 | .size = sizeof(_type), .align = __alignof__(_type), \ |
| 445 | 0, .filter_type = _filter_type }, |
Steven Rostedt | 4d4c9cc | 2014-06-17 08:59:16 -0400 | [diff] [blame] | 446 | |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 447 | #undef __field |
| 448 | #define __field(type, item) __field_ext(type, item, FILTER_OTHER) |
| 449 | |
Steven Rostedt | 4d4c9cc | 2014-06-17 08:59:16 -0400 | [diff] [blame] | 450 | #undef __field_struct |
| 451 | #define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER) |
| 452 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 453 | #undef __array |
Peter Zijlstra | 04ae87a | 2019-10-24 22:26:59 +0200 | [diff] [blame] | 454 | #define __array(_type, _item, _len) { \ |
| 455 | .type = #_type"["__stringify(_len)"]", .name = #_item, \ |
| 456 | .size = sizeof(_type[_len]), .align = __alignof__(_type), \ |
| 457 | .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER }, |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 458 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 459 | #undef __dynamic_array |
Peter Zijlstra | 04ae87a | 2019-10-24 22:26:59 +0200 | [diff] [blame] | 460 | #define __dynamic_array(_type, _item, _len) { \ |
| 461 | .type = "__data_loc " #_type "[]", .name = #_item, \ |
| 462 | .size = 4, .align = 4, \ |
| 463 | .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER }, |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 464 | |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 465 | #undef __string |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 466 | #define __string(item, src) __dynamic_array(char, item, -1) |
Frederic Weisbecker | 9cbf117 | 2009-04-19 04:51:29 +0200 | [diff] [blame] | 467 | |
Steven Rostedt (VMware) | 883b4ae | 2021-07-16 20:55:10 -0400 | [diff] [blame] | 468 | #undef __string_len |
| 469 | #define __string_len(item, src, len) __dynamic_array(char, item, -1) |
| 470 | |
Steven Rostedt (Red Hat) | 4449bf9 | 2014-05-06 13:10:24 -0400 | [diff] [blame] | 471 | #undef __bitmask |
| 472 | #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1) |
| 473 | |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 474 | #undef DECLARE_EVENT_CLASS |
| 475 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \ |
Peter Zijlstra | 04ae87a | 2019-10-24 22:26:59 +0200 | [diff] [blame] | 476 | static struct trace_event_fields trace_event_fields_##call[] = { \ |
| 477 | tstruct \ |
| 478 | {} }; |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 479 | |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 480 | #undef DEFINE_EVENT_PRINT |
Wei Yang | 61df16f | 2020-06-12 17:28:43 +0800 | [diff] [blame] | 481 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) |
Steven Rostedt | e5bc972 | 2009-11-18 20:36:26 -0500 | [diff] [blame] | 482 | |
Steven Rostedt | f42c85e | 2009-04-13 12:25:37 -0400 | [diff] [blame] | 483 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 484 | |
| 485 | /* |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 486 | * remember the offset of each array from the beginning of the event. |
| 487 | */ |
| 488 | |
| 489 | #undef __entry |
| 490 | #define __entry entry |
| 491 | |
| 492 | #undef __field |
| 493 | #define __field(type, item) |
| 494 | |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 495 | #undef __field_ext |
| 496 | #define __field_ext(type, item, filter_type) |
| 497 | |
Steven Rostedt | 4d4c9cc | 2014-06-17 08:59:16 -0400 | [diff] [blame] | 498 | #undef __field_struct |
| 499 | #define __field_struct(type, item) |
| 500 | |
| 501 | #undef __field_struct_ext |
| 502 | #define __field_struct_ext(type, item, filter_type) |
| 503 | |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 504 | #undef __array |
| 505 | #define __array(type, item, len) |
| 506 | |
| 507 | #undef __dynamic_array |
| 508 | #define __dynamic_array(type, item, len) \ |
Filipe Brandenburger | 114e7b5 | 2014-02-28 21:32:17 -0800 | [diff] [blame] | 509 | __item_length = (len) * sizeof(type); \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 510 | __data_offsets->item = __data_size + \ |
| 511 | offsetof(typeof(*entry), __data); \ |
Filipe Brandenburger | 114e7b5 | 2014-02-28 21:32:17 -0800 | [diff] [blame] | 512 | __data_offsets->item |= __item_length << 16; \ |
| 513 | __data_size += __item_length; |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 514 | |
| 515 | #undef __string |
Steven Rostedt (Red Hat) | 4e58e54 | 2013-11-26 09:22:54 -0500 | [diff] [blame] | 516 | #define __string(item, src) __dynamic_array(char, item, \ |
| 517 | strlen((src) ? (const char *)(src) : "(null)") + 1) |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 518 | |
Steven Rostedt (VMware) | 883b4ae | 2021-07-16 20:55:10 -0400 | [diff] [blame] | 519 | #undef __string_len |
| 520 | #define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1) |
| 521 | |
Steven Rostedt (Red Hat) | 4449bf9 | 2014-05-06 13:10:24 -0400 | [diff] [blame] | 522 | /* |
| 523 | * __bitmask_size_in_bytes_raw is the number of bytes needed to hold |
| 524 | * num_possible_cpus(). |
| 525 | */ |
| 526 | #define __bitmask_size_in_bytes_raw(nr_bits) \ |
| 527 | (((nr_bits) + 7) / 8) |
| 528 | |
| 529 | #define __bitmask_size_in_longs(nr_bits) \ |
| 530 | ((__bitmask_size_in_bytes_raw(nr_bits) + \ |
| 531 | ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8)) |
| 532 | |
| 533 | /* |
| 534 | * __bitmask_size_in_bytes is the number of bytes needed to hold |
| 535 | * num_possible_cpus() padded out to the nearest long. This is what |
| 536 | * is saved in the buffer, just to be consistent. |
| 537 | */ |
| 538 | #define __bitmask_size_in_bytes(nr_bits) \ |
| 539 | (__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8)) |
| 540 | |
| 541 | #undef __bitmask |
| 542 | #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, \ |
| 543 | __bitmask_size_in_longs(nr_bits)) |
| 544 | |
Ingo Molnar | 091ad36 | 2009-11-26 09:04:55 +0100 | [diff] [blame] | 545 | #undef DECLARE_EVENT_CLASS |
| 546 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
Steven Rostedt (Red Hat) | d0ee8f4 | 2015-05-13 15:40:23 -0400 | [diff] [blame] | 547 | static inline notrace int trace_event_get_offsets_##call( \ |
Steven Rostedt (Red Hat) | 62323a1 | 2015-05-13 15:33:52 -0400 | [diff] [blame] | 548 | struct trace_event_data_offsets_##call *__data_offsets, proto) \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 549 | { \ |
| 550 | int __data_size = 0; \ |
Filipe Brandenburger | 114e7b5 | 2014-02-28 21:32:17 -0800 | [diff] [blame] | 551 | int __maybe_unused __item_length; \ |
Steven Rostedt (Red Hat) | a723776 | 2015-05-13 15:27:47 -0400 | [diff] [blame] | 552 | struct trace_event_raw_##call __maybe_unused *entry; \ |
Li Zefan | 7fcb7c4 | 2009-06-01 15:35:46 +0800 | [diff] [blame] | 553 | \ |
| 554 | tstruct; \ |
| 555 | \ |
| 556 | return __data_size; \ |
| 557 | } |
| 558 | |
| 559 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 560 | |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 561 | /* |
| 562 | * Stage 4 of the trace events. |
| 563 | * |
Hou Pengyang | eba12ab | 2015-03-03 21:48:18 +0000 | [diff] [blame] | 564 | * Override the macros in the event tracepoint header <trace/events/XXX.h> |
| 565 | * to include the following: |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 566 | * |
| 567 | * For those macros defined with TRACE_EVENT: |
| 568 | * |
| 569 | * static struct trace_event_call event_<call>; |
| 570 | * |
| 571 | * static void trace_event_raw_event_<call>(void *__data, proto) |
| 572 | * { |
| 573 | * struct trace_event_file *trace_file = __data; |
| 574 | * struct trace_event_call *event_call = trace_file->event_call; |
| 575 | * struct trace_event_data_offsets_<call> __maybe_unused __data_offsets; |
| 576 | * unsigned long eflags = trace_file->flags; |
| 577 | * enum event_trigger_type __tt = ETT_NONE; |
| 578 | * struct ring_buffer_event *event; |
| 579 | * struct trace_event_raw_<call> *entry; <-- defined in stage 1 |
Steven Rostedt (VMware) | 1329249 | 2019-12-13 13:58:57 -0500 | [diff] [blame] | 580 | * struct trace_buffer *buffer; |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 581 | * unsigned long irq_flags; |
| 582 | * int __data_size; |
| 583 | * int pc; |
| 584 | * |
| 585 | * if (!(eflags & EVENT_FILE_FL_TRIGGER_COND)) { |
| 586 | * if (eflags & EVENT_FILE_FL_TRIGGER_MODE) |
| 587 | * event_triggers_call(trace_file, NULL); |
| 588 | * if (eflags & EVENT_FILE_FL_SOFT_DISABLED) |
| 589 | * return; |
| 590 | * } |
| 591 | * |
| 592 | * local_save_flags(irq_flags); |
| 593 | * pc = preempt_count(); |
| 594 | * |
| 595 | * __data_size = trace_event_get_offsets_<call>(&__data_offsets, args); |
| 596 | * |
| 597 | * event = trace_event_buffer_lock_reserve(&buffer, trace_file, |
| 598 | * event_<call>->event.type, |
| 599 | * sizeof(*entry) + __data_size, |
| 600 | * irq_flags, pc); |
| 601 | * if (!event) |
| 602 | * return; |
| 603 | * entry = ring_buffer_event_data(event); |
| 604 | * |
| 605 | * { <assign>; } <-- Here we assign the entries by the __field and |
| 606 | * __array macros. |
| 607 | * |
| 608 | * if (eflags & EVENT_FILE_FL_TRIGGER_COND) |
| 609 | * __tt = event_triggers_call(trace_file, entry); |
| 610 | * |
| 611 | * if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, |
| 612 | * &trace_file->flags)) |
| 613 | * ring_buffer_discard_commit(buffer, event); |
| 614 | * else if (!filter_check_discard(trace_file, entry, buffer, event)) |
| 615 | * trace_buffer_unlock_commit(buffer, event, irq_flags, pc); |
| 616 | * |
| 617 | * if (__tt) |
| 618 | * event_triggers_post_call(trace_file, __tt); |
| 619 | * } |
| 620 | * |
| 621 | * static struct trace_event ftrace_event_type_<call> = { |
| 622 | * .trace = trace_raw_output_<call>, <-- stage 2 |
| 623 | * }; |
| 624 | * |
| 625 | * static char print_fmt_<call>[] = <TP_printk>; |
| 626 | * |
| 627 | * static struct trace_event_class __used event_class_<template> = { |
| 628 | * .system = "<system>", |
Peter Zijlstra | 04ae87a | 2019-10-24 22:26:59 +0200 | [diff] [blame] | 629 | * .fields_array = trace_event_fields_<call>, |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 630 | * .fields = LIST_HEAD_INIT(event_class_##call.fields), |
| 631 | * .raw_init = trace_event_raw_init, |
| 632 | * .probe = trace_event_raw_event_##call, |
| 633 | * .reg = trace_event_reg, |
| 634 | * }; |
| 635 | * |
| 636 | * static struct trace_event_call event_<call> = { |
| 637 | * .class = event_class_<template>, |
| 638 | * { |
| 639 | * .tp = &__tracepoint_<call>, |
| 640 | * }, |
| 641 | * .event = &ftrace_event_type_<call>, |
| 642 | * .print_fmt = print_fmt_<call>, |
| 643 | * .flags = TRACE_EVENT_FL_TRACEPOINT, |
| 644 | * }; |
| 645 | * // its only safe to use pointers when doing linker tricks to |
| 646 | * // create an array. |
| 647 | * static struct trace_event_call __used |
Joe Perches | 33def84 | 2020-10-21 19:36:07 -0700 | [diff] [blame] | 648 | * __section("_ftrace_events") *__event_<call> = &event_<call>; |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 649 | * |
| 650 | */ |
| 651 | |
| 652 | #ifdef CONFIG_PERF_EVENTS |
| 653 | |
| 654 | #define _TRACE_PERF_PROTO(call, proto) \ |
| 655 | static notrace void \ |
| 656 | perf_trace_##call(void *__data, proto); |
| 657 | |
| 658 | #define _TRACE_PERF_INIT(call) \ |
| 659 | .perf_probe = perf_trace_##call, |
| 660 | |
| 661 | #else |
| 662 | #define _TRACE_PERF_PROTO(call, proto) |
| 663 | #define _TRACE_PERF_INIT(call) |
| 664 | #endif /* CONFIG_PERF_EVENTS */ |
| 665 | |
| 666 | #undef __entry |
| 667 | #define __entry entry |
| 668 | |
| 669 | #undef __field |
| 670 | #define __field(type, item) |
| 671 | |
| 672 | #undef __field_struct |
| 673 | #define __field_struct(type, item) |
| 674 | |
| 675 | #undef __array |
| 676 | #define __array(type, item, len) |
| 677 | |
| 678 | #undef __dynamic_array |
| 679 | #define __dynamic_array(type, item, len) \ |
| 680 | __entry->__data_loc_##item = __data_offsets.item; |
| 681 | |
| 682 | #undef __string |
| 683 | #define __string(item, src) __dynamic_array(char, item, -1) |
| 684 | |
Steven Rostedt (VMware) | 883b4ae | 2021-07-16 20:55:10 -0400 | [diff] [blame] | 685 | #undef __string_len |
| 686 | #define __string_len(item, src, len) __dynamic_array(char, item, -1) |
| 687 | |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 688 | #undef __assign_str |
| 689 | #define __assign_str(dst, src) \ |
| 690 | strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)"); |
| 691 | |
Steven Rostedt (VMware) | 883b4ae | 2021-07-16 20:55:10 -0400 | [diff] [blame] | 692 | #undef __assign_str_len |
| 693 | #define __assign_str_len(dst, src, len) \ |
| 694 | do { \ |
| 695 | memcpy(__get_str(dst), (src), (len)); \ |
| 696 | __get_str(dst)[len] = '\0'; \ |
| 697 | } while(0) |
| 698 | |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 699 | #undef __bitmask |
| 700 | #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1) |
| 701 | |
| 702 | #undef __get_bitmask |
| 703 | #define __get_bitmask(field) (char *)__get_dynamic_array(field) |
| 704 | |
| 705 | #undef __assign_bitmask |
| 706 | #define __assign_bitmask(dst, src, nr_bits) \ |
| 707 | memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits)) |
| 708 | |
| 709 | #undef TP_fast_assign |
| 710 | #define TP_fast_assign(args...) args |
| 711 | |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 712 | #undef __perf_count |
| 713 | #define __perf_count(c) (c) |
| 714 | |
| 715 | #undef __perf_task |
| 716 | #define __perf_task(t) (t) |
| 717 | |
| 718 | #undef DECLARE_EVENT_CLASS |
| 719 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 720 | \ |
| 721 | static notrace void \ |
| 722 | trace_event_raw_event_##call(void *__data, proto) \ |
| 723 | { \ |
| 724 | struct trace_event_file *trace_file = __data; \ |
| 725 | struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\ |
| 726 | struct trace_event_buffer fbuffer; \ |
| 727 | struct trace_event_raw_##call *entry; \ |
| 728 | int __data_size; \ |
| 729 | \ |
| 730 | if (trace_trigger_soft_disabled(trace_file)) \ |
| 731 | return; \ |
| 732 | \ |
| 733 | __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \ |
| 734 | \ |
| 735 | entry = trace_event_buffer_reserve(&fbuffer, trace_file, \ |
| 736 | sizeof(*entry) + __data_size); \ |
| 737 | \ |
| 738 | if (!entry) \ |
| 739 | return; \ |
| 740 | \ |
| 741 | tstruct \ |
| 742 | \ |
| 743 | { assign; } \ |
| 744 | \ |
| 745 | trace_event_buffer_commit(&fbuffer); \ |
| 746 | } |
| 747 | /* |
| 748 | * The ftrace_test_probe is compiled out, it is only here as a build time check |
| 749 | * to make sure that if the tracepoint handling changes, the ftrace probe will |
| 750 | * fail to compile unless it too is updated. |
| 751 | */ |
| 752 | |
| 753 | #undef DEFINE_EVENT |
| 754 | #define DEFINE_EVENT(template, call, proto, args) \ |
| 755 | static inline void ftrace_test_probe_##call(void) \ |
| 756 | { \ |
| 757 | check_trace_callback_type_##call(trace_event_raw_event_##template); \ |
| 758 | } |
| 759 | |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 760 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 761 | |
| 762 | #undef __entry |
| 763 | #define __entry REC |
| 764 | |
| 765 | #undef __print_flags |
| 766 | #undef __print_symbolic |
| 767 | #undef __print_hex |
Daniel Borkmann | 2acae0d | 2017-01-25 02:28:16 +0100 | [diff] [blame] | 768 | #undef __print_hex_str |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 769 | #undef __get_dynamic_array |
| 770 | #undef __get_dynamic_array_len |
| 771 | #undef __get_str |
| 772 | #undef __get_bitmask |
| 773 | #undef __print_array |
Piotr Maziarz | 02a65a0 | 2019-11-26 11:06:31 +0100 | [diff] [blame] | 774 | #undef __print_hex_dump |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 775 | |
Steven Rostedt | 62de4f2 | 2021-06-22 16:42:26 +0200 | [diff] [blame] | 776 | /* |
| 777 | * The below is not executed in the kernel. It is only what is |
| 778 | * displayed in the print format for userspace to parse. |
| 779 | */ |
| 780 | #undef __print_ns_to_secs |
| 781 | #define __print_ns_to_secs(val) (val) / 1000000000UL |
| 782 | |
| 783 | #undef __print_ns_without_secs |
| 784 | #define __print_ns_without_secs(val) (val) % 1000000000UL |
| 785 | |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 786 | #undef TP_printk |
| 787 | #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args) |
| 788 | |
| 789 | #undef DECLARE_EVENT_CLASS |
| 790 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 791 | _TRACE_PERF_PROTO(call, PARAMS(proto)); \ |
| 792 | static char print_fmt_##call[] = print; \ |
| 793 | static struct trace_event_class __used __refdata event_class_##call = { \ |
| 794 | .system = TRACE_SYSTEM_STRING, \ |
Peter Zijlstra | 04ae87a | 2019-10-24 22:26:59 +0200 | [diff] [blame] | 795 | .fields_array = trace_event_fields_##call, \ |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 796 | .fields = LIST_HEAD_INIT(event_class_##call.fields),\ |
| 797 | .raw_init = trace_event_raw_init, \ |
| 798 | .probe = trace_event_raw_event_##call, \ |
| 799 | .reg = trace_event_reg, \ |
| 800 | _TRACE_PERF_INIT(call) \ |
| 801 | }; |
| 802 | |
| 803 | #undef DEFINE_EVENT |
| 804 | #define DEFINE_EVENT(template, call, proto, args) \ |
| 805 | \ |
| 806 | static struct trace_event_call __used event_##call = { \ |
| 807 | .class = &event_class_##template, \ |
| 808 | { \ |
| 809 | .tp = &__tracepoint_##call, \ |
| 810 | }, \ |
| 811 | .event.funcs = &trace_event_type_funcs_##template, \ |
| 812 | .print_fmt = print_fmt_##template, \ |
| 813 | .flags = TRACE_EVENT_FL_TRACEPOINT, \ |
| 814 | }; \ |
| 815 | static struct trace_event_call __used \ |
Joe Perches | 33def84 | 2020-10-21 19:36:07 -0700 | [diff] [blame] | 816 | __section("_ftrace_events") *__event_##call = &event_##call |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 817 | |
| 818 | #undef DEFINE_EVENT_PRINT |
| 819 | #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ |
| 820 | \ |
| 821 | static char print_fmt_##call[] = print; \ |
| 822 | \ |
| 823 | static struct trace_event_call __used event_##call = { \ |
| 824 | .class = &event_class_##template, \ |
| 825 | { \ |
| 826 | .tp = &__tracepoint_##call, \ |
| 827 | }, \ |
| 828 | .event.funcs = &trace_event_type_funcs_##call, \ |
| 829 | .print_fmt = print_fmt_##call, \ |
| 830 | .flags = TRACE_EVENT_FL_TRACEPOINT, \ |
| 831 | }; \ |
| 832 | static struct trace_event_call __used \ |
Joe Perches | 33def84 | 2020-10-21 19:36:07 -0700 | [diff] [blame] | 833 | __section("_ftrace_events") *__event_##call = &event_##call |
Steven Rostedt (Red Hat) | 46ac518 | 2015-09-23 09:26:27 -0400 | [diff] [blame] | 834 | |
| 835 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |