trace.h 22 KB

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