ftrace.h 20 KB

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