ftrace_event.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. #ifndef _LINUX_FTRACE_EVENT_H
  2. #define _LINUX_FTRACE_EVENT_H
  3. #include <linux/ring_buffer.h>
  4. #include <linux/trace_seq.h>
  5. #include <linux/percpu.h>
  6. #include <linux/hardirq.h>
  7. #include <linux/perf_event.h>
  8. struct trace_array;
  9. struct tracer;
  10. struct dentry;
  11. struct trace_print_flags {
  12. unsigned long mask;
  13. const char *name;
  14. };
  15. struct trace_print_flags_u64 {
  16. unsigned long long mask;
  17. const char *name;
  18. };
  19. const char *ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
  20. unsigned long flags,
  21. const struct trace_print_flags *flag_array);
  22. const char *ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
  23. const struct trace_print_flags *symbol_array);
  24. #if BITS_PER_LONG == 32
  25. const char *ftrace_print_symbols_seq_u64(struct trace_seq *p,
  26. unsigned long long val,
  27. const struct trace_print_flags_u64
  28. *symbol_array);
  29. #endif
  30. const char *ftrace_print_hex_seq(struct trace_seq *p,
  31. const unsigned char *buf, int len);
  32. /*
  33. * The trace entry - the most basic unit of tracing. This is what
  34. * is printed in the end as a single line in the trace output, such as:
  35. *
  36. * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
  37. */
  38. struct trace_entry {
  39. unsigned short type;
  40. unsigned char flags;
  41. unsigned char preempt_count;
  42. int pid;
  43. int padding;
  44. };
  45. #define FTRACE_MAX_EVENT \
  46. ((1 << (sizeof(((struct trace_entry *)0)->type) * 8)) - 1)
  47. /*
  48. * Trace iterator - used by printout routines who present trace
  49. * results to users and which routines might sleep, etc:
  50. */
  51. struct trace_iterator {
  52. struct trace_array *tr;
  53. struct tracer *trace;
  54. void *private;
  55. int cpu_file;
  56. struct mutex mutex;
  57. struct ring_buffer_iter **buffer_iter;
  58. unsigned long iter_flags;
  59. /* trace_seq for __print_flags() and __print_symbolic() etc. */
  60. struct trace_seq tmp_seq;
  61. /* The below is zeroed out in pipe_read */
  62. struct trace_seq seq;
  63. struct trace_entry *ent;
  64. unsigned long lost_events;
  65. int leftover;
  66. int ent_size;
  67. int cpu;
  68. u64 ts;
  69. loff_t pos;
  70. long idx;
  71. cpumask_var_t started;
  72. };
  73. enum trace_iter_flags {
  74. TRACE_FILE_LAT_FMT = 1,
  75. TRACE_FILE_ANNOTATE = 2,
  76. TRACE_FILE_TIME_IN_NS = 4,
  77. };
  78. struct trace_event;
  79. typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter,
  80. int flags, struct trace_event *event);
  81. struct trace_event_functions {
  82. trace_print_func trace;
  83. trace_print_func raw;
  84. trace_print_func hex;
  85. trace_print_func binary;
  86. };
  87. struct trace_event {
  88. struct hlist_node node;
  89. struct list_head list;
  90. int type;
  91. struct trace_event_functions *funcs;
  92. };
  93. extern int register_ftrace_event(struct trace_event *event);
  94. extern int unregister_ftrace_event(struct trace_event *event);
  95. /* Return values for print_line callback */
  96. enum print_line_t {
  97. TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
  98. TRACE_TYPE_HANDLED = 1,
  99. TRACE_TYPE_UNHANDLED = 2, /* Relay to other output functions */
  100. TRACE_TYPE_NO_CONSUME = 3 /* Handled but ask to not consume */
  101. };
  102. void tracing_generic_entry_update(struct trace_entry *entry,
  103. unsigned long flags,
  104. int pc);
  105. struct ring_buffer_event *
  106. trace_current_buffer_lock_reserve(struct ring_buffer **current_buffer,
  107. int type, unsigned long len,
  108. unsigned long flags, int pc);
  109. void trace_current_buffer_unlock_commit(struct ring_buffer *buffer,
  110. struct ring_buffer_event *event,
  111. unsigned long flags, int pc);
  112. void trace_buffer_unlock_commit(struct ring_buffer *buffer,
  113. struct ring_buffer_event *event,
  114. unsigned long flags, int pc);
  115. void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer,
  116. struct ring_buffer_event *event,
  117. unsigned long flags, int pc,
  118. struct pt_regs *regs);
  119. void trace_current_buffer_discard_commit(struct ring_buffer *buffer,
  120. struct ring_buffer_event *event);
  121. void tracing_record_cmdline(struct task_struct *tsk);
  122. struct event_filter;
  123. enum trace_reg {
  124. TRACE_REG_REGISTER,
  125. TRACE_REG_UNREGISTER,
  126. #ifdef CONFIG_PERF_EVENTS
  127. TRACE_REG_PERF_REGISTER,
  128. TRACE_REG_PERF_UNREGISTER,
  129. TRACE_REG_PERF_OPEN,
  130. TRACE_REG_PERF_CLOSE,
  131. TRACE_REG_PERF_ADD,
  132. TRACE_REG_PERF_DEL,
  133. #endif
  134. };
  135. struct ftrace_event_call;
  136. struct ftrace_event_class {
  137. char *system;
  138. void *probe;
  139. #ifdef CONFIG_PERF_EVENTS
  140. void *perf_probe;
  141. #endif
  142. int (*reg)(struct ftrace_event_call *event,
  143. enum trace_reg type, void *data);
  144. int (*define_fields)(struct ftrace_event_call *);
  145. struct list_head *(*get_fields)(struct ftrace_event_call *);
  146. struct list_head fields;
  147. int (*raw_init)(struct ftrace_event_call *);
  148. };
  149. extern int ftrace_event_reg(struct ftrace_event_call *event,
  150. enum trace_reg type, void *data);
  151. enum {
  152. TRACE_EVENT_FL_ENABLED_BIT,
  153. TRACE_EVENT_FL_FILTERED_BIT,
  154. TRACE_EVENT_FL_RECORDED_CMD_BIT,
  155. TRACE_EVENT_FL_CAP_ANY_BIT,
  156. TRACE_EVENT_FL_NO_SET_FILTER_BIT,
  157. TRACE_EVENT_FL_IGNORE_ENABLE_BIT,
  158. };
  159. enum {
  160. TRACE_EVENT_FL_ENABLED = (1 << TRACE_EVENT_FL_ENABLED_BIT),
  161. TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT),
  162. TRACE_EVENT_FL_RECORDED_CMD = (1 << TRACE_EVENT_FL_RECORDED_CMD_BIT),
  163. TRACE_EVENT_FL_CAP_ANY = (1 << TRACE_EVENT_FL_CAP_ANY_BIT),
  164. TRACE_EVENT_FL_NO_SET_FILTER = (1 << TRACE_EVENT_FL_NO_SET_FILTER_BIT),
  165. TRACE_EVENT_FL_IGNORE_ENABLE = (1 << TRACE_EVENT_FL_IGNORE_ENABLE_BIT),
  166. };
  167. struct ftrace_event_call {
  168. struct list_head list;
  169. struct ftrace_event_class *class;
  170. char *name;
  171. struct dentry *dir;
  172. struct trace_event event;
  173. const char *print_fmt;
  174. struct event_filter *filter;
  175. void *mod;
  176. void *data;
  177. /*
  178. * 32 bit flags:
  179. * bit 1: enabled
  180. * bit 2: filter_active
  181. * bit 3: enabled cmd record
  182. * bit 4: allow trace by non root (cap any)
  183. * bit 5: failed to apply filter
  184. * bit 6: ftrace internal event (do not enable)
  185. *
  186. * Changes to flags must hold the event_mutex.
  187. *
  188. * Note: Reads of flags do not hold the event_mutex since
  189. * they occur in critical sections. But the way flags
  190. * is currently used, these changes do no affect the code
  191. * except that when a change is made, it may have a slight
  192. * delay in propagating the changes to other CPUs due to
  193. * caching and such.
  194. */
  195. unsigned int flags;
  196. #ifdef CONFIG_PERF_EVENTS
  197. int perf_refcount;
  198. struct hlist_head __percpu *perf_events;
  199. #endif
  200. };
  201. #define __TRACE_EVENT_FLAGS(name, value) \
  202. static int __init trace_init_flags_##name(void) \
  203. { \
  204. event_##name.flags = value; \
  205. return 0; \
  206. } \
  207. early_initcall(trace_init_flags_##name);
  208. #define PERF_MAX_TRACE_SIZE 2048
  209. #define MAX_FILTER_STR_VAL 256 /* Should handle KSYM_SYMBOL_LEN */
  210. extern void destroy_preds(struct ftrace_event_call *call);
  211. extern int filter_match_preds(struct event_filter *filter, void *rec);
  212. extern int filter_current_check_discard(struct ring_buffer *buffer,
  213. struct ftrace_event_call *call,
  214. void *rec,
  215. struct ring_buffer_event *event);
  216. enum {
  217. FILTER_OTHER = 0,
  218. FILTER_STATIC_STRING,
  219. FILTER_DYN_STRING,
  220. FILTER_PTR_STRING,
  221. FILTER_TRACE_FN,
  222. };
  223. #define EVENT_STORAGE_SIZE 128
  224. extern struct mutex event_storage_mutex;
  225. extern char event_storage[EVENT_STORAGE_SIZE];
  226. extern int trace_event_raw_init(struct ftrace_event_call *call);
  227. extern int trace_define_field(struct ftrace_event_call *call, const char *type,
  228. const char *name, int offset, int size,
  229. int is_signed, int filter_type);
  230. extern int trace_add_event_call(struct ftrace_event_call *call);
  231. extern void trace_remove_event_call(struct ftrace_event_call *call);
  232. #define is_signed_type(type) (((type)(-1)) < 0)
  233. int trace_set_clr_event(const char *system, const char *event, int set);
  234. /*
  235. * The double __builtin_constant_p is because gcc will give us an error
  236. * if we try to allocate the static variable to fmt if it is not a
  237. * constant. Even with the outer if statement optimizing out.
  238. */
  239. #define event_trace_printk(ip, fmt, args...) \
  240. do { \
  241. __trace_printk_check_format(fmt, ##args); \
  242. tracing_record_cmdline(current); \
  243. if (__builtin_constant_p(fmt)) { \
  244. static const char *trace_printk_fmt \
  245. __attribute__((section("__trace_printk_fmt"))) = \
  246. __builtin_constant_p(fmt) ? fmt : NULL; \
  247. \
  248. __trace_bprintk(ip, trace_printk_fmt, ##args); \
  249. } else \
  250. __trace_printk(ip, fmt, ##args); \
  251. } while (0)
  252. #ifdef CONFIG_PERF_EVENTS
  253. struct perf_event;
  254. DECLARE_PER_CPU(struct pt_regs, perf_trace_regs);
  255. extern int perf_trace_init(struct perf_event *event);
  256. extern void perf_trace_destroy(struct perf_event *event);
  257. extern int perf_trace_add(struct perf_event *event, int flags);
  258. extern void perf_trace_del(struct perf_event *event, int flags);
  259. extern int ftrace_profile_set_filter(struct perf_event *event, int event_id,
  260. char *filter_str);
  261. extern void ftrace_profile_free_filter(struct perf_event *event);
  262. extern void *perf_trace_buf_prepare(int size, unsigned short type,
  263. struct pt_regs *regs, int *rctxp);
  264. static inline void
  265. perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr,
  266. u64 count, struct pt_regs *regs, void *head,
  267. struct task_struct *task)
  268. {
  269. perf_tp_event(addr, count, raw_data, size, regs, head, rctx, task);
  270. }
  271. #endif
  272. #endif /* _LINUX_FTRACE_EVENT_H */