ftrace_event.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. int leftover;
  52. int cpu;
  53. u64 ts;
  54. loff_t pos;
  55. long idx;
  56. cpumask_var_t started;
  57. };
  58. typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter,
  59. int flags);
  60. struct trace_event {
  61. struct hlist_node node;
  62. struct list_head list;
  63. int type;
  64. trace_print_func trace;
  65. trace_print_func raw;
  66. trace_print_func hex;
  67. trace_print_func binary;
  68. };
  69. extern int register_ftrace_event(struct trace_event *event);
  70. extern int unregister_ftrace_event(struct trace_event *event);
  71. /* Return values for print_line callback */
  72. enum print_line_t {
  73. TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
  74. TRACE_TYPE_HANDLED = 1,
  75. TRACE_TYPE_UNHANDLED = 2, /* Relay to other output functions */
  76. TRACE_TYPE_NO_CONSUME = 3 /* Handled but ask to not consume */
  77. };
  78. void tracing_generic_entry_update(struct trace_entry *entry,
  79. unsigned long flags,
  80. int pc);
  81. struct ring_buffer_event *
  82. trace_current_buffer_lock_reserve(struct ring_buffer **current_buffer,
  83. int type, unsigned long len,
  84. unsigned long flags, int pc);
  85. void trace_current_buffer_unlock_commit(struct ring_buffer *buffer,
  86. struct ring_buffer_event *event,
  87. unsigned long flags, int pc);
  88. void trace_nowake_buffer_unlock_commit(struct ring_buffer *buffer,
  89. struct ring_buffer_event *event,
  90. unsigned long flags, int pc);
  91. void trace_current_buffer_discard_commit(struct ring_buffer *buffer,
  92. struct ring_buffer_event *event);
  93. void tracing_record_cmdline(struct task_struct *tsk);
  94. struct event_filter;
  95. struct ftrace_event_call {
  96. struct list_head list;
  97. char *name;
  98. char *system;
  99. struct dentry *dir;
  100. struct trace_event *event;
  101. int enabled;
  102. int (*regfunc)(struct ftrace_event_call *);
  103. void (*unregfunc)(struct ftrace_event_call *);
  104. int id;
  105. const char *print_fmt;
  106. int (*raw_init)(struct ftrace_event_call *);
  107. int (*define_fields)(struct ftrace_event_call *);
  108. struct list_head fields;
  109. int filter_active;
  110. struct event_filter *filter;
  111. void *mod;
  112. void *data;
  113. int perf_refcount;
  114. int (*perf_event_enable)(struct ftrace_event_call *);
  115. void (*perf_event_disable)(struct ftrace_event_call *);
  116. };
  117. #define PERF_MAX_TRACE_SIZE 2048
  118. #define MAX_FILTER_PRED 32
  119. #define MAX_FILTER_STR_VAL 256 /* Should handle KSYM_SYMBOL_LEN */
  120. extern void destroy_preds(struct ftrace_event_call *call);
  121. extern int filter_match_preds(struct event_filter *filter, void *rec);
  122. extern int filter_current_check_discard(struct ring_buffer *buffer,
  123. struct ftrace_event_call *call,
  124. void *rec,
  125. struct ring_buffer_event *event);
  126. enum {
  127. FILTER_OTHER = 0,
  128. FILTER_STATIC_STRING,
  129. FILTER_DYN_STRING,
  130. FILTER_PTR_STRING,
  131. };
  132. extern int trace_event_raw_init(struct ftrace_event_call *call);
  133. extern int trace_define_field(struct ftrace_event_call *call, const char *type,
  134. const char *name, int offset, int size,
  135. int is_signed, int filter_type);
  136. extern int trace_add_event_call(struct ftrace_event_call *call);
  137. extern void trace_remove_event_call(struct ftrace_event_call *call);
  138. #define is_signed_type(type) (((type)(-1)) < 0)
  139. int trace_set_clr_event(const char *system, const char *event, int set);
  140. /*
  141. * The double __builtin_constant_p is because gcc will give us an error
  142. * if we try to allocate the static variable to fmt if it is not a
  143. * constant. Even with the outer if statement optimizing out.
  144. */
  145. #define event_trace_printk(ip, fmt, args...) \
  146. do { \
  147. __trace_printk_check_format(fmt, ##args); \
  148. tracing_record_cmdline(current); \
  149. if (__builtin_constant_p(fmt)) { \
  150. static const char *trace_printk_fmt \
  151. __attribute__((section("__trace_printk_fmt"))) = \
  152. __builtin_constant_p(fmt) ? fmt : NULL; \
  153. \
  154. __trace_bprintk(ip, trace_printk_fmt, ##args); \
  155. } else \
  156. __trace_printk(ip, fmt, ##args); \
  157. } while (0)
  158. #ifdef CONFIG_PERF_EVENTS
  159. struct perf_event;
  160. DECLARE_PER_CPU(struct pt_regs, perf_trace_regs);
  161. extern int perf_trace_enable(int event_id);
  162. extern void perf_trace_disable(int event_id);
  163. extern int ftrace_profile_set_filter(struct perf_event *event, int event_id,
  164. char *filter_str);
  165. extern void ftrace_profile_free_filter(struct perf_event *event);
  166. extern void *
  167. perf_trace_buf_prepare(int size, unsigned short type, int *rctxp,
  168. unsigned long *irq_flags);
  169. static inline void
  170. perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr,
  171. u64 count, unsigned long irq_flags, struct pt_regs *regs)
  172. {
  173. struct trace_entry *entry = raw_data;
  174. perf_tp_event(entry->type, addr, count, raw_data, size, regs);
  175. perf_swevent_put_recursion_context(rctx);
  176. local_irq_restore(irq_flags);
  177. }
  178. #endif
  179. #endif /* _LINUX_FTRACE_EVENT_H */