trace_export.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 accesible via perf.
  26. */
  27. #undef FTRACE_ENTRY_REG
  28. #define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, \
  29. filter, regfn) \
  30. FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  31. filter)
  32. /* not needed for this file */
  33. #undef __field_struct
  34. #define __field_struct(type, item)
  35. #undef __field
  36. #define __field(type, item) type item;
  37. #undef __field_desc
  38. #define __field_desc(type, container, item) type item;
  39. #undef __array
  40. #define __array(type, item, size) type item[size];
  41. #undef __array_desc
  42. #define __array_desc(type, container, item, size) type item[size];
  43. #undef __dynamic_array
  44. #define __dynamic_array(type, item) type item[];
  45. #undef F_STRUCT
  46. #define F_STRUCT(args...) args
  47. #undef F_printk
  48. #define F_printk(fmt, args...) fmt, args
  49. #undef FTRACE_ENTRY
  50. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \
  51. struct ____ftrace_##name { \
  52. tstruct \
  53. }; \
  54. static void __always_unused ____ftrace_check_##name(void) \
  55. { \
  56. struct ____ftrace_##name *__entry = NULL; \
  57. \
  58. /* force compile-time check on F_printk() */ \
  59. printk(print); \
  60. }
  61. #undef FTRACE_ENTRY_DUP
  62. #define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print, filter) \
  63. FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  64. filter)
  65. #include "trace_entries.h"
  66. #undef __field
  67. #define __field(type, item) \
  68. ret = trace_define_field(event_call, #type, #item, \
  69. offsetof(typeof(field), item), \
  70. sizeof(field.item), \
  71. is_signed_type(type), filter_type); \
  72. if (ret) \
  73. return ret;
  74. #undef __field_desc
  75. #define __field_desc(type, container, item) \
  76. ret = trace_define_field(event_call, #type, #item, \
  77. offsetof(typeof(field), \
  78. container.item), \
  79. sizeof(field.container.item), \
  80. is_signed_type(type), filter_type); \
  81. if (ret) \
  82. return ret;
  83. #undef __array
  84. #define __array(type, item, len) \
  85. do { \
  86. char *type_str = #type"["__stringify(len)"]"; \
  87. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  88. ret = trace_define_field(event_call, type_str, #item, \
  89. offsetof(typeof(field), item), \
  90. sizeof(field.item), \
  91. is_signed_type(type), filter_type); \
  92. if (ret) \
  93. return ret; \
  94. } while (0);
  95. #undef __array_desc
  96. #define __array_desc(type, container, item, len) \
  97. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  98. ret = trace_define_field(event_call, #type "[" #len "]", #item, \
  99. offsetof(typeof(field), \
  100. container.item), \
  101. sizeof(field.container.item), \
  102. is_signed_type(type), filter_type); \
  103. if (ret) \
  104. return ret;
  105. #undef __dynamic_array
  106. #define __dynamic_array(type, item) \
  107. ret = trace_define_field(event_call, #type "[]", #item, \
  108. offsetof(typeof(field), item), \
  109. 0, is_signed_type(type), filter_type);\
  110. if (ret) \
  111. return ret;
  112. #undef FTRACE_ENTRY
  113. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \
  114. static int __init \
  115. ftrace_define_fields_##name(struct trace_event_call *event_call) \
  116. { \
  117. struct struct_name field; \
  118. int ret; \
  119. int filter_type = filter; \
  120. \
  121. tstruct; \
  122. \
  123. return ret; \
  124. }
  125. #include "trace_entries.h"
  126. #undef __entry
  127. #define __entry REC
  128. #undef __field
  129. #define __field(type, item)
  130. #undef __field_desc
  131. #define __field_desc(type, container, item)
  132. #undef __array
  133. #define __array(type, item, len)
  134. #undef __array_desc
  135. #define __array_desc(type, container, item, len)
  136. #undef __dynamic_array
  137. #define __dynamic_array(type, item)
  138. #undef F_printk
  139. #define F_printk(fmt, args...) __stringify(fmt) ", " __stringify(args)
  140. #undef FTRACE_ENTRY_REG
  141. #define FTRACE_ENTRY_REG(call, struct_name, etype, tstruct, print, filter,\
  142. regfn) \
  143. \
  144. struct trace_event_class __refdata event_class_ftrace_##call = { \
  145. .system = __stringify(TRACE_SYSTEM), \
  146. .define_fields = ftrace_define_fields_##call, \
  147. .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
  148. .reg = regfn, \
  149. }; \
  150. \
  151. struct trace_event_call __used event_##call = { \
  152. .class = &event_class_ftrace_##call, \
  153. { \
  154. .name = #call, \
  155. }, \
  156. .event.type = etype, \
  157. .print_fmt = print, \
  158. .flags = TRACE_EVENT_FL_IGNORE_ENABLE, \
  159. }; \
  160. struct trace_event_call __used \
  161. __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call;
  162. #undef FTRACE_ENTRY
  163. #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print, filter) \
  164. FTRACE_ENTRY_REG(call, struct_name, etype, \
  165. PARAMS(tstruct), PARAMS(print), filter, NULL)
  166. bool ftrace_event_is_function(struct trace_event_call *call)
  167. {
  168. return call == &event_function;
  169. }
  170. #include "trace_entries.h"