trace.h 23 KB

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