trace.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  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 <trace/kmemtrace.h>
  12. #include <trace/power.h>
  13. enum trace_type {
  14. __TRACE_FIRST_TYPE = 0,
  15. TRACE_FN,
  16. TRACE_CTX,
  17. TRACE_WAKE,
  18. TRACE_STACK,
  19. TRACE_PRINT,
  20. TRACE_BPRINT,
  21. TRACE_SPECIAL,
  22. TRACE_MMIO_RW,
  23. TRACE_MMIO_MAP,
  24. TRACE_BRANCH,
  25. TRACE_BOOT_CALL,
  26. TRACE_BOOT_RET,
  27. TRACE_GRAPH_RET,
  28. TRACE_GRAPH_ENT,
  29. TRACE_USER_STACK,
  30. TRACE_HW_BRANCHES,
  31. TRACE_SYSCALL_ENTER,
  32. TRACE_SYSCALL_EXIT,
  33. TRACE_KMEM_ALLOC,
  34. TRACE_KMEM_FREE,
  35. TRACE_POWER,
  36. TRACE_BLK,
  37. __TRACE_LAST_TYPE,
  38. };
  39. /*
  40. * The trace entry - the most basic unit of tracing. This is what
  41. * is printed in the end as a single line in the trace output, such as:
  42. *
  43. * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
  44. */
  45. struct trace_entry {
  46. unsigned char type;
  47. unsigned char flags;
  48. unsigned char preempt_count;
  49. int pid;
  50. int tgid;
  51. };
  52. /*
  53. * Function trace entry - function address and parent function addres:
  54. */
  55. struct ftrace_entry {
  56. struct trace_entry ent;
  57. unsigned long ip;
  58. unsigned long parent_ip;
  59. };
  60. /* Function call entry */
  61. struct ftrace_graph_ent_entry {
  62. struct trace_entry ent;
  63. struct ftrace_graph_ent graph_ent;
  64. };
  65. /* Function return entry */
  66. struct ftrace_graph_ret_entry {
  67. struct trace_entry ent;
  68. struct ftrace_graph_ret ret;
  69. };
  70. extern struct tracer boot_tracer;
  71. /*
  72. * Context switch trace entry - which task (and prio) we switched from/to:
  73. */
  74. struct ctx_switch_entry {
  75. struct trace_entry ent;
  76. unsigned int prev_pid;
  77. unsigned char prev_prio;
  78. unsigned char prev_state;
  79. unsigned int next_pid;
  80. unsigned char next_prio;
  81. unsigned char next_state;
  82. unsigned int next_cpu;
  83. };
  84. /*
  85. * Special (free-form) trace entry:
  86. */
  87. struct special_entry {
  88. struct trace_entry ent;
  89. unsigned long arg1;
  90. unsigned long arg2;
  91. unsigned long arg3;
  92. };
  93. /*
  94. * Stack-trace entry:
  95. */
  96. #define FTRACE_STACK_ENTRIES 8
  97. struct stack_entry {
  98. struct trace_entry ent;
  99. unsigned long caller[FTRACE_STACK_ENTRIES];
  100. };
  101. struct userstack_entry {
  102. struct trace_entry ent;
  103. unsigned long caller[FTRACE_STACK_ENTRIES];
  104. };
  105. /*
  106. * trace_printk entry:
  107. */
  108. struct bprint_entry {
  109. struct trace_entry ent;
  110. unsigned long ip;
  111. const char *fmt;
  112. u32 buf[];
  113. };
  114. struct print_entry {
  115. struct trace_entry ent;
  116. unsigned long ip;
  117. char buf[];
  118. };
  119. #define TRACE_OLD_SIZE 88
  120. struct trace_field_cont {
  121. unsigned char type;
  122. /* Temporary till we get rid of this completely */
  123. char buf[TRACE_OLD_SIZE - 1];
  124. };
  125. struct trace_mmiotrace_rw {
  126. struct trace_entry ent;
  127. struct mmiotrace_rw rw;
  128. };
  129. struct trace_mmiotrace_map {
  130. struct trace_entry ent;
  131. struct mmiotrace_map map;
  132. };
  133. struct trace_boot_call {
  134. struct trace_entry ent;
  135. struct boot_trace_call boot_call;
  136. };
  137. struct trace_boot_ret {
  138. struct trace_entry ent;
  139. struct boot_trace_ret boot_ret;
  140. };
  141. #define TRACE_FUNC_SIZE 30
  142. #define TRACE_FILE_SIZE 20
  143. struct trace_branch {
  144. struct trace_entry ent;
  145. unsigned line;
  146. char func[TRACE_FUNC_SIZE+1];
  147. char file[TRACE_FILE_SIZE+1];
  148. char correct;
  149. };
  150. struct hw_branch_entry {
  151. struct trace_entry ent;
  152. u64 from;
  153. u64 to;
  154. };
  155. struct trace_power {
  156. struct trace_entry ent;
  157. struct power_trace state_data;
  158. };
  159. struct kmemtrace_alloc_entry {
  160. struct trace_entry ent;
  161. enum kmemtrace_type_id type_id;
  162. unsigned long call_site;
  163. const void *ptr;
  164. size_t bytes_req;
  165. size_t bytes_alloc;
  166. gfp_t gfp_flags;
  167. int node;
  168. };
  169. struct kmemtrace_free_entry {
  170. struct trace_entry ent;
  171. enum kmemtrace_type_id type_id;
  172. unsigned long call_site;
  173. const void *ptr;
  174. };
  175. struct syscall_trace_enter {
  176. struct trace_entry ent;
  177. int nr;
  178. unsigned long args[];
  179. };
  180. struct syscall_trace_exit {
  181. struct trace_entry ent;
  182. int nr;
  183. unsigned long ret;
  184. };
  185. /*
  186. * trace_flag_type is an enumeration that holds different
  187. * states when a trace occurs. These are:
  188. * IRQS_OFF - interrupts were disabled
  189. * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
  190. * NEED_RESCED - reschedule is requested
  191. * HARDIRQ - inside an interrupt handler
  192. * SOFTIRQ - inside a softirq handler
  193. */
  194. enum trace_flag_type {
  195. TRACE_FLAG_IRQS_OFF = 0x01,
  196. TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
  197. TRACE_FLAG_NEED_RESCHED = 0x04,
  198. TRACE_FLAG_HARDIRQ = 0x08,
  199. TRACE_FLAG_SOFTIRQ = 0x10,
  200. };
  201. #define TRACE_BUF_SIZE 1024
  202. /*
  203. * The CPU trace array - it consists of thousands of trace entries
  204. * plus some other descriptor data: (for example which task started
  205. * the trace, etc.)
  206. */
  207. struct trace_array_cpu {
  208. atomic_t disabled;
  209. void *buffer_page; /* ring buffer spare */
  210. /* these fields get copied into max-trace: */
  211. unsigned long trace_idx;
  212. unsigned long overrun;
  213. unsigned long saved_latency;
  214. unsigned long critical_start;
  215. unsigned long critical_end;
  216. unsigned long critical_sequence;
  217. unsigned long nice;
  218. unsigned long policy;
  219. unsigned long rt_priority;
  220. cycle_t preempt_timestamp;
  221. pid_t pid;
  222. uid_t uid;
  223. char comm[TASK_COMM_LEN];
  224. };
  225. struct trace_iterator;
  226. /*
  227. * The trace array - an array of per-CPU trace arrays. This is the
  228. * highest level data structure that individual tracers deal with.
  229. * They have on/off state as well:
  230. */
  231. struct trace_array {
  232. struct ring_buffer *buffer;
  233. unsigned long entries;
  234. int cpu;
  235. cycle_t time_start;
  236. struct task_struct *waiter;
  237. struct trace_array_cpu *data[NR_CPUS];
  238. };
  239. #define FTRACE_CMP_TYPE(var, type) \
  240. __builtin_types_compatible_p(typeof(var), type *)
  241. #undef IF_ASSIGN
  242. #define IF_ASSIGN(var, entry, etype, id) \
  243. if (FTRACE_CMP_TYPE(var, etype)) { \
  244. var = (typeof(var))(entry); \
  245. WARN_ON(id && (entry)->type != id); \
  246. break; \
  247. }
  248. /* Will cause compile errors if type is not found. */
  249. extern void __ftrace_bad_type(void);
  250. /*
  251. * The trace_assign_type is a verifier that the entry type is
  252. * the same as the type being assigned. To add new types simply
  253. * add a line with the following format:
  254. *
  255. * IF_ASSIGN(var, ent, type, id);
  256. *
  257. * Where "type" is the trace type that includes the trace_entry
  258. * as the "ent" item. And "id" is the trace identifier that is
  259. * used in the trace_type enum.
  260. *
  261. * If the type can have more than one id, then use zero.
  262. */
  263. #define trace_assign_type(var, ent) \
  264. do { \
  265. IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
  266. IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
  267. IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
  268. IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
  269. IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
  270. IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
  271. IF_ASSIGN(var, ent, struct special_entry, 0); \
  272. IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
  273. TRACE_MMIO_RW); \
  274. IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
  275. TRACE_MMIO_MAP); \
  276. IF_ASSIGN(var, ent, struct trace_boot_call, TRACE_BOOT_CALL);\
  277. IF_ASSIGN(var, ent, struct trace_boot_ret, TRACE_BOOT_RET);\
  278. IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
  279. IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \
  280. TRACE_GRAPH_ENT); \
  281. IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
  282. TRACE_GRAPH_RET); \
  283. IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\
  284. IF_ASSIGN(var, ent, struct trace_power, TRACE_POWER); \
  285. IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry, \
  286. TRACE_KMEM_ALLOC); \
  287. IF_ASSIGN(var, ent, struct kmemtrace_free_entry, \
  288. TRACE_KMEM_FREE); \
  289. IF_ASSIGN(var, ent, struct syscall_trace_enter, \
  290. TRACE_SYSCALL_ENTER); \
  291. IF_ASSIGN(var, ent, struct syscall_trace_exit, \
  292. TRACE_SYSCALL_EXIT); \
  293. __ftrace_bad_type(); \
  294. } while (0)
  295. /* Return values for print_line callback */
  296. enum print_line_t {
  297. TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
  298. TRACE_TYPE_HANDLED = 1,
  299. TRACE_TYPE_UNHANDLED = 2, /* Relay to other output functions */
  300. TRACE_TYPE_NO_CONSUME = 3 /* Handled but ask to not consume */
  301. };
  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. struct trace_seq {
  373. unsigned char buffer[PAGE_SIZE];
  374. unsigned int len;
  375. unsigned int readpos;
  376. };
  377. static inline void
  378. trace_seq_init(struct trace_seq *s)
  379. {
  380. s->len = 0;
  381. s->readpos = 0;
  382. }
  383. #define TRACE_PIPE_ALL_CPU -1
  384. /*
  385. * Trace iterator - used by printout routines who present trace
  386. * results to users and which routines might sleep, etc:
  387. */
  388. struct trace_iterator {
  389. struct trace_array *tr;
  390. struct tracer *trace;
  391. void *private;
  392. int cpu_file;
  393. struct mutex mutex;
  394. struct ring_buffer_iter *buffer_iter[NR_CPUS];
  395. /* The below is zeroed out in pipe_read */
  396. struct trace_seq seq;
  397. struct trace_entry *ent;
  398. int cpu;
  399. u64 ts;
  400. unsigned long iter_flags;
  401. loff_t pos;
  402. long idx;
  403. cpumask_var_t started;
  404. };
  405. int tracer_init(struct tracer *t, struct trace_array *tr);
  406. int tracing_is_enabled(void);
  407. void trace_wake_up(void);
  408. void tracing_reset(struct trace_array *tr, int cpu);
  409. void tracing_reset_online_cpus(struct trace_array *tr);
  410. int tracing_open_generic(struct inode *inode, struct file *filp);
  411. struct dentry *tracing_init_dentry(void);
  412. void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
  413. struct ring_buffer_event;
  414. struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr,
  415. unsigned char type,
  416. unsigned long len,
  417. unsigned long flags,
  418. int pc);
  419. void trace_buffer_unlock_commit(struct trace_array *tr,
  420. struct ring_buffer_event *event,
  421. unsigned long flags, int pc);
  422. struct ring_buffer_event *
  423. trace_current_buffer_lock_reserve(unsigned char type, unsigned long len,
  424. unsigned long flags, int pc);
  425. void trace_current_buffer_unlock_commit(struct ring_buffer_event *event,
  426. unsigned long flags, int pc);
  427. void trace_nowake_buffer_unlock_commit(struct ring_buffer_event *event,
  428. unsigned long flags, int pc);
  429. struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
  430. struct trace_array_cpu *data);
  431. struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
  432. int *ent_cpu, u64 *ent_ts);
  433. void tracing_generic_entry_update(struct trace_entry *entry,
  434. unsigned long flags,
  435. int pc);
  436. void default_wait_pipe(struct trace_iterator *iter);
  437. void poll_wait_pipe(struct trace_iterator *iter);
  438. void ftrace(struct trace_array *tr,
  439. struct trace_array_cpu *data,
  440. unsigned long ip,
  441. unsigned long parent_ip,
  442. unsigned long flags, int pc);
  443. void tracing_sched_switch_trace(struct trace_array *tr,
  444. struct task_struct *prev,
  445. struct task_struct *next,
  446. unsigned long flags, int pc);
  447. void tracing_record_cmdline(struct task_struct *tsk);
  448. void tracing_sched_wakeup_trace(struct trace_array *tr,
  449. struct task_struct *wakee,
  450. struct task_struct *cur,
  451. unsigned long flags, int pc);
  452. void trace_special(struct trace_array *tr,
  453. struct trace_array_cpu *data,
  454. unsigned long arg1,
  455. unsigned long arg2,
  456. unsigned long arg3, int pc);
  457. void trace_function(struct trace_array *tr,
  458. unsigned long ip,
  459. unsigned long parent_ip,
  460. unsigned long flags, int pc);
  461. void trace_graph_return(struct ftrace_graph_ret *trace);
  462. int trace_graph_entry(struct ftrace_graph_ent *trace);
  463. void tracing_start_cmdline_record(void);
  464. void tracing_stop_cmdline_record(void);
  465. void tracing_sched_switch_assign_trace(struct trace_array *tr);
  466. void tracing_stop_sched_switch_record(void);
  467. void tracing_start_sched_switch_record(void);
  468. int register_tracer(struct tracer *type);
  469. void unregister_tracer(struct tracer *type);
  470. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  471. extern unsigned long tracing_max_latency;
  472. extern unsigned long tracing_thresh;
  473. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  474. void update_max_tr_single(struct trace_array *tr,
  475. struct task_struct *tsk, int cpu);
  476. void __trace_stack(struct trace_array *tr,
  477. unsigned long flags,
  478. int skip, int pc);
  479. extern cycle_t ftrace_now(int cpu);
  480. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  481. typedef void
  482. (*tracer_switch_func_t)(void *private,
  483. void *__rq,
  484. struct task_struct *prev,
  485. struct task_struct *next);
  486. struct tracer_switch_ops {
  487. tracer_switch_func_t func;
  488. void *private;
  489. struct tracer_switch_ops *next;
  490. };
  491. #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
  492. extern void trace_find_cmdline(int pid, char comm[]);
  493. #ifdef CONFIG_DYNAMIC_FTRACE
  494. extern unsigned long ftrace_update_tot_cnt;
  495. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  496. extern int DYN_FTRACE_TEST_NAME(void);
  497. #endif
  498. #ifdef CONFIG_FTRACE_STARTUP_TEST
  499. extern int trace_selftest_startup_function(struct tracer *trace,
  500. struct trace_array *tr);
  501. extern int trace_selftest_startup_function_graph(struct tracer *trace,
  502. struct trace_array *tr);
  503. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  504. struct trace_array *tr);
  505. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  506. struct trace_array *tr);
  507. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  508. struct trace_array *tr);
  509. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  510. struct trace_array *tr);
  511. extern int trace_selftest_startup_nop(struct tracer *trace,
  512. struct trace_array *tr);
  513. extern int trace_selftest_startup_sched_switch(struct tracer *trace,
  514. struct trace_array *tr);
  515. extern int trace_selftest_startup_sysprof(struct tracer *trace,
  516. struct trace_array *tr);
  517. extern int trace_selftest_startup_branch(struct tracer *trace,
  518. struct trace_array *tr);
  519. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  520. extern void *head_page(struct trace_array_cpu *data);
  521. extern long ns2usecs(cycle_t nsec);
  522. extern int
  523. trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
  524. extern int
  525. trace_vprintk(unsigned long ip, const char *fmt, va_list args);
  526. extern unsigned long trace_flags;
  527. /* Standard output formatting function used for function return traces */
  528. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  529. extern enum print_line_t print_graph_function(struct trace_iterator *iter);
  530. #ifdef CONFIG_DYNAMIC_FTRACE
  531. /* TODO: make this variable */
  532. #define FTRACE_GRAPH_MAX_FUNCS 32
  533. extern int ftrace_graph_count;
  534. extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
  535. static inline int ftrace_graph_addr(unsigned long addr)
  536. {
  537. int i;
  538. if (!ftrace_graph_count || test_tsk_trace_graph(current))
  539. return 1;
  540. for (i = 0; i < ftrace_graph_count; i++) {
  541. if (addr == ftrace_graph_funcs[i])
  542. return 1;
  543. }
  544. return 0;
  545. }
  546. #else
  547. static inline int ftrace_trace_addr(unsigned long addr)
  548. {
  549. return 1;
  550. }
  551. static inline int ftrace_graph_addr(unsigned long addr)
  552. {
  553. return 1;
  554. }
  555. #endif /* CONFIG_DYNAMIC_FTRACE */
  556. #else /* CONFIG_FUNCTION_GRAPH_TRACER */
  557. static inline enum print_line_t
  558. print_graph_function(struct trace_iterator *iter)
  559. {
  560. return TRACE_TYPE_UNHANDLED;
  561. }
  562. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  563. extern struct pid *ftrace_pid_trace;
  564. static inline int ftrace_trace_task(struct task_struct *task)
  565. {
  566. if (!ftrace_pid_trace)
  567. return 1;
  568. return test_tsk_trace_trace(task);
  569. }
  570. /*
  571. * trace_iterator_flags is an enumeration that defines bit
  572. * positions into trace_flags that controls the output.
  573. *
  574. * NOTE: These bits must match the trace_options array in
  575. * trace.c.
  576. */
  577. enum trace_iterator_flags {
  578. TRACE_ITER_PRINT_PARENT = 0x01,
  579. TRACE_ITER_SYM_OFFSET = 0x02,
  580. TRACE_ITER_SYM_ADDR = 0x04,
  581. TRACE_ITER_VERBOSE = 0x08,
  582. TRACE_ITER_RAW = 0x10,
  583. TRACE_ITER_HEX = 0x20,
  584. TRACE_ITER_BIN = 0x40,
  585. TRACE_ITER_BLOCK = 0x80,
  586. TRACE_ITER_STACKTRACE = 0x100,
  587. TRACE_ITER_SCHED_TREE = 0x200,
  588. TRACE_ITER_PRINTK = 0x400,
  589. TRACE_ITER_PREEMPTONLY = 0x800,
  590. TRACE_ITER_BRANCH = 0x1000,
  591. TRACE_ITER_ANNOTATE = 0x2000,
  592. TRACE_ITER_USERSTACKTRACE = 0x4000,
  593. TRACE_ITER_SYM_USEROBJ = 0x8000,
  594. TRACE_ITER_PRINTK_MSGONLY = 0x10000,
  595. TRACE_ITER_CONTEXT_INFO = 0x20000, /* Print pid/cpu/time */
  596. TRACE_ITER_LATENCY_FMT = 0x40000,
  597. TRACE_ITER_GLOBAL_CLK = 0x80000,
  598. TRACE_ITER_SLEEP_TIME = 0x100000,
  599. };
  600. /*
  601. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  602. * control the output of kernel symbols.
  603. */
  604. #define TRACE_ITER_SYM_MASK \
  605. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  606. extern struct tracer nop_trace;
  607. /**
  608. * ftrace_preempt_disable - disable preemption scheduler safe
  609. *
  610. * When tracing can happen inside the scheduler, there exists
  611. * cases that the tracing might happen before the need_resched
  612. * flag is checked. If this happens and the tracer calls
  613. * preempt_enable (after a disable), a schedule might take place
  614. * causing an infinite recursion.
  615. *
  616. * To prevent this, we read the need_resched flag before
  617. * disabling preemption. When we want to enable preemption we
  618. * check the flag, if it is set, then we call preempt_enable_no_resched.
  619. * Otherwise, we call preempt_enable.
  620. *
  621. * The rational for doing the above is that if need_resched is set
  622. * and we have yet to reschedule, we are either in an atomic location
  623. * (where we do not need to check for scheduling) or we are inside
  624. * the scheduler and do not want to resched.
  625. */
  626. static inline int ftrace_preempt_disable(void)
  627. {
  628. int resched;
  629. resched = need_resched();
  630. preempt_disable_notrace();
  631. return resched;
  632. }
  633. /**
  634. * ftrace_preempt_enable - enable preemption scheduler safe
  635. * @resched: the return value from ftrace_preempt_disable
  636. *
  637. * This is a scheduler safe way to enable preemption and not miss
  638. * any preemption checks. The disabled saved the state of preemption.
  639. * If resched is set, then we are either inside an atomic or
  640. * are inside the scheduler (we would have already scheduled
  641. * otherwise). In this case, we do not want to call normal
  642. * preempt_enable, but preempt_enable_no_resched instead.
  643. */
  644. static inline void ftrace_preempt_enable(int resched)
  645. {
  646. if (resched)
  647. preempt_enable_no_resched_notrace();
  648. else
  649. preempt_enable_notrace();
  650. }
  651. #ifdef CONFIG_BRANCH_TRACER
  652. extern int enable_branch_tracing(struct trace_array *tr);
  653. extern void disable_branch_tracing(void);
  654. static inline int trace_branch_enable(struct trace_array *tr)
  655. {
  656. if (trace_flags & TRACE_ITER_BRANCH)
  657. return enable_branch_tracing(tr);
  658. return 0;
  659. }
  660. static inline void trace_branch_disable(void)
  661. {
  662. /* due to races, always disable */
  663. disable_branch_tracing();
  664. }
  665. #else
  666. static inline int trace_branch_enable(struct trace_array *tr)
  667. {
  668. return 0;
  669. }
  670. static inline void trace_branch_disable(void)
  671. {
  672. }
  673. #endif /* CONFIG_BRANCH_TRACER */
  674. /* set ring buffers to default size if not already done so */
  675. int tracing_update_buffers(void);
  676. /* trace event type bit fields, not numeric */
  677. enum {
  678. TRACE_EVENT_TYPE_PRINTF = 1,
  679. TRACE_EVENT_TYPE_RAW = 2,
  680. };
  681. struct ftrace_event_field {
  682. struct list_head link;
  683. char *name;
  684. char *type;
  685. int offset;
  686. int size;
  687. };
  688. struct ftrace_event_call {
  689. char *name;
  690. char *system;
  691. struct dentry *dir;
  692. int enabled;
  693. int (*regfunc)(void);
  694. void (*unregfunc)(void);
  695. int id;
  696. int (*raw_init)(void);
  697. int (*show_format)(struct trace_seq *s);
  698. int (*define_fields)(void);
  699. struct list_head fields;
  700. struct filter_pred **preds;
  701. #ifdef CONFIG_EVENT_PROFILE
  702. atomic_t profile_count;
  703. int (*profile_enable)(struct ftrace_event_call *);
  704. void (*profile_disable)(struct ftrace_event_call *);
  705. #endif
  706. };
  707. struct event_subsystem {
  708. struct list_head list;
  709. const char *name;
  710. struct dentry *entry;
  711. struct filter_pred **preds;
  712. };
  713. #define events_for_each(event) \
  714. for (event = __start_ftrace_events; \
  715. (unsigned long)event < (unsigned long)__stop_ftrace_events; \
  716. event++)
  717. #define MAX_FILTER_PRED 8
  718. struct filter_pred;
  719. typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event);
  720. struct filter_pred {
  721. filter_pred_fn_t fn;
  722. u64 val;
  723. char *str_val;
  724. int str_len;
  725. char *field_name;
  726. int offset;
  727. int not;
  728. int or;
  729. int compound;
  730. int clear;
  731. };
  732. int trace_define_field(struct ftrace_event_call *call, char *type,
  733. char *name, int offset, int size);
  734. extern void filter_free_pred(struct filter_pred *pred);
  735. extern void filter_print_preds(struct filter_pred **preds,
  736. struct trace_seq *s);
  737. extern int filter_parse(char **pbuf, struct filter_pred *pred);
  738. extern int filter_add_pred(struct ftrace_event_call *call,
  739. struct filter_pred *pred);
  740. extern void filter_free_preds(struct ftrace_event_call *call);
  741. extern int filter_match_preds(struct ftrace_event_call *call, void *rec);
  742. extern void filter_free_subsystem_preds(struct event_subsystem *system);
  743. extern int filter_add_subsystem_pred(struct event_subsystem *system,
  744. struct filter_pred *pred);
  745. void event_trace_printk(unsigned long ip, const char *fmt, ...);
  746. extern struct ftrace_event_call __start_ftrace_events[];
  747. extern struct ftrace_event_call __stop_ftrace_events[];
  748. #define for_each_event(event) \
  749. for (event = __start_ftrace_events; \
  750. (unsigned long)event < (unsigned long)__stop_ftrace_events; \
  751. event++)
  752. extern const char *__start___trace_bprintk_fmt[];
  753. extern const char *__stop___trace_bprintk_fmt[];
  754. /*
  755. * The double __builtin_constant_p is because gcc will give us an error
  756. * if we try to allocate the static variable to fmt if it is not a
  757. * constant. Even with the outer if statement optimizing out.
  758. */
  759. #define event_trace_printk(ip, fmt, args...) \
  760. do { \
  761. __trace_printk_check_format(fmt, ##args); \
  762. tracing_record_cmdline(current); \
  763. if (__builtin_constant_p(fmt)) { \
  764. static const char *trace_printk_fmt \
  765. __attribute__((section("__trace_printk_fmt"))) = \
  766. __builtin_constant_p(fmt) ? fmt : NULL; \
  767. \
  768. __trace_bprintk(ip, trace_printk_fmt, ##args); \
  769. } else \
  770. __trace_printk(ip, fmt, ##args); \
  771. } while (0)
  772. #endif /* _LINUX_KERNEL_TRACE_H */