trace.h 7.0 KB

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