trace.h 22 KB

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