trace.h 23 KB

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