trace.h 23 KB

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