trace.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. #ifndef _LINUX_KERNEL_TRACE_H
  2. #define _LINUX_KERNEL_TRACE_H
  3. #include <linux/fs.h>
  4. #include <asm/atomic.h>
  5. #include <linux/sched.h>
  6. #include <linux/clocksource.h>
  7. #include <linux/ring_buffer.h>
  8. #include <linux/mmiotrace.h>
  9. #include <linux/tracepoint.h>
  10. #include <linux/ftrace.h>
  11. #include <linux/hw_breakpoint.h>
  12. #include <linux/trace_seq.h>
  13. #include <linux/ftrace_event.h>
  14. enum trace_type {
  15. __TRACE_FIRST_TYPE = 0,
  16. TRACE_FN,
  17. TRACE_CTX,
  18. TRACE_WAKE,
  19. TRACE_STACK,
  20. TRACE_PRINT,
  21. TRACE_BPRINT,
  22. TRACE_SPECIAL,
  23. TRACE_MMIO_RW,
  24. TRACE_MMIO_MAP,
  25. TRACE_BRANCH,
  26. TRACE_GRAPH_RET,
  27. TRACE_GRAPH_ENT,
  28. TRACE_USER_STACK,
  29. TRACE_BLK,
  30. __TRACE_LAST_TYPE,
  31. };
  32. #undef __field
  33. #define __field(type, item) type item;
  34. #undef __field_struct
  35. #define __field_struct(type, item) __field(type, item)
  36. #undef __field_desc
  37. #define __field_desc(type, container, item)
  38. #undef __array
  39. #define __array(type, item, size) type item[size];
  40. #undef __array_desc
  41. #define __array_desc(type, container, item, size)
  42. #undef __dynamic_array
  43. #define __dynamic_array(type, item) type item[];
  44. #undef F_STRUCT
  45. #define F_STRUCT(args...) args
  46. #undef FTRACE_ENTRY
  47. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
  48. struct struct_name { \
  49. struct trace_entry ent; \
  50. tstruct \
  51. }
  52. #undef TP_ARGS
  53. #define TP_ARGS(args...) args
  54. #undef FTRACE_ENTRY_DUP
  55. #define FTRACE_ENTRY_DUP(name, name_struct, id, tstruct, printk)
  56. #include "trace_entries.h"
  57. /*
  58. * syscalls are special, and need special handling, this is why
  59. * they are not included in trace_entries.h
  60. */
  61. struct syscall_trace_enter {
  62. struct trace_entry ent;
  63. int nr;
  64. unsigned long args[];
  65. };
  66. struct syscall_trace_exit {
  67. struct trace_entry ent;
  68. int nr;
  69. long ret;
  70. };
  71. struct kprobe_trace_entry_head {
  72. struct trace_entry ent;
  73. unsigned long ip;
  74. };
  75. struct kretprobe_trace_entry_head {
  76. struct trace_entry ent;
  77. unsigned long func;
  78. unsigned long ret_ip;
  79. };
  80. /*
  81. * trace_flag_type is an enumeration that holds different
  82. * states when a trace occurs. These are:
  83. * IRQS_OFF - interrupts were disabled
  84. * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
  85. * NEED_RESCHED - reschedule is requested
  86. * HARDIRQ - inside an interrupt handler
  87. * SOFTIRQ - inside a softirq handler
  88. */
  89. enum trace_flag_type {
  90. TRACE_FLAG_IRQS_OFF = 0x01,
  91. TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
  92. TRACE_FLAG_NEED_RESCHED = 0x04,
  93. TRACE_FLAG_HARDIRQ = 0x08,
  94. TRACE_FLAG_SOFTIRQ = 0x10,
  95. };
  96. #define TRACE_BUF_SIZE 1024
  97. /*
  98. * The CPU trace array - it consists of thousands of trace entries
  99. * plus some other descriptor data: (for example which task started
  100. * the trace, etc.)
  101. */
  102. struct trace_array_cpu {
  103. atomic_t disabled;
  104. void *buffer_page; /* ring buffer spare */
  105. unsigned long saved_latency;
  106. unsigned long critical_start;
  107. unsigned long critical_end;
  108. unsigned long critical_sequence;
  109. unsigned long nice;
  110. unsigned long policy;
  111. unsigned long rt_priority;
  112. unsigned long skipped_entries;
  113. cycle_t preempt_timestamp;
  114. pid_t pid;
  115. uid_t uid;
  116. char comm[TASK_COMM_LEN];
  117. };
  118. /*
  119. * The trace array - an array of per-CPU trace arrays. This is the
  120. * highest level data structure that individual tracers deal with.
  121. * They have on/off state as well:
  122. */
  123. struct trace_array {
  124. struct ring_buffer *buffer;
  125. unsigned long entries;
  126. int cpu;
  127. cycle_t time_start;
  128. struct task_struct *waiter;
  129. struct trace_array_cpu *data[NR_CPUS];
  130. };
  131. #define FTRACE_CMP_TYPE(var, type) \
  132. __builtin_types_compatible_p(typeof(var), type *)
  133. #undef IF_ASSIGN
  134. #define IF_ASSIGN(var, entry, etype, id) \
  135. if (FTRACE_CMP_TYPE(var, etype)) { \
  136. var = (typeof(var))(entry); \
  137. WARN_ON(id && (entry)->type != id); \
  138. break; \
  139. }
  140. /* Will cause compile errors if type is not found. */
  141. extern void __ftrace_bad_type(void);
  142. /*
  143. * The trace_assign_type is a verifier that the entry type is
  144. * the same as the type being assigned. To add new types simply
  145. * add a line with the following format:
  146. *
  147. * IF_ASSIGN(var, ent, type, id);
  148. *
  149. * Where "type" is the trace type that includes the trace_entry
  150. * as the "ent" item. And "id" is the trace identifier that is
  151. * used in the trace_type enum.
  152. *
  153. * If the type can have more than one id, then use zero.
  154. */
  155. #define trace_assign_type(var, ent) \
  156. do { \
  157. IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
  158. IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
  159. IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
  160. IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
  161. IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
  162. IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
  163. IF_ASSIGN(var, ent, struct special_entry, 0); \
  164. IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
  165. TRACE_MMIO_RW); \
  166. IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
  167. TRACE_MMIO_MAP); \
  168. IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
  169. IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \
  170. TRACE_GRAPH_ENT); \
  171. IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
  172. TRACE_GRAPH_RET); \
  173. __ftrace_bad_type(); \
  174. } while (0)
  175. /*
  176. * An option specific to a tracer. This is a boolean value.
  177. * The bit is the bit index that sets its value on the
  178. * flags value in struct tracer_flags.
  179. */
  180. struct tracer_opt {
  181. const char *name; /* Will appear on the trace_options file */
  182. u32 bit; /* Mask assigned in val field in tracer_flags */
  183. };
  184. /*
  185. * The set of specific options for a tracer. Your tracer
  186. * have to set the initial value of the flags val.
  187. */
  188. struct tracer_flags {
  189. u32 val;
  190. struct tracer_opt *opts;
  191. };
  192. /* Makes more easy to define a tracer opt */
  193. #define TRACER_OPT(s, b) .name = #s, .bit = b
  194. /**
  195. * struct tracer - a specific tracer and its callbacks to interact with debugfs
  196. * @name: the name chosen to select it on the available_tracers file
  197. * @init: called when one switches to this tracer (echo name > current_tracer)
  198. * @reset: called when one switches to another tracer
  199. * @start: called when tracing is unpaused (echo 1 > tracing_enabled)
  200. * @stop: called when tracing is paused (echo 0 > tracing_enabled)
  201. * @open: called when the trace file is opened
  202. * @pipe_open: called when the trace_pipe file is opened
  203. * @wait_pipe: override how the user waits for traces on trace_pipe
  204. * @close: called when the trace file is released
  205. * @pipe_close: called when the trace_pipe file is released
  206. * @read: override the default read callback on trace_pipe
  207. * @splice_read: override the default splice_read callback on trace_pipe
  208. * @selftest: selftest to run on boot (see trace_selftest.c)
  209. * @print_headers: override the first lines that describe your columns
  210. * @print_line: callback that prints a trace
  211. * @set_flag: signals one of your private flags changed (trace_options file)
  212. * @flags: your private flags
  213. */
  214. struct tracer {
  215. const char *name;
  216. int (*init)(struct trace_array *tr);
  217. void (*reset)(struct trace_array *tr);
  218. void (*start)(struct trace_array *tr);
  219. void (*stop)(struct trace_array *tr);
  220. void (*open)(struct trace_iterator *iter);
  221. void (*pipe_open)(struct trace_iterator *iter);
  222. void (*wait_pipe)(struct trace_iterator *iter);
  223. void (*close)(struct trace_iterator *iter);
  224. void (*pipe_close)(struct trace_iterator *iter);
  225. ssize_t (*read)(struct trace_iterator *iter,
  226. struct file *filp, char __user *ubuf,
  227. size_t cnt, loff_t *ppos);
  228. ssize_t (*splice_read)(struct trace_iterator *iter,
  229. struct file *filp,
  230. loff_t *ppos,
  231. struct pipe_inode_info *pipe,
  232. size_t len,
  233. unsigned int flags);
  234. #ifdef CONFIG_FTRACE_STARTUP_TEST
  235. int (*selftest)(struct tracer *trace,
  236. struct trace_array *tr);
  237. #endif
  238. void (*print_header)(struct seq_file *m);
  239. enum print_line_t (*print_line)(struct trace_iterator *iter);
  240. /* If you handled the flag setting, return 0 */
  241. int (*set_flag)(u32 old_flags, u32 bit, int set);
  242. struct tracer *next;
  243. int print_max;
  244. struct tracer_flags *flags;
  245. };
  246. #define TRACE_PIPE_ALL_CPU -1
  247. int tracer_init(struct tracer *t, struct trace_array *tr);
  248. int tracing_is_enabled(void);
  249. void trace_wake_up(void);
  250. void tracing_reset(struct trace_array *tr, int cpu);
  251. void tracing_reset_online_cpus(struct trace_array *tr);
  252. void tracing_reset_current(int cpu);
  253. void tracing_reset_current_online_cpus(void);
  254. int tracing_open_generic(struct inode *inode, struct file *filp);
  255. struct dentry *trace_create_file(const char *name,
  256. mode_t mode,
  257. struct dentry *parent,
  258. void *data,
  259. const struct file_operations *fops);
  260. struct dentry *tracing_init_dentry(void);
  261. struct ring_buffer_event;
  262. struct ring_buffer_event *
  263. trace_buffer_lock_reserve(struct ring_buffer *buffer,
  264. int type,
  265. unsigned long len,
  266. unsigned long flags,
  267. int pc);
  268. void trace_buffer_unlock_commit(struct ring_buffer *buffer,
  269. struct ring_buffer_event *event,
  270. unsigned long flags, int pc);
  271. struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
  272. struct trace_array_cpu *data);
  273. struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
  274. int *ent_cpu, u64 *ent_ts);
  275. void default_wait_pipe(struct trace_iterator *iter);
  276. void poll_wait_pipe(struct trace_iterator *iter);
  277. void ftrace(struct trace_array *tr,
  278. struct trace_array_cpu *data,
  279. unsigned long ip,
  280. unsigned long parent_ip,
  281. unsigned long flags, int pc);
  282. void tracing_sched_switch_trace(struct trace_array *tr,
  283. struct task_struct *prev,
  284. struct task_struct *next,
  285. unsigned long flags, int pc);
  286. void tracing_sched_wakeup_trace(struct trace_array *tr,
  287. struct task_struct *wakee,
  288. struct task_struct *cur,
  289. unsigned long flags, int pc);
  290. void trace_special(struct trace_array *tr,
  291. struct trace_array_cpu *data,
  292. unsigned long arg1,
  293. unsigned long arg2,
  294. unsigned long arg3, int pc);
  295. void trace_function(struct trace_array *tr,
  296. unsigned long ip,
  297. unsigned long parent_ip,
  298. unsigned long flags, int pc);
  299. void trace_default_header(struct seq_file *m);
  300. void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
  301. int trace_empty(struct trace_iterator *iter);
  302. void trace_graph_return(struct ftrace_graph_ret *trace);
  303. int trace_graph_entry(struct ftrace_graph_ent *trace);
  304. void set_graph_array(struct trace_array *tr);
  305. void tracing_start_cmdline_record(void);
  306. void tracing_stop_cmdline_record(void);
  307. void tracing_sched_switch_assign_trace(struct trace_array *tr);
  308. void tracing_stop_sched_switch_record(void);
  309. void tracing_start_sched_switch_record(void);
  310. int register_tracer(struct tracer *type);
  311. void unregister_tracer(struct tracer *type);
  312. int is_tracing_stopped(void);
  313. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  314. extern unsigned long tracing_thresh;
  315. #ifdef CONFIG_TRACER_MAX_TRACE
  316. extern unsigned long tracing_max_latency;
  317. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  318. void update_max_tr_single(struct trace_array *tr,
  319. struct task_struct *tsk, int cpu);
  320. #endif /* CONFIG_TRACER_MAX_TRACE */
  321. #ifdef CONFIG_STACKTRACE
  322. void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags,
  323. int skip, int pc);
  324. void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags,
  325. int pc);
  326. void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
  327. int pc);
  328. #else
  329. static inline void ftrace_trace_stack(struct ring_buffer *buffer,
  330. unsigned long flags, int skip, int pc)
  331. {
  332. }
  333. static inline void ftrace_trace_userstack(struct ring_buffer *buffer,
  334. unsigned long flags, int pc)
  335. {
  336. }
  337. static inline void __trace_stack(struct trace_array *tr, unsigned long flags,
  338. int skip, int pc)
  339. {
  340. }
  341. #endif /* CONFIG_STACKTRACE */
  342. extern cycle_t ftrace_now(int cpu);
  343. extern void trace_find_cmdline(int pid, char comm[]);
  344. #ifdef CONFIG_DYNAMIC_FTRACE
  345. extern unsigned long ftrace_update_tot_cnt;
  346. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  347. extern int DYN_FTRACE_TEST_NAME(void);
  348. #endif
  349. extern int ring_buffer_expanded;
  350. extern bool tracing_selftest_disabled;
  351. DECLARE_PER_CPU(int, ftrace_cpu_disabled);
  352. #ifdef CONFIG_FTRACE_STARTUP_TEST
  353. extern int trace_selftest_startup_function(struct tracer *trace,
  354. struct trace_array *tr);
  355. extern int trace_selftest_startup_function_graph(struct tracer *trace,
  356. struct trace_array *tr);
  357. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  358. struct trace_array *tr);
  359. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  360. struct trace_array *tr);
  361. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  362. struct trace_array *tr);
  363. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  364. struct trace_array *tr);
  365. extern int trace_selftest_startup_nop(struct tracer *trace,
  366. struct trace_array *tr);
  367. extern int trace_selftest_startup_sched_switch(struct tracer *trace,
  368. struct trace_array *tr);
  369. extern int trace_selftest_startup_branch(struct tracer *trace,
  370. struct trace_array *tr);
  371. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  372. extern void *head_page(struct trace_array_cpu *data);
  373. extern unsigned long long ns2usecs(cycle_t nsec);
  374. extern int
  375. trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
  376. extern int
  377. trace_vprintk(unsigned long ip, const char *fmt, va_list args);
  378. extern int
  379. trace_array_vprintk(struct trace_array *tr,
  380. unsigned long ip, const char *fmt, va_list args);
  381. int trace_array_printk(struct trace_array *tr,
  382. unsigned long ip, const char *fmt, ...);
  383. extern unsigned long trace_flags;
  384. extern int trace_clock_id;
  385. /* Standard output formatting function used for function return traces */
  386. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  387. /* Flag options */
  388. #define TRACE_GRAPH_PRINT_OVERRUN 0x1
  389. #define TRACE_GRAPH_PRINT_CPU 0x2
  390. #define TRACE_GRAPH_PRINT_OVERHEAD 0x4
  391. #define TRACE_GRAPH_PRINT_PROC 0x8
  392. #define TRACE_GRAPH_PRINT_DURATION 0x10
  393. #define TRACE_GRAPH_PRINT_ABS_TIME 0x20
  394. extern enum print_line_t
  395. print_graph_function_flags(struct trace_iterator *iter, u32 flags);
  396. extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
  397. extern enum print_line_t
  398. trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
  399. extern void graph_trace_open(struct trace_iterator *iter);
  400. extern void graph_trace_close(struct trace_iterator *iter);
  401. extern int __trace_graph_entry(struct trace_array *tr,
  402. struct ftrace_graph_ent *trace,
  403. unsigned long flags, int pc);
  404. extern void __trace_graph_return(struct trace_array *tr,
  405. struct ftrace_graph_ret *trace,
  406. unsigned long flags, int pc);
  407. #ifdef CONFIG_DYNAMIC_FTRACE
  408. /* TODO: make this variable */
  409. #define FTRACE_GRAPH_MAX_FUNCS 32
  410. extern int ftrace_graph_filter_enabled;
  411. extern int ftrace_graph_count;
  412. extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
  413. static inline int ftrace_graph_addr(unsigned long addr)
  414. {
  415. int i;
  416. if (!ftrace_graph_filter_enabled)
  417. return 1;
  418. for (i = 0; i < ftrace_graph_count; i++) {
  419. if (addr == ftrace_graph_funcs[i])
  420. return 1;
  421. }
  422. return 0;
  423. }
  424. #else
  425. static inline int ftrace_graph_addr(unsigned long addr)
  426. {
  427. return 1;
  428. }
  429. #endif /* CONFIG_DYNAMIC_FTRACE */
  430. #else /* CONFIG_FUNCTION_GRAPH_TRACER */
  431. static inline enum print_line_t
  432. print_graph_function_flags(struct trace_iterator *iter, u32 flags)
  433. {
  434. return TRACE_TYPE_UNHANDLED;
  435. }
  436. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  437. extern struct list_head ftrace_pids;
  438. #ifdef CONFIG_FUNCTION_TRACER
  439. static inline int ftrace_trace_task(struct task_struct *task)
  440. {
  441. if (list_empty(&ftrace_pids))
  442. return 1;
  443. return test_tsk_trace_trace(task);
  444. }
  445. #else
  446. static inline int ftrace_trace_task(struct task_struct *task)
  447. {
  448. return 1;
  449. }
  450. #endif
  451. /*
  452. * struct trace_parser - servers for reading the user input separated by spaces
  453. * @cont: set if the input is not complete - no final space char was found
  454. * @buffer: holds the parsed user input
  455. * @idx: user input length
  456. * @size: buffer size
  457. */
  458. struct trace_parser {
  459. bool cont;
  460. char *buffer;
  461. unsigned idx;
  462. unsigned size;
  463. };
  464. static inline bool trace_parser_loaded(struct trace_parser *parser)
  465. {
  466. return (parser->idx != 0);
  467. }
  468. static inline bool trace_parser_cont(struct trace_parser *parser)
  469. {
  470. return parser->cont;
  471. }
  472. static inline void trace_parser_clear(struct trace_parser *parser)
  473. {
  474. parser->cont = false;
  475. parser->idx = 0;
  476. }
  477. extern int trace_parser_get_init(struct trace_parser *parser, int size);
  478. extern void trace_parser_put(struct trace_parser *parser);
  479. extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
  480. size_t cnt, loff_t *ppos);
  481. /*
  482. * trace_iterator_flags is an enumeration that defines bit
  483. * positions into trace_flags that controls the output.
  484. *
  485. * NOTE: These bits must match the trace_options array in
  486. * trace.c.
  487. */
  488. enum trace_iterator_flags {
  489. TRACE_ITER_PRINT_PARENT = 0x01,
  490. TRACE_ITER_SYM_OFFSET = 0x02,
  491. TRACE_ITER_SYM_ADDR = 0x04,
  492. TRACE_ITER_VERBOSE = 0x08,
  493. TRACE_ITER_RAW = 0x10,
  494. TRACE_ITER_HEX = 0x20,
  495. TRACE_ITER_BIN = 0x40,
  496. TRACE_ITER_BLOCK = 0x80,
  497. TRACE_ITER_STACKTRACE = 0x100,
  498. TRACE_ITER_PRINTK = 0x200,
  499. TRACE_ITER_PREEMPTONLY = 0x400,
  500. TRACE_ITER_BRANCH = 0x800,
  501. TRACE_ITER_ANNOTATE = 0x1000,
  502. TRACE_ITER_USERSTACKTRACE = 0x2000,
  503. TRACE_ITER_SYM_USEROBJ = 0x4000,
  504. TRACE_ITER_PRINTK_MSGONLY = 0x8000,
  505. TRACE_ITER_CONTEXT_INFO = 0x10000, /* Print pid/cpu/time */
  506. TRACE_ITER_LATENCY_FMT = 0x20000,
  507. TRACE_ITER_SLEEP_TIME = 0x40000,
  508. TRACE_ITER_GRAPH_TIME = 0x80000,
  509. };
  510. /*
  511. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  512. * control the output of kernel symbols.
  513. */
  514. #define TRACE_ITER_SYM_MASK \
  515. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  516. extern struct tracer nop_trace;
  517. #ifdef CONFIG_BRANCH_TRACER
  518. extern int enable_branch_tracing(struct trace_array *tr);
  519. extern void disable_branch_tracing(void);
  520. static inline int trace_branch_enable(struct trace_array *tr)
  521. {
  522. if (trace_flags & TRACE_ITER_BRANCH)
  523. return enable_branch_tracing(tr);
  524. return 0;
  525. }
  526. static inline void trace_branch_disable(void)
  527. {
  528. /* due to races, always disable */
  529. disable_branch_tracing();
  530. }
  531. #else
  532. static inline int trace_branch_enable(struct trace_array *tr)
  533. {
  534. return 0;
  535. }
  536. static inline void trace_branch_disable(void)
  537. {
  538. }
  539. #endif /* CONFIG_BRANCH_TRACER */
  540. /* set ring buffers to default size if not already done so */
  541. int tracing_update_buffers(void);
  542. /* trace event type bit fields, not numeric */
  543. enum {
  544. TRACE_EVENT_TYPE_PRINTF = 1,
  545. TRACE_EVENT_TYPE_RAW = 2,
  546. };
  547. struct ftrace_event_field {
  548. struct list_head link;
  549. char *name;
  550. char *type;
  551. int filter_type;
  552. int offset;
  553. int size;
  554. int is_signed;
  555. };
  556. struct event_filter {
  557. int n_preds;
  558. struct filter_pred **preds;
  559. char *filter_string;
  560. };
  561. struct event_subsystem {
  562. struct list_head list;
  563. const char *name;
  564. struct dentry *entry;
  565. struct event_filter *filter;
  566. int nr_events;
  567. };
  568. struct filter_pred;
  569. struct regex;
  570. typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event,
  571. int val1, int val2);
  572. typedef int (*regex_match_func)(char *str, struct regex *r, int len);
  573. enum regex_type {
  574. MATCH_FULL = 0,
  575. MATCH_FRONT_ONLY,
  576. MATCH_MIDDLE_ONLY,
  577. MATCH_END_ONLY,
  578. };
  579. struct regex {
  580. char pattern[MAX_FILTER_STR_VAL];
  581. int len;
  582. int field_len;
  583. regex_match_func match;
  584. };
  585. struct filter_pred {
  586. filter_pred_fn_t fn;
  587. u64 val;
  588. struct regex regex;
  589. char *field_name;
  590. int offset;
  591. int not;
  592. int op;
  593. int pop_n;
  594. };
  595. extern struct list_head ftrace_common_fields;
  596. extern enum regex_type
  597. filter_parse_regex(char *buff, int len, char **search, int *not);
  598. extern void print_event_filter(struct ftrace_event_call *call,
  599. struct trace_seq *s);
  600. extern int apply_event_filter(struct ftrace_event_call *call,
  601. char *filter_string);
  602. extern int apply_subsystem_event_filter(struct event_subsystem *system,
  603. char *filter_string);
  604. extern void print_subsystem_event_filter(struct event_subsystem *system,
  605. struct trace_seq *s);
  606. extern int filter_assign_type(const char *type);
  607. struct list_head *
  608. trace_get_fields(struct ftrace_event_call *event_call);
  609. static inline int
  610. filter_check_discard(struct ftrace_event_call *call, void *rec,
  611. struct ring_buffer *buffer,
  612. struct ring_buffer_event *event)
  613. {
  614. if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) &&
  615. !filter_match_preds(call->filter, rec)) {
  616. ring_buffer_discard_commit(buffer, event);
  617. return 1;
  618. }
  619. return 0;
  620. }
  621. extern struct mutex event_mutex;
  622. extern struct list_head ftrace_events;
  623. extern const char *__start___trace_bprintk_fmt[];
  624. extern const char *__stop___trace_bprintk_fmt[];
  625. #undef FTRACE_ENTRY
  626. #define FTRACE_ENTRY(call, struct_name, id, tstruct, print) \
  627. extern struct ftrace_event_call \
  628. __attribute__((__aligned__(4))) event_##call;
  629. #undef FTRACE_ENTRY_DUP
  630. #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print) \
  631. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print))
  632. #include "trace_entries.h"
  633. #endif /* _LINUX_KERNEL_TRACE_H */