trace.h 8.8 KB

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