trace.h 23 KB

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