trace.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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_SPECIAL,
  21. TRACE_MMIO_RW,
  22. TRACE_MMIO_MAP,
  23. TRACE_BRANCH,
  24. TRACE_BOOT_CALL,
  25. TRACE_BOOT_RET,
  26. TRACE_GRAPH_RET,
  27. TRACE_GRAPH_ENT,
  28. TRACE_USER_STACK,
  29. TRACE_HW_BRANCHES,
  30. TRACE_KMEM_ALLOC,
  31. TRACE_KMEM_FREE,
  32. TRACE_POWER,
  33. TRACE_BLK,
  34. __TRACE_LAST_TYPE,
  35. };
  36. /*
  37. * The trace entry - the most basic unit of tracing. This is what
  38. * is printed in the end as a single line in the trace output, such as:
  39. *
  40. * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
  41. */
  42. struct trace_entry {
  43. unsigned char type;
  44. unsigned char flags;
  45. unsigned char preempt_count;
  46. int pid;
  47. int tgid;
  48. };
  49. /*
  50. * Function trace entry - function address and parent function addres:
  51. */
  52. struct ftrace_entry {
  53. struct trace_entry ent;
  54. unsigned long ip;
  55. unsigned long parent_ip;
  56. };
  57. /* Function call entry */
  58. struct ftrace_graph_ent_entry {
  59. struct trace_entry ent;
  60. struct ftrace_graph_ent graph_ent;
  61. };
  62. /* Function return entry */
  63. struct ftrace_graph_ret_entry {
  64. struct trace_entry ent;
  65. struct ftrace_graph_ret ret;
  66. };
  67. extern struct tracer boot_tracer;
  68. /*
  69. * Context switch trace entry - which task (and prio) we switched from/to:
  70. */
  71. struct ctx_switch_entry {
  72. struct trace_entry ent;
  73. unsigned int prev_pid;
  74. unsigned char prev_prio;
  75. unsigned char prev_state;
  76. unsigned int next_pid;
  77. unsigned char next_prio;
  78. unsigned char next_state;
  79. unsigned int next_cpu;
  80. };
  81. /*
  82. * Special (free-form) trace entry:
  83. */
  84. struct special_entry {
  85. struct trace_entry ent;
  86. unsigned long arg1;
  87. unsigned long arg2;
  88. unsigned long arg3;
  89. };
  90. /*
  91. * Stack-trace entry:
  92. */
  93. #define FTRACE_STACK_ENTRIES 8
  94. struct stack_entry {
  95. struct trace_entry ent;
  96. unsigned long caller[FTRACE_STACK_ENTRIES];
  97. };
  98. struct userstack_entry {
  99. struct trace_entry ent;
  100. unsigned long caller[FTRACE_STACK_ENTRIES];
  101. };
  102. /*
  103. * trace_printk entry:
  104. */
  105. struct print_entry {
  106. struct trace_entry ent;
  107. unsigned long ip;
  108. int depth;
  109. const char *fmt;
  110. u32 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. struct kmemtrace_alloc_entry {
  153. struct trace_entry ent;
  154. enum kmemtrace_type_id type_id;
  155. unsigned long call_site;
  156. const void *ptr;
  157. size_t bytes_req;
  158. size_t bytes_alloc;
  159. gfp_t gfp_flags;
  160. int node;
  161. };
  162. struct kmemtrace_free_entry {
  163. struct trace_entry ent;
  164. enum kmemtrace_type_id type_id;
  165. unsigned long call_site;
  166. const void *ptr;
  167. };
  168. /*
  169. * trace_flag_type is an enumeration that holds different
  170. * states when a trace occurs. These are:
  171. * IRQS_OFF - interrupts were disabled
  172. * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
  173. * NEED_RESCED - reschedule is requested
  174. * HARDIRQ - inside an interrupt handler
  175. * SOFTIRQ - inside a softirq handler
  176. */
  177. enum trace_flag_type {
  178. TRACE_FLAG_IRQS_OFF = 0x01,
  179. TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
  180. TRACE_FLAG_NEED_RESCHED = 0x04,
  181. TRACE_FLAG_HARDIRQ = 0x08,
  182. TRACE_FLAG_SOFTIRQ = 0x10,
  183. };
  184. #define TRACE_BUF_SIZE 1024
  185. /*
  186. * The CPU trace array - it consists of thousands of trace entries
  187. * plus some other descriptor data: (for example which task started
  188. * the trace, etc.)
  189. */
  190. struct trace_array_cpu {
  191. atomic_t disabled;
  192. void *buffer_page; /* ring buffer spare */
  193. /* these fields get copied into max-trace: */
  194. unsigned long trace_idx;
  195. unsigned long overrun;
  196. unsigned long saved_latency;
  197. unsigned long critical_start;
  198. unsigned long critical_end;
  199. unsigned long critical_sequence;
  200. unsigned long nice;
  201. unsigned long policy;
  202. unsigned long rt_priority;
  203. cycle_t preempt_timestamp;
  204. pid_t pid;
  205. uid_t uid;
  206. char comm[TASK_COMM_LEN];
  207. };
  208. struct trace_iterator;
  209. /*
  210. * The trace array - an array of per-CPU trace arrays. This is the
  211. * highest level data structure that individual tracers deal with.
  212. * They have on/off state as well:
  213. */
  214. struct trace_array {
  215. struct ring_buffer *buffer;
  216. unsigned long entries;
  217. int cpu;
  218. cycle_t time_start;
  219. struct task_struct *waiter;
  220. struct trace_array_cpu *data[NR_CPUS];
  221. };
  222. #define FTRACE_CMP_TYPE(var, type) \
  223. __builtin_types_compatible_p(typeof(var), type *)
  224. #undef IF_ASSIGN
  225. #define IF_ASSIGN(var, entry, etype, id) \
  226. if (FTRACE_CMP_TYPE(var, etype)) { \
  227. var = (typeof(var))(entry); \
  228. WARN_ON(id && (entry)->type != id); \
  229. break; \
  230. }
  231. /* Will cause compile errors if type is not found. */
  232. extern void __ftrace_bad_type(void);
  233. /*
  234. * The trace_assign_type is a verifier that the entry type is
  235. * the same as the type being assigned. To add new types simply
  236. * add a line with the following format:
  237. *
  238. * IF_ASSIGN(var, ent, type, id);
  239. *
  240. * Where "type" is the trace type that includes the trace_entry
  241. * as the "ent" item. And "id" is the trace identifier that is
  242. * used in the trace_type enum.
  243. *
  244. * If the type can have more than one id, then use zero.
  245. */
  246. #define trace_assign_type(var, ent) \
  247. do { \
  248. IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
  249. IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
  250. IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
  251. IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
  252. IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
  253. IF_ASSIGN(var, ent, struct special_entry, 0); \
  254. IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
  255. TRACE_MMIO_RW); \
  256. IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
  257. TRACE_MMIO_MAP); \
  258. IF_ASSIGN(var, ent, struct trace_boot_call, TRACE_BOOT_CALL);\
  259. IF_ASSIGN(var, ent, struct trace_boot_ret, TRACE_BOOT_RET);\
  260. IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
  261. IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \
  262. TRACE_GRAPH_ENT); \
  263. IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
  264. TRACE_GRAPH_RET); \
  265. IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\
  266. IF_ASSIGN(var, ent, struct trace_power, TRACE_POWER); \
  267. IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry, \
  268. TRACE_KMEM_ALLOC); \
  269. IF_ASSIGN(var, ent, struct kmemtrace_free_entry, \
  270. TRACE_KMEM_FREE); \
  271. __ftrace_bad_type(); \
  272. } while (0)
  273. /* Return values for print_line callback */
  274. enum print_line_t {
  275. TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
  276. TRACE_TYPE_HANDLED = 1,
  277. TRACE_TYPE_UNHANDLED = 2, /* Relay to other output functions */
  278. TRACE_TYPE_NO_CONSUME = 3 /* Handled but ask to not consume */
  279. };
  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. struct trace_seq {
  351. unsigned char buffer[PAGE_SIZE];
  352. unsigned int len;
  353. unsigned int readpos;
  354. };
  355. static inline void
  356. trace_seq_init(struct trace_seq *s)
  357. {
  358. s->len = 0;
  359. s->readpos = 0;
  360. }
  361. #define TRACE_PIPE_ALL_CPU -1
  362. /*
  363. * Trace iterator - used by printout routines who present trace
  364. * results to users and which routines might sleep, etc:
  365. */
  366. struct trace_iterator {
  367. struct trace_array *tr;
  368. struct tracer *trace;
  369. void *private;
  370. int cpu_file;
  371. struct mutex mutex;
  372. struct ring_buffer_iter *buffer_iter[NR_CPUS];
  373. /* The below is zeroed out in pipe_read */
  374. struct trace_seq seq;
  375. struct trace_entry *ent;
  376. int cpu;
  377. u64 ts;
  378. unsigned long iter_flags;
  379. loff_t pos;
  380. long idx;
  381. cpumask_var_t started;
  382. };
  383. int tracer_init(struct tracer *t, struct trace_array *tr);
  384. int tracing_is_enabled(void);
  385. void trace_wake_up(void);
  386. void tracing_reset(struct trace_array *tr, int cpu);
  387. void tracing_reset_online_cpus(struct trace_array *tr);
  388. int tracing_open_generic(struct inode *inode, struct file *filp);
  389. struct dentry *tracing_init_dentry(void);
  390. void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
  391. struct ring_buffer_event;
  392. struct ring_buffer_event *trace_buffer_lock_reserve(struct trace_array *tr,
  393. unsigned char type,
  394. unsigned long len,
  395. unsigned long flags,
  396. int pc);
  397. void trace_buffer_unlock_commit(struct trace_array *tr,
  398. struct ring_buffer_event *event,
  399. unsigned long flags, int pc);
  400. struct ring_buffer_event *
  401. trace_current_buffer_lock_reserve(unsigned char type, unsigned long len,
  402. unsigned long flags, int pc);
  403. void trace_current_buffer_unlock_commit(struct ring_buffer_event *event,
  404. unsigned long flags, int pc);
  405. struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
  406. struct trace_array_cpu *data);
  407. struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
  408. int *ent_cpu, u64 *ent_ts);
  409. void tracing_generic_entry_update(struct trace_entry *entry,
  410. unsigned long flags,
  411. int pc);
  412. void default_wait_pipe(struct trace_iterator *iter);
  413. void poll_wait_pipe(struct trace_iterator *iter);
  414. void ftrace(struct trace_array *tr,
  415. struct trace_array_cpu *data,
  416. unsigned long ip,
  417. unsigned long parent_ip,
  418. unsigned long flags, int pc);
  419. void tracing_sched_switch_trace(struct trace_array *tr,
  420. struct task_struct *prev,
  421. struct task_struct *next,
  422. unsigned long flags, int pc);
  423. void tracing_record_cmdline(struct task_struct *tsk);
  424. void tracing_sched_wakeup_trace(struct trace_array *tr,
  425. struct task_struct *wakee,
  426. struct task_struct *cur,
  427. unsigned long flags, int pc);
  428. void trace_special(struct trace_array *tr,
  429. struct trace_array_cpu *data,
  430. unsigned long arg1,
  431. unsigned long arg2,
  432. unsigned long arg3, int pc);
  433. void trace_function(struct trace_array *tr,
  434. unsigned long ip,
  435. unsigned long parent_ip,
  436. unsigned long flags, int pc);
  437. void trace_graph_return(struct ftrace_graph_ret *trace);
  438. int trace_graph_entry(struct ftrace_graph_ent *trace);
  439. void tracing_start_cmdline_record(void);
  440. void tracing_stop_cmdline_record(void);
  441. void tracing_sched_switch_assign_trace(struct trace_array *tr);
  442. void tracing_stop_sched_switch_record(void);
  443. void tracing_start_sched_switch_record(void);
  444. int register_tracer(struct tracer *type);
  445. void unregister_tracer(struct tracer *type);
  446. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  447. extern unsigned long tracing_max_latency;
  448. extern unsigned long tracing_thresh;
  449. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  450. void update_max_tr_single(struct trace_array *tr,
  451. struct task_struct *tsk, int cpu);
  452. void __trace_stack(struct trace_array *tr,
  453. unsigned long flags,
  454. int skip, int pc);
  455. extern cycle_t ftrace_now(int cpu);
  456. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  457. typedef void
  458. (*tracer_switch_func_t)(void *private,
  459. void *__rq,
  460. struct task_struct *prev,
  461. struct task_struct *next);
  462. struct tracer_switch_ops {
  463. tracer_switch_func_t func;
  464. void *private;
  465. struct tracer_switch_ops *next;
  466. };
  467. #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
  468. extern char *trace_find_cmdline(int pid);
  469. #ifdef CONFIG_DYNAMIC_FTRACE
  470. extern unsigned long ftrace_update_tot_cnt;
  471. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  472. extern int DYN_FTRACE_TEST_NAME(void);
  473. #endif
  474. #ifdef CONFIG_FTRACE_STARTUP_TEST
  475. extern int trace_selftest_startup_function(struct tracer *trace,
  476. struct trace_array *tr);
  477. extern int trace_selftest_startup_function_graph(struct tracer *trace,
  478. struct trace_array *tr);
  479. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  480. struct trace_array *tr);
  481. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  482. struct trace_array *tr);
  483. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  484. struct trace_array *tr);
  485. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  486. struct trace_array *tr);
  487. extern int trace_selftest_startup_nop(struct tracer *trace,
  488. struct trace_array *tr);
  489. extern int trace_selftest_startup_sched_switch(struct tracer *trace,
  490. struct trace_array *tr);
  491. extern int trace_selftest_startup_sysprof(struct tracer *trace,
  492. struct trace_array *tr);
  493. extern int trace_selftest_startup_branch(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 long ns2usecs(cycle_t nsec);
  498. extern int
  499. trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args);
  500. extern unsigned long trace_flags;
  501. /* Standard output formatting function used for function return traces */
  502. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  503. extern enum print_line_t print_graph_function(struct trace_iterator *iter);
  504. #ifdef CONFIG_DYNAMIC_FTRACE
  505. /* TODO: make this variable */
  506. #define FTRACE_GRAPH_MAX_FUNCS 32
  507. extern int ftrace_graph_count;
  508. extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
  509. static inline int ftrace_graph_addr(unsigned long addr)
  510. {
  511. int i;
  512. if (!ftrace_graph_count || test_tsk_trace_graph(current))
  513. return 1;
  514. for (i = 0; i < ftrace_graph_count; i++) {
  515. if (addr == ftrace_graph_funcs[i])
  516. return 1;
  517. }
  518. return 0;
  519. }
  520. #else
  521. static inline int ftrace_trace_addr(unsigned long addr)
  522. {
  523. return 1;
  524. }
  525. static inline int ftrace_graph_addr(unsigned long addr)
  526. {
  527. return 1;
  528. }
  529. #endif /* CONFIG_DYNAMIC_FTRACE */
  530. #else /* CONFIG_FUNCTION_GRAPH_TRACER */
  531. static inline enum print_line_t
  532. print_graph_function(struct trace_iterator *iter)
  533. {
  534. return TRACE_TYPE_UNHANDLED;
  535. }
  536. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  537. extern struct pid *ftrace_pid_trace;
  538. static inline int ftrace_trace_task(struct task_struct *task)
  539. {
  540. if (!ftrace_pid_trace)
  541. return 1;
  542. return test_tsk_trace_trace(task);
  543. }
  544. /*
  545. * trace_iterator_flags is an enumeration that defines bit
  546. * positions into trace_flags that controls the output.
  547. *
  548. * NOTE: These bits must match the trace_options array in
  549. * trace.c.
  550. */
  551. enum trace_iterator_flags {
  552. TRACE_ITER_PRINT_PARENT = 0x01,
  553. TRACE_ITER_SYM_OFFSET = 0x02,
  554. TRACE_ITER_SYM_ADDR = 0x04,
  555. TRACE_ITER_VERBOSE = 0x08,
  556. TRACE_ITER_RAW = 0x10,
  557. TRACE_ITER_HEX = 0x20,
  558. TRACE_ITER_BIN = 0x40,
  559. TRACE_ITER_BLOCK = 0x80,
  560. TRACE_ITER_STACKTRACE = 0x100,
  561. TRACE_ITER_SCHED_TREE = 0x200,
  562. TRACE_ITER_PRINTK = 0x400,
  563. TRACE_ITER_PREEMPTONLY = 0x800,
  564. TRACE_ITER_BRANCH = 0x1000,
  565. TRACE_ITER_ANNOTATE = 0x2000,
  566. TRACE_ITER_USERSTACKTRACE = 0x4000,
  567. TRACE_ITER_SYM_USEROBJ = 0x8000,
  568. TRACE_ITER_PRINTK_MSGONLY = 0x10000,
  569. TRACE_ITER_CONTEXT_INFO = 0x20000, /* Print pid/cpu/time */
  570. TRACE_ITER_LATENCY_FMT = 0x40000,
  571. };
  572. /*
  573. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  574. * control the output of kernel symbols.
  575. */
  576. #define TRACE_ITER_SYM_MASK \
  577. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  578. extern struct tracer nop_trace;
  579. /**
  580. * ftrace_preempt_disable - disable preemption scheduler safe
  581. *
  582. * When tracing can happen inside the scheduler, there exists
  583. * cases that the tracing might happen before the need_resched
  584. * flag is checked. If this happens and the tracer calls
  585. * preempt_enable (after a disable), a schedule might take place
  586. * causing an infinite recursion.
  587. *
  588. * To prevent this, we read the need_resched flag before
  589. * disabling preemption. When we want to enable preemption we
  590. * check the flag, if it is set, then we call preempt_enable_no_resched.
  591. * Otherwise, we call preempt_enable.
  592. *
  593. * The rational for doing the above is that if need_resched is set
  594. * and we have yet to reschedule, we are either in an atomic location
  595. * (where we do not need to check for scheduling) or we are inside
  596. * the scheduler and do not want to resched.
  597. */
  598. static inline int ftrace_preempt_disable(void)
  599. {
  600. int resched;
  601. resched = need_resched();
  602. preempt_disable_notrace();
  603. return resched;
  604. }
  605. /**
  606. * ftrace_preempt_enable - enable preemption scheduler safe
  607. * @resched: the return value from ftrace_preempt_disable
  608. *
  609. * This is a scheduler safe way to enable preemption and not miss
  610. * any preemption checks. The disabled saved the state of preemption.
  611. * If resched is set, then we are either inside an atomic or
  612. * are inside the scheduler (we would have already scheduled
  613. * otherwise). In this case, we do not want to call normal
  614. * preempt_enable, but preempt_enable_no_resched instead.
  615. */
  616. static inline void ftrace_preempt_enable(int resched)
  617. {
  618. if (resched)
  619. preempt_enable_no_resched_notrace();
  620. else
  621. preempt_enable_notrace();
  622. }
  623. #ifdef CONFIG_BRANCH_TRACER
  624. extern int enable_branch_tracing(struct trace_array *tr);
  625. extern void disable_branch_tracing(void);
  626. static inline int trace_branch_enable(struct trace_array *tr)
  627. {
  628. if (trace_flags & TRACE_ITER_BRANCH)
  629. return enable_branch_tracing(tr);
  630. return 0;
  631. }
  632. static inline void trace_branch_disable(void)
  633. {
  634. /* due to races, always disable */
  635. disable_branch_tracing();
  636. }
  637. #else
  638. static inline int trace_branch_enable(struct trace_array *tr)
  639. {
  640. return 0;
  641. }
  642. static inline void trace_branch_disable(void)
  643. {
  644. }
  645. #endif /* CONFIG_BRANCH_TRACER */
  646. /* trace event type bit fields, not numeric */
  647. enum {
  648. TRACE_EVENT_TYPE_PRINTF = 1,
  649. TRACE_EVENT_TYPE_RAW = 2,
  650. };
  651. struct ftrace_event_call {
  652. char *name;
  653. char *system;
  654. struct dentry *dir;
  655. int enabled;
  656. int (*regfunc)(void);
  657. void (*unregfunc)(void);
  658. int id;
  659. int (*raw_init)(void);
  660. int (*show_format)(struct trace_seq *s);
  661. };
  662. void event_trace_printk(unsigned long ip, const char *fmt, ...);
  663. extern struct ftrace_event_call __start_ftrace_events[];
  664. extern struct ftrace_event_call __stop_ftrace_events[];
  665. #endif /* _LINUX_KERNEL_TRACE_H */