trace.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. enum trace_type {
  8. __TRACE_FIRST_TYPE = 0,
  9. TRACE_FN,
  10. TRACE_CTX,
  11. TRACE_WAKE,
  12. TRACE_STACK,
  13. TRACE_SPECIAL,
  14. __TRACE_LAST_TYPE
  15. };
  16. /*
  17. * Function trace entry - function address and parent function addres:
  18. */
  19. struct ftrace_entry {
  20. unsigned long ip;
  21. unsigned long parent_ip;
  22. };
  23. /*
  24. * Context switch trace entry - which task (and prio) we switched from/to:
  25. */
  26. struct ctx_switch_entry {
  27. unsigned int prev_pid;
  28. unsigned char prev_prio;
  29. unsigned char prev_state;
  30. unsigned int next_pid;
  31. unsigned char next_prio;
  32. unsigned char next_state;
  33. };
  34. /*
  35. * Special (free-form) trace entry:
  36. */
  37. struct special_entry {
  38. unsigned long arg1;
  39. unsigned long arg2;
  40. unsigned long arg3;
  41. };
  42. /*
  43. * Stack-trace entry:
  44. */
  45. #define FTRACE_STACK_ENTRIES 8
  46. struct stack_entry {
  47. unsigned long caller[FTRACE_STACK_ENTRIES];
  48. };
  49. /*
  50. * The trace entry - the most basic unit of tracing. This is what
  51. * is printed in the end as a single line in the trace output, such as:
  52. *
  53. * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
  54. */
  55. struct trace_entry {
  56. char type;
  57. char cpu;
  58. char flags;
  59. char preempt_count;
  60. int pid;
  61. cycle_t t;
  62. union {
  63. struct ftrace_entry fn;
  64. struct ctx_switch_entry ctx;
  65. struct special_entry special;
  66. struct stack_entry stack;
  67. };
  68. };
  69. #define TRACE_ENTRY_SIZE sizeof(struct trace_entry)
  70. /*
  71. * The CPU trace array - it consists of thousands of trace entries
  72. * plus some other descriptor data: (for example which task started
  73. * the trace, etc.)
  74. */
  75. struct trace_array_cpu {
  76. struct list_head trace_pages;
  77. atomic_t disabled;
  78. raw_spinlock_t lock;
  79. struct lock_class_key lock_key;
  80. /* these fields get copied into max-trace: */
  81. unsigned trace_head_idx;
  82. unsigned trace_tail_idx;
  83. void *trace_head; /* producer */
  84. void *trace_tail; /* consumer */
  85. unsigned long trace_idx;
  86. unsigned long overrun;
  87. unsigned long saved_latency;
  88. unsigned long critical_start;
  89. unsigned long critical_end;
  90. unsigned long critical_sequence;
  91. unsigned long nice;
  92. unsigned long policy;
  93. unsigned long rt_priority;
  94. cycle_t preempt_timestamp;
  95. pid_t pid;
  96. uid_t uid;
  97. char comm[TASK_COMM_LEN];
  98. };
  99. struct trace_iterator;
  100. /*
  101. * The trace array - an array of per-CPU trace arrays. This is the
  102. * highest level data structure that individual tracers deal with.
  103. * They have on/off state as well:
  104. */
  105. struct trace_array {
  106. unsigned long entries;
  107. long ctrl;
  108. int cpu;
  109. cycle_t time_start;
  110. struct task_struct *waiter;
  111. struct trace_array_cpu *data[NR_CPUS];
  112. };
  113. /*
  114. * A specific tracer, represented by methods that operate on a trace array:
  115. */
  116. struct tracer {
  117. const char *name;
  118. void (*init)(struct trace_array *tr);
  119. void (*reset)(struct trace_array *tr);
  120. void (*open)(struct trace_iterator *iter);
  121. void (*pipe_open)(struct trace_iterator *iter);
  122. void (*close)(struct trace_iterator *iter);
  123. void (*start)(struct trace_iterator *iter);
  124. void (*stop)(struct trace_iterator *iter);
  125. ssize_t (*read)(struct trace_iterator *iter,
  126. struct file *filp, char __user *ubuf,
  127. size_t cnt, loff_t *ppos);
  128. void (*ctrl_update)(struct trace_array *tr);
  129. #ifdef CONFIG_FTRACE_STARTUP_TEST
  130. int (*selftest)(struct tracer *trace,
  131. struct trace_array *tr);
  132. #endif
  133. int (*print_line)(struct trace_iterator *iter);
  134. struct tracer *next;
  135. int print_max;
  136. };
  137. struct trace_seq {
  138. unsigned char buffer[PAGE_SIZE];
  139. unsigned int len;
  140. unsigned int readpos;
  141. };
  142. /*
  143. * Trace iterator - used by printout routines who present trace
  144. * results to users and which routines might sleep, etc:
  145. */
  146. struct trace_iterator {
  147. struct trace_array *tr;
  148. struct tracer *trace;
  149. void *private;
  150. long last_overrun[NR_CPUS];
  151. long overrun[NR_CPUS];
  152. /* The below is zeroed out in pipe_read */
  153. struct trace_seq seq;
  154. struct trace_entry *ent;
  155. int cpu;
  156. struct trace_entry *prev_ent;
  157. int prev_cpu;
  158. unsigned long iter_flags;
  159. loff_t pos;
  160. unsigned long next_idx[NR_CPUS];
  161. struct list_head *next_page[NR_CPUS];
  162. unsigned next_page_idx[NR_CPUS];
  163. long idx;
  164. };
  165. void tracing_reset(struct trace_array_cpu *data);
  166. int tracing_open_generic(struct inode *inode, struct file *filp);
  167. struct dentry *tracing_init_dentry(void);
  168. void ftrace(struct trace_array *tr,
  169. struct trace_array_cpu *data,
  170. unsigned long ip,
  171. unsigned long parent_ip,
  172. unsigned long flags);
  173. void tracing_sched_switch_trace(struct trace_array *tr,
  174. struct trace_array_cpu *data,
  175. struct task_struct *prev,
  176. struct task_struct *next,
  177. unsigned long flags);
  178. void tracing_record_cmdline(struct task_struct *tsk);
  179. void tracing_sched_wakeup_trace(struct trace_array *tr,
  180. struct trace_array_cpu *data,
  181. struct task_struct *wakee,
  182. struct task_struct *cur,
  183. unsigned long flags);
  184. void trace_special(struct trace_array *tr,
  185. struct trace_array_cpu *data,
  186. unsigned long arg1,
  187. unsigned long arg2,
  188. unsigned long arg3);
  189. void trace_function(struct trace_array *tr,
  190. struct trace_array_cpu *data,
  191. unsigned long ip,
  192. unsigned long parent_ip,
  193. unsigned long flags);
  194. void tracing_start_function_trace(void);
  195. void tracing_stop_function_trace(void);
  196. int register_tracer(struct tracer *type);
  197. void unregister_tracer(struct tracer *type);
  198. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  199. extern unsigned long tracing_max_latency;
  200. extern unsigned long tracing_thresh;
  201. extern atomic_t trace_record_cmdline_enabled;
  202. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  203. void update_max_tr_single(struct trace_array *tr,
  204. struct task_struct *tsk, int cpu);
  205. extern cycle_t ftrace_now(int cpu);
  206. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  207. typedef void
  208. (*tracer_switch_func_t)(void *private,
  209. void *__rq,
  210. struct task_struct *prev,
  211. struct task_struct *next);
  212. struct tracer_switch_ops {
  213. tracer_switch_func_t func;
  214. void *private;
  215. struct tracer_switch_ops *next;
  216. };
  217. #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
  218. #ifdef CONFIG_DYNAMIC_FTRACE
  219. extern unsigned long ftrace_update_tot_cnt;
  220. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  221. extern int DYN_FTRACE_TEST_NAME(void);
  222. #endif
  223. #ifdef CONFIG_FTRACE_STARTUP_TEST
  224. #ifdef CONFIG_FTRACE
  225. extern int trace_selftest_startup_function(struct tracer *trace,
  226. struct trace_array *tr);
  227. #endif
  228. #ifdef CONFIG_IRQSOFF_TRACER
  229. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  230. struct trace_array *tr);
  231. #endif
  232. #ifdef CONFIG_PREEMPT_TRACER
  233. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  234. struct trace_array *tr);
  235. #endif
  236. #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
  237. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  238. struct trace_array *tr);
  239. #endif
  240. #ifdef CONFIG_SCHED_TRACER
  241. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  242. struct trace_array *tr);
  243. #endif
  244. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  245. extern int trace_selftest_startup_sched_switch(struct tracer *trace,
  246. struct trace_array *tr);
  247. #endif
  248. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  249. extern void *head_page(struct trace_array_cpu *data);
  250. extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
  251. extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
  252. size_t cnt);
  253. extern long ns2usecs(cycle_t nsec);
  254. extern unsigned long trace_flags;
  255. /*
  256. * trace_iterator_flags is an enumeration that defines bit
  257. * positions into trace_flags that controls the output.
  258. *
  259. * NOTE: These bits must match the trace_options array in
  260. * trace.c.
  261. */
  262. enum trace_iterator_flags {
  263. TRACE_ITER_PRINT_PARENT = 0x01,
  264. TRACE_ITER_SYM_OFFSET = 0x02,
  265. TRACE_ITER_SYM_ADDR = 0x04,
  266. TRACE_ITER_VERBOSE = 0x08,
  267. TRACE_ITER_RAW = 0x10,
  268. TRACE_ITER_HEX = 0x20,
  269. TRACE_ITER_BIN = 0x40,
  270. TRACE_ITER_BLOCK = 0x80,
  271. TRACE_ITER_STACKTRACE = 0x100,
  272. TRACE_ITER_SCHED_TREE = 0x200,
  273. };
  274. #endif /* _LINUX_KERNEL_TRACE_H */