ftrace.h 23 KB

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