ftrace_event.h 8.2 KB

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