ftrace.h 23 KB

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