ftrace.h 20 KB

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