trace_export.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 <[email protected]>
  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 __array_desc
  44. #define __array_desc(type, container, item, size) type item[size];
  45. #undef __dynamic_array
  46. #define __dynamic_array(type, item) type item[];
  47. #undef F_STRUCT
  48. #define F_STRUCT(args...) args
  49. #undef F_printk
  50. #define F_printk(fmt, args...) fmt, args
  51. #undef FTRACE_ENTRY
  52. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
  53. struct ____ftrace_##name { \
  54. tstruct \
  55. }; \
  56. static void __always_unused ____ftrace_check_##name(void) \
  57. { \
  58. struct ____ftrace_##name *__entry = NULL; \
  59. \
  60. /* force compile-time check on F_printk() */ \
  61. printk(print); \
  62. }
  63. #undef FTRACE_ENTRY_DUP
  64. #define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print) \
  65. FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
  66. #include "trace_entries.h"
  67. #undef __field_ext
  68. #define __field_ext(_type, _item, _filter_type) { \
  69. .type = #_type, .name = #_item, \
  70. .size = sizeof(_type), .align = __alignof__(_type), \
  71. is_signed_type(_type), .filter_type = _filter_type },
  72. #undef __field_ext_packed
  73. #define __field_ext_packed(_type, _item, _filter_type) { \
  74. .type = #_type, .name = #_item, \
  75. .size = sizeof(_type), .align = 1, \
  76. is_signed_type(_type), .filter_type = _filter_type },
  77. #undef __field
  78. #define __field(_type, _item) __field_ext(_type, _item, FILTER_OTHER)
  79. #undef __field_fn
  80. #define __field_fn(_type, _item) __field_ext(_type, _item, FILTER_TRACE_FN)
  81. #undef __field_desc
  82. #define __field_desc(_type, _container, _item) __field_ext(_type, _item, FILTER_OTHER)
  83. #undef __field_packed
  84. #define __field_packed(_type, _container, _item) __field_ext_packed(_type, _item, FILTER_OTHER)
  85. #undef __array
  86. #define __array(_type, _item, _len) { \
  87. .type = #_type"["__stringify(_len)"]", .name = #_item, \
  88. .size = sizeof(_type[_len]), .align = __alignof__(_type), \
  89. is_signed_type(_type), .filter_type = FILTER_OTHER, \
  90. .len = _len },
  91. #undef __array_desc
  92. #define __array_desc(_type, _container, _item, _len) __array(_type, _item, _len)
  93. #undef __dynamic_array
  94. #define __dynamic_array(_type, _item) { \
  95. .type = #_type "[]", .name = #_item, \
  96. .size = 0, .align = __alignof__(_type), \
  97. is_signed_type(_type), .filter_type = FILTER_OTHER },
  98. #undef FTRACE_ENTRY
  99. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
  100. static struct trace_event_fields ftrace_event_fields_##name[] = { \
  101. tstruct \
  102. {} };
  103. #include "trace_entries.h"
  104. #undef __entry
  105. #define __entry REC
  106. #undef __field
  107. #define __field(type, item)
  108. #undef __field_fn
  109. #define __field_fn(type, item)
  110. #undef __field_desc
  111. #define __field_desc(type, container, item)
  112. #undef __field_packed
  113. #define __field_packed(type, container, item)
  114. #undef __array
  115. #define __array(type, item, len)
  116. #undef __array_desc
  117. #define __array_desc(type, container, item, len)
  118. #undef __dynamic_array
  119. #define __dynamic_array(type, item)
  120. #undef F_printk
  121. #define F_printk(fmt, args...) __stringify(fmt) ", " __stringify(args)
  122. #undef FTRACE_ENTRY_REG
  123. #define FTRACE_ENTRY_REG(call, struct_name, etype, tstruct, print, regfn) \
  124. static struct trace_event_class __refdata event_class_ftrace_##call = { \
  125. .system = __stringify(TRACE_SYSTEM), \
  126. .fields_array = ftrace_event_fields_##call, \
  127. .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
  128. .reg = regfn, \
  129. }; \
  130. \
  131. struct trace_event_call __used event_##call = { \
  132. .class = &event_class_ftrace_##call, \
  133. { \
  134. .name = #call, \
  135. }, \
  136. .event.type = etype, \
  137. .print_fmt = print, \
  138. .flags = TRACE_EVENT_FL_IGNORE_ENABLE, \
  139. }; \
  140. static struct trace_event_call __used \
  141. __section("_ftrace_events") *__event_##call = &event_##call;
  142. #undef FTRACE_ENTRY
  143. #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print) \
  144. FTRACE_ENTRY_REG(call, struct_name, etype, \
  145. PARAMS(tstruct), PARAMS(print), NULL)
  146. bool ftrace_event_is_function(struct trace_event_call *call)
  147. {
  148. return call == &event_function;
  149. }
  150. #include "trace_entries.h"