trace.h 6.3 KB

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