trace.h 27 KB

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