trace_export.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * trace_export.c - export basic ftrace utilities to user space
  4. *
  5. * Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com>
  6. */
  7. #include <linux/stringify.h>
  8. #include <linux/kallsyms.h>
  9. #include <linux/seq_file.h>
  10. #include <linux/uaccess.h>
  11. #include <linux/ftrace.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include "trace_output.h"
  15. /* Stub function for events with triggers */
  16. static int ftrace_event_register(struct trace_event_call *call,
  17. enum trace_reg type, void *data)
  18. {
  19. return 0;
  20. }
  21. #undef TRACE_SYSTEM
  22. #define TRACE_SYSTEM ftrace
  23. /*
  24. * The FTRACE_ENTRY_REG macro allows ftrace entry to define register
  25. * function and thus become accessible via perf.
  26. */
  27. #undef FTRACE_ENTRY_REG
  28. #define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, regfn) \
  29. FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
  30. /* not needed for this file */
  31. #undef __field_struct
  32. #define __field_struct(type, item)
  33. #undef __field
  34. #define __field(type, item) type item;
  35. #undef __field_fn
  36. #define __field_fn(type, item) type item;
  37. #undef __field_desc
  38. #define __field_desc(type, container, item) type item;
  39. #undef __field_packed
  40. #define __field_packed(type, container, item) type item;
  41. #undef __array
  42. #define __array(type, item, size) type item[size];
  43. #undef __stack_array
  44. #define __stack_array(type, item, size, field) __array(type, item, size)
  45. #undef __array_desc
  46. #define __array_desc(type, container, item, size) type item[size];
  47. #undef __dynamic_array
  48. #define __dynamic_array(type, item) type item[];
  49. #undef F_STRUCT
  50. #define F_STRUCT(args...) args
  51. #undef F_printk
  52. #define F_printk(fmt, args...) fmt, args
  53. #undef FTRACE_ENTRY
  54. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
  55. struct ____ftrace_##name { \
  56. tstruct \
  57. }; \
  58. static void __always_unused ____ftrace_check_##name(void) \
  59. { \
  60. struct ____ftrace_##name *__entry = NULL; \
  61. \
  62. /* force compile-time check on F_printk() */ \
  63. printk(print); \
  64. }
  65. #undef FTRACE_ENTRY_DUP
  66. #define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print) \
  67. FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
  68. #include "trace_entries.h"
  69. #undef __field_ext
  70. #define __field_ext(_type, _item, _filter_type) { \
  71. .type = #_type, .name = #_item, \
  72. .size = sizeof(_type), .align = __alignof__(_type), \
  73. is_signed_type(_type), .filter_type = _filter_type },
  74. #undef __field_ext_packed
  75. #define __field_ext_packed(_type, _item, _filter_type) { \
  76. .type = #_type, .name = #_item, \
  77. .size = sizeof(_type), .align = 1, \
  78. is_signed_type(_type), .filter_type = _filter_type },
  79. #undef __field
  80. #define __field(_type, _item) __field_ext(_type, _item, FILTER_OTHER)
  81. #undef __field_fn
  82. #define __field_fn(_type, _item) __field_ext(_type, _item, FILTER_TRACE_FN)
  83. #undef __field_desc
  84. #define __field_desc(_type, _container, _item) __field_ext(_type, _item, FILTER_OTHER)
  85. #undef __field_packed
  86. #define __field_packed(_type, _container, _item) __field_ext_packed(_type, _item, FILTER_OTHER)
  87. #undef __array
  88. #define __array(_type, _item, _len) { \
  89. .type = #_type"["__stringify(_len)"]", .name = #_item, \
  90. .size = sizeof(_type[_len]), .align = __alignof__(_type), \
  91. is_signed_type(_type), .filter_type = FILTER_OTHER, \
  92. .len = _len },
  93. #undef __stack_array
  94. #define __stack_array(_type, _item, _len, _field) __array(_type, _item, _len)
  95. #undef __array_desc
  96. #define __array_desc(_type, _container, _item, _len) __array(_type, _item, _len)
  97. #undef __dynamic_array
  98. #define __dynamic_array(_type, _item) { \
  99. .type = #_type "[]", .name = #_item, \
  100. .size = 0, .align = __alignof__(_type), \
  101. is_signed_type(_type), .filter_type = FILTER_OTHER },
  102. #undef FTRACE_ENTRY
  103. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
  104. static struct trace_event_fields ftrace_event_fields_##name[] = { \
  105. tstruct \
  106. {} };
  107. #include "trace_entries.h"
  108. #undef __entry
  109. #define __entry REC
  110. #undef __field
  111. #define __field(type, item)
  112. #undef __field_fn
  113. #define __field_fn(type, item)
  114. #undef __field_desc
  115. #define __field_desc(type, container, item)
  116. #undef __field_packed
  117. #define __field_packed(type, container, item)
  118. #undef __array
  119. #define __array(type, item, len)
  120. #undef __stack_array
  121. #define __stack_array(type, item, len, field)
  122. #undef __array_desc
  123. #define __array_desc(type, container, item, len)
  124. #undef __dynamic_array
  125. #define __dynamic_array(type, item)
  126. #undef F_printk
  127. #define F_printk(fmt, args...) __stringify(fmt) ", " __stringify(args)
  128. #undef FTRACE_ENTRY_REG
  129. #define FTRACE_ENTRY_REG(call, struct_name, etype, tstruct, print, regfn) \
  130. static struct trace_event_class __refdata event_class_ftrace_##call = { \
  131. .system = __stringify(TRACE_SYSTEM), \
  132. .fields_array = ftrace_event_fields_##call, \
  133. .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
  134. .reg = regfn, \
  135. }; \
  136. \
  137. struct trace_event_call __used event_##call = { \
  138. .class = &event_class_ftrace_##call, \
  139. { \
  140. .name = #call, \
  141. }, \
  142. .event.type = etype, \
  143. .print_fmt = print, \
  144. .flags = TRACE_EVENT_FL_IGNORE_ENABLE, \
  145. }; \
  146. static struct trace_event_call __used \
  147. __section("_ftrace_events") *__event_##call = &event_##call;
  148. #undef FTRACE_ENTRY
  149. #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print) \
  150. FTRACE_ENTRY_REG(call, struct_name, etype, \
  151. PARAMS(tstruct), PARAMS(print), NULL)
  152. bool ftrace_event_is_function(struct trace_event_call *call)
  153. {
  154. return call == &event_function;
  155. }
  156. #include "trace_entries.h"