trace.h 8.7 KB

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