ftrace.h 23 KB

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