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