trace.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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 5
  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 saved_latency;
  87. unsigned long critical_start;
  88. unsigned long critical_end;
  89. unsigned long critical_sequence;
  90. unsigned long nice;
  91. unsigned long policy;
  92. unsigned long rt_priority;
  93. cycle_t preempt_timestamp;
  94. pid_t pid;
  95. uid_t uid;
  96. char comm[TASK_COMM_LEN];
  97. };
  98. struct trace_iterator;
  99. /*
  100. * The trace array - an array of per-CPU trace arrays. This is the
  101. * highest level data structure that individual tracers deal with.
  102. * They have on/off state as well:
  103. */
  104. struct trace_array {
  105. unsigned long entries;
  106. long ctrl;
  107. int cpu;
  108. cycle_t time_start;
  109. struct task_struct *waiter;
  110. struct trace_array_cpu *data[NR_CPUS];
  111. };
  112. /*
  113. * A specific tracer, represented by methods that operate on a trace array:
  114. */
  115. struct tracer {
  116. const char *name;
  117. void (*init)(struct trace_array *tr);
  118. void (*reset)(struct trace_array *tr);
  119. void (*open)(struct trace_iterator *iter);
  120. void (*close)(struct trace_iterator *iter);
  121. void (*start)(struct trace_iterator *iter);
  122. void (*stop)(struct trace_iterator *iter);
  123. void (*ctrl_update)(struct trace_array *tr);
  124. #ifdef CONFIG_FTRACE_STARTUP_TEST
  125. int (*selftest)(struct tracer *trace,
  126. struct trace_array *tr);
  127. #endif
  128. int (*print_line)(struct trace_iterator *iter);
  129. struct tracer *next;
  130. int print_max;
  131. };
  132. struct trace_seq {
  133. unsigned char buffer[PAGE_SIZE];
  134. unsigned int len;
  135. };
  136. /*
  137. * Trace iterator - used by printout routines who present trace
  138. * results to users and which routines might sleep, etc:
  139. */
  140. struct trace_iterator {
  141. struct trace_seq seq;
  142. struct trace_array *tr;
  143. struct tracer *trace;
  144. struct trace_entry *ent;
  145. int cpu;
  146. struct trace_entry *prev_ent;
  147. int prev_cpu;
  148. unsigned long iter_flags;
  149. loff_t pos;
  150. unsigned long next_idx[NR_CPUS];
  151. struct list_head *next_page[NR_CPUS];
  152. unsigned next_page_idx[NR_CPUS];
  153. long idx;
  154. };
  155. void tracing_reset(struct trace_array_cpu *data);
  156. int tracing_open_generic(struct inode *inode, struct file *filp);
  157. struct dentry *tracing_init_dentry(void);
  158. void ftrace(struct trace_array *tr,
  159. struct trace_array_cpu *data,
  160. unsigned long ip,
  161. unsigned long parent_ip,
  162. unsigned long flags);
  163. void tracing_sched_switch_trace(struct trace_array *tr,
  164. struct trace_array_cpu *data,
  165. struct task_struct *prev,
  166. struct task_struct *next,
  167. unsigned long flags);
  168. void tracing_record_cmdline(struct task_struct *tsk);
  169. void tracing_sched_wakeup_trace(struct trace_array *tr,
  170. struct trace_array_cpu *data,
  171. struct task_struct *wakee,
  172. struct task_struct *cur,
  173. unsigned long flags);
  174. void trace_special(struct trace_array *tr,
  175. struct trace_array_cpu *data,
  176. unsigned long arg1,
  177. unsigned long arg2,
  178. unsigned long arg3);
  179. void trace_function(struct trace_array *tr,
  180. struct trace_array_cpu *data,
  181. unsigned long ip,
  182. unsigned long parent_ip,
  183. unsigned long flags);
  184. void tracing_start_function_trace(void);
  185. void tracing_stop_function_trace(void);
  186. int register_tracer(struct tracer *type);
  187. void unregister_tracer(struct tracer *type);
  188. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  189. extern unsigned long tracing_max_latency;
  190. extern unsigned long tracing_thresh;
  191. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  192. void update_max_tr_single(struct trace_array *tr,
  193. struct task_struct *tsk, int cpu);
  194. extern cycle_t ftrace_now(int cpu);
  195. #ifdef CONFIG_SCHED_TRACER
  196. extern void
  197. wakeup_sched_switch(struct task_struct *prev, struct task_struct *next);
  198. extern void
  199. wakeup_sched_wakeup(struct task_struct *wakee, struct task_struct *curr);
  200. #else
  201. static inline void
  202. wakeup_sched_switch(struct task_struct *prev, struct task_struct *next)
  203. {
  204. }
  205. static inline void
  206. wakeup_sched_wakeup(struct task_struct *wakee, struct task_struct *curr)
  207. {
  208. }
  209. #endif
  210. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  211. typedef void
  212. (*tracer_switch_func_t)(void *private,
  213. struct task_struct *prev,
  214. struct task_struct *next);
  215. struct tracer_switch_ops {
  216. tracer_switch_func_t func;
  217. void *private;
  218. struct tracer_switch_ops *next;
  219. };
  220. extern int register_tracer_switch(struct tracer_switch_ops *ops);
  221. extern int unregister_tracer_switch(struct tracer_switch_ops *ops);
  222. #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
  223. #ifdef CONFIG_DYNAMIC_FTRACE
  224. extern unsigned long ftrace_update_tot_cnt;
  225. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  226. extern int DYN_FTRACE_TEST_NAME(void);
  227. #endif
  228. #ifdef CONFIG_FTRACE_STARTUP_TEST
  229. #ifdef CONFIG_FTRACE
  230. extern int trace_selftest_startup_function(struct tracer *trace,
  231. struct trace_array *tr);
  232. #endif
  233. #ifdef CONFIG_IRQSOFF_TRACER
  234. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  235. struct trace_array *tr);
  236. #endif
  237. #ifdef CONFIG_PREEMPT_TRACER
  238. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  239. struct trace_array *tr);
  240. #endif
  241. #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
  242. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  243. struct trace_array *tr);
  244. #endif
  245. #ifdef CONFIG_SCHED_TRACER
  246. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  247. struct trace_array *tr);
  248. #endif
  249. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  250. extern int trace_selftest_startup_sched_switch(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 long ns2usecs(cycle_t nsec);
  257. extern unsigned long trace_flags;
  258. enum trace_iterator_flags {
  259. TRACE_ITER_PRINT_PARENT = 0x01,
  260. TRACE_ITER_SYM_OFFSET = 0x02,
  261. TRACE_ITER_SYM_ADDR = 0x04,
  262. TRACE_ITER_VERBOSE = 0x08,
  263. TRACE_ITER_RAW = 0x10,
  264. TRACE_ITER_HEX = 0x20,
  265. TRACE_ITER_BIN = 0x40,
  266. TRACE_ITER_BLOCK = 0x80,
  267. TRACE_ITER_STACKTRACE = 0x100,
  268. TRACE_ITER_SCHED_TREE = 0x200,
  269. };
  270. #endif /* _LINUX_KERNEL_TRACE_H */