ftrace.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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 trace_seq *s = &iter->seq; \
  228. struct ftrace_raw_##template *field; \
  229. struct trace_entry *entry; \
  230. struct trace_seq *p = &iter->tmp_seq; \
  231. int ret; \
  232. \
  233. entry = iter->ent; \
  234. \
  235. if (entry->type != event_##call.event.type) { \
  236. WARN_ON_ONCE(1); \
  237. return TRACE_TYPE_UNHANDLED; \
  238. } \
  239. \
  240. field = (typeof(field))entry; \
  241. \
  242. trace_seq_init(p); \
  243. ret = trace_seq_printf(s, "%s: ", #call); \
  244. if (ret) \
  245. ret = trace_seq_printf(s, print); \
  246. if (!ret) \
  247. return TRACE_TYPE_PARTIAL_LINE; \
  248. \
  249. return TRACE_TYPE_HANDLED; \
  250. } \
  251. static struct trace_event_functions ftrace_event_type_funcs_##call = { \
  252. .trace = ftrace_raw_output_##call, \
  253. };
  254. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  255. #undef __field_ext
  256. #define __field_ext(type, item, filter_type) \
  257. ret = trace_define_field(event_call, #type, #item, \
  258. offsetof(typeof(field), item), \
  259. sizeof(field.item), \
  260. is_signed_type(type), filter_type); \
  261. if (ret) \
  262. return ret;
  263. #undef __field
  264. #define __field(type, item) __field_ext(type, item, FILTER_OTHER)
  265. #undef __array
  266. #define __array(type, item, len) \
  267. do { \
  268. mutex_lock(&event_storage_mutex); \
  269. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  270. snprintf(event_storage, sizeof(event_storage), \
  271. "%s[%d]", #type, len); \
  272. ret = trace_define_field(event_call, event_storage, #item, \
  273. offsetof(typeof(field), item), \
  274. sizeof(field.item), \
  275. is_signed_type(type), FILTER_OTHER); \
  276. mutex_unlock(&event_storage_mutex); \
  277. if (ret) \
  278. return ret; \
  279. } while (0);
  280. #undef __dynamic_array
  281. #define __dynamic_array(type, item, len) \
  282. ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
  283. offsetof(typeof(field), __data_loc_##item), \
  284. sizeof(field.__data_loc_##item), \
  285. is_signed_type(type), FILTER_OTHER);
  286. #undef __string
  287. #define __string(item, src) __dynamic_array(char, item, -1)
  288. #undef DECLARE_EVENT_CLASS
  289. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
  290. static int notrace __init \
  291. ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
  292. { \
  293. struct ftrace_raw_##call field; \
  294. int ret; \
  295. \
  296. tstruct; \
  297. \
  298. return ret; \
  299. }
  300. #undef DEFINE_EVENT
  301. #define DEFINE_EVENT(template, name, proto, args)
  302. #undef DEFINE_EVENT_PRINT
  303. #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
  304. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  305. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  306. /*
  307. * remember the offset of each array from the beginning of the event.
  308. */
  309. #undef __entry
  310. #define __entry entry
  311. #undef __field
  312. #define __field(type, item)
  313. #undef __field_ext
  314. #define __field_ext(type, item, filter_type)
  315. #undef __array
  316. #define __array(type, item, len)
  317. #undef __dynamic_array
  318. #define __dynamic_array(type, item, len) \
  319. __data_offsets->item = __data_size + \
  320. offsetof(typeof(*entry), __data); \
  321. __data_offsets->item |= (len * sizeof(type)) << 16; \
  322. __data_size += (len) * sizeof(type);
  323. #undef __string
  324. #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)
  325. #undef DECLARE_EVENT_CLASS
  326. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  327. static inline notrace int ftrace_get_offsets_##call( \
  328. struct ftrace_data_offsets_##call *__data_offsets, proto) \
  329. { \
  330. int __data_size = 0; \
  331. struct ftrace_raw_##call __maybe_unused *entry; \
  332. \
  333. tstruct; \
  334. \
  335. return __data_size; \
  336. }
  337. #undef DEFINE_EVENT
  338. #define DEFINE_EVENT(template, name, proto, args)
  339. #undef DEFINE_EVENT_PRINT
  340. #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
  341. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  342. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  343. /*
  344. * Stage 4 of the trace events.
  345. *
  346. * Override the macros in <trace/trace_events.h> to include the following:
  347. *
  348. * For those macros defined with TRACE_EVENT:
  349. *
  350. * static struct ftrace_event_call event_<call>;
  351. *
  352. * static void ftrace_raw_event_<call>(void *__data, proto)
  353. * {
  354. * struct ftrace_event_file *ftrace_file = __data;
  355. * struct ftrace_event_call *event_call = ftrace_file->event_call;
  356. * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
  357. * struct ring_buffer_event *event;
  358. * struct ftrace_raw_<call> *entry; <-- defined in stage 1
  359. * struct ring_buffer *buffer;
  360. * unsigned long irq_flags;
  361. * int __data_size;
  362. * int pc;
  363. *
  364. * if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT,
  365. * &ftrace_file->flags))
  366. * return;
  367. *
  368. * local_save_flags(irq_flags);
  369. * pc = preempt_count();
  370. *
  371. * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
  372. *
  373. * event = trace_event_buffer_lock_reserve(&buffer, ftrace_file,
  374. * event_<call>->event.type,
  375. * sizeof(*entry) + __data_size,
  376. * irq_flags, pc);
  377. * if (!event)
  378. * return;
  379. * entry = ring_buffer_event_data(event);
  380. *
  381. * { <assign>; } <-- Here we assign the entries by the __field and
  382. * __array macros.
  383. *
  384. * if (!filter_check_discard(ftrace_file, entry, buffer, event))
  385. * trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
  386. * }
  387. *
  388. * static struct trace_event ftrace_event_type_<call> = {
  389. * .trace = ftrace_raw_output_<call>, <-- stage 2
  390. * };
  391. *
  392. * static const char print_fmt_<call>[] = <TP_printk>;
  393. *
  394. * static struct ftrace_event_class __used event_class_<template> = {
  395. * .system = "<system>",
  396. * .define_fields = ftrace_define_fields_<call>,
  397. * .fields = LIST_HEAD_INIT(event_class_##call.fields),
  398. * .raw_init = trace_event_raw_init,
  399. * .probe = ftrace_raw_event_##call,
  400. * .reg = ftrace_event_reg,
  401. * };
  402. *
  403. * static struct ftrace_event_call event_<call> = {
  404. * .name = "<call>",
  405. * .class = event_class_<template>,
  406. * .event = &ftrace_event_type_<call>,
  407. * .print_fmt = print_fmt_<call>,
  408. * };
  409. * // its only safe to use pointers when doing linker tricks to
  410. * // create an array.
  411. * static struct ftrace_event_call __used
  412. * __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>;
  413. *
  414. */
  415. #ifdef CONFIG_PERF_EVENTS
  416. #define _TRACE_PERF_PROTO(call, proto) \
  417. static notrace void \
  418. perf_trace_##call(void *__data, proto);
  419. #define _TRACE_PERF_INIT(call) \
  420. .perf_probe = perf_trace_##call,
  421. #else
  422. #define _TRACE_PERF_PROTO(call, proto)
  423. #define _TRACE_PERF_INIT(call)
  424. #endif /* CONFIG_PERF_EVENTS */
  425. #undef __entry
  426. #define __entry entry
  427. #undef __field
  428. #define __field(type, item)
  429. #undef __array
  430. #define __array(type, item, len)
  431. #undef __dynamic_array
  432. #define __dynamic_array(type, item, len) \
  433. __entry->__data_loc_##item = __data_offsets.item;
  434. #undef __string
  435. #define __string(item, src) __dynamic_array(char, item, -1) \
  436. #undef __assign_str
  437. #define __assign_str(dst, src) \
  438. strcpy(__get_str(dst), src);
  439. #undef TP_fast_assign
  440. #define TP_fast_assign(args...) args
  441. #undef __perf_addr
  442. #define __perf_addr(a) (a)
  443. #undef __perf_count
  444. #define __perf_count(c) (c)
  445. #undef __perf_task
  446. #define __perf_task(t) (t)
  447. #undef DECLARE_EVENT_CLASS
  448. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  449. \
  450. static notrace void \
  451. ftrace_raw_event_##call(void *__data, proto) \
  452. { \
  453. struct ftrace_event_file *ftrace_file = __data; \
  454. struct ftrace_event_call *event_call = ftrace_file->event_call; \
  455. struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
  456. struct ring_buffer_event *event; \
  457. struct ftrace_raw_##call *entry; \
  458. struct ring_buffer *buffer; \
  459. unsigned long irq_flags; \
  460. int __data_size; \
  461. int pc; \
  462. \
  463. if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, \
  464. &ftrace_file->flags)) \
  465. return; \
  466. \
  467. local_save_flags(irq_flags); \
  468. pc = preempt_count(); \
  469. \
  470. __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
  471. \
  472. event = trace_event_buffer_lock_reserve(&buffer, ftrace_file, \
  473. event_call->event.type, \
  474. sizeof(*entry) + __data_size, \
  475. irq_flags, pc); \
  476. if (!event) \
  477. return; \
  478. entry = ring_buffer_event_data(event); \
  479. \
  480. tstruct \
  481. \
  482. { assign; } \
  483. \
  484. if (!filter_check_discard(ftrace_file, entry, buffer, event)) \
  485. trace_buffer_unlock_commit(buffer, event, irq_flags, pc); \
  486. }
  487. /*
  488. * The ftrace_test_probe is compiled out, it is only here as a build time check
  489. * to make sure that if the tracepoint handling changes, the ftrace probe will
  490. * fail to compile unless it too is updated.
  491. */
  492. #undef DEFINE_EVENT
  493. #define DEFINE_EVENT(template, call, proto, args) \
  494. static inline void ftrace_test_probe_##call(void) \
  495. { \
  496. check_trace_callback_type_##call(ftrace_raw_event_##template); \
  497. }
  498. #undef DEFINE_EVENT_PRINT
  499. #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
  500. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  501. #undef __entry
  502. #define __entry REC
  503. #undef __print_flags
  504. #undef __print_symbolic
  505. #undef __print_hex
  506. #undef __get_dynamic_array
  507. #undef __get_str
  508. #undef TP_printk
  509. #define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
  510. #undef DECLARE_EVENT_CLASS
  511. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  512. _TRACE_PERF_PROTO(call, PARAMS(proto)); \
  513. static const char print_fmt_##call[] = print; \
  514. static struct ftrace_event_class __used __refdata event_class_##call = { \
  515. .system = __stringify(TRACE_SYSTEM), \
  516. .define_fields = ftrace_define_fields_##call, \
  517. .fields = LIST_HEAD_INIT(event_class_##call.fields),\
  518. .raw_init = trace_event_raw_init, \
  519. .probe = ftrace_raw_event_##call, \
  520. .reg = ftrace_event_reg, \
  521. _TRACE_PERF_INIT(call) \
  522. };
  523. #undef DEFINE_EVENT
  524. #define DEFINE_EVENT(template, call, proto, args) \
  525. \
  526. static struct ftrace_event_call __used event_##call = { \
  527. .name = #call, \
  528. .class = &event_class_##template, \
  529. .event.funcs = &ftrace_event_type_funcs_##template, \
  530. .print_fmt = print_fmt_##template, \
  531. }; \
  532. static struct ftrace_event_call __used \
  533. __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
  534. #undef DEFINE_EVENT_PRINT
  535. #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
  536. \
  537. static const char print_fmt_##call[] = print; \
  538. \
  539. static struct ftrace_event_call __used event_##call = { \
  540. .name = #call, \
  541. .class = &event_class_##template, \
  542. .event.funcs = &ftrace_event_type_funcs_##call, \
  543. .print_fmt = print_fmt_##call, \
  544. }; \
  545. static struct ftrace_event_call __used \
  546. __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
  547. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  548. #ifdef CONFIG_PERF_EVENTS
  549. #undef __entry
  550. #define __entry entry
  551. #undef __get_dynamic_array
  552. #define __get_dynamic_array(field) \
  553. ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
  554. #undef __get_str
  555. #define __get_str(field) (char *)__get_dynamic_array(field)
  556. #undef __perf_addr
  557. #define __perf_addr(a) (__addr = (a))
  558. #undef __perf_count
  559. #define __perf_count(c) (__count = (c))
  560. #undef __perf_task
  561. #define __perf_task(t) (__task = (t))
  562. #undef DECLARE_EVENT_CLASS
  563. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  564. static notrace void \
  565. perf_trace_##call(void *__data, proto) \
  566. { \
  567. struct ftrace_event_call *event_call = __data; \
  568. struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
  569. struct ftrace_raw_##call *entry; \
  570. struct pt_regs __regs; \
  571. u64 __addr = 0, __count = 1; \
  572. struct task_struct *__task = NULL; \
  573. struct hlist_head *head; \
  574. int __entry_size; \
  575. int __data_size; \
  576. int rctx; \
  577. \
  578. __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
  579. \
  580. head = this_cpu_ptr(event_call->perf_events); \
  581. if (__builtin_constant_p(!__task) && !__task && \
  582. hlist_empty(head)) \
  583. return; \
  584. \
  585. __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
  586. sizeof(u64)); \
  587. __entry_size -= sizeof(u32); \
  588. \
  589. perf_fetch_caller_regs(&__regs); \
  590. entry = perf_trace_buf_prepare(__entry_size, \
  591. event_call->event.type, &__regs, &rctx); \
  592. if (!entry) \
  593. return; \
  594. \
  595. tstruct \
  596. \
  597. { assign; } \
  598. \
  599. perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
  600. __count, &__regs, head, __task); \
  601. }
  602. /*
  603. * This part is compiled out, it is only here as a build time check
  604. * to make sure that if the tracepoint handling changes, the
  605. * perf probe will fail to compile unless it too is updated.
  606. */
  607. #undef DEFINE_EVENT
  608. #define DEFINE_EVENT(template, call, proto, args) \
  609. static inline void perf_test_probe_##call(void) \
  610. { \
  611. check_trace_callback_type_##call(perf_trace_##template); \
  612. }
  613. #undef DEFINE_EVENT_PRINT
  614. #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
  615. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  616. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  617. #endif /* CONFIG_PERF_EVENTS */