trace_export.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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, 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. #undef __array_desc
  91. #define __array_desc(_type, _container, _item, _len) __array(_type, _item, _len)
  92. #undef __dynamic_array
  93. #define __dynamic_array(_type, _item) { \
  94. .type = #_type "[]", .name = #_item, \
  95. .size = 0, .align = __alignof__(_type), \
  96. is_signed_type(_type), .filter_type = FILTER_OTHER },
  97. #undef FTRACE_ENTRY
  98. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
  99. static struct trace_event_fields ftrace_event_fields_##name[] = { \
  100. tstruct \
  101. {} };
  102. #include "trace_entries.h"
  103. #undef __entry
  104. #define __entry REC
  105. #undef __field
  106. #define __field(type, item)
  107. #undef __field_fn
  108. #define __field_fn(type, item)
  109. #undef __field_desc
  110. #define __field_desc(type, container, item)
  111. #undef __field_packed
  112. #define __field_packed(type, container, item)
  113. #undef __array
  114. #define __array(type, item, len)
  115. #undef __array_desc
  116. #define __array_desc(type, container, item, len)
  117. #undef __dynamic_array
  118. #define __dynamic_array(type, item)
  119. #undef F_printk
  120. #define F_printk(fmt, args...) __stringify(fmt) ", " __stringify(args)
  121. #undef FTRACE_ENTRY_REG
  122. #define FTRACE_ENTRY_REG(call, struct_name, etype, tstruct, print, regfn) \
  123. static struct trace_event_class __refdata event_class_ftrace_##call = { \
  124. .system = __stringify(TRACE_SYSTEM), \
  125. .fields_array = ftrace_event_fields_##call, \
  126. .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
  127. .reg = regfn, \
  128. }; \
  129. \
  130. struct trace_event_call __used event_##call = { \
  131. .class = &event_class_ftrace_##call, \
  132. { \
  133. .name = #call, \
  134. }, \
  135. .event.type = etype, \
  136. .print_fmt = print, \
  137. .flags = TRACE_EVENT_FL_IGNORE_ENABLE, \
  138. }; \
  139. static struct trace_event_call __used \
  140. __section("_ftrace_events") *__event_##call = &event_##call;
  141. #undef FTRACE_ENTRY
  142. #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print) \
  143. FTRACE_ENTRY_REG(call, struct_name, etype, \
  144. PARAMS(tstruct), PARAMS(print), NULL)
  145. bool ftrace_event_is_function(struct trace_event_call *call)
  146. {
  147. return call == &event_function;
  148. }
  149. #include "trace_entries.h"