ftrace_event.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 trace_buffer;
  10. struct tracer;
  11. struct dentry;
  12. struct trace_print_flags {
  13. unsigned long mask;
  14. const char *name;
  15. };
  16. struct trace_print_flags_u64 {
  17. unsigned long long mask;
  18. const char *name;
  19. };
  20. const char *ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
  21. unsigned long flags,
  22. const struct trace_print_flags *flag_array);
  23. const char *ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
  24. const struct trace_print_flags *symbol_array);
  25. #if BITS_PER_LONG == 32
  26. const char *ftrace_print_symbols_seq_u64(struct trace_seq *p,
  27. unsigned long long val,
  28. const struct trace_print_flags_u64
  29. *symbol_array);
  30. #endif
  31. const char *ftrace_print_hex_seq(struct trace_seq *p,
  32. const unsigned char *buf, int len);
  33. struct trace_iterator;
  34. struct trace_event;
  35. int ftrace_raw_output_prep(struct trace_iterator *iter,
  36. struct trace_event *event);
  37. /*
  38. * The trace entry - the most basic unit of tracing. This is what
  39. * is printed in the end as a single line in the trace output, such as:
  40. *
  41. * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
  42. */
  43. struct trace_entry {
  44. unsigned short type;
  45. unsigned char flags;
  46. unsigned char preempt_count;
  47. int pid;
  48. };
  49. #define FTRACE_MAX_EVENT \
  50. ((1 << (sizeof(((struct trace_entry *)0)->type) * 8)) - 1)
  51. /*
  52. * Trace iterator - used by printout routines who present trace
  53. * results to users and which routines might sleep, etc:
  54. */
  55. struct trace_iterator {
  56. struct trace_array *tr;
  57. struct tracer *trace;
  58. struct trace_buffer *trace_buffer;
  59. void *private;
  60. int cpu_file;
  61. struct mutex mutex;
  62. struct ring_buffer_iter **buffer_iter;
  63. unsigned long iter_flags;
  64. /* trace_seq for __print_flags() and __print_symbolic() etc. */
  65. struct trace_seq tmp_seq;
  66. /* The below is zeroed out in pipe_read */
  67. struct trace_seq seq;
  68. struct trace_entry *ent;
  69. unsigned long lost_events;
  70. int leftover;
  71. int ent_size;
  72. int cpu;
  73. u64 ts;
  74. loff_t pos;
  75. long idx;
  76. cpumask_var_t started;
  77. /* it's true when current open file is snapshot */
  78. bool snapshot;
  79. };
  80. enum trace_iter_flags {
  81. TRACE_FILE_LAT_FMT = 1,
  82. TRACE_FILE_ANNOTATE = 2,
  83. TRACE_FILE_TIME_IN_NS = 4,
  84. };
  85. typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter,
  86. int flags, struct trace_event *event);
  87. struct trace_event_functions {
  88. trace_print_func trace;
  89. trace_print_func raw;
  90. trace_print_func hex;
  91. trace_print_func binary;
  92. };
  93. struct trace_event {
  94. struct hlist_node node;
  95. struct list_head list;
  96. int type;
  97. struct trace_event_functions *funcs;
  98. };
  99. extern int register_ftrace_event(struct trace_event *event);
  100. extern int unregister_ftrace_event(struct trace_event *event);
  101. /* Return values for print_line callback */
  102. enum print_line_t {
  103. TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
  104. TRACE_TYPE_HANDLED = 1,
  105. TRACE_TYPE_UNHANDLED = 2, /* Relay to other output functions */
  106. TRACE_TYPE_NO_CONSUME = 3 /* Handled but ask to not consume */
  107. };
  108. void tracing_generic_entry_update(struct trace_entry *entry,
  109. unsigned long flags,
  110. int pc);
  111. struct ftrace_event_file;
  112. struct ring_buffer_event *
  113. trace_event_buffer_lock_reserve(struct ring_buffer **current_buffer,
  114. struct ftrace_event_file *ftrace_file,
  115. int type, unsigned long len,
  116. unsigned long flags, int pc);
  117. struct ring_buffer_event *
  118. trace_current_buffer_lock_reserve(struct ring_buffer **current_buffer,
  119. int type, unsigned long len,
  120. unsigned long flags, int pc);
  121. void trace_current_buffer_unlock_commit(struct ring_buffer *buffer,
  122. struct ring_buffer_event *event,
  123. unsigned long flags, int pc);
  124. void trace_buffer_unlock_commit(struct ring_buffer *buffer,
  125. struct ring_buffer_event *event,
  126. unsigned long flags, int pc);
  127. void trace_buffer_unlock_commit_regs(struct ring_buffer *buffer,
  128. struct ring_buffer_event *event,
  129. unsigned long flags, int pc,
  130. struct pt_regs *regs);
  131. void trace_current_buffer_discard_commit(struct ring_buffer *buffer,
  132. struct ring_buffer_event *event);
  133. void tracing_record_cmdline(struct task_struct *tsk);
  134. struct event_filter;
  135. enum trace_reg {
  136. TRACE_REG_REGISTER,
  137. TRACE_REG_UNREGISTER,
  138. #ifdef CONFIG_PERF_EVENTS
  139. TRACE_REG_PERF_REGISTER,
  140. TRACE_REG_PERF_UNREGISTER,
  141. TRACE_REG_PERF_OPEN,
  142. TRACE_REG_PERF_CLOSE,
  143. TRACE_REG_PERF_ADD,
  144. TRACE_REG_PERF_DEL,
  145. #endif
  146. };
  147. struct ftrace_event_call;
  148. struct ftrace_event_class {
  149. char *system;
  150. void *probe;
  151. #ifdef CONFIG_PERF_EVENTS
  152. void *perf_probe;
  153. #endif
  154. int (*reg)(struct ftrace_event_call *event,
  155. enum trace_reg type, void *data);
  156. int (*define_fields)(struct ftrace_event_call *);
  157. struct list_head *(*get_fields)(struct ftrace_event_call *);
  158. struct list_head fields;
  159. int (*raw_init)(struct ftrace_event_call *);
  160. };
  161. extern int ftrace_event_reg(struct ftrace_event_call *event,
  162. enum trace_reg type, void *data);
  163. enum {
  164. TRACE_EVENT_FL_FILTERED_BIT,
  165. TRACE_EVENT_FL_CAP_ANY_BIT,
  166. TRACE_EVENT_FL_NO_SET_FILTER_BIT,
  167. TRACE_EVENT_FL_IGNORE_ENABLE_BIT,
  168. TRACE_EVENT_FL_WAS_ENABLED_BIT,
  169. };
  170. /*
  171. * Event flags:
  172. * FILTERED - The event has a filter attached
  173. * CAP_ANY - Any user can enable for perf
  174. * NO_SET_FILTER - Set when filter has error and is to be ignored
  175. * IGNORE_ENABLE - For ftrace internal events, do not enable with debugfs file
  176. * WAS_ENABLED - Set and stays set when an event was ever enabled
  177. * (used for module unloading, if a module event is enabled,
  178. * it is best to clear the buffers that used it).
  179. */
  180. enum {
  181. TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT),
  182. TRACE_EVENT_FL_CAP_ANY = (1 << TRACE_EVENT_FL_CAP_ANY_BIT),
  183. TRACE_EVENT_FL_NO_SET_FILTER = (1 << TRACE_EVENT_FL_NO_SET_FILTER_BIT),
  184. TRACE_EVENT_FL_IGNORE_ENABLE = (1 << TRACE_EVENT_FL_IGNORE_ENABLE_BIT),
  185. TRACE_EVENT_FL_WAS_ENABLED = (1 << TRACE_EVENT_FL_WAS_ENABLED_BIT),
  186. };
  187. struct ftrace_event_call {
  188. struct list_head list;
  189. struct ftrace_event_class *class;
  190. char *name;
  191. struct trace_event event;
  192. const char *print_fmt;
  193. struct event_filter *filter;
  194. struct list_head *files;
  195. void *mod;
  196. void *data;
  197. /*
  198. * bit 0: filter_active
  199. * bit 1: allow trace by non root (cap any)
  200. * bit 2: failed to apply filter
  201. * bit 3: ftrace internal event (do not enable)
  202. * bit 4: Event was enabled by module
  203. */
  204. int flags; /* static flags of different events */
  205. #ifdef CONFIG_PERF_EVENTS
  206. int perf_refcount;
  207. struct hlist_head __percpu *perf_events;
  208. #endif
  209. };
  210. struct trace_array;
  211. struct ftrace_subsystem_dir;
  212. enum {
  213. FTRACE_EVENT_FL_ENABLED_BIT,
  214. FTRACE_EVENT_FL_RECORDED_CMD_BIT,
  215. };
  216. /*
  217. * Ftrace event file flags:
  218. * ENABLED - The event is enabled
  219. * RECORDED_CMD - The comms should be recorded at sched_switch
  220. */
  221. enum {
  222. FTRACE_EVENT_FL_ENABLED = (1 << FTRACE_EVENT_FL_ENABLED_BIT),
  223. FTRACE_EVENT_FL_RECORDED_CMD = (1 << FTRACE_EVENT_FL_RECORDED_CMD_BIT),
  224. };
  225. struct ftrace_event_file {
  226. struct list_head list;
  227. struct ftrace_event_call *event_call;
  228. struct dentry *dir;
  229. struct trace_array *tr;
  230. struct ftrace_subsystem_dir *system;
  231. /*
  232. * 32 bit flags:
  233. * bit 0: enabled
  234. * bit 1: enabled cmd record
  235. *
  236. * Changes to flags must hold the event_mutex.
  237. *
  238. * Note: Reads of flags do not hold the event_mutex since
  239. * they occur in critical sections. But the way flags
  240. * is currently used, these changes do not affect the code
  241. * except that when a change is made, it may have a slight
  242. * delay in propagating the changes to other CPUs due to
  243. * caching and such.
  244. */
  245. unsigned int flags;
  246. };
  247. #define __TRACE_EVENT_FLAGS(name, value) \
  248. static int __init trace_init_flags_##name(void) \
  249. { \
  250. event_##name.flags = value; \
  251. return 0; \
  252. } \
  253. early_initcall(trace_init_flags_##name);
  254. #define PERF_MAX_TRACE_SIZE 2048
  255. #define MAX_FILTER_STR_VAL 256 /* Should handle KSYM_SYMBOL_LEN */
  256. extern void destroy_preds(struct ftrace_event_call *call);
  257. extern int filter_match_preds(struct event_filter *filter, void *rec);
  258. extern int filter_current_check_discard(struct ring_buffer *buffer,
  259. struct ftrace_event_call *call,
  260. void *rec,
  261. struct ring_buffer_event *event);
  262. enum {
  263. FILTER_OTHER = 0,
  264. FILTER_STATIC_STRING,
  265. FILTER_DYN_STRING,
  266. FILTER_PTR_STRING,
  267. FILTER_TRACE_FN,
  268. };
  269. #define EVENT_STORAGE_SIZE 128
  270. extern struct mutex event_storage_mutex;
  271. extern char event_storage[EVENT_STORAGE_SIZE];
  272. extern int trace_event_raw_init(struct ftrace_event_call *call);
  273. extern int trace_define_field(struct ftrace_event_call *call, const char *type,
  274. const char *name, int offset, int size,
  275. int is_signed, int filter_type);
  276. extern int trace_add_event_call(struct ftrace_event_call *call);
  277. extern void trace_remove_event_call(struct ftrace_event_call *call);
  278. #define is_signed_type(type) (((type)(-1)) < (type)0)
  279. int trace_set_clr_event(const char *system, const char *event, int set);
  280. /*
  281. * The double __builtin_constant_p is because gcc will give us an error
  282. * if we try to allocate the static variable to fmt if it is not a
  283. * constant. Even with the outer if statement optimizing out.
  284. */
  285. #define event_trace_printk(ip, fmt, args...) \
  286. do { \
  287. __trace_printk_check_format(fmt, ##args); \
  288. tracing_record_cmdline(current); \
  289. if (__builtin_constant_p(fmt)) { \
  290. static const char *trace_printk_fmt \
  291. __attribute__((section("__trace_printk_fmt"))) = \
  292. __builtin_constant_p(fmt) ? fmt : NULL; \
  293. \
  294. __trace_bprintk(ip, trace_printk_fmt, ##args); \
  295. } else \
  296. __trace_printk(ip, fmt, ##args); \
  297. } while (0)
  298. #ifdef CONFIG_PERF_EVENTS
  299. struct perf_event;
  300. DECLARE_PER_CPU(struct pt_regs, perf_trace_regs);
  301. extern int perf_trace_init(struct perf_event *event);
  302. extern void perf_trace_destroy(struct perf_event *event);
  303. extern int perf_trace_add(struct perf_event *event, int flags);
  304. extern void perf_trace_del(struct perf_event *event, int flags);
  305. extern int ftrace_profile_set_filter(struct perf_event *event, int event_id,
  306. char *filter_str);
  307. extern void ftrace_profile_free_filter(struct perf_event *event);
  308. extern void *perf_trace_buf_prepare(int size, unsigned short type,
  309. struct pt_regs *regs, int *rctxp);
  310. static inline void
  311. perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr,
  312. u64 count, struct pt_regs *regs, void *head,
  313. struct task_struct *task)
  314. {
  315. perf_tp_event(addr, count, raw_data, size, regs, head, rctx, task);
  316. }
  317. #endif
  318. #endif /* _LINUX_FTRACE_EVENT_H */