trace.h 6.1 KB

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