ftrace.h 20 KB

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