ftrace.h 24 KB

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