trace.h 24 KB

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