trace.h 24 KB

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