trace_export.c 5.2 KB

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