ftrace.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. #undef __field
  20. #define __field(type, item) type item;
  21. #undef __array
  22. #define __array(type, item, len) type item[len];
  23. #undef __dynamic_array
  24. #define __dynamic_array(type, item, len) u32 __data_loc_##item;
  25. #undef __string
  26. #define __string(item, src) __dynamic_array(char, item, -1)
  27. #undef TP_STRUCT__entry
  28. #define TP_STRUCT__entry(args...) args
  29. #undef TRACE_EVENT
  30. #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
  31. struct ftrace_raw_##name { \
  32. struct trace_entry ent; \
  33. tstruct \
  34. char __data[0]; \
  35. }; \
  36. static struct ftrace_event_call event_##name
  37. /* Callbacks are meaningless to ftrace. */
  38. #undef TRACE_EVENT_FN
  39. #define TRACE_EVENT_FN(name, proto, args, tstruct, \
  40. assign, print, reg, unreg) \
  41. TRACE_EVENT(name, TP_PROTO(proto), TP_ARGS(args), \
  42. TP_STRUCT__entry(tstruct), \
  43. TP_fast_assign(assign), \
  44. TP_printk(print))
  45. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  46. /*
  47. * Stage 2 of the trace events.
  48. *
  49. * Include the following:
  50. *
  51. * struct ftrace_data_offsets_<call> {
  52. * u32 <item1>;
  53. * u32 <item2>;
  54. * [...]
  55. * };
  56. *
  57. * The __dynamic_array() macro will create each u32 <item>, this is
  58. * to keep the offset of each array from the beginning of the event.
  59. * The size of an array is also encoded, in the higher 16 bits of <item>.
  60. */
  61. #undef __field
  62. #define __field(type, item);
  63. #undef __array
  64. #define __array(type, item, len)
  65. #undef __dynamic_array
  66. #define __dynamic_array(type, item, len) u32 item;
  67. #undef __string
  68. #define __string(item, src) __dynamic_array(char, item, -1)
  69. #undef TRACE_EVENT
  70. #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
  71. struct ftrace_data_offsets_##call { \
  72. tstruct; \
  73. };
  74. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  75. /*
  76. * Setup the showing format of trace point.
  77. *
  78. * int
  79. * ftrace_format_##call(struct trace_seq *s)
  80. * {
  81. * struct ftrace_raw_##call field;
  82. * int ret;
  83. *
  84. * ret = trace_seq_printf(s, #type " " #item ";"
  85. * " offset:%u; size:%u;\n",
  86. * offsetof(struct ftrace_raw_##call, item),
  87. * sizeof(field.type));
  88. *
  89. * }
  90. */
  91. #undef TP_STRUCT__entry
  92. #define TP_STRUCT__entry(args...) args
  93. #undef __field
  94. #define __field(type, item) \
  95. ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
  96. "offset:%u;\tsize:%u;\n", \
  97. (unsigned int)offsetof(typeof(field), item), \
  98. (unsigned int)sizeof(field.item)); \
  99. if (!ret) \
  100. return 0;
  101. #undef __array
  102. #define __array(type, item, len) \
  103. ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
  104. "offset:%u;\tsize:%u;\n", \
  105. (unsigned int)offsetof(typeof(field), item), \
  106. (unsigned int)sizeof(field.item)); \
  107. if (!ret) \
  108. return 0;
  109. #undef __dynamic_array
  110. #define __dynamic_array(type, item, len) \
  111. ret = trace_seq_printf(s, "\tfield:__data_loc " #type "[] " #item ";\t"\
  112. "offset:%u;\tsize:%u;\n", \
  113. (unsigned int)offsetof(typeof(field), \
  114. __data_loc_##item), \
  115. (unsigned int)sizeof(field.__data_loc_##item)); \
  116. if (!ret) \
  117. return 0;
  118. #undef __string
  119. #define __string(item, src) __dynamic_array(char, item, -1)
  120. #undef __entry
  121. #define __entry REC
  122. #undef __print_symbolic
  123. #undef __get_dynamic_array
  124. #undef __get_str
  125. #undef TP_printk
  126. #define TP_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
  127. #undef TP_fast_assign
  128. #define TP_fast_assign(args...) args
  129. #undef TP_perf_assign
  130. #define TP_perf_assign(args...)
  131. #undef TRACE_EVENT
  132. #define TRACE_EVENT(call, proto, args, tstruct, func, print) \
  133. static int \
  134. ftrace_format_##call(struct ftrace_event_call *unused, \
  135. struct trace_seq *s) \
  136. { \
  137. struct ftrace_raw_##call field __attribute__((unused)); \
  138. int ret = 0; \
  139. \
  140. tstruct; \
  141. \
  142. trace_seq_printf(s, "\nprint fmt: " print); \
  143. \
  144. return ret; \
  145. }
  146. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  147. /*
  148. * Stage 3 of the trace events.
  149. *
  150. * Override the macros in <trace/trace_events.h> to include the following:
  151. *
  152. * enum print_line_t
  153. * ftrace_raw_output_<call>(struct trace_iterator *iter, int flags)
  154. * {
  155. * struct trace_seq *s = &iter->seq;
  156. * struct ftrace_raw_<call> *field; <-- defined in stage 1
  157. * struct trace_entry *entry;
  158. * struct trace_seq *p;
  159. * int ret;
  160. *
  161. * entry = iter->ent;
  162. *
  163. * if (entry->type != event_<call>.id) {
  164. * WARN_ON_ONCE(1);
  165. * return TRACE_TYPE_UNHANDLED;
  166. * }
  167. *
  168. * field = (typeof(field))entry;
  169. *
  170. * p = get_cpu_var(ftrace_event_seq);
  171. * trace_seq_init(p);
  172. * ret = trace_seq_printf(s, <TP_printk> "\n");
  173. * put_cpu();
  174. * if (!ret)
  175. * return TRACE_TYPE_PARTIAL_LINE;
  176. *
  177. * return TRACE_TYPE_HANDLED;
  178. * }
  179. *
  180. * This is the method used to print the raw event to the trace
  181. * output format. Note, this is not needed if the data is read
  182. * in binary.
  183. */
  184. #undef __entry
  185. #define __entry field
  186. #undef TP_printk
  187. #define TP_printk(fmt, args...) fmt "\n", args
  188. #undef __get_dynamic_array
  189. #define __get_dynamic_array(field) \
  190. ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
  191. #undef __get_str
  192. #define __get_str(field) (char *)__get_dynamic_array(field)
  193. #undef __print_flags
  194. #define __print_flags(flag, delim, flag_array...) \
  195. ({ \
  196. static const struct trace_print_flags flags[] = \
  197. { flag_array, { -1, NULL }}; \
  198. ftrace_print_flags_seq(p, delim, flag, flags); \
  199. })
  200. #undef __print_symbolic
  201. #define __print_symbolic(value, symbol_array...) \
  202. ({ \
  203. static const struct trace_print_flags symbols[] = \
  204. { symbol_array, { -1, NULL }}; \
  205. ftrace_print_symbols_seq(p, value, symbols); \
  206. })
  207. #undef TRACE_EVENT
  208. #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
  209. enum print_line_t \
  210. ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
  211. { \
  212. struct trace_seq *s = &iter->seq; \
  213. struct ftrace_raw_##call *field; \
  214. struct trace_entry *entry; \
  215. struct trace_seq *p; \
  216. int ret; \
  217. \
  218. entry = iter->ent; \
  219. \
  220. if (entry->type != event_##call.id) { \
  221. WARN_ON_ONCE(1); \
  222. return TRACE_TYPE_UNHANDLED; \
  223. } \
  224. \
  225. field = (typeof(field))entry; \
  226. \
  227. p = &get_cpu_var(ftrace_event_seq); \
  228. trace_seq_init(p); \
  229. ret = trace_seq_printf(s, #call ": " print); \
  230. put_cpu(); \
  231. if (!ret) \
  232. return TRACE_TYPE_PARTIAL_LINE; \
  233. \
  234. return TRACE_TYPE_HANDLED; \
  235. }
  236. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  237. #undef __field
  238. #define __field(type, item) \
  239. ret = trace_define_field(event_call, #type, #item, \
  240. offsetof(typeof(field), item), \
  241. sizeof(field.item), is_signed_type(type)); \
  242. if (ret) \
  243. return ret;
  244. #undef __array
  245. #define __array(type, item, len) \
  246. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  247. ret = trace_define_field(event_call, #type "[" #len "]", #item, \
  248. offsetof(typeof(field), item), \
  249. sizeof(field.item), 0); \
  250. if (ret) \
  251. return ret;
  252. #undef __dynamic_array
  253. #define __dynamic_array(type, item, len) \
  254. ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
  255. offsetof(typeof(field), __data_loc_##item), \
  256. sizeof(field.__data_loc_##item), 0);
  257. #undef __string
  258. #define __string(item, src) __dynamic_array(char, item, -1)
  259. #undef TRACE_EVENT
  260. #define TRACE_EVENT(call, proto, args, tstruct, func, print) \
  261. int \
  262. ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
  263. { \
  264. struct ftrace_raw_##call field; \
  265. int ret; \
  266. \
  267. ret = trace_define_common_fields(event_call); \
  268. if (ret) \
  269. return ret; \
  270. \
  271. tstruct; \
  272. \
  273. return ret; \
  274. }
  275. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  276. /*
  277. * remember the offset of each array from the beginning of the event.
  278. */
  279. #undef __entry
  280. #define __entry entry
  281. #undef __field
  282. #define __field(type, item)
  283. #undef __array
  284. #define __array(type, item, len)
  285. #undef __dynamic_array
  286. #define __dynamic_array(type, item, len) \
  287. __data_offsets->item = __data_size + \
  288. offsetof(typeof(*entry), __data); \
  289. __data_offsets->item |= (len * sizeof(type)) << 16; \
  290. __data_size += (len) * sizeof(type);
  291. #undef __string
  292. #define __string(item, src) __dynamic_array(char, item, strlen(src) + 1) \
  293. #undef TRACE_EVENT
  294. #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
  295. static inline int ftrace_get_offsets_##call( \
  296. struct ftrace_data_offsets_##call *__data_offsets, proto) \
  297. { \
  298. int __data_size = 0; \
  299. struct ftrace_raw_##call __maybe_unused *entry; \
  300. \
  301. tstruct; \
  302. \
  303. return __data_size; \
  304. }
  305. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  306. #ifdef CONFIG_EVENT_PROFILE
  307. /*
  308. * Generate the functions needed for tracepoint perf_counter support.
  309. *
  310. * NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later
  311. *
  312. * static int ftrace_profile_enable_<call>(struct ftrace_event_call *event_call)
  313. * {
  314. * int ret = 0;
  315. *
  316. * if (!atomic_inc_return(&event_call->profile_count))
  317. * ret = register_trace_<call>(ftrace_profile_<call>);
  318. *
  319. * return ret;
  320. * }
  321. *
  322. * static void ftrace_profile_disable_<call>(struct ftrace_event_call *event_call)
  323. * {
  324. * if (atomic_add_negative(-1, &event->call->profile_count))
  325. * unregister_trace_<call>(ftrace_profile_<call>);
  326. * }
  327. *
  328. */
  329. #undef TRACE_EVENT
  330. #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
  331. \
  332. static void ftrace_profile_##call(proto); \
  333. \
  334. static int ftrace_profile_enable_##call(struct ftrace_event_call *event_call) \
  335. { \
  336. int ret = 0; \
  337. \
  338. if (!atomic_inc_return(&event_call->profile_count)) \
  339. ret = register_trace_##call(ftrace_profile_##call); \
  340. \
  341. return ret; \
  342. } \
  343. \
  344. static void ftrace_profile_disable_##call(struct ftrace_event_call *event_call)\
  345. { \
  346. if (atomic_add_negative(-1, &event_call->profile_count)) \
  347. unregister_trace_##call(ftrace_profile_##call); \
  348. }
  349. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  350. #endif
  351. /*
  352. * Stage 4 of the trace events.
  353. *
  354. * Override the macros in <trace/trace_events.h> to include the following:
  355. *
  356. * static void ftrace_event_<call>(proto)
  357. * {
  358. * event_trace_printk(_RET_IP_, "<call>: " <fmt>);
  359. * }
  360. *
  361. * static int ftrace_reg_event_<call>(void)
  362. * {
  363. * int ret;
  364. *
  365. * ret = register_trace_<call>(ftrace_event_<call>);
  366. * if (!ret)
  367. * pr_info("event trace: Could not activate trace point "
  368. * "probe to <call>");
  369. * return ret;
  370. * }
  371. *
  372. * static void ftrace_unreg_event_<call>(void)
  373. * {
  374. * unregister_trace_<call>(ftrace_event_<call>);
  375. * }
  376. *
  377. *
  378. * For those macros defined with TRACE_EVENT:
  379. *
  380. * static struct ftrace_event_call event_<call>;
  381. *
  382. * static void ftrace_raw_event_<call>(proto)
  383. * {
  384. * struct ring_buffer_event *event;
  385. * struct ftrace_raw_<call> *entry; <-- defined in stage 1
  386. * unsigned long irq_flags;
  387. * int pc;
  388. *
  389. * local_save_flags(irq_flags);
  390. * pc = preempt_count();
  391. *
  392. * event = trace_current_buffer_lock_reserve(event_<call>.id,
  393. * sizeof(struct ftrace_raw_<call>),
  394. * irq_flags, pc);
  395. * if (!event)
  396. * return;
  397. * entry = ring_buffer_event_data(event);
  398. *
  399. * <assign>; <-- Here we assign the entries by the __field and
  400. * __array macros.
  401. *
  402. * trace_current_buffer_unlock_commit(event, irq_flags, pc);
  403. * }
  404. *
  405. * static int ftrace_raw_reg_event_<call>(void)
  406. * {
  407. * int ret;
  408. *
  409. * ret = register_trace_<call>(ftrace_raw_event_<call>);
  410. * if (!ret)
  411. * pr_info("event trace: Could not activate trace point "
  412. * "probe to <call>");
  413. * return ret;
  414. * }
  415. *
  416. * static void ftrace_unreg_event_<call>(void)
  417. * {
  418. * unregister_trace_<call>(ftrace_raw_event_<call>);
  419. * }
  420. *
  421. * static struct trace_event ftrace_event_type_<call> = {
  422. * .trace = ftrace_raw_output_<call>, <-- stage 2
  423. * };
  424. *
  425. * static int ftrace_raw_init_event_<call>(void)
  426. * {
  427. * int id;
  428. *
  429. * id = register_ftrace_event(&ftrace_event_type_<call>);
  430. * if (!id)
  431. * return -ENODEV;
  432. * event_<call>.id = id;
  433. * return 0;
  434. * }
  435. *
  436. * static struct ftrace_event_call __used
  437. * __attribute__((__aligned__(4)))
  438. * __attribute__((section("_ftrace_events"))) event_<call> = {
  439. * .name = "<call>",
  440. * .system = "<system>",
  441. * .raw_init = ftrace_raw_init_event_<call>,
  442. * .regfunc = ftrace_reg_event_<call>,
  443. * .unregfunc = ftrace_unreg_event_<call>,
  444. * .show_format = ftrace_format_<call>,
  445. * }
  446. *
  447. */
  448. #undef TP_FMT
  449. #define TP_FMT(fmt, args...) fmt "\n", ##args
  450. #ifdef CONFIG_EVENT_PROFILE
  451. #define _TRACE_PROFILE_INIT(call) \
  452. .profile_count = ATOMIC_INIT(-1), \
  453. .profile_enable = ftrace_profile_enable_##call, \
  454. .profile_disable = ftrace_profile_disable_##call,
  455. #else
  456. #define _TRACE_PROFILE_INIT(call)
  457. #endif
  458. #undef __entry
  459. #define __entry entry
  460. #undef __field
  461. #define __field(type, item)
  462. #undef __array
  463. #define __array(type, item, len)
  464. #undef __dynamic_array
  465. #define __dynamic_array(type, item, len) \
  466. __entry->__data_loc_##item = __data_offsets.item;
  467. #undef __string
  468. #define __string(item, src) __dynamic_array(char, item, -1) \
  469. #undef __assign_str
  470. #define __assign_str(dst, src) \
  471. strcpy(__get_str(dst), src);
  472. #undef TRACE_EVENT
  473. #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
  474. \
  475. static struct ftrace_event_call event_##call; \
  476. \
  477. static void ftrace_raw_event_##call(proto) \
  478. { \
  479. struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
  480. struct ftrace_event_call *event_call = &event_##call; \
  481. struct ring_buffer_event *event; \
  482. struct ftrace_raw_##call *entry; \
  483. unsigned long irq_flags; \
  484. int __data_size; \
  485. int pc; \
  486. \
  487. local_save_flags(irq_flags); \
  488. pc = preempt_count(); \
  489. \
  490. __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
  491. \
  492. event = trace_current_buffer_lock_reserve(event_##call.id, \
  493. sizeof(*entry) + __data_size, \
  494. irq_flags, pc); \
  495. if (!event) \
  496. return; \
  497. entry = ring_buffer_event_data(event); \
  498. \
  499. \
  500. tstruct \
  501. \
  502. { assign; } \
  503. \
  504. if (!filter_current_check_discard(event_call, entry, event)) \
  505. trace_nowake_buffer_unlock_commit(event, irq_flags, pc); \
  506. } \
  507. \
  508. static int ftrace_raw_reg_event_##call(void *ptr) \
  509. { \
  510. int ret; \
  511. \
  512. ret = register_trace_##call(ftrace_raw_event_##call); \
  513. if (ret) \
  514. pr_info("event trace: Could not activate trace point " \
  515. "probe to " #call "\n"); \
  516. return ret; \
  517. } \
  518. \
  519. static void ftrace_raw_unreg_event_##call(void *ptr) \
  520. { \
  521. unregister_trace_##call(ftrace_raw_event_##call); \
  522. } \
  523. \
  524. static struct trace_event ftrace_event_type_##call = { \
  525. .trace = ftrace_raw_output_##call, \
  526. }; \
  527. \
  528. static int ftrace_raw_init_event_##call(void) \
  529. { \
  530. int id; \
  531. \
  532. id = register_ftrace_event(&ftrace_event_type_##call); \
  533. if (!id) \
  534. return -ENODEV; \
  535. event_##call.id = id; \
  536. INIT_LIST_HEAD(&event_##call.fields); \
  537. init_preds(&event_##call); \
  538. return 0; \
  539. } \
  540. \
  541. static struct ftrace_event_call __used \
  542. __attribute__((__aligned__(4))) \
  543. __attribute__((section("_ftrace_events"))) event_##call = { \
  544. .name = #call, \
  545. .system = __stringify(TRACE_SYSTEM), \
  546. .event = &ftrace_event_type_##call, \
  547. .raw_init = ftrace_raw_init_event_##call, \
  548. .regfunc = ftrace_raw_reg_event_##call, \
  549. .unregfunc = ftrace_raw_unreg_event_##call, \
  550. .show_format = ftrace_format_##call, \
  551. .define_fields = ftrace_define_fields_##call, \
  552. _TRACE_PROFILE_INIT(call) \
  553. }
  554. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  555. /*
  556. * Define the insertion callback to profile events
  557. *
  558. * The job is very similar to ftrace_raw_event_<call> except that we don't
  559. * insert in the ring buffer but in a perf counter.
  560. *
  561. * static void ftrace_profile_<call>(proto)
  562. * {
  563. * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
  564. * struct ftrace_event_call *event_call = &event_<call>;
  565. * extern void perf_tpcounter_event(int, u64, u64, void *, int);
  566. * struct ftrace_raw_##call *entry;
  567. * u64 __addr = 0, __count = 1;
  568. * unsigned long irq_flags;
  569. * int __entry_size;
  570. * int __data_size;
  571. * int pc;
  572. *
  573. * local_save_flags(irq_flags);
  574. * pc = preempt_count();
  575. *
  576. * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
  577. *
  578. * // Below we want to get the aligned size by taking into account
  579. * // the u32 field that will later store the buffer size
  580. * __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),
  581. * sizeof(u64));
  582. * __entry_size -= sizeof(u32);
  583. *
  584. * do {
  585. * char raw_data[__entry_size]; <- allocate our sample in the stack
  586. * struct trace_entry *ent;
  587. *
  588. * zero dead bytes from alignment to avoid stack leak to userspace:
  589. *
  590. * *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL;
  591. * entry = (struct ftrace_raw_<call> *)raw_data;
  592. * ent = &entry->ent;
  593. * tracing_generic_entry_update(ent, irq_flags, pc);
  594. * ent->type = event_call->id;
  595. *
  596. * <tstruct> <- do some jobs with dynamic arrays
  597. *
  598. * <assign> <- affect our values
  599. *
  600. * perf_tpcounter_event(event_call->id, __addr, __count, entry,
  601. * __entry_size); <- submit them to perf counter
  602. * } while (0);
  603. *
  604. * }
  605. */
  606. #ifdef CONFIG_EVENT_PROFILE
  607. #undef __perf_addr
  608. #define __perf_addr(a) __addr = (a)
  609. #undef __perf_count
  610. #define __perf_count(c) __count = (c)
  611. #undef TRACE_EVENT
  612. #define TRACE_EVENT(call, proto, args, tstruct, assign, print) \
  613. static void ftrace_profile_##call(proto) \
  614. { \
  615. struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
  616. struct ftrace_event_call *event_call = &event_##call; \
  617. extern void perf_tpcounter_event(int, u64, u64, void *, int); \
  618. struct ftrace_raw_##call *entry; \
  619. u64 __addr = 0, __count = 1; \
  620. unsigned long irq_flags; \
  621. int __entry_size; \
  622. int __data_size; \
  623. int pc; \
  624. \
  625. local_save_flags(irq_flags); \
  626. pc = preempt_count(); \
  627. \
  628. __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
  629. __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
  630. sizeof(u64)); \
  631. __entry_size -= sizeof(u32); \
  632. \
  633. do { \
  634. char raw_data[__entry_size]; \
  635. struct trace_entry *ent; \
  636. \
  637. *(u64 *)(&raw_data[__entry_size - sizeof(u64)]) = 0ULL; \
  638. entry = (struct ftrace_raw_##call *)raw_data; \
  639. ent = &entry->ent; \
  640. tracing_generic_entry_update(ent, irq_flags, pc); \
  641. ent->type = event_call->id; \
  642. \
  643. tstruct \
  644. \
  645. { assign; } \
  646. \
  647. perf_tpcounter_event(event_call->id, __addr, __count, entry,\
  648. __entry_size); \
  649. } while (0); \
  650. \
  651. }
  652. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  653. #endif /* CONFIG_EVENT_PROFILE */
  654. #undef _TRACE_PROFILE_INIT