trace.h 7.4 KB

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