trace.h 24 KB

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