trace_events.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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 trace_event_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. #include <linux/trace_events.h>
  19. #ifndef TRACE_SYSTEM_VAR
  20. #define TRACE_SYSTEM_VAR TRACE_SYSTEM
  21. #endif
  22. #define __app__(x, y) str__##x##y
  23. #define __app(x, y) __app__(x, y)
  24. #define TRACE_SYSTEM_STRING __app(TRACE_SYSTEM_VAR,__trace_system_name)
  25. #define TRACE_MAKE_SYSTEM_STR() \
  26. static const char TRACE_SYSTEM_STRING[] = \
  27. __stringify(TRACE_SYSTEM)
  28. TRACE_MAKE_SYSTEM_STR();
  29. #undef TRACE_DEFINE_ENUM
  30. #define TRACE_DEFINE_ENUM(a) \
  31. static struct trace_eval_map __used __initdata \
  32. __##TRACE_SYSTEM##_##a = \
  33. { \
  34. .system = TRACE_SYSTEM_STRING, \
  35. .eval_string = #a, \
  36. .eval_value = a \
  37. }; \
  38. static struct trace_eval_map __used \
  39. __attribute__((section("_ftrace_eval_map"))) \
  40. *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
  41. /*
  42. * DECLARE_EVENT_CLASS can be used to add a generic function
  43. * handlers for events. That is, if all events have the same
  44. * parameters and just have distinct trace points.
  45. * Each tracepoint can be defined with DEFINE_EVENT and that
  46. * will map the DECLARE_EVENT_CLASS to the tracepoint.
  47. *
  48. * TRACE_EVENT is a one to one mapping between tracepoint and template.
  49. */
  50. #undef TRACE_EVENT
  51. #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
  52. DECLARE_EVENT_CLASS(name, \
  53. PARAMS(proto), \
  54. PARAMS(args), \
  55. PARAMS(tstruct), \
  56. PARAMS(assign), \
  57. PARAMS(print)); \
  58. DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
  59. #undef __field
  60. #define __field(type, item) type item;
  61. #undef __field_ext
  62. #define __field_ext(type, item, filter_type) type item;
  63. #undef __field_struct
  64. #define __field_struct(type, item) type item;
  65. #undef __field_struct_ext
  66. #define __field_struct_ext(type, item, filter_type) type item;
  67. #undef __array
  68. #define __array(type, item, len) type item[len];
  69. #undef __dynamic_array
  70. #define __dynamic_array(type, item, len) u32 __data_loc_##item;
  71. #undef __string
  72. #define __string(item, src) __dynamic_array(char, item, -1)
  73. #undef __bitmask
  74. #define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)
  75. #undef TP_STRUCT__entry
  76. #define TP_STRUCT__entry(args...) args
  77. #undef DECLARE_EVENT_CLASS
  78. #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
  79. struct trace_event_raw_##name { \
  80. struct trace_entry ent; \
  81. tstruct \
  82. char __data[0]; \
  83. }; \
  84. \
  85. static struct trace_event_class event_class_##name;
  86. #undef DEFINE_EVENT
  87. #define DEFINE_EVENT(template, name, proto, args) \
  88. static struct trace_event_call __used \
  89. __attribute__((__aligned__(4))) event_##name
  90. #undef DEFINE_EVENT_FN
  91. #define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg) \
  92. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  93. #undef DEFINE_EVENT_PRINT
  94. #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
  95. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  96. /* Callbacks are meaningless to ftrace. */
  97. #undef TRACE_EVENT_FN
  98. #define TRACE_EVENT_FN(name, proto, args, tstruct, \
  99. assign, print, reg, unreg) \
  100. TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
  101. PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
  102. #undef TRACE_EVENT_FN_COND
  103. #define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct, \
  104. assign, print, reg, unreg) \
  105. TRACE_EVENT_CONDITION(name, PARAMS(proto), PARAMS(args), PARAMS(cond), \
  106. PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
  107. #undef TRACE_EVENT_FLAGS
  108. #define TRACE_EVENT_FLAGS(name, value) \
  109. __TRACE_EVENT_FLAGS(name, value)
  110. #undef TRACE_EVENT_PERF_PERM
  111. #define TRACE_EVENT_PERF_PERM(name, expr...) \
  112. __TRACE_EVENT_PERF_PERM(name, expr)
  113. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  114. /*
  115. * Stage 2 of the trace events.
  116. *
  117. * Include the following:
  118. *
  119. * struct trace_event_data_offsets_<call> {
  120. * u32 <item1>;
  121. * u32 <item2>;
  122. * [...]
  123. * };
  124. *
  125. * The __dynamic_array() macro will create each u32 <item>, this is
  126. * to keep the offset of each array from the beginning of the event.
  127. * The size of an array is also encoded, in the higher 16 bits of <item>.
  128. */
  129. #undef TRACE_DEFINE_ENUM
  130. #define TRACE_DEFINE_ENUM(a)
  131. #undef __field
  132. #define __field(type, item)
  133. #undef __field_ext
  134. #define __field_ext(type, item, filter_type)
  135. #undef __field_struct
  136. #define __field_struct(type, item)
  137. #undef __field_struct_ext
  138. #define __field_struct_ext(type, item, filter_type)
  139. #undef __array
  140. #define __array(type, item, len)
  141. #undef __dynamic_array
  142. #define __dynamic_array(type, item, len) u32 item;
  143. #undef __string
  144. #define __string(item, src) __dynamic_array(char, item, -1)
  145. #undef __bitmask
  146. #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
  147. #undef DECLARE_EVENT_CLASS
  148. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  149. struct trace_event_data_offsets_##call { \
  150. tstruct; \
  151. };
  152. #undef DEFINE_EVENT
  153. #define DEFINE_EVENT(template, name, proto, args)
  154. #undef DEFINE_EVENT_PRINT
  155. #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
  156. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  157. #undef TRACE_EVENT_FLAGS
  158. #define TRACE_EVENT_FLAGS(event, flag)
  159. #undef TRACE_EVENT_PERF_PERM
  160. #define TRACE_EVENT_PERF_PERM(event, expr...)
  161. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  162. /*
  163. * Stage 3 of the trace events.
  164. *
  165. * Override the macros in <trace/trace_events.h> to include the following:
  166. *
  167. * enum print_line_t
  168. * trace_raw_output_<call>(struct trace_iterator *iter, int flags)
  169. * {
  170. * struct trace_seq *s = &iter->seq;
  171. * struct trace_event_raw_<call> *field; <-- defined in stage 1
  172. * struct trace_entry *entry;
  173. * struct trace_seq *p = &iter->tmp_seq;
  174. * int ret;
  175. *
  176. * entry = iter->ent;
  177. *
  178. * if (entry->type != event_<call>->event.type) {
  179. * WARN_ON_ONCE(1);
  180. * return TRACE_TYPE_UNHANDLED;
  181. * }
  182. *
  183. * field = (typeof(field))entry;
  184. *
  185. * trace_seq_init(p);
  186. * ret = trace_seq_printf(s, "%s: ", <call>);
  187. * if (ret)
  188. * ret = trace_seq_printf(s, <TP_printk> "\n");
  189. * if (!ret)
  190. * return TRACE_TYPE_PARTIAL_LINE;
  191. *
  192. * return TRACE_TYPE_HANDLED;
  193. * }
  194. *
  195. * This is the method used to print the raw event to the trace
  196. * output format. Note, this is not needed if the data is read
  197. * in binary.
  198. */
  199. #undef __entry
  200. #define __entry field
  201. #undef TP_printk
  202. #define TP_printk(fmt, args...) fmt "\n", args
  203. #undef __get_dynamic_array
  204. #define __get_dynamic_array(field) \
  205. ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
  206. #undef __get_dynamic_array_len
  207. #define __get_dynamic_array_len(field) \
  208. ((__entry->__data_loc_##field >> 16) & 0xffff)
  209. #undef __get_str
  210. #define __get_str(field) ((char *)__get_dynamic_array(field))
  211. #undef __get_bitmask
  212. #define __get_bitmask(field) \
  213. ({ \
  214. void *__bitmask = __get_dynamic_array(field); \
  215. unsigned int __bitmask_size; \
  216. __bitmask_size = __get_dynamic_array_len(field); \
  217. trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
  218. })
  219. #undef __print_flags
  220. #define __print_flags(flag, delim, flag_array...) \
  221. ({ \
  222. static const struct trace_print_flags __flags[] = \
  223. { flag_array, { -1, NULL }}; \
  224. trace_print_flags_seq(p, delim, flag, __flags); \
  225. })
  226. #undef __print_symbolic
  227. #define __print_symbolic(value, symbol_array...) \
  228. ({ \
  229. static const struct trace_print_flags symbols[] = \
  230. { symbol_array, { -1, NULL }}; \
  231. trace_print_symbols_seq(p, value, symbols); \
  232. })
  233. #undef __print_flags_u64
  234. #undef __print_symbolic_u64
  235. #if BITS_PER_LONG == 32
  236. #define __print_flags_u64(flag, delim, flag_array...) \
  237. ({ \
  238. static const struct trace_print_flags_u64 __flags[] = \
  239. { flag_array, { -1, NULL } }; \
  240. trace_print_flags_seq_u64(p, delim, flag, __flags); \
  241. })
  242. #define __print_symbolic_u64(value, symbol_array...) \
  243. ({ \
  244. static const struct trace_print_flags_u64 symbols[] = \
  245. { symbol_array, { -1, NULL } }; \
  246. trace_print_symbols_seq_u64(p, value, symbols); \
  247. })
  248. #else
  249. #define __print_flags_u64(flag, delim, flag_array...) \
  250. __print_flags(flag, delim, flag_array)
  251. #define __print_symbolic_u64(value, symbol_array...) \
  252. __print_symbolic(value, symbol_array)
  253. #endif
  254. #undef __print_hex
  255. #define __print_hex(buf, buf_len) \
  256. trace_print_hex_seq(p, buf, buf_len, false)
  257. #undef __print_hex_str
  258. #define __print_hex_str(buf, buf_len) \
  259. trace_print_hex_seq(p, buf, buf_len, true)
  260. #undef __print_array
  261. #define __print_array(array, count, el_size) \
  262. ({ \
  263. BUILD_BUG_ON(el_size != 1 && el_size != 2 && \
  264. el_size != 4 && el_size != 8); \
  265. trace_print_array_seq(p, array, count, el_size); \
  266. })
  267. #undef DECLARE_EVENT_CLASS
  268. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  269. static notrace enum print_line_t \
  270. trace_raw_output_##call(struct trace_iterator *iter, int flags, \
  271. struct trace_event *trace_event) \
  272. { \
  273. struct trace_seq *s = &iter->seq; \
  274. struct trace_seq __maybe_unused *p = &iter->tmp_seq; \
  275. struct trace_event_raw_##call *field; \
  276. int ret; \
  277. \
  278. field = (typeof(field))iter->ent; \
  279. \
  280. ret = trace_raw_output_prep(iter, trace_event); \
  281. if (ret != TRACE_TYPE_HANDLED) \
  282. return ret; \
  283. \
  284. trace_seq_printf(s, print); \
  285. \
  286. return trace_handle_return(s); \
  287. } \
  288. static struct trace_event_functions trace_event_type_funcs_##call = { \
  289. .trace = trace_raw_output_##call, \
  290. };
  291. #undef DEFINE_EVENT_PRINT
  292. #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
  293. static notrace enum print_line_t \
  294. trace_raw_output_##call(struct trace_iterator *iter, int flags, \
  295. struct trace_event *event) \
  296. { \
  297. struct trace_event_raw_##template *field; \
  298. struct trace_entry *entry; \
  299. struct trace_seq *p = &iter->tmp_seq; \
  300. \
  301. entry = iter->ent; \
  302. \
  303. if (entry->type != event_##call.event.type) { \
  304. WARN_ON_ONCE(1); \
  305. return TRACE_TYPE_UNHANDLED; \
  306. } \
  307. \
  308. field = (typeof(field))entry; \
  309. \
  310. trace_seq_init(p); \
  311. return trace_output_call(iter, #call, print); \
  312. } \
  313. static struct trace_event_functions trace_event_type_funcs_##call = { \
  314. .trace = trace_raw_output_##call, \
  315. };
  316. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  317. #undef __field_ext
  318. #define __field_ext(type, item, filter_type) \
  319. ret = trace_define_field(event_call, #type, #item, \
  320. offsetof(typeof(field), item), \
  321. sizeof(field.item), \
  322. is_signed_type(type), filter_type); \
  323. if (ret) \
  324. return ret;
  325. #undef __field_struct_ext
  326. #define __field_struct_ext(type, item, filter_type) \
  327. ret = trace_define_field(event_call, #type, #item, \
  328. offsetof(typeof(field), item), \
  329. sizeof(field.item), \
  330. 0, filter_type); \
  331. if (ret) \
  332. return ret;
  333. #undef __field
  334. #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
  335. #undef __field_struct
  336. #define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER)
  337. #undef __array
  338. #define __array(type, item, len) \
  339. do { \
  340. char *type_str = #type"["__stringify(len)"]"; \
  341. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  342. ret = trace_define_field(event_call, type_str, #item, \
  343. offsetof(typeof(field), item), \
  344. sizeof(field.item), \
  345. is_signed_type(type), FILTER_OTHER); \
  346. if (ret) \
  347. return ret; \
  348. } while (0);
  349. #undef __dynamic_array
  350. #define __dynamic_array(type, item, len) \
  351. ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
  352. offsetof(typeof(field), __data_loc_##item), \
  353. sizeof(field.__data_loc_##item), \
  354. is_signed_type(type), FILTER_OTHER);
  355. #undef __string
  356. #define __string(item, src) __dynamic_array(char, item, -1)
  357. #undef __bitmask
  358. #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
  359. #undef DECLARE_EVENT_CLASS
  360. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
  361. static int notrace __init \
  362. trace_event_define_fields_##call(struct trace_event_call *event_call) \
  363. { \
  364. struct trace_event_raw_##call field; \
  365. int ret; \
  366. \
  367. tstruct; \
  368. \
  369. return ret; \
  370. }
  371. #undef DEFINE_EVENT
  372. #define DEFINE_EVENT(template, name, proto, args)
  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. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  377. /*
  378. * remember the offset of each array from the beginning of the event.
  379. */
  380. #undef __entry
  381. #define __entry entry
  382. #undef __field
  383. #define __field(type, item)
  384. #undef __field_ext
  385. #define __field_ext(type, item, filter_type)
  386. #undef __field_struct
  387. #define __field_struct(type, item)
  388. #undef __field_struct_ext
  389. #define __field_struct_ext(type, item, filter_type)
  390. #undef __array
  391. #define __array(type, item, len)
  392. #undef __dynamic_array
  393. #define __dynamic_array(type, item, len) \
  394. __item_length = (len) * sizeof(type); \
  395. __data_offsets->item = __data_size + \
  396. offsetof(typeof(*entry), __data); \
  397. __data_offsets->item |= __item_length << 16; \
  398. __data_size += __item_length;
  399. #undef __string
  400. #define __string(item, src) __dynamic_array(char, item, \
  401. strlen((src) ? (const char *)(src) : "(null)") + 1)
  402. /*
  403. * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
  404. * num_possible_cpus().
  405. */
  406. #define __bitmask_size_in_bytes_raw(nr_bits) \
  407. (((nr_bits) + 7) / 8)
  408. #define __bitmask_size_in_longs(nr_bits) \
  409. ((__bitmask_size_in_bytes_raw(nr_bits) + \
  410. ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))
  411. /*
  412. * __bitmask_size_in_bytes is the number of bytes needed to hold
  413. * num_possible_cpus() padded out to the nearest long. This is what
  414. * is saved in the buffer, just to be consistent.
  415. */
  416. #define __bitmask_size_in_bytes(nr_bits) \
  417. (__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))
  418. #undef __bitmask
  419. #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, \
  420. __bitmask_size_in_longs(nr_bits))
  421. #undef DECLARE_EVENT_CLASS
  422. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  423. static inline notrace int trace_event_get_offsets_##call( \
  424. struct trace_event_data_offsets_##call *__data_offsets, proto) \
  425. { \
  426. int __data_size = 0; \
  427. int __maybe_unused __item_length; \
  428. struct trace_event_raw_##call __maybe_unused *entry; \
  429. \
  430. tstruct; \
  431. \
  432. return __data_size; \
  433. }
  434. #undef DEFINE_EVENT
  435. #define DEFINE_EVENT(template, name, proto, args)
  436. #undef DEFINE_EVENT_PRINT
  437. #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
  438. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  439. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  440. /*
  441. * Stage 4 of the trace events.
  442. *
  443. * Override the macros in <trace/trace_events.h> to include the following:
  444. *
  445. * For those macros defined with TRACE_EVENT:
  446. *
  447. * static struct trace_event_call event_<call>;
  448. *
  449. * static void trace_event_raw_event_<call>(void *__data, proto)
  450. * {
  451. * struct trace_event_file *trace_file = __data;
  452. * struct trace_event_call *event_call = trace_file->event_call;
  453. * struct trace_event_data_offsets_<call> __maybe_unused __data_offsets;
  454. * unsigned long eflags = trace_file->flags;
  455. * enum event_trigger_type __tt = ETT_NONE;
  456. * struct ring_buffer_event *event;
  457. * struct trace_event_raw_<call> *entry; <-- defined in stage 1
  458. * struct ring_buffer *buffer;
  459. * unsigned long irq_flags;
  460. * int __data_size;
  461. * int pc;
  462. *
  463. * if (!(eflags & EVENT_FILE_FL_TRIGGER_COND)) {
  464. * if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
  465. * event_triggers_call(trace_file, NULL);
  466. * if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
  467. * return;
  468. * }
  469. *
  470. * local_save_flags(irq_flags);
  471. * pc = preempt_count();
  472. *
  473. * __data_size = trace_event_get_offsets_<call>(&__data_offsets, args);
  474. *
  475. * event = trace_event_buffer_lock_reserve(&buffer, trace_file,
  476. * event_<call>->event.type,
  477. * sizeof(*entry) + __data_size,
  478. * irq_flags, pc);
  479. * if (!event)
  480. * return;
  481. * entry = ring_buffer_event_data(event);
  482. *
  483. * { <assign>; } <-- Here we assign the entries by the __field and
  484. * __array macros.
  485. *
  486. * if (eflags & EVENT_FILE_FL_TRIGGER_COND)
  487. * __tt = event_triggers_call(trace_file, entry);
  488. *
  489. * if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT,
  490. * &trace_file->flags))
  491. * ring_buffer_discard_commit(buffer, event);
  492. * else if (!filter_check_discard(trace_file, entry, buffer, event))
  493. * trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
  494. *
  495. * if (__tt)
  496. * event_triggers_post_call(trace_file, __tt);
  497. * }
  498. *
  499. * static struct trace_event ftrace_event_type_<call> = {
  500. * .trace = trace_raw_output_<call>, <-- stage 2
  501. * };
  502. *
  503. * static char print_fmt_<call>[] = <TP_printk>;
  504. *
  505. * static struct trace_event_class __used event_class_<template> = {
  506. * .system = "<system>",
  507. * .define_fields = trace_event_define_fields_<call>,
  508. * .fields = LIST_HEAD_INIT(event_class_##call.fields),
  509. * .raw_init = trace_event_raw_init,
  510. * .probe = trace_event_raw_event_##call,
  511. * .reg = trace_event_reg,
  512. * };
  513. *
  514. * static struct trace_event_call event_<call> = {
  515. * .class = event_class_<template>,
  516. * {
  517. * .tp = &__tracepoint_<call>,
  518. * },
  519. * .event = &ftrace_event_type_<call>,
  520. * .print_fmt = print_fmt_<call>,
  521. * .flags = TRACE_EVENT_FL_TRACEPOINT,
  522. * };
  523. * // its only safe to use pointers when doing linker tricks to
  524. * // create an array.
  525. * static struct trace_event_call __used
  526. * __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>;
  527. *
  528. */
  529. #ifdef CONFIG_PERF_EVENTS
  530. #define _TRACE_PERF_PROTO(call, proto) \
  531. static notrace void \
  532. perf_trace_##call(void *__data, proto);
  533. #define _TRACE_PERF_INIT(call) \
  534. .perf_probe = perf_trace_##call,
  535. #else
  536. #define _TRACE_PERF_PROTO(call, proto)
  537. #define _TRACE_PERF_INIT(call)
  538. #endif /* CONFIG_PERF_EVENTS */
  539. #undef __entry
  540. #define __entry entry
  541. #undef __field
  542. #define __field(type, item)
  543. #undef __field_struct
  544. #define __field_struct(type, item)
  545. #undef __array
  546. #define __array(type, item, len)
  547. #undef __dynamic_array
  548. #define __dynamic_array(type, item, len) \
  549. __entry->__data_loc_##item = __data_offsets.item;
  550. #undef __string
  551. #define __string(item, src) __dynamic_array(char, item, -1)
  552. #undef __assign_str
  553. #define __assign_str(dst, src) \
  554. strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
  555. #undef __bitmask
  556. #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
  557. #undef __get_bitmask
  558. #define __get_bitmask(field) (char *)__get_dynamic_array(field)
  559. #undef __assign_bitmask
  560. #define __assign_bitmask(dst, src, nr_bits) \
  561. memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
  562. #undef TP_fast_assign
  563. #define TP_fast_assign(args...) args
  564. #undef __perf_count
  565. #define __perf_count(c) (c)
  566. #undef __perf_task
  567. #define __perf_task(t) (t)
  568. #undef DECLARE_EVENT_CLASS
  569. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  570. \
  571. static notrace void \
  572. trace_event_raw_event_##call(void *__data, proto) \
  573. { \
  574. struct trace_event_file *trace_file = __data; \
  575. struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
  576. struct trace_event_buffer fbuffer; \
  577. struct trace_event_raw_##call *entry; \
  578. int __data_size; \
  579. \
  580. if (trace_trigger_soft_disabled(trace_file)) \
  581. return; \
  582. \
  583. __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
  584. \
  585. entry = trace_event_buffer_reserve(&fbuffer, trace_file, \
  586. sizeof(*entry) + __data_size); \
  587. \
  588. if (!entry) \
  589. return; \
  590. \
  591. tstruct \
  592. \
  593. { assign; } \
  594. \
  595. trace_event_buffer_commit(&fbuffer); \
  596. }
  597. /*
  598. * The ftrace_test_probe is compiled out, it is only here as a build time check
  599. * to make sure that if the tracepoint handling changes, the ftrace probe will
  600. * fail to compile unless it too is updated.
  601. */
  602. #undef DEFINE_EVENT
  603. #define DEFINE_EVENT(template, call, proto, args) \
  604. static inline void ftrace_test_probe_##call(void) \
  605. { \
  606. check_trace_callback_type_##call(trace_event_raw_event_##template); \
  607. }
  608. #undef DEFINE_EVENT_PRINT
  609. #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
  610. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  611. #undef __entry
  612. #define __entry REC
  613. #undef __print_flags
  614. #undef __print_symbolic
  615. #undef __print_hex
  616. #undef __print_hex_str
  617. #undef __get_dynamic_array
  618. #undef __get_dynamic_array_len
  619. #undef __get_str
  620. #undef __get_bitmask
  621. #undef __print_array
  622. #undef TP_printk
  623. #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
  624. #undef DECLARE_EVENT_CLASS
  625. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  626. _TRACE_PERF_PROTO(call, PARAMS(proto)); \
  627. static char print_fmt_##call[] = print; \
  628. static struct trace_event_class __used __refdata event_class_##call = { \
  629. .system = TRACE_SYSTEM_STRING, \
  630. .define_fields = trace_event_define_fields_##call, \
  631. .fields = LIST_HEAD_INIT(event_class_##call.fields),\
  632. .raw_init = trace_event_raw_init, \
  633. .probe = trace_event_raw_event_##call, \
  634. .reg = trace_event_reg, \
  635. _TRACE_PERF_INIT(call) \
  636. };
  637. #undef DEFINE_EVENT
  638. #define DEFINE_EVENT(template, call, proto, args) \
  639. \
  640. static struct trace_event_call __used event_##call = { \
  641. .class = &event_class_##template, \
  642. { \
  643. .tp = &__tracepoint_##call, \
  644. }, \
  645. .event.funcs = &trace_event_type_funcs_##template, \
  646. .print_fmt = print_fmt_##template, \
  647. .flags = TRACE_EVENT_FL_TRACEPOINT, \
  648. }; \
  649. static struct trace_event_call __used \
  650. __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
  651. #undef DEFINE_EVENT_PRINT
  652. #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
  653. \
  654. static char print_fmt_##call[] = print; \
  655. \
  656. static struct trace_event_call __used event_##call = { \
  657. .class = &event_class_##template, \
  658. { \
  659. .tp = &__tracepoint_##call, \
  660. }, \
  661. .event.funcs = &trace_event_type_funcs_##call, \
  662. .print_fmt = print_fmt_##call, \
  663. .flags = TRACE_EVENT_FL_TRACEPOINT, \
  664. }; \
  665. static struct trace_event_call __used \
  666. __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
  667. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)