ftrace_event.h 6.7 KB

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