ftrace.h 20 KB

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