ftrace.h 20 KB

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