trace.h 23 KB

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