trace_events.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  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_enum_map __used __initdata \
  32. __##TRACE_SYSTEM##_##a = \
  33. { \
  34. .system = TRACE_SYSTEM_STRING, \
  35. .enum_string = #a, \
  36. .enum_value = a \
  37. }; \
  38. static struct trace_enum_map __used \
  39. __attribute__((section("_ftrace_enum_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_symbolic_u64
  234. #if BITS_PER_LONG == 32
  235. #define __print_symbolic_u64(value, symbol_array...) \
  236. ({ \
  237. static const struct trace_print_flags_u64 symbols[] = \
  238. { symbol_array, { -1, NULL } }; \
  239. trace_print_symbols_seq_u64(p, value, symbols); \
  240. })
  241. #else
  242. #define __print_symbolic_u64(value, symbol_array...) \
  243. __print_symbolic(value, symbol_array)
  244. #endif
  245. #undef __print_hex
  246. #define __print_hex(buf, buf_len) trace_print_hex_seq(p, buf, buf_len)
  247. #undef __print_array
  248. #define __print_array(array, count, el_size) \
  249. ({ \
  250. BUILD_BUG_ON(el_size != 1 && el_size != 2 && \
  251. el_size != 4 && el_size != 8); \
  252. trace_print_array_seq(p, array, count, el_size); \
  253. })
  254. #undef DECLARE_EVENT_CLASS
  255. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  256. static notrace enum print_line_t \
  257. trace_raw_output_##call(struct trace_iterator *iter, int flags, \
  258. struct trace_event *trace_event) \
  259. { \
  260. struct trace_seq *s = &iter->seq; \
  261. struct trace_seq __maybe_unused *p = &iter->tmp_seq; \
  262. struct trace_event_raw_##call *field; \
  263. int ret; \
  264. \
  265. field = (typeof(field))iter->ent; \
  266. \
  267. ret = trace_raw_output_prep(iter, trace_event); \
  268. if (ret != TRACE_TYPE_HANDLED) \
  269. return ret; \
  270. \
  271. trace_seq_printf(s, print); \
  272. \
  273. return trace_handle_return(s); \
  274. } \
  275. static struct trace_event_functions trace_event_type_funcs_##call = { \
  276. .trace = trace_raw_output_##call, \
  277. };
  278. #undef DEFINE_EVENT_PRINT
  279. #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
  280. static notrace enum print_line_t \
  281. trace_raw_output_##call(struct trace_iterator *iter, int flags, \
  282. struct trace_event *event) \
  283. { \
  284. struct trace_event_raw_##template *field; \
  285. struct trace_entry *entry; \
  286. struct trace_seq *p = &iter->tmp_seq; \
  287. \
  288. entry = iter->ent; \
  289. \
  290. if (entry->type != event_##call.event.type) { \
  291. WARN_ON_ONCE(1); \
  292. return TRACE_TYPE_UNHANDLED; \
  293. } \
  294. \
  295. field = (typeof(field))entry; \
  296. \
  297. trace_seq_init(p); \
  298. return trace_output_call(iter, #call, print); \
  299. } \
  300. static struct trace_event_functions trace_event_type_funcs_##call = { \
  301. .trace = trace_raw_output_##call, \
  302. };
  303. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  304. #undef __field_ext
  305. #define __field_ext(type, item, filter_type) \
  306. ret = trace_define_field(event_call, #type, #item, \
  307. offsetof(typeof(field), item), \
  308. sizeof(field.item), \
  309. is_signed_type(type), filter_type); \
  310. if (ret) \
  311. return ret;
  312. #undef __field_struct_ext
  313. #define __field_struct_ext(type, item, filter_type) \
  314. ret = trace_define_field(event_call, #type, #item, \
  315. offsetof(typeof(field), item), \
  316. sizeof(field.item), \
  317. 0, filter_type); \
  318. if (ret) \
  319. return ret;
  320. #undef __field
  321. #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
  322. #undef __field_struct
  323. #define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER)
  324. #undef __array
  325. #define __array(type, item, len) \
  326. do { \
  327. char *type_str = #type"["__stringify(len)"]"; \
  328. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  329. ret = trace_define_field(event_call, type_str, #item, \
  330. offsetof(typeof(field), item), \
  331. sizeof(field.item), \
  332. is_signed_type(type), FILTER_OTHER); \
  333. if (ret) \
  334. return ret; \
  335. } while (0);
  336. #undef __dynamic_array
  337. #define __dynamic_array(type, item, len) \
  338. ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
  339. offsetof(typeof(field), __data_loc_##item), \
  340. sizeof(field.__data_loc_##item), \
  341. is_signed_type(type), FILTER_OTHER);
  342. #undef __string
  343. #define __string(item, src) __dynamic_array(char, item, -1)
  344. #undef __bitmask
  345. #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
  346. #undef DECLARE_EVENT_CLASS
  347. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
  348. static int notrace __init \
  349. trace_event_define_fields_##call(struct trace_event_call *event_call) \
  350. { \
  351. struct trace_event_raw_##call field; \
  352. int ret; \
  353. \
  354. tstruct; \
  355. \
  356. return ret; \
  357. }
  358. #undef DEFINE_EVENT
  359. #define DEFINE_EVENT(template, name, proto, args)
  360. #undef DEFINE_EVENT_PRINT
  361. #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
  362. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  363. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  364. /*
  365. * remember the offset of each array from the beginning of the event.
  366. */
  367. #undef __entry
  368. #define __entry entry
  369. #undef __field
  370. #define __field(type, item)
  371. #undef __field_ext
  372. #define __field_ext(type, item, filter_type)
  373. #undef __field_struct
  374. #define __field_struct(type, item)
  375. #undef __field_struct_ext
  376. #define __field_struct_ext(type, item, filter_type)
  377. #undef __array
  378. #define __array(type, item, len)
  379. #undef __dynamic_array
  380. #define __dynamic_array(type, item, len) \
  381. __item_length = (len) * sizeof(type); \
  382. __data_offsets->item = __data_size + \
  383. offsetof(typeof(*entry), __data); \
  384. __data_offsets->item |= __item_length << 16; \
  385. __data_size += __item_length;
  386. #undef __string
  387. #define __string(item, src) __dynamic_array(char, item, \
  388. strlen((src) ? (const char *)(src) : "(null)") + 1)
  389. /*
  390. * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
  391. * num_possible_cpus().
  392. */
  393. #define __bitmask_size_in_bytes_raw(nr_bits) \
  394. (((nr_bits) + 7) / 8)
  395. #define __bitmask_size_in_longs(nr_bits) \
  396. ((__bitmask_size_in_bytes_raw(nr_bits) + \
  397. ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))
  398. /*
  399. * __bitmask_size_in_bytes is the number of bytes needed to hold
  400. * num_possible_cpus() padded out to the nearest long. This is what
  401. * is saved in the buffer, just to be consistent.
  402. */
  403. #define __bitmask_size_in_bytes(nr_bits) \
  404. (__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))
  405. #undef __bitmask
  406. #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, \
  407. __bitmask_size_in_longs(nr_bits))
  408. #undef DECLARE_EVENT_CLASS
  409. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  410. static inline notrace int trace_event_get_offsets_##call( \
  411. struct trace_event_data_offsets_##call *__data_offsets, proto) \
  412. { \
  413. int __data_size = 0; \
  414. int __maybe_unused __item_length; \
  415. struct trace_event_raw_##call __maybe_unused *entry; \
  416. \
  417. tstruct; \
  418. \
  419. return __data_size; \
  420. }
  421. #undef DEFINE_EVENT
  422. #define DEFINE_EVENT(template, name, proto, args)
  423. #undef DEFINE_EVENT_PRINT
  424. #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
  425. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  426. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  427. /*
  428. * Stage 4 of the trace events.
  429. *
  430. * Override the macros in <trace/trace_events.h> to include the following:
  431. *
  432. * For those macros defined with TRACE_EVENT:
  433. *
  434. * static struct trace_event_call event_<call>;
  435. *
  436. * static void trace_event_raw_event_<call>(void *__data, proto)
  437. * {
  438. * struct trace_event_file *trace_file = __data;
  439. * struct trace_event_call *event_call = trace_file->event_call;
  440. * struct trace_event_data_offsets_<call> __maybe_unused __data_offsets;
  441. * unsigned long eflags = trace_file->flags;
  442. * enum event_trigger_type __tt = ETT_NONE;
  443. * struct ring_buffer_event *event;
  444. * struct trace_event_raw_<call> *entry; <-- defined in stage 1
  445. * struct ring_buffer *buffer;
  446. * unsigned long irq_flags;
  447. * int __data_size;
  448. * int pc;
  449. *
  450. * if (!(eflags & EVENT_FILE_FL_TRIGGER_COND)) {
  451. * if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
  452. * event_triggers_call(trace_file, NULL);
  453. * if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
  454. * return;
  455. * }
  456. *
  457. * local_save_flags(irq_flags);
  458. * pc = preempt_count();
  459. *
  460. * __data_size = trace_event_get_offsets_<call>(&__data_offsets, args);
  461. *
  462. * event = trace_event_buffer_lock_reserve(&buffer, trace_file,
  463. * event_<call>->event.type,
  464. * sizeof(*entry) + __data_size,
  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. *
  473. * if (eflags & EVENT_FILE_FL_TRIGGER_COND)
  474. * __tt = event_triggers_call(trace_file, entry);
  475. *
  476. * if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT,
  477. * &trace_file->flags))
  478. * ring_buffer_discard_commit(buffer, event);
  479. * else if (!filter_check_discard(trace_file, entry, buffer, event))
  480. * trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
  481. *
  482. * if (__tt)
  483. * event_triggers_post_call(trace_file, __tt);
  484. * }
  485. *
  486. * static struct trace_event ftrace_event_type_<call> = {
  487. * .trace = trace_raw_output_<call>, <-- stage 2
  488. * };
  489. *
  490. * static char print_fmt_<call>[] = <TP_printk>;
  491. *
  492. * static struct trace_event_class __used event_class_<template> = {
  493. * .system = "<system>",
  494. * .define_fields = trace_event_define_fields_<call>,
  495. * .fields = LIST_HEAD_INIT(event_class_##call.fields),
  496. * .raw_init = trace_event_raw_init,
  497. * .probe = trace_event_raw_event_##call,
  498. * .reg = trace_event_reg,
  499. * };
  500. *
  501. * static struct trace_event_call event_<call> = {
  502. * .class = event_class_<template>,
  503. * {
  504. * .tp = &__tracepoint_<call>,
  505. * },
  506. * .event = &ftrace_event_type_<call>,
  507. * .print_fmt = print_fmt_<call>,
  508. * .flags = TRACE_EVENT_FL_TRACEPOINT,
  509. * };
  510. * // its only safe to use pointers when doing linker tricks to
  511. * // create an array.
  512. * static struct trace_event_call __used
  513. * __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>;
  514. *
  515. */
  516. #ifdef CONFIG_PERF_EVENTS
  517. #define _TRACE_PERF_PROTO(call, proto) \
  518. static notrace void \
  519. perf_trace_##call(void *__data, proto);
  520. #define _TRACE_PERF_INIT(call) \
  521. .perf_probe = perf_trace_##call,
  522. #else
  523. #define _TRACE_PERF_PROTO(call, proto)
  524. #define _TRACE_PERF_INIT(call)
  525. #endif /* CONFIG_PERF_EVENTS */
  526. #undef __entry
  527. #define __entry entry
  528. #undef __field
  529. #define __field(type, item)
  530. #undef __field_struct
  531. #define __field_struct(type, item)
  532. #undef __array
  533. #define __array(type, item, len)
  534. #undef __dynamic_array
  535. #define __dynamic_array(type, item, len) \
  536. __entry->__data_loc_##item = __data_offsets.item;
  537. #undef __string
  538. #define __string(item, src) __dynamic_array(char, item, -1)
  539. #undef __assign_str
  540. #define __assign_str(dst, src) \
  541. strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
  542. #undef __bitmask
  543. #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
  544. #undef __get_bitmask
  545. #define __get_bitmask(field) (char *)__get_dynamic_array(field)
  546. #undef __assign_bitmask
  547. #define __assign_bitmask(dst, src, nr_bits) \
  548. memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
  549. #undef TP_fast_assign
  550. #define TP_fast_assign(args...) args
  551. #undef __perf_count
  552. #define __perf_count(c) (c)
  553. #undef __perf_task
  554. #define __perf_task(t) (t)
  555. #undef DECLARE_EVENT_CLASS
  556. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  557. \
  558. static notrace void \
  559. trace_event_raw_event_##call(void *__data, proto) \
  560. { \
  561. struct trace_event_file *trace_file = __data; \
  562. struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
  563. struct trace_event_buffer fbuffer; \
  564. struct trace_event_raw_##call *entry; \
  565. int __data_size; \
  566. \
  567. if (trace_trigger_soft_disabled(trace_file)) \
  568. return; \
  569. \
  570. __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
  571. \
  572. entry = trace_event_buffer_reserve(&fbuffer, trace_file, \
  573. sizeof(*entry) + __data_size); \
  574. \
  575. if (!entry) \
  576. return; \
  577. \
  578. tstruct \
  579. \
  580. { assign; } \
  581. \
  582. trace_event_buffer_commit(&fbuffer, \
  583. sizeof(*entry) + __data_size); \
  584. }
  585. /*
  586. * The ftrace_test_probe is compiled out, it is only here as a build time check
  587. * to make sure that if the tracepoint handling changes, the ftrace probe will
  588. * fail to compile unless it too is updated.
  589. */
  590. #undef DEFINE_EVENT
  591. #define DEFINE_EVENT(template, call, proto, args) \
  592. static inline void ftrace_test_probe_##call(void) \
  593. { \
  594. check_trace_callback_type_##call(trace_event_raw_event_##template); \
  595. }
  596. #undef DEFINE_EVENT_PRINT
  597. #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
  598. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  599. #undef __entry
  600. #define __entry REC
  601. #undef __print_flags
  602. #undef __print_symbolic
  603. #undef __print_hex
  604. #undef __get_dynamic_array
  605. #undef __get_dynamic_array_len
  606. #undef __get_str
  607. #undef __get_bitmask
  608. #undef __print_array
  609. #undef TP_printk
  610. #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
  611. #undef DECLARE_EVENT_CLASS
  612. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  613. _TRACE_PERF_PROTO(call, PARAMS(proto)); \
  614. static char print_fmt_##call[] = print; \
  615. static struct trace_event_class __used __refdata event_class_##call = { \
  616. .system = TRACE_SYSTEM_STRING, \
  617. .define_fields = trace_event_define_fields_##call, \
  618. .fields = LIST_HEAD_INIT(event_class_##call.fields),\
  619. .raw_init = trace_event_raw_init, \
  620. .probe = trace_event_raw_event_##call, \
  621. .reg = trace_event_reg, \
  622. _TRACE_PERF_INIT(call) \
  623. };
  624. #undef DEFINE_EVENT
  625. #define DEFINE_EVENT(template, call, proto, args) \
  626. \
  627. static struct trace_event_call __used event_##call = { \
  628. .class = &event_class_##template, \
  629. { \
  630. .tp = &__tracepoint_##call, \
  631. }, \
  632. .event.funcs = &trace_event_type_funcs_##template, \
  633. .print_fmt = print_fmt_##template, \
  634. .flags = TRACE_EVENT_FL_TRACEPOINT, \
  635. }; \
  636. static struct trace_event_call __used \
  637. __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
  638. #undef DEFINE_EVENT_PRINT
  639. #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
  640. \
  641. static char print_fmt_##call[] = print; \
  642. \
  643. static struct trace_event_call __used event_##call = { \
  644. .class = &event_class_##template, \
  645. { \
  646. .tp = &__tracepoint_##call, \
  647. }, \
  648. .event.funcs = &trace_event_type_funcs_##call, \
  649. .print_fmt = print_fmt_##call, \
  650. .flags = TRACE_EVENT_FL_TRACEPOINT, \
  651. }; \
  652. static struct trace_event_call __used \
  653. __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
  654. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)