trace.h 24 KB

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