ftrace_event.h 7.3 KB

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