ftrace_event.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. struct trace_event;
  74. typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter,
  75. int flags, struct trace_event *event);
  76. struct trace_event_functions {
  77. trace_print_func trace;
  78. trace_print_func raw;
  79. trace_print_func hex;
  80. trace_print_func binary;
  81. };
  82. struct trace_event {
  83. struct hlist_node node;
  84. struct list_head list;
  85. int type;
  86. struct trace_event_functions *funcs;
  87. };
  88. extern int register_ftrace_event(struct trace_event *event);
  89. extern int unregister_ftrace_event(struct trace_event *event);
  90. /* Return values for print_line callback */
  91. enum print_line_t {
  92. TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
  93. TRACE_TYPE_HANDLED = 1,
  94. TRACE_TYPE_UNHANDLED = 2, /* Relay to other output functions */
  95. TRACE_TYPE_NO_CONSUME = 3 /* Handled but ask to not consume */
  96. };
  97. void tracing_generic_entry_update(struct trace_entry *entry,
  98. unsigned long flags,
  99. int pc);
  100. struct ring_buffer_event *
  101. trace_current_buffer_lock_reserve(struct ring_buffer **current_buffer,
  102. int type, unsigned long len,
  103. unsigned long flags, int pc);
  104. void trace_current_buffer_unlock_commit(struct ring_buffer *buffer,
  105. struct ring_buffer_event *event,
  106. unsigned long flags, int pc);
  107. void trace_nowake_buffer_unlock_commit(struct ring_buffer *buffer,
  108. struct ring_buffer_event *event,
  109. unsigned long flags, int pc);
  110. void trace_nowake_buffer_unlock_commit_regs(struct ring_buffer *buffer,
  111. struct ring_buffer_event *event,
  112. unsigned long flags, int pc,
  113. struct pt_regs *regs);
  114. void trace_current_buffer_discard_commit(struct ring_buffer *buffer,
  115. struct ring_buffer_event *event);
  116. void tracing_record_cmdline(struct task_struct *tsk);
  117. struct event_filter;
  118. enum trace_reg {
  119. TRACE_REG_REGISTER,
  120. TRACE_REG_UNREGISTER,
  121. #ifdef CONFIG_PERF_EVENTS
  122. TRACE_REG_PERF_REGISTER,
  123. TRACE_REG_PERF_UNREGISTER,
  124. TRACE_REG_PERF_OPEN,
  125. TRACE_REG_PERF_CLOSE,
  126. TRACE_REG_PERF_ADD,
  127. TRACE_REG_PERF_DEL,
  128. #endif
  129. };
  130. struct ftrace_event_call;
  131. struct ftrace_event_class {
  132. char *system;
  133. void *probe;
  134. #ifdef CONFIG_PERF_EVENTS
  135. void *perf_probe;
  136. #endif
  137. int (*reg)(struct ftrace_event_call *event,
  138. enum trace_reg type, void *data);
  139. int (*define_fields)(struct ftrace_event_call *);
  140. struct list_head *(*get_fields)(struct ftrace_event_call *);
  141. struct list_head fields;
  142. int (*raw_init)(struct ftrace_event_call *);
  143. };
  144. extern int ftrace_event_reg(struct ftrace_event_call *event,
  145. enum trace_reg type, void *data);
  146. enum {
  147. TRACE_EVENT_FL_ENABLED_BIT,
  148. TRACE_EVENT_FL_FILTERED_BIT,
  149. TRACE_EVENT_FL_RECORDED_CMD_BIT,
  150. TRACE_EVENT_FL_CAP_ANY_BIT,
  151. TRACE_EVENT_FL_NO_SET_FILTER_BIT,
  152. TRACE_EVENT_FL_IGNORE_ENABLE_BIT,
  153. };
  154. enum {
  155. TRACE_EVENT_FL_ENABLED = (1 << TRACE_EVENT_FL_ENABLED_BIT),
  156. TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT),
  157. TRACE_EVENT_FL_RECORDED_CMD = (1 << TRACE_EVENT_FL_RECORDED_CMD_BIT),
  158. TRACE_EVENT_FL_CAP_ANY = (1 << TRACE_EVENT_FL_CAP_ANY_BIT),
  159. TRACE_EVENT_FL_NO_SET_FILTER = (1 << TRACE_EVENT_FL_NO_SET_FILTER_BIT),
  160. TRACE_EVENT_FL_IGNORE_ENABLE = (1 << TRACE_EVENT_FL_IGNORE_ENABLE_BIT),
  161. };
  162. struct ftrace_event_call {
  163. struct list_head list;
  164. struct ftrace_event_class *class;
  165. char *name;
  166. struct dentry *dir;
  167. struct trace_event event;
  168. const char *print_fmt;
  169. struct event_filter *filter;
  170. void *mod;
  171. void *data;
  172. /*
  173. * 32 bit flags:
  174. * bit 1: enabled
  175. * bit 2: filter_active
  176. * bit 3: enabled cmd record
  177. * bit 4: allow trace by non root (cap any)
  178. * bit 5: failed to apply filter
  179. * bit 6: ftrace internal event (do not enable)
  180. *
  181. * Changes to flags must hold the event_mutex.
  182. *
  183. * Note: Reads of flags do not hold the event_mutex since
  184. * they occur in critical sections. But the way flags
  185. * is currently used, these changes do no affect the code
  186. * except that when a change is made, it may have a slight
  187. * delay in propagating the changes to other CPUs due to
  188. * caching and such.
  189. */
  190. unsigned int flags;
  191. #ifdef CONFIG_PERF_EVENTS
  192. int perf_refcount;
  193. struct hlist_head __percpu *perf_events;
  194. #endif
  195. };
  196. #define __TRACE_EVENT_FLAGS(name, value) \
  197. static int __init trace_init_flags_##name(void) \
  198. { \
  199. event_##name.flags = value; \
  200. return 0; \
  201. } \
  202. early_initcall(trace_init_flags_##name);
  203. #define PERF_MAX_TRACE_SIZE 2048
  204. #define MAX_FILTER_STR_VAL 256 /* Should handle KSYM_SYMBOL_LEN */
  205. extern void destroy_preds(struct ftrace_event_call *call);
  206. extern int filter_match_preds(struct event_filter *filter, void *rec);
  207. extern int filter_current_check_discard(struct ring_buffer *buffer,
  208. struct ftrace_event_call *call,
  209. void *rec,
  210. struct ring_buffer_event *event);
  211. enum {
  212. FILTER_OTHER = 0,
  213. FILTER_STATIC_STRING,
  214. FILTER_DYN_STRING,
  215. FILTER_PTR_STRING,
  216. FILTER_TRACE_FN,
  217. };
  218. #define EVENT_STORAGE_SIZE 128
  219. extern struct mutex event_storage_mutex;
  220. extern char event_storage[EVENT_STORAGE_SIZE];
  221. extern int trace_event_raw_init(struct ftrace_event_call *call);
  222. extern int trace_define_field(struct ftrace_event_call *call, const char *type,
  223. const char *name, int offset, int size,
  224. int is_signed, int filter_type);
  225. extern int trace_add_event_call(struct ftrace_event_call *call);
  226. extern void trace_remove_event_call(struct ftrace_event_call *call);
  227. #define is_signed_type(type) (((type)(-1)) < 0)
  228. int trace_set_clr_event(const char *system, const char *event, int set);
  229. /*
  230. * The double __builtin_constant_p is because gcc will give us an error
  231. * if we try to allocate the static variable to fmt if it is not a
  232. * constant. Even with the outer if statement optimizing out.
  233. */
  234. #define event_trace_printk(ip, fmt, args...) \
  235. do { \
  236. __trace_printk_check_format(fmt, ##args); \
  237. tracing_record_cmdline(current); \
  238. if (__builtin_constant_p(fmt)) { \
  239. static const char *trace_printk_fmt \
  240. __attribute__((section("__trace_printk_fmt"))) = \
  241. __builtin_constant_p(fmt) ? fmt : NULL; \
  242. \
  243. __trace_bprintk(ip, trace_printk_fmt, ##args); \
  244. } else \
  245. __trace_printk(ip, fmt, ##args); \
  246. } while (0)
  247. #ifdef CONFIG_PERF_EVENTS
  248. struct perf_event;
  249. DECLARE_PER_CPU(struct pt_regs, perf_trace_regs);
  250. extern int perf_trace_init(struct perf_event *event);
  251. extern void perf_trace_destroy(struct perf_event *event);
  252. extern int perf_trace_add(struct perf_event *event, int flags);
  253. extern void perf_trace_del(struct perf_event *event, int flags);
  254. extern int ftrace_profile_set_filter(struct perf_event *event, int event_id,
  255. char *filter_str);
  256. extern void ftrace_profile_free_filter(struct perf_event *event);
  257. extern void *perf_trace_buf_prepare(int size, unsigned short type,
  258. struct pt_regs *regs, int *rctxp);
  259. static inline void
  260. perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr,
  261. u64 count, struct pt_regs *regs, void *head)
  262. {
  263. perf_tp_event(addr, count, raw_data, size, regs, head, rctx);
  264. }
  265. #endif
  266. #endif /* _LINUX_FTRACE_EVENT_H */