trace.h 21 KB

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