trace.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 init_tracer_sysprof_debugfs(struct dentry *d_tracer);
  169. void ftrace(struct trace_array *tr,
  170. struct trace_array_cpu *data,
  171. unsigned long ip,
  172. unsigned long parent_ip,
  173. unsigned long flags);
  174. void tracing_sched_switch_trace(struct trace_array *tr,
  175. struct trace_array_cpu *data,
  176. struct task_struct *prev,
  177. struct task_struct *next,
  178. unsigned long flags);
  179. void tracing_record_cmdline(struct task_struct *tsk);
  180. void tracing_sched_wakeup_trace(struct trace_array *tr,
  181. struct trace_array_cpu *data,
  182. struct task_struct *wakee,
  183. struct task_struct *cur,
  184. unsigned long flags);
  185. void trace_special(struct trace_array *tr,
  186. struct trace_array_cpu *data,
  187. unsigned long arg1,
  188. unsigned long arg2,
  189. unsigned long arg3);
  190. void trace_function(struct trace_array *tr,
  191. struct trace_array_cpu *data,
  192. unsigned long ip,
  193. unsigned long parent_ip,
  194. unsigned long flags);
  195. void tracing_start_function_trace(void);
  196. void tracing_stop_function_trace(void);
  197. int register_tracer(struct tracer *type);
  198. void unregister_tracer(struct tracer *type);
  199. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  200. extern unsigned long tracing_max_latency;
  201. extern unsigned long tracing_thresh;
  202. extern atomic_t trace_record_cmdline_enabled;
  203. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  204. void update_max_tr_single(struct trace_array *tr,
  205. struct task_struct *tsk, int cpu);
  206. extern cycle_t ftrace_now(int cpu);
  207. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  208. typedef void
  209. (*tracer_switch_func_t)(void *private,
  210. void *__rq,
  211. struct task_struct *prev,
  212. struct task_struct *next);
  213. struct tracer_switch_ops {
  214. tracer_switch_func_t func;
  215. void *private;
  216. struct tracer_switch_ops *next;
  217. };
  218. #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
  219. #ifdef CONFIG_DYNAMIC_FTRACE
  220. extern unsigned long ftrace_update_tot_cnt;
  221. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  222. extern int DYN_FTRACE_TEST_NAME(void);
  223. #endif
  224. #ifdef CONFIG_FTRACE_STARTUP_TEST
  225. #ifdef CONFIG_FTRACE
  226. extern int trace_selftest_startup_function(struct tracer *trace,
  227. struct trace_array *tr);
  228. #endif
  229. #ifdef CONFIG_IRQSOFF_TRACER
  230. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  231. struct trace_array *tr);
  232. #endif
  233. #ifdef CONFIG_PREEMPT_TRACER
  234. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  235. struct trace_array *tr);
  236. #endif
  237. #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
  238. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  239. struct trace_array *tr);
  240. #endif
  241. #ifdef CONFIG_SCHED_TRACER
  242. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  243. struct trace_array *tr);
  244. #endif
  245. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  246. extern int trace_selftest_startup_sched_switch(struct tracer *trace,
  247. struct trace_array *tr);
  248. #endif
  249. #ifdef CONFIG_SYSPROF_TRACER
  250. extern int trace_selftest_startup_sysprof(struct tracer *trace,
  251. struct trace_array *tr);
  252. #endif
  253. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  254. extern void *head_page(struct trace_array_cpu *data);
  255. extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
  256. extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
  257. size_t cnt);
  258. extern long ns2usecs(cycle_t nsec);
  259. extern unsigned long trace_flags;
  260. /*
  261. * trace_iterator_flags is an enumeration that defines bit
  262. * positions into trace_flags that controls the output.
  263. *
  264. * NOTE: These bits must match the trace_options array in
  265. * trace.c.
  266. */
  267. enum trace_iterator_flags {
  268. TRACE_ITER_PRINT_PARENT = 0x01,
  269. TRACE_ITER_SYM_OFFSET = 0x02,
  270. TRACE_ITER_SYM_ADDR = 0x04,
  271. TRACE_ITER_VERBOSE = 0x08,
  272. TRACE_ITER_RAW = 0x10,
  273. TRACE_ITER_HEX = 0x20,
  274. TRACE_ITER_BIN = 0x40,
  275. TRACE_ITER_BLOCK = 0x80,
  276. TRACE_ITER_STACKTRACE = 0x100,
  277. TRACE_ITER_SCHED_TREE = 0x200,
  278. };
  279. #endif /* _LINUX_KERNEL_TRACE_H */