ftrace.h 19 KB

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