trace_events.h 23 KB

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